/* ========================
* 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: PlotTemplate.java,v 1.3 2008/07/22 16:01:50 ogor Exp $
*
* Changes
* -------
* 25 february 2008 : Initial public release (CC);
*
*/
package jsynoptic.builtin;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ButtonGroup;
import javax.swing.JCheckBox;
import javax.swing.JRadioButton;
import jsynoptic.base.GridShapesTemplate;
import jsynoptic.builtin.TimePlot;
import jsynoptic.ui.Run;
import simtools.data.DataInfo;
import simtools.data.DataSource;
import simtools.data.DataSourcePool;
import simtools.data.DuplicateIdException;
import simtools.shapes.AbstractShape;
import simtools.ui.FilteredSourceTree;
import simtools.ui.MenuResourceBundle;
import simtools.ui.UserProperties;
import simtools.ui.ResourceFinder;
/**
* An abstract template dedicated to create grid of plots or time plots
* @author zxpletran007
*
*/
public class PlotTemplate extends GridShapesTemplate{
public static MenuResourceBundle resources = ResourceFinder.getMenu(PlotTemplate.class);
/**
* An optional default DataSource for each X axis plots.
* If null, plot X axis are not set */
protected DataSource defaultPrimaryXDataSource;
/**
* If true, create a TimePlot, otherwise create a standard plot
*/
protected boolean isTimePlot;
protected PlotGridShapesTemplatePanel plotGridShapePanel;
public PlotTemplate(){
super();
isTimePlot = false;
defaultPrimaryXDataSource = null;
// get properties from configuration file
UserProperties prop = Run.getProperties();
if (prop!=null){
nbColumns = prop.getInt("jsynoptic.base.GridShapesTemplate.nbRows", DEFAULT_ROW_NUMBER);
String defaultDSName = prop.getString("jsynoptic.base.GridShapesTemplate.defaultPrimaryXDataSource", DataInfo.getId((defaultPrimaryXDataSource)));
if (defaultDSName != null){
try{
defaultPrimaryXDataSource = DataSourcePool.global.getDataSourceWithId(defaultDSName);
}catch (DuplicateIdException e){
}
}
}
plotGridShapePanel = new PlotGridShapesTemplatePanel();
}
public String getName() {
return resources.getString("plotTemplate");
}
public String getTemplateInformation() {
return resources.getString("plotTemplateDesc");
}
protected AbstractShape createShape(int ox, int oy, int width, int height){
Plot res;
// plot's anchor is the axis origin
ox+=13;
oy-=22;
if (isTimePlot){
res = new TimePlot(ox, oy, width, height);
} else {
res = new Plot(ox, oy, width, height);
}
if (defaultPrimaryXDataSource != null){
res.setX(defaultPrimaryXDataSource, true);
}
return res;
}
public TemplatePanel getOptionPanelForTemplate(){
return plotGridShapePanel;
}
protected class PlotGridShapesTemplatePanel extends TemplatePanel {
protected FilteredSourceTree dstree;
protected JRadioButton rPlot, rTimePlot;
protected JCheckBox cbDefaultPrimaryXds;
public PlotGridShapesTemplatePanel(){
super();
dstree = FilteredSourceTree.getFromPool("PlotGridShapesTemplatePanel");
rPlot = new JRadioButton(resources.getString("plot"), false);
rTimePlot = new JRadioButton(resources.getString("timePlot"), false);
ButtonGroup bg = new ButtonGroup();
bg.add(rPlot);
bg.add(rTimePlot);
rTimePlot.setSelected(isTimePlot);
rPlot.setSelected(!isTimePlot);
cbDefaultPrimaryXds = new JCheckBox(resources.getString("defaultPrimaryXds"), (defaultPrimaryXDataSource != null));
cbDefaultPrimaryXds.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dstree.setEnabled(cbDefaultPrimaryXds.isSelected());
}
});
dstree.setEnabled(cbDefaultPrimaryXds.isSelected());
if (defaultPrimaryXDataSource != null){
dstree.setSelectedValue(defaultPrimaryXDataSource);
}
// Panel contents
addOnCurrentRow(gridShapePanel,4, true, false, true);
addOnCurrentRow(rPlot, 2);
addOnCurrentRow(rTimePlot, 2);
carriageReturn();
addOnCurrentRow(cbDefaultPrimaryXds, 3);
carriageReturn();
addOnCurrentRow(dstree, 4, true, true, true);
}
public void getProperties(){
gridShapePanel.getProperties();
isTimePlot = rTimePlot.isSelected();
if (cbDefaultPrimaryXds.isSelected()
&& ((dstree.getSelectedSourceOrCollection()) instanceof DataSource)
){
defaultPrimaryXDataSource = (DataSource)dstree.getSelectedSourceOrCollection();
}else {
defaultPrimaryXDataSource = null;
}
// save values
UserProperties prop = Run.getProperties();
if (prop!=null){
prop.setBoolean("jsynoptic.base.GridShapesTemplate.isTimePlot", isTimePlot);
if (defaultPrimaryXDataSource != null){
prop.setString("jsynoptic.base.GridShapesTemplate.defaultPrimaryXDataSource", DataInfo.getId((defaultPrimaryXDataSource)));
}
}
}
}
}