*******************************************************************************/\r
package org.simantics.jfreechart.chart;\r
\r
-import java.util.ArrayList;\r
import java.util.HashMap;\r
\r
import javax.swing.SwingUtilities;\r
\r
+import org.jfree.chart.JFreeChart;\r
import org.jfree.chart.axis.Axis;\r
import org.jfree.chart.plot.Plot;\r
import org.simantics.db.ReadGraph;\r
protected Plot plot;\r
protected PlotProperties currentProperties;\r
private PlotPropertyListener listener;\r
-\r
+ private org.jfree.chart.JFreeChart jfreechart;\r
\r
public AbstractPlot(ReadGraph graph, Resource resource) {\r
this.resource = resource;\r
public Resource getResource() {\r
return resource;\r
}\r
+ \r
+ @Override\r
+ public void setJFreeChart(JFreeChart jfreechart) {\r
+ this.jfreechart = jfreechart;\r
+ }\r
+ \r
+ public org.jfree.chart.JFreeChart getJfreechart() {\r
+ return jfreechart;\r
+ }\r
+ \r
+ public PlotProperties getPlotProperties() {\r
+ return currentProperties;\r
+ }\r
\r
protected abstract Plot newPlot();\r
- protected abstract void setPlotProperties(PlotProperties properties);\r
+ protected void setPlotProperties(PlotProperties properties) {\r
+ this.currentProperties = properties;\r
+ }\r
protected abstract void getOtherProperties(ReadGraph graph, PlotProperties properties) throws DatabaseException;\r
\r
@Override\r
}\r
\r
@Override\r
- public void configurePlot() {\r
- // TODO Auto-generated method stub\r
+ public void configurePlot(PlotProperties properties) {\r
\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
@Override\r
public void run() {\r
setPlotProperties(result);\r
- configurePlot();\r
+ configurePlot(result);\r
}\r
});\r
}\r
// Cleaner look: no outline borders\r
cplot.setInsets(new RectangleInsets(2,5,2,2), false);\r
cplot.setOutlineVisible(false);\r
+ super.setPlotProperties(properties);\r
}\r
\r
@Override\r
return jPanel;\r
}\r
\r
- private void setPanel(final ChartPanel panel) {\r
+ protected void setPanel(final ChartPanel panel) {\r
ThreadUtils.asyncExec(AWTThread.getThreadAccess(), new Runnable() {\r
\r
@Override\r
}\r
});\r
}\r
+ \r
+ public ChartPanel getChartPanel() {\r
+ return chartPanel;\r
+ }\r
+ \r
+ public IJFreeChart getChart() {\r
+ return chart;\r
+ }\r
\r
/**\r
* Creates and displays the chart defined in chartResource\r
\r
import org.jfree.data.category.DefaultCategoryDataset;\r
import org.jfree.data.general.AbstractDataset;\r
+import org.jfree.data.general.DatasetChangeEvent;\r
+import org.jfree.data.general.DatasetChangeListener;\r
\r
@SuppressWarnings("rawtypes")\r
-public class FilteringCategoryDataset extends AbstractDataset implements org.jfree.data.category.CategoryDataset, FilteredDataset{\r
+public class FilteringCategoryDataset extends AbstractDataset implements org.jfree.data.category.CategoryDataset, FilteredDataset, DatasetChangeListener{\r
\r
private static final long serialVersionUID = -4955124650051030544L;\r
\r
this.filtered = new DefaultCategoryDataset();\r
this.other = other;\r
this.used = filtered;\r
+ this.original.addChangeListener(this);\r
updateFiltered();\r
}\r
\r
if (Math.abs(value.doubleValue()) > total) {\r
filtered.addValue(value, (Comparable) row, (Comparable)column);\r
} else {\r
- // TODO : what is proper way to handle negative values?\r
- other += Math.abs(value.doubleValue()); \r
+ other += value.doubleValue(); \r
}\r
}\r
- if (other > 0.0) {\r
+ if (Math.abs(other) > 0.0) {\r
filtered.addValue(other, this.other, (Comparable)column);\r
}\r
}\r
if (Math.abs(value.doubleValue()) > total) {\r
filtered.addValue(value, (Comparable) row, (Comparable)column);\r
} else {\r
- // TODO : what is proper way to handle negative values?\r
- other += Math.abs(value.doubleValue()); \r
+ other += value.doubleValue(); \r
}\r
}\r
- if (other > 0.0) {\r
+ if (Math.abs(other) > 0.0) {\r
filtered.addValue(other, (Comparable)row, this.other);\r
}\r
}\r
return other;\r
}\r
\r
- \r
+ @Override\r
+ public void datasetChanged(DatasetChangeEvent event) {\r
+ // bypass change events from the original dataset.\r
+ fireDatasetChanged();\r
+ }\r
\r
\r
}\r
*/\r
public JFreeChart getChart();\r
\r
+ public IPlot getPlot();\r
+ \r
}\r
*******************************************************************************/\r
package org.simantics.jfreechart.chart;\r
\r
+import org.jfree.chart.JFreeChart;\r
import org.jfree.chart.plot.Plot;\r
import org.simantics.db.Resource;\r
import org.simantics.db.exception.DatabaseException;\r
*/\r
public Resource getResource();\r
\r
- public void configurePlot();\r
+ public void configurePlot(PlotProperties properties);\r
\r
+ public PlotProperties getPlotProperties();\r
+ \r
+ public void setJFreeChart(JFreeChart jfreechart);\r
+ \r
+ public JFreeChart getJfreechart();\r
}\r
\r
if(jfreechart == null)\r
jfreechart = new org.jfree.chart.JFreeChart(plot.getPlot());\r
-\r
+ \r
+ plot.setJFreeChart(jfreechart);\r
+ \r
if(listener == null) {\r
listener = new JFreeChartListener();\r
SimanticsUI.getSession().asyncRequest(new Read<Pair<ITitle, Boolean>>() {\r
\r
return jfreechart;\r
}\r
+ \r
+ @Override\r
+ public IPlot getPlot() {\r
+ return plot;\r
+ }\r
\r
@Override\r
public void dispose() {\r
* @author Teemu Lempinen\r
*\r
*/\r
- private class MyPiePlot extends org.jfree.chart.plot.PiePlot {\r
+ protected static class MyPiePlot extends org.jfree.chart.plot.PiePlot {\r
\r
private static final long serialVersionUID = -5917620061541212934L;\r
\r
@SuppressWarnings({ "unchecked", "rawtypes" })\r
@Override\r
protected void setPlotProperties(PlotProperties properties) {\r
- if(!(plot instanceof MyPiePlot))\r
+ if(!(plot instanceof org.jfree.chart.plot.PiePlot))\r
return;\r
\r
- final MyPiePlot piePlot = (MyPiePlot)plot;\r
+ final org.jfree.chart.plot.PiePlot piePlot = (org.jfree.chart.plot.PiePlot)plot;\r
\r
if(!properties.datasets.isEmpty()) {\r
// We assume that a pie plot has only one dataset\r
piePlot.setOutlineVisible(false);\r
piePlot.setLabelBackgroundPaint(Color.WHITE);\r
piePlot.setLabelFont(new Font("helvetica", Font.PLAIN, 11));\r
+ super.setPlotProperties(properties);\r
}\r
\r
}\r
--- /dev/null
+package org.simantics.jfreechart.chart;\r
+\r
+import java.util.ArrayList;\r
+import java.util.HashMap;\r
+\r
+public class PlotProperties {\r
+ \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
public class AxisDropAction implements DropActionFactory {\r
\r
@Override\r
- public Runnable create(ReadGraph g, Object target, Object source) throws DatabaseException {\r
+ public Runnable create(ReadGraph g, Object target, Object source, int operation) throws DatabaseException {\r
// Make sure that both target and source are resources\r
Resource t = AdaptionUtils.adaptToSingle(target, Resource.class);\r
Resource s = AdaptionUtils.adaptToSingle(source, Resource.class);\r
public class SeriesDropAction implements DropActionFactory {\r
\r
@Override\r
- public Runnable create(ReadGraph g, Object target, Object source) throws DatabaseException {\r
+ public Runnable create(ReadGraph g, Object target, Object source, int operation) throws DatabaseException {\r
// Make sure that both target and source are resources\r
Resource t = AdaptionUtils.adaptToSingle(target, Resource.class);\r
Resource s = AdaptionUtils.adaptToSingle(source, Resource.class);\r