1 74 75 76 package swingwtx.swing; 77 78 import org.eclipse.swt.SWT; 79 import org.eclipse.swt.widgets.Text; 80 81 import swingwtx.swing.text.Document; 82 83 public class JTextArea extends swingwtx.swing.text.JTextComponent { 84 85 protected boolean pWordWrap = false; 86 protected int pRows = 0; 87 protected int pCols = 0; 88 89 90 private String retVal = ""; 91 private int iRetVal = 0; 92 93 public JTextArea() { 94 this(null, "", 0, 0); 95 } 96 public JTextArea(String text) { 97 this(null, text, 0, 0); 98 } 99 public JTextArea(int rows, int columns) { 100 this(null, "", rows, columns); 101 } 102 public JTextArea(String text, int rows, int columns) { 103 this(null, text, rows, columns); 104 } 105 public JTextArea(Document doc) { 106 this(doc, "", 0, 0); 107 } 108 public JTextArea(Document doc, String text, int rows, int columns) { 109 super(); 110 if (doc != null) setDocument(doc); 111 if (text != null) { 112 setText(text); 113 view.updateModelFromComponent(getText()); 114 } 115 pRows = rows; 116 pCols = columns; 117 calculateFromRowsCols(); 118 } 119 120 124 protected void calculateFromRowsCols() { 125 if (pRows != 0 && pCols != 0) 126 setPreferredSize( new swingwt.awt.Dimension((SwingWTUtils.getRenderStringWidth("W") * pCols), 25 * pRows )); 127 else if (pRows == 0 && pCols != 0) 128 setPreferredSize( new swingwt.awt.Dimension((SwingWTUtils.getRenderStringWidth("W") * pCols), 25 )); 129 } 130 131 132 public void append(final String text) { 133 pText += text; 134 SwingUtilities.invokeSync(new Runnable () { 135 public void run() { 136 if (SwingWTUtils.isSWTControlAvailable(ppeer)) ppeer.append(text); 137 } 138 }); 139 } 140 141 public boolean getLineWrap() { return true; } 142 public void setLineWrap(boolean b) { } 143 public boolean getWrapStyleWord() { return pWordWrap; } 144 public void setWrapStyleWord(final boolean b) { pWordWrap = b; } 145 146 149 protected swingwt.awt.Dimension calculatePreferredSize() { 150 swingwt.awt.Dimension size = new swingwt.awt.Dimension( 151 SwingWTUtils.getRenderStringWidth(pText), 152 SwingWTUtils.getRenderStringHeight(pText) + 4); 153 setSize(size); 154 return size; 155 } 156 157 162 public void setSwingWTParent(swingwt.awt.Container parent) throws Exception { 163 descendantHasPeer = true; 164 ppeer = new Text(parent.getComposite(), SWT.BORDER | 165 ( showHorizontalScrollBar ? SWT.H_SCROLL : SWT.NONE) | 166 ( showVerticalScrollBar ? SWT.V_SCROLL : SWT.NONE) | 167 SWT.MULTI | 168 ( pWordWrap ? SWT.WRAP : SWT.NONE ) 169 ); 170 ppeer.setText(pText); 171 ppeer.setEditable(pEditable); 172 ppeer.setTabs(0); 173 peer = ppeer; 174 175 ppeer.addKeyListener(new org.eclipse.swt.events.KeyAdapter() { 176 public void keyPressed(org.eclipse.swt.events.KeyEvent e) { 177 178 if ((e.keyCode == 97 ) && ((e.stateMask & SWT.CTRL) > 0)) { 180 selectAll(); 181 e.doit = false; 182 } 183 184 if ((e.keyCode == SWT.TAB) && ((e.stateMask & SWT.SHIFT) > 0)) { 186 ppeer.traverse(SWT.TRAVERSE_TAB_PREVIOUS); 187 e.doit = false; 188 } 189 else if (e.keyCode == SWT.TAB) { 190 ppeer.traverse(SWT.TRAVERSE_TAB_NEXT); 191 e.doit = false; 192 } 193 194 } 195 }); 196 197 this.parent = parent; 198 } 199 200 } 201 | Popular Tags |