1:
37:
38: package ;
39:
40: import ;
41: import ;
42: import ;
43: import ;
44: import ;
45: import ;
46: import ;
47: import ;
48: import ;
49: import ;
50: import ;
51: import ;
52: import ;
53: import ;
54: import ;
55: import ;
56:
57: import ;
58: import ;
59: import ;
60: import ;
61: import ;
62:
63: public class SwingTextAreaPeer
64: extends SwingComponentPeer
65: implements TextAreaPeer
66: {
67:
68:
73: private class SwingScrollPane
74: extends JScrollPane
75: implements SwingComponent
76: {
77:
78: SwingTextArea textArea;
79:
80: SwingScrollPane(SwingTextArea textArea)
81: {
82: super(textArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
83: JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
84:
85: this.textArea = textArea;
86: }
87:
88:
93: public JComponent getJComponent()
94: {
95: return this;
96: }
97:
98:
104: public void handleMouseEvent(MouseEvent ev)
105: {
106: JViewport viewPort = getViewport();
107: if(viewPort.contains(ev.getPoint()))
108: {
109: ev.setSource(textArea);
110: textArea.dispatchEvent(ev);
111: }
112: else
113: {
114: ev.setSource(this);
115: this.dispatchEvent(ev);
116: }
117: }
118:
119:
122: public boolean isLightweight()
123: {
124: return false;
125: }
126:
127:
133: public void handleMouseMotionEvent(MouseEvent ev)
134: {
135: textArea.processMouseMotionEvent(ev);
136: }
137:
138:
143: public void handleKeyEvent(KeyEvent ev)
144: {
145: textArea.processKeyEvent(ev);
146: }
147:
148:
154: public void handleFocusEvent(FocusEvent ev)
155: {
156: textArea.processFocusEvent(ev);
157: }
158:
159:
165: public Point getLocationOnScreen()
166: {
167: return SwingTextAreaPeer.this.getLocationOnScreen();
168: }
169:
170:
177: public boolean isShowing()
178: {
179: boolean retVal = false;
180: if (SwingTextAreaPeer.this.awtComponent != null)
181: retVal = SwingTextAreaPeer.this.awtComponent.isShowing();
182: return retVal;
183: }
184:
185:
194: public Image createImage(int w, int h)
195: {
196: return SwingTextAreaPeer.this.createImage(w, h);
197: }
198:
199: public Graphics getGraphics()
200: {
201: return SwingTextAreaPeer.this.getGraphics();
202: }
203:
204: public Container getParent()
205: {
206: Container par = null;
207: if (SwingTextAreaPeer.this.awtComponent != null)
208: par = SwingTextAreaPeer.this.awtComponent.getParent();
209: return par;
210: }
211:
212: public void requestFocus() {
213: SwingTextAreaPeer.this.requestFocus(awtComponent, false, true, 0);
214: }
215:
216: public boolean requestFocus(boolean temporary) {
217: return SwingTextAreaPeer.this.requestFocus(awtComponent, temporary,
218: true, 0);
219: }
220:
221: }
222:
223: private class SwingTextArea extends JTextArea
224: {
225:
228: protected final void processComponentKeyEvent(KeyEvent e)
229: {
230: super.processComponentKeyEvent(e);
231: }
232:
233:
236: protected final void processMouseMotionEvent(MouseEvent ev)
237: {
238: super.processMouseMotionEvent(ev);
239: }
240:
241:
244: protected final void processComponentEvent(ComponentEvent e)
245: {
246: super.processComponentEvent(e);
247: }
248:
249:
252: protected final void processFocusEvent(FocusEvent e)
253: {
254: super.processFocusEvent(e);
255: }
256:
257:
260: protected final void processHierarchyBoundsEvent(HierarchyEvent e)
261: {
262: super.processHierarchyBoundsEvent(e);
263: }
264:
265:
268: protected final void processHierarchyEvent(HierarchyEvent e)
269: {
270: super.processHierarchyEvent(e);
271: }
272:
273:
276: protected final void processInputMethodEvent(InputMethodEvent e)
277: {
278: super.processInputMethodEvent(e);
279: }
280:
281:
284: protected final void processMouseEvent(MouseEvent e)
285: {
286: super.processMouseEvent(e);
287: }
288:
289:
292: protected final void processMouseWheelEvent(MouseWheelEvent e)
293: {
294: super.processMouseWheelEvent(e);
295: }
296:
297:
300: protected final void processKeyEvent(KeyEvent e)
301: {
302: super.processKeyEvent(e);
303: }
304:
305: public void requestFocus() {
306: SwingTextAreaPeer.this.requestFocus(awtComponent, false, true, 0);
307: }
308:
309: public boolean requestFocus(boolean temporary) {
310: return SwingTextAreaPeer.this.requestFocus(awtComponent, temporary,
311: true, 0);
312: }
313: }
314:
315:
318: private SwingTextArea jTextArea;
319:
320: public SwingTextAreaPeer(TextArea textArea)
321: {
322: super();
323: jTextArea = new SwingTextArea();
324: SwingScrollPane swingArea = new SwingScrollPane(jTextArea);
325: init(textArea, swingArea);
326:
327: JViewport viewport = new JViewport()
328: {
329: public Image createImage(int width, int height)
330: {
331: return awtComponent.createImage(width, height);
332: }
333: };
334:
335: viewport.setView(jTextArea);
336: swingArea.setViewport(viewport);
337:
338: setText(textArea.getText());
339:
340:
341:
342: int columns = textArea.getColumns();
343: int rows = textArea.getRows();
344:
345: if(columns == 0 && rows == 0)
346: {
347: columns = 25;
348: textArea.setColumns(columns);
349: rows = 5;
350: textArea.setRows(rows);
351: }
352:
353: jTextArea.setColumns(columns);
354: jTextArea.setRows(rows);
355: }
356:
357: public Dimension getMinimumSize(int rows, int cols)
358: {
359: return jTextArea.getMinimumSize();
360: }
361:
362: public Dimension getPreferredSize(int rows, int cols)
363: {
364: return jTextArea.getPreferredSize();
365: }
366:
367: public void insert(String text, int pos)
368: {
369: jTextArea.insert(text, pos);
370: }
371:
372: public void insertText(String text, int pos)
373: {
374: jTextArea.insert(text, pos);
375: }
376:
377: public Dimension minimumSize()
378: {
379: return jTextArea.getMinimumSize();
380: }
381:
382: public Dimension preferredSize()
383: {
384: return jTextArea.getPreferredSize();
385: }
386:
387: public Dimension minimumSize(int rows, int cols)
388: {
389: return jTextArea.getMinimumSize();
390: }
391:
392: public Dimension preferredSize(int rows, int cols)
393: {
394: return jTextArea.getPreferredSize();
395: }
396:
397: public void replaceRange(String text, int start, int end)
398: {
399: jTextArea.replaceRange(text, start, end);
400: }
401:
402: public void replaceText(String text, int start, int end)
403: {
404: jTextArea.replaceRange(text, start, end);
405: }
406:
407: public long filterEvents(long filter)
408: {
409:
410: return 0;
411: }
412:
413: public int getCaretPosition()
414: {
415: return jTextArea.getCaretPosition();
416: }
417:
418: public Rectangle getCharacterBounds(int pos)
419: {
420: Rectangle r;
421: try
422: {
423: return jTextArea.modelToView(pos);
424: }
425: catch (BadLocationException ex)
426: {
427: r = null;
428: }
429: return r;
430: }
431:
432: public int getIndexAtPoint(int x, int y)
433: {
434: return jTextArea.viewToModel(new Point(x, y));
435: }
436:
437: public InputMethodRequests getInputMethodRequests()
438: {
439:
440: return null;
441: }
442:
443: public int getSelectionEnd()
444: {
445: return jTextArea.getSelectionEnd();
446: }
447:
448: public int getSelectionStart()
449: {
450: return jTextArea.getSelectionStart();
451: }
452:
453: public String getText()
454: {
455: return jTextArea.getText();
456: }
457:
458: public void select(int start, int end)
459: {
460: jTextArea.select(start, end);
461: }
462:
463: public void setCaretPosition(int pos)
464: {
465: jTextArea.setCaretPosition(pos);
466: }
467:
468: public void setEditable(boolean editable)
469: {
470: jTextArea.setEditable(editable);
471: }
472:
473: public void setText(String text)
474: {
475: jTextArea.setText(text);
476: }
477:
478: public void reshape(int x, int y, int width, int height)
479: {
480: if (swingComponent != null)
481: {
482: swingComponent.getJComponent().setBounds(x, y, width, height);
483: swingComponent.getJComponent().validate();
484: }
485: }
486:
487: }