1 /* 2 * Copyright (c) 2003, 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 23 * questions. 24 */ 25 26 package sun.awt.X11; 27 28 import java.awt.*; 29 import java.awt.peer.*; 30 import java.awt.event.*; 31 32 import sun.awt.AWTAccessor; 33 34 final class XCheckboxMenuItemPeer extends XMenuItemPeer 35 implements CheckboxMenuItemPeer { 36 37 /************************************************ 38 * 39 * Construction 40 * 41 ************************************************/ XCheckboxMenuItemPeer(CheckboxMenuItem target)42 XCheckboxMenuItemPeer(CheckboxMenuItem target) { 43 super(target); 44 } 45 46 /************************************************ 47 * 48 * Implementaion of interface methods 49 * 50 ************************************************/ 51 52 //Prom CheckboxMenuItemtPeer 53 @Override setState(boolean t)54 public void setState(boolean t) { 55 repaintIfShowing(); 56 } 57 58 /************************************************ 59 * 60 * Access to target's fields 61 * 62 ************************************************/ getTargetState()63 boolean getTargetState() { 64 return AWTAccessor.getCheckboxMenuItemAccessor() 65 .getState((CheckboxMenuItem)getTarget()); 66 } 67 68 /************************************************ 69 * 70 * Utility functions 71 * 72 ************************************************/ 73 74 /** 75 * Toggles state and generates ItemEvent 76 */ 77 @Override action(long when, int modifiers)78 void action(long when, int modifiers) { 79 XToolkit.executeOnEventHandlerThread((CheckboxMenuItem)getTarget(), new Runnable() { 80 @Override 81 public void run() { 82 doToggleState(when); 83 } 84 }); 85 } 86 87 88 /************************************************ 89 * 90 * Private 91 * 92 ************************************************/ doToggleState(long when)93 private void doToggleState(long when) { 94 CheckboxMenuItem cb = (CheckboxMenuItem)getTarget(); 95 boolean newState = !getTargetState(); 96 cb.setState(newState); 97 ItemEvent e = new ItemEvent(cb, 98 ItemEvent.ITEM_STATE_CHANGED, 99 getTargetLabel(), 100 getTargetState() ? ItemEvent.SELECTED : ItemEvent.DESELECTED); 101 XWindow.postEventStatic(e); 102 //WToolkit does not post ActionEvent when clicking on menu item 103 //MToolkit _does_ post. 104 //Fix for 5005195 MAWT: CheckboxMenuItem fires action events 105 //Events should not be fired 106 //XWindow.postEventStatic(new ActionEvent(cb, ActionEvent.ACTION_PERFORMED, 107 // getTargetActionCommand(), when, 108 // 0)); 109 } 110 111 } // class XCheckboxMenuItemPeer 112