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

Print this page


   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


 157         this.tearOff = tearOff;
 158     }
 159 
 160     /**
 161      * Construct a name for this MenuComponent.  Called by getName() when
 162      * the name is null.
 163      */
 164     String constructComponentName() {
 165         synchronized (Menu.class) {
 166             return base + nameCounter++;
 167         }
 168     }
 169 
 170     /**
 171      * Creates the menu's peer.  The peer allows us to modify the
 172      * appearance of the menu without changing its functionality.
 173      */
 174     public void addNotify() {
 175         synchronized (getTreeLock()) {
 176             if (peer == null)
 177                 peer = Toolkit.getDefaultToolkit().createMenu(this);
 178             int nitems = getItemCount();
 179             for (int i = 0 ; i < nitems ; i++) {
 180                 MenuItem mi = getItem(i);
 181                 mi.parent = this;
 182                 mi.addNotify();
 183             }
 184         }
 185     }
 186 
 187     /**
 188      * Removes the menu's peer.  The peer allows us to modify the appearance
 189      * of the menu without changing its functionality.
 190      */
 191     public void removeNotify() {
 192         synchronized (getTreeLock()) {
 193             int nitems = getItemCount();
 194             for (int i = 0 ; i < nitems ; i++) {
 195                 getItem(i).removeNotify();
 196             }
 197             super.removeNotify();


   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


 157         this.tearOff = tearOff;
 158     }
 159 
 160     /**
 161      * Construct a name for this MenuComponent.  Called by getName() when
 162      * the name is null.
 163      */
 164     String constructComponentName() {
 165         synchronized (Menu.class) {
 166             return base + nameCounter++;
 167         }
 168     }
 169 
 170     /**
 171      * Creates the menu's peer.  The peer allows us to modify the
 172      * appearance of the menu without changing its functionality.
 173      */
 174     public void addNotify() {
 175         synchronized (getTreeLock()) {
 176             if (peer == null)
 177                 peer = getComponentFactory().createMenu(this);
 178             int nitems = getItemCount();
 179             for (int i = 0 ; i < nitems ; i++) {
 180                 MenuItem mi = getItem(i);
 181                 mi.parent = this;
 182                 mi.addNotify();
 183             }
 184         }
 185     }
 186 
 187     /**
 188      * Removes the menu's peer.  The peer allows us to modify the appearance
 189      * of the menu without changing its functionality.
 190      */
 191     public void removeNotify() {
 192         synchronized (getTreeLock()) {
 193             int nitems = getItemCount();
 194             for (int i = 0 ; i < nitems ; i++) {
 195                 getItem(i).removeNotify();
 196             }
 197             super.removeNotify();