< prev index next >

src/java.desktop/share/classes/java/awt/MenuComponent.java

Print this page


   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
  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} is the superclass
  42  * of all menu-related components. In this respect, the class
  43  * {@code MenuComponent} is analogous to the abstract superclass
  44  * {@code Component} for AWT components.
  45  * <p>
  46  * Menu components receive and process AWT events, just as components do,
  47  * through the method {@code processEvent}.
  48  *
  49  * @author      Arthur van Hoff
  50  * @since       1.0
  51  */
  52 public abstract class MenuComponent implements java.io.Serializable {
  53 
  54     static {
  55         /* ensure that the necessary native libraries are loaded */
  56         Toolkit.loadLibraries();
  57         if (!GraphicsEnvironment.isHeadless()) {
  58             initIDs();
  59         }
  60     }
  61 
  62     transient volatile MenuComponentPeer peer;
  63     transient MenuContainer parent;
  64 
  65     /**
  66      * The {@code AppContext} of the {@code MenuComponent}.
  67      * This is set in the constructor and never changes.
  68      */
  69     transient AppContext appContext;
  70 
  71     /**
  72      * The menu component's font. This value can be
  73      * {@code null} at which point a default will be used.
  74      * This defaults to {@code null}.
  75      *
  76      * @serial
  77      * @see #setFont(Font)
  78      * @see #getFont()
  79      */
  80     volatile Font font;
  81 
  82     /**
  83      * The menu component's name, which defaults to {@code null}.
  84      * @serial
  85      * @see #getName()
  86      * @see #setName(String)
  87      */
  88     private String name;
  89 
  90     /**
  91      * A variable to indicate whether a name is explicitly set.
  92      * If {@code true} the name will be set explicitly.
  93      * This defaults to {@code false}.
  94      * @serial
  95      * @see #setName(String)
  96      */
  97     private boolean nameExplicitlySet = false;
  98 
  99     /**
 100      * Defaults to {@code false}.
 101      * @serial
 102      * @see #dispatchEvent(AWTEvent)
 103      */
 104     boolean newEventsOnly = false;
 105 
 106     /*
 107      * The menu's AccessControlContext.
 108      */
 109     private transient volatile AccessControlContext acc =
 110             AccessController.getContext();
 111 
 112     /*
 113      * Returns the acc this menu component was constructed with.
 114      */
 115     final AccessControlContext getAccessControlContext() {
 116         if (acc == null) {
 117             throw new SecurityException(
 118                     "MenuComponent is missing AccessControlContext");
 119         }
 120         return acc;
 121     }
 122 
 123     /*
 124      * Internal constants for serialization.


   1 /*
   2  * Copyright (c) 1995, 2016, 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
  23  * questions.
  24  */
  25 
  26 package java.awt;
  27 

  28 import java.awt.event.ActionEvent;
  29 import java.awt.peer.MenuComponentPeer;
  30 import java.io.IOException;
  31 import java.io.ObjectInputStream;






  32 import java.security.AccessControlContext;
  33 import java.security.AccessController;
  34 
  35 import javax.accessibility.Accessible;
  36 import javax.accessibility.AccessibleComponent;
  37 import javax.accessibility.AccessibleContext;
  38 import javax.accessibility.AccessibleRole;
  39 import javax.accessibility.AccessibleSelection;
  40 import javax.accessibility.AccessibleState;
  41 import javax.accessibility.AccessibleStateSet;
  42 
  43 import sun.awt.AWTAccessor;
  44 import sun.awt.AppContext;
  45 import sun.awt.ComponentFactory;
  46 
  47 /**
  48  * The abstract class {@code MenuComponent} is the superclass
  49  * of all menu-related components. In this respect, the class
  50  * {@code MenuComponent} is analogous to the abstract superclass
  51  * {@code Component} for AWT components.
  52  * <p>
  53  * Menu components receive and process AWT events, just as components do,
  54  * through the method {@code processEvent}.
  55  *
  56  * @author      Arthur van Hoff
  57  * @since       1.0
  58  */
  59 public abstract class MenuComponent implements java.io.Serializable {
  60 
  61     static {
  62         /* ensure that the necessary native libraries are loaded */
  63         Toolkit.loadLibraries();
  64         if (!GraphicsEnvironment.isHeadless()) {
  65             initIDs();
  66         }
  67     }
  68 
  69     transient volatile MenuComponentPeer peer;
  70     transient volatile MenuContainer parent;
  71 
  72     /**
  73      * The {@code AppContext} of the {@code MenuComponent}.
  74      * This is set in the constructor and never changes.
  75      */
  76     private transient volatile AppContext appContext;
  77 
  78     /**
  79      * The menu component's font. This value can be
  80      * {@code null} at which point a default will be used.
  81      * This defaults to {@code null}.
  82      *
  83      * @serial
  84      * @see #setFont(Font)
  85      * @see #getFont()
  86      */
  87     private volatile Font font;
  88 
  89     /**
  90      * The menu component's name, which defaults to {@code null}.
  91      * @serial
  92      * @see #getName()
  93      * @see #setName(String)
  94      */
  95     private volatile String name;
  96 
  97     /**
  98      * A variable to indicate whether a name is explicitly set.
  99      * If {@code true} the name will be set explicitly.
 100      * This defaults to {@code false}.
 101      * @serial
 102      * @see #setName(String)
 103      */
 104     private volatile boolean nameExplicitlySet;
 105 
 106     /**
 107      * Defaults to {@code false}.
 108      * @serial
 109      * @see #dispatchEvent(AWTEvent)
 110      */
 111     volatile boolean newEventsOnly;
 112 
 113     /*
 114      * The menu's AccessControlContext.
 115      */
 116     private transient volatile AccessControlContext acc =
 117             AccessController.getContext();
 118 
 119     /*
 120      * Returns the acc this menu component was constructed with.
 121      */
 122     final AccessControlContext getAccessControlContext() {
 123         if (acc == null) {
 124             throw new SecurityException(
 125                     "MenuComponent is missing AccessControlContext");
 126         }
 127         return acc;
 128     }
 129 
 130     /*
 131      * Internal constants for serialization.


< prev index next >