Package DisplayProject.controls

Source Code of DisplayProject.controls.DropListUI

/*
Copyright (c) 2003-2009 ITerative Consulting Pty Ltd. All Rights Reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted
provided that the following conditions are met:

o Redistributions of source code must retain the above copyright notice, this list of conditions and
the following disclaimer.
 
o Redistributions in binary form must reproduce the above copyright notice, this list of conditions
and the following disclaimer in the documentation and/or other materials provided with the distribution.
   
o This jcTOOL Helper Class software, whether in binary or source form may not be used within,
or to derive, any other product without the specific prior written permission of the copyright holder

 
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


*/
package DisplayProject.controls;

import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Rectangle;

import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.ListCellRenderer;
import javax.swing.UIManager;
import javax.swing.plaf.basic.BasicComboPopup;
import javax.swing.plaf.basic.ComboPopup;

import DisplayProject.Constants;
import DisplayProject.actions.WidgetState;

import com.sun.java.swing.plaf.windows.WindowsComboBoxUI;
import com.sun.java.swing.plaf.windows.WindowsPopupMenuUI;

public class DropListUI extends WindowsComboBoxUI {
 
    public static DropListUI createUI(JComponent c) {
        return new DropListUI();
    }

    /**
     * Paints the currently selected item.
     */
    public void paintCurrentValue(Graphics g,Rectangle bounds,boolean hasFocus) {
        ListCellRenderer renderer = comboBox.getRenderer();
        Component c;

        if ( hasFocus && !isPopupVisible(comboBox) ) {
            c = renderer.getListCellRendererComponent( listBox,
                                                       comboBox.getSelectedItem(),
                                                       -1,
                                                       true,
                                                       false );
        }
        else {
            c = renderer.getListCellRendererComponent( listBox,
                                                       comboBox.getSelectedItem(),
                                                       -1,
                                                       false,
                                                       false );
            c.setBackground(UIManager.getColor("ComboBox.background"));
        }
        c.setFont(comboBox.getFont());

        if ( hasFocus && !isPopupVisible(comboBox) ) {
          c.setForeground(listBox.getSelectionForeground());
          c.setBackground(listBox.getSelectionBackground());
        }
        else {
          int state = WidgetState.get(comboBox);
          if (state == Constants.FS_DISABLED) {
            // In Forte the disabled colour is the normal disabled colour, but only then
            // (for example, INACTIVE still uses the normal foreground colour)
            c.setForeground((Color)UIManager.getDefaults().get("ComboBox.disabledForeground"));
          }
          else {
            c.setForeground(comboBox.getForeground());
          }
          c.setBackground(comboBox.getBackground());
        }
       
        // Fix for 4238829: should lay out the JPanel.
        boolean shouldValidate = false;
        if (c instanceof JPanel)  {
            shouldValidate = true;
        }

        currentValuePane.paintComponent(g,c,comboBox,bounds.x,bounds.y,
                                        bounds.width,bounds.height, shouldValidate);
    }

    @Override
    protected ComboPopup createPopup() {
      return new MyPopup(this.comboBox);
    }
   
    private class MyPopupUI extends WindowsPopupMenuUI {
     
    }
    @SuppressWarnings("serial")
  private class MyPopup extends BasicComboPopup {
        private static final String uiClassID = "MyPopupUI";

        @Override
        public String getUIClassID() {
            return uiClassID;
        }

        @Override
        public void updateUI() {
            setUI(MyPopupUI.createUI(this));
            invalidate();
        }

      public MyPopup(JComboBox combo) {
        super(combo);
      }
    }
}
TOP

Related Classes of DisplayProject.controls.DropListUI

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.