001: /*
002: * @(#)GCheckboxPeer.java 1.15 06/10/10
003: *
004: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: *
026: */
027:
028: package sun.awt.gtk;
029:
030: import java.awt.*;
031: import java.awt.event.*;
032: import sun.awt.peer.*;
033:
034: /**
035: *
036: *
037: * @author Nicholas Allen
038: */
039:
040: class GCheckboxPeer extends GComponentPeer implements CheckboxPeer {
041: private static native void initIDs();
042:
043: static {
044: initIDs();
045: }
046:
047: /** Creates a new GCheckboxPeer. */
048:
049: GCheckboxPeer(GToolkit toolkit, Checkbox target) {
050: super (toolkit, target);
051: setState(target.getState());
052: setLabel(target.getLabel());
053: }
054:
055: protected void create() {
056: CheckboxGroup group = ((Checkbox) target).getCheckboxGroup();
057: create(group != null);
058: }
059:
060: private native void create(boolean radio);
061:
062: public boolean isFocusTraversable() {
063: return true;
064: }
065:
066: public native void setState(boolean state);
067:
068: /* TODO: Changing of checkbox group after widget created. */
069:
070: public void setCheckboxGroup(CheckboxGroup g) {
071: }
072:
073: public void setLabel(String label) {
074: setLabelNative(stringToNulMultiByte(label));
075: }
076:
077: private native void setLabelNative(byte[] label);
078:
079: private void postItemEvent(boolean state) {
080: Checkbox cb = (Checkbox) target;
081: CheckboxGroup cbg = cb.getCheckboxGroup();
082: /* Bugid 4039594. If this is the current Checkbox in a CheckboxGroup,
083: * then return to prevent deselection. Otherwise, it's logical state
084: * will be turned off, but it will appear on.
085: */
086: if ((cbg != null) && (cbg.getSelectedCheckbox() == cb)
087: && cb.getState()) {
088: cb.setState(true);
089: return;
090: }
091: cb.setState(state);
092: // For some reason Java 2 only sends selected events is the checkbox is in a chekbox group.
093: // I don't know why this is but implemented this anyway to be consistent.
094:
095: if (cbg == null || state)
096: GToolkit.postEvent(new ItemEvent(cb,
097: ItemEvent.ITEM_STATE_CHANGED, cb.getLabel(),
098: state ? ItemEvent.SELECTED : ItemEvent.DESELECTED));
099: }
100: }
|