/*
* 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.EventObjectRecordable;
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.Component;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
import javax.swing.event.DocumentEvent;
import javax.swing.*;
/**
* <p>
* An editor which offers some standard methods for adding GUI elements
* </p>
*
* <p>
* If a subclass overwrites the method {@link #setElement(StructureElement)}, it should call the
* method of its superclass first.
* </p>
*
*
* @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
* @version 1.01
*/
public abstract class EnhancedEditor extends Editor {
/** The editor's component. */
protected JPanel editorPanel;
/** The GridBagConstraints. */
protected GridBagConstraints c;
/** The structure element to edit. */
private StructureElement element;
/** The number of rows contained in the editor's panel. */
private int rowCount;
/**
* Create a new event object recordable editor.
*
* @param env the environment
*/
public EnhancedEditor (Environment env) {
super(env);
Language language = getLanguage ();
rowCount = 0;
// The panel with the text fields
editorPanel = new JPanel();
editorPanel.setBorder (new EmptyBorder(10, 10, 10, 10));
editorPanel.setLayout (new GridBagLayout());
// Init the constraints
c = new GridBagConstraints();
c.ipadx = 5;
c.ipady = 5;
c.anchor = GridBagConstraints.WEST;
}
/**
* Adds a text field row to the editor's component. The text field is editable by default.
*
* @param labelText the text of the label
* @param length the number of columns of the text field
*
* @return the text field of that row
*/
protected JTextField addTextFieldRow (String labelText, int length) {
c.gridx = 0;
c.weightx = 40;
c.gridy = rowCount;
JLabel label = new JLabel(labelText + ":");
editorPanel.add (label, c);
c.gridx = 1;
c.weightx = 60;
JTextField result = new JTextField("", length);
editorPanel.add (result, c);
label.setLabelFor (result);
rowCount++;
return result;
}
/**
* Adds an integer text field row to the editor's component. The integer text field is editable
* by default.
*
* @param labelText the text of the label
* @param length the number of columns of the text field
*
* @return the integer text field of that row
*/
protected IntegerTextField addIntegerTextFieldRow (String labelText, int length) {
c.gridx = 0;
c.weightx = 40;
c.gridy = rowCount;
JLabel label = new JLabel(labelText + ":");
editorPanel.add (label, c);
c.gridx = 1;
c.weightx = 60;
IntegerTextField result = new IntegerTextField(length);
editorPanel.add (result, c);
label.setLabelFor (result);
rowCount++;
return result;
}
/**
* Adds a long text field row to the editor's component. The long text field is editable by
* default.
*
* @param labelText the text of the label
* @param length the number of columns of the text field
*
* @return the long text field of that row
*/
protected LongTextField addLongTextFieldRow (String labelText, int length) {
c.gridx = 0;
c.weightx = 40;
c.gridy = rowCount;
JLabel label = new JLabel(labelText + ":");
editorPanel.add (label, c);
c.gridx = 1;
c.weightx = 60;
LongTextField result = new LongTextField(length);
editorPanel.add (result, c);
label.setLabelFor (result);
rowCount++;
return result;
}
/**
* Adds a combobox row to the editor's component.
*
* @param labelText the text of the label
*
* @return the combo box of that row
*/
protected JComboBox addComboBoxRow (String labelText) {
c.gridx = 0;
c.weightx = 40;
c.gridy = rowCount;
JLabel label = new JLabel(labelText + ":");
editorPanel.add (label, c);
c.gridx = 1;
c.weightx = 60;
JComboBox result = new JComboBox();
editorPanel.add (result, c);
label.setLabelFor (result);
rowCount++;
return result;
}
/**
* Adds a checkbox row to the editor's component.
*
* @param labelText the text of the label
*
* @return the checkbox of that row
*/
protected JCheckBox addCheckBoxRow (String labelText) {
c.gridx = 0;
c.weightx = 40;
c.gridy = rowCount;
c.gridwidth = 2;
JCheckBox result = new JCheckBox(labelText);
editorPanel.add (result, c);
rowCount++;
return result;
}
/**
* Returns the actual structure element to be edited.
*
* @return DOCUMENT ME!
*/
public StructureElement getElement () {
return element;
}
/**
* Sets the structure element to edit.
*
* @param element DOCUMENT ME!
*/
public void setElement (StructureElement element) {
this.element = element;
}
/**
* Returns the component of the editor.
*
* @return the editor component
*/
public Component getComponent () {
return editorPanel;
}
}
|