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.ComponentPropertiesRecordable;
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.JCheckBox;
039: import javax.swing.JComboBox;
040: import javax.swing.JPanel;
041:
042: /**
043: * An editor for component mode recordables.
044: *
045: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
046: * @version 1.0
047: */
048: public class ComponentPropertiesRecordableEditor extends Editor {
049: /** The structure element to edit. */
050: private StructureElement element;
051:
052: /** The editor component. */
053: private JPanel editorComponent;
054:
055: /** Components for the isEnabled property. */
056: private JCheckBox isEnabledCheckBox;
057: private JComboBox isEnabledComboBox;
058:
059: /** Components for the isVisible property. */
060: private JCheckBox isVisibleCheckBox;
061: private JComboBox isVisibleComboBox;
062: private JCheckBox keepEnabledStateCheckBox;
063:
064: /**
065: * Create a new editor.
066: *
067: * @param env the environment
068: */
069: public ComponentPropertiesRecordableEditor(Environment env) {
070: super (env);
071:
072: Language language = getLanguage();
073:
074: editorComponent = new JPanel(new GridBagLayout());
075:
076: GridBagConstraints c = new GridBagConstraints();
077: c.insets = new Insets(5, 5, 5, 5);
078: c.anchor = GridBagConstraints.WEST;
079: c.fill = GridBagConstraints.NONE;
080:
081: // The enabled field
082: isEnabledCheckBox = new JCheckBox(
083: language
084: .getString("Recordables.ComponentPropertiesRecordable.Attributes.IsEnabled")
085: + ":");
086: isEnabledCheckBox.addActionListener(new ActionListener() {
087: public void actionPerformed(ActionEvent e) {
088: if (getElement() != null) {
089: ((ComponentPropertiesRecordable) getElement())
090: .setApplyIsEnabled(isEnabledCheckBox
091: .isSelected());
092: isEnabledComboBox.setEnabled(isEnabledCheckBox
093: .isSelected());
094: }
095: }
096: });
097: isEnabledComboBox = new JComboBox();
098: isEnabledComboBox.addItem(language.getString("General.True"));
099: isEnabledComboBox.addItem(language.getString("General.False"));
100: isEnabledComboBox.addActionListener(new ActionListener() {
101: public void actionPerformed(ActionEvent e) {
102: if (isUpdateOnChange && (getElement() != null)) {
103: ((ComponentPropertiesRecordable) getElement())
104: .setIsEnabled(isEnabledComboBox
105: .getSelectedIndex() == 0);
106: }
107: }
108: });
109: c.gridx = 0;
110: c.gridy = 0;
111: c.weightx = 20;
112: c.gridwidth = 1;
113: editorComponent.add(isEnabledCheckBox, c);
114: c.gridx = 1;
115: c.gridy = 0;
116: c.weightx = 30;
117: c.gridwidth = 1;
118: editorComponent.add(isEnabledComboBox, c);
119:
120: // The visible field
121: isVisibleCheckBox = new JCheckBox(
122: language
123: .getString("Recordables.ComponentPropertiesRecordable.Attributes.IsVisible")
124: + ":");
125: isVisibleCheckBox.addActionListener(new ActionListener() {
126: public void actionPerformed(ActionEvent e) {
127: if (getElement() != null) {
128: ((ComponentPropertiesRecordable) getElement())
129: .setApplyIsVisible(isVisibleCheckBox
130: .isSelected());
131: isVisibleComboBox.setEnabled(isVisibleCheckBox
132: .isSelected());
133: }
134: }
135: });
136: isVisibleComboBox = new JComboBox();
137: isVisibleComboBox.addItem(language.getString("General.True"));
138: isVisibleComboBox.addItem(language.getString("General.False"));
139: isVisibleComboBox.addActionListener(new ActionListener() {
140: public void actionPerformed(ActionEvent e) {
141: if (isUpdateOnChange && (getElement() != null)) {
142: ((ComponentPropertiesRecordable) getElement())
143: .setIsVisible(isVisibleComboBox
144: .getSelectedIndex() == 0);
145: }
146: }
147: });
148: c.gridx = 0;
149: c.gridy = 1;
150: c.weightx = 20;
151: c.gridwidth = 1;
152: editorComponent.add(isVisibleCheckBox, c);
153: c.gridx = 1;
154: c.gridy = 1;
155: c.weightx = 30;
156: c.gridwidth = 1;
157: editorComponent.add(isVisibleComboBox, c);
158:
159: // The keep state field
160: keepEnabledStateCheckBox = new JCheckBox(
161: language
162: .getString("Recordables.ComponentPropertiesRecordable.Attributes.KeepEnabledState"));
163: keepEnabledStateCheckBox
164: .addActionListener(new ActionListener() {
165: public void actionPerformed(ActionEvent e) {
166: if (getElement() != null) {
167: ((ComponentPropertiesRecordable) getElement())
168: .setKeepState(keepEnabledStateCheckBox
169: .isSelected());
170: }
171: }
172: });
173: c.gridx = 0;
174: c.gridy = 2;
175: editorComponent.add(keepEnabledStateCheckBox, c);
176: }
177:
178: /**
179: * Returns whether this editor is responsible for a given structure element. This editor is
180: * responsible for window properties recordables.
181: *
182: * @param element the structure element
183: *
184: * @return <code>true</code> if <i>element</i> is an window properties recordable and not
185: * <code>null</code>, otherwise <code>false</code>
186: */
187: public boolean handlesElement(StructureElement element) {
188: return (element != null)
189: && (element instanceof ComponentPropertiesRecordable);
190: }
191:
192: /**
193: * Returns the editor component.
194: *
195: * @return the component
196: */
197: public Component getComponent() {
198: return editorComponent;
199: }
200:
201: /**
202: * Returns the actual structure element to be edited.
203: *
204: * @return the element
205: */
206: public StructureElement getElement() {
207: return element;
208: }
209:
210: /**
211: * Sets the structure element to edit.
212: *
213: * @param element the structure element
214: */
215: public void setElement(StructureElement element) {
216: this .element = element;
217:
218: ComponentPropertiesRecordable recordable = (ComponentPropertiesRecordable) element;
219:
220: // isEnabled
221: isEnabledCheckBox.setSelected(recordable.getApplyIsEnabled());
222:
223: if (recordable.getIsEnabled()) {
224: isEnabledComboBox.setSelectedIndex(0);
225: } else {
226: isEnabledComboBox.setSelectedIndex(1);
227: }
228:
229: isEnabledComboBox.setEnabled(recordable.getApplyIsEnabled());
230:
231: // isVisible
232: isVisibleCheckBox.setSelected(recordable.getApplyIsVisible());
233:
234: if (recordable.getIsVisible()) {
235: isVisibleComboBox.setSelectedIndex(0);
236: } else {
237: isVisibleComboBox.setSelectedIndex(1);
238: }
239:
240: isVisibleComboBox.setEnabled(recordable.getApplyIsVisible());
241:
242: keepEnabledStateCheckBox.setSelected(recordable.getKeepState());
243: }
244: }
|