01: /*
02: * @(#)QtChoicePeer.java 1.13 06/10/10
03: *
04: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
05: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License version
09: * 2 only, as published by the Free Software Foundation.
10: *
11: * This program is distributed in the hope that it will be useful, but
12: * WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * General Public License version 2 for more details (a copy is
15: * included at /legal/license.txt).
16: *
17: * You should have received a copy of the GNU General Public License
18: * version 2 along with this work; if not, write to the Free Software
19: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA
21: *
22: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
23: * Clara, CA 95054 or visit www.sun.com if you need additional
24: * information or have any questions.
25: *
26: */
27:
28: package sun.awt.qt;
29:
30: import sun.awt.peer.*;
31: import java.awt.*;
32: import java.awt.event.*;
33:
34: /**
35: * Peer object for Qt+ choice widget.
36: *
37: */
38:
39: class QtChoicePeer extends QtComponentPeer implements ChoicePeer {
40: private static native void initIDs();
41:
42: static {
43: initIDs();
44: }
45:
46: QtChoicePeer(QtToolkit toolkit, Choice target) {
47: super (toolkit, target);
48:
49: int itemCount = target.getItemCount();
50:
51: for (int i = 0; i < itemCount; i++)
52: add(target.getItem(i), i);
53:
54: int selectedIndex = target.getSelectedIndex();
55:
56: if (selectedIndex >= 0 && itemCount > 0)
57: select(selectedIndex);
58: }
59:
60: protected native void create(QtComponentPeer parentPeer);
61:
62: public boolean isFocusTraversable() {
63: return true;
64: }
65:
66: protected native void addNative(String item, int index);
67:
68: public void add(String item, int index) {
69: if (item != null)
70: addNative(item, index);
71: target.invalidate();
72: }
73:
74: private native void removeNative(int index);
75:
76: public void remove(int index) {
77: removeNative(index);
78: target.invalidate();
79: }
80:
81: public native void select(int index);
82:
83: public boolean isFocusable() {
84: return true;
85: }
86:
87: private void postItemEvent(int index) {
88: Choice c = (Choice) target;
89: QtToolkit.postEvent(new ItemEvent(c,
90: ItemEvent.ITEM_STATE_CHANGED, c.getItem(index),
91: ItemEvent.SELECTED));
92: }
93:
94: }
|