1 19 20 21 package org.netbeans.modules.form.fakepeer; 22 23 import java.awt.*; 24 25 29 class FakeTextAreaPeer extends FakeTextComponentPeer 30 { 31 FakeTextAreaPeer(TextArea target) { 32 super(target); 33 } 34 35 Component createDelegate() { 36 return new Delegate(); 37 } 38 39 public void insert(String text, int pos) { 40 } 41 42 public void replaceRange(String text, int start, int end) { 43 } 44 45 public Dimension getPreferredSize(int rows, int columns) { 46 return new Dimension(100, 80); 47 } 48 49 public Dimension getMinimumSize(int rows, int columns) { 50 return new Dimension(100, 80); 51 } 52 53 public void insertText(String txt, int pos) { 54 insert(txt, pos); 55 } 56 57 public void replaceText(String txt, int start, int end) { 58 replaceRange(txt, start, end); 59 } 60 61 public Dimension preferredSize(int rows, int cols) { 62 return getPreferredSize(rows, cols); 63 } 64 65 public Dimension minimumSize(int rows, int cols) { 66 return getMinimumSize(rows, cols); 67 } 68 69 73 private class Delegate extends FakeTextComponentPeer.Delegate 74 { 75 public void paint(Graphics g) { 76 super.paint(g); 77 78 TextArea target = (TextArea) _target; 79 Dimension sz = target.getSize(); 80 int w = sz.width; 81 int h = sz.height; 82 String text = target.getText(); 83 84 if (text != null) { 85 g.setFont(target.getFont()); 86 g.setColor(target.getForeground()); 87 88 FontMetrics fm = g.getFontMetrics(); 89 int th = fm.getHeight(); 90 int ty = th; 91 int i = target.getCaretPosition(); 92 int len = text.length(); 93 94 StringBuffer buf = new StringBuffer (len); 95 96 for ( ; i < len; i++) { 97 char ch = text.charAt(i); 98 if (ch != '\n' && ch != '\r') buf.append(ch); 99 else if (ch == '\n') { 100 g.drawString(buf.toString(),4,ty); 101 if (ty > h) 102 break; 103 ty += th; 104 buf.delete(0,buf.length()); 105 } 106 } 107 g.drawString(buf.toString(), 4, ty); 108 } 109 110 if (sz.width > FakePeerUtils.SCROLL_W*2 && 111 sz.height > FakePeerUtils.SCROLL_H*2) { 112 g.setColor(SystemColor.controlHighlight); 113 FakePeerUtils.drawScrollbar(g,2,h-FakePeerUtils.SCROLL_H-2, 114 w-4-FakePeerUtils.SCROLL_W,FakePeerUtils.SCROLL_H, 115 Scrollbar.HORIZONTAL,false,true,0,0,0); 116 117 g.setColor(SystemColor.controlHighlight); 118 FakePeerUtils.drawScrollbar(g,w-FakePeerUtils.SCROLL_W-2,2, 119 FakePeerUtils.SCROLL_W,h-4-FakePeerUtils.SCROLL_H, 120 Scrollbar.VERTICAL,false,true,0,0,0); 121 122 g.setColor(SystemColor.controlHighlight); 123 g.fillRect(w-FakePeerUtils.SCROLL_W-2,h-FakePeerUtils.SCROLL_H-2, 124 FakePeerUtils.SCROLL_W,FakePeerUtils.SCROLL_H); 125 } 126 } 127 128 public Dimension getMinimumSize() { 129 TextArea target = (TextArea)_target; 130 return FakeTextAreaPeer.this.getMinimumSize(target.getColumns(),target.getRows()); 131 } 132 } 133 } 134 | Popular Tags |