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 23 * questions. 24 */ 25 package java.awt; 26 27 import java.awt.peer.MenuComponentPeer; 28 import java.awt.event.ActionEvent; 29 import java.io.IOException; 30 import java.io.ObjectInputStream; 31 import sun.awt.AppContext; 32 import sun.awt.AWTAccessor; 33 import javax.accessibility.*; 34 35 import java.security.AccessControlContext; 36 import java.security.AccessController; 37 38 /** 39 * The abstract class <code>MenuComponent</code> is the superclass 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 { 167 * <code>GraphicsEnvironment.isHeadless</code> 168 * returns <code>true</code> 169 * @see java.awt.GraphicsEnvironment#isHeadless 170 */ 171 public MenuComponent() throws HeadlessException { 172 GraphicsEnvironment.checkHeadless(); 173 appContext = AppContext.getAppContext(); 174 } 175 176 /** 177 * Constructs a name for this <code>MenuComponent</code>. 178 * Called by <code>getName</code> when the name is <code>null</code>. 179 * @return a name for this <code>MenuComponent</code> 180 */ 181 String constructComponentName() { 182 return null; // For strict compliance with prior platform versions, a MenuComponent 183 // that doesn't set its name should return null from 184 // getName() 185 } 186 187 /** 188 * Gets the name of the menu component. 189 * @return the name of the menu component 190 * @see java.awt.MenuComponent#setName(java.lang.String) 191 * @since 1.1 192 */ 193 public String getName() { 194 if (name == null && !nameExplicitlySet) { 195 synchronized(this) { 196 if (name == null && !nameExplicitlySet) 197 name = constructComponentName(); 198 } 199 } 200 return name; 201 } 202 203 /** 204 * Sets the name of the component to the specified string. 205 * @param name the name of the menu component 206 * @see java.awt.MenuComponent#getName | 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 23 * questions. 24 */ 25 package java.awt; 26 27 import java.awt.peer.MenuComponentPeer; 28 import java.awt.event.ActionEvent; 29 import java.io.IOException; 30 import java.io.ObjectInputStream; 31 import sun.awt.AppContext; 32 import sun.awt.AWTAccessor; 33 import sun.awt.ComponentFactory; 34 35 import javax.accessibility.*; 36 37 import java.security.AccessControlContext; 38 import java.security.AccessController; 39 40 /** 41 * The abstract class <code>MenuComponent</code> is the superclass 42 * of all menu-related components. In this respect, the class 43 * <code>MenuComponent</code> is analogous to the abstract superclass 44 * <code>Component</code> for AWT components. 45 * <p> 46 * Menu components receive and process AWT events, just as components do, 47 * through the method <code>processEvent</code>. 48 * 49 * @author Arthur van Hoff 50 * @since 1.0 51 */ 52 public abstract class MenuComponent implements java.io.Serializable { 53 54 static { 169 * <code>GraphicsEnvironment.isHeadless</code> 170 * returns <code>true</code> 171 * @see java.awt.GraphicsEnvironment#isHeadless 172 */ 173 public MenuComponent() throws HeadlessException { 174 GraphicsEnvironment.checkHeadless(); 175 appContext = AppContext.getAppContext(); 176 } 177 178 /** 179 * Constructs a name for this <code>MenuComponent</code>. 180 * Called by <code>getName</code> when the name is <code>null</code>. 181 * @return a name for this <code>MenuComponent</code> 182 */ 183 String constructComponentName() { 184 return null; // For strict compliance with prior platform versions, a MenuComponent 185 // that doesn't set its name should return null from 186 // getName() 187 } 188 189 final ComponentFactory getComponentFactory() { 190 final Toolkit toolkit = Toolkit.getDefaultToolkit(); 191 if (toolkit instanceof ComponentFactory) { 192 return (ComponentFactory) toolkit; 193 } 194 throw new AWTError("Unsupported toolkit: " + toolkit); 195 } 196 197 /** 198 * Gets the name of the menu component. 199 * @return the name of the menu component 200 * @see java.awt.MenuComponent#setName(java.lang.String) 201 * @since 1.1 202 */ 203 public String getName() { 204 if (name == null && !nameExplicitlySet) { 205 synchronized(this) { 206 if (name == null && !nameExplicitlySet) 207 name = constructComponentName(); 208 } 209 } 210 return name; 211 } 212 213 /** 214 * Sets the name of the component to the specified string. 215 * @param name the name of the menu component 216 * @see java.awt.MenuComponent#getName |