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.struct.InteractionModelStructureElement;
027: import jacareto.struct.StructureElement;
028: import jacareto.system.Environment;
029: import jacareto.system.Language;
030:
031: import java.awt.Component;
032: import java.awt.GridBagConstraints;
033: import java.awt.GridBagLayout;
034: import java.awt.Insets;
035: import java.awt.event.ActionEvent;
036: import java.awt.event.ActionListener;
037:
038: import javax.swing.JButton;
039: import javax.swing.JLabel;
040: import javax.swing.JList;
041: import javax.swing.JPanel;
042: import javax.swing.JScrollPane;
043: import javax.swing.ListSelectionModel;
044:
045: /**
046: * An editor for interaction-model structure element.
047: *
048: * @author <a href="mailto:Markus.Bois@web.de">Markus Bois</a>
049: * @version 1.0
050: */
051: public class InteractionModelStructureElementEditor extends Editor {
052: /** The structure element to edit. */
053: private StructureElement element;
054:
055: /** The editor's component. */
056: private JPanel editorPanel;
057:
058: /** The list of the setted concept or concept attributes. */
059: private JList conceptualElements;
060:
061: /** The remove Button */
062: private JButton removeButton;
063:
064: /** The clear button */
065: private JButton clearButton;
066:
067: /**
068: * Create a new interaction-model structure element editor.
069: *
070: * @param env the environment
071: */
072: public InteractionModelStructureElementEditor(Environment env) {
073: super (env);
074:
075: Language language = getLanguage();
076:
077: editorPanel = new JPanel();
078: editorPanel.setLayout(new GridBagLayout());
079:
080: // The concept field label
081: GridBagConstraints c = new GridBagConstraints();
082: c.gridx = 0;
083: c.gridy = 0;
084: c.weightx = 0;
085: c.insets = new Insets(5, 5, 5, 5);
086: c.anchor = GridBagConstraints.WEST;
087:
088: JLabel conceptsFieldLabel = new JLabel(
089: language
090: .getString("Editors.InteractionModelStructureElementEditor.Concept")
091: + ":");
092: editorPanel.add(conceptsFieldLabel, c);
093:
094: c.gridx = 0;
095: c.gridy = 1;
096: conceptualElements = new JList();
097: conceptualElements.setFixedCellWidth(325);
098: conceptualElements
099: .setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
100: editorPanel.add(new JScrollPane(conceptualElements), c);
101:
102: //The clear button
103: c.gridx = 0;
104: c.gridy = 6;
105: clearButton = new JButton(
106: language
107: .getString("Editors.InteractionModelStructureElementEditor.Clear"));
108: clearButton.addActionListener(new ActionListener() {
109: public void actionPerformed(ActionEvent e) {
110: if (isUpdateOnChange && (getElement() != null)) {
111: ((InteractionModelStructureElement) getElement())
112: .clearConceptualElements();
113: setElement(getElement());
114: }
115: }
116: });
117: editorPanel.add(clearButton, c);
118:
119: //The remove button
120: c.gridx = 0;
121: c.gridy = 6;
122: c.anchor = GridBagConstraints.CENTER;
123: removeButton = new JButton(
124: language
125: .getString("Editors.InteractionModelStructureElementEditor.Remove"));
126: removeButton.addActionListener(new ActionListener() {
127: public void actionPerformed(ActionEvent e) {
128: Object selected = conceptualElements.getSelectedValue();
129:
130: if (isUpdateOnChange && (getElement() != null)
131: && (selected != null)) {
132: ((InteractionModelStructureElement) getElement())
133: .removeConceptualElement(selected
134: .toString());
135: setElement(getElement());
136: }
137: }
138: });
139: editorPanel.add(removeButton, c);
140: }
141:
142: /**
143: * Returns whether this editor is responsible for a given structure element. This editor is
144: * responsible for interaction-model structure elements.
145: *
146: * @param element the structure element
147: *
148: * @return <code>true</code> if <i>element</i> is an interaction-model structure element and
149: * not <code>null</code>, otherwise <code>false</code>
150: */
151: public boolean handlesElement(StructureElement element) {
152: return (element != null)
153: && (element instanceof InteractionModelStructureElement);
154: }
155:
156: /**
157: * Returns the actual structure element to be edited.
158: *
159: * @return DOCUMENT ME!
160: */
161: public StructureElement getElement() {
162: return element;
163: }
164:
165: /**
166: * Sets the structure element to edit.
167: *
168: * @param element DOCUMENT ME!
169: */
170: public void setElement(StructureElement element) {
171: this .element = element;
172:
173: InteractionModelStructureElement sElement = (InteractionModelStructureElement) element;
174:
175: conceptualElements
176: .setListData(sElement.getConceptualElements());
177: }
178:
179: /**
180: * Returns the component of the editor.
181: *
182: * @return the editor component
183: */
184: public Component getComponent() {
185: return editorPanel;
186: }
187: }
|