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.comp.ComponentMode;
027: import jacareto.struct.StructureElement;
028: import jacareto.system.Environment;
029: import jacareto.system.Language;
030: import jacareto.toolkit.CollectionToolkit;
031:
032: import java.awt.BorderLayout;
033: import java.awt.Color;
034: import java.awt.Component;
035: import java.awt.FlowLayout;
036: import java.awt.GridBagConstraints;
037: import java.awt.GridBagLayout;
038: import java.awt.GridLayout;
039: import java.awt.Insets;
040: import java.awt.event.ActionEvent;
041: import java.awt.event.ActionListener;
042:
043: import javax.swing.DefaultListModel;
044: import javax.swing.JButton;
045: import javax.swing.JCheckBox;
046: import javax.swing.JComboBox;
047: import javax.swing.JList;
048: import javax.swing.JPanel;
049: import javax.swing.JScrollPane;
050: import javax.swing.JTabbedPane;
051: import javax.swing.JTextField;
052: import javax.swing.border.EmptyBorder;
053: import javax.swing.border.LineBorder;
054: import javax.swing.border.TitledBorder;
055:
056: /**
057: * An editor for component mode recordables.
058: *
059: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
060: * @version 1.0
061: */
062: public class ComponentModeEditor extends Editor {
063: /** The structure element to edit. */
064: private StructureElement element;
065:
066: /** The panel for general settings. */
067: private JPanel generalPanelWrapper;
068:
069: /** The tabbed pane. */
070: private JTabbedPane editorComponent;
071:
072: /** The panel for the new root names. */
073: private JPanel namesPanel;
074:
075: /** The text field for new window names. */
076: JTextField newNameField;
077:
078: /** The list with the new root names. */
079: private JList namesList;
080:
081: /** The list model. */
082: private DefaultListModel listModel;
083:
084: /** Components for the newDialogsModal property. */
085: private JCheckBox modalCheckBox;
086: private JComboBox modalComboBox;
087:
088: /** Component for the number popup menues property. */
089: private JCheckBox numberPopupMenuesCheckBox;
090:
091: /**
092: * Create a new component mode editor.
093: *
094: * @param env the environment
095: */
096: public ComponentModeEditor(Environment env) {
097: super (env);
098:
099: Language language = getLanguage();
100:
101: JPanel generalPanel = new JPanel(new GridBagLayout());
102:
103: GridBagConstraints c = new GridBagConstraints();
104: c.insets = new Insets(5, 5, 5, 5);
105: c.anchor = GridBagConstraints.WEST;
106:
107: // The modal field
108: modalCheckBox = new JCheckBox(language
109: .getString("Components.Mode.SetNewDialogsModal")
110: + ":");
111: modalCheckBox.addActionListener(new ActionListener() {
112: public void actionPerformed(ActionEvent e) {
113: if (getElement() != null) {
114: ((ComponentMode) getElement())
115: .setApplyNewDialogsModal(modalCheckBox
116: .isSelected());
117: modalComboBox
118: .setEnabled(modalCheckBox.isSelected());
119: }
120: }
121: });
122: modalComboBox = new JComboBox();
123: modalComboBox.addItem(language.getString("General.True"));
124: modalComboBox.addItem(language.getString("General.False"));
125: modalComboBox.addActionListener(new ActionListener() {
126: public void actionPerformed(ActionEvent e) {
127: if (isUpdateOnChange && (getElement() != null)) {
128: ((ComponentMode) getElement())
129: .setNewDialogsModal(modalComboBox
130: .getSelectedIndex() == 0);
131: }
132: }
133: });
134: c.gridx = 0;
135: c.gridy = 0;
136: c.weightx = 20;
137: c.gridwidth = 1;
138: generalPanel.add(modalCheckBox, c);
139: c.gridx = 1;
140: c.gridy = 0;
141: c.weightx = 30;
142: c.gridwidth = 2;
143: generalPanel.add(modalComboBox, c);
144:
145: // The modal field
146: numberPopupMenuesCheckBox = new JCheckBox(language
147: .getString("Components.Mode.NumberPopupMenues"));
148: numberPopupMenuesCheckBox
149: .addActionListener(new ActionListener() {
150: public void actionPerformed(ActionEvent e) {
151: if (getElement() != null) {
152: ((ComponentMode) getElement())
153: .setNumberPopupMenues(numberPopupMenuesCheckBox
154: .isSelected());
155: }
156: }
157: });
158: c.gridx = 0;
159: c.gridy = 1;
160: c.weightx = 20;
161: c.gridwidth = 1;
162: generalPanel.add(numberPopupMenuesCheckBox, c);
163:
164: generalPanelWrapper = new JPanel(
165: new FlowLayout(FlowLayout.LEFT));
166: generalPanelWrapper.add(generalPanel);
167:
168: // The panel for the new root names
169: listModel = new DefaultListModel();
170: namesList = new JList(listModel);
171:
172: JScrollPane namesListScrollPane = new JScrollPane(namesList);
173: TitledBorder namesListBorder = new TitledBorder(new LineBorder(
174: Color.black), language
175: .getString("Editors.ComponentModeEditor.NewRootNames"));
176: namesListScrollPane.setBorder(namesListBorder);
177:
178: JButton addButton = new JButton(language
179: .getString("Editors.ComponentModeEditor.Buttons.Add"));
180: addButton.addActionListener(new ActionListener() {
181: public void actionPerformed(ActionEvent e) {
182: if (isUpdateOnChange && (getElement() != null)
183: && (newNameField.getText() != null)
184: && !newNameField.getText().equals("")) {
185: listModel.addElement(newNameField.getText());
186: ((ComponentMode) getElement())
187: .addNewRootName(newNameField.getText());
188: newNameField.setText("");
189: }
190: }
191: });
192:
193: JButton removeButton = new JButton(
194: language
195: .getString("Editors.ComponentModeEditor.Buttons.Remove"));
196: removeButton.addActionListener(new ActionListener() {
197: public void actionPerformed(ActionEvent e) {
198: if (isUpdateOnChange && (getElement() != null)) {
199: int[] selectedIndices = namesList
200: .getSelectedIndices();
201:
202: for (int i = selectedIndices.length - 1; i >= 0; i--) {
203: listModel.remove(selectedIndices[i]);
204: ((ComponentMode) getElement())
205: .removeNewRootName(selectedIndices[i]);
206: }
207: }
208: }
209: });
210:
211: JButton clearButton = new JButton(language
212: .getString("Editors.ComponentModeEditor.Buttons.Clear"));
213: clearButton.addActionListener(new ActionListener() {
214: public void actionPerformed(ActionEvent e) {
215: if (isUpdateOnChange && (getElement() != null)) {
216: listModel.clear();
217: ((ComponentMode) getElement()).clearNewRootNames();
218: }
219: }
220: });
221:
222: JPanel newNamePanel = new JPanel(
223: new FlowLayout(FlowLayout.LEFT));
224: newNameField = new JTextField(30);
225: newNamePanel.add(newNameField);
226: newNamePanel.add(addButton);
227:
228: JPanel namesButtonPanel = new JPanel(new FlowLayout(
229: FlowLayout.LEFT));
230: namesButtonPanel.add(removeButton);
231: namesButtonPanel.add(clearButton);
232:
233: JPanel controlPanel = new JPanel(new GridLayout(2, 1));
234: controlPanel.add(namesButtonPanel);
235: controlPanel.add(newNamePanel);
236:
237: namesPanel = new JPanel();
238: namesPanel.setLayout(new BorderLayout());
239: namesPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
240: namesPanel.add(namesListScrollPane, BorderLayout.CENTER);
241: namesPanel.add(controlPanel, BorderLayout.SOUTH);
242: }
243:
244: /**
245: * Returns whether this editor is responsible for a given structure element. This editor is
246: * responsible for window properties recordables.
247: *
248: * @param element the structure element
249: *
250: * @return <code>true</code> if <i>element</i> is an window properties recordable and not
251: * <code>null</code>, otherwise <code>false</code>
252: */
253: public boolean handlesElement(StructureElement element) {
254: return (element != null) && (element instanceof ComponentMode);
255: }
256:
257: /**
258: * Returns the editor component.
259: *
260: * @return the component
261: */
262: public Component getComponent() {
263: if (editorComponent == null) {
264: editorComponent = new JTabbedPane();
265:
266: editorComponent
267: .addTab(
268: language
269: .getString("Editors.ComponentModeEditor.TabTitles.General"),
270: generalPanelWrapper);
271: editorComponent
272: .addTab(
273: language
274: .getString("Editors.ComponentModeEditor.TabTitles.NewRootNames"),
275: namesPanel);
276: }
277:
278: return editorComponent;
279: }
280:
281: /**
282: * Returns the actual structure element to be edited.
283: *
284: * @return the element
285: */
286: public StructureElement getElement() {
287: return element;
288: }
289:
290: /**
291: * Sets the structure element to edit.
292: *
293: * @param element the structure element
294: */
295: public void setElement(StructureElement element) {
296: this .element = element;
297:
298: ComponentMode mode = (ComponentMode) element;
299:
300: // modal components
301: modalCheckBox.setSelected(mode.getApplyNewDialogsModal());
302:
303: if (mode.getNewDialogsModal()) {
304: modalComboBox.setSelectedIndex(0);
305: } else {
306: modalComboBox.setSelectedIndex(1);
307: }
308:
309: modalComboBox.setEnabled(mode.getApplyNewDialogsModal());
310:
311: // modal components
312: numberPopupMenuesCheckBox.setSelected(mode
313: .getNumberPopupMenues());
314:
315: listModel.clear();
316: CollectionToolkit.add(mode.getNewRootNames(), listModel);
317: }
318: }
|