home *** CD-ROM | disk | FTP | other *** search
- package javax.swing;
-
- import java.awt.AWTEvent;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Dimension;
- import java.awt.Frame;
- import java.awt.Graphics;
- import java.awt.Insets;
- import java.awt.Point;
- import java.awt.event.InputEvent;
- import java.awt.event.KeyEvent;
- import java.awt.event.MouseEvent;
- import java.beans.PropertyChangeListener;
- import java.io.IOException;
- import java.io.ObjectInputStream;
- import java.io.ObjectOutputStream;
- import java.io.Serializable;
- import java.util.Vector;
- import javax.accessibility.Accessible;
- import javax.accessibility.AccessibleContext;
- import javax.accessibility.AccessibleState;
- import javax.swing.event.PopupMenuEvent;
- import javax.swing.event.PopupMenuListener;
- import javax.swing.plaf.PopupMenuUI;
-
- public class JPopupMenu extends JComponent implements Accessible, MenuElement {
- private static final String uiClassID = "PopupMenuUI";
- private static final Object defaultLWPopupEnabledKey = new StringBuffer("JPopupMenu.defaultLWPopupEnabledKey");
- transient Component invoker;
- transient Popup popup;
- transient Frame frame;
- private int desiredLocationX;
- private int desiredLocationY;
- private static PopupFactory popupFactory = new DefaultPopupFactory();
- private String label;
- private boolean paintBorder;
- private Insets margin;
- private boolean lightWeightPopupEnabled;
- private SingleSelectionModel selectionModel;
- private static final Object classLock = new Object();
- private static final boolean TRACE = false;
- private static final boolean VERBOSE = false;
- private static final boolean DEBUG = false;
- private boolean receivedKeyPressed;
- // $FF: synthetic field
- static Class class$javax$swing$event$PopupMenuListener;
-
- public static void setDefaultLightWeightPopupEnabled(boolean var0) {
- SwingUtilities.appContextPut(defaultLWPopupEnabledKey, new Boolean(var0));
- }
-
- public static boolean getDefaultLightWeightPopupEnabled() {
- Boolean var0 = (Boolean)SwingUtilities.appContextGet(defaultLWPopupEnabledKey);
- if (var0 == null) {
- SwingUtilities.appContextPut(defaultLWPopupEnabledKey, Boolean.TRUE);
- return true;
- } else {
- return var0;
- }
- }
-
- public JPopupMenu() {
- this((String)null);
- }
-
- public JPopupMenu(String var1) {
- this.label = null;
- this.paintBorder = true;
- this.margin = null;
- this.lightWeightPopupEnabled = true;
- this.label = var1;
- this.lightWeightPopupEnabled = getDefaultLightWeightPopupEnabled();
- this.setSelectionModel(new DefaultSingleSelectionModel());
- ((Component)this).addMouseListener(new 1(this));
- this.updateUI();
- }
-
- public PopupMenuUI getUI() {
- return (PopupMenuUI)super.ui;
- }
-
- public void setUI(PopupMenuUI var1) {
- super.setUI(var1);
- }
-
- public void updateUI() {
- this.setUI((PopupMenuUI)UIManager.getUI(this));
- }
-
- public String getUIClassID() {
- return "PopupMenuUI";
- }
-
- protected void processKeyEvent(KeyEvent var1) {
- boolean var2 = false;
- switch (((AWTEvent)var1).getID()) {
- case 401:
- var2 = this.receivedKeyPressed = true;
- break;
- case 402:
- if (this.receivedKeyPressed) {
- this.receivedKeyPressed = false;
- var2 = true;
- }
- break;
- default:
- var2 = this.receivedKeyPressed;
- }
-
- if (var2) {
- MenuSelectionManager.defaultManager().processKeyEvent(var1);
- }
-
- if (!((InputEvent)var1).isConsumed()) {
- if (var1.getKeyCode() != 9 && var1.getKeyChar() != '\t') {
- super.processKeyEvent(var1);
- } else {
- ((InputEvent)var1).consume();
- }
- }
- }
-
- public SingleSelectionModel getSelectionModel() {
- return this.selectionModel;
- }
-
- public void setSelectionModel(SingleSelectionModel var1) {
- this.selectionModel = var1;
- }
-
- public JMenuItem add(JMenuItem var1) {
- super.add(var1);
- return var1;
- }
-
- public JMenuItem add(String var1) {
- return this.add(new JMenuItem(var1));
- }
-
- public JMenuItem add(Action var1) {
- JMenuItem var2 = this.createActionComponent(var1);
- ((AbstractButton)var2).setAction(var1);
- this.add(var2);
- return var2;
- }
-
- protected JMenuItem createActionComponent(Action var1) {
- 2 var2 = new 2(this, (String)var1.getValue("Name"), (Icon)var1.getValue("SmallIcon"));
- ((AbstractButton)var2).setHorizontalTextPosition(4);
- ((AbstractButton)var2).setVerticalTextPosition(0);
- ((JMenuItem)var2).setEnabled(var1.isEnabled());
- return var2;
- }
-
- protected PropertyChangeListener createActionChangeListener(JMenuItem var1) {
- return new ActionChangedListener(this, var1);
- }
-
- public void remove(int var1) {
- if (var1 < 0) {
- throw new IllegalArgumentException("index less than zero.");
- } else if (var1 > ((Container)this).getComponentCount() - 1) {
- throw new IllegalArgumentException("index greater than the number of items.");
- } else {
- super.remove(var1);
- }
- }
-
- public void setLightWeightPopupEnabled(boolean var1) {
- this.lightWeightPopupEnabled = var1;
- }
-
- public boolean isLightWeightPopupEnabled() {
- return this.lightWeightPopupEnabled;
- }
-
- public String getLabel() {
- return this.label;
- }
-
- public void setLabel(String var1) {
- String var2 = this.label;
- this.label = var1;
- ((JComponent)this).firePropertyChange("label", var2, var1);
- if (super.accessibleContext != null) {
- super.accessibleContext.firePropertyChange("AccessibleVisibleData", var2, var1);
- }
-
- ((Container)this).invalidate();
- ((Component)this).repaint();
- }
-
- public void addSeparator() {
- ((Container)this).add(new Separator());
- }
-
- public void insert(Action var1, int var2) {
- JMenuItem var3 = this.createActionComponent(var1);
- ((AbstractButton)var3).setAction(var1);
- ((Container)this).add(var3, var2);
- }
-
- public void insert(Component var1, int var2) {
- if (var2 < 0) {
- throw new IllegalArgumentException("index less than zero.");
- } else {
- int var3 = ((Container)this).getComponentCount();
- Vector var4 = new Vector();
-
- for(int var5 = var2; var5 < var3; ++var5) {
- var4.addElement(((Container)this).getComponent(var2));
- this.remove(var2);
- }
-
- ((Container)this).add(var1);
-
- for(int var6 = 0; var6 < var4.size(); ++var6) {
- ((Container)this).add((Component)var4.elementAt(var6));
- }
-
- }
- }
-
- public void addPopupMenuListener(PopupMenuListener var1) {
- super.listenerList.add(class$javax$swing$event$PopupMenuListener == null ? (class$javax$swing$event$PopupMenuListener = class$("javax.swing.event.PopupMenuListener")) : class$javax$swing$event$PopupMenuListener, var1);
- }
-
- public void removePopupMenuListener(PopupMenuListener var1) {
- super.listenerList.remove(class$javax$swing$event$PopupMenuListener == null ? (class$javax$swing$event$PopupMenuListener = class$("javax.swing.event.PopupMenuListener")) : class$javax$swing$event$PopupMenuListener, var1);
- }
-
- protected void firePopupMenuWillBecomeVisible() {
- Object[] var1 = super.listenerList.getListenerList();
- PopupMenuEvent var2 = null;
-
- for(int var3 = var1.length - 2; var3 >= 0; var3 -= 2) {
- if (var1[var3] == (class$javax$swing$event$PopupMenuListener == null ? (class$javax$swing$event$PopupMenuListener = class$("javax.swing.event.PopupMenuListener")) : class$javax$swing$event$PopupMenuListener)) {
- if (var2 == null) {
- var2 = new PopupMenuEvent(this);
- }
-
- ((PopupMenuListener)var1[var3 + 1]).popupMenuWillBecomeVisible(var2);
- }
- }
-
- }
-
- protected void firePopupMenuWillBecomeInvisible() {
- Object[] var1 = super.listenerList.getListenerList();
- PopupMenuEvent var2 = null;
-
- for(int var3 = var1.length - 2; var3 >= 0; var3 -= 2) {
- if (var1[var3] == (class$javax$swing$event$PopupMenuListener == null ? (class$javax$swing$event$PopupMenuListener = class$("javax.swing.event.PopupMenuListener")) : class$javax$swing$event$PopupMenuListener)) {
- if (var2 == null) {
- var2 = new PopupMenuEvent(this);
- }
-
- ((PopupMenuListener)var1[var3 + 1]).popupMenuWillBecomeInvisible(var2);
- }
- }
-
- }
-
- protected void firePopupMenuCanceled() {
- Object[] var1 = super.listenerList.getListenerList();
- PopupMenuEvent var2 = null;
-
- for(int var3 = var1.length - 2; var3 >= 0; var3 -= 2) {
- if (var1[var3] == (class$javax$swing$event$PopupMenuListener == null ? (class$javax$swing$event$PopupMenuListener = class$("javax.swing.event.PopupMenuListener")) : class$javax$swing$event$PopupMenuListener)) {
- if (var2 == null) {
- var2 = new PopupMenuEvent(this);
- }
-
- ((PopupMenuListener)var1[var3 + 1]).popupMenuCanceled(var2);
- }
- }
-
- }
-
- boolean alwaysOnTop() {
- return true;
- }
-
- public void pack() {
- if (this.popup != null) {
- this.popup.pack();
- }
-
- }
-
- public void setVisible(boolean var1) {
- if (var1 != this.isVisible()) {
- if (!var1) {
- this.getSelectionModel().clearSelection();
- } else if (this.isPopupMenu()) {
- if (this.getSubElements().length > 0) {
- MenuElement[] var2 = new MenuElement[]{this, this.getSubElements()[0]};
- MenuSelectionManager.defaultManager().setSelectedPath(var2);
- } else {
- MenuElement[] var3 = new MenuElement[]{this};
- MenuSelectionManager.defaultManager().setSelectedPath(var3);
- }
- }
-
- if (var1) {
- this.firePopupMenuWillBecomeVisible();
- this.popup = popupFactory.getPopup(this, this.invoker, this.desiredLocationX, this.desiredLocationY);
- this.popup.show(this.invoker);
- } else if (this.popup != null) {
- this.firePopupMenuWillBecomeInvisible();
- this.popup.hide();
- this.popup.removeComponent(this);
- this.popup = null;
- }
-
- if (super.accessibleContext != null) {
- if (var1) {
- super.accessibleContext.firePropertyChange("AccessibleState", (Object)null, AccessibleState.VISIBLE);
- } else {
- super.accessibleContext.firePropertyChange("AccessibleState", AccessibleState.VISIBLE, (Object)null);
- }
- }
-
- }
- }
-
- public boolean isVisible() {
- return this.popup != null;
- }
-
- public void setLocation(int var1, int var2) {
- if (this.popup != null) {
- this.popup.setLocationOnScreen(var1, var2);
- } else {
- this.desiredLocationX = var1;
- this.desiredLocationY = var2;
- }
-
- }
-
- private boolean isPopupMenu() {
- return this.invoker != null && !(this.invoker instanceof JMenu);
- }
-
- public Component getInvoker() {
- return this.invoker;
- }
-
- public void setInvoker(Component var1) {
- Component var2 = this.invoker;
- this.invoker = var1;
- if (var2 != this.invoker && super.ui != null) {
- super.ui.uninstallUI(this);
- super.ui.installUI(this);
- }
-
- ((Container)this).invalidate();
- }
-
- public void show(Component var1, int var2, int var3) {
- this.setInvoker(var1);
- Frame var4 = getFrame(var1);
- if (var4 != this.frame && var4 != null) {
- this.frame = var4;
- if (this.popup != null) {
- this.setVisible(false);
- }
- }
-
- if (var1 != null) {
- Point var5 = var1.getLocationOnScreen();
- this.setLocation(var5.x + var2, var5.y + var3);
- } else {
- this.setLocation(var2, var3);
- }
-
- this.setVisible(true);
- }
-
- JPopupMenu getRootPopupMenu() {
- JPopupMenu var1;
- for(var1 = this; var1 != null && !var1.isPopupMenu() && var1.getInvoker() != null && var1.getInvoker().getParent() != null && var1.getInvoker().getParent() instanceof JPopupMenu; var1 = (JPopupMenu)var1.getInvoker().getParent()) {
- }
-
- return var1;
- }
-
- public Component getComponentAtIndex(int var1) {
- return ((Container)this).getComponent(var1);
- }
-
- public int getComponentIndex(Component var1) {
- int var2 = ((Container)this).getComponentCount();
- Component[] var3 = ((Container)this).getComponents();
-
- for(int var4 = 0; var4 < var2; ++var4) {
- Component var5 = var3[var4];
- if (var5 == var1) {
- return var4;
- }
- }
-
- return -1;
- }
-
- public void setPopupSize(Dimension var1) {
- if (this.popup != null) {
- this.popup.setSize(var1.width, var1.height);
- }
-
- }
-
- public void setPopupSize(int var1, int var2) {
- this.setPopupSize(new Dimension(var1, var2));
- }
-
- public void setSelected(Component var1) {
- SingleSelectionModel var2 = this.getSelectionModel();
- int var3 = this.getComponentIndex(var1);
- var2.setSelectedIndex(var3);
- }
-
- public boolean isBorderPainted() {
- return this.paintBorder;
- }
-
- public void setBorderPainted(boolean var1) {
- this.paintBorder = var1;
- ((Component)this).repaint();
- }
-
- protected void paintBorder(Graphics var1) {
- if (this.isBorderPainted()) {
- super.paintBorder(var1);
- }
-
- }
-
- public Insets getMargin() {
- return this.margin == null ? new Insets(0, 0, 0, 0) : this.margin;
- }
-
- boolean isSubPopupMenu(JPopupMenu var1) {
- int var2 = ((Container)this).getComponentCount();
- Component[] var3 = ((Container)this).getComponents();
-
- for(int var4 = 0; var4 < var2; ++var4) {
- Component var5 = var3[var4];
- if (var5 instanceof JMenu) {
- JMenu var6 = (JMenu)var5;
- JPopupMenu var7 = var6.getPopupMenu();
- if (var7 == var1) {
- return true;
- }
-
- if (var7.isSubPopupMenu(var1)) {
- return true;
- }
- }
- }
-
- return false;
- }
-
- private static Frame getFrame(Component var0) {
- Object var1;
- for(var1 = var0; !(var1 instanceof Frame) && var1 != null; var1 = ((Component)var1).getParent()) {
- }
-
- return (Frame)var1;
- }
-
- protected String paramString() {
- String var1 = this.label != null ? this.label : "";
- String var2 = this.paintBorder ? "true" : "false";
- String var3 = this.margin != null ? this.margin.toString() : "";
- String var4 = this.isLightWeightPopupEnabled() ? "true" : "false";
- return super.paramString() + ",desiredLocationX=" + this.desiredLocationX + ",desiredLocationY=" + this.desiredLocationY + ",label=" + var1 + ",lightWeightPopupEnabled=" + var4 + ",margin=" + var3 + ",paintBorder=" + var2;
- }
-
- public AccessibleContext getAccessibleContext() {
- if (super.accessibleContext == null) {
- super.accessibleContext = new AccessibleJPopupMenu(this);
- }
-
- return super.accessibleContext;
- }
-
- private void writeObject(ObjectOutputStream var1) throws IOException {
- Vector var2 = new Vector();
- var1.defaultWriteObject();
- if (this.invoker != null && this.invoker instanceof Serializable) {
- var2.addElement("invoker");
- var2.addElement(this.invoker);
- }
-
- if (this.popup != null && this.popup instanceof Serializable) {
- var2.addElement("popup");
- var2.addElement(this.popup);
- }
-
- if (this.frame != null && this.frame instanceof Serializable) {
- var2.addElement("frame");
- var2.addElement(this.frame);
- }
-
- var1.writeObject(var2);
- if (super.ui != null && this.getUIClassID().equals("PopupMenuUI")) {
- super.ui.installUI(this);
- }
-
- }
-
- private void readObject(ObjectInputStream var1) throws IOException, ClassNotFoundException {
- var1.defaultReadObject();
- Vector var2 = (Vector)var1.readObject();
- int var3 = 0;
- int var4 = var2.size();
- if (var3 < var4 && var2.elementAt(var3).equals("invoker")) {
- ++var3;
- this.invoker = (Component)var2.elementAt(var3);
- ++var3;
- }
-
- if (var3 < var4 && var2.elementAt(var3).equals("popup")) {
- ++var3;
- this.popup = (Popup)var2.elementAt(var3);
- ++var3;
- }
-
- if (var3 < var4 && var2.elementAt(var3).equals("frame")) {
- ++var3;
- this.frame = (Frame)var2.elementAt(var3);
- ++var3;
- }
-
- }
-
- public void processMouseEvent(MouseEvent var1, MenuElement[] var2, MenuSelectionManager var3) {
- }
-
- public void processKeyEvent(KeyEvent var1, MenuElement[] var2, MenuSelectionManager var3) {
- }
-
- public void menuSelectionChanged(boolean var1) {
- if (this.invoker instanceof JMenu) {
- JMenu var2 = (JMenu)this.invoker;
- if (var1) {
- var2.setPopupMenuVisible(true);
- } else {
- var2.setPopupMenuVisible(false);
- }
- }
-
- if (this.isPopupMenu() && !var1) {
- this.setVisible(false);
- }
-
- }
-
- public MenuElement[] getSubElements() {
- Vector var2 = new Vector();
- int var3 = ((Container)this).getComponentCount();
-
- for(int var4 = 0; var4 < var3; ++var4) {
- Component var5 = ((Container)this).getComponent(var4);
- if (var5 instanceof MenuElement) {
- var2.addElement(var5);
- }
- }
-
- MenuElement[] var1 = new MenuElement[var2.size()];
- int var7 = 0;
-
- for(int var6 = var2.size(); var7 < var6; ++var7) {
- var1[var7] = (MenuElement)var2.elementAt(var7);
- }
-
- return var1;
- }
-
- public Component getComponent() {
- return this;
- }
-
- public boolean isPopupTrigger(MouseEvent var1) {
- return this.getUI().isPopupTrigger(var1);
- }
-
- static void setPopupFactory(PopupFactory var0) {
- popupFactory = var0;
- }
-
- // $FF: synthetic method
- static Class class$(String var0) {
- try {
- return Class.forName(var0);
- } catch (ClassNotFoundException var2) {
- throw new NoClassDefFoundError(((Throwable)var2).getMessage());
- }
- }
- }
-