1 /*
2 * Copyright (c) 1995, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
40 * of all menu-related components. In this respect, the class
41 * <code>MenuComponent</code> is analogous to the abstract superclass
42 * <code>Component</code> for AWT components.
43 * <p>
44 * Menu components receive and process AWT events, just as components do,
45 * through the method <code>processEvent</code>.
46 *
47 * @author Arthur van Hoff
48 * @since 1.0
49 */
50 public abstract class MenuComponent implements java.io.Serializable {
51
52 static {
53 /* ensure that the necessary native libraries are loaded */
54 Toolkit.loadLibraries();
55 if (!GraphicsEnvironment.isHeadless()) {
56 initIDs();
57 }
58 }
59
60 transient MenuComponentPeer peer;
61 transient MenuContainer parent;
62
63 /**
64 * The <code>AppContext</code> of the <code>MenuComponent</code>.
65 * This is set in the constructor and never changes.
66 */
67 transient AppContext appContext;
68
69 /**
70 * The menu component's font. This value can be
71 * <code>null</code> at which point a default will be used.
72 * This defaults to <code>null</code>.
73 *
74 * @serial
75 * @see #setFont(Font)
76 * @see #getFont()
77 */
78 Font font;
79
80 /**
125 final static String itemListenerK = Component.itemListenerK;
126
127 /*
128 * JDK 1.1 serialVersionUID
129 */
130 private static final long serialVersionUID = -4536902356223894379L;
131
132 static {
133 AWTAccessor.setMenuComponentAccessor(
134 new AWTAccessor.MenuComponentAccessor() {
135 @Override
136 public AppContext getAppContext(MenuComponent menuComp) {
137 return menuComp.appContext;
138 }
139 @Override
140 public void setAppContext(MenuComponent menuComp,
141 AppContext appContext) {
142 menuComp.appContext = appContext;
143 }
144 @Override
145 public MenuContainer getParent(MenuComponent menuComp) {
146 return menuComp.parent;
147 }
148 @Override
149 public void setParent(MenuComponent menuComp, MenuContainer menuContainer) {
150 menuComp.parent = menuContainer;
151 }
152 @Override
153 public Font getFont_NoClientCode(MenuComponent menuComp) {
154 return menuComp.getFont_NoClientCode();
155 }
156 });
157 }
158
159 /**
160 * Creates a <code>MenuComponent</code>.
161 * @exception HeadlessException if
162 * <code>GraphicsEnvironment.isHeadless</code>
163 * returns <code>true</code>
164 * @see java.awt.GraphicsEnvironment#isHeadless
209 }
210
211 /**
212 * Returns the parent container for this menu component.
213 * @return the menu component containing this menu component,
214 * or <code>null</code> if this menu component
215 * is the outermost component, the menu bar itself
216 */
217 public MenuContainer getParent() {
218 return getParent_NoClientCode();
219 }
220 // NOTE: This method may be called by privileged threads.
221 // This functionality is implemented in a package-private method
222 // to insure that it cannot be overridden by client subclasses.
223 // DO NOT INVOKE CLIENT CODE ON THIS THREAD!
224 final MenuContainer getParent_NoClientCode() {
225 return parent;
226 }
227
228 /**
229 * @deprecated As of JDK version 1.1,
230 * programs should not directly manipulate peers.
231 * @return the peer for this component
232 */
233 @Deprecated
234 public MenuComponentPeer getPeer() {
235 return peer;
236 }
237
238 /**
239 * Gets the font used for this menu component.
240 * @return the font used in this menu component, if there is one;
241 * <code>null</code> otherwise
242 * @see java.awt.MenuComponent#setFont
243 */
244 public Font getFont() {
245 Font font = this.font;
246 if (font != null) {
247 return font;
248 }
249 MenuContainer parent = this.parent;
250 if (parent != null) {
251 return parent.getFont();
252 }
253 return null;
254 }
255
256 // NOTE: This method may be called by privileged threads.
257 // This functionality is implemented in a package-private method
258 // to insure that it cannot be overridden by client subclasses.
|
1 /*
2 * Copyright (c) 1995, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
40 * of all menu-related components. In this respect, the class
41 * <code>MenuComponent</code> is analogous to the abstract superclass
42 * <code>Component</code> for AWT components.
43 * <p>
44 * Menu components receive and process AWT events, just as components do,
45 * through the method <code>processEvent</code>.
46 *
47 * @author Arthur van Hoff
48 * @since 1.0
49 */
50 public abstract class MenuComponent implements java.io.Serializable {
51
52 static {
53 /* ensure that the necessary native libraries are loaded */
54 Toolkit.loadLibraries();
55 if (!GraphicsEnvironment.isHeadless()) {
56 initIDs();
57 }
58 }
59
60 transient volatile MenuComponentPeer peer;
61 transient MenuContainer parent;
62
63 /**
64 * The <code>AppContext</code> of the <code>MenuComponent</code>.
65 * This is set in the constructor and never changes.
66 */
67 transient AppContext appContext;
68
69 /**
70 * The menu component's font. This value can be
71 * <code>null</code> at which point a default will be used.
72 * This defaults to <code>null</code>.
73 *
74 * @serial
75 * @see #setFont(Font)
76 * @see #getFont()
77 */
78 Font font;
79
80 /**
125 final static String itemListenerK = Component.itemListenerK;
126
127 /*
128 * JDK 1.1 serialVersionUID
129 */
130 private static final long serialVersionUID = -4536902356223894379L;
131
132 static {
133 AWTAccessor.setMenuComponentAccessor(
134 new AWTAccessor.MenuComponentAccessor() {
135 @Override
136 public AppContext getAppContext(MenuComponent menuComp) {
137 return menuComp.appContext;
138 }
139 @Override
140 public void setAppContext(MenuComponent menuComp,
141 AppContext appContext) {
142 menuComp.appContext = appContext;
143 }
144 @Override
145 @SuppressWarnings("unchecked")
146 public <T extends MenuComponentPeer> T getPeer(MenuComponent menuComp) {
147 return (T) menuComp.peer;
148 }
149 @Override
150 public MenuContainer getParent(MenuComponent menuComp) {
151 return menuComp.parent;
152 }
153 @Override
154 public void setParent(MenuComponent menuComp, MenuContainer menuContainer) {
155 menuComp.parent = menuContainer;
156 }
157 @Override
158 public Font getFont_NoClientCode(MenuComponent menuComp) {
159 return menuComp.getFont_NoClientCode();
160 }
161 });
162 }
163
164 /**
165 * Creates a <code>MenuComponent</code>.
166 * @exception HeadlessException if
167 * <code>GraphicsEnvironment.isHeadless</code>
168 * returns <code>true</code>
169 * @see java.awt.GraphicsEnvironment#isHeadless
214 }
215
216 /**
217 * Returns the parent container for this menu component.
218 * @return the menu component containing this menu component,
219 * or <code>null</code> if this menu component
220 * is the outermost component, the menu bar itself
221 */
222 public MenuContainer getParent() {
223 return getParent_NoClientCode();
224 }
225 // NOTE: This method may be called by privileged threads.
226 // This functionality is implemented in a package-private method
227 // to insure that it cannot be overridden by client subclasses.
228 // DO NOT INVOKE CLIENT CODE ON THIS THREAD!
229 final MenuContainer getParent_NoClientCode() {
230 return parent;
231 }
232
233 /**
234 * Gets the font used for this menu component.
235 * @return the font used in this menu component, if there is one;
236 * <code>null</code> otherwise
237 * @see java.awt.MenuComponent#setFont
238 */
239 public Font getFont() {
240 Font font = this.font;
241 if (font != null) {
242 return font;
243 }
244 MenuContainer parent = this.parent;
245 if (parent != null) {
246 return parent.getFont();
247 }
248 return null;
249 }
250
251 // NOTE: This method may be called by privileged threads.
252 // This functionality is implemented in a package-private method
253 // to insure that it cannot be overridden by client subclasses.
|