001: /*
002: * @(#)QtListPeer.java 1.14 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 sun.awt.peer.*;
030: import java.awt.*;
031: import java.awt.event.*;
032:
033: /**
034: *
035: *
036: * @author Nicholas Allen
037: */
038:
039: class QtListPeer extends QtComponentPeer implements ListPeer {
040:
041: private static native void initIDs();
042:
043: static {
044: initIDs();
045: }
046:
047: /** Creates a new QtListPeer. */
048:
049: public QtListPeer(QtToolkit toolkit, List target) {
050: super (toolkit, target);
051:
052: int itemCount = target.getItemCount();
053:
054: for (int i = 0; i < itemCount; i++)
055: add(target.getItem(i), i);
056:
057: setMultipleMode(target.isMultipleMode());
058:
059: int[] selected = target.getSelectedIndexes();
060:
061: if (selected != null) {
062: for (int i = 0; i < selected.length; i++)
063: select(selected[i]);
064: }
065: }
066:
067: protected native void create(QtComponentPeer parentPeer);
068:
069: public boolean isFocusTraversable() {
070: return true;
071: }
072:
073: public native int[] getSelectedIndexes();
074:
075: public void add(String item, int index) {
076: if (item != null)
077: addNative(item, index);
078: }
079:
080: protected native void addNative(String item, int index);
081:
082: public native void delItems(int start, int end);
083:
084: public native void removeAll();
085:
086: public native void select(int index);
087:
088: public native void deselect(int index);
089:
090: public native void makeVisible(int index);
091:
092: public native void setMultipleMode(boolean b);
093:
094: private native int preferredWidth(int rows);
095:
096: private native int preferredHeight(int rows);
097:
098: public Dimension getPreferredSize(int rows) {
099: return new Dimension(preferredWidth(rows),
100: preferredHeight(rows));
101: }
102:
103: public Dimension getMinimumSize(int rows) {
104: return getPreferredSize(rows);
105: }
106:
107: /**
108: * DEPRECATED: Replaced by add(String, int).
109: */
110: public void addItem(String item, int index) {
111: add(item, index);
112: }
113:
114: /**
115: * DEPRECATED: Replaced by removeAll().
116: */
117: public void clear() {
118: removeAll();
119: }
120:
121: /**
122: * DEPRECATED: Replaced by setMultipleMode(boolean).
123: */
124: public void setMultipleSelections(boolean v) {
125: setMultipleMode(v);
126: }
127:
128: /**
129: * DEPRECATED: Replaced by getPreferredSize(int).
130: */
131: public Dimension preferredSize(int v) {
132: return getPreferredSize(v);
133: }
134:
135: /**
136: * DEPRECATED: Replaced by getMinimumSize(int).
137: */
138: public Dimension minimumSize(int v) {
139: return getMinimumSize(v);
140: }
141:
142: private void postItemEvent(int row, boolean selected,
143: boolean postActionEvent) {
144: List list = (List) target;
145: if (list.isMultipleMode() || selected) {
146: QtToolkit.postEvent(new ItemEvent(list,
147: ItemEvent.ITEM_STATE_CHANGED, new Integer(row),
148: selected ? ItemEvent.SELECTED
149: : ItemEvent.DESELECTED));
150: if (postActionEvent)
151: QtToolkit
152: .postEvent(new ActionEvent(list,
153: ActionEvent.ACTION_PERFORMED, list
154: .getItem(row)));
155: }
156: }
157:
158: private void postActionEvent(int row) {
159: List list = (List) target;
160:
161: QtToolkit.postEvent(new ActionEvent(list,
162: ActionEvent.ACTION_PERFORMED, list.getItem(row)));
163: }
164:
165: public boolean isFocusable() {
166: return true;
167: }
168: }
|