/*
* Jacareto Copyright (c) 2002-2005
* Applied Computer Science Research Group, Darmstadt University of
* Technology, Institute of Mathematics & Computer Science,
* Ludwigsburg University of Education, and Computer Based
* Learning Research Group, Aachen University. All rights reserved.
*
* Jacareto is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* Jacareto is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with Jacareto; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
package jacareto.editor;
import jacareto.record.InputEventRecordable;
import jacareto.struct.StructureElement;
import jacareto.system.Environment;
import jacareto.system.Language;
import jacareto.toolkit.event.TextValueListener;
import jacareto.toolkit.swing.IntegerTextField;
import jacareto.toolkit.swing.LongTextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JComboBox;
import javax.swing.event.DocumentEvent;
/**
* An editor for input event recordables.
*
* @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
* @version 1.02
*/
public class InputEventRecordableEditor extends ComponentEventRecordableEditor {
/** The text field for the when attribute. */
private LongTextField whenField;
/** The text field for the modifiers attribute. */
private IntegerTextField modifiersField;
/** The combo box for the "is consumed" attribute. */
private JComboBox isConsumedBox;
/**
* Create a new input event recordable editor.
*
* @param env the environment
*/
public InputEventRecordableEditor (Environment env) {
super(env);
Language language = getLanguage ();
// The when field.
whenField = addLongTextFieldRow (language.getString ("Events.InputEvent.When"), 10);
whenField.getDocument ().addDocumentListener (new TextValueListener() {
public void textValueChanged (DocumentEvent e) {
if (isUpdateOnChange && (getElement () != null)) {
((InputEventRecordable) getElement ()).setWhen (whenField.getValue ());
}
}
});
// The modifiers field.
modifiersField = addIntegerTextFieldRow (language.getString ("Events.InputEvent.Modifiers"),
10);
modifiersField.getDocument ().addDocumentListener (new TextValueListener() {
public void textValueChanged (DocumentEvent e) {
if (isUpdateOnChange && (getElement () != null)) {
((InputEventRecordable) getElement ()).setModifiers (modifiersField.getValue ());
}
}
});
// The is consumed box
isConsumedBox = addComboBoxRow (language.getString ("Events.InputEvent.Consumed"));
isConsumedBox.addItem (language.getString ("General.True"));
isConsumedBox.addItem (language.getString ("General.False"));
isConsumedBox.addActionListener (new ActionListener() {
public void actionPerformed (ActionEvent e) {
if (isUpdateOnChange && (getElement () != null)) {
if (isConsumedBox.getSelectedIndex () == 0) {
((InputEventRecordable) getElement ()).setConsumed (true);
} else {
((InputEventRecordable) getElement ()).setConsumed (false);
}
}
}
});
}
/**
* Returns whether this editor is responsible for a given structure element This editor is
* responsible for all input event recordables.
*
* @param element the structure element
*
* @return <code>true</code> if <i>element</i> is an input event recordable and not
* <code>null</code>, otherwise <code>false</code>
*/
public boolean handlesElement (StructureElement element) {
return (element != null) && (element instanceof InputEventRecordable);
}
/**
* Sets the structure element to edit.
*
* @param element DOCUMENT ME!
*/
public void setElement (StructureElement element) {
super.setElement (element);
InputEventRecordable iRecordable = (InputEventRecordable) element;
whenField.setValue (iRecordable.getWhen ());
modifiersField.setValue (iRecordable.getModifiers ());
if (iRecordable.isConsumed ()) {
isConsumedBox.setSelectedIndex (0);
} else {
isConsumedBox.setSelectedIndex (1);
}
}
}
|