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.Sequence;
027: import jacareto.struct.StructureElement;
028: import jacareto.system.Environment;
029: import jacareto.system.Language;
030: import jacareto.toolkit.swing.IntegerTextField;
031: import jacareto.toolkit.swing.LongTextField;
032:
033: import java.awt.Component;
034: import java.awt.GridBagConstraints;
035: import java.awt.GridBagLayout;
036:
037: import javax.swing.JLabel;
038: import javax.swing.JPanel;
039: import javax.swing.JTextField;
040: import javax.swing.border.EmptyBorder;
041:
042: /**
043: * An editor for JacShow sequences.
044: *
045: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
046: * @version 1.01
047: */
048: public class SequenceEditor extends Editor {
049: /** The element to edit. */
050: private StructureElement element;
051:
052: /** The panel. */
053: private JPanel editorPanel;
054:
055: /** The grid bag constraints. */
056: private GridBagConstraints c;
057:
058: /** The text field for the sequence name. */
059: private JTextField nameField;
060:
061: /** The text field for the performance duration. */
062: private LongTextField pdField;
063:
064: /** The text field for the special durations. */
065: private LongTextField daField;
066:
067: /** The text field for the special durations. */
068: private LongTextField dbField;
069:
070: /** The text field for the count B. */
071: private IntegerTextField countBField;
072:
073: /**
074: * Create a new editor.
075: *
076: * @param env the environment
077: */
078: public SequenceEditor(Environment env) {
079: super (env);
080:
081: Language language = getLanguage();
082:
083: // The panel with the text fields
084: editorPanel = new JPanel();
085: editorPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
086: editorPanel.setLayout(new GridBagLayout());
087:
088: // The source field label
089: c = new GridBagConstraints();
090: c.gridx = 0;
091: c.gridy = 0;
092: c.weightx = 40;
093: c.ipadx = 5;
094: c.ipady = 5;
095: c.anchor = GridBagConstraints.WEST;
096:
097: JLabel nameFieldLabel = new JLabel(language
098: .getString("Editors.SequenceEditor.SequenceName")
099: + ":");
100: editorPanel.add(nameFieldLabel, c);
101:
102: // The source field
103: c.gridx = 1;
104: c.weightx = 60;
105: nameField = new JTextField("", 20);
106: nameField.setEditable(false);
107: nameField.setBackground(editorPanel.getBackground());
108: editorPanel.add(nameField, c);
109: nameFieldLabel.setLabelFor(nameField);
110:
111: // The performance duration field label
112: c.gridx = 0;
113: c.gridy = 1;
114:
115: JLabel pdFieldLabel = new JLabel(
116: language
117: .getString("Editors.SequenceEditor.PerformanceDuration")
118: + ":");
119: editorPanel.add(pdFieldLabel, c);
120:
121: // The start x field
122: c.gridx = 1;
123: pdField = new LongTextField(0, 10);
124: pdField.setEditable(false);
125: pdField.setBackground(editorPanel.getBackground());
126: editorPanel.add(pdField, c);
127: pdFieldLabel.setLabelFor(pdField);
128:
129: // The durationA field label
130: c.gridx = 0;
131: c.gridy = 2;
132:
133: JLabel daFieldLabel = new JLabel(language
134: .getString("Editors.SequenceEditor.DurationA")
135: + ":");
136: editorPanel.add(daFieldLabel, c);
137:
138: // The start x field
139: c.gridx = 1;
140: daField = new LongTextField(0, 10);
141: daField.setEditable(false);
142: daField.setBackground(editorPanel.getBackground());
143: editorPanel.add(daField, c);
144: daFieldLabel.setLabelFor(daField);
145:
146: // The durationB field label
147: c.gridx = 0;
148: c.gridy = 3;
149:
150: JLabel dbFieldLabel = new JLabel(language
151: .getString("Editors.SequenceEditor.DurationB")
152: + ":");
153: editorPanel.add(dbFieldLabel, c);
154:
155: // The start x field
156: c.gridx = 1;
157: dbField = new LongTextField(0, 10);
158: dbField.setEditable(false);
159: dbField.setBackground(editorPanel.getBackground());
160: editorPanel.add(dbField, c);
161: dbFieldLabel.setLabelFor(dbField);
162:
163: // The countB field label
164: c.gridx = 0;
165: c.gridy = 4;
166:
167: JLabel countBFieldLabel = new JLabel(language
168: .getString("Editors.SequenceEditor.CountB")
169: + ":");
170: editorPanel.add(countBFieldLabel, c);
171:
172: // The start x field
173: c.gridx = 1;
174: countBField = new IntegerTextField(0, 10);
175: countBField.setEditable(false);
176: countBField.setBackground(editorPanel.getBackground());
177: editorPanel.add(countBField, c);
178: countBFieldLabel.setLabelFor(countBField);
179: }
180:
181: /**
182: * Returns whether this editor is responsible for a given structure element. This editor is
183: * responsible for all mouse drag elements.
184: *
185: * @param element the structure element
186: *
187: * @return <code>true</code> if <i>element</i> is a mouse event recordable and not
188: * <code>null</code>, otherwise <code>false</code>
189: */
190: public boolean handlesElement(StructureElement element) {
191: return (element != null) && (element instanceof Sequence);
192: }
193:
194: /**
195: * Returns the actual structure element to be edited.
196: *
197: * @return DOCUMENT ME!
198: */
199: public StructureElement getElement() {
200: return element;
201: }
202:
203: /**
204: * Sets the element to edit.
205: *
206: * @param element DOCUMENT ME!
207: */
208: public void setElement(StructureElement element) {
209: this .element = element;
210:
211: Sequence sequence = (Sequence) element;
212: pdField.setValue(sequence.getPerformanceDuration());
213: daField.setValue(sequence.getDurationA());
214: dbField.setValue(sequence.getDurationB());
215: countBField.setValue(sequence.getCountB());
216: nameField.setText(sequence.getName());
217: nameField.setCaretPosition(0);
218: }
219:
220: /**
221: * Returns the component of the editor.
222: *
223: * @return the editor component
224: */
225: public Component getComponent() {
226: return editorPanel;
227: }
228: }
|