home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 2000 March / pcp161a.iso / handson / files / copyjava.exe / com / sun / java / swing / JPopupMenu.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-02-26  |  17.8 KB  |  800 lines

  1. package com.sun.java.swing;
  2.  
  3. import com.sun.java.accessibility.Accessible;
  4. import com.sun.java.accessibility.AccessibleContext;
  5. import com.sun.java.swing.event.PopupMenuEvent;
  6. import com.sun.java.swing.event.PopupMenuListener;
  7. import com.sun.java.swing.plaf.PopupMenuUI;
  8. import java.awt.Component;
  9. import java.awt.Container;
  10. import java.awt.Dialog;
  11. import java.awt.Dimension;
  12. import java.awt.Frame;
  13. import java.awt.Graphics;
  14. import java.awt.GridBagConstraints;
  15. import java.awt.GridBagLayout;
  16. import java.awt.Insets;
  17. import java.awt.Point;
  18. import java.awt.Rectangle;
  19. import java.awt.Window;
  20. import java.awt.event.KeyEvent;
  21. import java.awt.event.MouseEvent;
  22. import java.beans.PropertyChangeListener;
  23. import java.io.IOException;
  24. import java.io.ObjectInputStream;
  25. import java.io.ObjectOutputStream;
  26. import java.io.Serializable;
  27. import java.util.Hashtable;
  28. import java.util.Vector;
  29.  
  30. public class JPopupMenu extends JComponent implements Accessible, MenuElement {
  31.    transient Component invoker;
  32.    transient Popup popup;
  33.    transient Frame frame;
  34.    private String label;
  35.    private boolean paintBorder;
  36.    private Insets margin;
  37.    private int desiredLocationX;
  38.    private int desiredLocationY;
  39.    private int lastPopupType;
  40.    private static final Object heavyPopupCacheKey = new StringBuffer("JPopupMenu.heavyPopupCache");
  41.    private static final Object lightPopupCacheKey = new StringBuffer("JPopupMenu.lightPopupCache");
  42.    private static final Object mediumPopupCacheKey = new StringBuffer("JPopupMenu.mediumPopupCache");
  43.    private static final Object defaultLWPopupEnabledKey = new StringBuffer("JPopupMenu.defaultLWPopupEnabledKey");
  44.    private static final int MAX_CACHE_SIZE = 5;
  45.    private transient MouseGrabber mouseGrabber;
  46.    private boolean lightWeightPopupEnabled;
  47.    private static final int LIGHT_WEIGHT_POPUP = 0;
  48.    private static final int MEDIUM_WEIGHT_POPUP = 1;
  49.    private static final int HEAVY_WEIGHT_POPUP = 2;
  50.    private SingleSelectionModel selectionModel;
  51.    // $FF: synthetic field
  52.    static Class class$com$sun$java$swing$event$PopupMenuListener;
  53.  
  54.    public static void setDefaultLightWeightPopupEnabled(boolean var0) {
  55.       SwingUtilities.appContextPut(defaultLWPopupEnabledKey, new Boolean(var0));
  56.    }
  57.  
  58.    public static boolean getDefaultLightWeightPopupEnabled() {
  59.       Boolean var0 = (Boolean)SwingUtilities.appContextGet(defaultLWPopupEnabledKey);
  60.       if (var0 == null) {
  61.          SwingUtilities.appContextPut(defaultLWPopupEnabledKey, Boolean.TRUE);
  62.          return true;
  63.       } else {
  64.          return var0;
  65.       }
  66.    }
  67.  
  68.    private static Hashtable getHeavyPopupCache() {
  69.       Hashtable var0 = (Hashtable)SwingUtilities.appContextGet(heavyPopupCacheKey);
  70.       if (var0 == null) {
  71.          var0 = new Hashtable(2);
  72.          SwingUtilities.appContextPut(heavyPopupCacheKey, var0);
  73.       }
  74.  
  75.       return var0;
  76.    }
  77.  
  78.    private static Vector getLightPopupCache() {
  79.       Vector var0 = (Vector)SwingUtilities.appContextGet(lightPopupCacheKey);
  80.       if (var0 == null) {
  81.          var0 = new Vector();
  82.          SwingUtilities.appContextPut(lightPopupCacheKey, var0);
  83.       }
  84.  
  85.       return var0;
  86.    }
  87.  
  88.    private static Vector getMediumPopupCache() {
  89.       Vector var0 = (Vector)SwingUtilities.appContextGet(mediumPopupCacheKey);
  90.       if (var0 == null) {
  91.          var0 = new Vector();
  92.          SwingUtilities.appContextPut(mediumPopupCacheKey, var0);
  93.       }
  94.  
  95.       return var0;
  96.    }
  97.  
  98.    static synchronized void recycleHeavyPopup(Popup var0) {
  99.       Frame var2 = getFrame((Component)var0);
  100.       Hashtable var3 = getHeavyPopupCache();
  101.       Vector var1;
  102.       if (var3.containsKey(var2)) {
  103.          var1 = (Vector)var3.get(var2);
  104.       } else {
  105.          var1 = new Vector();
  106.          var3.put(var2, var1);
  107.          ((Window)var2).addWindowListener(new 1(var2));
  108.       }
  109.  
  110.       if (var1.size() < 5) {
  111.          var1.addElement(var0);
  112.       }
  113.  
  114.    }
  115.  
  116.    static synchronized Popup getRecycledHeavyPopup(Frame var0) {
  117.       Hashtable var2 = getHeavyPopupCache();
  118.       if (var2.containsKey(var0)) {
  119.          Vector var1 = (Vector)var2.get(var0);
  120.          if (var1.size() > 0) {
  121.             Popup var4 = (Popup)var1.elementAt(0);
  122.             var1.removeElementAt(0);
  123.             return var4;
  124.          } else {
  125.             return null;
  126.          }
  127.       } else {
  128.          return null;
  129.       }
  130.    }
  131.  
  132.    static synchronized void recycleLightPopup(Popup var0) {
  133.       Vector var1 = getLightPopupCache();
  134.       if (var1.size() < 5) {
  135.          var1.addElement(var0);
  136.       }
  137.  
  138.    }
  139.  
  140.    static synchronized Popup getRecycledLightPopup() {
  141.       Vector var0 = getLightPopupCache();
  142.       if (var0.size() > 0) {
  143.          Popup var2 = (Popup)var0.elementAt(0);
  144.          var0.removeElementAt(0);
  145.          return var2;
  146.       } else {
  147.          return null;
  148.       }
  149.    }
  150.  
  151.    static synchronized void recycleMediumPopup(Popup var0) {
  152.       Vector var1 = getMediumPopupCache();
  153.       if (var1.size() < 5) {
  154.          var1.addElement(var0);
  155.       }
  156.  
  157.    }
  158.  
  159.    static synchronized Popup getRecycledMediumPopup() {
  160.       Vector var0 = getMediumPopupCache();
  161.       if (var0.size() > 0) {
  162.          Popup var2 = (Popup)var0.elementAt(0);
  163.          var0.removeElementAt(0);
  164.          return var2;
  165.       } else {
  166.          return null;
  167.       }
  168.    }
  169.  
  170.    static void recyclePopup(Popup var0) {
  171.       if (var0 instanceof JPanelPopup) {
  172.          recycleLightPopup(var0);
  173.       } else if (var0 instanceof WindowPopup) {
  174.          recycleHeavyPopup(var0);
  175.       } else {
  176.          if (var0 instanceof PanelPopup) {
  177.             recycleMediumPopup(var0);
  178.          }
  179.  
  180.       }
  181.    }
  182.  
  183.    public JPopupMenu() {
  184.       this((String)null);
  185.    }
  186.  
  187.    public JPopupMenu(String var1) {
  188.       this.paintBorder = true;
  189.       this.lastPopupType = 0;
  190.       this.lightWeightPopupEnabled = true;
  191.       this.label = var1;
  192.       ((Container)this).setLayout(new GridBagLayout());
  193.       this.lightWeightPopupEnabled = getDefaultLightWeightPopupEnabled();
  194.       this.setSelectionModel(new DefaultSingleSelectionModel());
  195.       ((Component)this).addMouseListener(new 2());
  196.       this.updateUI();
  197.    }
  198.  
  199.    public PopupMenuUI getUI() {
  200.       return (PopupMenuUI)super.ui;
  201.    }
  202.  
  203.    public void setUI(PopupMenuUI var1) {
  204.       super.setUI(var1);
  205.    }
  206.  
  207.    public void updateUI() {
  208.       this.setUI((PopupMenuUI)UIManager.getUI(this));
  209.    }
  210.  
  211.    public String getUIClassID() {
  212.       return "PopupMenuUI";
  213.    }
  214.  
  215.    public SingleSelectionModel getSelectionModel() {
  216.       return this.selectionModel;
  217.    }
  218.  
  219.    public void setSelectionModel(SingleSelectionModel var1) {
  220.       this.selectionModel = var1;
  221.    }
  222.  
  223.    public JMenuItem add(JMenuItem var1) {
  224.       GridBagConstraints var2 = new GridBagConstraints();
  225.       var2.fill = 2;
  226.       var2.gridx = 0;
  227.       var2.gridy = ((Container)this).getComponentCount() + 1;
  228.       super.add(var1, var2);
  229.       return var1;
  230.    }
  231.  
  232.    public Component add(Component var1) {
  233.       GridBagConstraints var2 = new GridBagConstraints();
  234.       var2.fill = 2;
  235.       var2.gridx = 0;
  236.       var2.gridy = ((Container)this).getComponentCount() + 1;
  237.       super.add(var1, var2);
  238.       return var1;
  239.    }
  240.  
  241.    public JMenuItem add(Action var1) {
  242.       JMenuItem var2 = new JMenuItem((String)var1.getValue("Name"), (Icon)var1.getValue("SmallIcon"));
  243.       ((AbstractButton)var2).setHorizontalTextPosition(4);
  244.       ((AbstractButton)var2).setVerticalTextPosition(0);
  245.       var2.setEnabled(var1.isEnabled());
  246.       ((AbstractButton)var2).addActionListener(var1);
  247.       this.add(var2);
  248.       PropertyChangeListener var3 = this.createActionChangeListener(var2);
  249.       var1.addPropertyChangeListener(var3);
  250.       return var2;
  251.    }
  252.  
  253.    protected PropertyChangeListener createActionChangeListener(JMenuItem var1) {
  254.       return new ActionChangedListener(this, var1);
  255.    }
  256.  
  257.    public void setLightWeightPopupEnabled(boolean var1) {
  258.       this.lightWeightPopupEnabled = var1;
  259.    }
  260.  
  261.    public boolean isLightWeightPopupEnabled() {
  262.       return this.lightWeightPopupEnabled;
  263.    }
  264.  
  265.    public String getLabel() {
  266.       return this.label;
  267.    }
  268.  
  269.    public void setLabel(String var1) {
  270.       this.label = var1;
  271.       ((JComponent)this).firePropertyChange("label", var1, var1);
  272.       if (super.accessibleContext != null) {
  273.          super.accessibleContext.firePropertyChange("AccessibleVisibleData", var1, var1);
  274.       }
  275.  
  276.       ((Container)this).invalidate();
  277.       ((Component)this).repaint();
  278.    }
  279.  
  280.    public void addSeparator() {
  281.       this.add((Component)(new JSeparator()));
  282.    }
  283.  
  284.    public void insert(Action var1, int var2) {
  285.       throw new Error("void insert(Action, int) {} not yet implemented");
  286.    }
  287.  
  288.    public void insert(Component var1, int var2) {
  289.       if (var2 < 0) {
  290.          throw new IllegalArgumentException("index less than zero.");
  291.       } else {
  292.          int var3 = ((Container)this).getComponentCount();
  293.          Vector var4 = new Vector();
  294.  
  295.          for(int var5 = var2; var5 < var3; ++var5) {
  296.             var4.addElement(((Container)this).getComponent(var2));
  297.             ((Container)this).remove(var2);
  298.          }
  299.  
  300.          this.add(var1);
  301.  
  302.          for(int var6 = 0; var6 < var4.size(); ++var6) {
  303.             this.add((Component)var4.elementAt(var6));
  304.          }
  305.  
  306.       }
  307.    }
  308.  
  309.    public void addPopupMenuListener(PopupMenuListener var1) {
  310.       super.listenerList.add(class$com$sun$java$swing$event$PopupMenuListener != null ? class$com$sun$java$swing$event$PopupMenuListener : (class$com$sun$java$swing$event$PopupMenuListener = JComponent.class$("com.sun.java.swing.event.PopupMenuListener")), var1);
  311.    }
  312.  
  313.    public void removePopupMenuListener(PopupMenuListener var1) {
  314.       super.listenerList.remove(class$com$sun$java$swing$event$PopupMenuListener != null ? class$com$sun$java$swing$event$PopupMenuListener : (class$com$sun$java$swing$event$PopupMenuListener = JComponent.class$("com.sun.java.swing.event.PopupMenuListener")), var1);
  315.    }
  316.  
  317.    protected void firePopupMenuWillBecomeVisible() {
  318.       Object[] var1 = super.listenerList.getListenerList();
  319.       PopupMenuEvent var2 = null;
  320.  
  321.       for(int var3 = var1.length - 2; var3 >= 0; var3 -= 2) {
  322.          if (var1[var3] == (class$com$sun$java$swing$event$PopupMenuListener != null ? class$com$sun$java$swing$event$PopupMenuListener : (class$com$sun$java$swing$event$PopupMenuListener = JComponent.class$("com.sun.java.swing.event.PopupMenuListener")))) {
  323.             if (var2 == null) {
  324.                var2 = new PopupMenuEvent(this);
  325.             }
  326.  
  327.             ((PopupMenuListener)var1[var3 + 1]).popupMenuWillBecomeVisible(var2);
  328.          }
  329.       }
  330.  
  331.    }
  332.  
  333.    protected void firePopupMenuWillBecomeInvisible() {
  334.       Object[] var1 = super.listenerList.getListenerList();
  335.       PopupMenuEvent var2 = null;
  336.  
  337.       for(int var3 = var1.length - 2; var3 >= 0; var3 -= 2) {
  338.          if (var1[var3] == (class$com$sun$java$swing$event$PopupMenuListener != null ? class$com$sun$java$swing$event$PopupMenuListener : (class$com$sun$java$swing$event$PopupMenuListener = JComponent.class$("com.sun.java.swing.event.PopupMenuListener")))) {
  339.             if (var2 == null) {
  340.                var2 = new PopupMenuEvent(this);
  341.             }
  342.  
  343.             ((PopupMenuListener)var1[var3 + 1]).popupMenuWillBecomeInvisible(var2);
  344.          }
  345.       }
  346.  
  347.    }
  348.  
  349.    protected void firePopupMenuCanceled() {
  350.       Object[] var1 = super.listenerList.getListenerList();
  351.       PopupMenuEvent var2 = null;
  352.  
  353.       for(int var3 = var1.length - 2; var3 >= 0; var3 -= 2) {
  354.          if (var1[var3] == (class$com$sun$java$swing$event$PopupMenuListener != null ? class$com$sun$java$swing$event$PopupMenuListener : (class$com$sun$java$swing$event$PopupMenuListener = JComponent.class$("com.sun.java.swing.event.PopupMenuListener")))) {
  355.             if (var2 == null) {
  356.                var2 = new PopupMenuEvent(this);
  357.             }
  358.  
  359.             ((PopupMenuListener)var1[var3 + 1]).popupMenuCanceled(var2);
  360.          }
  361.       }
  362.  
  363.    }
  364.  
  365.    public void pack() {
  366.       if (this.popup != null) {
  367.          this.popup.pack();
  368.       }
  369.  
  370.    }
  371.  
  372.    private Popup createLightWeightPopup() {
  373.       Object var1 = getRecycledLightPopup();
  374.       if (var1 == null) {
  375.          var1 = new JPanelPopup(this);
  376.       }
  377.  
  378.       return (Popup)var1;
  379.    }
  380.  
  381.    private Popup createMediumWeightPopup() {
  382.       Object var1 = getRecycledMediumPopup();
  383.       if (var1 == null) {
  384.          var1 = new PanelPopup(this);
  385.       }
  386.  
  387.       return (Popup)var1;
  388.    }
  389.  
  390.    private Popup createHeavyWeightPopup() {
  391.       Frame var1 = getFrame(this.invoker);
  392.       if (var1 != null) {
  393.          this.popup = getRecycledHeavyPopup(var1);
  394.       } else {
  395.          var1 = new Frame();
  396.       }
  397.  
  398.       if (this.popup == null) {
  399.          this.popup = new WindowPopup(this, var1);
  400.       }
  401.  
  402.       return this.popup;
  403.    }
  404.  
  405.    private boolean popupFit(Rectangle var1) {
  406.       if (this.invoker != null) {
  407.          for(Container var2 = this.invoker.getParent(); var2 != null; var2 = ((Component)var2).getParent()) {
  408.             if (var2 instanceof JFrame || var2 instanceof JDialog) {
  409.                return SwingUtilities.isRectangleContainingRectangle(((Component)var2).getBounds(), var1);
  410.             }
  411.  
  412.             if (var2 instanceof JApplet) {
  413.                Rectangle var3 = ((Component)var2).getBounds();
  414.                Point var4 = ((Component)var2).getLocationOnScreen();
  415.                var3.x = var4.x;
  416.                var3.y = var4.y;
  417.                return SwingUtilities.isRectangleContainingRectangle(var3, var1);
  418.             }
  419.  
  420.             if (var2 instanceof Frame) {
  421.                return SwingUtilities.isRectangleContainingRectangle(((Component)var2).getBounds(), var1);
  422.             }
  423.          }
  424.       }
  425.  
  426.       return false;
  427.    }
  428.  
  429.    private boolean ancestorIsDialog(Component var1) {
  430.       for(Container var2 = var1.getParent(); var2 != null; var2 = ((Component)var2).getParent()) {
  431.          if (var2 instanceof Dialog) {
  432.             return true;
  433.          }
  434.       }
  435.  
  436.       return false;
  437.    }
  438.  
  439.    private void replacePopup(int var1) {
  440.       this.popup.removeComponent(this);
  441.       recyclePopup(this.popup);
  442.       switch (var1) {
  443.          case 0:
  444.             this.popup = this.createLightWeightPopup();
  445.             break;
  446.          case 1:
  447.             this.popup = this.createMediumWeightPopup();
  448.             break;
  449.          case 2:
  450.             this.popup = this.createHeavyWeightPopup();
  451.       }
  452.  
  453.       this.popup.setLocationOnScreen(this.desiredLocationX, this.desiredLocationY);
  454.       this.popup.addComponent(this, "Center");
  455.       ((Container)this).invalidate();
  456.       this.popup.setBackground(((Component)this).getBackground());
  457.       this.popup.pack();
  458.    }
  459.  
  460.    public void setVisible(boolean var1) {
  461.       if (var1 != this.isVisible()) {
  462.          if (!var1) {
  463.             this.getSelectionModel().clearSelection();
  464.             if (this.getRootPopupMenu() == this) {
  465.                this.requestRemoveGrab(this.invoker);
  466.             }
  467.          } else if (this.isPopupMenu() && this.getSubElements().length > 0) {
  468.             MenuElement[] var2 = new MenuElement[]{this, this.getSubElements()[0]};
  469.             MenuSelectionManager.defaultManager().setSelectedPath(var2);
  470.          }
  471.  
  472.          if (var1) {
  473.             boolean var4 = this.ancestorIsDialog(this.invoker);
  474.             this.firePopupMenuWillBecomeVisible();
  475.             switch (this.lastPopupType) {
  476.                case 0:
  477.                   this.popup = this.createLightWeightPopup();
  478.                   break;
  479.                case 1:
  480.                   this.popup = this.createMediumWeightPopup();
  481.                   break;
  482.                case 2:
  483.                   this.popup = this.createHeavyWeightPopup();
  484.             }
  485.  
  486.             int var6 = this.lastPopupType;
  487.             this.popup.setLocationOnScreen(this.desiredLocationX, this.desiredLocationY);
  488.             this.popup.addComponent(this, "Center");
  489.             this.popup.setBackground(((Component)this).getBackground());
  490.             this.popup.pack();
  491.             Rectangle var5 = new Rectangle(this.desiredLocationX, this.desiredLocationY, this.popup.getWidth(), this.popup.getHeight());
  492.             byte var3;
  493.             if (this.popupFit(var5)) {
  494.                if (this.lightWeightPopupEnabled) {
  495.                   var3 = 0;
  496.                } else {
  497.                   var3 = 1;
  498.                }
  499.             } else if (var4) {
  500.                var3 = 1;
  501.             } else {
  502.                var3 = 2;
  503.             }
  504.  
  505.             if (var3 != var6) {
  506.                this.replacePopup(var3);
  507.                var6 = var3;
  508.             }
  509.  
  510.             this.lastPopupType = var6;
  511.             this.popup.show(this.invoker);
  512.             if (this.getRootPopupMenu() == this) {
  513.                this.requestAddGrab(this.invoker, this.popup);
  514.                return;
  515.             }
  516.          } else if (this.popup != null) {
  517.             this.firePopupMenuWillBecomeInvisible();
  518.             this.popup.hide();
  519.             this.popup.removeComponent(this);
  520.             recyclePopup(this.popup);
  521.             this.popup = null;
  522.          }
  523.  
  524.       }
  525.    }
  526.  
  527.    public boolean isVisible() {
  528.       return this.popup != null ? this.popup.isShowing() : false;
  529.    }
  530.  
  531.    public void setLocation(int var1, int var2) {
  532.       if (this.popup != null) {
  533.          this.popup.setLocationOnScreen(var1, var2);
  534.       } else {
  535.          this.desiredLocationX = var1;
  536.          this.desiredLocationY = var2;
  537.       }
  538.    }
  539.  
  540.    private boolean isPopupMenu() {
  541.       return this.invoker != null && !(this.invoker instanceof JMenu);
  542.    }
  543.  
  544.    public Component getInvoker() {
  545.       return this.invoker;
  546.    }
  547.  
  548.    public void setInvoker(Component var1) {
  549.       Component var2 = this.invoker;
  550.       this.invoker = var1;
  551.       if (var2 != this.invoker && super.ui != null) {
  552.          super.ui.uninstallUI(this);
  553.          super.ui.installUI(this);
  554.       }
  555.  
  556.       ((Container)this).invalidate();
  557.    }
  558.  
  559.    public void show(Component var1, int var2, int var3) {
  560.       this.setInvoker(var1);
  561.       Frame var4 = getFrame(var1);
  562.       if (var4 != this.frame && var4 != null) {
  563.          this.frame = var4;
  564.          if (this.popup != null) {
  565.             this.setVisible(false);
  566.          }
  567.       }
  568.  
  569.       Point var5 = var1.getLocationOnScreen();
  570.       this.setLocation(var5.x + var2, var5.y + var3);
  571.       this.setVisible(true);
  572.    }
  573.  
  574.    JPopupMenu getRootPopupMenu() {
  575.       JPopupMenu var1;
  576.       for(var1 = this; var1 != null && !var1.isPopupMenu() && var1.getInvoker() != null && var1.getInvoker().getParent() != null && var1.getInvoker().getParent() instanceof JPopupMenu; var1 = (JPopupMenu)var1.getInvoker().getParent()) {
  577.       }
  578.  
  579.       return var1;
  580.    }
  581.  
  582.    public int getComponentIndex(Component var1) {
  583.       int var2 = ((Container)this).getComponentCount();
  584.       Component[] var3 = ((Container)this).getComponents();
  585.  
  586.       for(int var4 = 0; var4 < var2; ++var4) {
  587.          Component var5 = var3[var4];
  588.          if (var5 == var1) {
  589.             return var4;
  590.          }
  591.       }
  592.  
  593.       return -1;
  594.    }
  595.  
  596.    public Component getComponentAtIndex(int var1) {
  597.       int var2 = ((Container)this).getComponentCount();
  598.       if (var1 <= var2) {
  599.          Component[] var3 = ((Container)this).getComponents();
  600.          return var3[var1];
  601.       } else {
  602.          return null;
  603.       }
  604.    }
  605.  
  606.    public void setPopupSize(Dimension var1) {
  607.       this.popup.setSize(var1.width, var1.height);
  608.    }
  609.  
  610.    public void setPopupSize(int var1, int var2) {
  611.       this.popup.setSize(var1, var2);
  612.    }
  613.  
  614.    public void setSelected(Component var1) {
  615.       SingleSelectionModel var2 = this.getSelectionModel();
  616.       int var3 = this.getComponentIndex(var1);
  617.       var2.setSelectedIndex(var3);
  618.    }
  619.  
  620.    public boolean isBorderPainted() {
  621.       return this.paintBorder;
  622.    }
  623.  
  624.    public void setBorderPainted(boolean var1) {
  625.       this.paintBorder = var1;
  626.       ((Component)this).repaint();
  627.    }
  628.  
  629.    protected void paintBorder(Graphics var1) {
  630.       if (this.isBorderPainted()) {
  631.          super.paintBorder(var1);
  632.       }
  633.  
  634.    }
  635.  
  636.    public Insets getMargin() {
  637.       return this.margin == null ? new Insets(0, 0, 0, 0) : this.margin;
  638.    }
  639.  
  640.    boolean isSubPopupMenu(JPopupMenu var1) {
  641.       int var2 = ((Container)this).getComponentCount();
  642.       Component[] var3 = ((Container)this).getComponents();
  643.  
  644.       for(int var4 = 0; var4 < var2; ++var4) {
  645.          Component var5 = var3[var4];
  646.          if (var5 instanceof JMenu) {
  647.             JMenu var6 = (JMenu)var5;
  648.             JPopupMenu var7 = var6.getPopupMenu();
  649.             if (var7 == var1) {
  650.                return true;
  651.             }
  652.  
  653.             if (var7.isSubPopupMenu(var1)) {
  654.                return true;
  655.             }
  656.          }
  657.       }
  658.  
  659.       return false;
  660.    }
  661.  
  662.    private static Window getWindow(Component var0) {
  663.       Object var1;
  664.       for(var1 = var0; !(var1 instanceof Window) && var1 != null; var1 = ((Component)var1).getParent()) {
  665.       }
  666.  
  667.       return (Window)var1;
  668.    }
  669.  
  670.    private static Frame getFrame(Component var0) {
  671.       Object var1;
  672.       for(var1 = var0; !(var1 instanceof Frame) && var1 != null; var1 = ((Component)var1).getParent()) {
  673.       }
  674.  
  675.       return (Frame)var1;
  676.    }
  677.  
  678.    private void requestAddGrab(Component var1, Popup var2) {
  679.       if (this.mouseGrabber == null) {
  680.          this.mouseGrabber = new MouseGrabber(this);
  681.       }
  682.  
  683.       Window var3 = getWindow(var1);
  684.       this.mouseGrabber.grabContainer(var3, var2.getComponent());
  685.    }
  686.  
  687.    private void requestRemoveGrab(Component var1) {
  688.       if (this.mouseGrabber != null) {
  689.          this.mouseGrabber.ungrabContainers();
  690.       }
  691.  
  692.    }
  693.  
  694.    public AccessibleContext getAccessibleContext() {
  695.       if (super.accessibleContext == null) {
  696.          super.accessibleContext = new AccessibleJPopupMenu(this);
  697.       }
  698.  
  699.       return super.accessibleContext;
  700.    }
  701.  
  702.    private void writeObject(ObjectOutputStream var1) throws IOException {
  703.       Vector var2 = new Vector();
  704.       var1.defaultWriteObject();
  705.       if (this.invoker != null && this.invoker instanceof Serializable) {
  706.          var2.addElement("invoker");
  707.          var2.addElement(this.invoker);
  708.       }
  709.  
  710.       if (this.popup != null && this.popup instanceof Serializable) {
  711.          var2.addElement("popup");
  712.          var2.addElement(this.popup);
  713.       }
  714.  
  715.       if (this.frame != null && this.frame instanceof Serializable) {
  716.          var2.addElement("frame");
  717.          var2.addElement(this.frame);
  718.       }
  719.  
  720.       var1.writeObject(var2);
  721.    }
  722.  
  723.    private void readObject(ObjectInputStream var1) throws IOException, ClassNotFoundException {
  724.       var1.defaultReadObject();
  725.       Vector var2 = (Vector)var1.readObject();
  726.       int var3 = 0;
  727.       int var4 = var2.size();
  728.       if (var3 < var4 && var2.elementAt(var3).equals("invoker")) {
  729.          ++var3;
  730.          this.invoker = (Component)var2.elementAt(var3);
  731.          ++var3;
  732.       }
  733.  
  734.       if (var3 < var4 && var2.elementAt(var3).equals("popup")) {
  735.          ++var3;
  736.          this.popup = (Popup)var2.elementAt(var3);
  737.          ++var3;
  738.       }
  739.  
  740.       if (var3 < var4 && var2.elementAt(var3).equals("frame")) {
  741.          ++var3;
  742.          this.frame = (Frame)var2.elementAt(var3);
  743.          ++var3;
  744.       }
  745.  
  746.    }
  747.  
  748.    public void processMouseEvent(MouseEvent var1, MenuElement[] var2, MenuSelectionManager var3) {
  749.    }
  750.  
  751.    public void processKeyEvent(KeyEvent var1, MenuElement[] var2, MenuSelectionManager var3) {
  752.    }
  753.  
  754.    public void menuSelectionChanged(boolean var1) {
  755.       if (this.invoker instanceof JMenu) {
  756.          JMenu var2 = (JMenu)this.invoker;
  757.          if (var1) {
  758.             var2.setPopupMenuVisible(true);
  759.          } else {
  760.             var2.setPopupMenuVisible(false);
  761.          }
  762.       }
  763.  
  764.       if (this.isPopupMenu() && !var1) {
  765.          this.setVisible(false);
  766.       }
  767.  
  768.    }
  769.  
  770.    public MenuElement[] getSubElements() {
  771.       Vector var2 = new Vector();
  772.       int var3 = ((Container)this).getComponentCount();
  773.  
  774.       for(int var4 = 0; var4 < var3; ++var4) {
  775.          Component var5 = ((Container)this).getComponent(var4);
  776.          if (var5 instanceof MenuElement) {
  777.             var2.addElement(var5);
  778.          }
  779.       }
  780.  
  781.       MenuElement[] var1 = new MenuElement[var2.size()];
  782.       int var7 = 0;
  783.  
  784.       for(int var6 = var2.size(); var7 < var6; ++var7) {
  785.          var1[var7] = (MenuElement)var2.elementAt(var7);
  786.       }
  787.  
  788.       return var1;
  789.    }
  790.  
  791.    public Component getComponent() {
  792.       return this;
  793.    }
  794.  
  795.    // $FF: synthetic method
  796.    static Hashtable access$0() {
  797.       return getHeavyPopupCache();
  798.    }
  799. }
  800.