From 4be942e0fcd008d56bdc5617814322e5dcaee517 Mon Sep 17 00:00:00 2001 From: Simon Ebner Date: Wed, 23 Oct 2013 10:33:57 +0200 Subject: [PATCH] Cleanups --- ch.psi.plot/.classpath | 38 +++- .../org.eclipse.core.resources.prefs | 3 + .../.settings/org.eclipse.jdt.core.prefs | 4 +- ch.psi.plot/Readme.md | 12 ++ ch.psi.plot/documentation/Readme.txt | 1 - ch.psi.plot/pom.xml | 14 +- .../src/main/java/ch/psi/plot/Plot.java | 4 - .../main/java/ch/psi/plot/xy/LinePlot.java | 95 +--------- .../java/ch/psi/plot/xy/tools/Average.java | 3 +- .../java/ch/psi/plot/xy/tools/Derivative.java | 3 +- .../java/ch/psi/plot/xy/tools/Integral.java | 3 +- .../java/ch/psi/plot/xy/tools/Maximum.java | 3 +- .../java/ch/psi/plot/xy/tools/Minimum.java | 3 +- .../java/ch/psi/plot/xyz/ColorManager.java | 3 +- .../ch/psi/plot/xyz/DynamicXYZDataset.java | 166 +----------------- .../psi/plot/xyz/DynamicXYZDatasetList.java | 14 -- .../psi/plot/xyz/DynamicXYZDatasetNumber.java | 3 - .../java/ch/psi/plot/xyz/MatrixPlot2.java | 9 - .../java/ch/psi/plot/xyz/MatrixPlotData.java | 3 - .../java/ch/psi/plot/xyz/XYZDatasetUtil.java | 2 - 20 files changed, 77 insertions(+), 309 deletions(-) create mode 100644 ch.psi.plot/.settings/org.eclipse.core.resources.prefs create mode 100644 ch.psi.plot/Readme.md delete mode 100644 ch.psi.plot/documentation/Readme.txt diff --git a/ch.psi.plot/.classpath b/ch.psi.plot/.classpath index 8be6238..953de0b 100644 --- a/ch.psi.plot/.classpath +++ b/ch.psi.plot/.classpath @@ -1,10 +1,36 @@ - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ch.psi.plot/.settings/org.eclipse.core.resources.prefs b/ch.psi.plot/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..5b781ec --- /dev/null +++ b/ch.psi.plot/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,3 @@ +eclipse.preferences.version=1 +encoding//src/main/java=UTF-8 +encoding//src/test/java=UTF-8 diff --git a/ch.psi.plot/.settings/org.eclipse.jdt.core.prefs b/ch.psi.plot/.settings/org.eclipse.jdt.core.prefs index 16ba924..ec4300d 100644 --- a/ch.psi.plot/.settings/org.eclipse.jdt.core.prefs +++ b/ch.psi.plot/.settings/org.eclipse.jdt.core.prefs @@ -1,3 +1,5 @@ -#Tue Oct 18 15:36:07 CEST 2011 eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.compliance=1.7 org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/ch.psi.plot/Readme.md b/ch.psi.plot/Readme.md new file mode 100644 index 0000000..edb69b0 --- /dev/null +++ b/ch.psi.plot/Readme.md @@ -0,0 +1,12 @@ +# Overview + +# Notes +JFree is not thread safe! + +While data is modified while JFree is rendering the plot there will be an runtime exception. + +E.g. if you define an array of hundred points to be plotted by JFree and for some reason +you decide to remove (or alter) these points, then the rendering thread tries to finish rendering the 100 +points it started with but allows the concurrent modification of the data. This causes a runtime +ArrayIndexOutOfBounds or similar Runtime Exception in the worst case or at least give a 'noisy' impression of the plotting. +However, the problem occurs only for large datasets and/or high update frequencies. diff --git a/ch.psi.plot/documentation/Readme.txt b/ch.psi.plot/documentation/Readme.txt deleted file mode 100644 index 94f8265..0000000 --- a/ch.psi.plot/documentation/Readme.txt +++ /dev/null @@ -1 +0,0 @@ -JFree is not thread safe. If a manipulate the plotting data used by JFree, the rendering process is not synchronized in the sense that it does not lock the data and hence does not finish plotting the data it started with. If you e.g. define a array of hundred points to be plotted by JFree and for some reason you decide to remove (or alter) these points, then the rendering thread tries to finish rendering the 100 points it started with but allows the concurrent modification of the data. This can cause a runtime Array Index Out of Bounds Exception in the worst case or at least give a 'noisy' impression of the plotting. However, the problem occurs only for large datasets and/or high update frequencies. diff --git a/ch.psi.plot/pom.xml b/ch.psi.plot/pom.xml index 7054861..419c6d3 100644 --- a/ch.psi.plot/pom.xml +++ b/ch.psi.plot/pom.xml @@ -2,13 +2,13 @@ 4.0.0 ch.psi plot - 1.1.30 + 1.1.31 org.jfree - chart - 1.0.13 + jfreechart + 1.0.15 junit @@ -20,6 +20,14 @@ + + maven-compiler-plugin + + UTF-8 + 1.7 + 1.7 + + org.apache.maven.plugins diff --git a/ch.psi.plot/src/main/java/ch/psi/plot/Plot.java b/ch.psi.plot/src/main/java/ch/psi/plot/Plot.java index f3145a7..f9dc7d9 100644 --- a/ch.psi.plot/src/main/java/ch/psi/plot/Plot.java +++ b/ch.psi.plot/src/main/java/ch/psi/plot/Plot.java @@ -22,10 +22,6 @@ package ch.psi.plot; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; -/** - * @author ebner - * - */ public interface Plot { /** * Get the chart panel diff --git a/ch.psi.plot/src/main/java/ch/psi/plot/xy/LinePlot.java b/ch.psi.plot/src/main/java/ch/psi/plot/xy/LinePlot.java index ffe6c37..b77ae1f 100644 --- a/ch.psi.plot/src/main/java/ch/psi/plot/xy/LinePlot.java +++ b/ch.psi.plot/src/main/java/ch/psi/plot/xy/LinePlot.java @@ -50,8 +50,6 @@ import ch.psi.plot.xy.tools.Minimum; public class LinePlot implements Plot { - - // Get Logger private static final Logger logger = Logger.getLogger(LinePlot.class.getName()); private ChartPanel chartPanel; @@ -77,7 +75,6 @@ public class LinePlot implements Plot { private boolean tooltips = false; /** - * Constructor * @param title Title of plot */ public LinePlot(String title){ @@ -86,7 +83,6 @@ public class LinePlot implements Plot { /** - * Constructor * @param title Title of plot * @param data Data of plot */ @@ -222,7 +218,7 @@ public class LinePlot implements Plot { } /** - * Add additional items to the context menu of the frame + * Add additional items to the context menu of the plot */ public void amendContextMenu(){ @@ -231,7 +227,7 @@ public class LinePlot implements Plot { JMenu toolsMenu = new JMenu("Tools"); chartPanel.getPopupMenu().add(toolsMenu); - // Manipulation function + // Mark average JMenuItem averageMenuItem = new JMenuItem("Average"); averageMenuItem.addActionListener(new ActionListener() { @Override @@ -239,8 +235,6 @@ public class LinePlot implements Plot { Average average = new Average(); for (XYSeriesP series : data.getSeries()) { double a = average.average(series); -// System.out.println("Average: "+a); - // Remove all range markers Collection c = chartPanel.getChart().getXYPlot().getRangeMarkers(Layer.FOREGROUND); if(c!=null){ @@ -269,9 +263,10 @@ public class LinePlot implements Plot { } } }); -// chartPanel.getPopupMenu().add(averageMenuItem); toolsMenu.add(averageMenuItem); + + // Mark minimum value JMenuItem minimumMenuItem = new JMenuItem("Minimum"); minimumMenuItem.addActionListener(new ActionListener() { @Override @@ -290,10 +285,10 @@ public class LinePlot implements Plot { } } }); -// chartPanel.getPopupMenu().add(minimumMenuItem); toolsMenu.add(minimumMenuItem); + // Mark maximum value JMenuItem maximumMenuItem = new JMenuItem("Maximum"); maximumMenuItem.addActionListener(new ActionListener() { @Override @@ -301,7 +296,6 @@ public class LinePlot implements Plot { Maximum maximum = new Maximum(); for (XYSeriesP series : data.getSeries()) { XYDataItem m = maximum.maximum(series); -// System.out.println("Maximum: "+m.getXValue()); // Remove all annotation for the series for(Object o: chartPanel.getChart().getXYPlot().getAnnotations()){ chartPanel.getChart().getXYPlot().removeAnnotation((XYAnnotation) o); @@ -312,26 +306,15 @@ public class LinePlot implements Plot { } } }); -// chartPanel.getPopupMenu().add(maximumMenuItem); toolsMenu.add(maximumMenuItem); + + // Show derivative JMenuItem derivativeMenuItem = new JMenuItem("Derivative"); derivativeMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Derivative derivative = new Derivative(); -// for (XYSeriesP series : data.getSeries()) { -// // Show derivative in same plot -// final XYSeriesP s = derivative.derivative(series); -// SwingUtilities.invokeLater(new Runnable() { // Avoid concurrent modification exception -// @Override -// public void run() { -// data.addSeries(s); // Add Derivative -// } -// }); -// } - - // Show new frame LinePlot p = new LinePlot("Derivative - " + title, derivative.derivative(data)); JFrame frame = new JFrame(); @@ -341,9 +324,9 @@ public class LinePlot implements Plot { frame.setVisible(true); } }); -// chartPanel.getPopupMenu().add(derivativeMenuItem); toolsMenu.add(derivativeMenuItem); + // Show integral JMenuItem integralMenuItem = new JMenuItem("Integral"); integralMenuItem.addActionListener(new ActionListener() { @Override @@ -360,37 +343,10 @@ public class LinePlot implements Plot { frame.setVisible(true); } }); -// chartPanel.getPopupMenu().add(integralMenuItem); toolsMenu.add(integralMenuItem); chartPanel.getPopupMenu().addSeparator(); -// // Plot all series of the plot in a own plot -// JMenuItem splitPlotMenuItem = new JMenuItem("Split"); -// splitPlotMenuItem.addActionListener(new ActionListener() { -// @Override -// public void actionPerformed(ActionEvent e) { -// for (XYSeriesP serie : data.getSeries()) { -// XYSeriesCollectionP collection = new XYSeriesCollectionP(); -// collection.addSeries(serie); -// -// int index = data.indexOf(serie); -// //The right colors are not automatically assigned -// Paint paint = chart.getXYPlot().getRenderer().getSeriesPaint(index); -// LinePlot p = new LinePlot((String) serie.getKey(), collection); -// // there is only one series in this plot, so we choose index 0 to assign paint -// p.getChartPanel().getChart().getXYPlot().getRenderer().setSeriesPaint(0, paint); -// -// JFrame frame = new JFrame(); -// frame.setContentPane(p.getChartPanel()); -// frame.pack(); -// RefineryUtilities.centerFrameOnScreen(frame); -// frame.setVisible(true); -// } -// } -// }); -// chartPanel.getPopupMenu().add(splitPlotMenuItem); - // Detach plot into a separate frame JMenuItem detachPlotMenuItem = new JMenuItem("Detach"); detachPlotMenuItem.addActionListener(new ActionListener() { @@ -454,9 +410,6 @@ public class LinePlot implements Plot { } - /** - * Show tooltips - */ private void showTooltips(){ tooltips = true; DecimalFormat dm = new DecimalFormat("0.##########"); @@ -466,9 +419,6 @@ public class LinePlot implements Plot { chartPanel.getChartRenderingInfo().setEntityCollection(new StandardEntityCollection()); } - /** - * Hide tooltips - */ private void hideTooltips(){ tooltips = false; // http://www.jfree.org/phpBB2/viewtopic.php?t=12788&highlight=redraw+speed+performance+problem @@ -477,13 +427,8 @@ public class LinePlot implements Plot { } - /* (non-Javadoc) - * @see ch.psi.plot.Plot#update() - */ @Override public void update() { - // Fire chart change event -// chart.fireChartChanged(); if(data != null){ SwingUtilities.invokeLater(new Runnable() { // Try to avoid concurrent modification exception @Override @@ -502,48 +447,26 @@ public class LinePlot implements Plot { } - /* (non-Javadoc) - * @see ch.psi.plot.Plot#getChart() - */ @Override public JFreeChart getChart() { return chart; } - //getter and setter + // Getter and setter public XYSeriesCollectionP getData() { return data; } - - /** - * @return the xAxisLabel - */ public String getxAxisLabel() { return xAxisLabel; } - - /** - * @param xAxisLabel the xAxisLabel to set - */ public void setxAxisLabel(String xAxisLabel) { this.xAxisLabel = xAxisLabel; } - - /** - * @return the yAxisLabel - */ public String getyAxisLabel() { return yAxisLabel; } - - /** - * @param yAxisLabel the yAxisLabel to set - */ public void setyAxisLabel(String yAxisLabel) { this.yAxisLabel = yAxisLabel; } - - - } diff --git a/ch.psi.plot/src/main/java/ch/psi/plot/xy/tools/Average.java b/ch.psi.plot/src/main/java/ch/psi/plot/xy/tools/Average.java index 94e6c1a..3d63bcf 100644 --- a/ch.psi.plot/src/main/java/ch/psi/plot/xy/tools/Average.java +++ b/ch.psi.plot/src/main/java/ch/psi/plot/xy/tools/Average.java @@ -26,8 +26,7 @@ import ch.psi.plot.xy.XYSeriesP; /** - * @author ebner - * + * Calculate average of series */ public class Average { diff --git a/ch.psi.plot/src/main/java/ch/psi/plot/xy/tools/Derivative.java b/ch.psi.plot/src/main/java/ch/psi/plot/xy/tools/Derivative.java index 5deb51f..68a5f6f 100644 --- a/ch.psi.plot/src/main/java/ch/psi/plot/xy/tools/Derivative.java +++ b/ch.psi.plot/src/main/java/ch/psi/plot/xy/tools/Derivative.java @@ -25,8 +25,7 @@ import ch.psi.plot.xy.XYSeriesCollectionP; import ch.psi.plot.xy.XYSeriesP; /** - * @author ebner - * + * Calculate derivative of series */ public class Derivative { diff --git a/ch.psi.plot/src/main/java/ch/psi/plot/xy/tools/Integral.java b/ch.psi.plot/src/main/java/ch/psi/plot/xy/tools/Integral.java index 4643958..d4014b0 100644 --- a/ch.psi.plot/src/main/java/ch/psi/plot/xy/tools/Integral.java +++ b/ch.psi.plot/src/main/java/ch/psi/plot/xy/tools/Integral.java @@ -25,8 +25,7 @@ import ch.psi.plot.xy.XYSeriesCollectionP; import ch.psi.plot.xy.XYSeriesP; /** - * @author ebner - * + * Calculate integral of series */ public class Integral { diff --git a/ch.psi.plot/src/main/java/ch/psi/plot/xy/tools/Maximum.java b/ch.psi.plot/src/main/java/ch/psi/plot/xy/tools/Maximum.java index 35c8ca3..1f60676 100644 --- a/ch.psi.plot/src/main/java/ch/psi/plot/xy/tools/Maximum.java +++ b/ch.psi.plot/src/main/java/ch/psi/plot/xy/tools/Maximum.java @@ -23,8 +23,7 @@ import org.jfree.data.xy.XYDataItem; import ch.psi.plot.xy.XYSeriesP; /** - * @author ebner - * + * Find maximum of series */ public class Maximum { diff --git a/ch.psi.plot/src/main/java/ch/psi/plot/xy/tools/Minimum.java b/ch.psi.plot/src/main/java/ch/psi/plot/xy/tools/Minimum.java index 218493a..50c49ce 100644 --- a/ch.psi.plot/src/main/java/ch/psi/plot/xy/tools/Minimum.java +++ b/ch.psi.plot/src/main/java/ch/psi/plot/xy/tools/Minimum.java @@ -23,8 +23,7 @@ import org.jfree.data.xy.XYDataItem; import ch.psi.plot.xy.XYSeriesP; /** - * @author ebner - * + * Find minimum of series */ public class Minimum { diff --git a/ch.psi.plot/src/main/java/ch/psi/plot/xyz/ColorManager.java b/ch.psi.plot/src/main/java/ch/psi/plot/xyz/ColorManager.java index 72e7626..9ad603a 100644 --- a/ch.psi.plot/src/main/java/ch/psi/plot/xyz/ColorManager.java +++ b/ch.psi.plot/src/main/java/ch/psi/plot/xyz/ColorManager.java @@ -22,8 +22,7 @@ package ch.psi.plot.xyz; import java.awt.Color; /** - * @author ebner - * + * Utility class for applying a color map */ public class ColorManager { diff --git a/ch.psi.plot/src/main/java/ch/psi/plot/xyz/DynamicXYZDataset.java b/ch.psi.plot/src/main/java/ch/psi/plot/xyz/DynamicXYZDataset.java index 6d8e4ce..a101356 100644 --- a/ch.psi.plot/src/main/java/ch/psi/plot/xyz/DynamicXYZDataset.java +++ b/ch.psi.plot/src/main/java/ch/psi/plot/xyz/DynamicXYZDataset.java @@ -24,7 +24,6 @@ import java.util.List; import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.renderer.xy.XYBlockRenderer; import org.jfree.data.DomainOrder; -import org.jfree.data.general.DatasetChangeEvent; import org.jfree.data.general.DatasetChangeListener; import org.jfree.data.general.DatasetGroup; import org.jfree.data.xy.XYZDataset; @@ -32,15 +31,11 @@ import org.jfree.ui.RectangleAnchor; /** * Dynamic dataset - * @author ebner - * */ public class DynamicXYZDataset implements XYZDataset{ private final double xResolution; private final double yResolution; - private final double incX; - private final double incY; private final NumberAxis xAxis = new NumberAxis(); private double xLowerBound = Double.NaN; @@ -56,7 +51,6 @@ public class DynamicXYZDataset implements XYZDataset{ private final XYBlockRenderer renderer = new XYBlockRenderer(); - private final List listeners = new ArrayList(); private List items = new ArrayList(); /** @@ -65,8 +59,6 @@ public class DynamicXYZDataset implements XYZDataset{ public DynamicXYZDataset(){ xResolution = 1.0; yResolution = 1.0; - incX = xResolution/2; - incY = yResolution/2; xAxis.setRange(xLowerBound, xUpperBound); yAxis.setRange(yLowerBound, yUpperBound); @@ -77,150 +69,56 @@ public class DynamicXYZDataset implements XYZDataset{ renderer.setBaseCreateEntities(false); } - /** - * Add datapoint - * @param x - * @param y - * @param z - */ public void addData(double x, double y, double z){ items.add(new DynamicXYZDataset.Vector(x,y,z)); - - // Update axis - - -// if(Double.isNaN(xLowerBound) && Double.isNaN(xUpperBound)){ -// xLowerBound = x-incX; -// xUpperBound = x+incX; -// xAxis.setRange(xLowerBound, xUpperBound); -// } -// else{ -// if(x>(xUpperBound+incX)){ -// xUpperBound = x+incX; -// xAxis.setUpperBound(xUpperBound); -// } -// else if(x(yUpperBound+incY)){ -// yUpperBound = y+incY; -// yAxis.setUpperBound(yUpperBound); -// } -// else if(yzUpperBound){ -// zUpperBound = z; -// } -// else if(z