/*
* 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.struct.MouseChangedComponent;
import jacareto.struct.StructureElement;
import jacareto.system.Environment;
import jacareto.system.Language;
import java.awt.Component;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
/**
* An editor for "mouse changed component" elements.
*
* @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
* @version 1.01
*/
public class MouseChangedComponentEditor extends Editor {
/** The element to edit. */
private StructureElement element;
/** The panel. */
private JPanel editorPanel;
/** The grid bag constraints. */
private GridBagConstraints c;
/** The text field for the old component name. */
private JTextField oldComponentField;
/** The text field for the new component name. */
private JTextField newComponentField;
/**
* Create a new "mouse exited" recordable editor.
*
* @param env the environment
*/
public MouseChangedComponentEditor (Environment env) {
super(env);
Language language = getLanguage ();
// The panel with the text fields
editorPanel = new JPanel();
editorPanel.setBorder (new EmptyBorder(10, 10, 10, 10));
editorPanel.setLayout (new GridBagLayout());
// The old component field label
c = new GridBagConstraints();
c.gridx = 0;
c.gridy = 0;
c.weightx = 40;
c.ipadx = 5;
c.ipady = 5;
c.anchor = GridBagConstraints.WEST;
JLabel oldComponentFieldLabel = new JLabel(language.getString (
"Structures.MouseChangedComponent.OldComponent") + ":");
editorPanel.add (oldComponentFieldLabel, c);
// The old component field
c.gridx = 1;
c.weightx = 60;
oldComponentField = new JTextField("", 20);
oldComponentField.setEditable (false);
editorPanel.add (oldComponentField, c);
oldComponentFieldLabel.setLabelFor (oldComponentField);
// The new component field label
c.gridx = 0;
c.gridy = 1;
JLabel newComponentFieldLabel = new JLabel(language.getString (
"Structures.MouseChangedComponent.NewComponent") + ":");
editorPanel.add (newComponentFieldLabel, c);
// The old component field
c.gridx = 1;
newComponentField = new JTextField("", 20);
newComponentField.setEditable (false);
editorPanel.add (newComponentField, c);
newComponentFieldLabel.setLabelFor (newComponentField);
}
/**
* Returns whether this editor is responsible for a given structure element. This editor is
* responsible for all "mouse exited" elements.
*
* @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 MouseChangedComponent);
}
/**
* Returns the actual structure element to be edited.
*
* @return DOCUMENT ME!
*/
public StructureElement getElement () {
return element;
}
/**
* Sets the element to edit.
*
* @param element DOCUMENT ME!
*/
public void setElement (StructureElement element) {
this.element = element;
MouseChangedComponent changed = (MouseChangedComponent) element;
oldComponentField.setText (changed.getOldComponent ());
oldComponentField.setCaretPosition (0);
newComponentField.setText (changed.getNewComponent ());
newComponentField.setCaretPosition (0);
}
/**
* Returns the component of the editor.
*
* @return the editor component
*/
public Component getComponent () {
return editorPanel;
}
}
|