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.ListSelectionEventRecordable;
027: import jacareto.struct.StructureElement;
028: import jacareto.system.Environment;
029: import jacareto.system.Language;
030: import jacareto.toolkit.event.TextValueListener;
031: import jacareto.toolkit.swing.IntegerTextField;
032:
033: import java.awt.event.ActionEvent;
034: import java.awt.event.ActionListener;
035:
036: import javax.swing.JComboBox;
037: import javax.swing.event.DocumentEvent;
038:
039: /**
040: * An editor for list selection event recordables.
041: *
042: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
043: * @version 1.00
044: */
045: public class ListSelectionEventRecordableEditor extends
046: EventObjectRecordableEditor {
047: /** The text field for the first index. */
048: private IntegerTextField firstIndexField;
049:
050: /** The text field for the last index. */
051: private IntegerTextField lastIndexField;
052:
053: /** The combo box for the "value is adjusting" value. */
054: private JComboBox adjustingBox;
055:
056: /**
057: * Create a new list selection event recordable editor.
058: *
059: * @param env the environment
060: */
061: public ListSelectionEventRecordableEditor(Environment env) {
062: super (env);
063:
064: Language language = getLanguage();
065:
066: // The first index field.
067: firstIndexField = addIntegerTextFieldRow(language
068: .getString("Events.ListSelectionEvent.FirstIndex"), 5);
069: firstIndexField.getDocument().addDocumentListener(
070: new TextValueListener() {
071: public void textValueChanged(DocumentEvent e) {
072: if (isUpdateOnChange && (getElement() != null)) {
073: ((ListSelectionEventRecordable) getElement())
074: .setFirstIndex(firstIndexField
075: .getValue());
076: }
077: }
078: });
079:
080: // The last index field.
081: lastIndexField = addIntegerTextFieldRow(language
082: .getString("Events.ListSelectionEvent.LastIndex"), 5);
083: lastIndexField.getDocument().addDocumentListener(
084: new TextValueListener() {
085: public void textValueChanged(DocumentEvent e) {
086: if (isUpdateOnChange && (getElement() != null)) {
087: ((ListSelectionEventRecordable) getElement())
088: .setLastIndex(lastIndexField
089: .getValue());
090: }
091: }
092: });
093:
094: // The valueIsAdjusting box
095: adjustingBox = addComboBoxRow(language
096: .getString("Events.MouseEvent.PopupTrigger"));
097: adjustingBox.addItem(language.getString("General.True"));
098: adjustingBox.addItem(language.getString("General.False"));
099: adjustingBox.addActionListener(new ActionListener() {
100: public void actionPerformed(ActionEvent e) {
101: if (isUpdateOnChange && (getElement() != null)) {
102: if (adjustingBox.getSelectedIndex() == 0) {
103: ((ListSelectionEventRecordable) getElement())
104: .setValueIsAdjusting(true);
105: } else {
106: ((ListSelectionEventRecordable) getElement())
107: .setValueIsAdjusting(false);
108: }
109: }
110: }
111: });
112: }
113:
114: /**
115: * Returns whether this editor is responsible for a given structure element. This editor is
116: * responsible for all list selection event recordables.
117: *
118: * @param element the structure element
119: *
120: * @return <code>true</code> if <i>element</i> is a list selection event recordable and not
121: * <code>null</code>, otherwise <code>false</code>
122: */
123: public boolean handlesElement(StructureElement element) {
124: return (element != null)
125: && (element instanceof ListSelectionEventRecordable);
126: }
127:
128: /**
129: * Sets the structure element to edit.
130: *
131: * @param element DOCUMENT ME!
132: */
133: public void setElement(StructureElement element) {
134: super .setElement(element);
135:
136: ListSelectionEventRecordable lRecordable = (ListSelectionEventRecordable) element;
137: firstIndexField.setValue(lRecordable.getFirstIndex());
138: lastIndexField.setValue(lRecordable.getLastIndex());
139:
140: if (lRecordable.getValueIsAdjusting()) {
141: adjustingBox.setSelectedIndex(0);
142: } else {
143: adjustingBox.setSelectedIndex(1);
144: }
145: }
146: }
|