Fixed bugs on MatrixPlotArray 7 LinePlotArray & Non-continuous mode on JZY3d

This commit is contained in:
2014-08-22 09:29:25 +02:00
parent 58cf30d915
commit 8b38fe3354
7 changed files with 81 additions and 30 deletions
+1 -1
View File
@@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>ch.psi</groupId> <groupId>ch.psi</groupId>
<artifactId>plot</artifactId> <artifactId>plot</artifactId>
<version>2.0-SNAPSHOT</version> <version>2.1-SNAPSHOT</version>
<repositories> <repositories>
<repository> <repository>
<id>jzy3d-releases</id> <id>jzy3d-releases</id>
@@ -128,6 +128,7 @@ abstract public class LinePlotBase extends PlotBase<LinePlotSeries> implements L
frame.pack(); frame.pack();
SwingUtils.centerOnScreen(frame); SwingUtils.centerOnScreen(frame);
frame.setVisible(true); frame.setVisible(true);
frame.requestFocus();
} catch (Exception ex) { } catch (Exception ex) {
SwingUtils.showException(getChartPanel(), ex); SwingUtils.showException(getChartPanel(), ex);
} }
@@ -11,6 +11,8 @@ import java.awt.image.BufferedImage;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@@ -182,6 +184,7 @@ abstract public class PlotBase<T extends PlotSeries> implements Plot<T> {
//Series list support //Series list support
final HashMap<String, T> seriesList = new HashMap<>(); final HashMap<String, T> seriesList = new HashMap<>();
volatile int seriesID=1;
@Override @Override
public void addSeries(T series) { public void addSeries(T series) {
@@ -199,6 +202,7 @@ abstract public class PlotBase<T extends PlotSeries> implements Plot<T> {
seriesList.put(series.name, series); seriesList.put(series.name, series);
} }
series.setPlot(this); series.setPlot(this);
series.id=seriesID++;
series.setToken(onAddedSeries(series)); series.setToken(onAddedSeries(series));
} }
@@ -211,12 +215,14 @@ abstract public class PlotBase<T extends PlotSeries> implements Plot<T> {
@Override @Override
public void removeSeries(T series) { public void removeSeries(T series) {
if (series.getPlot() == this) { if (series!=null){
series.setPlot(null); if (series.getPlot() == this) {
} series.setPlot(null);
onRemovedSeries(series); }
synchronized (seriesList) { onRemovedSeries(series);
seriesList.remove(series.name); synchronized (seriesList) {
seriesList.remove(series.name);
}
} }
} }
@@ -227,14 +233,13 @@ abstract public class PlotBase<T extends PlotSeries> implements Plot<T> {
} }
} }
//TODO: Not respecting order
@Override @Override
public T getSeries(int index) { public T getSeries(int index) {
synchronized (seriesList) { synchronized (seriesList) {
if ((index < 0) || (index >= seriesList.size())) { if ((index < 0) || (index >= seriesList.size())) {
return null; return null;
} }
return seriesList.get(getAllSeries()[index]); return getAllSeries()[index];
} }
} }
@@ -243,6 +248,13 @@ abstract public class PlotBase<T extends PlotSeries> implements Plot<T> {
return seriesList.size(); return seriesList.size();
} }
public class SeriesComparator implements Comparator<T> {
@Override
public int compare(T o1, T o2) {
return Integer.valueOf(o1.id).compareTo(Integer.valueOf(o2.id));
}
}
@Override @Override
public T[] getAllSeries() { public T[] getAllSeries() {
synchronized (seriesList) { synchronized (seriesList) {
@@ -250,6 +262,7 @@ abstract public class PlotBase<T extends PlotSeries> implements Plot<T> {
for (T series : seriesList.values()) { for (T series : seriesList.values()) {
list.add(series); list.add(series);
} }
Collections.sort(list, new SeriesComparator());
return list.toArray((T[]) Array.newInstance(seriesType, 0)); return list.toArray((T[]) Array.newInstance(seriesType, 0));
} }
} }
@@ -9,6 +9,7 @@ package ch.psi.plot;
public abstract class PlotSeries<T extends Plot> { public abstract class PlotSeries<T extends Plot> {
volatile boolean updating = false; volatile boolean updating = false;
volatile int id;
protected PlotSeries() { protected PlotSeries() {
this(""); this("");
@@ -28,7 +29,7 @@ public abstract class PlotSeries<T extends Plot> {
return token; return token;
} }
private T plot; private T plot;
void setPlot(T plot) { void setPlot(T plot) {
this.plot = plot; this.plot = plot;
@@ -11,6 +11,7 @@ import ch.psi.plot.utils.SwingUtils;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Component; import java.awt.Component;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
@@ -25,6 +26,7 @@ import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.media.opengl.GLAnimatorControl; import javax.media.opengl.GLAnimatorControl;
import javax.media.opengl.awt.GLCanvas;
import javax.swing.ButtonGroup; import javax.swing.ButtonGroup;
import javax.swing.JCheckBoxMenuItem; import javax.swing.JCheckBoxMenuItem;
import javax.swing.JMenu; import javax.swing.JMenu;
@@ -65,6 +67,8 @@ public class MatrixPlot extends MatrixPlotBase {
JPanel panel; JPanel panel;
private Chart chart; private Chart chart;
GLAnimatorControl animatorControl;
IScreenCanvas screenCanvas;
private Mapper mapper; private Mapper mapper;
private Shape surface; private Shape surface;
private MatrixPlotSeries series; private MatrixPlotSeries series;
@@ -86,11 +90,13 @@ public class MatrixPlot extends MatrixPlotBase {
if ((chart == null) && (series != null)) { if ((chart == null) && (series != null)) {
createGraph(); createGraph();
} }
checkBounds(true); checkBounds(true);
} }
protected void onHidden() { protected void onHidden() {
if (chart != null) { if (chart != null) {
chart.stopAnimator();
panel.removeAll();
chart.dispose(); chart.dispose();
chart = null; chart = null;
} }
@@ -276,7 +282,6 @@ public class MatrixPlot extends MatrixPlotBase {
createGraph(); createGraph();
} }
} }
public boolean getContinuousRendering() { public boolean getContinuousRendering() {
return continuousRendering; return continuousRendering;
} }
@@ -430,6 +435,7 @@ public class MatrixPlot extends MatrixPlotBase {
final JCheckBoxMenuItem menuShowLegend = new JCheckBoxMenuItem("Show Legend"); final JCheckBoxMenuItem menuShowLegend = new JCheckBoxMenuItem("Show Legend");
final JCheckBoxMenuItem menuShowFace = new JCheckBoxMenuItem("Show Face"); final JCheckBoxMenuItem menuShowFace = new JCheckBoxMenuItem("Show Face");
final JCheckBoxMenuItem menuShowFrame = new JCheckBoxMenuItem("Show Frame"); final JCheckBoxMenuItem menuShowFrame = new JCheckBoxMenuItem("Show Frame");
//final JCheckBoxMenuItem menuContinuous = new JCheckBoxMenuItem("Continuous Rendering");
JMenuItem frameColor = new JMenuItem("Set Frame Color"); JMenuItem frameColor = new JMenuItem("Set Frame Color");
final JMenu menuColormap = new JMenu("Colormap"); final JMenu menuColormap = new JMenu("Colormap");
@@ -440,6 +446,7 @@ public class MatrixPlot extends MatrixPlotBase {
menuPopup.add(menuShowLegend); menuPopup.add(menuShowLegend);
menuPopup.add(menuShowFace); menuPopup.add(menuShowFace);
menuPopup.add(menuShowFrame); menuPopup.add(menuShowFrame);
//menuPopup.add(menuContinuous);
menuPopup.add(frameColor); menuPopup.add(frameColor);
menuPopup.add(menuColormap); menuPopup.add(menuColormap);
menuPopup.add(menuMode); menuPopup.add(menuMode);
@@ -484,7 +491,20 @@ public class MatrixPlot extends MatrixPlotBase {
} }
}); });
menuShowFrame.setSelected(getShowFrame()); menuShowFrame.setSelected(getShowFrame());
/*
menuContinuous.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
setContinuousRendering(!getContinuousRendering());
menuContinuous.setSelected(getContinuousRendering());
}
});
}
});
menuContinuous.setSelected(getShowFrame());
*/
menuShowLegend.addActionListener(new ActionListener() { menuShowLegend.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
setShowLegend(!getShowLegend()); setShowLegend(!getShowLegend());
@@ -656,16 +676,14 @@ public class MatrixPlot extends MatrixPlotBase {
} }
}; };
GLAnimatorControl ac = null; animatorControl = null;
Component canvas = (Component) chart.getCanvas(); screenCanvas=null;
Component canvas = (Component) chart.getCanvas();
if (canvas instanceof IScreenCanvas) { if (canvas instanceof IScreenCanvas) {
ac = ((IScreenCanvas) canvas).getAnimator(); screenCanvas=(IScreenCanvas) canvas;
} animatorControl = screenCanvas.getAnimator();
final GLAnimatorControl animatorControl = ac;
if (!getContinuousRendering() && (animatorControl != null)) {
animatorControl.pause();
} }
panel.removeAll(); panel.removeAll();
panel.add(canvas); panel.add(canvas);
@@ -692,21 +710,22 @@ public class MatrixPlot extends MatrixPlotBase {
public void mouseWheelMoved(com.jogamp.newt.event.MouseEvent me) { public void mouseWheelMoved(com.jogamp.newt.event.MouseEvent me) {
if (!getContinuousRendering() && (animatorControl != null)) { if (!getContinuousRendering() && (animatorControl != null)) {
if (animatorControl.isPaused()) { if (animatorControl.isPaused()) {
((IScreenCanvas) canvas).display(); screenCanvas.display();
} }
} }
} }
@Override @Override
public void mouseReleased(com.jogamp.newt.event.MouseEvent e) { public void mouseReleased(com.jogamp.newt.event.MouseEvent e) {
if (e.getButton() == com.jogamp.newt.event.MouseEvent.BUTTON3) { if ((e.getButton() == com.jogamp.newt.event.MouseEvent.BUTTON3) &&
(!e.isAltDown())&&(!e.isControlDown())&&(!e.isShiftDown()) ){
menuPopup.show(panel, e.getX(), e.getY()); menuPopup.show(panel, e.getX(), e.getY());
} }
if (!getContinuousRendering() && (animatorControl != null)) { if (!getContinuousRendering() && (animatorControl != null)) {
if ((e.getClickCount() != 2) && (e.getButtonsDown().length <= 1)) { if ((e.getClickCount() != 2) && (e.getButtonsDown().length <= 1)) {
animatorControl.pause(); animatorControl.pause();
((IScreenCanvas) canvas).display(); screenCanvas.display();
} }
} }
} }
@@ -719,7 +738,7 @@ public class MatrixPlot extends MatrixPlotBase {
if (!getContinuousRendering() && (animatorControl != null)) { if (!getContinuousRendering() && (animatorControl != null)) {
if ((e.getClickCount() != 2) ) { if ((e.getClickCount() != 2) ) {
animatorControl.pause(); animatorControl.pause();
((IScreenCanvas) canvas).display(); screenCanvas.display();
} }
} }
} }
@@ -727,7 +746,7 @@ public class MatrixPlot extends MatrixPlotBase {
public void mouseWheelMoved(MouseWheelEvent e){ public void mouseWheelMoved(MouseWheelEvent e){
if (!getContinuousRendering() && (animatorControl != null)) { if (!getContinuousRendering() && (animatorControl != null)) {
if (animatorControl.isPaused()) { if (animatorControl.isPaused()) {
((IScreenCanvas) canvas).display(); screenCanvas.display();
} }
} }
} }
@@ -742,7 +761,8 @@ public class MatrixPlot extends MatrixPlotBase {
} }
private void checkPopup(MouseEvent e) { private void checkPopup(MouseEvent e) {
if (e.isPopupTrigger()) { if (e.isPopupTrigger() &&
(!e.isAltDown())&&(!e.isControlDown())&&(!e.isShiftDown()) ) {
menuPopup.show(e.getComponent(), e.getX(), e.getY()); menuPopup.show(e.getComponent(), e.getX(), e.getY());
} }
} }
@@ -751,6 +771,17 @@ public class MatrixPlot extends MatrixPlotBase {
chart.getCanvas().addMouseController(listener); chart.getCanvas().addMouseController(listener);
updateGraph(true); updateGraph(true);
if (!getContinuousRendering() && (animatorControl != null)) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
animatorControl.pause();
}
});
}
} }
if (formerChart != null) { if (formerChart != null) {
formerChart.dispose(); formerChart.dispose();
@@ -758,7 +789,7 @@ public class MatrixPlot extends MatrixPlotBase {
} }
} }
private void updateGraph(final boolean newSeries) { private void updateGraph(final boolean newSeries) {
if (!SwingUtilities.isEventDispatchThread()) { if (!SwingUtilities.isEventDispatchThread()) {
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@@ -5,6 +5,8 @@ package ch.psi.plot.utils;
*/ */
import java.awt.event.HierarchyEvent; import java.awt.event.HierarchyEvent;
import java.awt.event.HierarchyListener; import java.awt.event.HierarchyListener;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JPanel; import javax.swing.JPanel;
/** /**
@@ -21,11 +23,13 @@ public class MonitoredPanel extends JPanel {
try { try {
onShown(); onShown();
} catch (Exception ex) { } catch (Exception ex) {
Logger.getLogger(MonitoredPanel.class.getName()).log(Level.FINE, null, ex);
} }
} else { } else {
try { try {
onHidden(); onHidden();
} catch (Exception ex) { } catch (Exception ex) {
Logger.getLogger(MonitoredPanel.class.getName()).log(Level.FINE, null, ex);
} }
} }
} }
+2 -1
View File
@@ -77,7 +77,8 @@ public class LinePlotTest {
} }
} }
} }
// plot.removeSeries(plot.getSeries(0));
// plot.removeSeries(plot.getSeries(1));
System.out.println("DONE: " + (System.currentTimeMillis() - start)); System.out.println("DONE: " + (System.currentTimeMillis() - start));
} }
}); });