01: /*
02: * @(#)GChoicePeer.java 1.17 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.gtk;
29:
30: import sun.awt.peer.*;
31: import java.awt.*;
32: import java.awt.event.*;
33:
34: /**
35: * Peer object for Gtk+ choice widget.
36: *
37: * @author Nicholas Allen
38: */
39:
40: class GChoicePeer extends GComponentPeer implements ChoicePeer {
41: private static native void initIDs();
42:
43: static {
44: initIDs();
45: }
46:
47: GChoicePeer(GToolkit toolkit, Choice target) {
48: super (toolkit, target);
49: int itemCount = target.getItemCount();
50: for (int i = 0; i < itemCount; i++)
51: add(target.getItem(i), i);
52: int selectedIndex = target.getSelectedIndex();
53: if (selectedIndex >= 0 && itemCount > 0)
54: select(selectedIndex);
55: }
56:
57: protected native void create();
58:
59: public boolean isFocusTraversable() {
60: return true;
61: }
62:
63: private native void addNative(byte[] item, int index,
64: int selectedIndex);
65:
66: public void add(String item, int index) {
67: if (item != null)
68: addNative(stringToNulMultiByte(item), index,
69: ((Choice) target).getSelectedIndex());
70: target.invalidate();
71: }
72:
73: private native void removeNative(int index, int selectedIndex);
74:
75: public void remove(int index) {
76: removeNative(index, ((Choice) target).getSelectedIndex());
77: target.invalidate();
78: }
79:
80: public native void select(int index);
81:
82: final static int DOWNARROW = 20;
83:
84: private void postItemEvent(int index) {
85: Choice c = (Choice) target;
86: GToolkit.postEvent(new ItemEvent(c,
87: ItemEvent.ITEM_STATE_CHANGED, c.getItem(index),
88: ItemEvent.SELECTED));
89: }
90: }
|