/* ========================
* 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: EllipsePropertiesPanel.java,v 1.15 2008/09/29 08:44:53 ogor Exp $
*
* Changes
* -------
* 20 jan 2005 : Initial public release (JB);
*
*/
package jsynoptic.builtin.ui;
import java.util.ResourceBundle;
import javax.swing.ButtonGroup;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JRadioButton;
import javax.swing.event.ChangeEvent;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import jsynoptic.builtin.EllipseShape;
import simtools.data.DataSource;
import simtools.ui.ActionRadioButton;
import simtools.ui.FilteredSourceTree;
import simtools.ui.NumberField;
import simtools.ui.GridBagPanel;
import simtools.ui.ResourceFinder;
/**
*/
public class EllipsePropertiesPanel extends PropertiesPanel2D {
public static ResourceBundle resources = ResourceFinder.get(EllipseShape.class);
protected ActionRadioButton rbfull, rbsourcestart, rbsourceend;
protected JRadioButton rbpie, rbchord, rbopen, rbfixedstart, rbfixedend, rbdegstart, rbdegend, rbradstart,
rbradend;
protected NumberField nfstart, nfend;
protected FilteredSourceTree dstreestart, dstreeend;
protected JLabel lunitstart, lunitend;
public EllipsePropertiesPanel(String shapeName) {
super(true, false, true, true, shapeName);
this.addOnCurrentRow(createContent(), 2, true, true, true);
carriageReturn();
}
protected JComponent createContent() {
JLabel ltype = new JLabel(resources.getString("Type:"));
rbfull = new ActionRadioButton(resources.getString("Full")) {
public void stateChanged(ChangeEvent e) {
if (isSelected()) {
rbsourcestart.setEnabled(false);
rbfixedstart.setEnabled(false);
dstreestart.setEnabled(false);
rbsourceend.setEnabled(false);
rbfixedend.setEnabled(false);
dstreeend.setEnabled(false);
nfstart.setEnabled(false);
nfend.setEnabled(false);
lunitstart.setEnabled(false);
lunitend.setEnabled(false);
rbdegstart.setEnabled(false);
rbdegend.setEnabled(false);
rbradstart.setEnabled(false);
rbradend.setEnabled(false);
} else {
rbfixedstart.setEnabled(true);
rbfixedend.setEnabled(true);
lunitstart.setEnabled(true);
lunitend.setEnabled(true);
rbdegstart.setEnabled(true);
rbdegend.setEnabled(true);
rbradstart.setEnabled(true);
rbradend.setEnabled(true);
rbsourcestart.setEnabled(true);
rbsourcestart.setSelected(false);
rbfixedstart.setSelected(false);
rbsourcestart.apply();
rbsourceend.setEnabled(true);
rbsourceend.setSelected(false);
rbfixedend.setSelected(false);
rbsourceend.apply();
}
}
};
rbpie = new JRadioButton(resources.getString("Pie"));
rbchord = new JRadioButton(resources.getString("Chord"));
rbopen = new JRadioButton(resources.getString("Open"));
ButtonGroup bg = new ButtonGroup();
bg.add(rbfull);
bg.add(rbpie);
bg.add(rbchord);
bg.add(rbopen);
GridBagPanel typePanel = new GridBagPanel();
typePanel.addOnCurrentRow(ltype);
typePanel.addOnCurrentRow(rbfull);
typePanel.addOnCurrentRow(rbpie);
typePanel.addOnCurrentRow(rbchord);
typePanel.addOnCurrentRow(rbopen);
typePanel.carriageReturn();
// start angle
GridBagPanel startAnglePanel = new GridBagPanel(resources.getString("StartAngle"));
lunitstart = new JLabel(resources.getString("Unit:"));
rbdegstart = new JRadioButton(resources.getString("Degree"), true);
rbradstart = new JRadioButton(resources.getString("Radian"), false);
bg = new ButtonGroup();
bg.add(rbdegstart);
bg.add(rbradstart);
rbfixedstart = new JRadioButton(resources.getString("FixedValue:"));
nfstart = new NumberField(0.0);
dstreestart = FilteredSourceTree.getFromPool("PropertiesPanel0");
dstreestart.getSourceTree().addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent e) {
updateWarnings();
}
});
rbsourcestart = new ActionRadioButton(resources.getString("UseDataSource")) {
public void stateChanged(ChangeEvent e) {
nfstart.setEnabled(!isSelected());
dstreestart.setEnabled(isSelected());
updateWarnings();
}
};
bg = new ButtonGroup();
bg.add(rbfixedstart);
bg.add(rbsourcestart);
// end angle
GridBagPanel endAnglePanel = new GridBagPanel(resources.getString("EndAngle"));
lunitend = new JLabel(resources.getString("Unit:"));
rbdegend = new JRadioButton(resources.getString("Degree"), true);
rbradend = new JRadioButton(resources.getString("Radian"), false);
bg = new ButtonGroup();
bg.add(rbdegend);
bg.add(rbradend);
rbfixedend = new JRadioButton(resources.getString("FixedValue:"));
nfend = new NumberField(0.0);
dstreeend = FilteredSourceTree.getFromPool("PropertiesPanel1");
dstreeend.getSourceTree().addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent e) {
updateWarnings();
}
});
rbsourceend = new ActionRadioButton(resources.getString("UseDataSource")) {
public void stateChanged(ChangeEvent e) {
nfend.setEnabled(!isSelected());
dstreeend.setEnabled(isSelected());
updateWarnings();
}
};
bg = new ButtonGroup();
bg.add(rbfixedend);
bg.add(rbsourceend);
rbsourcestart.apply();
rbsourceend.apply();
rbfull.apply();
// Create panel
GridBagPanel unitPanel = new GridBagPanel();
unitPanel.addOnCurrentRow(lunitstart);
unitPanel.addOnCurrentRow(rbdegstart);
unitPanel.addOnCurrentRow(rbradstart);
unitPanel.carriageReturn();
startAnglePanel.addOnCurrentRow(unitPanel, 1, false, false, true);
startAnglePanel.addOnCurrentRow(rbfixedstart);
startAnglePanel.addOnCurrentRow(nfstart, 2, true, false, true);
startAnglePanel.addOnCurrentRow(rbsourcestart, 3);
startAnglePanel.carriageReturn();
startAnglePanel.addOnCurrentRow(dstreestart, 3, true, true, true);
GridBagPanel eunitPanel = new GridBagPanel();
eunitPanel.addOnCurrentRow(lunitend);
eunitPanel.addOnCurrentRow(rbdegend);
eunitPanel.addOnCurrentRow(rbradend);
eunitPanel.carriageReturn();
endAnglePanel.addOnCurrentRow(eunitPanel, 1, false, false, true);
endAnglePanel.addOnCurrentRow(rbfixedend);
endAnglePanel.addOnCurrentRow(nfend, 2, true, false, true);
endAnglePanel.addOnCurrentRow(rbsourceend, 3);
endAnglePanel.carriageReturn();
endAnglePanel.addOnCurrentRow(dstreeend, 3, true, true, true);
GridBagPanel ellipsePanel = new GridBagPanel(resources.getString("Ellipse"));
ellipsePanel.addOnCurrentRow(typePanel, 1, false, false, true);
ellipsePanel.addOnCurrentRow(startAnglePanel, 4, true, true, false);
ellipsePanel.addOnCurrentRow(endAnglePanel, 4, true, true, true);
return ellipsePanel;
}
protected String fillColorLabel() {
return resources.getString("FillEllipse");
}
/*
* (non-Javadoc)
*
* @see jsynoptic.builtin.ui.PropertiesPanel1D#updateWarnings()
*/
public boolean updateWarnings() {
boolean res;
if (dstreestart.isEnabled() && (!(dstreestart.getSelectedSourceOrCollection() instanceof DataSource))) {
displayWarning(resources.getString("selectAStartDataSource"));
res = true;
} else if (dstreeend.isEnabled() && (!(dstreeend.getSelectedSourceOrCollection() instanceof DataSource))) {
displayWarning(resources.getString("selectAnEndDataSource"));
res = true;
} else {
res = super.updateWarnings();
}
return res;
}
public String[] getPropertyNames() {
if (_propertyNames == null) {
_propertyNames = new EllipseShape.EllipseShapePropertiesNames().getPropertyNames();
}
return _propertyNames;
}
public void setPropertyValue(String name, Object value) {
if (name.equalsIgnoreCase("ELLIPSE_TYPE")) {
if (value instanceof Integer) {
switch (((Integer) value).intValue()) {
case EllipseShape.TYPE_FULL:
rbfull.setSelected(true);
break;
case EllipseShape.TYPE_PIE:
rbpie.setSelected(true);
break;
case EllipseShape.TYPE_CHORD:
rbchord.setSelected(true);
break;
case EllipseShape.TYPE_OPEN:
rbopen.setSelected(true);
break;
}
}
} else if (name.equalsIgnoreCase("START_UNIT")) {
if (value instanceof Integer) {
switch (((Integer) value).intValue()) {
case EllipseShape.ANGLE_UNIT_DEGREE:
rbdegstart.setSelected(true);
break;
case EllipseShape.ANGLE_UNIT_RADIAN:
rbradstart.setSelected(true);
break;
}
}
} else if (name.equalsIgnoreCase("END_UNIT")) {
if (value instanceof Integer) {
switch (((Integer) value).intValue()) {
case EllipseShape.ANGLE_UNIT_DEGREE:
rbdegend.setSelected(true);
break;
case EllipseShape.ANGLE_UNIT_RADIAN:
rbradend.setSelected(true);
break;
}
}
} else if (name.equalsIgnoreCase("START_ANGLE")) {
if (value instanceof Double) {
nfstart.setValue(((Double) value).doubleValue());
}
} else if (name.equalsIgnoreCase("END_ANGLE")) {
if (value instanceof Double) {
nfend.setValue(((Double) value).doubleValue());
}
} else if (name.equalsIgnoreCase("START_ANGLE_SOURCE")) {
if (value == null) {
rbsourcestart.setSelected(false);
} else {
if (value instanceof DataSource) {
rbsourcestart.setSelected(true);
dstreestart.setSelectedValue(value);
}
}
} else if (name.equalsIgnoreCase("END_ANGLE_SOURCE")) {
if (value == null) {
rbsourceend.setSelected(false);
} else {
if (value instanceof DataSource) {
rbsourceend.setSelected(true);
dstreeend.setSelectedValue(value);
}
}
}
super.setPropertyValue(name, value);
}
public Object getPropertyValue(String name) {
Object res = super.getPropertyValue(name);
if (name.equalsIgnoreCase("ELLIPSE_TYPE")) {
int type = -1;
if (rbfull.isSelected()) {
type = EllipseShape.TYPE_FULL;
} else if (rbpie.isSelected()) {
type = EllipseShape.TYPE_PIE;
} else if (rbchord.isSelected()) {
type = EllipseShape.TYPE_CHORD;
} else if (rbopen.isSelected()) {
type = EllipseShape.TYPE_OPEN;
}
res = new Integer(type);
} else if (name.equalsIgnoreCase("START_UNIT")) {
if (rbdegstart.isSelected()) {
res = new Integer(EllipseShape.ANGLE_UNIT_DEGREE);
} else {
res = new Integer(EllipseShape.ANGLE_UNIT_RADIAN);
}
} else if (name.equalsIgnoreCase("END_UNIT")) {
if (rbdegend.isSelected()) {
res = new Integer(EllipseShape.ANGLE_UNIT_DEGREE);
} else {
res = new Integer(EllipseShape.ANGLE_UNIT_RADIAN);
}
} else if (name.equalsIgnoreCase("START_ANGLE")) {
if (!rbfull.isSelected()) {
res = new Double(nfstart.getDoubleValue());
}
} else if (name.equalsIgnoreCase("END_ANGLE")) {
if (!rbfull.isSelected()) {
res = new Double(nfend.getDoubleValue());
}
} else if (name.equalsIgnoreCase("START_ANGLE_SOURCE")) {
if (rbsourcestart.isSelected()) {
res = dstreestart.getSelectedSourceOrCollection();
}
} else if (name.equalsIgnoreCase("END_ANGLE_SOURCE")) {
if (rbsourceend.isSelected()) {
res = dstreeend.getSelectedSourceOrCollection();
}
}
return res;
}
}