/* ========================
* 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-2003, by :
* Corporate:
* Astrium SAS
* EADS CRC
* Individual:
* Nicolas Brodu
*
* $Id: ParametricPlotShape.java,v 1.6 2008/02/25 13:06:37 ogor Exp $
*
* Changes
* -------
* 25-Sep-2003 : Initial public release (NB);
*
*/
package jsynoptic.plugins.jfreechart;
import java.util.ResourceBundle;
import java.util.Vector;
import javax.swing.undo.CompoundEdit;
import jsynoptic.ui.JSynoptic;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.XYPlot;
import simtools.data.DataSource;
import simtools.data.DataSourceCollection;
import simtools.ui.ResourceFinder;
/**
* @author nbrodu
*
* To change the template for this generated type comment go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
public class ParametricPlotShape extends StandardPlotShape {
static final long serialVersionUID = 8119591099401841377L;
public static ResourceBundle resources = ResourceFinder.get(ParametricPlotShape.class, StandardPlotShape.resources);
public ParametricPlotShape(JFreeChart chart) {
this(chart,0,0,400,300);
}
public ParametricPlotShape(JFreeChart chart, int ox, int oy, int width, int height) {
super(chart, ox, oy, width, height);
XYPlot plot = (XYPlot)chart.getXYPlot();
SourceXYDataset dst = (SourceXYDataset)plot.getDataset();
dst.setNameAccordingToYOnly(false);
}
/* (non-Javadoc)
* @see jsynoptic.base.ContextualActionProvider#getActions(double, double, java.lang.Object, int)
*/
public String[] getActions(double x, double y, Object o, int context) {
if (context==MOUSE_OVER_CONTEXT) {
return super.getActions(x,y,o,context);
}
if (context==MOUSE_OUT_CONTEXT) {
return super.getActions(x,y,o,context);
}
if (context==MOUSE_PRESSED_CONTEXT) {
return null;
}
if (context==EDITOR_CONTEXT) {
}
Vector v = new Vector();
v.add(resources.getString("Properties..."));
XYPlot plot = (XYPlot)chart.getXYPlot();
SourceXYDataset dst = (SourceXYDataset)plot.getDataset();
if (o instanceof DataSource) {
int n = dst.getSources().size();
v.add (resources.getString("SetAsX1"));
for (int i=0; i<n; ++i) {
if (dst.getXSource(i)!=null) v.add (resources.getString("SetAsY")+(i+1));
v.add (resources.getString("SetAsX")+(i+2));
}
}
else if (o instanceof DataSourceCollection) {
v.add(resources.getString("SetAsCommonX,Y1...Yn"));
v.add(resources.getString("SetAs(X1,Y1)...(Xn,Yn)"));
}
if (v.size()==0) {
JSynoptic.setStatus(resources.getString("noSource"));
}
return (String[])v.toArray(new String[v.size()]);
}
/* (non-Javadoc)
* @see jsynoptic.base.ContextualActionProvider#doAction(double, double, java.lang.Object, java.lang.String)
*/
public boolean doAction(double x, double y, Object o, String action, CompoundEdit undoableEdit) {
if (action.equals(resources.getString("SetAsCommonX,Y1...Yn"))) {
try {
XYPlot plot = chart.getXYPlot();
SourceXYDataset dst = (SourceXYDataset)plot.getDataset();
dst.setDataSourceCollection((DataSourceCollection)o);
chart.setTitle(dst.getName());
notifyChange();
return true;
} catch (ClassCastException cce) {
JSynoptic.setStatus(resources.getString("ErrorWhileSettingDataSourceCollection"));
return false;
}
}
if (action.equals(resources.getString("SetAs(X1,Y1)...(Xn,Yn)"))) {
try {
XYPlot plot = chart.getXYPlot();
SourceXYDataset dst = (SourceXYDataset)plot.getDataset();
dst.setDataSourceCollectionAsCouples((DataSourceCollection)o);
chart.setTitle(dst.getName());
notifyChange();
return true;
} catch (ClassCastException cce) {
JSynoptic.setStatus(resources.getString("ErrorWhileSettingDataSourceCollection"));
return false;
}
}
if (action.startsWith(resources.getString("SetAsX"))) {
try {
XYPlot plot = chart.getXYPlot();
SourceXYDataset dst = (SourceXYDataset)plot.getDataset();
int i = (int)Long.parseLong(action.substring(action.length()-1));
dst.setXSource((DataSource)o,i-1);
notifyChange();
return true;
} catch (ClassCastException cce) {
JSynoptic.setStatus(resources.getString("ErrorWhileSettingXDataSource"));
return false;
}
}
if (action.startsWith(resources.getString("SetAsY"))) {
try {
XYPlot plot = chart.getXYPlot();
SourceXYDataset dst = (SourceXYDataset)plot.getDataset();
int i = (int)Long.parseLong(action.substring(action.length()-1));
dst.setYSource((DataSource)o,i-1);
notifyChange();
return true;
} catch (ClassCastException cce) {
JSynoptic.setStatus(resources.getString("ErrorWhileSettingYDataSource"));
return false;
}
}
return super.doAction(x,y,o,action, undoableEdit);
}
}