1 14 package org.compiere.swing; 15 16 import java.awt.Color ; 17 import java.awt.event.FocusListener ; 18 import java.awt.event.InputMethodListener ; 19 import java.awt.event.KeyListener ; 20 import java.awt.event.MouseListener ; 21 import java.awt.im.InputMethodRequests ; 22 23 import javax.swing.InputVerifier ; 24 import javax.swing.JScrollPane ; 25 import javax.swing.JTextArea ; 26 import javax.swing.text.Document ; 27 28 import org.compiere.plaf.CompierePLAF; 29 30 37 public class CText extends JScrollPane 38 implements CEditor 39 { 40 44 public CText() 45 { 46 this (new JTextArea ()); 47 } 49 55 public CText (String text) 56 { 57 this (new JTextArea (text)); 58 } 60 70 public CText (int rows, int columns) 71 { 72 this (new JTextArea (rows, columns)); 73 } 75 85 public CText (String text, int rows, int columns) 86 { 87 this (new JTextArea (text, rows, columns)); 88 } 90 96 public CText (Document doc) 97 { 98 this (new JTextArea (doc)); 99 } 101 113 public CText (Document doc, String text, int rows, int columns) 114 { 115 this (new JTextArea (doc, text, rows, columns)); 116 } 118 119 123 public CText (JTextArea textArea) 124 { 125 super (textArea); 126 m_textArea = textArea; 127 super.setOpaque(false); 128 super.getViewport().setOpaque(false); 129 m_textArea.setFont(CompierePLAF.getFont_Field()); 130 m_textArea.setForeground(CompierePLAF.getTextColor_Normal()); 131 } 133 private JTextArea m_textArea = null; 134 135 136 137 138 private boolean m_mandatory = false; 139 140 144 public void setMandatory (boolean mandatory) 145 { 146 m_mandatory = mandatory; 147 setBackground(false); 148 } 150 154 public boolean isMandatory() 155 { 156 return m_mandatory; 157 } 159 163 public void setReadWrite (boolean rw) 164 { 165 if (m_textArea.isEditable() != rw) 166 m_textArea.setEditable (rw); 167 setBackground(false); 168 } 170 174 public boolean isReadWrite() 175 { 176 return m_textArea.isEditable(); 177 } 179 183 public void setBackground (boolean error) 184 { 185 if (error) 186 setBackground(CompierePLAF.getFieldBackground_Error()); 187 else if (!isReadWrite()) 188 setBackground(CompierePLAF.getFieldBackground_Inactive()); 189 else if (m_mandatory) 190 setBackground(CompierePLAF.getFieldBackground_Mandatory()); 191 else 192 setBackground(CompierePLAF.getFieldBackground_Normal()); 193 } 195 public void setBackground (Color color) 196 { 197 if (color.equals(getBackground())) 198 return; 199 if (m_textArea == null) super.setBackground(color); 201 else 202 m_textArea.setBackground(color); 203 } 204 public Color getBackground () 205 { 206 if (m_textArea == null) return super.getBackground(); 208 else 209 return m_textArea.getBackground(); 210 } 211 public void setForeground (Color color) 212 { 213 if (m_textArea == null) super.setForeground(color); 215 else 216 m_textArea.setForeground(color); 217 } 218 public Color getForeground () 219 { 220 if (m_textArea == null) return super.getForeground(); 222 else 223 return m_textArea.getForeground(); 224 } 225 226 230 public void setValue (Object value) 231 { 232 if (value == null) 233 m_textArea.setText(""); 234 else 235 m_textArea.setText(value.toString()); 236 } 238 242 public Object getValue() 243 { 244 return m_textArea.getText(); 245 } 247 251 public String getDisplay() 252 { 253 return m_textArea.getText(); 254 } 256 257 261 public void setText (String text) 262 { 263 m_textArea.setText(text); 264 } 265 public String getText() 266 { 267 return m_textArea.getText(); 268 } 269 public void append (String text) 270 { 271 m_textArea.append (text); 272 } 273 274 public void setColumns (int cols) 275 { 276 m_textArea.setColumns (cols); 277 } 278 public int getColumns() 279 { 280 return m_textArea.getColumns(); 281 } 282 283 public void setRows (int rows) 284 { 285 m_textArea.setRows(rows); 286 } 287 public int getRows() 288 { 289 return m_textArea.getRows(); 290 } 291 292 public void setCaretPosition (int pos) 293 { 294 m_textArea.setCaretPosition (pos); 295 } 296 public int getCaretPosition() 297 { 298 return m_textArea.getCaretPosition(); 299 } 300 301 public void setEditable (boolean edit) 302 { 303 m_textArea.setEditable(edit); 304 } 305 public boolean isEditable() 306 { 307 return m_textArea.isEditable(); 308 } 309 310 public void setLineWrap (boolean wrap) 311 { 312 m_textArea.setLineWrap (wrap); 313 } 314 public void setWrapStyleWord (boolean word) 315 { 316 m_textArea.setWrapStyleWord (word); 317 } 318 319 public void setOpaque (boolean isOpaque) 320 { 321 if (m_textArea == null) super.setOpaque(isOpaque); 324 else 325 m_textArea.setOpaque(isOpaque); 326 } 328 public void addFocusListener (FocusListener l) 329 { 330 if (m_textArea == null) super.addFocusListener(l); 332 else 333 m_textArea.addFocusListener(l); 334 } 335 public void addMouseListener (MouseListener l) 336 { 337 m_textArea.addMouseListener(l); 338 } 339 public void addKeyListener (KeyListener l) 340 { 341 m_textArea.addKeyListener(l); 342 } 343 344 public void addInputMethodListener (InputMethodListener l) 345 { 346 m_textArea.addInputMethodListener(l); 347 } 348 public InputMethodRequests getInputMethodRequests() 349 { 350 return m_textArea.getInputMethodRequests(); 351 } 352 public void setInputVerifier (InputVerifier l) 353 { 354 m_textArea.setInputVerifier(l); 355 } 356 357 358 359 } | Popular Tags |