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