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.AudioClipRecordable;
027: import jacareto.struct.StructureElement;
028: import jacareto.system.Environment;
029: import jacareto.system.Language;
030: import jacareto.toolkit.swing.AudioClipFileFilter;
031:
032: import java.awt.Component;
033: import java.awt.GridBagConstraints;
034: import java.awt.GridBagLayout;
035: import java.awt.Insets;
036: import java.awt.event.ActionEvent;
037: import java.awt.event.ActionListener;
038:
039: import javax.swing.JButton;
040: import javax.swing.JFileChooser;
041: import javax.swing.JLabel;
042: import javax.swing.JPanel;
043: import javax.swing.JTextField;
044: import javax.swing.SwingUtilities;
045:
046: /**
047: * An editor for audio clip recordables.
048: *
049: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
050: * @version 1.0
051: */
052: public class AudioClipRecordableEditor extends Editor {
053: /** The structure element to edit. */
054: private StructureElement element;
055:
056: /** The editor's component. */
057: private JPanel editorPanel;
058:
059: /** The text field for the name. */
060: private JTextField filenameField;
061:
062: /**
063: * Create a new audio clip recordable editor.
064: *
065: * @param env the environment
066: */
067: public AudioClipRecordableEditor(Environment env) {
068: super (env);
069:
070: Language language = getLanguage();
071:
072: editorPanel = new JPanel();
073: editorPanel.setLayout(new GridBagLayout());
074:
075: // The filename field label
076: GridBagConstraints c = new GridBagConstraints();
077: c.gridx = 0;
078: c.gridy = 0;
079: c.weightx = 30;
080:
081: //c.ipady = 3;
082: //c.ipadx = 5;
083: c.insets = new Insets(5, 5, 5, 5);
084: c.anchor = GridBagConstraints.WEST;
085:
086: JLabel filenameFieldLabel = new JLabel(language
087: .getString("General.Filename")
088: + ":");
089: editorPanel.add(filenameFieldLabel, c);
090:
091: // The filename field
092: c.gridx = 1;
093: c.weightx = 60;
094: filenameField = new JTextField(20);
095:
096: /**
097: * filenameField.getDocument ().addDocumentListener (new TextValueListener() { public void
098: * textValueChanged (DocumentEvent e) { if (isUpdateOnChange && (getElement () != null)) {
099: * ((AudioClipRecordable) getElement ()).setFilename (filenameField.getText ()); }}});
100: */
101: editorPanel.add(filenameField, c);
102: filenameFieldLabel.setLabelFor(filenameField);
103:
104: // The choose button
105: JButton chooseButton = new JButton(language
106: .getString("General.Choose")
107: + "...");
108: chooseButton.addActionListener(new ActionListener() {
109: public void actionPerformed(ActionEvent event) {
110: JFileChooser chooser = new JFileChooser(".");
111:
112: // chooser.setFileSelectionMode (JFileChooser.FILES_ONLY);
113: chooser
114: .setDialogTitle(getLanguage()
115: .getString(
116: "Editors.AudioClipRecordableEditor.FileChooser.Title"));
117: chooser
118: .setFileFilter(new AudioClipFileFilter(
119: getLanguage()
120: .getString(
121: "Editors.AudioClipRecordableEditor.FileChooser.FileFilterDescription")));
122:
123: int returnVal = chooser.showDialog(SwingUtilities
124: .getWindowAncestor(editorPanel), getLanguage()
125: .getString("General.Open"));
126:
127: if (returnVal == JFileChooser.APPROVE_OPTION) {
128: String filename = chooser.getSelectedFile()
129: .getAbsolutePath();
130:
131: if (isUpdateOnChange && (getElement() != null)) {
132: ((AudioClipRecordable) getElement())
133: .setFilename(filename);
134:
135: if (((AudioClipRecordable) getElement())
136: .determineDuration()) {
137: filenameField.setText(filename);
138: } else {
139: ((AudioClipRecordable) getElement())
140: .setFilename(null);
141: }
142: }
143: }
144: }
145: });
146: c.gridy = 1;
147: c.gridx = 0;
148: c.gridwidth = 2;
149: c.anchor = GridBagConstraints.CENTER;
150: editorPanel.add(chooseButton, c);
151: }
152:
153: /**
154: * Returns whether this editor is responsible for a given structure element. This editor is
155: * responsible for audio clip recordables.
156: *
157: * @param element the structure element
158: *
159: * @return <code>true</code> if <i>element</i> is an audio clip recordable and not
160: * <code>null</code>, otherwise <code>false</code>
161: */
162: public boolean handlesElement(StructureElement element) {
163: return (element != null)
164: && (element instanceof AudioClipRecordable);
165: }
166:
167: /**
168: * Returns the actual structure element to be edited.
169: *
170: * @return {@link StructureElement}
171: */
172: public StructureElement getElement() {
173: return element;
174: }
175:
176: /**
177: * Sets the structure element to edit.
178: *
179: * @param element {@link StructureElement}
180: */
181: public void setElement(StructureElement element) {
182: this .element = element;
183:
184: AudioClipRecordable aRecordable = (AudioClipRecordable) element;
185: filenameField.setText(aRecordable.getFilename());
186: }
187:
188: /**
189: * Returns the component of the editor.
190: *
191: * @return the editor component
192: */
193: public Component getComponent() {
194: return editorPanel;
195: }
196: }
|