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: public GtkTextFieldPeer (TextField tf)
116: {
117: super (tf);
118:
119: setText (tf.getText ());
120: setCaretPosition (0);
121:
122: if (tf.echoCharIsSet ())
123: setEchoChar (tf.getEchoChar ());
124: }
125:
126: public Dimension getMinimumSize (int cols)
127: {
128: return minimumSize (cols);
129: }
130:
131: public Dimension getPreferredSize (int cols)
132: {
133: return preferredSize (cols);
134: }
135:
136: public native void setEchoChar (char c);
137:
138:
139: public Dimension minimumSize (int cols)
140: {
141: int dim[] = new int[2];
142:
143: gtkWidgetGetPreferredDimensions (dim);
144:
145: Font f = awtComponent.getFont ();
146: if (f == null)
147: return new Dimension (2 * gtkEntryGetBorderWidth (), dim[1]);
148:
149: FontMetrics fm = getFontMetrics (f);
150:
151: int text_width = cols * fm.getMaxAdvance ();
152:
153: int width = text_width + 2 * gtkEntryGetBorderWidth ();
154:
155: return new Dimension (width, dim[1]);
156: }
157:
158: public Dimension preferredSize (int cols)
159: {
160: int dim[] = new int[2];
161:
162: gtkWidgetGetPreferredDimensions (dim);
163:
164: Font f = awtComponent.getFont ();
165: if (f == null)
166: return new Dimension (2 * gtkEntryGetBorderWidth (), dim[1]);
167:
168: FontMetrics fm = getFontMetrics (f);
169:
170: int text_width = cols * fm.getMaxAdvance ();
171:
172: int width = text_width + 2 * gtkEntryGetBorderWidth ();
173:
174: return new Dimension (width, dim[1]);
175: }
176:
177: public void setEchoCharacter (char c)
178: {
179: setEchoChar (c);
180: }
181:
182: public void handleEvent (AWTEvent e)
183: {
184: if (e.getID () == KeyEvent.KEY_PRESSED)
185: {
186: KeyEvent ke = (KeyEvent) e;
187:
188: if (!ke.isConsumed ()
189: && ke.getKeyCode () == KeyEvent.VK_ENTER)
190: postActionEvent (getText (), ke.getModifiersEx ());
191: }
192:
193: super.handleEvent (e);
194: }
195: public InputMethodRequests getInputMethodRequests()
196: {
197:
198: return null;
199: }
200: }