home *** CD-ROM | disk | FTP | other *** search
/ S283 Planetary Science &… the Search for Life CD 3 / 0_CD-ROM.iso / install / jre1_3 / lib / rt.jar / javax / swing / JPopupMenu.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  12.4 KB  |  604 lines

  1. package javax.swing;
  2.  
  3. import java.awt.AWTEvent;
  4. import java.awt.Component;
  5. import java.awt.Container;
  6. import java.awt.Dimension;
  7. import java.awt.Frame;
  8. import java.awt.Graphics;
  9. import java.awt.Insets;
  10. import java.awt.Point;
  11. import java.awt.event.InputEvent;
  12. import java.awt.event.KeyEvent;
  13. import java.awt.event.MouseEvent;
  14. import java.beans.PropertyChangeListener;
  15. import java.io.IOException;
  16. import java.io.ObjectInputStream;
  17. import java.io.ObjectOutputStream;
  18. import java.io.Serializable;
  19. import java.util.Vector;
  20. import javax.accessibility.Accessible;
  21. import javax.accessibility.AccessibleContext;
  22. import javax.accessibility.AccessibleState;
  23. import javax.swing.event.PopupMenuEvent;
  24. import javax.swing.event.PopupMenuListener;
  25. import javax.swing.plaf.PopupMenuUI;
  26.  
  27. public class JPopupMenu extends JComponent implements Accessible, MenuElement {
  28.    private static final String uiClassID = "PopupMenuUI";
  29.    private static final Object defaultLWPopupEnabledKey = new StringBuffer("JPopupMenu.defaultLWPopupEnabledKey");
  30.    transient Component invoker;
  31.    transient Popup popup;
  32.    transient Frame frame;
  33.    private int desiredLocationX;
  34.    private int desiredLocationY;
  35.    private static PopupFactory popupFactory = new DefaultPopupFactory();
  36.    private String label;
  37.    private boolean paintBorder;
  38.    private Insets margin;
  39.    private boolean lightWeightPopupEnabled;
  40.    private SingleSelectionModel selectionModel;
  41.    private static final Object classLock = new Object();
  42.    private static final boolean TRACE = false;
  43.    private static final boolean VERBOSE = false;
  44.    private static final boolean DEBUG = false;
  45.    private boolean receivedKeyPressed;
  46.    // $FF: synthetic field
  47.    static Class class$javax$swing$event$PopupMenuListener;
  48.  
  49.    public static void setDefaultLightWeightPopupEnabled(boolean var0) {
  50.       SwingUtilities.appContextPut(defaultLWPopupEnabledKey, new Boolean(var0));
  51.    }
  52.  
  53.    public static boolean getDefaultLightWeightPopupEnabled() {
  54.       Boolean var0 = (Boolean)SwingUtilities.appContextGet(defaultLWPopupEnabledKey);
  55.       if (var0 == null) {
  56.          SwingUtilities.appContextPut(defaultLWPopupEnabledKey, Boolean.TRUE);
  57.          return true;
  58.       } else {
  59.          return var0;
  60.       }
  61.    }
  62.  
  63.    public JPopupMenu() {
  64.       this((String)null);
  65.    }
  66.  
  67.    public JPopupMenu(String var1) {
  68.       this.label = null;
  69.       this.paintBorder = true;
  70.       this.margin = null;
  71.       this.lightWeightPopupEnabled = true;
  72.       this.label = var1;
  73.       this.lightWeightPopupEnabled = getDefaultLightWeightPopupEnabled();
  74.       this.setSelectionModel(new DefaultSingleSelectionModel());
  75.       ((Component)this).addMouseListener(new 1(this));
  76.       this.updateUI();
  77.    }
  78.  
  79.    public PopupMenuUI getUI() {
  80.       return (PopupMenuUI)super.ui;
  81.    }
  82.  
  83.    public void setUI(PopupMenuUI var1) {
  84.       super.setUI(var1);
  85.    }
  86.  
  87.    public void updateUI() {
  88.       this.setUI((PopupMenuUI)UIManager.getUI(this));
  89.    }
  90.  
  91.    public String getUIClassID() {
  92.       return "PopupMenuUI";
  93.    }
  94.  
  95.    protected void processKeyEvent(KeyEvent var1) {
  96.       boolean var2 = false;
  97.       switch (((AWTEvent)var1).getID()) {
  98.          case 401:
  99.             var2 = this.receivedKeyPressed = true;
  100.             break;
  101.          case 402:
  102.             if (this.receivedKeyPressed) {
  103.                this.receivedKeyPressed = false;
  104.                var2 = true;
  105.             }
  106.             break;
  107.          default:
  108.             var2 = this.receivedKeyPressed;
  109.       }
  110.  
  111.       if (var2) {
  112.          MenuSelectionManager.defaultManager().processKeyEvent(var1);
  113.       }
  114.  
  115.       if (!((InputEvent)var1).isConsumed()) {
  116.          if (var1.getKeyCode() != 9 && var1.getKeyChar() != '\t') {
  117.             super.processKeyEvent(var1);
  118.          } else {
  119.             ((InputEvent)var1).consume();
  120.          }
  121.       }
  122.    }
  123.  
  124.    public SingleSelectionModel getSelectionModel() {
  125.       return this.selectionModel;
  126.    }
  127.  
  128.    public void setSelectionModel(SingleSelectionModel var1) {
  129.       this.selectionModel = var1;
  130.    }
  131.  
  132.    public JMenuItem add(JMenuItem var1) {
  133.       super.add(var1);
  134.       return var1;
  135.    }
  136.  
  137.    public JMenuItem add(String var1) {
  138.       return this.add(new JMenuItem(var1));
  139.    }
  140.  
  141.    public JMenuItem add(Action var1) {
  142.       JMenuItem var2 = this.createActionComponent(var1);
  143.       ((AbstractButton)var2).setAction(var1);
  144.       this.add(var2);
  145.       return var2;
  146.    }
  147.  
  148.    protected JMenuItem createActionComponent(Action var1) {
  149.       2 var2 = new 2(this, (String)var1.getValue("Name"), (Icon)var1.getValue("SmallIcon"));
  150.       ((AbstractButton)var2).setHorizontalTextPosition(4);
  151.       ((AbstractButton)var2).setVerticalTextPosition(0);
  152.       ((JMenuItem)var2).setEnabled(var1.isEnabled());
  153.       return var2;
  154.    }
  155.  
  156.    protected PropertyChangeListener createActionChangeListener(JMenuItem var1) {
  157.       return new ActionChangedListener(this, var1);
  158.    }
  159.  
  160.    public void remove(int var1) {
  161.       if (var1 < 0) {
  162.          throw new IllegalArgumentException("index less than zero.");
  163.       } else if (var1 > ((Container)this).getComponentCount() - 1) {
  164.          throw new IllegalArgumentException("index greater than the number of items.");
  165.       } else {
  166.          super.remove(var1);
  167.       }
  168.    }
  169.  
  170.    public void setLightWeightPopupEnabled(boolean var1) {
  171.       this.lightWeightPopupEnabled = var1;
  172.    }
  173.  
  174.    public boolean isLightWeightPopupEnabled() {
  175.       return this.lightWeightPopupEnabled;
  176.    }
  177.  
  178.    public String getLabel() {
  179.       return this.label;
  180.    }
  181.  
  182.    public void setLabel(String var1) {
  183.       String var2 = this.label;
  184.       this.label = var1;
  185.       ((JComponent)this).firePropertyChange("label", var2, var1);
  186.       if (super.accessibleContext != null) {
  187.          super.accessibleContext.firePropertyChange("AccessibleVisibleData", var2, var1);
  188.       }
  189.  
  190.       ((Container)this).invalidate();
  191.       ((Component)this).repaint();
  192.    }
  193.  
  194.    public void addSeparator() {
  195.       ((Container)this).add(new Separator());
  196.    }
  197.  
  198.    public void insert(Action var1, int var2) {
  199.       JMenuItem var3 = this.createActionComponent(var1);
  200.       ((AbstractButton)var3).setAction(var1);
  201.       ((Container)this).add(var3, var2);
  202.    }
  203.  
  204.    public void insert(Component var1, int var2) {
  205.       if (var2 < 0) {
  206.          throw new IllegalArgumentException("index less than zero.");
  207.       } else {
  208.          int var3 = ((Container)this).getComponentCount();
  209.          Vector var4 = new Vector();
  210.  
  211.          for(int var5 = var2; var5 < var3; ++var5) {
  212.             var4.addElement(((Container)this).getComponent(var2));
  213.             this.remove(var2);
  214.          }
  215.  
  216.          ((Container)this).add(var1);
  217.  
  218.          for(int var6 = 0; var6 < var4.size(); ++var6) {
  219.             ((Container)this).add((Component)var4.elementAt(var6));
  220.          }
  221.  
  222.       }
  223.    }
  224.  
  225.    public void addPopupMenuListener(PopupMenuListener var1) {
  226.       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);
  227.    }
  228.  
  229.    public void removePopupMenuListener(PopupMenuListener var1) {
  230.       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);
  231.    }
  232.  
  233.    protected void firePopupMenuWillBecomeVisible() {
  234.       Object[] var1 = super.listenerList.getListenerList();
  235.       PopupMenuEvent var2 = null;
  236.  
  237.       for(int var3 = var1.length - 2; var3 >= 0; var3 -= 2) {
  238.          if (var1[var3] == (class$javax$swing$event$PopupMenuListener == null ? (class$javax$swing$event$PopupMenuListener = class$("javax.swing.event.PopupMenuListener")) : class$javax$swing$event$PopupMenuListener)) {
  239.             if (var2 == null) {
  240.                var2 = new PopupMenuEvent(this);
  241.             }
  242.  
  243.             ((PopupMenuListener)var1[var3 + 1]).popupMenuWillBecomeVisible(var2);
  244.          }
  245.       }
  246.  
  247.    }
  248.  
  249.    protected void firePopupMenuWillBecomeInvisible() {
  250.       Object[] var1 = super.listenerList.getListenerList();
  251.       PopupMenuEvent var2 = null;
  252.  
  253.       for(int var3 = var1.length - 2; var3 >= 0; var3 -= 2) {
  254.          if (var1[var3] == (class$javax$swing$event$PopupMenuListener == null ? (class$javax$swing$event$PopupMenuListener = class$("javax.swing.event.PopupMenuListener")) : class$javax$swing$event$PopupMenuListener)) {
  255.             if (var2 == null) {
  256.                var2 = new PopupMenuEvent(this);
  257.             }
  258.  
  259.             ((PopupMenuListener)var1[var3 + 1]).popupMenuWillBecomeInvisible(var2);
  260.          }
  261.       }
  262.  
  263.    }
  264.  
  265.    protected void firePopupMenuCanceled() {
  266.       Object[] var1 = super.listenerList.getListenerList();
  267.       PopupMenuEvent var2 = null;
  268.  
  269.       for(int var3 = var1.length - 2; var3 >= 0; var3 -= 2) {
  270.          if (var1[var3] == (class$javax$swing$event$PopupMenuListener == null ? (class$javax$swing$event$PopupMenuListener = class$("javax.swing.event.PopupMenuListener")) : class$javax$swing$event$PopupMenuListener)) {
  271.             if (var2 == null) {
  272.                var2 = new PopupMenuEvent(this);
  273.             }
  274.  
  275.             ((PopupMenuListener)var1[var3 + 1]).popupMenuCanceled(var2);
  276.          }
  277.       }
  278.  
  279.    }
  280.  
  281.    boolean alwaysOnTop() {
  282.       return true;
  283.    }
  284.  
  285.    public void pack() {
  286.       if (this.popup != null) {
  287.          this.popup.pack();
  288.       }
  289.  
  290.    }
  291.  
  292.    public void setVisible(boolean var1) {
  293.       if (var1 != this.isVisible()) {
  294.          if (!var1) {
  295.             this.getSelectionModel().clearSelection();
  296.          } else if (this.isPopupMenu()) {
  297.             if (this.getSubElements().length > 0) {
  298.                MenuElement[] var2 = new MenuElement[]{this, this.getSubElements()[0]};
  299.                MenuSelectionManager.defaultManager().setSelectedPath(var2);
  300.             } else {
  301.                MenuElement[] var3 = new MenuElement[]{this};
  302.                MenuSelectionManager.defaultManager().setSelectedPath(var3);
  303.             }
  304.          }
  305.  
  306.          if (var1) {
  307.             this.firePopupMenuWillBecomeVisible();
  308.             this.popup = popupFactory.getPopup(this, this.invoker, this.desiredLocationX, this.desiredLocationY);
  309.             this.popup.show(this.invoker);
  310.          } else if (this.popup != null) {
  311.             this.firePopupMenuWillBecomeInvisible();
  312.             this.popup.hide();
  313.             this.popup.removeComponent(this);
  314.             this.popup = null;
  315.          }
  316.  
  317.          if (super.accessibleContext != null) {
  318.             if (var1) {
  319.                super.accessibleContext.firePropertyChange("AccessibleState", (Object)null, AccessibleState.VISIBLE);
  320.             } else {
  321.                super.accessibleContext.firePropertyChange("AccessibleState", AccessibleState.VISIBLE, (Object)null);
  322.             }
  323.          }
  324.  
  325.       }
  326.    }
  327.  
  328.    public boolean isVisible() {
  329.       return this.popup != null;
  330.    }
  331.  
  332.    public void setLocation(int var1, int var2) {
  333.       if (this.popup != null) {
  334.          this.popup.setLocationOnScreen(var1, var2);
  335.       } else {
  336.          this.desiredLocationX = var1;
  337.          this.desiredLocationY = var2;
  338.       }
  339.  
  340.    }
  341.  
  342.    private boolean isPopupMenu() {
  343.       return this.invoker != null && !(this.invoker instanceof JMenu);
  344.    }
  345.  
  346.    public Component getInvoker() {
  347.       return this.invoker;
  348.    }
  349.  
  350.    public void setInvoker(Component var1) {
  351.       Component var2 = this.invoker;
  352.       this.invoker = var1;
  353.       if (var2 != this.invoker && super.ui != null) {
  354.          super.ui.uninstallUI(this);
  355.          super.ui.installUI(this);
  356.       }
  357.  
  358.       ((Container)this).invalidate();
  359.    }
  360.  
  361.    public void show(Component var1, int var2, int var3) {
  362.       this.setInvoker(var1);
  363.       Frame var4 = getFrame(var1);
  364.       if (var4 != this.frame && var4 != null) {
  365.          this.frame = var4;
  366.          if (this.popup != null) {
  367.             this.setVisible(false);
  368.          }
  369.       }
  370.  
  371.       if (var1 != null) {
  372.          Point var5 = var1.getLocationOnScreen();
  373.          this.setLocation(var5.x + var2, var5.y + var3);
  374.       } else {
  375.          this.setLocation(var2, var3);
  376.       }
  377.  
  378.       this.setVisible(true);
  379.    }
  380.  
  381.    JPopupMenu getRootPopupMenu() {
  382.       JPopupMenu var1;
  383.       for(var1 = this; var1 != null && !var1.isPopupMenu() && var1.getInvoker() != null && var1.getInvoker().getParent() != null && var1.getInvoker().getParent() instanceof JPopupMenu; var1 = (JPopupMenu)var1.getInvoker().getParent()) {
  384.       }
  385.  
  386.       return var1;
  387.    }
  388.  
  389.    public Component getComponentAtIndex(int var1) {
  390.       return ((Container)this).getComponent(var1);
  391.    }
  392.  
  393.    public int getComponentIndex(Component var1) {
  394.       int var2 = ((Container)this).getComponentCount();
  395.       Component[] var3 = ((Container)this).getComponents();
  396.  
  397.       for(int var4 = 0; var4 < var2; ++var4) {
  398.          Component var5 = var3[var4];
  399.          if (var5 == var1) {
  400.             return var4;
  401.          }
  402.       }
  403.  
  404.       return -1;
  405.    }
  406.  
  407.    public void setPopupSize(Dimension var1) {
  408.       if (this.popup != null) {
  409.          this.popup.setSize(var1.width, var1.height);
  410.       }
  411.  
  412.    }
  413.  
  414.    public void setPopupSize(int var1, int var2) {
  415.       this.setPopupSize(new Dimension(var1, var2));
  416.    }
  417.  
  418.    public void setSelected(Component var1) {
  419.       SingleSelectionModel var2 = this.getSelectionModel();
  420.       int var3 = this.getComponentIndex(var1);
  421.       var2.setSelectedIndex(var3);
  422.    }
  423.  
  424.    public boolean isBorderPainted() {
  425.       return this.paintBorder;
  426.    }
  427.  
  428.    public void setBorderPainted(boolean var1) {
  429.       this.paintBorder = var1;
  430.       ((Component)this).repaint();
  431.    }
  432.  
  433.    protected void paintBorder(Graphics var1) {
  434.       if (this.isBorderPainted()) {
  435.          super.paintBorder(var1);
  436.       }
  437.  
  438.    }
  439.  
  440.    public Insets getMargin() {
  441.       return this.margin == null ? new Insets(0, 0, 0, 0) : this.margin;
  442.    }
  443.  
  444.    boolean isSubPopupMenu(JPopupMenu var1) {
  445.       int var2 = ((Container)this).getComponentCount();
  446.       Component[] var3 = ((Container)this).getComponents();
  447.  
  448.       for(int var4 = 0; var4 < var2; ++var4) {
  449.          Component var5 = var3[var4];
  450.          if (var5 instanceof JMenu) {
  451.             JMenu var6 = (JMenu)var5;
  452.             JPopupMenu var7 = var6.getPopupMenu();
  453.             if (var7 == var1) {
  454.                return true;
  455.             }
  456.  
  457.             if (var7.isSubPopupMenu(var1)) {
  458.                return true;
  459.             }
  460.          }
  461.       }
  462.  
  463.       return false;
  464.    }
  465.  
  466.    private static Frame getFrame(Component var0) {
  467.       Object var1;
  468.       for(var1 = var0; !(var1 instanceof Frame) && var1 != null; var1 = ((Component)var1).getParent()) {
  469.       }
  470.  
  471.       return (Frame)var1;
  472.    }
  473.  
  474.    protected String paramString() {
  475.       String var1 = this.label != null ? this.label : "";
  476.       String var2 = this.paintBorder ? "true" : "false";
  477.       String var3 = this.margin != null ? this.margin.toString() : "";
  478.       String var4 = this.isLightWeightPopupEnabled() ? "true" : "false";
  479.       return super.paramString() + ",desiredLocationX=" + this.desiredLocationX + ",desiredLocationY=" + this.desiredLocationY + ",label=" + var1 + ",lightWeightPopupEnabled=" + var4 + ",margin=" + var3 + ",paintBorder=" + var2;
  480.    }
  481.  
  482.    public AccessibleContext getAccessibleContext() {
  483.       if (super.accessibleContext == null) {
  484.          super.accessibleContext = new AccessibleJPopupMenu(this);
  485.       }
  486.  
  487.       return super.accessibleContext;
  488.    }
  489.  
  490.    private void writeObject(ObjectOutputStream var1) throws IOException {
  491.       Vector var2 = new Vector();
  492.       var1.defaultWriteObject();
  493.       if (this.invoker != null && this.invoker instanceof Serializable) {
  494.          var2.addElement("invoker");
  495.          var2.addElement(this.invoker);
  496.       }
  497.  
  498.       if (this.popup != null && this.popup instanceof Serializable) {
  499.          var2.addElement("popup");
  500.          var2.addElement(this.popup);
  501.       }
  502.  
  503.       if (this.frame != null && this.frame instanceof Serializable) {
  504.          var2.addElement("frame");
  505.          var2.addElement(this.frame);
  506.       }
  507.  
  508.       var1.writeObject(var2);
  509.       if (super.ui != null && this.getUIClassID().equals("PopupMenuUI")) {
  510.          super.ui.installUI(this);
  511.       }
  512.  
  513.    }
  514.  
  515.    private void readObject(ObjectInputStream var1) throws IOException, ClassNotFoundException {
  516.       var1.defaultReadObject();
  517.       Vector var2 = (Vector)var1.readObject();
  518.       int var3 = 0;
  519.       int var4 = var2.size();
  520.       if (var3 < var4 && var2.elementAt(var3).equals("invoker")) {
  521.          ++var3;
  522.          this.invoker = (Component)var2.elementAt(var3);
  523.          ++var3;
  524.       }
  525.  
  526.       if (var3 < var4 && var2.elementAt(var3).equals("popup")) {
  527.          ++var3;
  528.          this.popup = (Popup)var2.elementAt(var3);
  529.          ++var3;
  530.       }
  531.  
  532.       if (var3 < var4 && var2.elementAt(var3).equals("frame")) {
  533.          ++var3;
  534.          this.frame = (Frame)var2.elementAt(var3);
  535.          ++var3;
  536.       }
  537.  
  538.    }
  539.  
  540.    public void processMouseEvent(MouseEvent var1, MenuElement[] var2, MenuSelectionManager var3) {
  541.    }
  542.  
  543.    public void processKeyEvent(KeyEvent var1, MenuElement[] var2, MenuSelectionManager var3) {
  544.    }
  545.  
  546.    public void menuSelectionChanged(boolean var1) {
  547.       if (this.invoker instanceof JMenu) {
  548.          JMenu var2 = (JMenu)this.invoker;
  549.          if (var1) {
  550.             var2.setPopupMenuVisible(true);
  551.          } else {
  552.             var2.setPopupMenuVisible(false);
  553.          }
  554.       }
  555.  
  556.       if (this.isPopupMenu() && !var1) {
  557.          this.setVisible(false);
  558.       }
  559.  
  560.    }
  561.  
  562.    public MenuElement[] getSubElements() {
  563.       Vector var2 = new Vector();
  564.       int var3 = ((Container)this).getComponentCount();
  565.  
  566.       for(int var4 = 0; var4 < var3; ++var4) {
  567.          Component var5 = ((Container)this).getComponent(var4);
  568.          if (var5 instanceof MenuElement) {
  569.             var2.addElement(var5);
  570.          }
  571.       }
  572.  
  573.       MenuElement[] var1 = new MenuElement[var2.size()];
  574.       int var7 = 0;
  575.  
  576.       for(int var6 = var2.size(); var7 < var6; ++var7) {
  577.          var1[var7] = (MenuElement)var2.elementAt(var7);
  578.       }
  579.  
  580.       return var1;
  581.    }
  582.  
  583.    public Component getComponent() {
  584.       return this;
  585.    }
  586.  
  587.    public boolean isPopupTrigger(MouseEvent var1) {
  588.       return this.getUI().isPopupTrigger(var1);
  589.    }
  590.  
  591.    static void setPopupFactory(PopupFactory var0) {
  592.       popupFactory = var0;
  593.    }
  594.  
  595.    // $FF: synthetic method
  596.    static Class class$(String var0) {
  597.       try {
  598.          return Class.forName(var0);
  599.       } catch (ClassNotFoundException var2) {
  600.          throw new NoClassDefFoundError(((Throwable)var2).getMessage());
  601.       }
  602.    }
  603. }
  604.