protected Resource resource;\r
protected Plot plot;\r
protected PlotProperties currentProperties;\r
- private PlotPropertyListener listener;\r
- private org.jfree.chart.JFreeChart jfreechart;\r
+ protected PlotPropertyListener listener;\r
+ protected org.jfree.chart.JFreeChart jfreechart;\r
\r
public AbstractPlot(ReadGraph graph, Resource resource) {\r
this.resource = resource;\r
\r
if(listener == null || listener.isDisposed()) {\r
listener = new PlotPropertyListener();\r
- SimanticsUI.getSession().asyncRequest(new Read<PlotProperties>() {\r
+ SimanticsUI.getSession().asyncRequest(new PlotPropertyQuery(), listener);\r
+ }\r
\r
- @Override\r
- public PlotProperties perform(ReadGraph graph) throws DatabaseException {\r
+ return plot;\r
+ }\r
+ \r
+ protected IDataset getDataset(ReadGraph graph, Resource datasetResource) throws DatabaseException{\r
+ return graph.adapt(datasetResource, IDataset.class);\r
+ }\r
+ \r
+ @Override\r
+ public void configurePlot(PlotProperties properties) {\r
+ \r
+ }\r
\r
- PlotProperties properties = new PlotProperties();\r
+ protected class PlotPropertyQuery implements Read<PlotProperties> {\r
+ \r
+ public PlotPropertyQuery() {\r
+ \r
+ }\r
\r
- Layer0 l0 = Layer0.getInstance(graph);\r
- JFreeChartResource jfree = JFreeChartResource.getInstance(graph);\r
+ @Override\r
+ public PlotProperties perform(ReadGraph graph) throws DatabaseException {\r
\r
- HashMap<Resource, IAxis> axisMap = new HashMap<Resource, IAxis>();\r
+ PlotProperties properties = new PlotProperties();\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
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ JFreeChartResource jfree = JFreeChartResource.getInstance(graph);\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
+ HashMap<Resource, IAxis> axisMap = new HashMap<Resource, IAxis>();\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
+ // 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 = getDataset(graph, datasetResource);\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
- getOtherProperties(graph, properties);\r
- return properties;\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
- }, listener);\r
- }\r
+ }\r
+ getOtherProperties(graph, properties);\r
+ return properties;\r
\r
- return plot;\r
+ }\r
}\r
\r
- @Override\r
- public void configurePlot(PlotProperties properties) {\r
- \r
- }\r
-\r
- private class PlotPropertyListener implements Listener<PlotProperties> {\r
+ protected class PlotPropertyListener implements Listener<PlotProperties> {\r
\r
private boolean disposed = false;\r
+ \r
+ public PlotPropertyListener() {\r
+ \r
+ }\r
\r
public void dispose() {\r
disposed = true;\r
*/\r
public class JFreeChart implements IJFreeChart {\r
\r
- private org.jfree.chart.JFreeChart jfreechart;\r
- private IPlot plot;\r
- private ITitle title;\r
- private Resource chartResource;\r
+ protected org.jfree.chart.JFreeChart jfreechart;\r
+ protected JFreeChartListener listener;\r
+ protected IPlot plot;\r
+ protected ITitle title;\r
+ protected 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
- 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
- } catch(DatabaseException e) {\r
- e.printStackTrace();\r
- }\r
+ this.chartResource = chartResource; \r
+ initialize(graph);\r
+ }\r
+ \r
+ protected JFreeChart() {\r
+ // default constructor is used with inherited classes.\r
+ }\r
+ \r
+ protected void initialize(ReadGraph graph) {\r
+ try {\r
+ JFreeChartResource jfree = JFreeChartResource.getInstance(graph);\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+\r
+ Collection<Resource> plotsCollection = graph.syncRequest(new ObjectsWithType(chartResource, l0.ConsistsOf, jfree.Plot));\r
+ for(Resource plotResource : plotsCollection) {\r
+ this.plot = getPlot(graph,plotResource);\r
+ } \r
+\r
+ } catch(DatabaseException e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+ \r
+ protected IPlot getPlot(ReadGraph graph, Resource plotResource) throws DatabaseException{\r
+ return graph.adapt(plotResource, IPlot.class);\r
}\r
\r
\r
- JFreeChartListener listener;\r
+ \r
\r
/**\r
* Returns a new chart using the information collected in the constructor\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
- }, listener);\r
+ SimanticsUI.getSession().asyncRequest(new JFreeChartQuery(), listener);\r
}\r
\r
return jfreechart;\r
plot.dispose();\r
}\r
\r
+ protected class JFreeChartQuery implements Read<Pair<ITitle, Boolean>> {\r
+ \r
+ public JFreeChartQuery() {\r
+ }\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
- private class JFreeChartListener implements Listener<Pair<ITitle, Boolean>> {\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
+ \r
+ protected class JFreeChartListener implements Listener<Pair<ITitle, Boolean>> {\r
\r
private boolean disposed = false;\r
private LegendTitle legend;\r
+ \r
+ public JFreeChartListener() {\r
+ \r
+ }\r
\r
public void dispose() {\r
disposed = true;\r