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.record.DrawingRecordable;
027: import jacareto.struct.StructureElement;
028: import jacareto.system.Environment;
029: import jacareto.system.Language;
030: import jacareto.toolkit.event.TextValueListener;
031:
032: import java.awt.BorderLayout;
033: import java.awt.Component;
034: import java.awt.FlowLayout;
035:
036: import javax.swing.JLabel;
037: import javax.swing.JPanel;
038: import javax.swing.JScrollPane;
039: import javax.swing.JTextArea;
040: import javax.swing.JTextField;
041: import javax.swing.event.DocumentEvent;
042:
043: /**
044: * An editor for drawing recordables.
045: *
046: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
047: * @version 1.0
048: */
049: public class DrawingRecordableEditor extends Editor {
050: /** The number of rows of the annotation area. */
051: private final static int DEFAULTNUMBEROFROWS = 6;
052:
053: /** The number of columns of the annotation area. */
054: private final static int DEFAULTNUMBEROFCOLS = 40;
055:
056: /** The structure element to edit. */
057: private StructureElement element;
058:
059: /** The editor's component. */
060: private JPanel editorPanel;
061:
062: /** The text area for the drawing text. */
063: private JTextArea drawingArea;
064:
065: /** The text field for the window's name. */
066: private JTextField windowField;
067:
068: /**
069: * Create a new drawing recordable editor.
070: *
071: * @param env the environment
072: */
073: public DrawingRecordableEditor(Environment env) {
074: super (env);
075: editorPanel = new JPanel(new BorderLayout());
076:
077: Language language = getLanguage();
078:
079: JLabel windowLabel = new JLabel(language
080: .getString("General.Window")
081: + ":");
082: windowField = new JTextField(25);
083: windowField.setEditable(false);
084:
085: JPanel windowPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
086: windowPanel.add(windowLabel);
087: windowPanel.add(windowField);
088: editorPanel.add(windowPanel, BorderLayout.NORTH);
089:
090: /* Setting up the drawing area. */
091: int rows = getCustomization().getInt(
092: "DrawingRecordableEditor.Rows", DEFAULTNUMBEROFROWS);
093: int cols = getCustomization().getInt(
094: "DrawingRecordableEditor.Columns", DEFAULTNUMBEROFCOLS);
095: drawingArea = new JTextArea(rows, cols);
096: drawingArea.setLineWrap(false);
097: drawingArea.setWrapStyleWord(false);
098: drawingArea.getDocument().addDocumentListener(
099: new TextValueListener() {
100: public void textValueChanged(DocumentEvent e) {
101: if (isUpdateOnChange && (getElement() != null)) {
102: ((DrawingRecordable) getElement())
103: .setFigureString(drawingArea
104: .getText());
105: }
106: }
107: });
108:
109: JScrollPane scrollPane = new JScrollPane(drawingArea,
110: JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
111: JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
112: editorPanel.add(scrollPane, BorderLayout.CENTER);
113: }
114:
115: /**
116: * Returns whether this editor is responsible for a given structure element. This editor is
117: * responsible for drawing recordables.
118: *
119: * @param element the structure element
120: *
121: * @return <code>true</code> if <i>element</i> is an drawing recordable and not
122: * <code>null</code>, otherwise <code>false</code>
123: */
124: public boolean handlesElement(StructureElement element) {
125: return (element != null)
126: && (element instanceof DrawingRecordable);
127: }
128:
129: /**
130: * Returns the actual structure element to be edited.
131: *
132: * @return DOCUMENT ME!
133: */
134: public StructureElement getElement() {
135: return element;
136: }
137:
138: /**
139: * Sets the structure element to edit.
140: *
141: * @param element DOCUMENT ME!
142: */
143: public void setElement(StructureElement element) {
144: this .element = element;
145:
146: DrawingRecordable dRecordable = (DrawingRecordable) element;
147: windowField.setText(dRecordable.getWindowName());
148: windowField.setCaretPosition(0);
149: drawingArea.setText(dRecordable.getFigureString());
150: drawingArea.setCaretPosition(0);
151: }
152:
153: /**
154: * Returns the component of the editor.
155: *
156: * @return the editor component
157: */
158: public Component getComponent() {
159: return editorPanel;
160: }
161: }
|