home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 2000 March / pcp161a.iso / handson / files / copyjava.exe / com / sun / java / swing / plaf / basic / BasicComboBoxUI.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-02-26  |  21.1 KB  |  907 lines

  1. package com.sun.java.swing.plaf.basic;
  2.  
  3. import com.sun.java.swing.BorderFactory;
  4. import com.sun.java.swing.BoxLayout;
  5. import com.sun.java.swing.CellRendererPane;
  6. import com.sun.java.swing.ComboBoxEditor;
  7. import com.sun.java.swing.ComboBoxModel;
  8. import com.sun.java.swing.JButton;
  9. import com.sun.java.swing.JComboBox;
  10. import com.sun.java.swing.JComponent;
  11. import com.sun.java.swing.JDialog;
  12. import com.sun.java.swing.JList;
  13. import com.sun.java.swing.JPopupMenu;
  14. import com.sun.java.swing.JRootPane;
  15. import com.sun.java.swing.JScrollPane;
  16. import com.sun.java.swing.KeyStroke;
  17. import com.sun.java.swing.ListCellRenderer;
  18. import com.sun.java.swing.LookAndFeel;
  19. import com.sun.java.swing.SwingUtilities;
  20. import com.sun.java.swing.Timer;
  21. import com.sun.java.swing.UIManager;
  22. import com.sun.java.swing.border.Border;
  23. import com.sun.java.swing.plaf.ComboBoxUI;
  24. import com.sun.java.swing.plaf.ComponentUI;
  25. import com.sun.java.swing.plaf.UIResource;
  26. import java.awt.Color;
  27. import java.awt.Component;
  28. import java.awt.Container;
  29. import java.awt.Dialog;
  30. import java.awt.Dimension;
  31. import java.awt.Graphics;
  32. import java.awt.Insets;
  33. import java.awt.LayoutManager;
  34. import java.awt.Point;
  35. import java.awt.Rectangle;
  36. import java.awt.Toolkit;
  37. import java.awt.Window;
  38. import java.awt.event.FocusEvent;
  39. import java.awt.event.FocusListener;
  40. import java.awt.event.InputEvent;
  41. import java.awt.event.ItemEvent;
  42. import java.awt.event.ItemListener;
  43. import java.awt.event.KeyEvent;
  44. import java.awt.event.KeyListener;
  45. import java.awt.event.MouseEvent;
  46. import java.awt.event.MouseListener;
  47. import java.awt.event.MouseMotionListener;
  48. import java.beans.PropertyChangeEvent;
  49. import java.beans.PropertyChangeListener;
  50. import java.io.Serializable;
  51. import java.util.EventObject;
  52.  
  53. public class BasicComboBoxUI extends ComboBoxUI implements LayoutManager, MouseListener, MouseMotionListener, ItemListener, FocusListener, KeyListener, PropertyChangeListener, Serializable {
  54.    protected static final Color selectionBackgroundColor = new Color(0, 0, 128);
  55.    protected static final int BORDER_THICKNESS = 2;
  56.    protected JComboBox comboBox;
  57.    protected CellRendererPane currentValuePane = new CellRendererPane();
  58.    protected JButton arrowButton;
  59.    protected Component editor;
  60.    protected JPopupMenu menu;
  61.    protected JList listBox;
  62.    protected JScrollPane scrollPane;
  63.    protected Timer autoscrollTimer;
  64.    protected Point lastMouseLocation;
  65.    protected static JComboBox showingComboBox = null;
  66.    protected Point popupLocation;
  67.    protected boolean hasFocus = false;
  68.  
  69.    public static ComponentUI createUI(JComponent var0) {
  70.       return new BasicComboBoxUI();
  71.    }
  72.  
  73.    public void installUI(JComponent var1) {
  74.       this.comboBox = (JComboBox)var1;
  75.       this.addArrowButton();
  76.       this.comboBox.add(this.currentValuePane);
  77.       this.comboBox.setLayout(this);
  78.       this.comboBox.addItemListener(this);
  79.       this.comboBox.addFocusListener(this);
  80.       this.comboBox.addMouseListener(this);
  81.       this.comboBox.addMouseMotionListener(this);
  82.       this.comboBox.addKeyListener(this);
  83.       this.comboBox.addPropertyChangeListener(this);
  84.       if (this.comboBox.getRenderer() == null) {
  85.          this.comboBox.setRenderer((ListCellRenderer)UIManager.get("ComboBox.renderer"));
  86.       }
  87.  
  88.       this.editablePropertyChanged();
  89.       this.addKeyAccelerators(this.comboBox);
  90.       this.configureComboBox();
  91.    }
  92.  
  93.    public void uninstallUI(JComponent var1) {
  94.       this.hidePopup();
  95.       this.removeEditor();
  96.       this.removeArrowButton();
  97.       this.comboBox.setLayout((LayoutManager)null);
  98.       this.comboBox.removeFocusListener(this);
  99.       if (this.listBox != null) {
  100.          this.listBox.removeMouseListener(this);
  101.          this.listBox.removeMouseMotionListener(this);
  102.       }
  103.  
  104.       this.comboBox.removeItemListener(this);
  105.       this.comboBox.removeMouseListener(this);
  106.       this.comboBox.removeMouseMotionListener(this);
  107.       this.comboBox.removeKeyListener(this);
  108.       this.comboBox.resetKeyboardActions();
  109.       this.comboBox.remove(this.currentValuePane);
  110.       this.comboBox.removePropertyChangeListener(this);
  111.       if (this.comboBox.getRenderer() instanceof UIResource) {
  112.          this.comboBox.setRenderer((ListCellRenderer)null);
  113.       }
  114.  
  115.       if (this.comboBox.getEditor() instanceof UIResource) {
  116.          this.comboBox.setEditor((ComboBoxEditor)null);
  117.       }
  118.  
  119.       this.comboBox = null;
  120.       this.unconfigureComboBox();
  121.    }
  122.  
  123.    public boolean isFocusTraversable() {
  124.       return !this.comboBox.isEditable();
  125.    }
  126.  
  127.    protected void configureComboBox() {
  128.       LookAndFeel.installColorsAndFont(this.comboBox, "ComboBox.background", "ComboBox.foreground", "ComboBox.font");
  129.    }
  130.  
  131.    protected void unconfigureComboBox() {
  132.    }
  133.  
  134.    public void editablePropertyChanged() {
  135.       if (this.comboBox.isEditable()) {
  136.          this.addEditor();
  137.       } else {
  138.          this.removeEditor();
  139.       }
  140.    }
  141.  
  142.    public void enablePropertyChanged() {
  143.       boolean var1 = this.comboBox.isEnabled();
  144.       if (var1) {
  145.          if (this.editor != null) {
  146.             this.editor.setEnabled(true);
  147.          }
  148.  
  149.          if (this.arrowButton != null) {
  150.             this.arrowButton.setEnabled(true);
  151.          }
  152.       } else {
  153.          if (this.editor != null) {
  154.             this.editor.setEnabled(false);
  155.          }
  156.  
  157.          if (this.arrowButton != null) {
  158.             this.arrowButton.setEnabled(false);
  159.          }
  160.       }
  161.  
  162.       this.comboBox.repaint();
  163.    }
  164.  
  165.    public void addEditor() {
  166.       if (this.editor != null) {
  167.          this.removeEditor();
  168.       }
  169.  
  170.       if (this.comboBox.getEditor() == null) {
  171.          this.comboBox.setEditor((ComboBoxEditor)UIManager.get("ComboBox.editor"));
  172.       }
  173.  
  174.       this.editor = this.comboBox.getEditor().getEditorComponent();
  175.       this.comboBox.add(this.editor);
  176.       this.editor.setFont(this.comboBox.getFont());
  177.       this.editor.setBackground(this.comboBox.getBackground());
  178.       this.editor.setForeground(this.comboBox.getForeground());
  179.       this.comboBox.configureEditor(this.comboBox.getEditor(), this.comboBox.getSelectedItem());
  180.    }
  181.  
  182.    public void removeEditor() {
  183.       if (this.editor != null) {
  184.          this.comboBox.remove(this.editor);
  185.          this.editor = null;
  186.       }
  187.  
  188.    }
  189.  
  190.    public void addArrowButton() {
  191.       this.arrowButton = this.createArrowButton();
  192.       this.arrowButton.setRequestFocusEnabled(false);
  193.       this.arrowButton.addMouseListener(this);
  194.       this.arrowButton.addMouseMotionListener(this);
  195.       this.arrowButton.resetKeyboardActions();
  196.       this.comboBox.add(this.arrowButton);
  197.    }
  198.  
  199.    public void removeArrowButton() {
  200.       if (this.arrowButton != null) {
  201.          this.comboBox.remove(this.arrowButton);
  202.          this.arrowButton.removeMouseListener(this);
  203.          this.arrowButton.removeMouseMotionListener(this);
  204.          this.arrowButton = null;
  205.       }
  206.  
  207.    }
  208.  
  209.    protected JList createListBox(ComboBoxModel var1) {
  210.       return new JList(var1);
  211.    }
  212.  
  213.    public JList getList() {
  214.       return this.listBox;
  215.    }
  216.  
  217.    protected JButton createArrowButton() {
  218.       return new BasicArrowButton(5);
  219.    }
  220.  
  221.    public void paint(Graphics var1, JComponent var2) {
  222.       Rectangle var3 = ((Component)var2).getBounds();
  223.       BasicGraphicsUtils.drawEtchedRect(var1, 0, 0, var3.width, var3.height);
  224.       boolean var4 = this.comboBox.hasFocus();
  225.       if (!this.comboBox.isEditable()) {
  226.          Rectangle var5 = this.rectangleForCurrentValue();
  227.          this.paintCurrentValueBackground(var1, var5, var4);
  228.          this.paintCurrentValue(var1, var5, var4);
  229.       }
  230.  
  231.    }
  232.  
  233.    public void paintCurrentValue(Graphics var1, Rectangle var2, boolean var3) {
  234.       ListCellRenderer var4 = this.comboBox.getRenderer();
  235.       this.validateMenu();
  236.       Component var5;
  237.       if (var3 && !this.popupIsVisible()) {
  238.          var5 = var4.getListCellRendererComponent(this.listBox, this.comboBox.getSelectedItem(), -1, true, false);
  239.       } else {
  240.          var5 = var4.getListCellRendererComponent(this.listBox, this.comboBox.getSelectedItem(), -1, false, false);
  241.          var5.setBackground(UIManager.getColor("ComboBox.background"));
  242.       }
  243.  
  244.       var5.setFont(this.comboBox.getFont());
  245.       if (var3 && !this.popupIsVisible()) {
  246.          var5.setForeground(this.listBox.getSelectionForeground());
  247.          var5.setBackground(this.listBox.getSelectionBackground());
  248.       } else if (this.comboBox.isEnabled()) {
  249.          var5.setForeground(this.comboBox.getForeground());
  250.          var5.setBackground(this.comboBox.getBackground());
  251.       } else {
  252.          var5.setForeground(UIManager.getColor("ComboBox.disabledForeground"));
  253.          var5.setBackground(UIManager.getColor("ComboBox.disabledBackground"));
  254.       }
  255.  
  256.       this.currentValuePane.paintComponent(var1, var5, this.comboBox, var2.x, var2.y, var2.width, var2.height);
  257.    }
  258.  
  259.    public void paintCurrentValueBackground(Graphics var1, Rectangle var2, boolean var3) {
  260.       Color var4 = var1.getColor();
  261.       if (this.comboBox.isEnabled()) {
  262.          var1.setColor(UIManager.getColor("ComboBox.background"));
  263.       } else {
  264.          var1.setColor(UIManager.getColor("ComboBox.disabledBackground"));
  265.       }
  266.  
  267.       var1.fillRect(var2.x, var2.y, var2.width, var2.height);
  268.       var1.setColor(var4);
  269.    }
  270.  
  271.    protected Dimension getDefaultSize() {
  272.       return new Dimension(100, 20);
  273.    }
  274.  
  275.    protected Dimension getMaxPreferredSize() {
  276.       Dimension var3 = new Dimension();
  277.       ListCellRenderer var4 = this.comboBox.getRenderer();
  278.       ComboBoxModel var5 = this.comboBox.getModel();
  279.       this.validateMenu();
  280.       if (var4 != null && var5.getSize() > 0) {
  281.          int var1 = 0;
  282.  
  283.          for(int var2 = var5.getSize(); var1 < var2; ++var1) {
  284.             Component var6 = var4.getListCellRendererComponent(this.listBox, var5.getElementAt(var1), -1, false, false);
  285.             this.currentValuePane.add(var6);
  286.             var6.setFont(this.comboBox.getFont());
  287.             Dimension var7 = var6.getPreferredSize();
  288.             this.currentValuePane.remove(var6);
  289.             var3.width = Math.max(var3.width, var7.width);
  290.             var3.height = Math.max(var3.height, var7.height);
  291.          }
  292.  
  293.          if (this.comboBox.isEditable()) {
  294.             Dimension var8 = this.editor.getPreferredSize();
  295.             var3.width = Math.max(var3.width, var8.width);
  296.             var3.height = Math.max(var3.height, var8.height);
  297.          }
  298.  
  299.          return var3;
  300.       } else {
  301.          return this.getDefaultSize();
  302.       }
  303.    }
  304.  
  305.    protected Dimension getMaxMinimumSize() {
  306.       Dimension var3 = new Dimension();
  307.       ListCellRenderer var4 = this.comboBox.getRenderer();
  308.       ComboBoxModel var5 = this.comboBox.getModel();
  309.       this.validateMenu();
  310.       if (var4 != null && var5.getSize() > 0) {
  311.          int var1 = 0;
  312.  
  313.          for(int var2 = var5.getSize(); var1 < var2; ++var1) {
  314.             Component var6 = var4.getListCellRendererComponent(this.listBox, var5.getElementAt(var1), -1, false, false);
  315.             this.currentValuePane.add(var6);
  316.             var6.setFont(this.comboBox.getFont());
  317.             Dimension var7 = var6.getMinimumSize();
  318.             this.currentValuePane.remove(var6);
  319.             var3.width = Math.max(var3.width, var7.width);
  320.             var3.height = Math.max(var3.height, var7.height);
  321.          }
  322.  
  323.          if (this.comboBox.isEditable()) {
  324.             Dimension var8 = this.editor.getMinimumSize();
  325.             var3.width = Math.max(var3.width, var8.width);
  326.             var3.height = Math.max(var3.height, var8.height);
  327.          }
  328.  
  329.          return var3;
  330.       } else {
  331.          return this.getDefaultSize();
  332.       }
  333.    }
  334.  
  335.    protected Dimension getMaxMaximumSize() {
  336.       Dimension var3 = new Dimension();
  337.       ListCellRenderer var4 = this.comboBox.getRenderer();
  338.       ComboBoxModel var5 = this.comboBox.getModel();
  339.       this.validateMenu();
  340.       if (var4 != null && var5.getSize() > 0) {
  341.          int var1 = 0;
  342.  
  343.          for(int var2 = var5.getSize(); var1 < var2; ++var1) {
  344.             Component var6 = var4.getListCellRendererComponent(this.listBox, var5.getElementAt(var1), -1, false, false);
  345.             this.currentValuePane.add(var6);
  346.             var6.setFont(this.comboBox.getFont());
  347.             Dimension var7 = var6.getMaximumSize();
  348.             this.currentValuePane.remove(var6);
  349.             var3.width = Math.max(var3.width, var7.width);
  350.             var3.height = Math.max(var3.height, var7.height);
  351.          }
  352.  
  353.          if (this.comboBox.isEditable()) {
  354.             Dimension var8 = this.editor.getMaximumSize();
  355.             var3.width = Math.max(var3.width, var8.width);
  356.             var3.height = Math.max(var3.height, var8.height);
  357.          }
  358.  
  359.          return var3;
  360.       } else {
  361.          return this.getDefaultSize();
  362.       }
  363.    }
  364.  
  365.    public Dimension getPreferredSize(JComponent var1) {
  366.       Dimension var2 = this.getMaxPreferredSize();
  367.       var2.height += 4;
  368.       int var3 = var2.height - 4;
  369.       var2.width += 4 + var3;
  370.       return var2;
  371.    }
  372.  
  373.    public Dimension getMinimumSize(JComponent var1) {
  374.       Dimension var2 = this.getMaxMinimumSize();
  375.       var2.height += 4;
  376.       int var3 = var2.height - 4;
  377.       var2.width += 4 + var3;
  378.       return var2;
  379.    }
  380.  
  381.    public Dimension getMaximumSize(JComponent var1) {
  382.       Dimension var2 = this.getMaxMaximumSize();
  383.       var2.height += 4;
  384.       var2.width = 32767;
  385.       return var2;
  386.    }
  387.  
  388.    public void addLayoutComponent(String var1, Component var2) {
  389.    }
  390.  
  391.    public void removeLayoutComponent(Component var1) {
  392.    }
  393.  
  394.    public Dimension preferredLayoutSize(Container var1) {
  395.       JComboBox var10000 = (JComboBox)var1;
  396.       return var1.getPreferredSize();
  397.    }
  398.  
  399.    public Dimension minimumLayoutSize(Container var1) {
  400.       JComboBox var10000 = (JComboBox)var1;
  401.       return var1.getMinimumSize();
  402.    }
  403.  
  404.    protected Rectangle rectangleForCurrentValue() {
  405.       Dimension var1 = this.comboBox.getSize();
  406.       int var2 = var1.height - 4;
  407.       return new Rectangle(2, 2, var1.width - 4 - var2, var1.height - 4);
  408.    }
  409.  
  410.    public void layoutContainer(Container var1) {
  411.       JComboBox var2 = (JComboBox)var1;
  412.       Dimension var3 = ((Component)var2).getSize();
  413.       int var4 = var3.height - 4;
  414.       if (this.editor != null) {
  415.          Rectangle var5 = this.rectangleForCurrentValue();
  416.          this.editor.setBounds(var5);
  417.       }
  418.  
  419.       if (this.arrowButton != null) {
  420.          this.arrowButton.setBounds(2 + var3.width - 4 - var4, 2, var4, var4);
  421.       }
  422.  
  423.    }
  424.  
  425.    public void itemStateChanged(ItemEvent var1) {
  426.       ComboBoxModel var2 = this.comboBox.getModel();
  427.       Object var3 = var2.getSelectedItem();
  428.       if (this.editor != null) {
  429.          this.comboBox.configureEditor(this.comboBox.getEditor(), var3);
  430.       } else {
  431.          Rectangle var4 = this.rectangleForCurrentValue();
  432.          this.comboBox.repaint(0L, var4.x, var4.y, var4.width, var4.height);
  433.       }
  434.  
  435.       if (this.popupIsVisible()) {
  436.          this.updateListBoxSelection();
  437.       }
  438.  
  439.    }
  440.  
  441.    public void focusGained(FocusEvent var1) {
  442.       if (!this.comboBox.isEditable()) {
  443.          this.repaintCurrentValue();
  444.          this.hasFocus = true;
  445.       }
  446.  
  447.    }
  448.  
  449.    public void focusLost(FocusEvent var1) {
  450.       if (!this.comboBox.isEditable()) {
  451.          this.repaintCurrentValue();
  452.          this.hasFocus = false;
  453.       }
  454.  
  455.    }
  456.  
  457.    public void propertyChange(PropertyChangeEvent var1) {
  458.       String var2 = var1.getPropertyName();
  459.       if (var2.equals("model") && this.listBox != null) {
  460.          this.listBox.setModel(this.comboBox.getModel());
  461.          if (this.popupIsVisible()) {
  462.             this.hidePopup();
  463.          }
  464.       }
  465.  
  466.    }
  467.  
  468.    void repaintCurrentValue() {
  469.       Rectangle var1 = this.rectangleForCurrentValue();
  470.       this.comboBox.repaint(var1.x, var1.y, var1.width, var1.height);
  471.    }
  472.  
  473.    public void mouseClicked(MouseEvent var1) {
  474.    }
  475.  
  476.    public void mouseEntered(MouseEvent var1) {
  477.    }
  478.  
  479.    public void mouseExited(MouseEvent var1) {
  480.    }
  481.  
  482.    public void mouseReleased(MouseEvent var1) {
  483.       this.stopAutoscrolling();
  484.       if (this.popupIsVisible()) {
  485.          if (((EventObject)var1).getSource() == this.listBox) {
  486.             this.updateListBoxSelectionForEvent(var1, true);
  487.             this.comboBox.getModel().setSelectedItem(this.listBox.getSelectedValue());
  488.             this.hidePopup();
  489.             return;
  490.          }
  491.  
  492.          if (((EventObject)var1).getSource() == this.arrowButton && !SwingUtilities.getLocalBounds(this.arrowButton).contains(var1.getPoint())) {
  493.             MouseEvent var5 = this.convertEventToListBox(var1);
  494.             this.updateListBoxSelectionForEvent(var5, true);
  495.             Object var4 = this.listBox.getSelectedValue();
  496.             if (var4 != null) {
  497.                this.comboBox.getModel().setSelectedItem(var4);
  498.             }
  499.  
  500.             this.hidePopup();
  501.             return;
  502.          }
  503.  
  504.          if (((EventObject)var1).getSource() == this.comboBox && !SwingUtilities.getLocalBounds(this.comboBox).contains(var1.getPoint())) {
  505.             MouseEvent var3 = this.convertEventToListBox(var1);
  506.             this.updateListBoxSelectionForEvent(var3, true);
  507.             Object var2 = this.listBox.getSelectedValue();
  508.             if (var2 != null) {
  509.                this.comboBox.getModel().setSelectedItem(var2);
  510.             }
  511.  
  512.             this.hidePopup();
  513.          }
  514.       }
  515.  
  516.    }
  517.  
  518.    protected boolean shouldActivatePopupForEvent(MouseEvent var1) {
  519.       Rectangle var2 = this.rectangleForCurrentValue();
  520.       return var2.contains(var1.getPoint());
  521.    }
  522.  
  523.    public void mousePressed(MouseEvent var1) {
  524.       if (SwingUtilities.isLeftMouseButton(var1)) {
  525.          if (this.comboBox.isEnabled()) {
  526.             if (((EventObject)var1).getSource() == this.arrowButton) {
  527.                Rectangle var2 = SwingUtilities.getLocalBounds(this.arrowButton);
  528.                if (var2.contains(var1.getX(), var1.getY())) {
  529.                   if (this.popupIsVisible()) {
  530.                      this.hidePopup();
  531.                      return;
  532.                   }
  533.  
  534.                   this.showPopup();
  535.                   return;
  536.                }
  537.             } else if (((EventObject)var1).getSource() == this.comboBox && this.shouldActivatePopupForEvent(var1)) {
  538.                if (this.popupIsVisible()) {
  539.                   this.hidePopup();
  540.                   return;
  541.                }
  542.  
  543.                this.showPopup();
  544.             }
  545.  
  546.          }
  547.       }
  548.    }
  549.  
  550.    public void mouseDragged(MouseEvent var1) {
  551.       if (this.popupIsVisible() && (((EventObject)var1).getSource() == this.arrowButton && !SwingUtilities.getLocalBounds(this.arrowButton).contains(var1.getPoint()) || ((EventObject)var1).getSource() == this.comboBox && !SwingUtilities.getLocalBounds(this.comboBox).contains(var1.getPoint()))) {
  552.          MouseEvent var3 = this.convertEventToListBox(var1);
  553.          this.updateListBoxSelectionForEvent(var3, true);
  554.          this.lastMouseLocation = SwingUtilities.convertPoint((Component)((EventObject)var1).getSource(), var1.getPoint(), (Component)null);
  555.          Window var2 = SwingUtilities.windowForComponent((Component)((EventObject)var1).getSource());
  556.          Point var10000 = this.lastMouseLocation;
  557.          var10000.x += ((Component)var2).getBounds().x;
  558.          var10000 = this.lastMouseLocation;
  559.          var10000.y += ((Component)var2).getBounds().y;
  560.          this.startAutoscrolling();
  561.       }
  562.  
  563.    }
  564.  
  565.    public void mouseMoved(MouseEvent var1) {
  566.       Object var2 = ((EventObject)var1).getSource();
  567.       if (this.popupIsVisible() && var2 == this.listBox) {
  568.          Point var3 = var1.getPoint();
  569.          Rectangle var4 = new Rectangle();
  570.          this.listBox.computeVisibleRect(var4);
  571.          if (var4.contains(var3)) {
  572.             this.updateListBoxSelectionForEvent(var1, false);
  573.          }
  574.       }
  575.  
  576.    }
  577.  
  578.    public void keyTyped(KeyEvent var1) {
  579.    }
  580.  
  581.    public void keyReleased(KeyEvent var1) {
  582.    }
  583.  
  584.    public void keyPressed(KeyEvent var1) {
  585.       if ((((EventObject)var1).getSource() == this.comboBox && !this.comboBox.isEditable() || ((EventObject)var1).getSource() == this.listBox && !this.comboBox.isEditable()) && this.comboBox.selectWithKeyChar(var1.getKeyChar())) {
  586.          ((InputEvent)var1).consume();
  587.       }
  588.  
  589.    }
  590.  
  591.    public void validateMenu() {
  592.       if (this.menu == null) {
  593.          this.menu = new JPopupMenu();
  594.          this.menu.setLayout(new BoxLayout(this.menu, 1));
  595.          this.menu.setBorderPainted(true);
  596.          this.menu.setBorder(BorderFactory.createLineBorder(Color.black));
  597.          this.menu.setOpaque(false);
  598.          this.listBox = this.createListBox(this.comboBox.getModel());
  599.          this.listBox.setRequestFocusEnabled(false);
  600.          this.listBox.setBorder((Border)null);
  601.          this.listBox.setCellRenderer(this.comboBox.getRenderer());
  602.          this.listBox.addMouseListener(this);
  603.          this.listBox.addMouseMotionListener(this);
  604.          this.listBox.addKeyListener(this);
  605.          this.listBox.setBorder((Border)null);
  606.          this.scrollPane = new JScrollPane(this.listBox, 20, 31);
  607.          this.scrollPane.setRequestFocusEnabled(false);
  608.          this.scrollPane.getVerticalScrollBar().setRequestFocusEnabled(false);
  609.          this.scrollPane.setBorder((Border)null);
  610.          this.menu.add(this.scrollPane);
  611.          this.menu.setDoubleBuffered(true);
  612.          this.menu.registerKeyboardAction(new 1(this), KeyStroke.getKeyStroke(27, 0), 1);
  613.          this.menu.registerKeyboardAction(new 2(this), KeyStroke.getKeyStroke(10, 0), 1);
  614.          this.addKeyAccelerators(this.menu);
  615.       }
  616.  
  617.    }
  618.  
  619.    private Dialog getDialog() {
  620.       Container var1;
  621.       for(var1 = this.comboBox.getParent(); var1 != null && !(var1 instanceof Dialog) && !(var1 instanceof Window); var1 = ((Component)var1).getParent()) {
  622.       }
  623.  
  624.       return var1 instanceof Dialog ? (Dialog)var1 : null;
  625.    }
  626.  
  627.    private boolean inModalDialog() {
  628.       return this.getDialog() != null;
  629.    }
  630.  
  631.    protected Rectangle computePopupBounds(int var1, int var2, int var3, int var4) {
  632.       Rectangle var6 = new Rectangle(var1, var2, var3, var4);
  633.       boolean var7 = this.inModalDialog();
  634.       Rectangle var5;
  635.       if (var7) {
  636.          Dialog var8 = this.getDialog();
  637.          if (var8 instanceof JDialog) {
  638.             JRootPane var10 = ((JDialog)var8).getRootPane();
  639.             Point var9 = ((Component)var10).getLocationOnScreen();
  640.             var5 = ((Component)var10).getBounds();
  641.             var5.x = var9.x;
  642.             var5.y = var9.y;
  643.          } else {
  644.             var5 = ((Component)var8).getBounds();
  645.          }
  646.  
  647.          Point var13 = new Point(var5.x, var5.y);
  648.          SwingUtilities.convertPointFromScreen(var13, this.comboBox);
  649.          var5.x = var13.x;
  650.          var5.y = var13.y;
  651.       } else {
  652.          Dimension var14 = Toolkit.getDefaultToolkit().getScreenSize();
  653.          var5 = new Rectangle();
  654.          Point var11 = new Point(0, 0);
  655.          SwingUtilities.convertPointFromScreen(var11, this.comboBox);
  656.          var5.x = var11.x;
  657.          var5.y = var11.y;
  658.          var5.width = var14.width;
  659.          var5.height = var14.height;
  660.       }
  661.  
  662.       if (SwingUtilities.isRectangleContainingRectangle(var5, var6)) {
  663.          return var6;
  664.       } else {
  665.          Rectangle var12 = new Rectangle(0, -var6.height, var6.width, var6.height);
  666.          if (SwingUtilities.isRectangleContainingRectangle(var5, var12)) {
  667.             return var12;
  668.          } else if (var7) {
  669.             SwingUtilities.computeIntersection(var5.x, var5.y, var5.width, var5.height, var6);
  670.             SwingUtilities.computeIntersection(var5.x, var5.y, var5.width, var5.height, var12);
  671.             return var6.height > var12.height ? var6 : var12;
  672.          } else {
  673.             return var12;
  674.          }
  675.       }
  676.    }
  677.  
  678.    public void showPopup() {
  679.       Rectangle var3 = this.comboBox.getBounds();
  680.       this.popupLocation = new Point(var3.x, var3.y);
  681.       if (showingComboBox != null && showingComboBox != this.comboBox) {
  682.          showingComboBox.getUI().hidePopup();
  683.          showingComboBox = null;
  684.       }
  685.  
  686.       this.validateMenu();
  687.       this.comboBox.requestFocus();
  688.       this.setupListBox(this.listBox, this.comboBox);
  689.       Dimension var2 = new Dimension(var3.width, this.getPopupHeightForRowCount(this.comboBox.getMaximumRowCount()));
  690.       Border var1 = this.menu.getBorder();
  691.       if (var1 != null) {
  692.          Insets var5 = var1.getBorderInsets(this.menu);
  693.          var2.width -= var5.left + var5.right;
  694.          var2.height -= var5.top + var5.bottom;
  695.       }
  696.  
  697.       this.updateListBoxSelection();
  698.       this.listBox.invalidate();
  699.       Rectangle var4 = this.computePopupBounds(0, this.comboBox.getBounds().height, var2.width, var2.height);
  700.       var2.width = var4.width;
  701.       var2.height = var4.height;
  702.       this.scrollPane.setMaximumSize(var2);
  703.       this.scrollPane.setPreferredSize(var2);
  704.       this.scrollPane.setMinimumSize(var2);
  705.       this.menu.setLightWeightPopupEnabled(this.comboBox.isLightWeightPopupEnabled());
  706.       this.menu.show(this.comboBox, var4.x, var4.y);
  707.       this.menu.repaint();
  708.       this.comboBox.registerKeyboardAction(new 3(this), KeyStroke.getKeyStroke(27, 0), 2);
  709.       this.comboBox.registerKeyboardAction(new 4(this), KeyStroke.getKeyStroke(10, 0), 2);
  710.       this.repaintCurrentValue();
  711.       this.listBox.requestFocus();
  712.       showingComboBox = this.comboBox;
  713.    }
  714.  
  715.    protected void setupListBox(JList var1, JComboBox var2) {
  716.       ((Component)var1).setFont(((Component)var2).getFont());
  717.       ((Component)var1).setForeground(((Component)var2).getForeground());
  718.       ((Component)var1).setBackground(((Component)var2).getBackground());
  719.    }
  720.  
  721.    public void hidePopup() {
  722.       if (this.menu != null && this.listBox != null) {
  723.          if (this.popupIsVisible()) {
  724.             this.menu.setVisible(false);
  725.             this.requestFocusLater();
  726.             this.comboBox.unregisterKeyboardAction(KeyStroke.getKeyStroke(27, 0));
  727.             this.comboBox.unregisterKeyboardAction(KeyStroke.getKeyStroke(10, 0));
  728.          }
  729.       }
  730.    }
  731.  
  732.    protected void requestFocusLater() {
  733.       if (this.comboBox.isEditable()) {
  734.          requestFocusLaterForComponent(this.comboBox.getEditor().getEditorComponent());
  735.       } else {
  736.          requestFocusLaterForComponent(this.comboBox);
  737.          this.repaintCurrentValue();
  738.       }
  739.    }
  740.  
  741.    protected int getPopupHeightForRowCount(int var1) {
  742.       int var2 = this.comboBox.getModel().getSize();
  743.       if (var2 > 0) {
  744.          Rectangle var3 = this.listBox.getCellBounds(0, 0);
  745.          if (var3.height <= 2) {
  746.             var3.height = 17;
  747.          }
  748.  
  749.          return var1 < var2 ? var3.height * var1 + 2 : var3.height * var2 + 2;
  750.       } else {
  751.          return 100;
  752.       }
  753.    }
  754.  
  755.    public boolean popupIsVisible() {
  756.       if (this.menu == null) {
  757.          return false;
  758.       } else {
  759.          this.validateMenu();
  760.          return this.menu.isVisible();
  761.       }
  762.    }
  763.  
  764.    public void maximumRowCountChanged() {
  765.       if (this.popupIsVisible()) {
  766.          this.hidePopup();
  767.          this.showPopup();
  768.       }
  769.  
  770.    }
  771.  
  772.    protected void updateListBoxSelection() {
  773.       Object var1 = this.comboBox.getModel().getSelectedItem();
  774.       if (var1 == null && this.listBox != null) {
  775.          this.listBox.setSelectedIndex(-1);
  776.       } else {
  777.          this.listBox.setSelectedValue(var1, true);
  778.       }
  779.    }
  780.  
  781.    protected void startAutoscrolling() {
  782.       if (this.autoscrollTimer == null) {
  783.          this.autoscrollTimer = new Timer(100, new 5(this));
  784.       }
  785.  
  786.       this.autoscrollTimer.start();
  787.    }
  788.  
  789.    protected void stopAutoscrolling() {
  790.       if (this.autoscrollTimer != null) {
  791.          this.autoscrollTimer.stop();
  792.       }
  793.  
  794.       this.lastMouseLocation = null;
  795.    }
  796.  
  797.    protected void autoscroll() {
  798.       if (this.listBox != null) {
  799.          Window var1 = SwingUtilities.windowForComponent(this.listBox);
  800.          if (this.lastMouseLocation != null && var1 != null) {
  801.             Point var2 = new Point(this.lastMouseLocation.x - ((Component)var1).getBounds().x, this.lastMouseLocation.y - ((Component)var1).getBounds().y);
  802.             var2 = SwingUtilities.convertPoint((Component)null, var2, this.listBox);
  803.             int var3 = this.listBox.locationToIndex(var2);
  804.             if (var3 == -1) {
  805.                if (var2.y < 0) {
  806.                   var3 = 0;
  807.                } else {
  808.                   var3 = this.comboBox.getModel().getSize() - 1;
  809.                }
  810.             }
  811.  
  812.             this.listBox.setSelectedIndex(var3);
  813.             this.listBox.ensureIndexIsVisible(var3);
  814.          }
  815.  
  816.       }
  817.    }
  818.  
  819.    protected void updateListBoxSelectionForEvent(MouseEvent var1, boolean var2) {
  820.       Point var3 = var1.getPoint();
  821.       if (this.listBox != null) {
  822.          int var4 = this.listBox.locationToIndex(var3);
  823.          if (var4 == -1) {
  824.             if (var3.y < 0) {
  825.                var4 = 0;
  826.             } else {
  827.                var4 = this.comboBox.getModel().getSize() - 1;
  828.             }
  829.          }
  830.  
  831.          this.listBox.setSelectedIndex(var4);
  832.          if (var2) {
  833.             this.listBox.ensureIndexIsVisible(var4);
  834.          }
  835.  
  836.       }
  837.    }
  838.  
  839.    protected void selectNextPossibleValue() {
  840.       this.validateMenu();
  841.       int var1;
  842.       if (this.popupIsVisible()) {
  843.          var1 = this.listBox.getSelectedIndex();
  844.       } else {
  845.          var1 = this.comboBox.getSelectedIndex();
  846.       }
  847.  
  848.       if (var1 < this.comboBox.getModel().getSize() - 1) {
  849.          this.comboBox.setSelectedIndex(var1 + 1);
  850.       }
  851.  
  852.    }
  853.  
  854.    protected void selectPreviousPossibleValue() {
  855.       this.validateMenu();
  856.       int var1;
  857.       if (this.popupIsVisible()) {
  858.          var1 = this.listBox.getSelectedIndex();
  859.       } else {
  860.          var1 = this.comboBox.getSelectedIndex();
  861.       }
  862.  
  863.       if (var1 > 0) {
  864.          this.comboBox.setSelectedIndex(var1 - 1);
  865.       }
  866.  
  867.    }
  868.  
  869.    protected void toggleOpenClose() {
  870.       if (this.popupIsVisible()) {
  871.          this.hidePopup();
  872.       } else {
  873.          this.showPopup();
  874.       }
  875.    }
  876.  
  877.    protected MouseEvent convertEventToListBox(MouseEvent var1) {
  878.       MouseEvent var5 = SwingUtilities.convertMouseEvent((Component)((EventObject)var1).getSource(), var1, (Component)null);
  879.       Window var3 = SwingUtilities.windowForComponent((Component)((EventObject)var1).getSource());
  880.       Rectangle var2 = ((Component)var3).getBounds();
  881.       var5.translatePoint(var2.x, var2.y);
  882.       Window var4 = SwingUtilities.windowForComponent(this.listBox);
  883.       var2 = ((Component)var4).getBounds();
  884.       var5.translatePoint(-var2.x, -var2.y);
  885.       var5 = SwingUtilities.convertMouseEvent((Component)null, var5, this.listBox);
  886.       return var5;
  887.    }
  888.  
  889.    protected void addKeyAccelerators(JComponent var1) {
  890.       var1.registerKeyboardAction(new 6(this), KeyStroke.getKeyStroke(40, 0), 1);
  891.       var1.registerKeyboardAction(new 7(this), KeyStroke.getKeyStroke(38, 0), 1);
  892.       var1.registerKeyboardAction(new 8(this), KeyStroke.getKeyStroke(38, 8), 1);
  893.       var1.registerKeyboardAction(new 9(this), KeyStroke.getKeyStroke(40, 8), 1);
  894.    }
  895.  
  896.    protected void removeKeyAccelerators(JComponent var1) {
  897.       var1.unregisterKeyboardAction(KeyStroke.getKeyStroke(40, 0));
  898.       var1.unregisterKeyboardAction(KeyStroke.getKeyStroke(38, 0));
  899.       var1.unregisterKeyboardAction(KeyStroke.getKeyStroke(40, 8));
  900.       var1.unregisterKeyboardAction(KeyStroke.getKeyStroke(38, 8));
  901.    }
  902.  
  903.    protected static void requestFocusLaterForComponent(Component var0) {
  904.       new FocusRequestHelper(var0);
  905.    }
  906. }
  907.