33 |
33 |
34 /** |
34 /** |
35 * A class that implements a menu which can be dynamically popped up |
35 * A class that implements a menu which can be dynamically popped up |
36 * at a specified position within a component. |
36 * at a specified position within a component. |
37 * <p> |
37 * <p> |
38 * As the inheritance hierarchy implies, a <code>PopupMenu</code> |
38 * As the inheritance hierarchy implies, a {@code PopupMenu} |
39 * can be used anywhere a <code>Menu</code> can be used. |
39 * can be used anywhere a {@code Menu} can be used. |
40 * However, if you use a <code>PopupMenu</code> like a <code>Menu</code> |
40 * However, if you use a {@code PopupMenu} like a {@code Menu} |
41 * (e.g., you add it to a <code>MenuBar</code>), then you <b>cannot</b> |
41 * (e.g., you add it to a {@code MenuBar}), then you <b>cannot</b> |
42 * call <code>show</code> on that <code>PopupMenu</code>. |
42 * call {@code show} on that {@code PopupMenu}. |
43 * |
43 * |
44 * @author Amy Fowler |
44 * @author Amy Fowler |
45 */ |
45 */ |
46 public class PopupMenu extends Menu { |
46 public class PopupMenu extends Menu { |
47 |
47 |
75 } |
75 } |
76 |
76 |
77 /** |
77 /** |
78 * Creates a new popup menu with the specified name. |
78 * Creates a new popup menu with the specified name. |
79 * |
79 * |
80 * @param label a non-<code>null</code> string specifying |
80 * @param label a non-{@code null} string specifying |
81 * the popup menu's label |
81 * the popup menu's label |
82 * @exception HeadlessException if GraphicsEnvironment.isHeadless() |
82 * @exception HeadlessException if GraphicsEnvironment.isHeadless() |
83 * returns true. |
83 * returns true. |
84 * @see java.awt.GraphicsEnvironment#isHeadless |
84 * @see java.awt.GraphicsEnvironment#isHeadless |
85 */ |
85 */ |
96 } |
96 } |
97 return super.getParent(); |
97 return super.getParent(); |
98 } |
98 } |
99 |
99 |
100 /** |
100 /** |
101 * Constructs a name for this <code>MenuComponent</code>. |
101 * Constructs a name for this {@code MenuComponent}. |
102 * Called by <code>getName</code> when the name is <code>null</code>. |
102 * Called by {@code getName} when the name is {@code null}. |
103 */ |
103 */ |
104 String constructComponentName() { |
104 String constructComponentName() { |
105 synchronized (PopupMenu.class) { |
105 synchronized (PopupMenu.class) { |
106 return base + nameCounter++; |
106 return base + nameCounter++; |
107 } |
107 } |
137 * component. |
137 * component. |
138 * The origin component must be contained within the component |
138 * The origin component must be contained within the component |
139 * hierarchy of the popup menu's parent. Both the origin and the parent |
139 * hierarchy of the popup menu's parent. Both the origin and the parent |
140 * must be showing on the screen for this method to be valid. |
140 * must be showing on the screen for this method to be valid. |
141 * <p> |
141 * <p> |
142 * If this <code>PopupMenu</code> is being used as a <code>Menu</code> |
142 * If this {@code PopupMenu} is being used as a {@code Menu} |
143 * (i.e., it has a non-<code>Component</code> parent), |
143 * (i.e., it has a non-{@code Component} parent), |
144 * then you cannot call this method on the <code>PopupMenu</code>. |
144 * then you cannot call this method on the {@code PopupMenu}. |
145 * |
145 * |
146 * @param origin the component which defines the coordinate space |
146 * @param origin the component which defines the coordinate space |
147 * @param x the x coordinate position to popup the menu |
147 * @param x the x coordinate position to popup the menu |
148 * @param y the y coordinate position to popup the menu |
148 * @param y the y coordinate position to popup the menu |
149 * @exception NullPointerException if the parent is <code>null</code> |
149 * @exception NullPointerException if the parent is {@code null} |
150 * @exception IllegalArgumentException if this <code>PopupMenu</code> |
150 * @exception IllegalArgumentException if this {@code PopupMenu} |
151 * has a non-<code>Component</code> parent |
151 * has a non-{@code Component} parent |
152 * @exception IllegalArgumentException if the origin is not in the |
152 * @exception IllegalArgumentException if the origin is not in the |
153 * parent's hierarchy |
153 * parent's hierarchy |
154 * @exception RuntimeException if the parent is not showing on screen |
154 * @exception RuntimeException if the parent is not showing on screen |
155 */ |
155 */ |
156 public void show(Component origin, int x, int y) { |
156 public void show(Component origin, int x, int y) { |
194 ///////////////// |
194 ///////////////// |
195 // Accessibility support |
195 // Accessibility support |
196 //////////////// |
196 //////////////// |
197 |
197 |
198 /** |
198 /** |
199 * Gets the <code>AccessibleContext</code> associated with this |
199 * Gets the {@code AccessibleContext} associated with this |
200 * <code>PopupMenu</code>. |
200 * {@code PopupMenu}. |
201 * |
201 * |
202 * @return the <code>AccessibleContext</code> of this |
202 * @return the {@code AccessibleContext} of this |
203 * <code>PopupMenu</code> |
203 * {@code PopupMenu} |
204 * @since 1.3 |
204 * @since 1.3 |
205 */ |
205 */ |
206 public AccessibleContext getAccessibleContext() { |
206 public AccessibleContext getAccessibleContext() { |
207 if (accessibleContext == null) { |
207 if (accessibleContext == null) { |
208 accessibleContext = new AccessibleAWTPopupMenu(); |
208 accessibleContext = new AccessibleAWTPopupMenu(); |