1:
37:
38:
39: package ;
40:
41: import ;
42: import ;
43: import ;
44: import ;
45: import ;
46: import ;
47: import ;
48: import ;
49: import ;
50: import ;
51:
52: public class GtkTextFieldPeer extends GtkComponentPeer
53: implements TextComponentPeer, TextFieldPeer
54: {
55: native void create (int width);
56: native void gtkWidgetSetBackground (int red, int green, int blue);
57: native void gtkWidgetSetForeground (int red, int green, int blue);
58:
59: public native void connectSignals ();
60:
61: public native int getCaretPosition ();
62: public native void setCaretPosition (int pos);
63: public native int getSelectionStart ();
64: public native int getSelectionEnd ();
65: public native String getText ();
66: public native void select (int start, int end);
67: public native void setEditable (boolean state);
68: public native void setText (String text);
69:
70: public int getIndexAtPoint(int x, int y)
71: {
72:
73: return 0;
74: }
75:
76: public Rectangle getCharacterBounds (int pos)
77: {
78:
79: return null;
80: }
81:
82: public long filterEvents (long filter)
83: {
84:
85: return filter;
86: }
87:
88: void create ()
89: {
90: Font f = awtComponent.getFont ();
91:
92:
93:
94:
95: if (f == null)
96: {
97: f = new Font ("Dialog", Font.PLAIN, 12);
98: awtComponent.setFont (f);
99: }
100:
101: FontMetrics fm = getFontMetrics (f);
102:
103: TextField tf = ((TextField) awtComponent);
104: int cols = tf.getColumns ();
105:
106: int text_width = cols * fm.getMaxAdvance ();
107:
108: create (text_width);
109:
110: setEditable (tf.isEditable ());
111: }
112:
113: native int gtkEntryGetBorderWidth ();
114:
115: native void gtkWidgetModifyFont (String name, int style, int size);
116:
117: public GtkTextFieldPeer (TextField tf)
118: {
119: super (tf);
120:
121: setText (tf.getText ());
122: setCaretPosition (0);
123:
124: if (tf.echoCharIsSet ())
125: setEchoChar (tf.getEchoChar ());
126: }
127:
128: public Dimension getMinimumSize (int cols)
129: {
130: return minimumSize (cols);
131: }
132:
133: public Dimension getPreferredSize (int cols)
134: {
135: return preferredSize (cols);
136: }
137:
138: public native void setEchoChar (char c);
139:
140:
141: public Dimension minimumSize (int cols)
142: {
143: int dim[] = new int[2];
144:
145: gtkWidgetGetPreferredDimensions (dim);
146:
147: Font f = awtComponent.getFont ();
148: if (f == null)
149: return new Dimension (2 * gtkEntryGetBorderWidth (), dim[1]);
150:
151: FontMetrics fm = getFontMetrics (f);
152:
153: int text_width = cols * fm.getMaxAdvance ();
154:
155: int width = text_width + 2 * gtkEntryGetBorderWidth ();
156:
157: return new Dimension (width, dim[1]);
158: }
159:
160: public Dimension preferredSize (int cols)
161: {
162: int dim[] = new int[2];
163:
164: gtkWidgetGetPreferredDimensions (dim);
165:
166: Font f = awtComponent.getFont ();
167: if (f == null)
168: return new Dimension (2 * gtkEntryGetBorderWidth (), dim[1]);
169:
170: FontMetrics fm = getFontMetrics (f);
171:
172: int text_width = cols * fm.getMaxAdvance ();
173:
174: int width = text_width + 2 * gtkEntryGetBorderWidth ();
175:
176: return new Dimension (width, dim[1]);
177: }
178:
179: public void setEchoCharacter (char c)
180: {
181: setEchoChar (c);
182: }
183:
184: public void handleEvent (AWTEvent e)
185: {
186: if (e.getID () == KeyEvent.KEY_PRESSED)
187: {
188: KeyEvent ke = (KeyEvent) e;
189:
190: if (!ke.isConsumed ()
191: && ke.getKeyCode () == KeyEvent.VK_ENTER)
192: postActionEvent (getText (), ke.getModifiersEx ());
193: }
194:
195: super.handleEvent (e);
196: }
197: public InputMethodRequests getInputMethodRequests()
198: {
199:
200: return null;
201: }
202: }