001: /*
002: * Jacareto Copyright (c) 2002-2005
003: * Applied Computer Science Research Group, Darmstadt University of
004: * Technology, Institute of Mathematics & Computer Science,
005: * Ludwigsburg University of Education, and Computer Based
006: * Learning Research Group, Aachen University. All rights reserved.
007: *
008: * Jacareto is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation; either
011: * version 2 of the License, or (at your option) any later version.
012: *
013: * Jacareto is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public
019: * License along with Jacareto; if not, write to the Free
020: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
021: *
022: */
023:
024: package jacareto.editor;
025:
026: import jacareto.record.MessageDialogRecordable;
027: import jacareto.struct.StructureElement;
028: import jacareto.system.Environment;
029: import jacareto.toolkit.event.TextValueListener;
030: import jacareto.toolkit.swing.IntegerTextField;
031: import jacareto.toolkit.swing.LongTextField;
032:
033: import java.awt.Component;
034: import java.awt.GridBagConstraints;
035: import java.awt.GridBagLayout;
036: import java.awt.Insets;
037: import java.awt.event.ActionEvent;
038: import java.awt.event.ActionListener;
039:
040: import javax.swing.JCheckBox;
041: import javax.swing.JLabel;
042: import javax.swing.JPanel;
043: import javax.swing.JTextField;
044: import javax.swing.event.DocumentEvent;
045:
046: /**
047: * An editor for message dialog recordables.
048: *
049: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
050: * @version 1.01
051: */
052: public class MessageDialogEditor extends Editor {
053: /** The editor's component. */
054: protected JPanel editorPanel;
055:
056: /** The grid bag constraints. */
057: protected GridBagConstraints c;
058:
059: /** The element to edit. */
060: private StructureElement element;
061:
062: /** The text field for the messag text. */
063: private JTextField textField;
064:
065: /** The text area for the duration. */
066: private LongTextField durationField;
067:
068: /** The text area for the font size. */
069: private IntegerTextField fontSizeField;
070:
071: /** The checkbox for the hasButton value. */
072: private JCheckBox hasButtonBox;
073:
074: /** The button text field. */
075: private JTextField buttonTextField;
076:
077: /**
078: * Create a new editor.
079: *
080: * @param env the environment
081: */
082: public MessageDialogEditor(Environment env) {
083: super (env);
084: editorPanel = new JPanel();
085: c = new GridBagConstraints();
086: editorPanel.setLayout(new GridBagLayout());
087:
088: c.insets = new Insets(5, 5, 5, 5);
089: c.anchor = GridBagConstraints.WEST;
090:
091: // The text field label
092: c.gridx = 0;
093: c.gridy = 0;
094:
095: JLabel textFieldLabel = new JLabel(
096: language
097: .getString("Recordables.MessageDialogRecordable.Attributes.Text")
098: + ":");
099: editorPanel.add(textFieldLabel, c);
100:
101: // The duration field
102: c.gridx = 1;
103: textField = new JTextField(35);
104: textField.getDocument().addDocumentListener(
105: new TextValueListener() {
106: public void textValueChanged(DocumentEvent e) {
107: if (isUpdateOnChange && (getElement() != null)) {
108: ((MessageDialogRecordable) getElement())
109: .setText(textField.getText());
110: }
111: }
112: });
113: editorPanel.add(textField, c);
114: textFieldLabel.setLabelFor(textField);
115:
116: // The font size field label
117: c.gridx = 0;
118: c.gridy = 1;
119:
120: JLabel fontSizeFieldLabel = new JLabel(
121: language
122: .getString("Recordables.MessageDialogRecordable.Attributes.FontSize")
123: + ":");
124: editorPanel.add(fontSizeFieldLabel, c);
125:
126: // The duration field
127: c.gridx = 1;
128: fontSizeField = new IntegerTextField(5);
129: fontSizeField.getDocument().addDocumentListener(
130: new TextValueListener() {
131: public void textValueChanged(DocumentEvent e) {
132: if (isUpdateOnChange && (getElement() != null)) {
133: ((MessageDialogRecordable) getElement())
134: .setFontSize(fontSizeField
135: .getValue());
136: }
137: }
138: });
139: editorPanel.add(fontSizeField, c);
140: fontSizeFieldLabel.setLabelFor(fontSizeField);
141:
142: // The duration field label
143: c.gridx = 0;
144: c.gridy = 2;
145:
146: JLabel durationFieldLabel = new JLabel(
147: language
148: .getString("Recordables.MessageDialogRecordable.Attributes.Duration")
149: + ":");
150: editorPanel.add(durationFieldLabel, c);
151:
152: // The duration field
153: c.gridx = 1;
154: durationField = new LongTextField(5);
155: durationField.getDocument().addDocumentListener(
156: new TextValueListener() {
157: public void textValueChanged(DocumentEvent e) {
158: if (isUpdateOnChange && (getElement() != null)) {
159: ((MessageDialogRecordable) getElement())
160: .setDuration(durationField
161: .getValue());
162: }
163: }
164: });
165: editorPanel.add(durationField, c);
166: durationFieldLabel.setLabelFor(durationField);
167:
168: // The hasButton checkbox
169: c.gridx = 0;
170: c.gridy = 3;
171: c.gridwidth = 2;
172: hasButtonBox = new JCheckBox(
173: language
174: .getString("Recordables.MessageDialogRecordable.Attributes.HasButton"));
175: hasButtonBox.addActionListener(new ActionListener() {
176: public void actionPerformed(ActionEvent e) {
177: if (isUpdateOnChange && (getElement() != null)) {
178: ((MessageDialogRecordable) getElement())
179: .setHasButton(hasButtonBox.isSelected());
180: buttonTextField.setEnabled(hasButtonBox
181: .isSelected());
182: durationField
183: .setEnabled(!hasButtonBox.isSelected());
184: }
185: }
186: });
187: editorPanel.add(hasButtonBox, c);
188:
189: // The button text field
190: c.gridx = 0;
191: c.gridy = 4;
192: c.gridwidth = 1;
193:
194: JLabel buttonTextFieldLabel = new JLabel(
195: language
196: .getString("Recordables.MessageDialogRecordable.Attributes.ButtonText")
197: + ":");
198: editorPanel.add(buttonTextFieldLabel, c);
199:
200: c.gridx = 1;
201: buttonTextField = new JTextField(35);
202: buttonTextField.getDocument().addDocumentListener(
203: new TextValueListener() {
204: public void textValueChanged(DocumentEvent e) {
205: if (isUpdateOnChange && (getElement() != null)) {
206: ((MessageDialogRecordable) getElement())
207: .setButtonText(buttonTextField
208: .getText());
209: }
210: }
211: });
212: editorPanel.add(buttonTextField, c);
213: buttonTextFieldLabel.setLabelFor(buttonTextField);
214: }
215:
216: /**
217: * Returns whether this editor is responsible for a given structure element. This editor is
218: * responsible for message dialog recordables.
219: *
220: * @param element the structure element
221: *
222: * @return <code>true</code> if <i>element</i> is a message dialog recordable and not
223: * <code>null</code>, otherwise <code>false</code>
224: */
225: public boolean handlesElement(StructureElement element) {
226: return (element != null)
227: && (element instanceof MessageDialogRecordable);
228: }
229:
230: /**
231: * Returns the actual structure element to be edited.
232: *
233: * @return DOCUMENT ME!
234: */
235: public StructureElement getElement() {
236: return element;
237: }
238:
239: /**
240: * Sets the element to edit.
241: *
242: * @param element DOCUMENT ME!
243: */
244: public void setElement(StructureElement element) {
245: this .element = element;
246:
247: MessageDialogRecordable recordable = (MessageDialogRecordable) element;
248: textField.setText(recordable.getText());
249: durationField.setValue(recordable.getDuration());
250: fontSizeField.setValue((int) recordable.getFontSize());
251: hasButtonBox.setSelected(recordable.hasButton());
252: buttonTextField.setEnabled(hasButtonBox.isSelected());
253: durationField.setEnabled(!hasButtonBox.isSelected());
254: }
255:
256: /**
257: * Returns the component of the editor.
258: *
259: * @return the editor component
260: */
261: public Component getComponent() {
262: return editorPanel;
263: }
264: }
|