Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/classes/sun/awt/X11/XCheckboxMenuItemPeer.java
32288 views
/*1* Copyright (c) 2003, 2012, 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;3233class XCheckboxMenuItemPeer extends XMenuItemPeer implements CheckboxMenuItemPeer {3435/************************************************36*37* Construction38*39************************************************/40XCheckboxMenuItemPeer(CheckboxMenuItem target) {41super(target);42}4344/************************************************45*46* Implementaion of interface methods47*48************************************************/4950//Prom CheckboxMenuItemtPeer51public void setState(boolean t) {52repaintIfShowing();53}5455/************************************************56*57* Access to target's fields58*59************************************************/60boolean getTargetState() {61return AWTAccessor.getCheckboxMenuItemAccessor()62.getState((CheckboxMenuItem)getTarget());63}6465/************************************************66*67* Utility functions68*69************************************************/7071/**72* Toggles state and generates ItemEvent73*/74void action(final long when) {75XToolkit.executeOnEventHandlerThread((CheckboxMenuItem)getTarget(), new Runnable() {76public void run() {77doToggleState(when);78}79});80}818283/************************************************84*85* Private86*87************************************************/88private void doToggleState(long when) {89CheckboxMenuItem cb = (CheckboxMenuItem)getTarget();90boolean newState = !getTargetState();91cb.setState(newState);92ItemEvent e = new ItemEvent(cb,93ItemEvent.ITEM_STATE_CHANGED,94getTargetLabel(),95getTargetState() ? ItemEvent.SELECTED : ItemEvent.DESELECTED);96XWindow.postEventStatic(e);97//WToolkit does not post ActionEvent when clicking on menu item98//MToolkit _does_ post.99//Fix for 5005195 MAWT: CheckboxMenuItem fires action events100//Events should not be fired101//XWindow.postEventStatic(new ActionEvent(cb, ActionEvent.ACTION_PERFORMED,102// getTargetActionCommand(), when,103// 0));104}105106} // class XCheckboxMenuItemPeer107108109