Package DisplayProject.controls

Source Code of DisplayProject.controls.DropListUI$MyPopup

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$MyPopup

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.