protected Double min, max, rotate;\r
\r
/**\r
- *\r
+ * Creates a new axis\r
* @param graph ReadGraph\r
* @param axisResource resource of type JFreeChart.NumberAxis\r
*/\r
public AbstractAxis(ReadGraph graph, Resource axisResource) {\r
try {\r
+ /*\r
+ * Axis is practically always called from a listener, \r
+ * so it is safe to always create a new axis every time. \r
+ * \r
+ * The parent listener takes care that the axis is updated. \r
+ * (And the code stays much more readable)\r
+ */\r
Layer0 l0 = Layer0.getInstance(graph);\r
JFreeChartResource jfree = JFreeChartResource.getInstance(graph);\r
label = graph.getPossibleRelatedValue(axisResource, l0.HasLabel);\r
import org.simantics.db.common.request.ObjectsWithType;\r
import org.simantics.db.common.utils.ListUtils;\r
import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.procedure.Listener;\r
+import org.simantics.db.request.Read;\r
import org.simantics.layer0.Layer0;\r
import org.simantics.sysdyn.JFreeChartResource;\r
+import org.simantics.ui.SimanticsUI;\r
\r
/**\r
* Abstract plot class for all JFreeChart plots\r
public abstract class AbstractPlot implements IPlot {\r
\r
protected Resource resource;\r
- protected ArrayList<IAxis> ranges;\r
- protected ArrayList<IAxis> domains;\r
- protected ArrayList<IDataset> datasets;\r
- protected HashMap<IDataset, IAxis> rangeMappings;\r
- protected HashMap<IDataset, IAxis> domainMappings;\r
protected Plot plot;\r
- \r
+ protected PlotProperties currentProperties;\r
+ private PlotPropertyListener listener;\r
+\r
+\r
public AbstractPlot(ReadGraph graph, Resource resource) {\r
this.resource = resource;\r
- \r
- try {\r
- Layer0 l0 = Layer0.getInstance(graph);\r
- JFreeChartResource jfree = JFreeChartResource.getInstance(graph);\r
+ }\r
\r
- HashMap<Resource, IAxis> axisMap = new HashMap<Resource, IAxis>();\r
- ranges = new ArrayList<IAxis>();\r
+ @Override\r
+ public void dispose() {\r
+ if(currentProperties != null) {\r
+ for(IAxis axis : currentProperties.ranges)\r
+ axis.dispose();\r
\r
- // Get all range axis\r
- Resource rangeList = graph.getPossibleObject(resource, jfree.Plot_rangeAxisList);\r
- if(rangeList != null) {\r
- for(Resource axisResource : ListUtils.toList(graph, rangeList)) {\r
- IAxis axis = graph.adapt(axisResource, IAxis.class);\r
- if(axis.getAxis() instanceof Axis) {\r
- ranges.add(axis);\r
- axisMap.put(axisResource, axis);\r
- }\r
- }\r
- }\r
- \r
- // Get all domain axis\r
- // There usually is only one domain axis, but this supports also multiple domain axis\r
- domains = new ArrayList<IAxis>();\r
- for(Resource axisResource : graph.syncRequest(new ObjectsWithType(resource, jfree.Plot_domainAxis, jfree.Axis))) {\r
- IAxis axis = graph.adapt(axisResource, IAxis.class);\r
- if(axis.getAxis() instanceof Axis) {\r
- domains.add(axis);\r
- axisMap.put(axisResource, axis);\r
- }\r
- }\r
+ for(IAxis axis : currentProperties.domains)\r
+ axis.dispose();\r
\r
- // Get all datasets and map them to axis\r
- datasets = new ArrayList<IDataset>();\r
- rangeMappings = new HashMap<IDataset, IAxis>();\r
- domainMappings = new HashMap<IDataset, IAxis>();\r
- for(Resource datasetResource : graph.syncRequest(new ObjectsWithType(resource, l0.ConsistsOf, jfree.Dataset))) {\r
- IDataset dataset = graph.adapt(datasetResource, IDataset.class);\r
- if(dataset != null) {\r
- datasets.add(dataset);\r
- Resource axisResource = graph.getPossibleObject(datasetResource, jfree.Dataset_mapToRangeAxis);\r
- IAxis axis;\r
- if(axisMap.containsKey(axisResource)) {\r
- axis = axisMap.get(axisResource);\r
- rangeMappings.put(dataset, axis);\r
- }\r
- \r
- axisResource = graph.getPossibleObject(datasetResource, jfree.Dataset_mapToDomainAxis);\r
- if(axisMap.containsKey(axisResource)) {\r
- axis = axisMap.get(axisResource);\r
- domainMappings.put(dataset, axis);\r
- }\r
- }\r
- }\r
- \r
- } catch (DatabaseException e) {\r
- e.printStackTrace();\r
+ for(IDataset dataset : currentProperties.datasets)\r
+ dataset.dispose();\r
}\r
- \r
- }\r
- \r
- @Override\r
- public void dispose() {\r
- for(IAxis axis : ranges)\r
- axis.dispose();\r
- \r
- for(IAxis axis : domains)\r
- axis.dispose();\r
- \r
- for(IDataset dataset : datasets)\r
- dataset.dispose();\r
+ if(listener != null)\r
+ listener.dispose();\r
}\r
\r
@Override\r
public Resource getResource() {\r
return resource;\r
}\r
- \r
+\r
protected abstract Plot newPlot();\r
- protected abstract void setPlotProperties();\r
- \r
+ protected abstract void setPlotProperties(PlotProperties properties);\r
+ protected abstract void getOtherProperties(ReadGraph graph, PlotProperties properties) throws DatabaseException;\r
+\r
@Override\r
public Plot getPlot() {\r
if(plot == null)\r
plot = newPlot();\r
- \r
- SwingUtilities.invokeLater(new Runnable() {\r
- \r
- @Override\r
- public void run() {\r
- setPlotProperties();\r
- }\r
- });\r
- \r
+\r
+ if(listener == null || listener.isDisposed()) {\r
+ listener = new PlotPropertyListener();\r
+ SimanticsUI.getSession().asyncRequest(new Read<PlotProperties>() {\r
+\r
+ @Override\r
+ public PlotProperties perform(ReadGraph graph) throws DatabaseException {\r
+\r
+ PlotProperties properties = new PlotProperties();\r
+\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ JFreeChartResource jfree = JFreeChartResource.getInstance(graph);\r
+\r
+ HashMap<Resource, IAxis> axisMap = new HashMap<Resource, IAxis>();\r
+\r
+ // Get all range axis\r
+ Resource rangeList = graph.getPossibleObject(resource, jfree.Plot_rangeAxisList);\r
+ if(rangeList != null) {\r
+ for(Resource axisResource : ListUtils.toList(graph, rangeList)) {\r
+ IAxis axis = graph.adapt(axisResource, IAxis.class);\r
+ if(axis.getAxis() instanceof Axis) {\r
+ properties.ranges.add(axis);\r
+ axisMap.put(axisResource, axis);\r
+ }\r
+ }\r
+ }\r
+\r
+ // Get all domain axis\r
+ // There usually is only one domain axis, but this supports also multiple domain axis\r
+ for(Resource axisResource : graph.syncRequest(new ObjectsWithType(resource, jfree.Plot_domainAxis, jfree.Axis))) {\r
+ IAxis axis = graph.adapt(axisResource, IAxis.class);\r
+ if(axis.getAxis() instanceof Axis) {\r
+ properties.domains.add(axis);\r
+ axisMap.put(axisResource, axis);\r
+ }\r
+ }\r
+\r
+ // Get all datasets and map them to axis\r
+ for(Resource datasetResource : graph.syncRequest(new ObjectsWithType(resource, l0.ConsistsOf, jfree.Dataset))) {\r
+ IDataset dataset = graph.adapt(datasetResource, IDataset.class);\r
+ if(dataset != null) {\r
+ properties.datasets.add(dataset);\r
+ Resource axisResource = graph.getPossibleObject(datasetResource, jfree.Dataset_mapToRangeAxis);\r
+ IAxis axis;\r
+ if(axisMap.containsKey(axisResource)) {\r
+ axis = axisMap.get(axisResource);\r
+ properties.rangeMappings.put(dataset, axis);\r
+ }\r
+\r
+ axisResource = graph.getPossibleObject(datasetResource, jfree.Dataset_mapToDomainAxis);\r
+ if(axisMap.containsKey(axisResource)) {\r
+ axis = axisMap.get(axisResource);\r
+ properties.domainMappings.put(dataset, axis);\r
+ }\r
+ }\r
+ }\r
+ getOtherProperties(graph, properties);\r
+ return properties;\r
+\r
+ }\r
+ }, listener);\r
+ }\r
+\r
return plot;\r
}\r
+\r
+ protected class PlotProperties {\r
+ public ArrayList<IAxis> ranges;\r
+ public ArrayList<IAxis> domains;\r
+ public ArrayList<IDataset> datasets;\r
+ public HashMap<IDataset, IAxis> rangeMappings;\r
+ public HashMap<IDataset, IAxis> domainMappings;\r
+ public HashMap<String, Object> otherProperties;\r
+ \r
+ public PlotProperties() {\r
+ datasets = new ArrayList<IDataset>();\r
+ rangeMappings = new HashMap<IDataset, IAxis>();\r
+ domainMappings = new HashMap<IDataset, IAxis>();\r
+ ranges = new ArrayList<IAxis>();\r
+ domains = new ArrayList<IAxis>();\r
+ otherProperties = new HashMap<String, Object>();\r
+ }\r
+\r
+ @Override\r
+ public boolean equals(Object other) {\r
+ if(!this.getClass().equals(other.getClass()))\r
+ return false;\r
+ PlotProperties p = (PlotProperties)other;\r
+ if(!ranges.equals(p.ranges))\r
+ return false;\r
+ if(!domains.equals(p.domains))\r
+ return false;\r
+ if(!datasets.equals(p.datasets))\r
+ return false;\r
+ if(!rangeMappings.equals(p.rangeMappings))\r
+ return false;\r
+ if(!domainMappings.equals(p.domainMappings))\r
+ return false;\r
+ if(!otherProperties.equals(p.otherProperties))\r
+ return false;\r
+ return true;\r
+ }\r
+ }\r
+\r
+ private class PlotPropertyListener implements Listener<PlotProperties> {\r
+\r
+ private boolean disposed = false;\r
+\r
+ public void dispose() {\r
+ disposed = true;\r
+ }\r
+ @Override\r
+ public void execute(final PlotProperties result) {\r
+ SwingUtilities.invokeLater(new Runnable() {\r
+\r
+ @Override\r
+ public void run() {\r
+ setPlotProperties(result);\r
+ }\r
+ });\r
+ }\r
+\r
+ @Override\r
+ public void exception(Throwable t) {\r
+ t.printStackTrace();\r
+ }\r
+\r
+ @Override\r
+ public boolean isDisposed() {\r
+ return disposed;\r
+ }\r
+\r
+ }\r
}\r
// Add found series\r
for(int i = 0; i < series.size(); i++) {\r
TempSeries s = series.get(i);\r
- if(renderer instanceof org.jfree.chart.renderer.category.StackedBarRenderer) {\r
+ if(renderer instanceof org.jfree.chart.renderer.category.StackedBarRenderer && s.name.contains("[")) {\r
String category = s.name.substring(0, s.name.indexOf('['));\r
String series = s.name.substring(s.name.indexOf('['));\r
dataset.addValue(s.value, series, category);\r
*\r
*/\r
public class CategoryPlot extends AbstractPlot {\r
- \r
- private Boolean visibleGrid;\r
-\r
\r
public CategoryPlot(ReadGraph graph, Resource resource) {\r
super(graph, resource);\r
- \r
- try {\r
- JFreeChartResource jfree = JFreeChartResource.getInstance(graph);\r
- // Visual properties\r
- visibleGrid = graph.getPossibleRelatedValue(resource, jfree.Plot_visibleGrid);\r
- } catch(DatabaseException e) {\r
- e.printStackTrace();\r
- }\r
-\r
- \r
}\r
\r
@Override\r
}\r
\r
@Override\r
- protected void setPlotProperties() {\r
+ protected void setPlotProperties(PlotProperties properties) {\r
if(!(plot instanceof org.jfree.chart.plot.CategoryPlot))\r
return;\r
\r
/* Support using multiple axis, but prefer using only one domain and \r
* one range axis\r
*/\r
- for(int i = 0; i < ranges.size(); i++) {\r
- cplot.setRangeAxis(i, (ValueAxis)ranges.get(i).getAxis());\r
+ for(int i = 0; i < properties.ranges.size(); i++) {\r
+ cplot.setRangeAxis(i, (ValueAxis)properties.ranges.get(i).getAxis());\r
}\r
\r
- for(int i = 0; i < domains.size(); i++) {\r
- cplot.setDomainAxis(i, (CategoryAxis)domains.get(i).getAxis());\r
+ for(int i = 0; i < properties.domains.size(); i++) {\r
+ cplot.setDomainAxis(i, (CategoryAxis)properties.domains.get(i).getAxis());\r
}\r
\r
IAxis axis;\r
- for(int i = 0; i < datasets.size(); i++) {\r
- IDataset dataset = datasets.get(i);\r
+ for(int i = 0; i < properties.datasets.size(); i++) {\r
+ IDataset dataset = properties.datasets.get(i);\r
org.jfree.data.category.CategoryDataset ds = (org.jfree.data.category.CategoryDataset)dataset.getDataset();\r
cplot.setDataset(i, ds);\r
// System.out.println("setting dataset " + i + ": " + ds);\r
cplot.setRenderer(i, (CategoryItemRenderer)dataset.getRenderer());\r
- axis = rangeMappings.get(dataset);\r
- if(axis != null && ranges.contains(axis))\r
- cplot.mapDatasetToRangeAxis(i, ranges.indexOf(axis));\r
- axis = domainMappings.get(dataset);\r
- if(axis != null && ranges.contains(axis))\r
- cplot.mapDatasetToDomainAxis(i, domains.indexOf(axis));\r
+ axis = properties.rangeMappings.get(dataset);\r
+ if(axis != null && properties.ranges.contains(axis))\r
+ cplot.mapDatasetToRangeAxis(i, properties.ranges.indexOf(axis));\r
+ axis = properties.domainMappings.get(dataset);\r
+ if(axis != null && properties.ranges.contains(axis))\r
+ cplot.mapDatasetToDomainAxis(i, properties.domains.indexOf(axis));\r
}\r
\r
+ Boolean visibleGrid = (Boolean)properties.otherProperties.get("visibleGrid");\r
if(visibleGrid != null) {\r
cplot.setRangeGridlinesVisible(visibleGrid);\r
cplot.setDomainGridlinesVisible(false);\r
cplot.setOutlineVisible(false);\r
}\r
\r
+ @Override\r
+ protected void getOtherProperties(ReadGraph graph, PlotProperties properties) throws DatabaseException {\r
+ JFreeChartResource jfree = JFreeChartResource.getInstance(graph);\r
+ Boolean visibleGrid = graph.getPossibleRelatedValue(resource, jfree.Plot_visibleGrid);\r
+ properties.otherProperties.put("visibleGrid", visibleGrid);\r
+ }\r
+\r
}\r
\r
import javax.swing.SwingUtilities;\r
\r
+import org.jfree.chart.title.LegendTitle;\r
+import org.jfree.chart.title.TextTitle;\r
import org.jfree.ui.RectangleInsets;\r
import org.simantics.databoard.Bindings;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.common.request.ObjectsWithType;\r
import org.simantics.db.common.request.PossibleObjectWithType;\r
import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.procedure.Listener;\r
+import org.simantics.db.request.Read;\r
import org.simantics.layer0.Layer0;\r
import org.simantics.sysdyn.JFreeChartResource;\r
-import org.simantics.utils.RunnableWithObject;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.utils.datastructures.Pair;\r
\r
/**\r
* Class representing a complete JFreeChart.Chart\r
public class JFreeChart implements IJFreeChart {\r
\r
private org.jfree.chart.JFreeChart jfreechart;\r
-\r
- private ITitle title;\r
- private Boolean legendVisible;\r
-\r
private IPlot plot;\r
+ private ITitle title;\r
+ private Resource chartResource;\r
\r
/**\r
* \r
* @param chartResource Resource of type JFreeChart.Chart\r
*/\r
public JFreeChart(ReadGraph graph, Resource chartResource) {\r
+ this.chartResource = chartResource;\r
+\r
try {\r
JFreeChartResource jfree = JFreeChartResource.getInstance(graph);\r
Layer0 l0 = Layer0.getInstance(graph);\r
\r
- Resource titleResource = graph.syncRequest(new PossibleObjectWithType(chartResource, l0.ConsistsOf, jfree.Title));\r
- title = graph.adapt(titleResource, ITitle.class);\r
- legendVisible = graph.getPossibleRelatedValue(chartResource, jfree.Chart_visibleLegend, Bindings.BOOLEAN);\r
-\r
Collection<Resource> plotsCollection = graph.syncRequest(new ObjectsWithType(chartResource, l0.ConsistsOf, jfree.Plot));\r
for(Resource plotResource : plotsCollection) {\r
this.plot = graph.adapt(plotResource, IPlot.class);\r
}\r
}\r
\r
+\r
+ JFreeChartListener listener;\r
+\r
/**\r
* Returns a new chart using the information collected in the constructor\r
*/\r
if(plot == null)\r
return null;\r
\r
- jfreechart = new org.jfree.chart.JFreeChart(plot.getPlot());\r
-\r
- SwingUtilities.invokeLater(new RunnableWithObject(plot) {\r
- @Override\r
- public void run() {\r
- if(jfreechart == null)\r
- return;\r
-\r
- jfreechart.setBackgroundPaint(Color.WHITE);\r
- if(jfreechart.getLegend() != null) {\r
- jfreechart.getLegend().setBorder(0, 0, 0, 0);\r
- int size = jfreechart.getLegend().getItemFont().getSize();\r
- jfreechart.getLegend().setItemFont(new Font("helvetica", Font.PLAIN, size));\r
- }\r
-\r
- org.jfree.chart.title.TextTitle t = (org.jfree.chart.title.TextTitle)title.getTitle();\r
- if(t.isVisible()) {\r
- t.setFont(new Font("georgia", Font.BOLD, 13));\r
- t.setPadding(new RectangleInsets(4, 0, 0, 0));\r
- jfreechart.setTitle(t);\r
+ if(jfreechart == null)\r
+ jfreechart = new org.jfree.chart.JFreeChart(plot.getPlot());\r
+\r
+ if(listener == null) {\r
+ listener = new JFreeChartListener();\r
+ SimanticsUI.getSession().asyncRequest(new Read<Pair<ITitle, Boolean>>() {\r
+\r
+ @Override\r
+ public Pair<ITitle, Boolean> perform(ReadGraph graph) throws DatabaseException {\r
+ if(chartResource == null || !graph.hasStatement(chartResource))\r
+ return null;\r
+ \r
+ JFreeChartResource jfree = JFreeChartResource.getInstance(graph);\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+\r
+ Resource titleResource = graph.syncRequest(new PossibleObjectWithType(chartResource, l0.ConsistsOf, jfree.Title));\r
+ title = graph.adapt(titleResource, ITitle.class);\r
+ Boolean legendVisible = graph.getPossibleRelatedValue(chartResource, jfree.Chart_visibleLegend, Bindings.BOOLEAN);\r
+ return new Pair<ITitle, Boolean>(title, legendVisible);\r
}\r
-\r
- if(legendVisible != null && !legendVisible) {\r
- jfreechart.removeLegend();\r
- }\r
- }\r
- });\r
+ }, listener);\r
+ }\r
\r
return jfreechart;\r
}\r
@Override\r
public void dispose() {\r
// Call dispose to title and plots to disable their possible listeners\r
- title.dispose();\r
+ if(title != null)\r
+ title.dispose();\r
+ if(listener != null)\r
+ listener.dispose();\r
if(plot != null)\r
plot.dispose();\r
}\r
\r
+\r
+ private class JFreeChartListener implements Listener<Pair<ITitle, Boolean>> {\r
+\r
+ private boolean disposed = false;\r
+ private LegendTitle legend;\r
+\r
+ public void dispose() {\r
+ disposed = true;\r
+ }\r
+\r
+ @Override\r
+ public void execute(final Pair<ITitle, Boolean> result) {\r
+ if(result == null)\r
+ return;\r
+ \r
+ SwingUtilities.invokeLater(new Runnable() {\r
+ @Override\r
+ public void run() {\r
+ if(jfreechart == null)\r
+ return;\r
+\r
+ jfreechart.setBackgroundPaint(Color.WHITE);\r
+ \r
+ if(jfreechart.getLegend() != null && !jfreechart.getLegend().equals(legend)) {\r
+ legend = jfreechart.getLegend(); \r
+ legend.setBorder(0, 0, 0, 0);\r
+ int size = legend.getItemFont().getSize();\r
+ legend.setItemFont(new Font("helvetica", Font.PLAIN, size));\r
+ }\r
+\r
+ if(Boolean.FALSE.equals(result.second)) {\r
+ jfreechart.removeLegend();\r
+ } else if (jfreechart.getLegend() == null && legend != null){\r
+ jfreechart.addLegend(legend);\r
+ }\r
+\r
+ TextTitle t = (org.jfree.chart.title.TextTitle)result.first.getTitle();\r
+ if(t.isVisible()) {\r
+ t.setFont(new Font("georgia", Font.BOLD, 13));\r
+ t.setPadding(new RectangleInsets(4, 0, 0, 0));\r
+ jfreechart.setTitle(t);\r
+ } else {\r
+ jfreechart.setTitle((TextTitle)null);\r
+ }\r
+ }\r
+ });\r
+ }\r
+\r
+ @Override\r
+ public void exception(Throwable t) {\r
+ t.printStackTrace();\r
+ }\r
+\r
+ @Override\r
+ public boolean isDisposed() {\r
+ return disposed;\r
+ }\r
+\r
+ }\r
+\r
}\r
private org.jfree.data.general.PieDataset pieDataset;\r
private DatasetChangeListener listener;\r
\r
- private Boolean labelsVisible;\r
-\r
public PiePlot(ReadGraph graph, Resource resource) {\r
super(graph, resource);\r
- \r
- try {\r
- labelsVisible = graph.getPossibleRelatedValue(resource, JFreeChartResource.getInstance(graph).Plot_visibleLabels, Bindings.BOOLEAN);\r
- } catch (DatabaseException e) {\r
- e.printStackTrace();\r
- }\r
}\r
\r
/**\r
}\r
\r
@Override\r
- protected void setPlotProperties() {\r
+ protected void getOtherProperties(ReadGraph graph, PlotProperties properties) throws DatabaseException {\r
+ Boolean labelsVisible = graph.getPossibleRelatedValue(resource, JFreeChartResource.getInstance(graph).Plot_visibleLabels, Bindings.BOOLEAN);\r
+ properties.otherProperties.put("labelsVisible", labelsVisible);\r
+ }\r
+ \r
+ @Override\r
+ protected void setPlotProperties(PlotProperties properties) {\r
if(!(plot instanceof MyPiePlot))\r
return;\r
\r
final MyPiePlot piePlot = (MyPiePlot)plot;\r
\r
- if(!datasets.isEmpty()) {\r
+ if(!properties.datasets.isEmpty()) {\r
// We assume that a pie plot has only one dataset\r
- final IDataset ds = datasets.get(0);\r
+ final IDataset ds = properties.datasets.get(0);\r
Dataset dataset = ((PieDataset)ds).getDataset();\r
\r
if(dataset == null)\r
\r
pieDataset = (org.jfree.data.general.PieDataset)dataset;\r
piePlot.setDataset(pieDataset);\r
+ \r
+ Boolean labelsVisible = (Boolean)properties.otherProperties.get("labelsVisible");\r
if(Boolean.FALSE.equals(labelsVisible))\r
piePlot.setLabelGenerator(null);\r
else if(piePlot.getLabelGenerator() == null)\r
public class XYDataset extends AbstractDataset {\r
\r
private XYLineAndShapeRenderer renderer;\r
- private double[] domainValues;\r
- private List<Resource> seriesList;\r
- private String realizationURI;\r
\r
public XYDataset(ReadGraph graph, final Resource datasetResource) {\r
super(graph, datasetResource);\r
-\r
- try {\r
- Layer0 l0 = Layer0.getInstance(graph);\r
- ModelingResources mr = ModelingResources.getInstance(graph);\r
- JFreeChartResource jfree = JFreeChartResource.getInstance(graph);\r
-\r
- // Find the model where the chart is located\r
- Resource model = datasetResource;\r
- do {\r
- model = graph.getPossibleObject(model, l0.PartOf);\r
- } while(model != null && !graph.isInstanceOf(model, mr.StructuralModel));\r
-\r
- // Find the variable realization of the current experiment\r
- realizationURI = null;\r
- Resource realization = graph.syncRequest(new PossibleActiveExperiment(model));\r
- if (realization == null) {\r
- Layer0X L0X = Layer0X.getInstance(graph);\r
- realization = graph.getPossibleObject(model, L0X.HasBaseRealization);\r
- }\r
- if (realization != null)\r
- realizationURI = graph.getURI(realization);\r
-\r
- if(realizationURI == null)\r
- return; // No experiment -> No results\r
-\r
-\r
- // Get a variable for the x-axis (if not time)\r
- domainValues = null;\r
- Resource domainAxis = graph.getPossibleObject(datasetResource, jfree.Dataset_mapToDomainAxis);\r
- if(domainAxis != null) {\r
- String rvi = graph.getPossibleRelatedValue(domainAxis, jfree.variableRVI);\r
- if(rvi != null && !rvi.isEmpty()) {\r
- try {\r
- Variable domainVariable = Variables.getVariable(graph, realizationURI + rvi);\r
- domainValues = domainVariable.getPossiblePropertyValue(graph, SysdynVariableProperties.VALUES , Bindings.DOUBLE_ARRAY);\r
- } catch(MissingVariableException e) {\r
- //Do nothing, use time as domain axis\r
- }\r
- }\r
- }\r
-\r
- Resource seriesList = graph.getPossibleObject(resource, jfree.Dataset_seriesList);\r
- if(seriesList != null) {\r
- this.seriesList = ListUtils.toList(graph, seriesList);\r
- }\r
-\r
- } catch (DatabaseException e) {\r
- e.printStackTrace();\r
- }\r
}\r
\r
private DefaultXYDataset dataset;\r
\r
@Override\r
public Dataset getDataset() {\r
-\r
- if(seriesList == null || seriesList.isEmpty())\r
- return null;\r
-\r
if(dataset == null) {\r
dataset = new DefaultXYDataset();\r
} \r
JFreeChartResource jfree = JFreeChartResource.getInstance(graph);\r
\r
ArrayList<TempSeries> series = new ArrayList<TempSeries>();\r
+\r
+ String realizationURI = getRealizationURI(graph);\r
+\r
+ if(realizationURI == null)\r
+ return series; // No experiment -> No results\r
+\r
+ // Get a variable for the x-axis (if not time)\r
+ double[] domainValues = null;\r
+ Resource domainAxis = graph.getPossibleObject(resource, jfree.Dataset_mapToDomainAxis);\r
+ if(domainAxis != null) {\r
+ String rvi = graph.getPossibleRelatedValue(domainAxis, jfree.variableRVI);\r
+ if(rvi != null && !rvi.isEmpty()) {\r
+ try {\r
+ Variable domainVariable = Variables.getVariable(graph, realizationURI + rvi);\r
+ domainValues = domainVariable.getPossiblePropertyValue(graph, SysdynVariableProperties.VALUES , Bindings.DOUBLE_ARRAY);\r
+ } catch(MissingVariableException e) {\r
+ //Do nothing, use time as domain axis\r
+ }\r
+ }\r
+ }\r
+\r
+ Resource seriesList = graph.getPossibleObject(resource, jfree.Dataset_seriesList);\r
+\r
// Get properties for all series\r
if(seriesList != null) {\r
- for(Resource r : seriesList) {\r
+ for(Resource r : ListUtils.toList(graph, seriesList)) {\r
String rvi = graph.getPossibleRelatedValue(r, jfree.variableRVI);\r
if(rvi == null)\r
continue;\r
public Double perform(ReadGraph graph) throws DatabaseException {\r
JFreeChartResource jfree = JFreeChartResource.getInstance(graph);\r
// Get properties for all series\r
- if(seriesList != null) {\r
- for(Resource r : seriesList) {\r
- String rvi = graph.getPossibleRelatedValue(r, jfree.variableRVI);\r
- if(rvi == null)\r
- continue;\r
- try {\r
- // Get a variable for the series\r
- Variable v = Variables.getVariable(graph, realizationURI + rvi);\r
- Double time = v.getPossiblePropertyValue(graph, SysdynVariableProperties.TIME , Bindings.DOUBLE);\r
- return time;\r
- } catch (MissingVariableException e) {\r
- // Do nothing, if variable was not found.\r
+ Resource series = graph.getPossibleObject(resource, jfree.Dataset_seriesList);\r
+ if(series != null) {\r
+ List<Resource> seriesList = ListUtils.toList(graph, series);\r
+ if(seriesList != null) {\r
+ String realizationURI = getRealizationURI(graph);\r
+ for(Resource r : seriesList) {\r
+ String rvi = graph.getPossibleRelatedValue(r, jfree.variableRVI);\r
+ if(rvi == null)\r
+ continue;\r
+ try {\r
+ // Get a variable for the series\r
+ Variable v = Variables.getVariable(graph, realizationURI + rvi);\r
+ Double time = v.getPossiblePropertyValue(graph, SysdynVariableProperties.TIME , Bindings.DOUBLE);\r
+ return time;\r
+ } catch (MissingVariableException e) {\r
+ // Do nothing, if variable was not found.\r
+ }\r
}\r
}\r
}\r
}\r
return renderer;\r
}\r
+\r
+ /**\r
+ * Get the realization uri of the current dataset resource\r
+ * @param graph ReadGraph\r
+ * @return realization uri for current dataset resource\r
+ * @throws DatabaseException\r
+ */\r
+ private String getRealizationURI(ReadGraph graph) throws DatabaseException {\r
+ if(resource == null)\r
+ return null;\r
+ \r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ ModelingResources mr = ModelingResources.getInstance(graph);\r
+\r
+ // Find the model where the chart is located\r
+ Resource model = resource;\r
+ do {\r
+ model = graph.getPossibleObject(model, l0.PartOf);\r
+ } while(model != null && !graph.isInstanceOf(model, mr.StructuralModel));\r
+\r
+ if(model == null)\r
+ return null;\r
+ \r
+ // Find the variable realization of the current experiment\r
+ String realizationURI = null;\r
+ Resource realization = graph.syncRequest(new PossibleActiveExperiment(model));\r
+ if (realization == null) {\r
+ Layer0X L0X = Layer0X.getInstance(graph);\r
+ realization = graph.getPossibleObject(model, L0X.HasBaseRealization);\r
+ }\r
+ if (realization != null)\r
+ realizationURI = graph.getURI(realization);\r
+\r
+ return realizationURI;\r
+ }\r
}\r
*/\r
public class XYPlot extends AbstractPlot {\r
\r
- private Boolean visibleGrid;\r
-\r
public XYPlot(ReadGraph graph, Resource plotResource) {\r
super(graph, plotResource);\r
-\r
- try {\r
- JFreeChartResource jfree = JFreeChartResource.getInstance(graph);\r
- // Visual properties\r
- visibleGrid = graph.getPossibleRelatedValue(plotResource, jfree.Plot_visibleGrid);\r
- } catch(DatabaseException e) {\r
- e.printStackTrace();\r
- }\r
-\r
}\r
\r
@Override\r
protected Plot newPlot() {\r
return new org.jfree.chart.plot.XYPlot(null, null, null, null);\r
}\r
+ \r
+ @Override\r
+ protected void getOtherProperties(ReadGraph graph, PlotProperties properties) throws DatabaseException {\r
+ JFreeChartResource jfree = JFreeChartResource.getInstance(graph);\r
+ Boolean visibleGrid = graph.getPossibleRelatedValue(resource, jfree.Plot_visibleGrid);\r
+ properties.otherProperties.put("visibleGrid", visibleGrid);\r
+ }\r
\r
@Override\r
- protected void setPlotProperties() {\r
+ protected void setPlotProperties(PlotProperties properties) {\r
if(!(plot instanceof org.jfree.chart.plot.XYPlot))\r
return;\r
\r
xyplot.clearDomainAxes();\r
xyplot.clearRangeAxes();\r
\r
- for(int i = 0; i < ranges.size(); i++) {\r
- xyplot.setRangeAxis(i, (ValueAxis)ranges.get(i).getAxis());\r
+ for(int i = 0; i < properties.ranges.size(); i++) {\r
+ xyplot.setRangeAxis(i, (ValueAxis)properties.ranges.get(i).getAxis());\r
}\r
\r
- for(int i = 0; i < domains.size(); i++) {\r
- xyplot.setDomainAxis(i, (ValueAxis)domains.get(i).getAxis());\r
+ for(int i = 0; i < properties.domains.size(); i++) {\r
+ xyplot.setDomainAxis(i, (ValueAxis)properties.domains.get(i).getAxis());\r
}\r
\r
IAxis axis;\r
- for(int i = 0; i < datasets.size(); i++) {\r
- IDataset dataset = datasets.get(i);\r
+ for(int i = 0; i < properties.datasets.size(); i++) {\r
+ IDataset dataset = properties.datasets.get(i);\r
xyplot.setDataset(i, (XYDataset)dataset.getDataset());\r
xyplot.setRenderer(i, (XYItemRenderer)dataset.getRenderer());\r
- axis = rangeMappings.get(dataset);\r
- if(axis != null && ranges.contains(axis))\r
- xyplot.mapDatasetToRangeAxis(i, ranges.indexOf(axis));\r
- axis = domainMappings.get(dataset);\r
- if(axis != null && ranges.contains(axis))\r
- xyplot.mapDatasetToDomainAxis(i, domains.indexOf(axis));\r
+ axis = properties.rangeMappings.get(dataset);\r
+ if(axis != null && properties.ranges.contains(axis))\r
+ xyplot.mapDatasetToRangeAxis(i, properties.ranges.indexOf(axis));\r
+ axis = properties.domainMappings.get(dataset);\r
+ if(axis != null && properties.ranges.contains(axis))\r
+ xyplot.mapDatasetToDomainAxis(i, properties.domains.indexOf(axis));\r
}\r
\r
+ Boolean visibleGrid = (Boolean)properties.otherProperties.get("visibleGrid");\r
if(visibleGrid == null)\r
visibleGrid = true;\r
\r
public void load(ReadGraph g, ICanvasContext canvas, IDiagram diagram, Resource element, IElement e) throws DatabaseException {\r
\r
Resource chartResource;\r
+ \r
+ ElementPropertySetter ps = e.getElementClass().getSingleItem(ElementPropertySetter.class);\r
+ ps.loadProperties(e, element, g);\r
+ \r
+ AffineTransform at = DiagramGraphUtil.getAffineTransform(g, element);\r
+ // Hack for disabling all rotations in chart elements\r
+ double x = at.getTranslateX();\r
+ double y = at.getTranslateY();\r
+ at.setToRotation(0);\r
+ at.setToTranslation(x, y);\r
+ ElementUtils.setTransform(e, at); // Set hint transform without rotations\r
+ ps.overrideProperty(e, "Transform", at); // Set property Transform without rotations\r
+ \r
+ e.setHint(SynchronizationHints.HINT_SYNCHRONIZER, HINT_SYNCHRONIZER);\r
+ \r
\r
Object o = e.getHint(KEY_CHART_COMPONENT);\r
if(o == null || !(o instanceof Resource)) {\r
chartResource = (Resource)o;\r
}\r
\r
- if(chartResource == null || !g.hasStatement(chartResource)) \r
+ if(chartResource == null || !g.hasStatement(chartResource)) {\r
+ e.removeHint(KEY_CHART);\r
+ e.removeHint(KEY_CHART_COMPONENT);\r
return;\r
-\r
- ElementPropertySetter ps = e.getElementClass().getSingleItem(ElementPropertySetter.class);\r
- ps.loadProperties(e, element, g);\r
+ }\r
\r
IJFreeChart ichart = g.adapt(chartResource, IJFreeChart.class);\r
\r
e.setHint(KEY_CHART, chart);\r
}\r
\r
- \r
- AffineTransform at = DiagramGraphUtil.getAffineTransform(g, element);\r
- // Hack for disabling all rotations in chart elements\r
- double x = at.getTranslateX();\r
- double y = at.getTranslateY();\r
- at.setToRotation(0);\r
- at.setToTranslation(x, y);\r
- ElementUtils.setTransform(e, at); // Set hint transform without rotations\r
- ps.overrideProperty(e, "Transform", at); // Set property Transform without rotations\r
- \r
- e.setHint(SynchronizationHints.HINT_SYNCHRONIZER, HINT_SYNCHRONIZER);\r
-\r
}\r
\r
\r
}\r
\r
g2d.setTransform(ot);\r
-\r
-\r
+ } else {\r
+ /*\r
+ * Component == null\r
+ * \r
+ * The related chart definition ha been removed. \r
+ */\r
+ System.out.println("TÄÄLLÄ, TÄÄLLÄ");\r
}\r
}\r
\r