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

  1. package com.sun.java.swing.plaf.metal;
  2.  
  3. import com.sun.java.swing.AbstractButton;
  4. import com.sun.java.swing.Icon;
  5. import com.sun.java.swing.JButton;
  6. import com.sun.java.swing.JComboBox;
  7. import com.sun.java.swing.JComponent;
  8. import com.sun.java.swing.ListCellRenderer;
  9. import com.sun.java.swing.UIManager;
  10. import com.sun.java.swing.plaf.basic.BasicComboBoxUI;
  11. import java.awt.Component;
  12. import java.awt.Dimension;
  13. import java.awt.Graphics;
  14. import java.awt.Insets;
  15.  
  16. public class MetalComboBoxButton extends JButton {
  17.    protected JComboBox comboBox;
  18.    protected Icon comboIcon;
  19.    protected boolean iconOnly;
  20.    protected boolean forceDrawFocus;
  21.  
  22.    public final JComboBox getComboBox() {
  23.       return this.comboBox;
  24.    }
  25.  
  26.    public final void setComboBox(JComboBox var1) {
  27.       this.comboBox = var1;
  28.    }
  29.  
  30.    public final Icon getComboIcon() {
  31.       return this.comboIcon;
  32.    }
  33.  
  34.    public final void setComboIcon(Icon var1) {
  35.       this.comboIcon = var1;
  36.    }
  37.  
  38.    MetalComboBoxButton() {
  39.       super("");
  40.       this.iconOnly = false;
  41.       this.forceDrawFocus = false;
  42.    }
  43.  
  44.    public MetalComboBoxButton(JComboBox var1, Icon var2) {
  45.       super("");
  46.       this.iconOnly = false;
  47.       this.forceDrawFocus = false;
  48.       this.comboBox = var1;
  49.       this.comboIcon = var2;
  50.    }
  51.  
  52.    public MetalComboBoxButton(JComboBox var1, Icon var2, boolean var3) {
  53.       this(var1, var2);
  54.       this.iconOnly = var3;
  55.    }
  56.  
  57.    public Insets getInsets() {
  58.       return this.comboBox != null ? this.comboBox.getInsets() : new Insets(0, 0, 0, 0);
  59.    }
  60.  
  61.    public void paint(Graphics var1) {
  62.       super.paint(var1);
  63.       Dimension var2 = ((Component)this).getSize();
  64.       Insets var3 = this.getInsets();
  65.       var2.width -= var3.left + var3.right;
  66.       var2.height -= var3.top + var3.bottom;
  67.       int var4 = var3.left + var2.width;
  68.       if (this.comboIcon != null) {
  69.          int var5 = this.comboIcon.getIconWidth();
  70.          byte var6 = 8;
  71.          if (this.iconOnly) {
  72.             var4 = var3.left + var2.width / 2 - var5 / 2;
  73.          } else {
  74.             var4 -= var5 + var6;
  75.          }
  76.  
  77.          int var7 = this.comboIcon.getIconHeight();
  78.          int var8 = var3.top + var2.height / 2 - var7 / 2;
  79.          this.comboIcon.paintIcon(this, var1, var4, var8);
  80.       }
  81.  
  82.       if (!this.iconOnly && this.comboBox != null) {
  83.          MetalComboBoxUI var9 = (MetalComboBoxUI)this.comboBox.getUI();
  84.          ListCellRenderer var10 = this.comboBox.getRenderer();
  85.          ((BasicComboBoxUI)var9).validateMenu();
  86.          boolean var12 = ((AbstractButton)this).getModel().isPressed();
  87.          Component var11 = var10.getListCellRendererComponent(((BasicComboBoxUI)var9).getList(), this.comboBox.getSelectedItem(), -1, var12, false);
  88.          var11.setFont(var9.getCurrentValuePane().getFont());
  89.          if (super.model.isArmed() && super.model.isPressed()) {
  90.             if (((JComponent)this).isOpaque()) {
  91.                var11.setBackground(UIManager.getColor("Button.pressed"));
  92.             }
  93.          } else {
  94.             var11.setBackground(this.comboBox.getBackground());
  95.          }
  96.  
  97.          var11.setForeground(this.comboBox.getForeground());
  98.          var9.getCurrentValuePane().paintComponent(var1, var11, this, var3.left + 4, var3.top + 4, var4 - 8 - var3.left, var3.top + var2.height - 8);
  99.       }
  100.  
  101.    }
  102.  
  103.    public boolean hasFocus() {
  104.       return this.comboBox.isEditable() ? super.hasFocus() : this.forceDrawFocus;
  105.    }
  106.  
  107.    public void forceDrawFocus(boolean var1) {
  108.       this.forceDrawFocus = var1;
  109.    }
  110.  
  111.    public boolean isFocusTraversable() {
  112.       return this.comboBox.isEditable();
  113.    }
  114.  
  115.    public void requestFocus() {
  116.    }
  117.  
  118.    public void updateUI() {
  119.       ((AbstractButton)this).setUI(new MetalComboBoxButtonUI(this, this));
  120.    }
  121. }
  122.