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.struct.HyperlinkChosen;
027: import jacareto.struct.StructureElement;
028: import jacareto.system.Environment;
029: import jacareto.system.Language;
030:
031: import java.awt.Component;
032: import java.awt.GridBagConstraints;
033: import java.awt.GridBagLayout;
034:
035: import javax.swing.JLabel;
036: import javax.swing.JPanel;
037: import javax.swing.JTextField;
038: import javax.swing.border.EmptyBorder;
039:
040: /**
041: * An editor for hyperlink chosen elements.
042: *
043: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
044: * @version 1.00
045: */
046: public class HyperlinkChosenEditor extends Editor {
047: /** The element to edit. */
048: private StructureElement element;
049:
050: /** The panel. */
051: private JPanel editorPanel;
052:
053: /** The text field for the url. */
054: private JTextField urlField;
055:
056: /**
057: * Create a new editor.
058: *
059: * @param env the environment
060: */
061: public HyperlinkChosenEditor(Environment env) {
062: super (env);
063:
064: Language language = getLanguage();
065:
066: // The panel with the text fields
067: editorPanel = new JPanel();
068: editorPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
069: editorPanel.setLayout(new GridBagLayout());
070:
071: // The url field label
072: GridBagConstraints c = new GridBagConstraints();
073: c.gridx = 0;
074: c.gridy = 0;
075: c.weightx = 40;
076: c.ipadx = 5;
077: c.ipady = 5;
078: c.anchor = GridBagConstraints.WEST;
079:
080: JLabel urlFieldLabel = new JLabel(language
081: .getString("Events.HyperlinkEvent.URL")
082: + ":");
083: editorPanel.add(urlFieldLabel, c);
084:
085: // The url field.
086: c.gridx = 1;
087: c.weightx = 60;
088: urlField = new JTextField(20);
089: urlField.setEditable(false);
090: editorPanel.add(urlField, c);
091: urlFieldLabel.setLabelFor(urlField);
092: }
093:
094: /**
095: * Returns whether this editor is responsible for a given structure element. This editor is
096: * responsible for all hyperlink chosen recordables.
097: *
098: * @param element the structure element
099: *
100: * @return <code>true</code> if <i>element</i> is a list selection event recordable and not
101: * <code>null</code>, otherwise <code>false</code>
102: */
103: public boolean handlesElement(StructureElement element) {
104: return (element != null)
105: && (element instanceof HyperlinkChosen);
106: }
107:
108: /**
109: * Returns the actual structure element to be edited.
110: *
111: * @return DOCUMENT ME!
112: */
113: public StructureElement getElement() {
114: return element;
115: }
116:
117: /**
118: * Sets the structure element to edit.
119: *
120: * @param element DOCUMENT ME!
121: */
122: public void setElement(StructureElement element) {
123: this .element = element;
124:
125: HyperlinkChosen chosen = (HyperlinkChosen) element;
126: urlField.setText(chosen.getURL());
127: }
128:
129: /**
130: * Returns the component of the editor.
131: *
132: * @return the editor component
133: */
134: public Component getComponent() {
135: return editorPanel;
136: }
137: }
|