/* ========================
* JSynoptic : a free Synoptic editor
* ========================
*
* Project Info: http://jsynoptic.sourceforge.net/index.html
*
* This program is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any later version.
*
* This program 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* (C) Copyright 2001-2005, by :
* Corporate:
* EADS Astrium SAS
* EADS CRC
* Individual:
* Claude Cazenave
*
* $Id: RectanglePropertiesPanel.java,v 1.12 2008/09/29 08:44:53 ogor Exp $
*
* Changes
* -------
* 7 juil. 2005 : Initial public release (CC);
*
*/
package jsynoptic.builtin.ui;
import java.awt.event.ActionEvent;
import java.util.ResourceBundle;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import jsynoptic.builtin.RectangleShape;
import jsynoptic.builtin.RectangleShape.RectangleShapePropertiesNames;
import simtools.data.DataSource;
import simtools.ui.ActionCheckBox;
import simtools.ui.FilteredSourceTree;
import simtools.ui.NumberField;
import simtools.ui.GridBagPanel;
import simtools.ui.ResourceFinder;
/**
* A panel to display/edit rectnagle properties
*
* @author cazenave_c
*/
public class RectanglePropertiesPanel extends PropertiesPanel2D {
public static ResourceBundle resources = ResourceFinder.get(RectangleShape.class);
protected NumberField nfmin, nfmax;
protected FilteredSourceTree dstreeProg;
protected JCheckBox cbProg;
public RectanglePropertiesPanel(String shapeName) {
super(true, false, true, true, shapeName);
this.addOnCurrentRow(createRectangleContent(), 2, true, true, true);
}
protected JComponent createRectangleContent() {
// Create elements
cbProg = new ActionCheckBox(resources.getString("UseProgress")) {
public void actionPerformed(ActionEvent e) {
nfmin.setEnabled(isSelected());
nfmax.setEnabled(isSelected());
dstreeProg.setEnabled(isSelected());
updateWarnings();
}
};
dstreeProg = FilteredSourceTree.getFromPool("PropertiesPanel0");
dstreeProg.getSourceTree().addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent e) {
updateWarnings();
}
});
nfmin = new NumberField(0.);
nfmin.setColumns(20);
nfmax = new NumberField(1.);
nfmax.setColumns(20);
GridBagPanel rectanglePanel = new GridBagPanel(resources.getString("DynamicFill"));
rectanglePanel.addOnCurrentRow(cbProg, 2);
rectanglePanel.carriageReturn();
rectanglePanel.addOnCurrentRow(dstreeProg, 5, true, true, true); // full
// line
GridBagPanel linePanel = new GridBagPanel();
linePanel.addOnCurrentRow(new JLabel(resources.getString("ProgressSourceMin")));
linePanel.addOnCurrentRow(nfmin);
linePanel.addOnCurrentRow(new JLabel(resources.getString("ProgressSourceMax")));
linePanel.addOnCurrentRow(nfmax);
linePanel.carriageReturn();
rectanglePanel.addOnCurrentRow(linePanel, 5, false, false, true); // full
return rectanglePanel;
}
/*
* (non-Javadoc)
*
* @see jsynoptic.builtin.ui.PropertiesPanel1D#updateWarnings()
*/
public boolean updateWarnings() {
boolean res = false;
if (cbProg.isSelected()) {
if (!(dstreeProg.getSelectedSourceOrCollection() instanceof DataSource)) {
displayWarning(resources.getString("selectADataSource"));
res = true;
}
}
if (!res){
res = super.updateWarnings();
}
return res;
}
public String[] getPropertyNames() {
if (_propertyNames == null) {
_propertyNames = new RectangleShapePropertiesNames().getPropertyNames();
}
return _propertyNames;
}
public void setPropertyValue(String name, Object value) {
if (name.equalsIgnoreCase("PROGRESS_MIN")) {
if (value instanceof Double) {
nfmin.setValue(((Double) value).doubleValue());
}
} else if (name.equalsIgnoreCase("PROGRESS_MAX")) {
if (value instanceof Double) {
nfmax.setValue(((Double) value).doubleValue());
}
} else if (name.equalsIgnoreCase("PROGRESS_SOURCE")) {
if (value instanceof DataSource) {
cbProg.setSelected(true);
nfmin.setEnabled(true);
nfmax.setEnabled(true);
dstreeProg.setSelectedValue(value);
} else {
cbProg.setSelected(false);
nfmin.setEnabled(false);
nfmax.setEnabled(false);
dstreeProg.setSelectedValue(null);
dstreeProg.setEnabled(false);
}
}
super.setPropertyValue(name, value);
}
public Object getPropertyValue(String name) {
Object res = super.getPropertyValue(name);
if (name.equalsIgnoreCase("PROGRESS_MIN")) {
res = new Double(nfmin.getDoubleValue());
} else if (name.equalsIgnoreCase("PROGRESS_MAX")) {
res = new Double(nfmax.getDoubleValue());
} else if (name.equalsIgnoreCase("PROGRESS_SOURCE")) {
res = cbProg.isSelected() ? dstreeProg.getSelectedSourceOrCollection() : null;
}
return res;
}
}