/*
* 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.VideoClipRecordable;
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.VideoClipFileFilter;
import java.awt.Component;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.event.DocumentEvent;
/**
* Editor for video clips.
*
* @author Oliver Specht
* @version $revision$
*/
public class VideoClipRecordableEditor extends Editor {
/** The structure element to edit. */
private StructureElement element;
/** The editor's component. */
private JPanel editorPanel;
/** The text field for the name. */
private JTextField filenameField;
/** The text fields for the window coordinates. */
private IntegerTextField locationXField;
private IntegerTextField locationYField;
private IntegerTextField widthField;
private IntegerTextField heightField;
private JCheckBox sizeCheckBox;
/**
* Create a new video clip recordable editor.
*
* @param env the environment
*/
public VideoClipRecordableEditor (Environment env) {
super(env);
Language language = getLanguage ();
editorPanel = new JPanel();
editorPanel.setLayout (new GridBagLayout());
// The filename field label
GridBagConstraints c = new GridBagConstraints();
c.gridx = 0;
c.gridy = 0;
c.weightx = 30;
//c.ipady = 3;
//c.ipadx = 5;
c.insets = new Insets(5, 5, 5, 5);
c.anchor = GridBagConstraints.WEST;
JLabel filenameFieldLabel = new JLabel(language.getString ("General.Filename") + ":");
editorPanel.add (filenameFieldLabel, c);
// The filename field
c.gridx = 1;
c.weightx = 60;
filenameField = new JTextField(20);
filenameField.getDocument ().addDocumentListener (new TextValueListener() {
public void textValueChanged (DocumentEvent e) {
if (isUpdateOnChange && (getElement () != null)) {
((VideoClipRecordable) getElement ()).setFilename (filenameField.getText ());
}
}
});
editorPanel.add (filenameField, c);
filenameFieldLabel.setLabelFor (filenameField);
// The choose button
JButton chooseButton = new JButton(language.getString ("General.Choose") + "...");
chooseButton.addActionListener (new ActionListener() {
public void actionPerformed (ActionEvent event) {
JFileChooser chooser = new JFileChooser(".");
// chooser.setFileSelectionMode (JFileChooser.FILES_AND_DIRECTORIES);
chooser.setDialogTitle (getLanguage ().getString ("Editors.VideoClipRecordableEditor.FileChooser.Title"));
chooser.setFileFilter (new VideoClipFileFilter(getLanguage ().getString ("Editors.VideoClipRecordableEditor.FileChooser.FileFilterDescription")));
int returnVal = chooser.showDialog (SwingUtilities.getWindowAncestor (
editorPanel), getLanguage ().getString ("General.Open"));
if (returnVal == JFileChooser.APPROVE_OPTION) {
String filename = chooser.getSelectedFile ().getAbsolutePath ();
if (isUpdateOnChange && (getElement () != null)) {
((VideoClipRecordable) getElement ()).setFilename (filename);
if (((VideoClipRecordable) getElement ()).determineDuration ()) {
filenameField.setText (filename);
}
}
}
}
});
c.gridy = 1;
c.gridx = 0;
c.gridwidth = 2;
c.anchor = GridBagConstraints.CENTER;
editorPanel.add (chooseButton, c);
JLabel locationXLabel = new JLabel(language.getString ("General.Coordinates.X") + ":",
SwingConstants.RIGHT);
c.gridx = 0;
c.gridy = 2;
c.gridwidth = 1;
c.anchor = GridBagConstraints.WEST;
editorPanel.add (locationXLabel, c);
locationXField = new IntegerTextField(4);
locationXField.getDocument ().addDocumentListener (new TextValueListener() {
public void textValueChanged (DocumentEvent e) {
if (isUpdateOnChange && (getElement () != null)) {
((VideoClipRecordable) getElement ()).setX (locationXField.getValue ());
}
}
});
c.gridx = 1;
editorPanel.add (locationXField, c);
JLabel locationYLabel = new JLabel(language.getString ("General.Coordinates.Y") + ":",
SwingConstants.RIGHT);
c.gridx = 0;
c.gridy = 3;
editorPanel.add (locationYLabel, c);
locationYField = new IntegerTextField(4);
locationYField.getDocument ().addDocumentListener (new TextValueListener() {
public void textValueChanged (DocumentEvent e) {
if (isUpdateOnChange && (getElement () != null)) {
((VideoClipRecordable) getElement ()).setY (locationYField.getValue ());
}
}
});
c.gridx = 1;
editorPanel.add (locationYField, c);
// The size components
sizeCheckBox = new JCheckBox(language.getString (
"Recordables.VideoClipRecordable.Attributes.AutomaticSizeDetection"));
sizeCheckBox.addActionListener (new ActionListener() {
public void actionPerformed (ActionEvent e) {
if (getElement () != null) {
((VideoClipRecordable) getElement ()).setAutomaticSizeDetection (sizeCheckBox.isSelected ());
widthField.setEnabled (! sizeCheckBox.isSelected ());
heightField.setEnabled (! sizeCheckBox.isSelected ());
}
}
});
c.gridx = 0;
c.gridy = 4;
c.gridwidth = 2;
editorPanel.add (sizeCheckBox, c);
JLabel widthLabel = new JLabel(language.getString ("General.Width") + ":",
SwingConstants.RIGHT);
c.gridx = 0;
c.gridy = 5;
c.gridwidth = 1;
editorPanel.add (widthLabel, c);
widthField = new IntegerTextField(4);
widthField.getDocument ().addDocumentListener (new TextValueListener() {
public void textValueChanged (DocumentEvent e) {
if (isUpdateOnChange && (getElement () != null)) {
((VideoClipRecordable) getElement ()).setWidth (widthField.getValue ());
}
}
});
c.gridx = 1;
editorPanel.add (widthField, c);
JLabel heightLabel = new JLabel(language.getString ("General.Height") + ":",
SwingConstants.RIGHT);
c.gridx = 0;
c.gridy = 6;
editorPanel.add (heightLabel, c);
heightField = new IntegerTextField(4);
heightField.getDocument ().addDocumentListener (new TextValueListener() {
public void textValueChanged (DocumentEvent e) {
if (isUpdateOnChange && (getElement () != null)) {
((VideoClipRecordable) getElement ()).setHeight (heightField.getValue ());
}
}
});
c.gridx = 1;
editorPanel.add (heightField, c);
}
/**
* Returns whether this editor is responsible for a given structure element. This editor is
* responsible for video clip recordables.
*
* @param element the structure element
*
* @return <code>true</code> if <i>element</i> is an video clip recordable and not
* <code>null</code>, otherwise <code>false</code>
*/
public boolean handlesElement (StructureElement element) {
return (element != null) && (element instanceof VideoClipRecordable);
}
/**
* 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;
VideoClipRecordable aRecordable = (VideoClipRecordable) element;
filenameField.setText (aRecordable.getFilename ());
locationXField.setValue (aRecordable.getX ());
locationYField.setValue (aRecordable.getY ());
widthField.setValue (aRecordable.getWidth ());
heightField.setValue (aRecordable.getHeight ());
sizeCheckBox.setSelected (aRecordable.hasAutomaticSizeDetection ());
widthField.setEnabled (! sizeCheckBox.isSelected ());
heightField.setEnabled (! sizeCheckBox.isSelected ());
}
/**
* Returns the component of the editor.
*
* @return the editor component
*/
public Component getComponent () {
return editorPanel;
}
}
|