home *** CD-ROM | disk | FTP | other *** search
- package javax.swing;
-
- import java.awt.AWTEvent;
- import java.awt.Component;
- import java.awt.EventQueue;
- import java.awt.ItemSelectable;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.InputEvent;
- import java.awt.event.ItemEvent;
- import java.awt.event.ItemListener;
- import java.awt.event.KeyEvent;
- import java.beans.PropertyChangeListener;
- import java.io.IOException;
- import java.io.ObjectOutputStream;
- import java.util.Vector;
- import javax.accessibility.Accessible;
- import javax.accessibility.AccessibleContext;
- import javax.swing.event.ListDataEvent;
- import javax.swing.event.ListDataListener;
- import javax.swing.event.PopupMenuEvent;
- import javax.swing.event.PopupMenuListener;
- import javax.swing.plaf.ComboBoxUI;
- import javax.swing.plaf.UIResource;
-
- public class JComboBox extends JComponent implements ItemSelectable, ListDataListener, ActionListener, Accessible {
- private static final String uiClassID = "ComboBoxUI";
- protected ComboBoxModel dataModel;
- protected ListCellRenderer renderer;
- protected ComboBoxEditor editor;
- protected int maximumRowCount = 8;
- protected boolean isEditable = false;
- protected KeySelectionManager keySelectionManager = null;
- protected String actionCommand = "comboBoxChanged";
- protected boolean lightWeightPopupEnabled = JPopupMenu.getDefaultLightWeightPopupEnabled();
- protected Object selectedItemReminder = null;
- private Object prototypeDisplayValue;
- private boolean firingActionEvent = false;
- private boolean selectingItem = false;
- private Action action;
- private PropertyChangeListener actionPropertyChangeListener;
-
- public JComboBox(ComboBoxModel var1) {
- this.setModel(var1);
- this.init();
- }
-
- public JComboBox(Object[] var1) {
- this.setModel(new DefaultComboBoxModel(var1));
- this.init();
- }
-
- public JComboBox(Vector<?> var1) {
- this.setModel(new DefaultComboBoxModel(var1));
- this.init();
- }
-
- public JComboBox() {
- this.setModel(new DefaultComboBoxModel());
- this.init();
- }
-
- private void init() {
- this.installAncestorListener();
- this.setOpaque(true);
- this.updateUI();
- }
-
- protected void installAncestorListener() {
- this.addAncestorListener(new 1(this));
- }
-
- public void setUI(ComboBoxUI var1) {
- super.setUI(var1);
- }
-
- public void updateUI() {
- this.setUI((ComboBoxUI)UIManager.getUI(this));
- ListCellRenderer var1 = this.getRenderer();
- if (!(var1 instanceof UIResource) && var1 instanceof Component) {
- SwingUtilities.updateComponentTreeUI((Component)var1);
- }
-
- }
-
- public String getUIClassID() {
- return "ComboBoxUI";
- }
-
- public ComboBoxUI getUI() {
- return (ComboBoxUI)this.ui;
- }
-
- public void setModel(ComboBoxModel var1) {
- ComboBoxModel var2 = this.dataModel;
- if (var2 != null) {
- var2.removeListDataListener(this);
- }
-
- this.dataModel = var1;
- this.dataModel.addListDataListener(this);
- this.selectedItemReminder = this.dataModel.getSelectedItem();
- this.firePropertyChange("model", var2, this.dataModel);
- }
-
- public ComboBoxModel getModel() {
- return this.dataModel;
- }
-
- public void setLightWeightPopupEnabled(boolean var1) {
- boolean var2 = this.lightWeightPopupEnabled;
- this.lightWeightPopupEnabled = var1;
- this.firePropertyChange("lightWeightPopupEnabled", var2, this.lightWeightPopupEnabled);
- }
-
- public boolean isLightWeightPopupEnabled() {
- return this.lightWeightPopupEnabled;
- }
-
- public void setEditable(boolean var1) {
- boolean var2 = this.isEditable;
- this.isEditable = var1;
- this.firePropertyChange("editable", var2, this.isEditable);
- }
-
- public boolean isEditable() {
- return this.isEditable;
- }
-
- public void setMaximumRowCount(int var1) {
- int var2 = this.maximumRowCount;
- this.maximumRowCount = var1;
- this.firePropertyChange("maximumRowCount", var2, this.maximumRowCount);
- }
-
- public int getMaximumRowCount() {
- return this.maximumRowCount;
- }
-
- public void setRenderer(ListCellRenderer var1) {
- ListCellRenderer var2 = this.renderer;
- this.renderer = var1;
- this.firePropertyChange("renderer", var2, this.renderer);
- this.invalidate();
- }
-
- public ListCellRenderer getRenderer() {
- return this.renderer;
- }
-
- public void setEditor(ComboBoxEditor var1) {
- ComboBoxEditor var2 = this.editor;
- if (this.editor != null) {
- this.editor.removeActionListener(this);
- }
-
- this.editor = var1;
- if (this.editor != null) {
- this.editor.addActionListener(this);
- }
-
- this.firePropertyChange("editor", var2, this.editor);
- }
-
- public ComboBoxEditor getEditor() {
- return this.editor;
- }
-
- public void setSelectedItem(Object var1) {
- Object var2 = this.selectedItemReminder;
- Object var3 = var1;
- if (var2 == null || !var2.equals(var1)) {
- if (var1 != null && !this.isEditable()) {
- boolean var4 = false;
-
- for(int var5 = 0; var5 < this.dataModel.getSize(); ++var5) {
- Object var6 = this.dataModel.getElementAt(var5);
- if (var1.equals(var6)) {
- var4 = true;
- var3 = var6;
- break;
- }
- }
-
- if (!var4) {
- return;
- }
- }
-
- this.selectingItem = true;
- this.dataModel.setSelectedItem(var3);
- this.selectingItem = false;
- if (this.selectedItemReminder != this.dataModel.getSelectedItem()) {
- this.selectedItemChanged();
- }
- }
-
- this.fireActionEvent();
- }
-
- public Object getSelectedItem() {
- return this.dataModel.getSelectedItem();
- }
-
- public void setSelectedIndex(int var1) {
- int var2 = this.dataModel.getSize();
- if (var1 == -1) {
- this.setSelectedItem((Object)null);
- } else {
- if (var1 < -1 || var1 >= var2) {
- throw new IllegalArgumentException("setSelectedIndex: " + var1 + " out of bounds");
- }
-
- this.setSelectedItem(this.dataModel.getElementAt(var1));
- }
-
- }
-
- public int getSelectedIndex() {
- Object var1 = this.dataModel.getSelectedItem();
- int var2 = 0;
-
- for(int var3 = this.dataModel.getSize(); var2 < var3; ++var2) {
- Object var4 = this.dataModel.getElementAt(var2);
- if (var4 != null && var4.equals(var1)) {
- return var2;
- }
- }
-
- return -1;
- }
-
- public Object getPrototypeDisplayValue() {
- return this.prototypeDisplayValue;
- }
-
- public void setPrototypeDisplayValue(Object var1) {
- Object var2 = this.prototypeDisplayValue;
- this.prototypeDisplayValue = var1;
- this.firePropertyChange("prototypeDisplayValue", var2, var1);
- }
-
- public void addItem(Object var1) {
- this.checkMutableComboBoxModel();
- ((MutableComboBoxModel)this.dataModel).addElement(var1);
- }
-
- public void insertItemAt(Object var1, int var2) {
- this.checkMutableComboBoxModel();
- ((MutableComboBoxModel)this.dataModel).insertElementAt(var1, var2);
- }
-
- public void removeItem(Object var1) {
- this.checkMutableComboBoxModel();
- ((MutableComboBoxModel)this.dataModel).removeElement(var1);
- }
-
- public void removeItemAt(int var1) {
- this.checkMutableComboBoxModel();
- ((MutableComboBoxModel)this.dataModel).removeElementAt(var1);
- }
-
- public void removeAllItems() {
- this.checkMutableComboBoxModel();
- MutableComboBoxModel var1 = (MutableComboBoxModel)this.dataModel;
- int var2 = var1.getSize();
- if (var1 instanceof DefaultComboBoxModel) {
- ((DefaultComboBoxModel)var1).removeAllElements();
- } else {
- for(int var3 = 0; var3 < var2; ++var3) {
- Object var4 = var1.getElementAt(0);
- var1.removeElement(var4);
- }
- }
-
- this.selectedItemReminder = null;
- if (this.isEditable()) {
- this.editor.setItem((Object)null);
- }
-
- }
-
- void checkMutableComboBoxModel() {
- if (!(this.dataModel instanceof MutableComboBoxModel)) {
- throw new RuntimeException("Cannot use this method with a non-Mutable data model.");
- }
- }
-
- public void showPopup() {
- this.setPopupVisible(true);
- }
-
- public void hidePopup() {
- this.setPopupVisible(false);
- }
-
- public void setPopupVisible(boolean var1) {
- this.getUI().setPopupVisible(this, var1);
- }
-
- public boolean isPopupVisible() {
- return this.getUI().isPopupVisible(this);
- }
-
- public void addItemListener(ItemListener var1) {
- this.listenerList.add(ItemListener.class, var1);
- }
-
- public void removeItemListener(ItemListener var1) {
- this.listenerList.remove(ItemListener.class, var1);
- }
-
- public ItemListener[] getItemListeners() {
- return (ItemListener[])this.listenerList.getListeners(ItemListener.class);
- }
-
- public void addActionListener(ActionListener var1) {
- this.listenerList.add(ActionListener.class, var1);
- }
-
- public void removeActionListener(ActionListener var1) {
- if (var1 != null && this.getAction() == var1) {
- this.setAction((Action)null);
- } else {
- this.listenerList.remove(ActionListener.class, var1);
- }
-
- }
-
- public ActionListener[] getActionListeners() {
- return (ActionListener[])this.listenerList.getListeners(ActionListener.class);
- }
-
- public void addPopupMenuListener(PopupMenuListener var1) {
- this.listenerList.add(PopupMenuListener.class, var1);
- }
-
- public void removePopupMenuListener(PopupMenuListener var1) {
- this.listenerList.remove(PopupMenuListener.class, var1);
- }
-
- public PopupMenuListener[] getPopupMenuListeners() {
- return (PopupMenuListener[])this.listenerList.getListeners(PopupMenuListener.class);
- }
-
- public void firePopupMenuWillBecomeVisible() {
- Object[] var1 = this.listenerList.getListenerList();
- PopupMenuEvent var2 = null;
-
- for(int var3 = var1.length - 2; var3 >= 0; var3 -= 2) {
- if (var1[var3] == PopupMenuListener.class) {
- if (var2 == null) {
- var2 = new PopupMenuEvent(this);
- }
-
- ((PopupMenuListener)var1[var3 + 1]).popupMenuWillBecomeVisible(var2);
- }
- }
-
- }
-
- public void firePopupMenuWillBecomeInvisible() {
- Object[] var1 = this.listenerList.getListenerList();
- PopupMenuEvent var2 = null;
-
- for(int var3 = var1.length - 2; var3 >= 0; var3 -= 2) {
- if (var1[var3] == PopupMenuListener.class) {
- if (var2 == null) {
- var2 = new PopupMenuEvent(this);
- }
-
- ((PopupMenuListener)var1[var3 + 1]).popupMenuWillBecomeInvisible(var2);
- }
- }
-
- }
-
- public void firePopupMenuCanceled() {
- Object[] var1 = this.listenerList.getListenerList();
- PopupMenuEvent var2 = null;
-
- for(int var3 = var1.length - 2; var3 >= 0; var3 -= 2) {
- if (var1[var3] == PopupMenuListener.class) {
- if (var2 == null) {
- var2 = new PopupMenuEvent(this);
- }
-
- ((PopupMenuListener)var1[var3 + 1]).popupMenuCanceled(var2);
- }
- }
-
- }
-
- public void setActionCommand(String var1) {
- this.actionCommand = var1;
- }
-
- public String getActionCommand() {
- return this.actionCommand;
- }
-
- public void setAction(Action var1) {
- Action var2 = this.getAction();
- if (this.action == null || !this.action.equals(var1)) {
- this.action = var1;
- if (var2 != null) {
- this.removeActionListener(var2);
- var2.removePropertyChangeListener(this.actionPropertyChangeListener);
- this.actionPropertyChangeListener = null;
- }
-
- this.configurePropertiesFromAction(this.action);
- if (this.action != null) {
- if (!this.isListener(ActionListener.class, this.action)) {
- this.addActionListener(this.action);
- }
-
- this.actionPropertyChangeListener = this.createActionPropertyChangeListener(this.action);
- this.action.addPropertyChangeListener(this.actionPropertyChangeListener);
- }
-
- this.firePropertyChange("action", var2, this.action);
- }
-
- }
-
- private boolean isListener(Class var1, ActionListener var2) {
- boolean var3 = false;
- Object[] var4 = this.listenerList.getListenerList();
-
- for(int var5 = var4.length - 2; var5 >= 0; var5 -= 2) {
- if (var4[var5] == var1 && var4[var5 + 1] == var2) {
- var3 = true;
- }
- }
-
- return var3;
- }
-
- public Action getAction() {
- return this.action;
- }
-
- protected void configurePropertiesFromAction(Action var1) {
- AbstractAction.setEnabledFromAction(this, var1);
- AbstractAction.setToolTipTextFromAction(this, var1);
- this.setActionCommandFromAction(var1);
- }
-
- protected PropertyChangeListener createActionPropertyChangeListener(Action var1) {
- return new ComboBoxActionPropertyChangeListener(this, var1);
- }
-
- protected void actionPropertyChanged(Action var1, String var2) {
- if (var2 == "ActionCommandKey") {
- this.setActionCommandFromAction(var1);
- } else if (var2 == "enabled") {
- AbstractAction.setEnabledFromAction(this, var1);
- } else if ("ShortDescription" == var2) {
- AbstractAction.setToolTipTextFromAction(this, var1);
- }
-
- }
-
- private void setActionCommandFromAction(Action var1) {
- this.setActionCommand(var1 != null ? (String)var1.getValue("ActionCommandKey") : null);
- }
-
- protected void fireItemStateChanged(ItemEvent var1) {
- Object[] var2 = this.listenerList.getListenerList();
-
- for(int var3 = var2.length - 2; var3 >= 0; var3 -= 2) {
- if (var2[var3] == ItemListener.class) {
- ((ItemListener)var2[var3 + 1]).itemStateChanged(var1);
- }
- }
-
- }
-
- protected void fireActionEvent() {
- if (!this.firingActionEvent) {
- this.firingActionEvent = true;
- ActionEvent var1 = null;
- Object[] var2 = this.listenerList.getListenerList();
- long var3 = EventQueue.getMostRecentEventTime();
- int var5 = 0;
- AWTEvent var6 = EventQueue.getCurrentEvent();
- if (var6 instanceof InputEvent) {
- var5 = ((InputEvent)var6).getModifiers();
- } else if (var6 instanceof ActionEvent) {
- var5 = ((ActionEvent)var6).getModifiers();
- }
-
- for(int var7 = var2.length - 2; var7 >= 0; var7 -= 2) {
- if (var2[var7] == ActionListener.class) {
- if (var1 == null) {
- var1 = new ActionEvent(this, 1001, this.getActionCommand(), var3, var5);
- }
-
- ((ActionListener)var2[var7 + 1]).actionPerformed(var1);
- }
- }
-
- this.firingActionEvent = false;
- }
-
- }
-
- protected void selectedItemChanged() {
- if (this.selectedItemReminder != null) {
- this.fireItemStateChanged(new ItemEvent(this, 701, this.selectedItemReminder, 2));
- }
-
- this.selectedItemReminder = this.dataModel.getSelectedItem();
- if (this.selectedItemReminder != null) {
- this.fireItemStateChanged(new ItemEvent(this, 701, this.selectedItemReminder, 1));
- }
-
- }
-
- public Object[] getSelectedObjects() {
- Object var1 = this.getSelectedItem();
- if (var1 == null) {
- return new Object[0];
- } else {
- Object[] var2 = new Object[]{var1};
- return var2;
- }
- }
-
- public void actionPerformed(ActionEvent var1) {
- Object var2 = this.getEditor().getItem();
- this.setPopupVisible(false);
- this.getModel().setSelectedItem(var2);
- String var3 = this.getActionCommand();
- this.setActionCommand("comboBoxEdited");
- this.fireActionEvent();
- this.setActionCommand(var3);
- }
-
- public void contentsChanged(ListDataEvent var1) {
- Object var2 = this.selectedItemReminder;
- Object var3 = this.dataModel.getSelectedItem();
- if (var2 == null || !var2.equals(var3)) {
- this.selectedItemChanged();
- if (!this.selectingItem) {
- this.fireActionEvent();
- }
- }
-
- }
-
- public void intervalAdded(ListDataEvent var1) {
- if (this.selectedItemReminder != this.dataModel.getSelectedItem()) {
- this.selectedItemChanged();
- }
-
- }
-
- public void intervalRemoved(ListDataEvent var1) {
- this.contentsChanged(var1);
- }
-
- public boolean selectWithKeyChar(char var1) {
- if (this.keySelectionManager == null) {
- this.keySelectionManager = this.createDefaultKeySelectionManager();
- }
-
- int var2 = this.keySelectionManager.selectionForKey(var1, this.getModel());
- if (var2 != -1) {
- this.setSelectedIndex(var2);
- return true;
- } else {
- return false;
- }
- }
-
- public void setEnabled(boolean var1) {
- super.setEnabled(var1);
- this.firePropertyChange("enabled", !this.isEnabled(), this.isEnabled());
- }
-
- public void configureEditor(ComboBoxEditor var1, Object var2) {
- var1.setItem(var2);
- }
-
- public void processKeyEvent(KeyEvent var1) {
- if (var1.getKeyCode() == 9) {
- this.hidePopup();
- }
-
- super.processKeyEvent(var1);
- }
-
- public void setKeySelectionManager(KeySelectionManager var1) {
- this.keySelectionManager = var1;
- }
-
- public KeySelectionManager getKeySelectionManager() {
- return this.keySelectionManager;
- }
-
- public int getItemCount() {
- return this.dataModel.getSize();
- }
-
- public Object getItemAt(int var1) {
- return this.dataModel.getElementAt(var1);
- }
-
- protected KeySelectionManager createDefaultKeySelectionManager() {
- return new DefaultKeySelectionManager(this);
- }
-
- private void writeObject(ObjectOutputStream var1) throws IOException {
- var1.defaultWriteObject();
- if (this.getUIClassID().equals("ComboBoxUI")) {
- byte var2 = JComponent.getWriteObjCounter(this);
- --var2;
- JComponent.setWriteObjCounter(this, var2);
- if (var2 == 0 && this.ui != null) {
- this.ui.installUI(this);
- }
- }
-
- }
-
- protected String paramString() {
- String var1 = this.selectedItemReminder != null ? this.selectedItemReminder.toString() : "";
- String var2 = this.isEditable ? "true" : "false";
- String var3 = this.lightWeightPopupEnabled ? "true" : "false";
- return super.paramString() + ",isEditable=" + var2 + ",lightWeightPopupEnabled=" + var3 + ",maximumRowCount=" + this.maximumRowCount + ",selectedItemReminder=" + var1;
- }
-
- public AccessibleContext getAccessibleContext() {
- if (this.accessibleContext == null) {
- this.accessibleContext = new AccessibleJComboBox(this);
- }
-
- return this.accessibleContext;
- }
- }
-