home *** CD-ROM | disk | FTP | other *** search
- package com.sun.java.swing.plaf.metal;
-
- import com.sun.java.swing.CellRendererPane;
- import com.sun.java.swing.JButton;
- import com.sun.java.swing.JComboBox;
- import com.sun.java.swing.JComponent;
- import com.sun.java.swing.JList;
- import com.sun.java.swing.KeyStroke;
- import com.sun.java.swing.SwingUtilities;
- import com.sun.java.swing.UIManager;
- import com.sun.java.swing.border.Border;
- import com.sun.java.swing.border.EmptyBorder;
- import com.sun.java.swing.plaf.BorderUIResource;
- import com.sun.java.swing.plaf.ComponentUI;
- import com.sun.java.swing.plaf.basic.BasicComboBoxUI;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Dimension;
- import java.awt.Font;
- import java.awt.Graphics;
- import java.awt.Point;
- import java.awt.Window;
- import java.awt.event.FocusEvent;
- import java.awt.event.MouseEvent;
- import java.util.EventObject;
-
- public class MetalComboBoxUI extends BasicComboBoxUI {
- protected MetalComboBoxButton button;
- protected MetalComboBoxButton arrowCache;
- private static Border emptyBorder = new BorderUIResource(new EmptyBorder(0, 0, 0, 0));
-
- public static ComponentUI createUI(JComponent var0) {
- return new MetalComboBoxUI();
- }
-
- public void installUI(JComponent var1) {
- super.installUI(var1);
- this.removeArrowButton();
- this.addArrowButton();
- if (super.editor != null) {
- Font var2 = ((Component)var1).getFont();
- super.editor.setFont(new Font(var2.getName(), var2.getStyle(), var2.getSize()));
- }
-
- }
-
- public void uninstallUI(JComponent var1) {
- if (this.button != null) {
- super.comboBox.remove(this.button);
- this.button = null;
- }
-
- JComboBox var2 = super.comboBox;
- super.uninstallUI(var1);
- ((Container)var2).removeAll();
- }
-
- public void paint(Graphics var1, JComponent var2) {
- }
-
- protected JButton createArrowButton() {
- MetalComboBoxButton var1 = new MetalComboBoxButton(super.comboBox, new MetalComboBoxIcon(), true);
- if (super.comboBox.isEditable()) {
- this.arrowCache = var1;
- }
-
- return var1;
- }
-
- public void layoutContainer(Container var1) {
- if (super.comboBox.isEditable()) {
- super.layoutContainer(var1);
- } else {
- if (this.button != null) {
- this.button.setSize(super.comboBox.getSize().width, super.comboBox.getSize().height);
- }
-
- }
- }
-
- public void editablePropertyChanged() {
- if (super.comboBox.isEditable()) {
- if (this.button != null) {
- super.comboBox.remove(this.button);
- this.button = null;
- }
-
- super.editablePropertyChanged();
- if (this.arrowCache != null) {
- super.comboBox.add(this.arrowCache);
- super.comboBox.repaint();
- } else if (super.arrowButton == null) {
- this.addArrowButton();
- }
-
- this.arrowCache = (MetalComboBoxButton)super.arrowButton;
- super.comboBox.setBorder(emptyBorder);
- } else {
- ((BasicComboBoxUI)this).removeEditor();
- if (super.arrowButton != null) {
- super.comboBox.remove(super.arrowButton);
- this.arrowCache = (MetalComboBoxButton)super.arrowButton;
- super.arrowButton = null;
- }
-
- if (this.button == null) {
- super.comboBox.getInsets();
- this.button = new MetalComboBoxButton(super.comboBox, new MetalComboBoxIcon());
- this.button.setLocation(0, 0);
- this.button.setSize(super.comboBox.getSize().width - 2, super.comboBox.getSize().height);
- }
-
- super.comboBox.add(this.button);
- }
- }
-
- protected void setupListBox(JList var1, JComboBox var2) {
- ((Component)var1).setFont(((Component)var2).getFont());
- ((Component)var1).setForeground(UIManager.getColor("ComboBox.listForeground"));
- ((Component)var1).setBackground(UIManager.getColor("ComboBox.listBackground"));
- var1.setSelectionForeground(UIManager.getColor("ComboBox.selectedForeground"));
- var1.setSelectionBackground(UIManager.getColor("ComboBox.selectedBackground"));
- }
-
- public void hidePopup() {
- super.hidePopup();
- if (this.arrowCache != null) {
- this.arrowCache.getModel().setPressed(false);
- this.arrowCache.repaint();
- }
-
- }
-
- public void focusGained(FocusEvent var1) {
- super.focusGained(var1);
- if (this.button != null) {
- this.button.forceDrawFocus(true);
- this.button.repaint();
- }
-
- }
-
- public void focusLost(FocusEvent var1) {
- super.focusLost(var1);
- if (this.button != null) {
- this.button.forceDrawFocus(false);
- this.button.repaint();
- }
-
- }
-
- public CellRendererPane getCurrentValuePane() {
- return super.currentValuePane;
- }
-
- public void addArrowButton() {
- super.arrowButton = this.createArrowButton();
- super.arrowButton.setRequestFocusEnabled(true);
- super.comboBox.add(super.arrowButton);
- super.comboBox.repaint();
- }
-
- public void removeArrowButton() {
- if (super.arrowButton != null) {
- super.comboBox.remove(super.arrowButton);
- super.arrowButton = null;
- }
-
- }
-
- public void mouseReleased(MouseEvent var1) {
- super.mouseReleased(var1);
- if (((EventObject)var1).getSource() == super.listBox && this.button != null) {
- this.button.getModel().setPressed(false);
- } else {
- if (((EventObject)var1).getSource() == super.listBox && super.arrowButton != null) {
- super.arrowButton.getModel().setPressed(false);
- }
-
- }
- }
-
- public void doMouseDragged(MouseEvent var1) {
- if (((BasicComboBoxUI)this).popupIsVisible()) {
- MouseEvent var3 = ((BasicComboBoxUI)this).convertEventToListBox(var1);
- ((BasicComboBoxUI)this).updateListBoxSelectionForEvent(var3, true);
- super.lastMouseLocation = SwingUtilities.convertPoint((Component)((EventObject)var1).getSource(), var1.getPoint(), (Component)null);
- Window var2 = SwingUtilities.windowForComponent((Component)((EventObject)var1).getSource());
- Point var10000 = super.lastMouseLocation;
- var10000.x += ((Component)var2).getBounds().x;
- var10000 = super.lastMouseLocation;
- var10000.y += ((Component)var2).getBounds().y;
- ((BasicComboBoxUI)this).startAutoscrolling();
- }
-
- }
-
- public Dimension getMaximumSize(JComponent var1) {
- Dimension var2 = super.getMaximumSize(var1);
- var2.height += 4;
- return var2;
- }
-
- public void doMouseReleased(MouseEvent var1) {
- ((BasicComboBoxUI)this).stopAutoscrolling();
- if (((BasicComboBoxUI)this).popupIsVisible()) {
- MouseEvent var3 = ((BasicComboBoxUI)this).convertEventToListBox(var1);
- ((BasicComboBoxUI)this).updateListBoxSelectionForEvent(var3, true);
- Object var2 = super.listBox.getSelectedValue();
- if (var2 != null) {
- super.comboBox.getModel().setSelectedItem(var2);
- }
-
- this.hidePopup();
- }
-
- }
-
- public void enablePropertyChanged() {
- if (this.button != null) {
- this.button.setEnabled(super.comboBox.isEnabled());
- }
-
- if (this.arrowCache != null) {
- this.arrowCache.setEnabled(super.comboBox.isEnabled());
- }
-
- super.enablePropertyChanged();
- }
-
- protected void addKeyAccelerators(JComponent var1) {
- JComboBox var2 = super.comboBox;
- super.addKeyAccelerators(var1);
- super.comboBox.registerKeyboardAction(new 1(var2, this), KeyStroke.getKeyStroke(32, 0), 0);
- }
-
- protected void removeKeyAccelerators(JComponent var1) {
- super.removeKeyAccelerators(var1);
- super.comboBox.unregisterKeyboardAction(KeyStroke.getKeyStroke(32, 0));
- }
- }
-