Path: blob/master/src/java.desktop/unix/classes/sun/awt/X11/XCheckboxMenuItemPeer.java
41159 views
/*1* Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.awt.X11;2627import java.awt.*;28import java.awt.peer.*;29import java.awt.event.*;3031import sun.awt.AWTAccessor;3233final class XCheckboxMenuItemPeer extends XMenuItemPeer34implements CheckboxMenuItemPeer {3536/************************************************37*38* Construction39*40************************************************/41XCheckboxMenuItemPeer(CheckboxMenuItem target) {42super(target);43}4445/************************************************46*47* Implementaion of interface methods48*49************************************************/5051//Prom CheckboxMenuItemtPeer52@Override53public void setState(boolean t) {54repaintIfShowing();55}5657/************************************************58*59* Access to target's fields60*61************************************************/62boolean getTargetState() {63return AWTAccessor.getCheckboxMenuItemAccessor()64.getState((CheckboxMenuItem)getTarget());65}6667/************************************************68*69* Utility functions70*71************************************************/7273/**74* Toggles state and generates ItemEvent75*/76@Override77void action(long when, int modifiers) {78XToolkit.executeOnEventHandlerThread((CheckboxMenuItem)getTarget(), new Runnable() {79@Override80public void run() {81doToggleState(when);82}83});84}858687/************************************************88*89* Private90*91************************************************/92private void doToggleState(long when) {93CheckboxMenuItem cb = (CheckboxMenuItem)getTarget();94boolean newState = !getTargetState();95cb.setState(newState);96ItemEvent e = new ItemEvent(cb,97ItemEvent.ITEM_STATE_CHANGED,98getTargetLabel(),99getTargetState() ? ItemEvent.SELECTED : ItemEvent.DESELECTED);100XWindow.postEventStatic(e);101//WToolkit does not post ActionEvent when clicking on menu item102//MToolkit _does_ post.103//Fix for 5005195 MAWT: CheckboxMenuItem fires action events104//Events should not be fired105//XWindow.postEventStatic(new ActionEvent(cb, ActionEvent.ACTION_PERFORMED,106// getTargetActionCommand(), when,107// 0));108}109110} // class XCheckboxMenuItemPeer111112113