src/java.desktop/share/classes/javax/swing/JPopupMenu.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -20,34 +20,30 @@
  *
  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
-
 package javax.swing;
 
 import java.awt.*;
 import java.awt.event.*;
 import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.io.Serializable;
-import java.beans.*;
+import java.beans.JavaBean;
+import java.beans.BeanProperty;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
 
-import java.util.Locale;
 import java.util.Vector;
-import java.util.Hashtable;
 import javax.accessibility.*;
 import javax.swing.plaf.PopupMenuUI;
-import javax.swing.plaf.ComponentUI;
 import javax.swing.plaf.basic.BasicComboPopup;
 import javax.swing.event.*;
 
 import sun.awt.SunToolkit;
-import sun.security.util.SecurityConstants;
-
-import java.applet.Applet;
 
 /**
  * An implementation of a popup menu -- a small window that pops up
  * and displays a series of choices. A <code>JPopupMenu</code> is used for the
  * menu that appears when the user selects an item on the menu bar.

@@ -73,19 +69,17 @@
  * the same version of Swing.  As of 1.4, support for long term storage
  * of all JavaBeans&trade;
  * has been added to the <code>java.beans</code> package.
  * Please see {@link java.beans.XMLEncoder}.
  *
- * @beaninfo
- *   attribute: isContainer false
- * description: A small window that pops up and displays a series of choices.
- *
  * @author Georges Saab
  * @author David Karlton
  * @author Arnaud Weber
  * @since 1.2
  */
