01: /*
02: * SwingML Copyright (C) 2002 SwingML Team
03: *
04: * This library is free software; you can redistribute it and/or modify it under
05: * the terms of the GNU Lesser General Public License as published by the Free
06: * Software Foundation; either version 2 of the License, or (at your option) any
07: * later version.
08: *
09: * This library is distributed in the hope that it will be useful, but WITHOUT
10: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11: * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12: * details.
13: *
14: * You should have received a copy of the GNU Lesser General Public License
15: * along with this library; if not, write to the Free Software Foundation, Inc.,
16: * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17: *
18: * Authors: Ezequiel Cuellar <ecuellar@crosslogic.com>
19: *
20: */
21:
22: package org.swingml.component;
23:
24: import java.awt.event.*;
25:
26: import javax.swing.*;
27: import javax.swing.event.*;
28:
29: import org.swingml.*;
30: import org.swingml.event.*;
31: import org.swingml.model.*;
32:
33: public class JTextAreaComponent extends JTextArea implements
34: XMLTranslatable, DocumentListener, FocusListener {
35:
36: private EventHandler eventHandler = EventHandler.getInstance();
37: private JTextAreaModel model = null;
38:
39: public JTextAreaComponent(JTextAreaModel aModel) {
40: this .model = aModel;
41: super .setName(aModel.getName());
42: super .setColumns(aModel.getCols());
43: super .setRows(aModel.getRows());
44: super .setText(aModel.getText() != null ? aModel.getText()
45: .trim() : "");
46: super .setToolTipText(aModel.getTooltip());
47: super .getDocument().addDocumentListener(this );
48: super .addFocusListener(this );
49: super .setLineWrap(aModel.getLineWrap());
50: super .setWrapStyleWord(aModel.getWrapStyleWord());
51: if (aModel.getBackground() != null) {
52: super .setBackground(aModel.getBackground());
53: }
54: if (aModel.getForeground() != null) {
55: super .setForeground(aModel.getForeground());
56: }
57: super .setEditable(aModel.isEditable());
58: }
59:
60: public void changedUpdate(DocumentEvent aEvt) {
61: this .eventHandler.handleEvent(this .getModel(),
62: Constants.CHANGED_UPDATE, this );
63: }
64:
65: public void focusGained(FocusEvent aEvt) {
66: this .eventHandler.handleEvent(this .getModel(),
67: Constants.FOCUS_GAINED, this );
68: }
69:
70: public void focusLost(FocusEvent aEvt) {
71: this .eventHandler.handleEvent(this .getModel(),
72: Constants.FOCUS_LOST, this );
73: }
74:
75: public JTextAreaModel getModel() {
76: return model;
77: }
78:
79: public String getXMLValue() {
80: return super .getText();
81: }
82:
83: public void insertUpdate(DocumentEvent evt) {
84: eventHandler.handleEvent(this .getModel(),
85: Constants.INSERT_UPDATE, this );
86: }
87:
88: /**
89: * Don't allow focus if the field is not editable
90: */
91: public boolean isFocusable() {
92: return isEditable();
93: }
94:
95: public void removeUpdate(DocumentEvent evt) {
96: eventHandler.handleEvent(this.getModel(),
97: Constants.REMOVE_UPDATE, this);
98: }
99: }
|