Charts are JPanel instances (GUI builder), uniformization of menu, copy, print...
This commit is contained in:
@@ -12,6 +12,7 @@ import java.io.IOException;
|
|||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JMenu;
|
import javax.swing.JMenu;
|
||||||
import javax.swing.JMenuItem;
|
import javax.swing.JMenuItem;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: FDA calls to .update -> requestUpdate()
|
* TODO: FDA calls to .update -> requestUpdate()
|
||||||
@@ -27,10 +28,15 @@ abstract public class LinePlotBase extends PlotBase<LinePlotSeries> implements L
|
|||||||
|
|
||||||
protected LinePlotBase(String title) {
|
protected LinePlotBase(String title) {
|
||||||
super(LinePlotSeries.class, title);
|
super(LinePlotSeries.class, title);
|
||||||
createAxis(AxisId.X, "X");
|
|
||||||
createAxis(AxisId.Y, "Y");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void createChart() {
|
||||||
|
super.createChart();
|
||||||
|
createAxis(AxisId.X, "X");
|
||||||
|
createAxis(AxisId.Y, "Y");
|
||||||
|
}
|
||||||
|
|
||||||
//TODO: Improve it to share the same X rows
|
//TODO: Improve it to share the same X rows
|
||||||
@Override
|
@Override
|
||||||
@@ -102,7 +108,8 @@ abstract public class LinePlotBase extends PlotBase<LinePlotSeries> implements L
|
|||||||
|
|
||||||
//Injecting specific entries in popup menu
|
//Injecting specific entries in popup menu
|
||||||
@Override
|
@Override
|
||||||
protected void onCreatedPanel() {
|
protected void createPopupMenu() {
|
||||||
|
super.createPopupMenu();
|
||||||
addPopupMenuItem(null);//Separator
|
addPopupMenuItem(null);//Separator
|
||||||
// Detach plot into a separate frame
|
// Detach plot into a separate frame
|
||||||
JMenu detachPlotMenu = new JMenu("Detach");
|
JMenu detachPlotMenu = new JMenu("Detach");
|
||||||
@@ -124,13 +131,13 @@ abstract public class LinePlotBase extends PlotBase<LinePlotSeries> implements L
|
|||||||
}
|
}
|
||||||
|
|
||||||
JFrame frame = new JFrame(getTitle());
|
JFrame frame = new JFrame(getTitle());
|
||||||
frame.setContentPane(p.getChartPanel());
|
frame.setContentPane((JPanel)p);
|
||||||
frame.pack();
|
frame.pack();
|
||||||
SwingUtils.centerOnScreen(frame);
|
SwingUtils.centerOnScreen(frame);
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
frame.requestFocus();
|
frame.requestFocus();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
SwingUtils.showException(getChartPanel(), ex);
|
SwingUtils.showException(LinePlotBase.this, ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
package ch.psi.plot;
|
package ch.psi.plot;
|
||||||
|
|
||||||
import ch.psi.plot.utils.SwingUtils;
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -17,11 +16,9 @@ public class LinePlotSeries extends PlotSeries<LinePlot> {
|
|||||||
|
|
||||||
void onSeriesAppendData(LinePlotSeries series, double x, double y);
|
void onSeriesAppendData(LinePlotSeries series, double x, double y);
|
||||||
}
|
}
|
||||||
|
|
||||||
public LinePlotSeries(String name) {
|
public LinePlotSeries(String name) {
|
||||||
//If create a random color in none is provided - but it is deterministic if name is provided
|
this(name, /*SwingUtils.generateRandomColor()*/ null);
|
||||||
this(name, ((name!=null)&& (name.length()>0)) ?
|
|
||||||
SwingUtils.generateRandomColor(name.hashCode()) :
|
|
||||||
SwingUtils.generateRandomColor());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public LinePlotSeries(String name, Color color) {
|
public LinePlotSeries(String name, Color color) {
|
||||||
|
|||||||
@@ -9,10 +9,10 @@ import ch.psi.plot.utils.SwingUtils;
|
|||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JMenu;
|
import javax.swing.JMenu;
|
||||||
import javax.swing.JMenuItem;
|
import javax.swing.JMenuItem;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -25,10 +25,15 @@ abstract public class MatrixPlotBase extends PlotBase<MatrixPlotSeries> implemen
|
|||||||
|
|
||||||
protected MatrixPlotBase(String title) {
|
protected MatrixPlotBase(String title) {
|
||||||
super(MatrixPlotSeries.class, title);
|
super(MatrixPlotSeries.class, title);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void createChart() {
|
||||||
|
super.createChart();
|
||||||
createAxis(AxisId.X, "X");
|
createAxis(AxisId.X, "X");
|
||||||
createAxis(AxisId.Y, "Y");
|
createAxis(AxisId.Y, "Y");
|
||||||
createAxis(AxisId.Z);
|
createAxis(AxisId.Z);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Only supporting one series for now so let's gain some speed
|
//Only supporting one series for now so let's gain some speed
|
||||||
@Override
|
@Override
|
||||||
@@ -98,7 +103,8 @@ abstract public class MatrixPlotBase extends PlotBase<MatrixPlotSeries> implemen
|
|||||||
|
|
||||||
//Injecting specific entries in popup menu
|
//Injecting specific entries in popup menu
|
||||||
@Override
|
@Override
|
||||||
protected void onCreatedPanel() {
|
protected void createPopupMenu() {
|
||||||
|
super.createPopupMenu();
|
||||||
addPopupMenuItem(null);//Separator
|
addPopupMenuItem(null);//Separator
|
||||||
// Detach plot into a separate frame
|
// Detach plot into a separate frame
|
||||||
JMenu detachPlotMenu = new JMenu("Detach");
|
JMenu detachPlotMenu = new JMenu("Detach");
|
||||||
@@ -123,12 +129,12 @@ abstract public class MatrixPlotBase extends PlotBase<MatrixPlotSeries> implemen
|
|||||||
detachedSeries.setData(s.getData());
|
detachedSeries.setData(s.getData());
|
||||||
|
|
||||||
JFrame frame = new JFrame(getTitle());
|
JFrame frame = new JFrame(getTitle());
|
||||||
frame.setContentPane(p.getChartPanel());
|
frame.setContentPane((JPanel)p);
|
||||||
frame.pack();
|
frame.pack();
|
||||||
SwingUtils.centerOnScreen(frame);
|
SwingUtils.centerOnScreen(frame);
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
SwingUtils.showException(getChartPanel(), ex);
|
SwingUtils.showException(MatrixPlotBase.this, ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -10,10 +10,8 @@ import javax.swing.JPanel;
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public interface Plot<T extends PlotSeries> {
|
public interface Plot<T extends PlotSeries>{
|
||||||
|
|
||||||
public JPanel getChartPanel();
|
|
||||||
|
|
||||||
//Request update on event loop
|
//Request update on event loop
|
||||||
public void update(boolean deferred);
|
public void update(boolean deferred);
|
||||||
|
|
||||||
@@ -32,6 +30,8 @@ public interface Plot<T extends PlotSeries> {
|
|||||||
public BufferedImage getSnapshot();
|
public BufferedImage getSnapshot();
|
||||||
|
|
||||||
public void saveSnapshot(String filename, String format) throws IOException;
|
public void saveSnapshot(String filename, String format) throws IOException;
|
||||||
|
|
||||||
|
public void copy();
|
||||||
|
|
||||||
//Series list management
|
//Series list management
|
||||||
public void addSeries(T series);
|
public void addSeries(T series);
|
||||||
|
|||||||
@@ -4,10 +4,25 @@
|
|||||||
package ch.psi.plot;
|
package ch.psi.plot;
|
||||||
|
|
||||||
import ch.psi.plot.utils.IO;
|
import ch.psi.plot.utils.IO;
|
||||||
|
import ch.psi.plot.utils.MonitoredPanel;
|
||||||
import ch.psi.plot.utils.SwingUtils;
|
import ch.psi.plot.utils.SwingUtils;
|
||||||
|
import ch.psi.plot.utils.SwingUtils.ExtensionFileFilter;
|
||||||
|
import ch.psi.plot.utils.SwingUtils.ImageTransferHandler;
|
||||||
|
import java.awt.Graphics;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.Toolkit;
|
||||||
|
import java.awt.datatransfer.Clipboard;
|
||||||
|
import java.awt.datatransfer.ClipboardOwner;
|
||||||
|
import java.awt.datatransfer.Transferable;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.geom.AffineTransform;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.awt.print.PageFormat;
|
||||||
|
import java.awt.print.Printable;
|
||||||
|
import java.awt.print.PrinterException;
|
||||||
|
import java.awt.print.PrinterJob;
|
||||||
|
import java.io.File;
|
||||||
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;
|
||||||
@@ -25,34 +40,48 @@ import javax.swing.filechooser.FileNameExtensionFilter;
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
abstract public class PlotBase<T extends PlotSeries> implements Plot<T> {
|
abstract public class PlotBase<T extends PlotSeries> extends MonitoredPanel implements Plot<T>, Printable {
|
||||||
|
|
||||||
final String LINE_SEPARATOR = System.lineSeparator();
|
final String LINE_SEPARATOR = System.lineSeparator();
|
||||||
final String FIELD_SEPARATOR = "\t";
|
final String FIELD_SEPARATOR = "\t";
|
||||||
|
|
||||||
protected static final int PREFERRED_WIDTH = 500;
|
protected static final int PREFERRED_WIDTH = 500;
|
||||||
protected static final int PREFERRED_HEIGHT = 270;
|
protected static final int PREFERRED_HEIGHT = 270;
|
||||||
|
|
||||||
|
|
||||||
final Class seriesType;
|
final Class seriesType;
|
||||||
|
|
||||||
protected PlotBase(Class<T> seriesType) {
|
protected PlotBase(Class<T> seriesType) {
|
||||||
this(seriesType, null);
|
this(seriesType, null);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
volatile boolean instantiated;
|
||||||
|
|
||||||
protected PlotBase(Class<T> seriesType, String title) {
|
protected PlotBase(Class<T> seriesType, String title) {
|
||||||
|
super();
|
||||||
if (title == null) {
|
if (title == null) {
|
||||||
title = "Plot";
|
title = "Plot";
|
||||||
}
|
}
|
||||||
setTitle(title);
|
setTitle(title);
|
||||||
this.seriesType = seriesType;
|
this.seriesType = seriesType;
|
||||||
|
// SwingUtilities.invokeLater(new Runnable() {
|
||||||
|
// @Override
|
||||||
|
// public void run() {
|
||||||
|
try {
|
||||||
|
createChart();
|
||||||
|
createPopupMenu();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
Logger.getLogger(PlotBase.class.getName()).log(Level.INFO, null, ex);
|
||||||
|
}
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
instantiated=true;
|
||||||
}
|
}
|
||||||
|
|
||||||
String title;
|
String title;
|
||||||
|
|
||||||
public void setTitle(String title) {
|
public void setTitle(String title) {
|
||||||
this.title = title;
|
this.title = title;
|
||||||
|
if (instantiated)
|
||||||
|
onTitleChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTitle() {
|
public String getTitle() {
|
||||||
@@ -109,77 +138,156 @@ abstract public class PlotBase<T extends PlotSeries> implements Plot<T> {
|
|||||||
* Should be improved in implementations to make it independent of the
|
* Should be improved in implementations to make it independent of the
|
||||||
* window state;
|
* window state;
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public BufferedImage getSnapshot() {
|
public BufferedImage getSnapshot() {
|
||||||
return SwingUtils.createImage(getChartPanel());
|
return SwingUtils.createImage(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void saveSnapshot(String filename, String format) throws IOException {
|
public void saveSnapshot(String filename, String format) throws IOException {
|
||||||
IO.writeImageToFile(getSnapshot(), filename, format);
|
IO.writeImageToFile(getSnapshot(), filename, format);
|
||||||
}
|
}
|
||||||
|
|
||||||
JPanel panel;
|
public void copy() {
|
||||||
|
BufferedImage img = getSnapshot();
|
||||||
public JPanel getChartPanel() {
|
if (img != null) {
|
||||||
if (panel == null) {
|
ImageTransferHandler imageSelection = new ImageTransferHandler(img);
|
||||||
panel = createChartPanel();
|
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
|
||||||
|
clipboard.setContents(imageSelection, new ClipboardOwner() {
|
||||||
addPopupMenuItem(null);//Separator
|
@Override
|
||||||
JMenuItem saveData = new JMenuItem("Save Data");
|
public void lostOwnership(Clipboard clipboard, Transferable contents) {
|
||||||
saveData.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
try {
|
|
||||||
JFileChooser chooser = new JFileChooser();
|
|
||||||
FileNameExtensionFilter filter = new FileNameExtensionFilter("Text data files", "txt", "dat");
|
|
||||||
chooser.setFileFilter(filter);
|
|
||||||
int returnVal = chooser.showSaveDialog(panel);
|
|
||||||
if (returnVal == JFileChooser.APPROVE_OPTION) {
|
|
||||||
String filename = chooser.getSelectedFile().getAbsolutePath();
|
|
||||||
String type = IO.getExtension(chooser.getSelectedFile());
|
|
||||||
if (type == null) {
|
|
||||||
type = "txt";
|
|
||||||
filename += "." + type;
|
|
||||||
}
|
|
||||||
saveData(filename);
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
SwingUtils.showException(panel, ex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
addPopupMenuItem(saveData);
|
|
||||||
JMenuItem saveSnapshot = new JMenuItem("Save Snapshot");
|
|
||||||
saveSnapshot.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
try {
|
|
||||||
JFileChooser chooser = new JFileChooser();
|
|
||||||
FileNameExtensionFilter filter = new FileNameExtensionFilter("Image File", "png", "jpg", "bmp");
|
|
||||||
chooser.setFileFilter(filter);
|
|
||||||
int returnVal = chooser.showSaveDialog(panel);
|
|
||||||
if (returnVal == JFileChooser.APPROVE_OPTION) {
|
|
||||||
String filename = chooser.getSelectedFile().getAbsolutePath();
|
|
||||||
String type = IO.getExtension(chooser.getSelectedFile());
|
|
||||||
if (type == null) {
|
|
||||||
type = "png";
|
|
||||||
filename += "." + type;
|
|
||||||
}
|
|
||||||
saveSnapshot(filename, type);
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
SwingUtils.showException(panel, ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
addPopupMenuItem(saveSnapshot);
|
|
||||||
onCreatedPanel();
|
|
||||||
}
|
}
|
||||||
return panel;
|
}
|
||||||
|
|
||||||
|
//Printable interface
|
||||||
|
public int print(Graphics g, PageFormat pf, int page) throws PrinterException {
|
||||||
|
|
||||||
|
if (page > 0) {
|
||||||
|
return NO_SUCH_PAGE;
|
||||||
|
}
|
||||||
|
|
||||||
|
BufferedImage img = getSnapshot();
|
||||||
|
|
||||||
|
//Schrinks the image if too big but does not expand it
|
||||||
|
double scaleX = img.getWidth()>pf.getImageableWidth() ? ((double) pf.getImageableWidth()) / img.getWidth() : 1.0;
|
||||||
|
double scaleY = img.getHeight() > pf.getImageableHeight() ? ((double) pf.getImageableHeight()) / img.getHeight() : 1.0;
|
||||||
|
double scale = Math.min(scaleX, scaleY); //Keep aspect ratio
|
||||||
|
AffineTransform transf = new AffineTransform();
|
||||||
|
transf.scale(scale, scale);
|
||||||
|
|
||||||
|
Graphics2D g2d = (Graphics2D) g;
|
||||||
|
g2d.translate(pf.getImageableX(), pf.getImageableY());
|
||||||
|
g2d.drawImage(img, transf, null);
|
||||||
|
//g2d.drawImage(img,0,0,null);
|
||||||
|
return PAGE_EXISTS;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Overidables
|
protected void createChart() {
|
||||||
protected void onCreatedPanel() {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract protected JPanel createChartPanel();
|
protected void createPopupMenu() {
|
||||||
|
addPopupMenuItem(null);//Separator
|
||||||
|
|
||||||
|
JMenuItem saveSnapshot = new JMenuItem("Save Image As...");
|
||||||
|
saveSnapshot.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
JFileChooser chooser = new JFileChooser(".");
|
||||||
|
chooser.addChoosableFileFilter(new ExtensionFileFilter("PNG files (*.png)", new String[]{"png"}));
|
||||||
|
chooser.addChoosableFileFilter(new ExtensionFileFilter("Bitmap files (*.bmp)", new String[]{"bmp"}));
|
||||||
|
chooser.addChoosableFileFilter(new ExtensionFileFilter("JPEG files (*.jpg)", new String[]{"jpg", "jpeg"}));
|
||||||
|
chooser.setAcceptAllFileFilterUsed(false);
|
||||||
|
if (chooser.showSaveDialog(PlotBase.this) == JFileChooser.APPROVE_OPTION) {
|
||||||
|
|
||||||
|
String filename = chooser.getSelectedFile().getAbsolutePath();
|
||||||
|
String type = "png";
|
||||||
|
String ext = IO.getExtension(chooser.getSelectedFile());
|
||||||
|
for (String fe : new String[]{"bmp", "jpg"}) {
|
||||||
|
if ((chooser.getFileFilter().getDescription().contains(fe))
|
||||||
|
|| (fe.equals(ext))) {
|
||||||
|
type = fe;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ext == null) {
|
||||||
|
filename += "." + type;
|
||||||
|
}
|
||||||
|
if (new File(filename).exists()) {
|
||||||
|
if (SwingUtils.showOption(PlotBase.this, "Overwrite", "File " + filename + " already exists.\nDo you want to overwrite it?", javax.swing.JOptionPane.YES_NO_OPTION) == javax.swing.JOptionPane.NO_OPTION) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
saveSnapshot(filename, type);
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
SwingUtils.showException(PlotBase.this, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
addPopupMenuItem(saveSnapshot);
|
||||||
|
|
||||||
|
JMenuItem saveData = new JMenuItem("Save Data As...");
|
||||||
|
saveData.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
try {
|
||||||
|
JFileChooser chooser = new JFileChooser();
|
||||||
|
FileNameExtensionFilter filter = new FileNameExtensionFilter("Text data files", "txt", "dat");
|
||||||
|
chooser.setFileFilter(filter);
|
||||||
|
int returnVal = chooser.showSaveDialog(PlotBase.this);
|
||||||
|
if (returnVal == JFileChooser.APPROVE_OPTION) {
|
||||||
|
String filename = chooser.getSelectedFile().getAbsolutePath();
|
||||||
|
String type = IO.getExtension(chooser.getSelectedFile());
|
||||||
|
if (type == null) {
|
||||||
|
type = "txt";
|
||||||
|
filename += "." + type;
|
||||||
|
}
|
||||||
|
saveData(filename);
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
SwingUtils.showException(PlotBase.this, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
addPopupMenuItem(saveData);
|
||||||
|
|
||||||
|
JMenuItem print = new JMenuItem("Print...");
|
||||||
|
print.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
try {
|
||||||
|
PrinterJob job = PrinterJob.getPrinterJob();
|
||||||
|
job.setPrintable(PlotBase.this);
|
||||||
|
|
||||||
|
PrinterJob pj = PrinterJob.getPrinterJob();
|
||||||
|
//PageFormat pdef=pj.defaultPage();
|
||||||
|
//PageFormat pf = pj.pageDialog(pdef);
|
||||||
|
//if (pf!=pdef){
|
||||||
|
if (job.printDialog()) {
|
||||||
|
job.print();
|
||||||
|
}
|
||||||
|
//}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
SwingUtils.showException(PlotBase.this, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
addPopupMenuItem(print);
|
||||||
|
|
||||||
|
JMenuItem copy = new JMenuItem("Copy");
|
||||||
|
copy.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
try {
|
||||||
|
copy();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
SwingUtils.showException(PlotBase.this, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
addPopupMenuItem(copy);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* null for separator
|
* null for separator
|
||||||
@@ -188,7 +296,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;
|
volatile int seriesID = 1;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addSeries(T series) {
|
public void addSeries(T series) {
|
||||||
@@ -206,7 +314,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.id = seriesID++;
|
||||||
series.setToken(onAddedSeries(series));
|
series.setToken(onAddedSeries(series));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,7 +327,7 @@ abstract public class PlotBase<T extends PlotSeries> implements Plot<T> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeSeries(T series) {
|
public void removeSeries(T series) {
|
||||||
if (series!=null){
|
if (series != null) {
|
||||||
if (series.getPlot() == this) {
|
if (series.getPlot() == this) {
|
||||||
series.setPlot(null);
|
series.setPlot(null);
|
||||||
}
|
}
|
||||||
@@ -253,12 +361,13 @@ abstract public class PlotBase<T extends PlotSeries> implements Plot<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public class SeriesComparator implements Comparator<T> {
|
public class SeriesComparator implements Comparator<T> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compare(T o1, T o2) {
|
public int compare(T o1, T o2) {
|
||||||
return Integer.valueOf(o1.id).compareTo(Integer.valueOf(o2.id));
|
return Integer.valueOf(o1.id).compareTo(Integer.valueOf(o2.id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public T[] getAllSeries() {
|
public T[] getAllSeries() {
|
||||||
synchronized (seriesList) {
|
synchronized (seriesList) {
|
||||||
@@ -333,6 +442,12 @@ abstract public class PlotBase<T extends PlotSeries> implements Plot<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Axis Callbacks
|
//Axis Callbacks
|
||||||
|
protected void onTitleChanged() {
|
||||||
|
if (isUpdatesEnabled()) {
|
||||||
|
doUpdate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected void onAxisLabelChanged(AxisId axis) {
|
protected void onAxisLabelChanged(AxisId axis) {
|
||||||
if (isUpdatesEnabled()) {
|
if (isUpdatesEnabled()) {
|
||||||
doUpdate();
|
doUpdate();
|
||||||
@@ -343,29 +458,30 @@ abstract public class PlotBase<T extends PlotSeries> implements Plot<T> {
|
|||||||
if (isUpdatesEnabled()) {
|
if (isUpdatesEnabled()) {
|
||||||
doUpdate();
|
doUpdate();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
//Static Configuration
|
|
||||||
|
|
||||||
//Hardware Acceleration
|
|
||||||
static boolean hardwareAccelerated=true;
|
|
||||||
public static void setHardwareAccelerated(boolean value){
|
|
||||||
hardwareAccelerated=value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean getHardwareAccelerated(){
|
|
||||||
return hardwareAccelerated;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean lighweightPopups=true;
|
//Static Configuration
|
||||||
public static void setLighweightPopups(boolean value){
|
//Hardware Acceleration
|
||||||
lighweightPopups=value;
|
static boolean hardwareAccelerated = true;
|
||||||
if (javax.swing.JPopupMenu.getDefaultLightWeightPopupEnabled()!=value){
|
|
||||||
|
public static void setHardwareAccelerated(boolean value) {
|
||||||
|
hardwareAccelerated = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean getHardwareAccelerated() {
|
||||||
|
return hardwareAccelerated;
|
||||||
|
}
|
||||||
|
|
||||||
|
static boolean lighweightPopups = true;
|
||||||
|
|
||||||
|
public static void setLighweightPopups(boolean value) {
|
||||||
|
lighweightPopups = value;
|
||||||
|
if (javax.swing.JPopupMenu.getDefaultLightWeightPopupEnabled() != value) {
|
||||||
javax.swing.JPopupMenu.setDefaultLightWeightPopupEnabled(lighweightPopups);
|
javax.swing.JPopupMenu.setDefaultLightWeightPopupEnabled(lighweightPopups);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean getLighweightPopups(){
|
public static boolean getLighweightPopups() {
|
||||||
return lighweightPopups;
|
return lighweightPopups;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,6 @@ import javafx.scene.paint.Color;
|
|||||||
import javafx.scene.shape.Rectangle;
|
import javafx.scene.shape.Rectangle;
|
||||||
import javax.swing.JMenu;
|
import javax.swing.JMenu;
|
||||||
import javax.swing.JMenuItem;
|
import javax.swing.JMenuItem;
|
||||||
import javax.swing.JPanel;
|
|
||||||
import javax.swing.JPopupMenu;
|
import javax.swing.JPopupMenu;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -55,10 +54,55 @@ public class LinePlot extends ch.psi.plot.LinePlotBase {
|
|||||||
|
|
||||||
public LinePlot() {
|
public LinePlot() {
|
||||||
super();
|
super();
|
||||||
createChart();
|
|
||||||
setRequireUpdateOnAppend(false);
|
setRequireUpdateOnAppend(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void onTitleChanged() {
|
||||||
|
Platform.runLater(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
chart.setId(getTitle());
|
||||||
|
chart.setTitle(getTitle());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void onAxisLabelChanged(final AxisId axis) {
|
||||||
|
//TODO
|
||||||
|
/*
|
||||||
|
Platform.runLater(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
switch (axis){
|
||||||
|
case X:
|
||||||
|
break;
|
||||||
|
case Y:
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onAxisRangeChanged(AxisId axis_id) {
|
||||||
|
NumberAxis axis = null;
|
||||||
|
switch (axis_id) {
|
||||||
|
case X:
|
||||||
|
axis = (NumberAxis) chart.getXAxis();
|
||||||
|
break;
|
||||||
|
case Y:
|
||||||
|
axis = (NumberAxis) chart.getYAxis();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
axis.setAutoRanging(getAxis(axis_id).isAutoRange());
|
||||||
|
axis.setLowerBound(getAxis(axis_id).getMin());
|
||||||
|
axis.setUpperBound(getAxis(axis_id).getMax());
|
||||||
|
}
|
||||||
|
|
||||||
final LinkedHashMap<XYChart.Series, ConcurrentLinkedQueue<Data<Number, Number>>> seriesList = new LinkedHashMap<>();
|
final LinkedHashMap<XYChart.Series, ConcurrentLinkedQueue<Data<Number, Number>>> seriesList = new LinkedHashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -153,11 +197,33 @@ public class LinePlot extends ch.psi.plot.LinePlotBase {
|
|||||||
private JFXPanel fxContainer;
|
private JFXPanel fxContainer;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected JPanel createChartPanel() {
|
protected void createChart() {
|
||||||
|
super.createChart();
|
||||||
|
|
||||||
|
fxContainer = new JFXPanel(); //Must do bedore any JavaFX call
|
||||||
|
//xAxis = new NumberAxis(lower,upper,tick);
|
||||||
|
NumberAxis xAxis = new NumberAxis();
|
||||||
|
xAxis.setForceZeroInRange(false);
|
||||||
|
xAxis.setAutoRanging(true);
|
||||||
|
|
||||||
|
xAxis.setTickLabelsVisible(true);
|
||||||
|
xAxis.setTickMarkVisible(true);
|
||||||
|
xAxis.setMinorTickVisible(true);
|
||||||
|
|
||||||
|
NumberAxis yAxis = new NumberAxis();
|
||||||
|
yAxis.setForceZeroInRange(false);
|
||||||
|
yAxis.setAutoRanging(true);
|
||||||
|
|
||||||
|
chart = new MyLineChart<>(xAxis, yAxis);
|
||||||
|
chart.setAnimated(false);
|
||||||
|
chart.setCreateSymbols(false);
|
||||||
|
chart.setCursor(Cursor.CROSSHAIR);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fxContainer.setPreferredSize(new Dimension(PREFERRED_WIDTH, PREFERRED_HEIGHT));
|
fxContainer.setPreferredSize(new Dimension(PREFERRED_WIDTH, PREFERRED_HEIGHT));
|
||||||
JPanel panel = new JPanel();
|
setLayout(new BorderLayout());
|
||||||
panel.setLayout(new BorderLayout());
|
add(fxContainer);
|
||||||
panel.add(fxContainer);
|
|
||||||
// create JavaFX scene
|
// create JavaFX scene
|
||||||
Platform.runLater(new Runnable() {
|
Platform.runLater(new Runnable() {
|
||||||
|
|
||||||
@@ -166,7 +232,6 @@ public class LinePlot extends ch.psi.plot.LinePlotBase {
|
|||||||
createScene();
|
createScene();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return panel;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyLineChart<X extends Object, Y extends Object> extends LineChart<X, Y> {
|
class MyLineChart<X extends Object, Y extends Object> extends LineChart<X, Y> {
|
||||||
@@ -232,28 +297,6 @@ public class LinePlot extends ch.psi.plot.LinePlotBase {
|
|||||||
return drawSymbols;
|
return drawSymbols;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createChart() {
|
|
||||||
fxContainer = new JFXPanel(); //Must do bedore any JavaFX call
|
|
||||||
//xAxis = new NumberAxis(lower,upper,tick);
|
|
||||||
NumberAxis xAxis = new NumberAxis();
|
|
||||||
xAxis.setForceZeroInRange(false);
|
|
||||||
xAxis.setAutoRanging(true);
|
|
||||||
|
|
||||||
xAxis.setTickLabelsVisible(true);
|
|
||||||
xAxis.setTickMarkVisible(true);
|
|
||||||
xAxis.setMinorTickVisible(true);
|
|
||||||
|
|
||||||
NumberAxis yAxis = new NumberAxis();
|
|
||||||
yAxis.setForceZeroInRange(false);
|
|
||||||
yAxis.setAutoRanging(true);
|
|
||||||
|
|
||||||
//-- Chart
|
|
||||||
chart = new MyLineChart<>(xAxis, yAxis);
|
|
||||||
chart.setAnimated(false);
|
|
||||||
chart.setCreateSymbols(false);
|
|
||||||
chart.setCursor(Cursor.CROSSHAIR);
|
|
||||||
}
|
|
||||||
|
|
||||||
Rectangle zoomRect;
|
Rectangle zoomRect;
|
||||||
|
|
||||||
private void createScene() {
|
private void createScene() {
|
||||||
@@ -524,24 +567,6 @@ public class LinePlot extends ch.psi.plot.LinePlotBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onAxisRangeChanged(AxisId axis_id) {
|
|
||||||
NumberAxis axis = null;
|
|
||||||
switch (axis_id) {
|
|
||||||
case X:
|
|
||||||
axis = (NumberAxis) chart.getXAxis();
|
|
||||||
break;
|
|
||||||
case Y:
|
|
||||||
axis = (NumberAxis) chart.getYAxis();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
axis.setAutoRanging(getAxis(axis_id).isAutoRange());
|
|
||||||
axis.setLowerBound(getAxis(axis_id).getMin());
|
|
||||||
axis.setUpperBound(getAxis(axis_id).getMax());
|
|
||||||
}
|
|
||||||
|
|
||||||
ContextMenu contextMenu;
|
ContextMenu contextMenu;
|
||||||
|
|
||||||
public void setUpContextMenu() {
|
public void setUpContextMenu() {
|
||||||
|
|||||||
@@ -3,10 +3,15 @@ package ch.psi.plot.jfree;
|
|||||||
import ch.psi.plot.LinePlotBase;
|
import ch.psi.plot.LinePlotBase;
|
||||||
import ch.psi.plot.LinePlotSeries;
|
import ch.psi.plot.LinePlotSeries;
|
||||||
import java.awt.BasicStroke;
|
import java.awt.BasicStroke;
|
||||||
|
import java.awt.BorderLayout;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
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.KeyEvent;
|
import java.awt.event.KeyEvent;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.awt.print.PageFormat;
|
||||||
|
import java.awt.print.PrinterException;
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -16,7 +21,6 @@ import javax.swing.JComponent;
|
|||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JMenu;
|
import javax.swing.JMenu;
|
||||||
import javax.swing.JMenuItem;
|
import javax.swing.JMenuItem;
|
||||||
import javax.swing.JPanel;
|
|
||||||
import javax.swing.KeyStroke;
|
import javax.swing.KeyStroke;
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
import org.jfree.chart.ChartFactory;
|
import org.jfree.chart.ChartFactory;
|
||||||
@@ -65,8 +69,7 @@ public class LinePlot extends LinePlotBase {
|
|||||||
* @param title Title of plot
|
* @param title Title of plot
|
||||||
*/
|
*/
|
||||||
public LinePlot() {
|
public LinePlot() {
|
||||||
super();
|
super();
|
||||||
data = new XYSeriesCollection();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -152,7 +155,10 @@ public class LinePlot extends LinePlotBase {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected JPanel createChartPanel() {
|
protected void createChart() {
|
||||||
|
super.createChart();
|
||||||
|
|
||||||
|
data = new XYSeriesCollection();
|
||||||
// Create chart
|
// Create chart
|
||||||
chart = ChartFactory.createXYLineChart(getTitle(), getAxis(AxisId.X).getLabel(), getAxis(AxisId.Y).getLabel(), data, PlotOrientation.VERTICAL, true, tooltips, false);
|
chart = ChartFactory.createXYLineChart(getTitle(), getAxis(AxisId.X).getLabel(), getAxis(AxisId.Y).getLabel(), data, PlotOrientation.VERTICAL, true, tooltips, false);
|
||||||
|
|
||||||
@@ -178,23 +184,61 @@ public class LinePlot extends LinePlotBase {
|
|||||||
((NumberAxis) plot.getRangeAxis()).setAutoRangeIncludesZero(false);
|
((NumberAxis) plot.getRangeAxis()).setAutoRangeIncludesZero(false);
|
||||||
|
|
||||||
// Lazy creation of the chart panel
|
// Lazy creation of the chart panel
|
||||||
chartPanel = new ChartPanel(chart);
|
chartPanel = new ChartPanel(chart);
|
||||||
chartPanel.setName(getTitle());
|
|
||||||
|
|
||||||
// Remove border
|
// Remove border
|
||||||
chartPanel.getChart().setBorderVisible(false);
|
chartPanel.getChart().setBorderVisible(false);
|
||||||
|
|
||||||
// Set size of chart
|
// Set size of chart
|
||||||
chartPanel.setPreferredSize(new java.awt.Dimension(PREFERRED_WIDTH, PREFERRED_HEIGHT));
|
chartPanel.setPreferredSize(new java.awt.Dimension(PREFERRED_WIDTH, PREFERRED_HEIGHT));
|
||||||
|
|
||||||
// Add more items to the context menu
|
|
||||||
amendContextMenu();
|
|
||||||
|
|
||||||
//Activate (arrow) keys
|
//Activate (arrow) keys
|
||||||
addKeyBindings();
|
addKeyBindings();
|
||||||
return chartPanel;
|
|
||||||
|
setLayout(new BorderLayout());
|
||||||
|
add(chartPanel);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onTitleChanged() {
|
||||||
|
chartPanel.setName(getTitle());
|
||||||
|
chart.setTitle(getTitle());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onAxisLabelChanged(AxisId axis) {
|
||||||
|
switch (axis){
|
||||||
|
case X:
|
||||||
|
chart.getXYPlot().getDomainAxis().setLabel(getAxis(AxisId.X).getLabel());
|
||||||
|
break;
|
||||||
|
case Y:
|
||||||
|
chart.getXYPlot().getRangeAxis().setLabel(getAxis(AxisId.Y).getLabel());
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onAxisRangeChanged(AxisId axis_id) {
|
||||||
|
ValueAxis axis = null;
|
||||||
|
|
||||||
|
switch (axis_id) {
|
||||||
|
case X:
|
||||||
|
axis = chart.getXYPlot().getDomainAxis();
|
||||||
|
break;
|
||||||
|
case Y:
|
||||||
|
axis = chart.getXYPlot().getRangeAxis();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (getAxis(axis_id).isAutoRange()) {
|
||||||
|
axis.setAutoRange(true);
|
||||||
|
} else {
|
||||||
|
axis.setRange(new Range(getAxis(axis_id).getMin(), getAxis(axis_id).getMax()), true, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Change visible part of chart
|
* Change visible part of chart
|
||||||
*
|
*
|
||||||
@@ -273,33 +317,15 @@ public class LinePlot extends LinePlotBase {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onAxisRangeChanged(AxisId axis_id) {
|
|
||||||
ValueAxis axis = null;
|
|
||||||
|
|
||||||
switch (axis_id) {
|
|
||||||
case X:
|
|
||||||
axis = chart.getXYPlot().getDomainAxis();
|
|
||||||
break;
|
|
||||||
case Y:
|
|
||||||
axis = chart.getXYPlot().getRangeAxis();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (getAxis(axis_id).isAutoRange()) {
|
|
||||||
axis.setAutoRange(true);
|
|
||||||
} else {
|
|
||||||
axis.setRange(new Range(getAxis(axis_id).getMin(), getAxis(axis_id).getMax()), true, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add additional items to the context menu of the plot
|
* Add additional items to the context menu of the plot
|
||||||
*/
|
*/
|
||||||
public void amendContextMenu() {
|
@Override
|
||||||
|
protected void createPopupMenu() {
|
||||||
chartPanel.getPopupMenu().addSeparator();
|
//Remove copy/save as/print menus: copy is buggy, save is limited
|
||||||
|
for (int index=6;index>=2;index--)
|
||||||
|
chartPanel.getPopupMenu().remove(index);
|
||||||
|
|
||||||
|
|
||||||
JMenu toolsMenu = new JMenu("Tools");
|
JMenu toolsMenu = new JMenu("Tools");
|
||||||
chartPanel.getPopupMenu().add(toolsMenu);
|
chartPanel.getPopupMenu().add(toolsMenu);
|
||||||
@@ -394,7 +420,7 @@ public class LinePlot extends LinePlotBase {
|
|||||||
dseries.setData(derivative[0], derivative[1]);
|
dseries.setData(derivative[0], derivative[1]);
|
||||||
}
|
}
|
||||||
JFrame frame = new JFrame();
|
JFrame frame = new JFrame();
|
||||||
frame.setContentPane(p.getChartPanel());
|
frame.setContentPane(p);
|
||||||
frame.pack();
|
frame.pack();
|
||||||
RefineryUtilities.centerFrameOnScreen(frame);
|
RefineryUtilities.centerFrameOnScreen(frame);
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
@@ -417,7 +443,7 @@ public class LinePlot extends LinePlotBase {
|
|||||||
dseries.setData(integral[0], integral[1]);
|
dseries.setData(integral[0], integral[1]);
|
||||||
}
|
}
|
||||||
JFrame frame = new JFrame();
|
JFrame frame = new JFrame();
|
||||||
frame.setContentPane(p.getChartPanel());
|
frame.setContentPane(p);
|
||||||
frame.pack();
|
frame.pack();
|
||||||
RefineryUtilities.centerFrameOnScreen(frame);
|
RefineryUtilities.centerFrameOnScreen(frame);
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
@@ -441,7 +467,7 @@ public class LinePlot extends LinePlotBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
JFrame frame = new JFrame();
|
JFrame frame = new JFrame();
|
||||||
frame.setContentPane(p.getChartPanel());
|
frame.setContentPane(p);
|
||||||
frame.pack();
|
frame.pack();
|
||||||
RefineryUtilities.centerFrameOnScreen(frame);
|
RefineryUtilities.centerFrameOnScreen(frame);
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
@@ -487,7 +513,7 @@ public class LinePlot extends LinePlotBase {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
chartPanel.getPopupMenu().add(hideToolTipsMenuItem);
|
chartPanel.getPopupMenu().add(hideToolTipsMenuItem);
|
||||||
|
super.createPopupMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showTooltips() {
|
private void showTooltips() {
|
||||||
@@ -540,4 +566,9 @@ public class LinePlot extends LinePlotBase {
|
|||||||
this.data = (XYSeriesCollection) data;
|
this.data = (XYSeriesCollection) data;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int print(Graphics g, PageFormat pf, int page) throws PrinterException {
|
||||||
|
return chartPanel.print(g, pf, page);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,15 +2,18 @@ package ch.psi.plot.jfree;
|
|||||||
|
|
||||||
import ch.psi.plot.MatrixPlotBase;
|
import ch.psi.plot.MatrixPlotBase;
|
||||||
import ch.psi.plot.MatrixPlotSeries;
|
import ch.psi.plot.MatrixPlotSeries;
|
||||||
|
import java.awt.BorderLayout;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
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.print.PageFormat;
|
||||||
|
import java.awt.print.PrinterException;
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import javax.swing.JMenu;
|
import javax.swing.JMenu;
|
||||||
import javax.swing.JMenuItem;
|
import javax.swing.JMenuItem;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
import javax.swing.JPanel;
|
|
||||||
import org.jfree.chart.ChartPanel;
|
import org.jfree.chart.ChartPanel;
|
||||||
import org.jfree.chart.JFreeChart;
|
import org.jfree.chart.JFreeChart;
|
||||||
import org.jfree.chart.axis.NumberAxis;
|
import org.jfree.chart.axis.NumberAxis;
|
||||||
@@ -53,54 +56,11 @@ public class MatrixPlot extends MatrixPlotBase {
|
|||||||
* @param data
|
* @param data
|
||||||
*/
|
*/
|
||||||
XYPlot plot;
|
XYPlot plot;
|
||||||
final NumberAxis xAxis, yAxis;
|
NumberAxis xAxis, yAxis;
|
||||||
final XYBlockRenderer renderer;
|
XYBlockRenderer renderer;
|
||||||
|
|
||||||
public MatrixPlot() {
|
public MatrixPlot() {
|
||||||
super();
|
super();
|
||||||
// Create matrix chart
|
|
||||||
// Init size of plot area according to min and max set in the datas metadata
|
|
||||||
// Set axis: (plus half bin size on both sides), since we plot the bins centered.
|
|
||||||
xAxis = new NumberAxis("");
|
|
||||||
yAxis = new NumberAxis("");
|
|
||||||
|
|
||||||
// Configure block renderer to have the blocks rendered in the correct size
|
|
||||||
renderer = new XYBlockRenderer();
|
|
||||||
renderer.setBaseCreateEntities(false);
|
|
||||||
plot = new XYPlot(null, xAxis, yAxis, renderer);
|
|
||||||
|
|
||||||
// Remove background paint/color
|
|
||||||
plot.setBackgroundPaint(null);
|
|
||||||
|
|
||||||
// Set the maximum zoom out to the initial zoom rate This also
|
|
||||||
// provides a workaround for dynamic plots because there zoom out does not work correctly (zoom out to infinity)
|
|
||||||
plot.getRangeAxis().addChangeListener(new AxisChangeListener() {
|
|
||||||
@Override
|
|
||||||
public void axisChanged(AxisChangeEvent event) {
|
|
||||||
if (series == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ValueAxis axis = ((ValueAxis) event.getAxis());
|
|
||||||
if (axis.getLowerBound() < yMin || axis.getUpperBound() > yMax) {
|
|
||||||
Range range = new Range(yMin, yMax);
|
|
||||||
axis.setRange(range, true, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
plot.getDomainAxis().addChangeListener(new AxisChangeListener() {
|
|
||||||
@Override
|
|
||||||
public void axisChanged(AxisChangeEvent event) {
|
|
||||||
if (series == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ValueAxis axis = ((ValueAxis) event.getAxis());
|
|
||||||
if (axis.getLowerBound() < xMin || axis.getUpperBound() > xMax) {
|
|
||||||
Range range = new Range(xMin, xMax);
|
|
||||||
axis.setRange(range, true, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
double xMin, xMax, yMin, yMax;
|
double xMin, xMax, yMin, yMax;
|
||||||
@@ -122,8 +82,6 @@ public class MatrixPlot extends MatrixPlotBase {
|
|||||||
|
|
||||||
onAxisRangeChanged(AxisId.X);
|
onAxisRangeChanged(AxisId.X);
|
||||||
onAxisRangeChanged(AxisId.Y);
|
onAxisRangeChanged(AxisId.Y);
|
||||||
xAxis.setLabel(getAxis(AxisId.X).getLabel());
|
|
||||||
yAxis.setLabel(getAxis(AxisId.Y).getLabel());
|
|
||||||
|
|
||||||
renderer.setBlockWidth(series.getBinWidthX()); // If this is not set the default block size is 1
|
renderer.setBlockWidth(series.getBinWidthX()); // If this is not set the default block size is 1
|
||||||
renderer.setBlockHeight(series.getBinWidthY()); // If this is not set the default block size is 1
|
renderer.setBlockHeight(series.getBinWidthY()); // If this is not set the default block size is 1
|
||||||
@@ -136,6 +94,27 @@ public class MatrixPlot extends MatrixPlotBase {
|
|||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onTitleChanged() {
|
||||||
|
chartPanel.setName(getTitle());
|
||||||
|
chart.setTitle(getTitle());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onAxisLabelChanged(AxisId axis) {
|
||||||
|
switch (axis) {
|
||||||
|
case X:
|
||||||
|
xAxis.setLabel(getAxis(AxisId.X).getLabel());
|
||||||
|
break;
|
||||||
|
case Y:
|
||||||
|
yAxis.setLabel(getAxis(AxisId.Y).getLabel());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onAxisRangeChanged(AxisId axis_id) {
|
protected void onAxisRangeChanged(AxisId axis_id) {
|
||||||
@@ -215,11 +194,11 @@ public class MatrixPlot extends MatrixPlotBase {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Action Classes that implement methods called after keyboard input
|
@Override
|
||||||
/**
|
protected void createPopupMenu() {
|
||||||
* Adapt the context menu of the chart panel
|
//Remove copy/save as/print menus: copy is buggy, save is limited
|
||||||
*/
|
for (int index=6;index>=2;index--)
|
||||||
private void adaptContextMenu(final ChartPanel chartPanel) {
|
chartPanel.getPopupMenu().remove(index);
|
||||||
|
|
||||||
// Show hide tooltips
|
// Show hide tooltips
|
||||||
final String tooltipsMenuLabel = "Tooltips";
|
final String tooltipsMenuLabel = "Tooltips";
|
||||||
@@ -310,7 +289,7 @@ public class MatrixPlot extends MatrixPlotBase {
|
|||||||
|
|
||||||
final JFrame frame = new JFrame(title);
|
final JFrame frame = new JFrame(title);
|
||||||
frame.getContentPane();
|
frame.getContentPane();
|
||||||
frame.setContentPane(p.getChartPanel());
|
frame.setContentPane(p);
|
||||||
frame.pack();
|
frame.pack();
|
||||||
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); // Close application if frame is closed
|
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); // Close application if frame is closed
|
||||||
|
|
||||||
@@ -326,6 +305,7 @@ public class MatrixPlot extends MatrixPlotBase {
|
|||||||
});
|
});
|
||||||
chartPanel.getPopupMenu().add(contextMenuItemDetach);
|
chartPanel.getPopupMenu().add(contextMenuItemDetach);
|
||||||
*/
|
*/
|
||||||
|
super.createPopupMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -357,9 +337,11 @@ public class MatrixPlot extends MatrixPlotBase {
|
|||||||
* is created
|
* is created
|
||||||
*/
|
*/
|
||||||
public void adaptColorMapScale() {
|
public void adaptColorMapScale() {
|
||||||
double[] v = series.minMaxZValue();
|
if (series!=null){
|
||||||
if (v[0] != Double.NaN && v[1] != Double.NaN && v[0] < v[1]) {
|
double[] v = series.minMaxZValue();
|
||||||
setColorScale(v[0], v[1]);
|
if (v[0] != Double.NaN && v[1] != Double.NaN && v[0] < v[1]) {
|
||||||
|
setColorScale(v[0], v[1]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -431,7 +413,53 @@ public class MatrixPlot extends MatrixPlotBase {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected JPanel createChartPanel() {
|
protected void createChart() {
|
||||||
|
super.createChart();
|
||||||
|
|
||||||
|
// Create matrix chart
|
||||||
|
// Init size of plot area according to min and max set in the datas metadata
|
||||||
|
// Set axis: (plus half bin size on both sides), since we plot the bins centered.
|
||||||
|
xAxis = new NumberAxis("");
|
||||||
|
yAxis = new NumberAxis("");
|
||||||
|
|
||||||
|
// Configure block renderer to have the blocks rendered in the correct size
|
||||||
|
renderer = new XYBlockRenderer();
|
||||||
|
renderer.setBaseCreateEntities(false);
|
||||||
|
plot = new XYPlot(null, xAxis, yAxis, renderer);
|
||||||
|
|
||||||
|
// Remove background paint/color
|
||||||
|
plot.setBackgroundPaint(null);
|
||||||
|
|
||||||
|
// Set the maximum zoom out to the initial zoom rate This also
|
||||||
|
// provides a workaround for dynamic plots because there zoom out does not work correctly (zoom out to infinity)
|
||||||
|
plot.getRangeAxis().addChangeListener(new AxisChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void axisChanged(AxisChangeEvent event) {
|
||||||
|
if (series == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ValueAxis axis = ((ValueAxis) event.getAxis());
|
||||||
|
if (axis.getLowerBound() < yMin || axis.getUpperBound() > yMax) {
|
||||||
|
Range range = new Range(yMin, yMax);
|
||||||
|
axis.setRange(range, true, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
plot.getDomainAxis().addChangeListener(new AxisChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void axisChanged(AxisChangeEvent event) {
|
||||||
|
if (series == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ValueAxis axis = ((ValueAxis) event.getAxis());
|
||||||
|
if (axis.getLowerBound() < xMin || axis.getUpperBound() > xMax) {
|
||||||
|
Range range = new Range(xMin, xMax);
|
||||||
|
axis.setRange(range, true, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
chart = new JFreeChart(getTitle(), plot);
|
chart = new JFreeChart(getTitle(), plot);
|
||||||
|
|
||||||
//Remove the series label (also called legend)
|
//Remove the series label (also called legend)
|
||||||
@@ -447,10 +475,8 @@ public class MatrixPlot extends MatrixPlotBase {
|
|||||||
|
|
||||||
chartPanel.setPreferredSize(new java.awt.Dimension(PREFERRED_WIDTH, PREFERRED_HEIGHT));
|
chartPanel.setPreferredSize(new java.awt.Dimension(PREFERRED_WIDTH, PREFERRED_HEIGHT));
|
||||||
|
|
||||||
//All interactive menu items
|
setLayout(new BorderLayout());
|
||||||
adaptContextMenu(chartPanel);
|
add(chartPanel); }
|
||||||
return chartPanel;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see ch.psi.plot.Plot#update()
|
* @see ch.psi.plot.Plot#update()
|
||||||
@@ -475,6 +501,12 @@ public class MatrixPlot extends MatrixPlotBase {
|
|||||||
chartPanel.getPopupMenu().add(item);
|
chartPanel.getPopupMenu().add(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int print(Graphics g, PageFormat pf, int page) throws PrinterException {
|
||||||
|
return chartPanel.print(g, pf, page);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//public JFreeChart getChart() {
|
//public JFreeChart getChart() {
|
||||||
// return chart;
|
// return chart;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ package ch.psi.plot.jlchart;
|
|||||||
|
|
||||||
import ch.psi.plot.LinePlotBase;
|
import ch.psi.plot.LinePlotBase;
|
||||||
import ch.psi.plot.LinePlotSeries;
|
import ch.psi.plot.LinePlotSeries;
|
||||||
import ch.psi.plot.utils.MonitoredPanel;
|
import ch.psi.plot.utils.SwingUtils;
|
||||||
import fr.esrf.tangoatk.widget.util.chart.DataList;
|
import fr.esrf.tangoatk.widget.util.chart.DataList;
|
||||||
import fr.esrf.tangoatk.widget.util.chart.JLAxis;
|
import fr.esrf.tangoatk.widget.util.chart.JLAxis;
|
||||||
import fr.esrf.tangoatk.widget.util.chart.JLChart;
|
import fr.esrf.tangoatk.widget.util.chart.JLChart;
|
||||||
@@ -14,75 +14,51 @@ import java.awt.BorderLayout;
|
|||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Random;
|
||||||
import javax.swing.JMenuItem;
|
import javax.swing.JMenuItem;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPopupMenu;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class LinePlot extends LinePlotBase {
|
public class LinePlot extends LinePlotBase {
|
||||||
|
|
||||||
final JLChart plot;
|
JLChart plot;
|
||||||
|
|
||||||
final ArrayList<JLDataView> views = new ArrayList<>();
|
final ArrayList<JLDataView> views = new ArrayList<>();
|
||||||
|
|
||||||
public LinePlot() {
|
public LinePlot() {
|
||||||
super();
|
super();
|
||||||
plot = new JLChart();
|
|
||||||
plot.getXAxis().setAnnotation(JLAxis.VALUE_ANNO);
|
|
||||||
//plot.getXAxis().setLabelFormat(JLAxis.SCIENTIFIC_FORMAT);
|
|
||||||
plot.getY1Axis().setAutoScale(true);
|
|
||||||
plot.getY2Axis().setAutoScale(true);
|
|
||||||
plot.getXAxis().setAutoScale(true);
|
|
||||||
plot.getY1Axis().setGridVisible(true);
|
|
||||||
plot.getXAxis().setGridVisible(true);
|
|
||||||
|
|
||||||
/*
|
|
||||||
plot.getY1Axis().setAutoScale(false);
|
|
||||||
plot.getY2Axis().setAutoScale(false);
|
|
||||||
plot.getXAxis().setAutoScale(false);
|
|
||||||
plot.getY1Axis().setMinimum(0);
|
|
||||||
plot.getY1Axis().setMaximum(10);
|
|
||||||
plot.getY2Axis().setMinimum(0);
|
|
||||||
plot.getY2Axis().setMaximum(10);
|
|
||||||
plot.getXAxis().setMinimum(0);
|
|
||||||
plot.getXAxis().setMaximum(10);
|
|
||||||
*/
|
|
||||||
plot.setLabelVisible(false);
|
|
||||||
plot.setBackground(new Color(240, 240, 240));
|
|
||||||
setRequireUpdateOnAppend(false);
|
setRequireUpdateOnAppend(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static final Color[] defaultColors = new Color[]{Color.RED,Color.BLUE,Color.GREEN,Color.ORANGE,Color.MAGENTA,Color.CYAN,Color.YELLOW,Color.PINK,Color.LIGHT_GRAY,Color.GRAY};
|
||||||
|
Random random;
|
||||||
|
|
||||||
@Override
|
int colorIndex=0;
|
||||||
protected void onAxisRangeChanged(AxisId axis_id) {
|
|
||||||
JLAxis axis = null;
|
|
||||||
switch (axis_id) {
|
|
||||||
case X:
|
|
||||||
axis = plot.getXAxis();
|
|
||||||
break;
|
|
||||||
case Y:
|
|
||||||
axis = plot.getY1Axis();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
axis.setAutoScale(getAxis(axis_id).isAutoRange());
|
|
||||||
axis.setMinimum(getAxis(axis_id).getMin());
|
|
||||||
axis.setMaximum(getAxis(axis_id).getMax());
|
|
||||||
update(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Object onAddedSeries(LinePlotSeries series) {
|
protected Object onAddedSeries(LinePlotSeries series) {
|
||||||
JLDataView view = new JLDataView();
|
JLDataView view = new JLDataView();
|
||||||
|
Color color = series.getColor();
|
||||||
view.setColor(series.getColor());
|
if (color==null){
|
||||||
|
if (colorIndex < defaultColors.length) {
|
||||||
|
color = defaultColors[colorIndex%10];
|
||||||
|
colorIndex++;
|
||||||
|
}
|
||||||
|
if (color==null){
|
||||||
|
if (random==null)
|
||||||
|
random = new Random(1000);// Generate a random color, but repeatable for same graphs.
|
||||||
|
color = SwingUtils.generateRandomColor(random);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
view.setColor(color);
|
||||||
//view.setLineWidth(1);
|
//view.setLineWidth(1);
|
||||||
|
|
||||||
int markerSize = 4;
|
int markerSize = 4;
|
||||||
view.setName(series.getName());
|
view.setName(series.getName());
|
||||||
view.setMarkerSize(markerSize);
|
view.setMarkerSize(markerSize);
|
||||||
view.setMarkerColor(series.getColor());
|
view.setMarkerColor(color);
|
||||||
|
|
||||||
view.setViewType(JLDataView.TYPE_LINE);
|
view.setViewType(JLDataView.TYPE_LINE);
|
||||||
|
|
||||||
@@ -165,24 +141,97 @@ public class LinePlot extends LinePlotBase {
|
|||||||
return new double[][]{x, y};
|
return new double[][]{x, y};
|
||||||
}
|
}
|
||||||
|
|
||||||
JPanel chartPanel;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected JPanel createChartPanel() {
|
protected void onShown() {
|
||||||
JPanel chartPanel = new MonitoredPanel() {
|
addKeyBindings();
|
||||||
protected void onShown() {
|
}
|
||||||
addKeyBindings();
|
|
||||||
}
|
@Override
|
||||||
};
|
protected void createChart() {
|
||||||
|
super.createChart();
|
||||||
|
|
||||||
|
plot = new JLChart();
|
||||||
|
plot.getXAxis().setAnnotation(JLAxis.VALUE_ANNO);
|
||||||
|
//plot.getXAxis().setLabelFormat(JLAxis.SCIENTIFIC_FORMAT);
|
||||||
|
plot.getY1Axis().setAutoScale(true);
|
||||||
|
plot.getY2Axis().setAutoScale(true);
|
||||||
|
plot.getXAxis().setAutoScale(true);
|
||||||
|
plot.getY1Axis().setGridVisible(true);
|
||||||
|
plot.getXAxis().setGridVisible(true);
|
||||||
|
|
||||||
chartPanel.setLayout(new BorderLayout());
|
/*
|
||||||
chartPanel.add(plot);
|
plot.getY1Axis().setAutoScale(false);
|
||||||
chartPanel.setPreferredSize(new Dimension(PREFERRED_WIDTH, PREFERRED_HEIGHT));
|
plot.getY2Axis().setAutoScale(false);
|
||||||
|
plot.getXAxis().setAutoScale(false);
|
||||||
|
plot.getY1Axis().setMinimum(0);
|
||||||
|
plot.getY1Axis().setMaximum(10);
|
||||||
|
plot.getY2Axis().setMinimum(0);
|
||||||
|
plot.getY2Axis().setMaximum(10);
|
||||||
|
plot.getXAxis().setMinimum(0);
|
||||||
|
plot.getXAxis().setMaximum(10);
|
||||||
|
*/
|
||||||
|
plot.setLabelVisible(false);
|
||||||
|
plot.setBackground(new Color(240, 240, 240));
|
||||||
|
|
||||||
|
setLayout(new BorderLayout());
|
||||||
|
add(plot);
|
||||||
|
setPreferredSize(new Dimension(PREFERRED_WIDTH, PREFERRED_HEIGHT));
|
||||||
|
|
||||||
plot.setHeader(getTitle());
|
plot.setHeader(getTitle());
|
||||||
plot.getY1Axis().setName(getAxis(AxisId.Y).getLabel());
|
plot.getY1Axis().setName(getAxis(AxisId.Y).getLabel());
|
||||||
plot.getXAxis().setName(getAxis(AxisId.Y).getLabel());
|
plot.getXAxis().setName(getAxis(AxisId.X).getLabel());
|
||||||
return chartPanel;
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onTitleChanged() {
|
||||||
|
plot.setHeader(getTitle());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onAxisLabelChanged(AxisId axis) {
|
||||||
|
switch (axis){
|
||||||
|
case X:
|
||||||
|
plot.getXAxis().setName(getAxis(AxisId.X).getLabel());
|
||||||
|
break;
|
||||||
|
case Y:
|
||||||
|
plot.getY1Axis().setName(getAxis(AxisId.Y).getLabel());
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onAxisRangeChanged(AxisId axis_id) {
|
||||||
|
JLAxis axis = null;
|
||||||
|
switch (axis_id) {
|
||||||
|
case X:
|
||||||
|
axis = plot.getXAxis();
|
||||||
|
break;
|
||||||
|
case Y:
|
||||||
|
axis = plot.getY1Axis();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
axis.setAutoScale(getAxis(axis_id).isAutoRange());
|
||||||
|
axis.setMinimum(getAxis(axis_id).getMin());
|
||||||
|
axis.setMaximum(getAxis(axis_id).getMax());
|
||||||
|
update(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void createPopupMenu() {
|
||||||
|
super.createPopupMenu();
|
||||||
|
|
||||||
|
//Remove duplicated menu items
|
||||||
|
JMenuItem dummy=new JMenuItem();
|
||||||
|
plot.addMenuItem(dummy);
|
||||||
|
JPopupMenu menu = (JPopupMenu) dummy.getParent();
|
||||||
|
for (int index=9;index>=6;index--)
|
||||||
|
menu.remove(index);
|
||||||
|
menu.remove(dummy);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -6,12 +6,10 @@ package ch.psi.plot.jzy3d;
|
|||||||
import ch.psi.plot.MatrixPlotBase;
|
import ch.psi.plot.MatrixPlotBase;
|
||||||
import ch.psi.plot.MatrixPlotSeries;
|
import ch.psi.plot.MatrixPlotSeries;
|
||||||
import ch.psi.plot.utils.IO;
|
import ch.psi.plot.utils.IO;
|
||||||
import ch.psi.plot.utils.MonitoredPanel;
|
|
||||||
import ch.psi.plot.utils.SwingUtils;
|
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;
|
||||||
@@ -26,12 +24,10 @@ 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;
|
||||||
import javax.swing.JMenuItem;
|
import javax.swing.JMenuItem;
|
||||||
import javax.swing.JPanel;
|
|
||||||
import javax.swing.JPopupMenu;
|
import javax.swing.JPopupMenu;
|
||||||
import javax.swing.JRadioButtonMenuItem;
|
import javax.swing.JRadioButtonMenuItem;
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
@@ -65,7 +61,6 @@ import org.jzy3d.plot3d.rendering.view.modes.ViewBoundMode;
|
|||||||
*/
|
*/
|
||||||
public class MatrixPlot extends MatrixPlotBase {
|
public class MatrixPlot extends MatrixPlotBase {
|
||||||
|
|
||||||
JPanel panel;
|
|
||||||
private Chart chart;
|
private Chart chart;
|
||||||
GLAnimatorControl animatorControl;
|
GLAnimatorControl animatorControl;
|
||||||
IScreenCanvas screenCanvas;
|
IScreenCanvas screenCanvas;
|
||||||
@@ -73,6 +68,7 @@ public class MatrixPlot extends MatrixPlotBase {
|
|||||||
private Shape surface;
|
private Shape surface;
|
||||||
private MatrixPlotSeries series;
|
private MatrixPlotSeries series;
|
||||||
private double[][] data;
|
private double[][] data;
|
||||||
|
JPopupMenu menuPopup;
|
||||||
|
|
||||||
enum CanvasType {
|
enum CanvasType {
|
||||||
|
|
||||||
@@ -84,40 +80,44 @@ public class MatrixPlot extends MatrixPlotBase {
|
|||||||
|
|
||||||
public MatrixPlot() {
|
public MatrixPlot() {
|
||||||
super();
|
super();
|
||||||
panel = new MonitoredPanel() {
|
}
|
||||||
@Override
|
|
||||||
protected void onShown() {
|
@Override
|
||||||
|
protected void onShown() {
|
||||||
// if ((chart == null) && (series != null)) {
|
// if ((chart == null) && (series != null)) {
|
||||||
if (series != null) {
|
if (series != null) {
|
||||||
SwingUtilities.invokeLater(new Runnable() { //Invoking later because was not rendering when setting date with FDA
|
SwingUtilities.invokeLater(new Runnable() { //Invoking later because was not rendering when setting date with FDA
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
createGraph();
|
createGraph();
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else
|
|
||||||
checkBounds(true);
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
checkBounds(true);
|
||||||
|
}
|
||||||
|
|
||||||
protected void onHidden() {
|
protected void onHidden() {
|
||||||
if (chart != null) {
|
if (chart != null) {
|
||||||
chart.stopAnimator();
|
chart.stopAnimator();
|
||||||
panel.removeAll();
|
removeAll();
|
||||||
chart.dispose();
|
chart.dispose();
|
||||||
chart = null;
|
chart = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
panel.setLayout(new BorderLayout());
|
@Override
|
||||||
|
protected void createChart() {
|
||||||
|
super.createChart();
|
||||||
|
setLayout(new BorderLayout());
|
||||||
//panel.setLayout(new GridLayout(1,1));
|
//panel.setLayout(new GridLayout(1,1));
|
||||||
setColormap(Colormap.TEMPERATURE);
|
setColormap(Colormap.TEMPERATURE);
|
||||||
if (getHardwareAccelerated() != Settings.getInstance().isHardwareAccelerated()) {
|
if (getHardwareAccelerated() != Settings.getInstance().isHardwareAccelerated()) {
|
||||||
Settings.getInstance().setHardwareAccelerated(getHardwareAccelerated());
|
Settings.getInstance().setHardwareAccelerated(getHardwareAccelerated());
|
||||||
}
|
}
|
||||||
panel.setPreferredSize(new Dimension(PREFERRED_WIDTH, PREFERRED_HEIGHT));
|
setPreferredSize(new Dimension(PREFERRED_WIDTH, PREFERRED_HEIGHT));
|
||||||
setupPopupMenu();
|
menuPopup = new JPopupMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Object onAddedSeries(final MatrixPlotSeries s) {
|
protected Object onAddedSeries(final MatrixPlotSeries s) {
|
||||||
@@ -179,7 +179,7 @@ public class MatrixPlot extends MatrixPlotBase {
|
|||||||
series = s;
|
series = s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((panel != null) && (panel.isShowing())) {
|
if (isShowing()) {
|
||||||
createGraph();
|
createGraph();
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
@@ -225,86 +225,91 @@ public class MatrixPlot extends MatrixPlotBase {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected JPanel createChartPanel() {
|
|
||||||
return panel;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Range rangeX;
|
private Range rangeX;
|
||||||
private Range rangeY;
|
private Range rangeY;
|
||||||
double[] rangeZ = null;
|
double[] rangeZ = null;
|
||||||
|
|
||||||
boolean showLegend = true;
|
Boolean showLegend;
|
||||||
|
|
||||||
public void setShowLegend(boolean value) {
|
public void setShowLegend(boolean value) {
|
||||||
if (value != showLegend) {
|
if (value != getShowLegend()) {
|
||||||
showLegend = value;
|
showLegend = value;
|
||||||
if ((panel != null) && (panel.isShowing())) {
|
if (isShowing()) {
|
||||||
updateGraph(true);
|
updateGraph(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getShowLegend() {
|
public boolean getShowLegend() {
|
||||||
|
if (showLegend==null)
|
||||||
|
return true;
|
||||||
return showLegend;
|
return showLegend;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean showFace = true;
|
Boolean showFace;
|
||||||
|
|
||||||
public void setShowFace(boolean value) {
|
public void setShowFace(boolean value) {
|
||||||
if (value != showFace) {
|
if (value != getShowFace()) {
|
||||||
showFace = value;
|
showFace = value;
|
||||||
if ((panel != null) && (panel.isShowing())) {
|
if (isShowing()) {
|
||||||
updateGraph(true);
|
updateGraph(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getShowFace() {
|
public boolean getShowFace() {
|
||||||
|
if (showFace==null)
|
||||||
|
return true;
|
||||||
return showFace;
|
return showFace;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean showFrame = false;
|
Boolean showFrame;
|
||||||
|
|
||||||
public void setShowFrame(boolean value) {
|
public void setShowFrame(boolean value) {
|
||||||
if (value != showFrame) {
|
if (value != getShowFrame()) {
|
||||||
showFrame = value;
|
showFrame = value;
|
||||||
if ((panel != null) && (panel.isShowing())) {
|
if (isShowing()) {
|
||||||
updateGraph(true);
|
updateGraph(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getShowFrame() {
|
public boolean getShowFrame() {
|
||||||
|
if (showFrame==null)
|
||||||
|
return false;
|
||||||
return showFrame;
|
return showFrame;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean showAxis = true;
|
Boolean showAxis;
|
||||||
|
|
||||||
public void setShowAxis(boolean value) {
|
public void setShowAxis(boolean value) {
|
||||||
if (value != showAxis) {
|
if (value != getShowAxis()) {
|
||||||
showAxis = value;
|
showAxis = value;
|
||||||
if ((panel != null) && (panel.isShowing())) {
|
if (isShowing()) {
|
||||||
updateGraph(true);
|
updateGraph(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getShowAxis() {
|
public boolean getShowAxis() {
|
||||||
|
if (showAxis==null)
|
||||||
|
return true;
|
||||||
return showAxis;
|
return showAxis;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean continuousRendering = false;
|
Boolean continuousRendering;
|
||||||
|
|
||||||
public void setContinuousRendering(boolean value) {
|
public void setContinuousRendering(boolean value) {
|
||||||
if (value != continuousRendering) {
|
if (value != getContinuousRendering()) {
|
||||||
continuousRendering = value;
|
continuousRendering = value;
|
||||||
if ((panel != null) && (panel.isShowing())) {
|
if (isShowing()) {
|
||||||
createGraph();
|
createGraph();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public boolean getContinuousRendering() {
|
public boolean getContinuousRendering() {
|
||||||
|
if (continuousRendering==null)
|
||||||
|
return false;
|
||||||
return continuousRendering;
|
return continuousRendering;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -313,18 +318,20 @@ public class MatrixPlot extends MatrixPlotBase {
|
|||||||
GRAYSCALE,
|
GRAYSCALE,
|
||||||
TEMPERATURE,
|
TEMPERATURE,
|
||||||
}
|
}
|
||||||
Colormap colormap = Colormap.TEMPERATURE;
|
Colormap colormap;
|
||||||
|
|
||||||
public void setColormap(Colormap value) {
|
public void setColormap(Colormap value) {
|
||||||
if (value != colormap) {
|
if (value != getColormap()) {
|
||||||
colormap = value;
|
colormap = value;
|
||||||
if ((panel != null) && (panel.isShowing())) {
|
if (isShowing()) {
|
||||||
updateGraph(true);
|
updateGraph(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Colormap getColormap() {
|
public Colormap getColormap() {
|
||||||
|
if (colormap==null)
|
||||||
|
return Colormap.TEMPERATURE;
|
||||||
return colormap;
|
return colormap;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -349,18 +356,20 @@ public class MatrixPlot extends MatrixPlotBase {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Quality quality = Quality.HIGH;
|
Quality quality;
|
||||||
|
|
||||||
public void setQuality(Quality quality) {
|
public void setQuality(Quality quality) {
|
||||||
this.quality = quality;
|
this.quality = quality;
|
||||||
if (series != null) {
|
if (series != null) {
|
||||||
if ((panel != null) && (panel.isShowing())) {
|
if (isShowing()) {
|
||||||
createGraph();
|
createGraph();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Quality getQuality() {
|
public Quality getQuality() {
|
||||||
|
if (quality==null)
|
||||||
|
return Quality.HIGH;
|
||||||
return quality;
|
return quality;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -382,7 +391,7 @@ public class MatrixPlot extends MatrixPlotBase {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Mode mode = Mode.FREE;
|
Mode mode;
|
||||||
|
|
||||||
public void setMode(Mode mode) {
|
public void setMode(Mode mode) {
|
||||||
this.mode = mode;
|
this.mode = mode;
|
||||||
@@ -392,6 +401,8 @@ public class MatrixPlot extends MatrixPlotBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Mode getMode() {
|
public Mode getMode() {
|
||||||
|
if (mode==null)
|
||||||
|
return Mode.FREE;
|
||||||
return mode;
|
return mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -404,22 +415,24 @@ public class MatrixPlot extends MatrixPlotBase {
|
|||||||
CONTOUR_3D
|
CONTOUR_3D
|
||||||
|
|
||||||
}
|
}
|
||||||
Contour contour = Contour.NONE;
|
Contour contour;
|
||||||
|
|
||||||
public void setContour(Contour contour) {
|
public void setContour(Contour contour) {
|
||||||
this.contour = contour;
|
this.contour = contour;
|
||||||
if (series != null) {
|
if (series != null) {
|
||||||
if ((panel != null) && (panel.isShowing())) {
|
if (isShowing()) {
|
||||||
createGraph();
|
createGraph();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Contour getContour() {
|
public Contour getContour() {
|
||||||
|
if (contour==null)
|
||||||
|
return Contour.NONE;
|
||||||
return contour;
|
return contour;
|
||||||
}
|
}
|
||||||
|
|
||||||
int contourLevels = 10;
|
Integer contourLevels;
|
||||||
|
|
||||||
public void setContourLevels(int value) {
|
public void setContourLevels(int value) {
|
||||||
contourLevels = value;
|
contourLevels = value;
|
||||||
@@ -427,10 +440,12 @@ public class MatrixPlot extends MatrixPlotBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getContourLevels() {
|
public int getContourLevels() {
|
||||||
|
if (contourLevels==null)
|
||||||
|
return 10;
|
||||||
return contourLevels;
|
return contourLevels;
|
||||||
}
|
}
|
||||||
|
|
||||||
int contourDensity = 400;
|
Integer contourDensity;
|
||||||
|
|
||||||
public void setContourDensity(int value) {
|
public void setContourDensity(int value) {
|
||||||
contourDensity = value;
|
contourDensity = value;
|
||||||
@@ -438,10 +453,12 @@ public class MatrixPlot extends MatrixPlotBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getContourDensity() {
|
public int getContourDensity() {
|
||||||
|
if (contourDensity==null)
|
||||||
|
return 400;
|
||||||
return contourDensity;
|
return contourDensity;
|
||||||
}
|
}
|
||||||
|
|
||||||
java.awt.Color frameColor = java.awt.Color.BLACK;
|
java.awt.Color frameColor;
|
||||||
|
|
||||||
public void setFrameColor(java.awt.Color value) {
|
public void setFrameColor(java.awt.Color value) {
|
||||||
frameColor = value;
|
frameColor = value;
|
||||||
@@ -449,10 +466,12 @@ public class MatrixPlot extends MatrixPlotBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public java.awt.Color getFrameColor() {
|
public java.awt.Color getFrameColor() {
|
||||||
|
if (frameColor==null)
|
||||||
|
return java.awt.Color.BLACK;
|
||||||
return frameColor;
|
return frameColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean hideEmptyRows = true;
|
Boolean hideEmptyRows;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* By default empty lines (containing only NaN) are not plotted.
|
* By default empty lines (containing only NaN) are not plotted.
|
||||||
@@ -463,208 +482,11 @@ public class MatrixPlot extends MatrixPlotBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean getHideEmptyRows() {
|
public boolean getHideEmptyRows() {
|
||||||
|
if (hideEmptyRows==null)
|
||||||
|
return true;
|
||||||
return hideEmptyRows;
|
return hideEmptyRows;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
JPopupMenu menuPopup;
|
|
||||||
|
|
||||||
void setupPopupMenu() {
|
|
||||||
menuPopup = new JPopupMenu();
|
|
||||||
JMenuItem menuUpdate = new JMenuItem("Update");
|
|
||||||
final JCheckBoxMenuItem menuShowAxis = new JCheckBoxMenuItem("Show Axis");
|
|
||||||
final JCheckBoxMenuItem menuShowLegend = new JCheckBoxMenuItem("Show Legend");
|
|
||||||
final JCheckBoxMenuItem menuShowFace = new JCheckBoxMenuItem("Show Face");
|
|
||||||
final JCheckBoxMenuItem menuShowFrame = new JCheckBoxMenuItem("Show Frame");
|
|
||||||
//final JCheckBoxMenuItem menuHideEmptyRows = new JCheckBoxMenuItem("Hide Empty Rows");
|
|
||||||
//final JCheckBoxMenuItem menuContinuous = new JCheckBoxMenuItem("Continuous Rendering");
|
|
||||||
JMenuItem frameColor = new JMenuItem("Set Frame Color");
|
|
||||||
|
|
||||||
final JMenu menuColormap = new JMenu("Colormap");
|
|
||||||
final JMenu menuMode = new JMenu("Mode");
|
|
||||||
final JMenu menuContour = new JMenu("Contour");
|
|
||||||
final JMenu menuQuality = new JMenu("Quality");
|
|
||||||
menuPopup.add(menuShowAxis);
|
|
||||||
menuPopup.add(menuShowLegend);
|
|
||||||
menuPopup.add(menuShowFace);
|
|
||||||
menuPopup.add(menuShowFrame);
|
|
||||||
//menuPopup.add(menuHideEmptyRows);
|
|
||||||
//menuPopup.add(menuContinuous);
|
|
||||||
menuPopup.add(frameColor);
|
|
||||||
menuPopup.add(menuColormap);
|
|
||||||
menuPopup.add(menuMode);
|
|
||||||
menuPopup.add(menuContour);
|
|
||||||
menuPopup.add(menuQuality);
|
|
||||||
menuPopup.add(menuUpdate);
|
|
||||||
menuUpdate.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
try {
|
|
||||||
update(true);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
frameColor.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
try {
|
|
||||||
String ret = SwingUtils.getString(panel, "Enter frame color (name or R,G,B):", getFrameColor().getRed() + "," + getFrameColor().getGreen() + "," + getFrameColor().getBlue());
|
|
||||||
if (ret != null) {
|
|
||||||
java.awt.Color color = null;
|
|
||||||
if (ret.contains(",")) {
|
|
||||||
String[] tokens = ret.split(",");
|
|
||||||
color = new java.awt.Color(Integer.valueOf(tokens[0]), Integer.valueOf(tokens[1]), Integer.valueOf(tokens[2]));
|
|
||||||
} else {
|
|
||||||
Field field = java.awt.Color.class.getField(ret);
|
|
||||||
color = (java.awt.Color) field.get(null);
|
|
||||||
}
|
|
||||||
setFrameColor(color);
|
|
||||||
updateGraph(true);
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
SwingUtils.showException(panel, ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
menuShowFrame.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
setShowFrame(!getShowFrame());
|
|
||||||
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());
|
|
||||||
menuHideEmptyRows.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
setHideEmptyRows(!getHideEmptyRows());
|
|
||||||
menuHideEmptyRows.setSelected(getHideEmptyRows());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
menuHideEmptyRows.setSelected(getHideEmptyRows());
|
|
||||||
*/
|
|
||||||
|
|
||||||
menuShowLegend.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
setShowLegend(!getShowLegend());
|
|
||||||
menuShowLegend.setSelected(getShowLegend());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
menuShowLegend.setSelected(getShowLegend());
|
|
||||||
|
|
||||||
menuShowFace.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
setShowFace(!getShowFace());
|
|
||||||
menuShowLegend.setSelected(getShowFace());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
menuShowFace.setSelected(getShowFace());
|
|
||||||
|
|
||||||
menuShowAxis.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
setShowAxis(!getShowAxis());
|
|
||||||
menuShowAxis.setSelected(getShowAxis());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
menuShowAxis.setSelected(getShowAxis());
|
|
||||||
|
|
||||||
ButtonGroup colormapGroup = new ButtonGroup();
|
|
||||||
for (Colormap c : Colormap.values()) {
|
|
||||||
final JRadioButtonMenuItem menuItem = new JRadioButtonMenuItem(c.toString());
|
|
||||||
colormapGroup.add(menuItem);
|
|
||||||
menuItem.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
setColormap(Colormap.valueOf(e.getActionCommand()));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
menuItem.setSelected(getColormap().toString().equals(menuItem.getText()));
|
|
||||||
menuColormap.add(menuItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
ButtonGroup modeGroup = new ButtonGroup();
|
|
||||||
for (Mode q : Mode.values()) {
|
|
||||||
final JRadioButtonMenuItem menuItem = new JRadioButtonMenuItem(q.toString());
|
|
||||||
modeGroup.add(menuItem);
|
|
||||||
menuItem.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
setMode(Mode.valueOf(e.getActionCommand()));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
menuItem.setSelected(getMode().toString().equals(menuItem.getText()));
|
|
||||||
menuMode.add(menuItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
ButtonGroup contourGroup = new ButtonGroup();
|
|
||||||
for (Contour q : Contour.values()) {
|
|
||||||
final JRadioButtonMenuItem menuItem = new JRadioButtonMenuItem(q.toString());
|
|
||||||
contourGroup.add(menuItem);
|
|
||||||
menuItem.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
setContour(Contour.valueOf(e.getActionCommand()));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
menuItem.setSelected(getContour().toString().equals(menuItem.getText()));
|
|
||||||
menuContour.add(menuItem);
|
|
||||||
}
|
|
||||||
menuContour.addSeparator();
|
|
||||||
JMenuItem levels = new JMenuItem("Set Levels");
|
|
||||||
levels.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
try {
|
|
||||||
String ret = SwingUtils.getString(panel, "Enter number of contour levels:", getContourLevels());
|
|
||||||
if (ret != null) {
|
|
||||||
Integer levels = Integer.valueOf(ret);
|
|
||||||
setContourLevels(levels);
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
SwingUtils.showException(panel, ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
menuContour.add(levels);
|
|
||||||
|
|
||||||
JMenuItem density = new JMenuItem("Set Density");
|
|
||||||
density.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
try {
|
|
||||||
String ret = SwingUtils.getString(panel, "Enter contour density:", getContourDensity());
|
|
||||||
if (ret != null) {
|
|
||||||
Integer density = Integer.valueOf(ret);
|
|
||||||
setContourDensity(density);
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
SwingUtils.showException(panel, ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
menuContour.add(density);
|
|
||||||
|
|
||||||
ButtonGroup qualityGroup = new ButtonGroup();
|
|
||||||
for (Quality q : Quality.values()) {
|
|
||||||
final JRadioButtonMenuItem menuItem = new JRadioButtonMenuItem(q.toString());
|
|
||||||
qualityGroup.add(menuItem);
|
|
||||||
menuItem.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
setQuality(Quality.valueOf(e.getActionCommand()));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
menuItem.setSelected(getQuality().toString().equals(menuItem.getText()));
|
|
||||||
menuQuality.add(menuItem);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static void remap(Shape shape, Mapper mapper) {
|
protected static void remap(Shape shape, Mapper mapper) {
|
||||||
List<AbstractDrawable> polygons = shape.getDrawables();
|
List<AbstractDrawable> polygons = shape.getDrawables();
|
||||||
for (AbstractDrawable d : polygons) {
|
for (AbstractDrawable d : polygons) {
|
||||||
@@ -735,12 +557,12 @@ public class MatrixPlot extends MatrixPlotBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
panel.removeAll();
|
MatrixPlot.this.removeAll();
|
||||||
panel.add(canvas);
|
MatrixPlot.this.add(canvas);
|
||||||
|
|
||||||
//Todo: why it is not displyed if I don'r pack the Window?
|
//Todo: why it is not displyed if I don'r pack the Window?
|
||||||
if (panel.isVisible()) {
|
if (MatrixPlot.this.isVisible()) {
|
||||||
panel.validate();
|
MatrixPlot.this.validate();
|
||||||
}
|
}
|
||||||
|
|
||||||
chart.addMouseController();
|
chart.addMouseController();
|
||||||
@@ -769,7 +591,7 @@ public class MatrixPlot extends MatrixPlotBase {
|
|||||||
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()) ){
|
(!e.isAltDown())&&(!e.isControlDown())&&(!e.isShiftDown()) ){
|
||||||
menuPopup.show(panel, e.getX(), e.getY());
|
menuPopup.show(MatrixPlot.this, e.getX(), e.getY());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!getContinuousRendering() && (animatorControl != null)) {
|
if (!getContinuousRendering() && (animatorControl != null)) {
|
||||||
@@ -838,6 +660,203 @@ public class MatrixPlot extends MatrixPlotBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void createPopupMenu() {
|
||||||
|
JMenuItem menuUpdate = new JMenuItem("Update");
|
||||||
|
final JCheckBoxMenuItem menuShowAxis = new JCheckBoxMenuItem("Show Axis");
|
||||||
|
final JCheckBoxMenuItem menuShowLegend = new JCheckBoxMenuItem("Show Legend");
|
||||||
|
final JCheckBoxMenuItem menuShowFace = new JCheckBoxMenuItem("Show Face");
|
||||||
|
final JCheckBoxMenuItem menuShowFrame = new JCheckBoxMenuItem("Show Frame");
|
||||||
|
//final JCheckBoxMenuItem menuHideEmptyRows = new JCheckBoxMenuItem("Hide Empty Rows");
|
||||||
|
//final JCheckBoxMenuItem menuContinuous = new JCheckBoxMenuItem("Continuous Rendering");
|
||||||
|
JMenuItem frameColor = new JMenuItem("Set Frame Color");
|
||||||
|
|
||||||
|
final JMenu menuColormap = new JMenu("Colormap");
|
||||||
|
final JMenu menuMode = new JMenu("Mode");
|
||||||
|
final JMenu menuContour = new JMenu("Contour");
|
||||||
|
final JMenu menuQuality = new JMenu("Quality");
|
||||||
|
menuPopup.add(menuShowAxis);
|
||||||
|
menuPopup.add(menuShowLegend);
|
||||||
|
menuPopup.add(menuShowFace);
|
||||||
|
menuPopup.add(menuShowFrame);
|
||||||
|
//menuPopup.add(menuHideEmptyRows);
|
||||||
|
//menuPopup.add(menuContinuous);
|
||||||
|
menuPopup.add(frameColor);
|
||||||
|
menuPopup.add(menuColormap);
|
||||||
|
menuPopup.add(menuMode);
|
||||||
|
menuPopup.add(menuContour);
|
||||||
|
menuPopup.add(menuQuality);
|
||||||
|
menuPopup.add(menuUpdate);
|
||||||
|
menuUpdate.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
try {
|
||||||
|
update(true);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
frameColor.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
try {
|
||||||
|
String ret = SwingUtils.getString(MatrixPlot.this, "Enter frame color (name or R,G,B):", getFrameColor().getRed() + "," + getFrameColor().getGreen() + "," + getFrameColor().getBlue());
|
||||||
|
if (ret != null) {
|
||||||
|
java.awt.Color color = null;
|
||||||
|
if (ret.contains(",")) {
|
||||||
|
String[] tokens = ret.split(",");
|
||||||
|
color = new java.awt.Color(Integer.valueOf(tokens[0]), Integer.valueOf(tokens[1]), Integer.valueOf(tokens[2]));
|
||||||
|
} else {
|
||||||
|
Field field = java.awt.Color.class.getField(ret);
|
||||||
|
color = (java.awt.Color) field.get(null);
|
||||||
|
}
|
||||||
|
setFrameColor(color);
|
||||||
|
updateGraph(true);
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
SwingUtils.showException(MatrixPlot.this, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
menuShowFrame.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
setShowFrame(!getShowFrame());
|
||||||
|
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());
|
||||||
|
menuHideEmptyRows.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
setHideEmptyRows(!getHideEmptyRows());
|
||||||
|
menuHideEmptyRows.setSelected(getHideEmptyRows());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
menuHideEmptyRows.setSelected(getHideEmptyRows());
|
||||||
|
*/
|
||||||
|
|
||||||
|
menuShowLegend.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
setShowLegend(!getShowLegend());
|
||||||
|
menuShowLegend.setSelected(getShowLegend());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
menuShowLegend.setSelected(getShowLegend());
|
||||||
|
|
||||||
|
menuShowFace.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
setShowFace(!getShowFace());
|
||||||
|
menuShowFace.setSelected(getShowFace());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
menuShowFace.setSelected(getShowFace());
|
||||||
|
|
||||||
|
menuShowAxis.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
setShowAxis(!getShowAxis());
|
||||||
|
menuShowAxis.setSelected(getShowAxis());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
menuShowAxis.setSelected(getShowAxis());
|
||||||
|
|
||||||
|
ButtonGroup colormapGroup = new ButtonGroup();
|
||||||
|
for (Colormap c : Colormap.values()) {
|
||||||
|
final JRadioButtonMenuItem menuItem = new JRadioButtonMenuItem(c.toString());
|
||||||
|
colormapGroup.add(menuItem);
|
||||||
|
menuItem.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
setColormap(Colormap.valueOf(e.getActionCommand()));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
menuItem.setSelected(getColormap().toString().equals(menuItem.getText()));
|
||||||
|
menuColormap.add(menuItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
ButtonGroup modeGroup = new ButtonGroup();
|
||||||
|
for (Mode q : Mode.values()) {
|
||||||
|
final JRadioButtonMenuItem menuItem = new JRadioButtonMenuItem(q.toString());
|
||||||
|
modeGroup.add(menuItem);
|
||||||
|
menuItem.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
setMode(Mode.valueOf(e.getActionCommand()));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
menuItem.setSelected(getMode().toString().equals(menuItem.getText()));
|
||||||
|
menuMode.add(menuItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
ButtonGroup contourGroup = new ButtonGroup();
|
||||||
|
for (Contour q : Contour.values()) {
|
||||||
|
final JRadioButtonMenuItem menuItem = new JRadioButtonMenuItem(q.toString());
|
||||||
|
contourGroup.add(menuItem);
|
||||||
|
menuItem.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
setContour(Contour.valueOf(e.getActionCommand()));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
menuItem.setSelected(getContour().toString().equals(menuItem.getText()));
|
||||||
|
menuContour.add(menuItem);
|
||||||
|
}
|
||||||
|
menuContour.addSeparator();
|
||||||
|
JMenuItem levels = new JMenuItem("Set Levels");
|
||||||
|
levels.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
try {
|
||||||
|
String ret = SwingUtils.getString(MatrixPlot.this, "Enter number of contour levels:", getContourLevels());
|
||||||
|
if (ret != null) {
|
||||||
|
Integer levels = Integer.valueOf(ret);
|
||||||
|
setContourLevels(levels);
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
SwingUtils.showException(MatrixPlot.this, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
menuContour.add(levels);
|
||||||
|
|
||||||
|
JMenuItem density = new JMenuItem("Set Density");
|
||||||
|
density.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
try {
|
||||||
|
String ret = SwingUtils.getString(MatrixPlot.this, "Enter contour density:", getContourDensity());
|
||||||
|
if (ret != null) {
|
||||||
|
Integer density = Integer.valueOf(ret);
|
||||||
|
setContourDensity(density);
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
SwingUtils.showException(MatrixPlot.this, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
menuContour.add(density);
|
||||||
|
|
||||||
|
ButtonGroup qualityGroup = new ButtonGroup();
|
||||||
|
for (Quality q : Quality.values()) {
|
||||||
|
final JRadioButtonMenuItem menuItem = new JRadioButtonMenuItem(q.toString());
|
||||||
|
qualityGroup.add(menuItem);
|
||||||
|
menuItem.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
setQuality(Quality.valueOf(e.getActionCommand()));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
menuItem.setSelected(getQuality().toString().equals(menuItem.getText()));
|
||||||
|
menuQuality.add(menuItem);
|
||||||
|
}
|
||||||
|
super.createPopupMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateGraph(final boolean newSeries) {
|
private void updateGraph(final boolean newSeries) {
|
||||||
@@ -868,7 +887,7 @@ public class MatrixPlot extends MatrixPlotBase {
|
|||||||
//if (true) {
|
//if (true) {
|
||||||
surface = (Shape) Builder.buildOrthonormal(
|
surface = (Shape) Builder.buildOrthonormal(
|
||||||
new OrthonormalGrid(rangeX, series.getNumberOfBinsX(), rangeY, series.getNumberOfBinsY()), mapper);
|
new OrthonormalGrid(rangeX, series.getNumberOfBinsX(), rangeY, series.getNumberOfBinsY()), mapper);
|
||||||
ColorMapper colorMapper = new ColorMapper((colormap == Colormap.TEMPERATURE) ? new ColorMapRainbow() : new ColorMapGrayscale(),
|
ColorMapper colorMapper = new ColorMapper((getColormap() == Colormap.TEMPERATURE) ? new ColorMapRainbow() : new ColorMapGrayscale(),
|
||||||
(float) ((getAxis(AxisId.Z).isAutoRange()) ? surface.getBounds().getZmin() : getAxis(AxisId.Z).getMin()),
|
(float) ((getAxis(AxisId.Z).isAutoRange()) ? surface.getBounds().getZmin() : getAxis(AxisId.Z).getMin()),
|
||||||
(float) ((getAxis(AxisId.Z).isAutoRange()) ? surface.getBounds().getZmax() : getAxis(AxisId.Z).getMax()),
|
(float) ((getAxis(AxisId.Z).isAutoRange()) ? surface.getBounds().getZmax() : getAxis(AxisId.Z).getMax()),
|
||||||
new Color(1, 1, 1, .5f));
|
new Color(1, 1, 1, .5f));
|
||||||
@@ -876,7 +895,7 @@ public class MatrixPlot extends MatrixPlotBase {
|
|||||||
surface.setFaceDisplayed(true);
|
surface.setFaceDisplayed(true);
|
||||||
surface.setWireframeDisplayed(getShowFrame());
|
surface.setWireframeDisplayed(getShowFrame());
|
||||||
|
|
||||||
surface.setWireframeColor(new Color(frameColor.getRed(), frameColor.getGreen(), frameColor.getBlue(), frameColor.getAlpha()));
|
surface.setWireframeColor(new Color(getFrameColor().getRed(), getFrameColor().getGreen(), getFrameColor().getBlue(), getFrameColor().getAlpha()));
|
||||||
surface.setFaceDisplayed(getShowFace());
|
surface.setFaceDisplayed(getShowFace());
|
||||||
if (getShowLegend()) {
|
if (getShowLegend()) {
|
||||||
AWTColorbarLegend cbar = new AWTColorbarLegend(surface, chart.getView().getAxe().getLayout());
|
AWTColorbarLegend cbar = new AWTColorbarLegend(surface, chart.getView().getAxe().getLayout());
|
||||||
@@ -955,6 +974,14 @@ public class MatrixPlot extends MatrixPlotBase {
|
|||||||
}
|
}
|
||||||
//System.out.println(System.currentTimeMillis()-start);
|
//System.out.println(System.currentTimeMillis()-start);
|
||||||
}
|
}
|
||||||
|
if (newSeries){
|
||||||
|
if (!getContinuousRendering() && (animatorControl != null)) {
|
||||||
|
if (animatorControl.isPaused()) {
|
||||||
|
screenCanvas.display();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean checkBounds(boolean updateBounds) {
|
protected boolean checkBounds(boolean updateBounds) {
|
||||||
@@ -970,7 +997,7 @@ public class MatrixPlot extends MatrixPlotBase {
|
|||||||
//If manual bounds
|
//If manual bounds
|
||||||
if ( manual_bounds) {
|
if ( manual_bounds) {
|
||||||
//Deferring setting bounds untiul the panel is displayed
|
//Deferring setting bounds untiul the panel is displayed
|
||||||
if (panel.isShowing() && (chart != null)) {
|
if (isShowing() && (chart != null)) {
|
||||||
if (chart.getView().getBoundsMode() != ViewBoundMode.MANUAL) {
|
if (chart.getView().getBoundsMode() != ViewBoundMode.MANUAL) {
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,11 +7,19 @@ import java.awt.Color;
|
|||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.Image;
|
||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
import java.awt.Toolkit;
|
import java.awt.Toolkit;
|
||||||
|
import java.awt.datatransfer.DataFlavor;
|
||||||
|
import java.awt.datatransfer.Transferable;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.File;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
import javax.swing.JComponent;
|
||||||
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
|
import javax.swing.TransferHandler;
|
||||||
|
import javax.swing.filechooser.FileFilter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -31,17 +39,17 @@ public class SwingUtils {
|
|||||||
component.setLocation(dim.width / 2 - component.getSize().width / 2, dim.height / 2 - component.getSize().height / 2);
|
component.setLocation(dim.width / 2 - component.getSize().width / 2, dim.height / 2 - component.getSize().height / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Color generateRandomColor(long seed) {
|
public static Color generateRandomColor(long seed) {
|
||||||
Random random = new Random(seed);
|
Random random = new Random(seed);
|
||||||
return generateRandomColor(random);
|
return generateRandomColor(random);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Color generateRandomColor() {
|
public static Color generateRandomColor() {
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
return generateRandomColor(random);
|
return generateRandomColor(random);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Color generateRandomColor(Random random) {
|
public static Color generateRandomColor(Random random) {
|
||||||
|
|
||||||
Color mix = Color.WHITE;
|
Color mix = Color.WHITE;
|
||||||
int red = (random.nextInt(256) + mix.getRed()) / 2;
|
int red = (random.nextInt(256) + mix.getRed()) / 2;
|
||||||
@@ -59,10 +67,16 @@ public class SwingUtils {
|
|||||||
public static void showException(Component parent, Exception ex) {
|
public static void showException(Component parent, Exception ex) {
|
||||||
JOptionPane.showMessageDialog(parent, ex.getMessage(), "Exception", JOptionPane.WARNING_MESSAGE, null);
|
JOptionPane.showMessageDialog(parent, ex.getMessage(), "Exception", JOptionPane.WARNING_MESSAGE, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int showOption(Component parent, String title, String msg, int optionType)
|
||||||
|
{
|
||||||
|
return JOptionPane.showOptionDialog(parent,msg,title,optionType,JOptionPane.QUESTION_MESSAGE,null,null,null);
|
||||||
|
}
|
||||||
|
|
||||||
public static String getString(Component parent, String msg, Object current_value) {
|
public static String getString(Component parent, String msg, Object current_value) {
|
||||||
return JOptionPane.showInputDialog(parent, msg, String.valueOf(current_value));
|
return JOptionPane.showInputDialog(parent, msg, String.valueOf(current_value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static BufferedImage createImage(Component panel) {
|
public static BufferedImage createImage(Component panel) {
|
||||||
if (panel == null) {
|
if (panel == null) {
|
||||||
@@ -74,5 +88,97 @@ public class SwingUtils {
|
|||||||
Graphics2D g2 = image.createGraphics();
|
Graphics2D g2 = image.createGraphics();
|
||||||
panel.paint(g2);
|
panel.paint(g2);
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class ImageTransferHandler extends TransferHandler implements Transferable {
|
||||||
|
|
||||||
|
private static final DataFlavor[] dataFlavors = {DataFlavor.imageFlavor};
|
||||||
|
private Image image;
|
||||||
|
|
||||||
|
public ImageTransferHandler(Image data) {
|
||||||
|
this.image = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getTransferData(DataFlavor flavor) {
|
||||||
|
if (isDataFlavorSupported(flavor)) {
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DataFlavor[] getTransferDataFlavors() {
|
||||||
|
return dataFlavors;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSourceActions(JComponent c) {
|
||||||
|
return TransferHandler.COPY;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canImport(JComponent comp, DataFlavor flavor[]) {
|
||||||
|
if (!(comp instanceof JLabel)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (int i = 0, n = flavor.length; i < n; i++) {
|
||||||
|
for (int j = 0, m = dataFlavors.length; j < m; j++) {
|
||||||
|
if (flavor[i].equals(dataFlavors[j])) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDataFlavorSupported(DataFlavor flavor) {
|
||||||
|
return flavor.equals(DataFlavor.imageFlavor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ExtensionFileFilter extends FileFilter {
|
||||||
|
|
||||||
|
String description;
|
||||||
|
|
||||||
|
String extensions[];
|
||||||
|
|
||||||
|
public ExtensionFileFilter(String description, String extension) {
|
||||||
|
this(description, new String[]{extension});
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExtensionFileFilter(String description, String extensions[]) {
|
||||||
|
if (description == null) {
|
||||||
|
this.description = extensions[0];
|
||||||
|
} else {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
this.extensions = (String[]) extensions.clone();
|
||||||
|
for (int i = 0, n = extensions.length; i < n; i++) {
|
||||||
|
extensions[i] = extensions[i].toLowerCase();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean accept(File file) {
|
||||||
|
if (file.isDirectory()) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
String path = file.getAbsolutePath().toLowerCase();
|
||||||
|
for (int i = 0, n = extensions.length; i < n; i++) {
|
||||||
|
String extension = extensions[i];
|
||||||
|
if ((path.endsWith(extension) && (path.charAt(path.length() - extension.length() - 1)) == '.')) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
42
ch.psi.plot/src/test/java/Frame.form
Normal file
42
ch.psi.plot/src/test/java/Frame.form
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
|
||||||
|
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
|
||||||
|
<Properties>
|
||||||
|
<Property name="defaultCloseOperation" type="int" value="3"/>
|
||||||
|
</Properties>
|
||||||
|
<SyntheticProperties>
|
||||||
|
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
|
||||||
|
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
|
||||||
|
</SyntheticProperties>
|
||||||
|
<AuxValues>
|
||||||
|
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
|
||||||
|
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
|
||||||
|
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
|
||||||
|
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
|
||||||
|
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
|
||||||
|
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
|
||||||
|
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
|
||||||
|
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
|
||||||
|
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
|
||||||
|
</AuxValues>
|
||||||
|
|
||||||
|
<Layout>
|
||||||
|
<DimensionLayout dim="0">
|
||||||
|
<Group type="103" groupAlignment="0" attributes="0">
|
||||||
|
<Component id="plot" alignment="0" pref="520" max="32767" attributes="0"/>
|
||||||
|
</Group>
|
||||||
|
</DimensionLayout>
|
||||||
|
<DimensionLayout dim="1">
|
||||||
|
<Group type="103" groupAlignment="0" attributes="0">
|
||||||
|
<Component id="plot" min="-2" max="-2" attributes="0"/>
|
||||||
|
</Group>
|
||||||
|
</DimensionLayout>
|
||||||
|
</Layout>
|
||||||
|
<SubComponents>
|
||||||
|
<Component class="ch.psi.plot.jlchart.LinePlot" name="plot">
|
||||||
|
<Properties>
|
||||||
|
<Property name="title" type="java.lang.String" value="Frame Test"/>
|
||||||
|
</Properties>
|
||||||
|
</Component>
|
||||||
|
</SubComponents>
|
||||||
|
</Form>
|
||||||
93
ch.psi.plot/src/test/java/Frame.java
Normal file
93
ch.psi.plot/src/test/java/Frame.java
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
|
||||||
|
import ch.psi.plot.LinePlotSeries;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2014 Paul Scherrer Institute. All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author gobbo_a
|
||||||
|
*/
|
||||||
|
public class Frame extends javax.swing.JFrame {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates new form Frame
|
||||||
|
*/
|
||||||
|
public Frame() {
|
||||||
|
initComponents();
|
||||||
|
LinePlotSeries series = new LinePlotSeries("Test");
|
||||||
|
plot.addSeries(series);
|
||||||
|
series.appendData(1,3);
|
||||||
|
series.appendData(2,4);
|
||||||
|
series.appendData(4,3);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is called from within the constructor to initialize the form.
|
||||||
|
* WARNING: Do NOT modify this code. The content of this method is always
|
||||||
|
* regenerated by the Form Editor.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||||
|
private void initComponents() {
|
||||||
|
|
||||||
|
plot = new ch.psi.plot.jlchart.LinePlot();
|
||||||
|
|
||||||
|
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
|
||||||
|
|
||||||
|
plot.setTitle("Frame Test");
|
||||||
|
|
||||||
|
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
|
||||||
|
getContentPane().setLayout(layout);
|
||||||
|
layout.setHorizontalGroup(
|
||||||
|
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||||
|
.addComponent(plot, javax.swing.GroupLayout.DEFAULT_SIZE, 520, Short.MAX_VALUE)
|
||||||
|
);
|
||||||
|
layout.setVerticalGroup(
|
||||||
|
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||||
|
.addComponent(plot, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||||
|
);
|
||||||
|
|
||||||
|
pack();
|
||||||
|
}// </editor-fold>//GEN-END:initComponents
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param args the command line arguments
|
||||||
|
*/
|
||||||
|
public static void main(String args[]) {
|
||||||
|
/* Set the Nimbus look and feel */
|
||||||
|
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
|
||||||
|
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
|
||||||
|
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
|
||||||
|
*/
|
||||||
|
try {
|
||||||
|
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
|
||||||
|
if ("Nimbus".equals(info.getName())) {
|
||||||
|
javax.swing.UIManager.setLookAndFeel(info.getClassName());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (ClassNotFoundException ex) {
|
||||||
|
java.util.logging.Logger.getLogger(Frame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||||
|
} catch (InstantiationException ex) {
|
||||||
|
java.util.logging.Logger.getLogger(Frame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||||
|
} catch (IllegalAccessException ex) {
|
||||||
|
java.util.logging.Logger.getLogger(Frame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||||
|
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
|
||||||
|
java.util.logging.Logger.getLogger(Frame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||||
|
}
|
||||||
|
//</editor-fold>
|
||||||
|
|
||||||
|
/* Create and display the form */
|
||||||
|
java.awt.EventQueue.invokeLater(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
new Frame().setVisible(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||||
|
private ch.psi.plot.jlchart.LinePlot plot;
|
||||||
|
// End of variables declaration//GEN-END:variables
|
||||||
|
}
|
||||||
@@ -9,6 +9,7 @@ import ch.psi.plot.utils.SwingUtils;
|
|||||||
import ch.psi.plot.xy.generator.Sinus;
|
import ch.psi.plot.xy.generator.Sinus;
|
||||||
import ch.psi.plot.xy.generator.XYGenerator;
|
import ch.psi.plot.xy.generator.XYGenerator;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for the LinePlot class
|
* Test for the LinePlot class
|
||||||
@@ -20,19 +21,22 @@ public class LinePlotTest {
|
|||||||
{
|
{
|
||||||
//LinePlot linePlot = ServiceLoader.load(LinePlot.class).iterator().next();
|
//LinePlot linePlot = ServiceLoader.load(LinePlot.class).iterator().next();
|
||||||
//LinePlot linePlot = new ch.psi.plot.jlchart.LinePlot();
|
//LinePlot linePlot = new ch.psi.plot.jlchart.LinePlot();
|
||||||
//LinePlot linePlot = new ch.psi.plot.jfree.LinePlot();
|
LinePlot linePlot = new ch.psi.plot.jfree.LinePlot();
|
||||||
LinePlot linePlot = new ch.psi.plot.javafx.LinePlot() ;
|
//LinePlot linePlot = new ch.psi.plot.javafx.LinePlot() ;
|
||||||
|
|
||||||
linePlot.setTitle("Title");
|
linePlot.setTitle("Title");
|
||||||
|
//linePlot.getAxis(Plot.AxisId.X).setLabel("aaa");
|
||||||
|
//linePlot.getAxis(Plot.AxisId.Y).setLabel("bbb");
|
||||||
|
|
||||||
//linePlot.setRangeX(0,10000);
|
//linePlot.setRangeX(0,10000);
|
||||||
//linePlot.setRangeY(0,10);
|
//linePlot.setRangeY(0,10);
|
||||||
//linePlot.setData(getDataFromGenerator(1));
|
//linePlot.setData(getDataFromGenerator(1));
|
||||||
addDataFromGenerator(0, 10, 1000, linePlot);
|
addDataFromGenerator(0, 10, 1000, linePlot);
|
||||||
|
|
||||||
JFrame frame = new JFrame();
|
JFrame frame = new JFrame();
|
||||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
frame.setContentPane(linePlot.getChartPanel());
|
//frame.setContentPane(linePlot.getChartPanel());
|
||||||
|
frame.setContentPane((JPanel)linePlot);
|
||||||
frame.pack();
|
frame.pack();
|
||||||
SwingUtils.centerOnScreen(frame);
|
SwingUtils.centerOnScreen(frame);
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
|
|||||||
@@ -3,11 +3,10 @@
|
|||||||
*/
|
*/
|
||||||
import ch.psi.plot.MatrixPlotSeries;
|
import ch.psi.plot.MatrixPlotSeries;
|
||||||
import ch.psi.plot.Plot;
|
import ch.psi.plot.Plot;
|
||||||
|
import ch.psi.plot.PlotBase;
|
||||||
import ch.psi.plot.xyz.generator.Gauss2D;
|
import ch.psi.plot.xyz.generator.Gauss2D;
|
||||||
|
|
||||||
//import ch.psi.sls.xasec.data.DataSet;
|
|
||||||
//import ch.psi.sls.xasec.data.DataSetUtils;
|
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JPanel;
|
||||||
import javax.swing.WindowConstants;
|
import javax.swing.WindowConstants;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -26,6 +25,7 @@ public class MatrixPlotTest {
|
|||||||
final static Gauss2D generator = new Gauss2D(50, 500, 40, 800, 2);
|
final static Gauss2D generator = new Gauss2D(50, 500, 40, 800, 2);
|
||||||
|
|
||||||
public static void main(final String[] args) throws InterruptedException {
|
public static void main(final String[] args) throws InterruptedException {
|
||||||
|
PlotBase.setLighweightPopups(false);
|
||||||
final ch.psi.plot.MatrixPlot plot = new ch.psi.plot.jzy3d.MatrixPlot();
|
final ch.psi.plot.MatrixPlot plot = new ch.psi.plot.jzy3d.MatrixPlot();
|
||||||
//final ch.psi.plot.MatrixPlot plot=new ch.psi.plot.jfree.MatrixPlot();
|
//final ch.psi.plot.MatrixPlot plot=new ch.psi.plot.jfree.MatrixPlot();
|
||||||
|
|
||||||
@@ -35,9 +35,12 @@ public class MatrixPlotTest {
|
|||||||
plot.setTitle("Matrix Plot Test");
|
plot.setTitle("Matrix Plot Test");
|
||||||
//plot.getAxis(Plot.AxisId.Z).setRange(2.0, 3.0);
|
//plot.getAxis(Plot.AxisId.Z).setRange(2.0, 3.0);
|
||||||
//plot.addSeries(data);
|
//plot.addSeries(data);
|
||||||
|
// plot.getAxis(Plot.AxisId.X).setLabel("aaa");
|
||||||
|
// plot.getAxis(Plot.AxisId.Y).setLabel("bbb");
|
||||||
|
// plot.getAxis(Plot.AxisId.Z).setLabel("ccc");
|
||||||
|
|
||||||
final JFrame frame = new JFrame("");
|
final JFrame frame = new JFrame("");
|
||||||
frame.setContentPane(plot.getChartPanel());
|
frame.setContentPane((JPanel)plot);
|
||||||
frame.pack();
|
frame.pack();
|
||||||
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); // Close application if frame is closed
|
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); // Close application if frame is closed
|
||||||
|
|
||||||
|
|||||||
@@ -5,10 +5,8 @@ import ch.psi.plot.MatrixPlotSeries;
|
|||||||
import ch.psi.plot.Plot;
|
import ch.psi.plot.Plot;
|
||||||
import ch.psi.plot.xyz.generator.Gauss2D;
|
import ch.psi.plot.xyz.generator.Gauss2D;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
|
||||||
//import ch.psi.sls.xasec.data.DataSet;
|
|
||||||
//import ch.psi.sls.xasec.data.DataSetUtils;
|
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JPanel;
|
||||||
import javax.swing.WindowConstants;
|
import javax.swing.WindowConstants;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -47,7 +45,7 @@ public class MatrixPlotTest2 {
|
|||||||
|
|
||||||
|
|
||||||
final JFrame frame = new JFrame("");
|
final JFrame frame = new JFrame("");
|
||||||
frame.setContentPane(plot.getChartPanel());
|
frame.setContentPane((JPanel)plot);
|
||||||
frame.pack();
|
frame.pack();
|
||||||
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); // Close application if frame is closed
|
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); // Close application if frame is closed
|
||||||
java.awt.EventQueue.invokeLater(new Runnable() {
|
java.awt.EventQueue.invokeLater(new Runnable() {
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ public class LinePlotTest {
|
|||||||
//addDataFromGenerator(0, 10, 1000, linePlot);
|
//addDataFromGenerator(0, 10, 1000, linePlot);
|
||||||
JFrame frame = new JFrame();
|
JFrame frame = new JFrame();
|
||||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
frame.setContentPane(linePlot.getChartPanel());
|
frame.setContentPane((JPanel)linePlot);
|
||||||
frame.pack();
|
frame.pack();
|
||||||
SwingUtils.centerOnScreen(frame);
|
SwingUtils.centerOnScreen(frame);
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
@@ -94,7 +94,7 @@ public class LinePlotTest {
|
|||||||
for (int i = 0; i < 1; i++) {
|
for (int i = 0; i < 1; i++) {
|
||||||
LinePlotSeries[] d = loadDataFromGenerator(linePlot);
|
LinePlotSeries[] d = loadDataFromGenerator(linePlot);
|
||||||
//linePlot.addSeries(d);
|
//linePlot.addSeries(d);
|
||||||
JPanel chartPanel = linePlot.getChartPanel();
|
JPanel chartPanel = (JPanel) linePlot;
|
||||||
JFrame frame = new JFrame();
|
JFrame frame = new JFrame();
|
||||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
frame.setContentPane(chartPanel);
|
frame.setContentPane(chartPanel);
|
||||||
@@ -120,7 +120,7 @@ public class LinePlotTest {
|
|||||||
linePlot.addSeries(getDataFromGenerator(1, linePlot));
|
linePlot.addSeries(getDataFromGenerator(1, linePlot));
|
||||||
JFrame frame = new JFrame();
|
JFrame frame = new JFrame();
|
||||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
frame.setContentPane(linePlot.getChartPanel());
|
frame.setContentPane((JPanel)linePlot);
|
||||||
frame.pack();
|
frame.pack();
|
||||||
SwingUtils.centerOnScreen(frame);
|
SwingUtils.centerOnScreen(frame);
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
@@ -149,7 +149,7 @@ public class LinePlotTest {
|
|||||||
|
|
||||||
JFrame frame = new JFrame();
|
JFrame frame = new JFrame();
|
||||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
frame.setContentPane(linePlot.getChartPanel());
|
frame.setContentPane((JPanel)linePlot);
|
||||||
frame.pack();
|
frame.pack();
|
||||||
SwingUtils.centerOnScreen(frame);
|
SwingUtils.centerOnScreen(frame);
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
@@ -170,7 +170,7 @@ public class LinePlotTest {
|
|||||||
|
|
||||||
JFrame frame = new JFrame();
|
JFrame frame = new JFrame();
|
||||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
frame.setContentPane(linePlot.getChartPanel());
|
frame.setContentPane((JPanel)linePlot);
|
||||||
frame.pack();
|
frame.pack();
|
||||||
SwingUtils.centerOnScreen(frame);
|
SwingUtils.centerOnScreen(frame);
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
@@ -197,7 +197,7 @@ public class LinePlotTest {
|
|||||||
linePlot.addSeries(getDataFromFile());
|
linePlot.addSeries(getDataFromFile());
|
||||||
JFrame frame = new JFrame();
|
JFrame frame = new JFrame();
|
||||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
frame.setContentPane(linePlot.getChartPanel());
|
frame.setContentPane((JPanel)linePlot);
|
||||||
frame.pack();
|
frame.pack();
|
||||||
SwingUtils.centerOnScreen(frame);
|
SwingUtils.centerOnScreen(frame);
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
|
|||||||
Reference in New Issue
Block a user