< prev index next >

src/java.desktop/macosx/classes/sun/lwawt/macosx/CMenuItem.java

Print this page


   1 /*
   2  * Copyright (c) 2011, 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


 112      * it isn't defined in the peer api.
 113      */
 114     public final void setImage(final java.awt.Image img) {
 115         CImage cimg = CImage.getCreator().createFromImage(img);
 116         execute(ptr -> {
 117             if (cimg == null) {
 118                 nativeSetImage(ptr, 0L);
 119             } else {
 120                 cimg.execute(imgPtr -> nativeSetImage(ptr, imgPtr));
 121             }
 122         });
 123     }
 124 
 125     /**
 126      * New API for tooltips
 127      */
 128     public final void setToolTipText(final String text) {
 129         execute(ptr -> nativeSetTooltip(ptr, text));
 130     }
 131 
 132 //    @Override
 133     public void enable() {
 134         setEnabled(true);
 135     }
 136 
 137 //    @Override
 138     public void disable() {
 139         setEnabled(false);
 140     }
 141 
 142     public final boolean isEnabled() {
 143         return enabled.get();
 144     }
 145 
 146     @Override
 147     public void setEnabled(boolean b) {
 148         final Object parent = LWToolkit.targetToPeer(getTarget().getParent());
 149         if (parent instanceof CMenuItem) {
 150             b &= ((CMenuItem) parent).isEnabled();
 151         }
 152         if (enabled.compareAndSet(!b, b)) {
 153             final boolean finalB = b;
 154             execute(ptr->nativeSetEnabled(ptr, finalB));
 155         }
 156     }
 157 
 158     private native long nativeCreate(long parentMenu, boolean isSeparator);
 159     private native void nativeSetLabel(long modelPtr, String label, char keyChar, int keyCode, int modifiers);
 160     private native void nativeSetImage(long modelPtr, long image);
 161     private native void nativeSetTooltip(long modelPtr, String text);
   1 /*
   2  * Copyright (c) 2011, 2018, 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


 112      * it isn't defined in the peer api.
 113      */
 114     public final void setImage(final java.awt.Image img) {
 115         CImage cimg = CImage.getCreator().createFromImage(img);
 116         execute(ptr -> {
 117             if (cimg == null) {
 118                 nativeSetImage(ptr, 0L);
 119             } else {
 120                 cimg.execute(imgPtr -> nativeSetImage(ptr, imgPtr));
 121             }
 122         });
 123     }
 124 
 125     /**
 126      * New API for tooltips
 127      */
 128     public final void setToolTipText(final String text) {
 129         execute(ptr -> nativeSetTooltip(ptr, text));
 130     }
 131 










 132     public final boolean isEnabled() {
 133         return enabled.get();
 134     }
 135 
 136     @Override
 137     public void setEnabled(boolean b) {
 138         final Object parent = LWToolkit.targetToPeer(getTarget().getParent());
 139         if (parent instanceof CMenuItem) {
 140             b &= ((CMenuItem) parent).isEnabled();
 141         }
 142         if (enabled.compareAndSet(!b, b)) {
 143             final boolean finalB = b;
 144             execute(ptr->nativeSetEnabled(ptr, finalB));
 145         }
 146     }
 147 
 148     private native long nativeCreate(long parentMenu, boolean isSeparator);
 149     private native void nativeSetLabel(long modelPtr, String label, char keyChar, int keyCode, int modifiers);
 150     private native void nativeSetImage(long modelPtr, long image);
 151     private native void nativeSetTooltip(long modelPtr, String text);
< prev index next >