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.ContainerEventRecordable;
027: import jacareto.struct.StructureElement;
028: import jacareto.system.Environment;
029: import jacareto.system.Language;
030: import jacareto.toolkit.event.TextValueListener;
031:
032: import java.awt.event.ActionEvent;
033: import java.awt.event.ActionListener;
034: import java.awt.event.ContainerEvent;
035:
036: import javax.swing.JComboBox;
037: import javax.swing.JTextField;
038: import javax.swing.event.DocumentEvent;
039:
040: /**
041: * <p>
042: * An editor for container event recordables.
043: * </p>
044: *
045: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
046: * @version 1.01
047: */
048: public class ContainerEventRecordableEditor extends
049: ComponentEventRecordableEditor {
050: /** The text field for the container's name. */
051: private JTextField containerField;
052:
053: /** The text field for the child's name. */
054: private JTextField childField;
055:
056: /** The combo box for the event type (=id). */
057: private JComboBox typeBox;
058:
059: /**
060: * Create a new container event recordable editor.
061: *
062: * @param env the environment
063: */
064: public ContainerEventRecordableEditor(Environment env) {
065: super (env);
066:
067: Language language = getLanguage();
068:
069: // The container field.
070: containerField = addTextFieldRow(language
071: .getString("Events.ContainerEvent.Container"), 20);
072: containerField.getDocument().addDocumentListener(
073: new TextValueListener() {
074: public void textValueChanged(DocumentEvent e) {
075: if (isUpdateOnChange && (getElement() != null)) {
076: ((ContainerEventRecordable) getElement())
077: .setContainerName(containerField
078: .getText());
079: }
080: }
081: });
082:
083: // The child field.
084: childField = addTextFieldRow(language
085: .getString("Events.ContainerEvent.Child"), 20);
086: childField.getDocument().addDocumentListener(
087: new TextValueListener() {
088: public void textValueChanged(DocumentEvent e) {
089: if (isUpdateOnChange && (getElement() != null)) {
090: ((ContainerEventRecordable) getElement())
091: .setChildName(childField.getText());
092: }
093: }
094: });
095:
096: // The type box
097: typeBox = addComboBoxRow(language
098: .getString("Events.ContainerEvent.Type"));
099: typeBox.addItem(language
100: .getString("Events.ContainerEvent.Added"));
101: typeBox.addItem(language
102: .getString("Events.ContainerEvent.Removed"));
103: typeBox.addActionListener(new ActionListener() {
104: public void actionPerformed(ActionEvent e) {
105: ContainerEventRecordable cRecordable = (ContainerEventRecordable) getElement();
106:
107: if (isUpdateOnChange && (cRecordable != null)) {
108: switch (typeBox.getSelectedIndex()) {
109: case 0:
110: cRecordable
111: .setID(ContainerEvent.COMPONENT_ADDED);
112:
113: break;
114:
115: case 1:
116: cRecordable
117: .setID(ContainerEvent.COMPONENT_REMOVED);
118:
119: break;
120: }
121: }
122: }
123: });
124: }
125:
126: /**
127: * Returns whether this editor is responsible for a given structure element. This editor is
128: * responsible for all container event recordables.
129: *
130: * @param element the structure element
131: *
132: * @return <code>true</code> if <i>element</i> is an container event recordable and not
133: * <code>null</code>, otherwise <code>false</code>
134: */
135: public boolean handlesElement(StructureElement element) {
136: return (element != null)
137: && (element instanceof ContainerEventRecordable);
138: }
139:
140: /**
141: * Sets the structure element to edit.
142: *
143: * @param element DOCUMENT ME!
144: */
145: public void setElement(StructureElement element) {
146: super .setElement(element);
147:
148: ContainerEventRecordable cRecordable = (ContainerEventRecordable) element;
149: containerField.setText(cRecordable.getContainerName());
150: childField.setText(cRecordable.getChildName());
151:
152: switch (cRecordable.getID()) {
153: case ContainerEvent.COMPONENT_ADDED:
154: typeBox.setSelectedIndex(0);
155:
156: break;
157:
158: case ContainerEvent.COMPONENT_REMOVED:
159: typeBox.setSelectedIndex(1);
160:
161: break;
162: }
163: }
164: }
|