repaintDiagram(getBounds());
return true;
}
if (action.equals(resources.getStringValue("properties"))) {
new LongAction(LongAction.LONG_ACTION_SHAPE, null, this) {
protected void doAction() {
JPropertiesPanel panel=createPanel();
/** Only one shape properties dialog box can be displayed at once
* When user opens a dialog box properties while another one is still displayed: this last dislaog box is closed
*/
Point oldLocation=null;
if (currentDialogBox!=null){
oldLocation= currentDialogBox.getBounds().getLocation();
currentDialogBox.dispose();
}
ArrayList shapes = new ArrayList();
shapes.add(Plot.this);
PlotPropertiesDialogBox optionDialog = new PlotPropertiesDialogBox(JSynoptic.gui.getOwner(), panel, panel.getShapeName(), shapes);
if (oldLocation!=null)
optionDialog.setLocation(oldLocation);
currentDialogBox = optionDialog;
optionDialog.show();
}
}.start();
return true;
}
if (action.startsWith(resources.getStringValue("adjustOnX"))) {
if (o instanceof Double[]){
HashMap oldValues=getAxesProperties(null, -1);
Double[] xranges = ((Double[])o);
axesLimitsArray[PX].min = xranges[0].doubleValue();
axesLimitsArray[PX].max = xranges[1].doubleValue();
axesLimitsArray[PX].step = computeStep(axesLimitsArray[PX].min, axesLimitsArray[PX].max, preferredXGraduation);
if ( (xranges[2] != null) && (_asx2 != null)) {
axesLimitsArray[SX].min = xranges[2].doubleValue();
axesLimitsArray[SX].max = xranges[3].doubleValue();
axesLimitsArray[SX].step = computeStep(axesLimitsArray[SX].min, axesLimitsArray[SX].max, preferredXGraduation);
}
repaintDiagram(getBounds());
PlotCompoundEdit ce=new PlotCompoundEdit(oldValues);
if(undoableEdit != null){
undoableEdit.addEdit(ce);
}
return true;
} else {
return false;
}
}
if (action.equals(resources.getStringValue("autoscale"))) {
// get the old values for the 4 axes
HashMap oldValues=getAxesProperties(null, -1);
for(int i =0; i< AXE_NUMBER;i++){
axesLimitsArray[i].validity = false;
}
repaintDiagram(getBounds());
PlotCompoundEdit ce=new PlotCompoundEdit(oldValues);
if(undoableEdit != null){
undoableEdit.addEdit(ce);
}
return true;
}
if (action.equals(resources.getStringValue("autoscaleOnY"))) {
// get the old values for the 4 axes
HashMap oldValues=getAxesProperties(null, -1);
// auto-scale on primary Y
axesLimitsArray[PY].validity = false;
// auto-scale on secondary Y
axesLimitsArray[SY].validity = false;
repaintDiagram(getBounds());
PlotCompoundEdit ce=new PlotCompoundEdit(oldValues);
if(undoableEdit != null){
undoableEdit.addEdit(ce);
}
return true;
}
if (o instanceof DataSource) {
boolean res = false;
DataSource ds = (DataSource)o;
if (action.equals(resources.getStringValue("setX"))) {
res = setPrimaryX(ds, true);
}
if (action.equals(resources.getStringValue("addY"))) {
res = addPrimaryY(ds, true);
}
if (action.equals(resources.getStringValue("addYSecX"))) {
res = addPrimaryYForSecondaryX(ds, true);
}
if (action.equals(resources.getStringValue("addSecY"))) {
res = addSecondaryY(ds, true);
}
if (action.equals(resources.getStringValue("setSecX"))) {
res = setSecondaryX(ds, true);
}
if (action.equals(resources.getStringValue("addSecYSecX"))) {
res = addSecondaryYForSecondaryX(ds, true);
}
return res;
}
if (o instanceof DataSourceCollection) {
DataSourceCollection dsc = (DataSourceCollection)o;
if (action.equals(resources.getStringValue("setXY1Yn"))) {
if (dsc.size()<1) return false;
new LongAction(0, new Object[] {dsc,action}) {
protected void doAction() {
DataSourceCollection dsc = (DataSourceCollection)((Object[])param)[0];
setPrimaryX((DataSource)dsc.get(0), false);
boolean hasValues = axesLimitsArray[PY].validity;
axesLimitsArray[PY].validity = true; // compute only once all curve are inserted
for (int i=1; i<dsc.size()-1; i++)
addPrimaryY((DataSource)dsc.get(i), false);
axesLimitsArray[PY].validity = hasValues;
if (dsc.size()>1) addPrimaryY((DataSource)dsc.get(dsc.size()-1), false);
Rectangle bounds = getBounds();
setTitle(DataInfo.getLabel(dsc));
repaintDiagram(bounds);
}
}.start();
return false;
}
if (action.equals(resources.getStringValue("addY1Yn"))) {
if (dsc.size()<1) return false;
new LongAction(0, new Object[] {dsc,action}) {
protected void doAction() {
DataSourceCollection dsc = (DataSourceCollection)((Object[])param)[0];
boolean hasValues = axesLimitsArray[PY].validity;
axesLimitsArray[PY].validity = true; // compute only once all curve are inserted
for (int i=0; i<dsc.size()-1; i++)
addPrimaryY((DataSource)dsc.get(i), false);
axesLimitsArray[PY].validity = hasValues;
if (dsc.size()>0) addPrimaryY((DataSource)dsc.get(dsc.size()-1), false);
Rectangle bounds = getBounds();
repaintDiagram(bounds);
}
}.start();
return false;
}
if (action.equals(resources.getStringValue("addSecY1Yn"))) {
if (dsc.size()<1) return false;
new LongAction(0, new Object[] {dsc,action}) {
protected void doAction() {
DataSourceCollection dsc = (DataSourceCollection)((Object[])param)[0];
boolean hasValues = axesLimitsArray[SY].validity;
boolean hasLabel = (axesLimitsArray[SY].label!=null);
axesLimitsArray[SY].validity = true; // compute only once all curve are inserted
for (int i=0; i<dsc.size()-1; i++)
addSecondaryY((DataSource)dsc.get(i), false);
axesLimitsArray[SY].validity = hasValues;
if (dsc.size()>0) addSecondaryY((DataSource)dsc.get(dsc.size()-1), false);
Rectangle bounds = getBounds();
if ((!hasLabel) && (dsc.size()>1)) {axesLimitsArray[SY].label = null; setLegendVisible(true);}
repaintDiagram(bounds);
}
}.start();
return false;
}
if (action.equals(resources.getStringValue("setSecXY1Yn"))) {
if (dsc.size()<1) return false;
new LongAction(0, new Object[] {dsc,action}) {
protected void doAction() {
DataSourceCollection dsc = (DataSourceCollection)((Object[])param)[0];
setSecondaryX((DataSource)dsc.get(0), false);
boolean hasValues = axesLimitsArray[SY].validity;
boolean hasLabel = (axesLimitsArray[SY].label!=null);
axesLimitsArray[SY].validity = true; // compute only once all curve are inserted
for (int i=1; i<dsc.size()-1; i++)
addSecondaryY((DataSource)dsc.get(i), false);
axesLimitsArray[SY].validity = hasValues;
if (dsc.size()>1) addSecondaryY((DataSource)dsc.get(dsc.size()-1), false);
Rectangle bounds = getBounds();
if ((!hasLabel) && (dsc.size()>2)) {axesLimitsArray[SY].label = null; setLegendVisible(true);}
repaintDiagram(bounds);
}
}.start();
return false;
}
if (action.equals(resources.getStringValue("addSecY1YnForSecX"))) {
if (dsc.size()<1) return false;
new LongAction(0, new Object[] {dsc,action}) {
protected void doAction() {
DataSourceCollection dsc = (DataSourceCollection)((Object[])param)[0];
boolean hasValues = axesLimitsArray[SY].validity;
boolean hasLabel = (axesLimitsArray[SY].label!=null);
axesLimitsArray[SY].validity = true; // compute only once all curve are inserted