home *** CD-ROM | disk | FTP | other *** search
- package com.sun.java.swing.plaf.metal;
-
- import com.sun.java.swing.AbstractButton;
- import com.sun.java.swing.Icon;
- import com.sun.java.swing.JButton;
- import com.sun.java.swing.JComboBox;
- import com.sun.java.swing.JComponent;
- import com.sun.java.swing.ListCellRenderer;
- import com.sun.java.swing.UIManager;
- import com.sun.java.swing.plaf.basic.BasicComboBoxUI;
- import java.awt.Component;
- import java.awt.Dimension;
- import java.awt.Graphics;
- import java.awt.Insets;
-
- public class MetalComboBoxButton extends JButton {
- protected JComboBox comboBox;
- protected Icon comboIcon;
- protected boolean iconOnly;
- protected boolean forceDrawFocus;
-
- public final JComboBox getComboBox() {
- return this.comboBox;
- }
-
- public final void setComboBox(JComboBox var1) {
- this.comboBox = var1;
- }
-
- public final Icon getComboIcon() {
- return this.comboIcon;
- }
-
- public final void setComboIcon(Icon var1) {
- this.comboIcon = var1;
- }
-
- MetalComboBoxButton() {
- super("");
- this.iconOnly = false;
- this.forceDrawFocus = false;
- }
-
- public MetalComboBoxButton(JComboBox var1, Icon var2) {
- super("");
- this.iconOnly = false;
- this.forceDrawFocus = false;
- this.comboBox = var1;
- this.comboIcon = var2;
- }
-
- public MetalComboBoxButton(JComboBox var1, Icon var2, boolean var3) {
- this(var1, var2);
- this.iconOnly = var3;
- }
-
- public Insets getInsets() {
- return this.comboBox != null ? this.comboBox.getInsets() : new Insets(0, 0, 0, 0);
- }
-
- public void paint(Graphics var1) {
- super.paint(var1);
- Dimension var2 = ((Component)this).getSize();
- Insets var3 = this.getInsets();
- var2.width -= var3.left + var3.right;
- var2.height -= var3.top + var3.bottom;
- int var4 = var3.left + var2.width;
- if (this.comboIcon != null) {
- int var5 = this.comboIcon.getIconWidth();
- byte var6 = 8;
- if (this.iconOnly) {
- var4 = var3.left + var2.width / 2 - var5 / 2;
- } else {
- var4 -= var5 + var6;
- }
-
- int var7 = this.comboIcon.getIconHeight();
- int var8 = var3.top + var2.height / 2 - var7 / 2;
- this.comboIcon.paintIcon(this, var1, var4, var8);
- }
-
- if (!this.iconOnly && this.comboBox != null) {
- MetalComboBoxUI var9 = (MetalComboBoxUI)this.comboBox.getUI();
- ListCellRenderer var10 = this.comboBox.getRenderer();
- ((BasicComboBoxUI)var9).validateMenu();
- boolean var12 = ((AbstractButton)this).getModel().isPressed();
- Component var11 = var10.getListCellRendererComponent(((BasicComboBoxUI)var9).getList(), this.comboBox.getSelectedItem(), -1, var12, false);
- var11.setFont(var9.getCurrentValuePane().getFont());
- if (super.model.isArmed() && super.model.isPressed()) {
- if (((JComponent)this).isOpaque()) {
- var11.setBackground(UIManager.getColor("Button.pressed"));
- }
- } else {
- var11.setBackground(this.comboBox.getBackground());
- }
-
- var11.setForeground(this.comboBox.getForeground());
- var9.getCurrentValuePane().paintComponent(var1, var11, this, var3.left + 4, var3.top + 4, var4 - 8 - var3.left, var3.top + var2.height - 8);
- }
-
- }
-
- public boolean hasFocus() {
- return this.comboBox.isEditable() ? super.hasFocus() : this.forceDrawFocus;
- }
-
- public void forceDrawFocus(boolean var1) {
- this.forceDrawFocus = var1;
- }
-
- public boolean isFocusTraversable() {
- return this.comboBox.isEditable();
- }
-
- public void requestFocus() {
- }
-
- public void updateUI() {
- ((AbstractButton)this).setUI(new MetalComboBoxButtonUI(this, this));
- }
- }
-