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