/*
* 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.MouseEventRecordable;
import jacareto.struct.StructureElement;
import jacareto.system.Environment;
import jacareto.system.Language;
import jacareto.toolkit.event.TextValueListener;
import jacareto.toolkit.swing.IntegerTextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import javax.swing.JComboBox;
import javax.swing.event.DocumentEvent;
/**
* An editor for mouse events which are not mouse motions.
*
* @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
* @version 1.02
*/
public class MouseEventRecordableEditor extends InputEventRecordableEditor {
/** The text field for the x position. */
private IntegerTextField xPosField;
/** The text field for the y position. */
private IntegerTextField yPosField;
/** The text field for the root x position. */
private IntegerTextField rootXPosField;
/** The text field for the root y position. */
private IntegerTextField rootYPosField;
/** The text field for the click count. */
private IntegerTextField clickCountField;
/** The popup Trigger box. */
private JComboBox popupTriggerBox;
/** The type box. */
private JComboBox typeBox;
/**
* Create a new mouse event recordable editor.
*
* @param env the environment
*/
public MouseEventRecordableEditor (Environment env) {
super(env);
Language language = getLanguage ();
// The type box
typeBox = addComboBoxRow (language.getString ("Events.MouseEvent.Type"));
typeBox.addItem (language.getString ("Events.MouseEvent.MousePressed"));
typeBox.addItem (language.getString ("Events.MouseEvent.MouseReleased"));
typeBox.addItem (language.getString ("Events.MouseEvent.MouseClicked"));
typeBox.addItem (language.getString ("Events.MouseEvent.MouseEntered"));
typeBox.addItem (language.getString ("Events.MouseEvent.MouseExited"));
typeBox.addItem (language.getString ("Events.MouseEvent.MouseMoved"));
typeBox.addItem (language.getString ("Events.MouseEvent.MouseDragged"));
typeBox.addActionListener (new ActionListener() {
public void actionPerformed (ActionEvent e) {
MouseEventRecordable mRecordable = (MouseEventRecordable) getElement ();
if (isUpdateOnChange && (mRecordable != null)) {
switch (typeBox.getSelectedIndex ()) {
case 0:
mRecordable.setID (MouseEvent.MOUSE_PRESSED);
break;
case 1:
mRecordable.setID (MouseEvent.MOUSE_RELEASED);
break;
case 2:
mRecordable.setID (MouseEvent.MOUSE_CLICKED);
break;
case 3:
mRecordable.setID (MouseEvent.MOUSE_ENTERED);
break;
case 4:
mRecordable.setID (MouseEvent.MOUSE_EXITED);
break;
case 5:
mRecordable.setID (MouseEvent.MOUSE_MOVED);
break;
case 6:
mRecordable.setID (MouseEvent.MOUSE_DRAGGED);
break;
}
}
}
});
// The x pos field
xPosField = addIntegerTextFieldRow (language.getString ("Events.MouseEvent.XPosition"), 5);
xPosField.getDocument ().addDocumentListener (new TextValueListener() {
public void textValueChanged (DocumentEvent e) {
if (isUpdateOnChange && (getElement () != null)) {
MouseEventRecordable meRecordable = (MouseEventRecordable) getElement ();
int diffX = xPosField.getValue () - meRecordable.getX ();
meRecordable.setX (xPosField.getValue ());
meRecordable.setRootX (meRecordable.getRootX () + diffX);
rootXPosField.setValue (meRecordable.getRootX ());
}
}
});
// The y pos field
yPosField = addIntegerTextFieldRow (language.getString ("Events.MouseEvent.YPosition"), 5);
yPosField.getDocument ().addDocumentListener (new TextValueListener() {
public void textValueChanged (DocumentEvent e) {
if (isUpdateOnChange && (getElement () != null)) {
MouseEventRecordable meRecordable = (MouseEventRecordable) getElement ();
int diffY = yPosField.getValue () - meRecordable.getY ();
meRecordable.setY (yPosField.getValue ());
meRecordable.setRootY (meRecordable.getRootY () + diffY);
rootYPosField.setValue (meRecordable.getRootY ());
}
}
});
// The root x pos field
rootXPosField = addIntegerTextFieldRow (language.getString (
"Events.MouseEvent.RootXPosition"), 5);
rootXPosField.setEditable (false);
// The root y pos field
rootYPosField = addIntegerTextFieldRow (language.getString (
"Events.MouseEvent.RootYPosition"), 5);
rootYPosField.setEditable (false);
// The click count field
clickCountField = addIntegerTextFieldRow (language.getString (
"Events.MouseEvent.ClickCount"), 5);
clickCountField.getDocument ().addDocumentListener (new TextValueListener() {
public void textValueChanged (DocumentEvent e) {
if (isUpdateOnChange && (getElement () != null)) {
((MouseEventRecordable) getElement ()).setClickCount (clickCountField.getValue ());
}
}
});
// The is popup trigger box
popupTriggerBox = addComboBoxRow (language.getString ("Events.MouseEvent.PopupTrigger"));
popupTriggerBox.addItem (language.getString ("General.True"));
popupTriggerBox.addItem (language.getString ("General.False"));
popupTriggerBox.addActionListener (new ActionListener() {
public void actionPerformed (ActionEvent e) {
if (isUpdateOnChange && (getElement () != null)) {
if (popupTriggerBox.getSelectedIndex () == 0) {
((MouseEventRecordable) getElement ()).setConsumed (true);
} else {
((MouseEventRecordable) getElement ()).setConsumed (false);
}
}
}
});
}
/**
* Returns whether this editor is responsible for a given structure element. This editor is
* responsible for all event recordables.
*
* @param element the structure element
*
* @return <code>true</code> if <i>element</i> is a mouse event recordable and not
* <code>null</code>, otherwise <code>false</code>
*/
public boolean handlesElement (StructureElement element) {
return (element != null) && (element instanceof MouseEventRecordable);
}
/**
* Sets the element to edit.
*
* @param element DOCUMENT ME!
*/
public void setElement (StructureElement element) {
super.setElement (element);
MouseEventRecordable mRecordable = (MouseEventRecordable) element;
xPosField.setValue (mRecordable.getX ());
yPosField.setValue (mRecordable.getY ());
rootXPosField.setValue (mRecordable.getRootX ());
rootYPosField.setValue (mRecordable.getRootY ());
clickCountField.setValue (mRecordable.getClickCount ());
if (mRecordable.isPopupTrigger ()) {
popupTriggerBox.setSelectedIndex (0);
} else {
popupTriggerBox.setSelectedIndex (1);
}
switch (mRecordable.getID ()) {
case MouseEvent.MOUSE_PRESSED:
typeBox.setSelectedIndex (0);
break;
case MouseEvent.MOUSE_RELEASED:
typeBox.setSelectedIndex (1);
break;
case MouseEvent.MOUSE_CLICKED:
typeBox.setSelectedIndex (2);
break;
case MouseEvent.MOUSE_ENTERED:
typeBox.setSelectedIndex (3);
break;
case MouseEvent.MOUSE_EXITED:
typeBox.setSelectedIndex (4);
break;
case MouseEvent.MOUSE_MOVED:
typeBox.setSelectedIndex (5);
break;
case MouseEvent.MOUSE_DRAGGED:
typeBox.setSelectedIndex (6);
break;
}
}
}
|