+@JavaBean(defaultProperty = "UI", description = "A small window that pops up and displays a series of choices.")
+@SwingContainer(false)
 @SuppressWarnings("serial")
 public class JPopupMenu extends JComponent implements Accessible,MenuElement {
 
     /**
      * @see #getUIClassID

@@ -208,16 +202,13 @@
     /**
      * Sets the L&amp;F object that renders this component.
      *
      * @param ui the new <code>PopupMenuUI</code> L&amp;F object
      * @see UIDefaults#getUI
-     * @beaninfo
-     *        bound: true
-     *       hidden: true
-     *    attribute: visualUpdate true
-     *  description: The UI object that implements the Component's LookAndFeel.
      */
+    @BeanProperty(hidden = true, visualUpdate = true, description
+            = "The UI object that implements the Component's LookAndFeel.")
     public void setUI(PopupMenuUI ui) {
         super.setUI(ui);
     }
 
     /**

@@ -235,10 +226,11 @@
      *
      * @return the string "PopupMenuUI"
      * @see JComponent#getUIClassID
      * @see UIDefaults#getUI
      */
+    @BeanProperty(bound = false)
     public String getUIClassID() {
         return uiClassID;
     }
 
     protected void processFocusEvent(FocusEvent evt) {

@@ -272,14 +264,13 @@
     /**
      * Sets the model object to handle single selections.
      *
      * @param model the new <code>SingleSelectionModel</code>
      * @see SingleSelectionModel
-     * @beaninfo
-     * description: The selection model for the popup menu
-     *      expert: true
      */
+    @BeanProperty(bound = false, expert = true, description
+            = "The selection model for the popup menu")
     public void setSelectionModel(SingleSelectionModel model) {
         selectionModel = model;
     }
 
     /**

@@ -493,16 +484,15 @@
      * you should disable lightweight popups.
      * Some look and feels might always use heavyweight popups,
      * no matter what the value of this property.
      *
      * @param aFlag  <code>false</code> to disable lightweight popups
-     * @beaninfo
-     * description: Determines whether lightweight popups are used when possible
-     *      expert: true
      *
      * @see #isLightWeightPopupEnabled
      */
+    @BeanProperty(bound = false, expert = true, description
+            = "Determines whether lightweight popups are used when possible")
     public void setLightWeightPopupEnabled(boolean aFlag) {
         // NOTE: this use to set the flag on a shared JPopupMenu, which meant
         // this effected ALL JPopupMenus.
         lightWeightPopup = aFlag;
     }

@@ -532,14 +522,13 @@
      * to display or not display this.
      *
      * @param label a string specifying the label for the popup menu
      *
      * @see #setLabel
-     * @beaninfo
-     * description: The label for the popup menu.
-     *       bound: true
      */
+    @BeanProperty(description
+            = "The label for the popup menu.")
     public void setLabel(String label) {
         String oldValue = this.label;
         this.label = label;
         firePropertyChange("label", oldValue, label);
         if (accessibleContext != null) {

@@ -635,10 +624,11 @@
      *
      * @return all of the <code>PopupMenuListener</code>s added or an empty
      *         array if no listeners have been added
      * @since 1.4
      */
+    @BeanProperty(bound = false)
     public PopupMenuListener[] getPopupMenuListeners() {
         return listenerList.getListeners(PopupMenuListener.class);
     }
 
     /**

@@ -667,10 +657,11 @@
      *
      * @return all of the <code>MenuKeyListener</code>s added or an empty
      *         array if no listeners have been added
      * @since 1.5
      */
+    @BeanProperty(bound = false)
     public MenuKeyListener[] getMenuKeyListeners() {
         return listenerList.getListeners(MenuKeyListener.class);
     }
 
     /**

@@ -751,14 +742,13 @@
     /**
      * Sets the visibility of the popup menu.
      *
      * @param b true to make the popup visible, or false to
      *          hide it
-     * @beaninfo
-     *           bound: true
-     *     description: Makes the popup visible
      */
+    @BeanProperty(description
+            = "Makes the popup visible")
     public void setVisible(boolean b) {
         if (DEBUG) {
             System.out.println("JPopupMenu.setVisible " + b);
         }
 

@@ -866,13 +856,13 @@
      *
      * @param x the x coordinate of the popup's new position
      *          in the screen's coordinate space
      * @param y the y coordinate of the popup's new position
      *          in the screen's coordinate space
-     * @beaninfo
-     * description: The location of the popup menu.
      */
+    @BeanProperty(description
+            = "The location of the popup menu.")
     public void setLocation(int x, int y) {
         int oldX = desiredLocationX;
         int oldY = desiredLocationY;
 
         desiredLocationX = x;

@@ -906,14 +896,13 @@
      * Sets the invoker of this popup menu -- the component in which
      * the popup menu menu is to be displayed.
      *
      * @param invoker the <code>Component</code> in which the popup
      *          menu is displayed
-     * @beaninfo
-     * description: The invoking component for the popup menu
-     *      expert: true
      */
+    @BeanProperty(bound = false, expert = true, description
+            = "The invoking component for the popup menu")
     public void setInvoker(Component invoker) {
         Component oldInvoker = this.invoker;
         this.invoker = invoker;
         if ((oldInvoker != this.invoker) && (ui != null)) {
             ui.uninstallUI(this);

@@ -1022,13 +1011,13 @@
      * Sets the size of the Popup window using a <code>Dimension</code> object.
      * This is equivalent to <code>setPreferredSize(d)</code>.
      *
      * @param d   the <code>Dimension</code> specifying the new size
      * of this component.
-     * @beaninfo
-     * description: The size of the popup menu
      */
+    @BeanProperty(description
+            = "The size of the popup menu")
     public void setPopupSize(Dimension d) {
         Dimension oldSize = getPreferredSize();
 
         setPreferredSize(d);
         if (popup != null) {

@@ -1045,27 +1034,25 @@
      * height. This is equivalent to
      *  <code>setPreferredSize(new Dimension(width, height))</code>.
      *
      * @param width the new width of the Popup in pixels
      * @param height the new height of the Popup in pixels
-     * @beaninfo
-     * description: The size of the popup menu
      */
+    @BeanProperty(description
+            = "The size of the popup menu")
     public void setPopupSize(int width, int height) {
         setPopupSize(new Dimension(width, height));
     }
 
     /**
      * Sets the currently selected component,  This will result
      * in a change to the selection model.
      *
      * @param sel the <code>Component</code> to select
-     * @beaninfo
-     * description: The selected component on the popup menu
-     *      expert: true
-     *      hidden: true
      */
+    @BeanProperty(expert = true, hidden = true, description
+            = "The selected component on the popup menu")
     public void setSelected(Component sel) {
         SingleSelectionModel model = getSelectionModel();
         int index = getComponentIndex(sel);
         model.setSelectedIndex(index);
     }

@@ -1083,13 +1070,13 @@
     /**
      * Sets whether the border should be painted.
      *
      * @param b if true, the border is painted.
      * @see #isBorderPainted
-     * @beaninfo
-     * description: Is the border of the popup menu painted
      */
+    @BeanProperty(bound = false, description
+            = "Is the border of the popup menu painted")
     public void setBorderPainted(boolean b) {
         paintBorder = b;
         repaint();
     }
 

@@ -1111,10 +1098,11 @@
      * Returns the margin, in pixels, between the popup menu's border and
      * its containers.
      *
      * @return an <code>Insets</code> object containing the margin values.
      */
+    @BeanProperty(bound = false)
     public Insets getMargin() {
         if(margin == null) {
             return new Insets(0,0,0,0);
         } else {
             return margin;

@@ -1196,10 +1184,11 @@
      * A new AccessibleJPopupMenu instance is created if necessary.
      *
      * @return an AccessibleJPopupMenu that serves as the
      *         AccessibleContext of this JPopupMenu
      */
+    @BeanProperty(bound = false)
     public AccessibleContext getAccessibleContext() {
         if (accessibleContext == null) {
             accessibleContext = new AccessibleJPopupMenu();
         }
         return accessibleContext;

@@ -1510,10 +1499,11 @@
      * <code>MenuElement</code> interface.
      *
      * @return an array of <code>MenuElement</code> objects
      * @see MenuElement#getSubElements
      */
+    @BeanProperty(bound = false)
     public MenuElement[] getSubElements() {
         MenuElement result[];
         Vector<MenuElement> tmp = new Vector<MenuElement>();
         int c = getComponentCount();
         int i;