src/macosx/classes/sun/lwawt/macosx/CMenu.java

Print this page




   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 sun.lwawt.macosx;
  27 
  28 import java.awt.*;

  29 import java.awt.peer.MenuPeer;
  30 
  31 public class CMenu extends CMenuItem implements MenuPeer {

  32     public CMenu(Menu target) {
  33         super(target);
  34     }
  35 
  36     // This way we avoiding invocation of the setters twice
  37     @Override
  38     protected void initialize(MenuItem target) {
  39         setLabel(target.getLabel());
  40         setEnabled(target.isEnabled());














  41     }
  42 
  43     @Override
  44     protected long createModel() {
  45         CMenuComponent parent = (CMenuComponent)
  46             LWCToolkit.targetToPeer(getTarget().getParent());
  47 
  48         if (parent instanceof CMenu ||
  49             parent instanceof CPopupMenu)
  50         {
  51             return nativeCreateSubMenu(parent.getModel());
  52         } else if (parent instanceof CMenuBar) {
  53             MenuBar parentContainer = (MenuBar)getTarget().getParent();
  54             boolean isHelpMenu = parentContainer.getHelpMenu() == getTarget();
  55             int insertionLocation = ((CMenuBar)parent).getNextInsertionIndex();
  56             return nativeCreateMenu(parent.getModel(),
  57                                     isHelpMenu, insertionLocation);
  58         } else {
  59             throw new InternalError("Parent must be CMenu or CMenuBar");
  60         }




   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 sun.lwawt.macosx;
  27 
  28 import java.awt.*;
  29 import java.awt.peer.MenuItemPeer;
  30 import java.awt.peer.MenuPeer;
  31 
  32 public class CMenu extends CMenuItem implements MenuPeer {
  33 
  34     public CMenu(Menu target) {
  35         super(target);
  36     }
  37 
  38     // This way we avoiding invocation of the setters twice
  39     @Override
  40     protected void initialize(MenuItem target) {
  41         setLabel(target.getLabel());
  42         setEnabled(target.isEnabled());
  43     }
  44 
  45     @Override
  46     public final void setEnabled(final boolean b) {
  47         super.setEnabled(b);
  48         final Menu target = (Menu) getTarget();
  49         final int count = target.getItemCount();
  50         for (int i = 0; i < count; ++i) {
  51             MenuItem item = target.getItem(i);
  52             MenuItemPeer p = (MenuItemPeer) LWCToolkit.targetToPeer(item);
  53             if (p != null) {
  54                 p.setEnabled(b && item.isEnabled());
  55             }
  56         }
  57     }
  58 
  59     @Override
  60     protected long createModel() {
  61         CMenuComponent parent = (CMenuComponent)
  62             LWCToolkit.targetToPeer(getTarget().getParent());
  63 
  64         if (parent instanceof CMenu ||
  65             parent instanceof CPopupMenu)
  66         {
  67             return nativeCreateSubMenu(parent.getModel());
  68         } else if (parent instanceof CMenuBar) {
  69             MenuBar parentContainer = (MenuBar)getTarget().getParent();
  70             boolean isHelpMenu = parentContainer.getHelpMenu() == getTarget();
  71             int insertionLocation = ((CMenuBar)parent).getNextInsertionIndex();
  72             return nativeCreateMenu(parent.getModel(),
  73                                     isHelpMenu, insertionLocation);
  74         } else {
  75             throw new InternalError("Parent must be CMenu or CMenuBar");
  76         }