001: /*
002: * @(#)QtCheckboxPeer.java 1.12 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: package sun.awt.qt;
028:
029: import java.awt.*;
030: import java.awt.event.*;
031: import sun.awt.peer.*;
032:
033: /**
034: *
035: *
036: * @author Nicholas Allen
037: */
038:
039: class QtCheckboxPeer extends QtComponentPeer implements CheckboxPeer {
040: private static native void initIDs();
041:
042: static {
043: initIDs();
044: }
045:
046: /** Creates a new QtCheckboxPeer. */
047:
048: QtCheckboxPeer(QtToolkit toolkit, Checkbox target) {
049: super (toolkit, target);
050: setState(target.getState());
051: setLabel(target.getLabel());
052: }
053:
054: protected void create(QtComponentPeer parentPeer) {
055: CheckboxGroup group = ((Checkbox) target).getCheckboxGroup();
056:
057: create(parentPeer, group != null);
058: }
059:
060: private native void create(QtComponentPeer parentPeer, 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(label);
075: }
076:
077: public boolean isFocusable() {
078: return true;
079: }
080:
081: private native void setLabelNative(String label);
082:
083: private void postItemEvent(boolean state) {
084: Checkbox cb = (Checkbox) target;
085: CheckboxGroup cbg = cb.getCheckboxGroup();
086:
087: /* Bugid 4039594. If this is the current Checkbox in a CheckboxGroup,
088: * then return to prevent deselection. Otherwise, it's logical state
089: * will be turned off, but it will appear on.
090: */
091: if ((cbg != null) && (cbg.getSelectedCheckbox() == cb)
092: && cb.getState()) {
093: cb.setState(true);
094: return;
095: }
096:
097: cb.setState(state);
098:
099: // For some reason Java 2 only sends selected events is the
100: // checkbox is in a chekbox group.
101: // I don't know why this is but implemented this anyway
102: // to be consistent.
103: if (cbg == null || state)
104: QtToolkit.postEvent(new ItemEvent(cb,
105: ItemEvent.ITEM_STATE_CHANGED, cb.getLabel(),
106: state ? ItemEvent.SELECTED : ItemEvent.DESELECTED));
107: }
108: }
|