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