Charts are JPanel instances (GUI builder), uniformization of menu, copy, print...

This commit is contained in:
2014-09-08 18:03:33 +02:00
parent 73cdc280c0
commit f6539cc630
17 changed files with 1149 additions and 613 deletions

View File

@@ -12,6 +12,7 @@ import java.io.IOException;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
/**
* TODO: FDA calls to .update -> requestUpdate()
@@ -27,10 +28,15 @@ abstract public class LinePlotBase extends PlotBase<LinePlotSeries> implements L
protected LinePlotBase(String 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
@Override
@@ -102,7 +108,8 @@ abstract public class LinePlotBase extends PlotBase<LinePlotSeries> implements L
//Injecting specific entries in popup menu
@Override
protected void onCreatedPanel() {
protected void createPopupMenu() {
super.createPopupMenu();
addPopupMenuItem(null);//Separator
// Detach plot into a separate frame
JMenu detachPlotMenu = new JMenu("Detach");
@@ -124,13 +131,13 @@ abstract public class LinePlotBase extends PlotBase<LinePlotSeries> implements L
}
JFrame frame = new JFrame(getTitle());
frame.setContentPane(p.getChartPanel());
frame.setContentPane((JPanel)p);
frame.pack();
SwingUtils.centerOnScreen(frame);
frame.setVisible(true);
frame.requestFocus();
} catch (Exception ex) {
SwingUtils.showException(getChartPanel(), ex);
SwingUtils.showException(LinePlotBase.this, ex);
}
}
};

View File

@@ -3,7 +3,6 @@
*/
package ch.psi.plot;
import ch.psi.plot.utils.SwingUtils;
import java.awt.Color;
/**
@@ -17,11 +16,9 @@ public class LinePlotSeries extends PlotSeries<LinePlot> {
void onSeriesAppendData(LinePlotSeries series, double x, double y);
}
public LinePlotSeries(String name) {
//If create a random color in none is provided - but it is deterministic if name is provided
this(name, ((name!=null)&& (name.length()>0)) ?
SwingUtils.generateRandomColor(name.hashCode()) :
SwingUtils.generateRandomColor());
this(name, /*SwingUtils.generateRandomColor()*/ null);
}
public LinePlotSeries(String name, Color color) {

View File

@@ -9,10 +9,10 @@ import ch.psi.plot.utils.SwingUtils;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.util.HashMap;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
/**
*
@@ -25,10 +25,15 @@ abstract public class MatrixPlotBase extends PlotBase<MatrixPlotSeries> implemen
protected MatrixPlotBase(String title) {
super(MatrixPlotSeries.class, title);
}
@Override
protected void createChart() {
super.createChart();
createAxis(AxisId.X, "X");
createAxis(AxisId.Y, "Y");
createAxis(AxisId.Z);
}
}
//Only supporting one series for now so let's gain some speed
@Override
@@ -98,7 +103,8 @@ abstract public class MatrixPlotBase extends PlotBase<MatrixPlotSeries> implemen
//Injecting specific entries in popup menu
@Override
protected void onCreatedPanel() {
protected void createPopupMenu() {
super.createPopupMenu();
addPopupMenuItem(null);//Separator
// Detach plot into a separate frame
JMenu detachPlotMenu = new JMenu("Detach");
@@ -123,12 +129,12 @@ abstract public class MatrixPlotBase extends PlotBase<MatrixPlotSeries> implemen
detachedSeries.setData(s.getData());
JFrame frame = new JFrame(getTitle());
frame.setContentPane(p.getChartPanel());
frame.setContentPane((JPanel)p);
frame.pack();
SwingUtils.centerOnScreen(frame);
frame.setVisible(true);
} catch (Exception ex) {
SwingUtils.showException(getChartPanel(), ex);
SwingUtils.showException(MatrixPlotBase.this, ex);
}
}
};

View File

@@ -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
public void update(boolean deferred);
@@ -32,6 +30,8 @@ public interface Plot<T extends PlotSeries> {
public BufferedImage getSnapshot();
public void saveSnapshot(String filename, String format) throws IOException;
public void copy();
//Series list management
public void addSeries(T series);

View File

@@ -4,10 +4,25 @@
package ch.psi.plot;
import ch.psi.plot.utils.IO;
import ch.psi.plot.utils.MonitoredPanel;
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.ActionListener;
import java.awt.geom.AffineTransform;
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.lang.reflect.Array;
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 FIELD_SEPARATOR = "\t";
protected static final int PREFERRED_WIDTH = 500;
protected static final int PREFERRED_HEIGHT = 270;
final Class seriesType;
protected PlotBase(Class<T> seriesType) {
this(seriesType, null);
}
volatile boolean instantiated;
protected PlotBase(Class<T> seriesType, String title) {
super();
if (title == null) {
title = "Plot";
}
setTitle(title);
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;
public void setTitle(String title) {
public void setTitle(String title) {
this.title = title;
if (instantiated)
onTitleChanged();
}
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
* window state;
*/
@Override
public BufferedImage getSnapshot() {
return SwingUtils.createImage(getChartPanel());
return SwingUtils.createImage(this);
}
@Override
public void saveSnapshot(String filename, String format) throws IOException {
IO.writeImageToFile(getSnapshot(), filename, format);
}
JPanel panel;
public JPanel getChartPanel() {
if (panel == null) {
panel = createChartPanel();
addPopupMenuItem(null);//Separator
JMenuItem saveData = new JMenuItem("Save Data");
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);
}
public void copy() {
BufferedImage img = getSnapshot();
if (img != null) {
ImageTransferHandler imageSelection = new ImageTransferHandler(img);
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(imageSelection, new ClipboardOwner() {
@Override
public void lostOwnership(Clipboard clipboard, Transferable contents) {
}
});
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 onCreatedPanel() {
protected void createChart() {
}
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
@@ -188,7 +296,7 @@ abstract public class PlotBase<T extends PlotSeries> implements Plot<T> {
//Series list support
final HashMap<String, T> seriesList = new HashMap<>();
volatile int seriesID=1;
volatile int seriesID = 1;
@Override
public void addSeries(T series) {
@@ -206,7 +314,7 @@ abstract public class PlotBase<T extends PlotSeries> implements Plot<T> {
seriesList.put(series.name, series);
}
series.setPlot(this);
series.id=seriesID++;
series.id = seriesID++;
series.setToken(onAddedSeries(series));
}
@@ -219,7 +327,7 @@ abstract public class PlotBase<T extends PlotSeries> implements Plot<T> {
@Override
public void removeSeries(T series) {
if (series!=null){
if (series != null) {
if (series.getPlot() == this) {
series.setPlot(null);
}
@@ -253,12 +361,13 @@ abstract public class PlotBase<T extends PlotSeries> implements Plot<T> {
}
public class SeriesComparator implements Comparator<T> {
@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));
}
}
}
@Override
public T[] getAllSeries() {
synchronized (seriesList) {
@@ -333,6 +442,12 @@ abstract public class PlotBase<T extends PlotSeries> implements Plot<T> {
}
//Axis Callbacks
protected void onTitleChanged() {
if (isUpdatesEnabled()) {
doUpdate();
}
}
protected void onAxisLabelChanged(AxisId axis) {
if (isUpdatesEnabled()) {
doUpdate();
@@ -343,29 +458,30 @@ abstract public class PlotBase<T extends PlotSeries> implements Plot<T> {
if (isUpdatesEnabled()) {
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;
public static void setLighweightPopups(boolean value){
lighweightPopups=value;
if (javax.swing.JPopupMenu.getDefaultLightWeightPopupEnabled()!=value){
//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;
public static void setLighweightPopups(boolean value) {
lighweightPopups = value;
if (javax.swing.JPopupMenu.getDefaultLightWeightPopupEnabled() != value) {
javax.swing.JPopupMenu.setDefaultLightWeightPopupEnabled(lighweightPopups);
}
}
public static boolean getLighweightPopups(){
return lighweightPopups;
}
}
public static boolean getLighweightPopups() {
return lighweightPopups;
}
}

View File

@@ -43,7 +43,6 @@ import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
/**
@@ -55,10 +54,55 @@ public class LinePlot extends ch.psi.plot.LinePlotBase {
public LinePlot() {
super();
createChart();
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<>();
@Override
@@ -153,11 +197,33 @@ public class LinePlot extends ch.psi.plot.LinePlotBase {
private JFXPanel fxContainer;
@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));
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.add(fxContainer);
setLayout(new BorderLayout());
add(fxContainer);
// create JavaFX scene
Platform.runLater(new Runnable() {
@@ -166,7 +232,6 @@ public class LinePlot extends ch.psi.plot.LinePlotBase {
createScene();
}
});
return panel;
}
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;
}
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;
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;
public void setUpContextMenu() {

View File

@@ -3,10 +3,15 @@ package ch.psi.plot.jfree;
import ch.psi.plot.LinePlotBase;
import ch.psi.plot.LinePlotSeries;
import java.awt.BasicStroke;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
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.util.Collection;
import java.util.List;
@@ -16,7 +21,6 @@ import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.KeyStroke;
import javax.swing.SwingUtilities;
import org.jfree.chart.ChartFactory;
@@ -65,8 +69,7 @@ public class LinePlot extends LinePlotBase {
* @param title Title of plot
*/
public LinePlot() {
super();
data = new XYSeriesCollection();
super();
}
@Override
@@ -152,7 +155,10 @@ public class LinePlot extends LinePlotBase {
* @return
*/
@Override
protected JPanel createChartPanel() {
protected void createChart() {
super.createChart();
data = new XYSeriesCollection();
// Create chart
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);
// Lazy creation of the chart panel
chartPanel = new ChartPanel(chart);
chartPanel.setName(getTitle());
chartPanel = new ChartPanel(chart);
// Remove border
chartPanel.getChart().setBorderVisible(false);
// Set size of chart
chartPanel.setPreferredSize(new java.awt.Dimension(PREFERRED_WIDTH, PREFERRED_HEIGHT));
// Add more items to the context menu
amendContextMenu();
//Activate (arrow) keys
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
*
@@ -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
*/
public void amendContextMenu() {
chartPanel.getPopupMenu().addSeparator();
@Override
protected void createPopupMenu() {
//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");
chartPanel.getPopupMenu().add(toolsMenu);
@@ -394,7 +420,7 @@ public class LinePlot extends LinePlotBase {
dseries.setData(derivative[0], derivative[1]);
}
JFrame frame = new JFrame();
frame.setContentPane(p.getChartPanel());
frame.setContentPane(p);
frame.pack();
RefineryUtilities.centerFrameOnScreen(frame);
frame.setVisible(true);
@@ -417,7 +443,7 @@ public class LinePlot extends LinePlotBase {
dseries.setData(integral[0], integral[1]);
}
JFrame frame = new JFrame();
frame.setContentPane(p.getChartPanel());
frame.setContentPane(p);
frame.pack();
RefineryUtilities.centerFrameOnScreen(frame);
frame.setVisible(true);
@@ -441,7 +467,7 @@ public class LinePlot extends LinePlotBase {
}
JFrame frame = new JFrame();
frame.setContentPane(p.getChartPanel());
frame.setContentPane(p);
frame.pack();
RefineryUtilities.centerFrameOnScreen(frame);
frame.setVisible(true);
@@ -487,7 +513,7 @@ public class LinePlot extends LinePlotBase {
}
});
chartPanel.getPopupMenu().add(hideToolTipsMenuItem);
super.createPopupMenu();
}
private void showTooltips() {
@@ -540,4 +566,9 @@ public class LinePlot extends LinePlotBase {
this.data = (XYSeriesCollection) data;
}
*/
@Override
public int print(Graphics g, PageFormat pf, int page) throws PrinterException {
return chartPanel.print(g, pf, page);
}
}

View File

@@ -2,15 +2,18 @@ package ch.psi.plot.jfree;
import ch.psi.plot.MatrixPlotBase;
import ch.psi.plot.MatrixPlotSeries;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.print.PageFormat;
import java.awt.print.PrinterException;
import java.text.DecimalFormat;
import java.util.Arrays;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
@@ -53,54 +56,11 @@ public class MatrixPlot extends MatrixPlotBase {
* @param data
*/
XYPlot plot;
final NumberAxis xAxis, yAxis;
final XYBlockRenderer renderer;
NumberAxis xAxis, yAxis;
XYBlockRenderer renderer;
public MatrixPlot() {
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;
@@ -122,8 +82,6 @@ public class MatrixPlot extends MatrixPlotBase {
onAxisRangeChanged(AxisId.X);
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.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;
}
@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
protected void onAxisRangeChanged(AxisId axis_id) {
@@ -215,11 +194,11 @@ public class MatrixPlot extends MatrixPlotBase {
return ret;
}
// Action Classes that implement methods called after keyboard input
/**
* Adapt the context menu of the chart panel
*/
private void adaptContextMenu(final ChartPanel chartPanel) {
@Override
protected void createPopupMenu() {
//Remove copy/save as/print menus: copy is buggy, save is limited
for (int index=6;index>=2;index--)
chartPanel.getPopupMenu().remove(index);
// Show hide tooltips
final String tooltipsMenuLabel = "Tooltips";
@@ -310,7 +289,7 @@ public class MatrixPlot extends MatrixPlotBase {
final JFrame frame = new JFrame(title);
frame.getContentPane();
frame.setContentPane(p.getChartPanel());
frame.setContentPane(p);
frame.pack();
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);
*/
super.createPopupMenu();
}
/**
@@ -357,9 +337,11 @@ public class MatrixPlot extends MatrixPlotBase {
* is created
*/
public void adaptColorMapScale() {
double[] v = series.minMaxZValue();
if (v[0] != Double.NaN && v[1] != Double.NaN && v[0] < v[1]) {
setColorScale(v[0], v[1]);
if (series!=null){
double[] v = series.minMaxZValue();
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
*/
@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);
//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));
//All interactive menu items
adaptContextMenu(chartPanel);
return chartPanel;
}
setLayout(new BorderLayout());
add(chartPanel); }
/* (non-Javadoc)
* @see ch.psi.plot.Plot#update()
@@ -475,6 +501,12 @@ public class MatrixPlot extends MatrixPlotBase {
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() {
// return chart;

View File

@@ -5,7 +5,7 @@ package ch.psi.plot.jlchart;
import ch.psi.plot.LinePlotBase;
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.JLAxis;
import fr.esrf.tangoatk.widget.util.chart.JLChart;
@@ -14,75 +14,51 @@ import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.util.ArrayList;
import java.util.Random;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
/**
*
*/
public class LinePlot extends LinePlotBase {
final JLChart plot;
JLChart plot;
final ArrayList<JLDataView> views = new ArrayList<>();
public LinePlot() {
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);
}
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
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);
}
int colorIndex=0;
@Override
protected Object onAddedSeries(LinePlotSeries series) {
JLDataView view = new JLDataView();
view.setColor(series.getColor());
Color color = 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);
int markerSize = 4;
view.setName(series.getName());
view.setMarkerSize(markerSize);
view.setMarkerColor(series.getColor());
view.setMarkerColor(color);
view.setViewType(JLDataView.TYPE_LINE);
@@ -165,24 +141,97 @@ public class LinePlot extends LinePlotBase {
return new double[][]{x, y};
}
JPanel chartPanel;
@Override
protected JPanel createChartPanel() {
JPanel chartPanel = new MonitoredPanel() {
protected void onShown() {
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);
chartPanel.setPreferredSize(new Dimension(PREFERRED_WIDTH, PREFERRED_HEIGHT));
/*
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));
setLayout(new BorderLayout());
add(plot);
setPreferredSize(new Dimension(PREFERRED_WIDTH, PREFERRED_HEIGHT));
plot.setHeader(getTitle());
plot.getY1Axis().setName(getAxis(AxisId.Y).getLabel());
plot.getXAxis().setName(getAxis(AxisId.Y).getLabel());
return chartPanel;
plot.getXAxis().setName(getAxis(AxisId.X).getLabel());
}
@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

View File

@@ -6,12 +6,10 @@ package ch.psi.plot.jzy3d;
import ch.psi.plot.MatrixPlotBase;
import ch.psi.plot.MatrixPlotSeries;
import ch.psi.plot.utils.IO;
import ch.psi.plot.utils.MonitoredPanel;
import ch.psi.plot.utils.SwingUtils;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
@@ -26,12 +24,10 @@ import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.media.opengl.GLAnimatorControl;
import javax.media.opengl.awt.GLCanvas;
import javax.swing.ButtonGroup;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.SwingUtilities;
@@ -65,7 +61,6 @@ import org.jzy3d.plot3d.rendering.view.modes.ViewBoundMode;
*/
public class MatrixPlot extends MatrixPlotBase {
JPanel panel;
private Chart chart;
GLAnimatorControl animatorControl;
IScreenCanvas screenCanvas;
@@ -73,6 +68,7 @@ public class MatrixPlot extends MatrixPlotBase {
private Shape surface;
private MatrixPlotSeries series;
private double[][] data;
JPopupMenu menuPopup;
enum CanvasType {
@@ -84,40 +80,44 @@ public class MatrixPlot extends MatrixPlotBase {
public MatrixPlot() {
super();
panel = new MonitoredPanel() {
@Override
protected void onShown() {
}
@Override
protected void onShown() {
// if ((chart == null) && (series != null)) {
if (series != null) {
SwingUtilities.invokeLater(new Runnable() { //Invoking later because was not rendering when setting date with FDA
@Override
public void run() {
createGraph();
}
});
}
else
checkBounds(true);
if (series != null) {
SwingUtilities.invokeLater(new Runnable() { //Invoking later because was not rendering when setting date with FDA
@Override
public void run() {
createGraph();
}
});
}
else
checkBounds(true);
}
protected void onHidden() {
if (chart != null) {
chart.stopAnimator();
panel.removeAll();
chart.dispose();
chart = null;
}
}
};
panel.setLayout(new BorderLayout());
protected void onHidden() {
if (chart != null) {
chart.stopAnimator();
removeAll();
chart.dispose();
chart = null;
}
}
@Override
protected void createChart() {
super.createChart();
setLayout(new BorderLayout());
//panel.setLayout(new GridLayout(1,1));
setColormap(Colormap.TEMPERATURE);
if (getHardwareAccelerated() != Settings.getInstance().isHardwareAccelerated()) {
Settings.getInstance().setHardwareAccelerated(getHardwareAccelerated());
}
panel.setPreferredSize(new Dimension(PREFERRED_WIDTH, PREFERRED_HEIGHT));
setupPopupMenu();
}
setPreferredSize(new Dimension(PREFERRED_WIDTH, PREFERRED_HEIGHT));
menuPopup = new JPopupMenu();
}
@Override
protected Object onAddedSeries(final MatrixPlotSeries s) {
@@ -179,7 +179,7 @@ public class MatrixPlot extends MatrixPlotBase {
series = s;
}
}
if ((panel != null) && (panel.isShowing())) {
if (isShowing()) {
createGraph();
}
return this;
@@ -225,86 +225,91 @@ public class MatrixPlot extends MatrixPlotBase {
return data;
}
@Override
protected JPanel createChartPanel() {
return panel;
}
private Range rangeX;
private Range rangeY;
double[] rangeZ = null;
boolean showLegend = true;
Boolean showLegend;
public void setShowLegend(boolean value) {
if (value != showLegend) {
if (value != getShowLegend()) {
showLegend = value;
if ((panel != null) && (panel.isShowing())) {
if (isShowing()) {
updateGraph(true);
}
}
}
public boolean getShowLegend() {
if (showLegend==null)
return true;
return showLegend;
}
boolean showFace = true;
Boolean showFace;
public void setShowFace(boolean value) {
if (value != showFace) {
if (value != getShowFace()) {
showFace = value;
if ((panel != null) && (panel.isShowing())) {
if (isShowing()) {
updateGraph(true);
}
}
}
public boolean getShowFace() {
if (showFace==null)
return true;
return showFace;
}
boolean showFrame = false;
Boolean showFrame;
public void setShowFrame(boolean value) {
if (value != showFrame) {
if (value != getShowFrame()) {
showFrame = value;
if ((panel != null) && (panel.isShowing())) {
if (isShowing()) {
updateGraph(true);
}
}
}
public boolean getShowFrame() {
if (showFrame==null)
return false;
return showFrame;
}
boolean showAxis = true;
Boolean showAxis;
public void setShowAxis(boolean value) {
if (value != showAxis) {
if (value != getShowAxis()) {
showAxis = value;
if ((panel != null) && (panel.isShowing())) {
if (isShowing()) {
updateGraph(true);
}
}
}
public boolean getShowAxis() {
if (showAxis==null)
return true;
return showAxis;
}
boolean continuousRendering = false;
Boolean continuousRendering;
public void setContinuousRendering(boolean value) {
if (value != continuousRendering) {
if (value != getContinuousRendering()) {
continuousRendering = value;
if ((panel != null) && (panel.isShowing())) {
if (isShowing()) {
createGraph();
}
}
}
public boolean getContinuousRendering() {
if (continuousRendering==null)
return false;
return continuousRendering;
}
@@ -313,18 +318,20 @@ public class MatrixPlot extends MatrixPlotBase {
GRAYSCALE,
TEMPERATURE,
}
Colormap colormap = Colormap.TEMPERATURE;
Colormap colormap;
public void setColormap(Colormap value) {
if (value != colormap) {
if (value != getColormap()) {
colormap = value;
if ((panel != null) && (panel.isShowing())) {
if (isShowing()) {
updateGraph(true);
}
}
}
public Colormap getColormap() {
if (colormap==null)
return Colormap.TEMPERATURE;
return colormap;
}
@@ -349,18 +356,20 @@ public class MatrixPlot extends MatrixPlotBase {
return null;
}
}
Quality quality = Quality.HIGH;
Quality quality;
public void setQuality(Quality quality) {
this.quality = quality;
if (series != null) {
if ((panel != null) && (panel.isShowing())) {
if (isShowing()) {
createGraph();
}
}
}
public Quality getQuality() {
if (quality==null)
return Quality.HIGH;
return quality;
}
@@ -382,7 +391,7 @@ public class MatrixPlot extends MatrixPlotBase {
return null;
}
}
Mode mode = Mode.FREE;
Mode mode;
public void setMode(Mode mode) {
this.mode = mode;
@@ -392,6 +401,8 @@ public class MatrixPlot extends MatrixPlotBase {
}
public Mode getMode() {
if (mode==null)
return Mode.FREE;
return mode;
}
@@ -404,22 +415,24 @@ public class MatrixPlot extends MatrixPlotBase {
CONTOUR_3D
}
Contour contour = Contour.NONE;
Contour contour;
public void setContour(Contour contour) {
this.contour = contour;
if (series != null) {
if ((panel != null) && (panel.isShowing())) {
if (isShowing()) {
createGraph();
}
}
}
public Contour getContour() {
if (contour==null)
return Contour.NONE;
return contour;
}
int contourLevels = 10;
Integer contourLevels;
public void setContourLevels(int value) {
contourLevels = value;
@@ -427,10 +440,12 @@ public class MatrixPlot extends MatrixPlotBase {
}
public int getContourLevels() {
if (contourLevels==null)
return 10;
return contourLevels;
}
int contourDensity = 400;
Integer contourDensity;
public void setContourDensity(int value) {
contourDensity = value;
@@ -438,10 +453,12 @@ public class MatrixPlot extends MatrixPlotBase {
}
public int getContourDensity() {
if (contourDensity==null)
return 400;
return contourDensity;
}
java.awt.Color frameColor = java.awt.Color.BLACK;
java.awt.Color frameColor;
public void setFrameColor(java.awt.Color value) {
frameColor = value;
@@ -449,10 +466,12 @@ public class MatrixPlot extends MatrixPlotBase {
}
public java.awt.Color getFrameColor() {
if (frameColor==null)
return java.awt.Color.BLACK;
return frameColor;
}
boolean hideEmptyRows = true;
Boolean hideEmptyRows;
/**
* By default empty lines (containing only NaN) are not plotted.
@@ -463,208 +482,11 @@ public class MatrixPlot extends MatrixPlotBase {
}
public boolean getHideEmptyRows() {
if (hideEmptyRows==null)
return true;
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) {
List<AbstractDrawable> polygons = shape.getDrawables();
for (AbstractDrawable d : polygons) {
@@ -735,12 +557,12 @@ public class MatrixPlot extends MatrixPlotBase {
}
panel.removeAll();
panel.add(canvas);
MatrixPlot.this.removeAll();
MatrixPlot.this.add(canvas);
//Todo: why it is not displyed if I don'r pack the Window?
if (panel.isVisible()) {
panel.validate();
if (MatrixPlot.this.isVisible()) {
MatrixPlot.this.validate();
}
chart.addMouseController();
@@ -769,7 +591,7 @@ public class MatrixPlot extends MatrixPlotBase {
public void mouseReleased(com.jogamp.newt.event.MouseEvent e) {
if ((e.getButton() == com.jogamp.newt.event.MouseEvent.BUTTON3) &&
(!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)) {
@@ -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) {
@@ -868,7 +887,7 @@ public class MatrixPlot extends MatrixPlotBase {
//if (true) {
surface = (Shape) Builder.buildOrthonormal(
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().getZmax() : getAxis(AxisId.Z).getMax()),
new Color(1, 1, 1, .5f));
@@ -876,7 +895,7 @@ public class MatrixPlot extends MatrixPlotBase {
surface.setFaceDisplayed(true);
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());
if (getShowLegend()) {
AWTColorbarLegend cbar = new AWTColorbarLegend(surface, chart.getView().getAxe().getLayout());
@@ -955,6 +974,14 @@ public class MatrixPlot extends MatrixPlotBase {
}
//System.out.println(System.currentTimeMillis()-start);
}
if (newSeries){
if (!getContinuousRendering() && (animatorControl != null)) {
if (animatorControl.isPaused()) {
screenCanvas.display();
}
}
}
}
protected boolean checkBounds(boolean updateBounds) {
@@ -970,7 +997,7 @@ public class MatrixPlot extends MatrixPlotBase {
//If manual bounds
if ( manual_bounds) {
//Deferring setting bounds untiul the panel is displayed
if (panel.isShowing() && (chart != null)) {
if (isShowing() && (chart != null)) {
if (chart.getView().getBoundsMode() != ViewBoundMode.MANUAL) {
changed = true;
}

View File

@@ -7,11 +7,19 @@ import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.Random;
import javax.swing.JComponent;
import javax.swing.JLabel;
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);
}
public static Color generateRandomColor(long seed) {
public static Color generateRandomColor(long seed) {
Random random = new Random(seed);
return generateRandomColor(random);
}
public static Color generateRandomColor() {
public static Color generateRandomColor() {
Random random = new Random();
return generateRandomColor(random);
}
static Color generateRandomColor(Random random) {
public static Color generateRandomColor(Random random) {
Color mix = Color.WHITE;
int red = (random.nextInt(256) + mix.getRed()) / 2;
@@ -59,10 +67,16 @@ public class SwingUtils {
public static void showException(Component parent, Exception ex) {
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) {
return JOptionPane.showInputDialog(parent, msg, String.valueOf(current_value));
}
public static BufferedImage createImage(Component panel) {
if (panel == null) {
@@ -74,5 +88,97 @@ public class SwingUtils {
Graphics2D g2 = image.createGraphics();
panel.paint(g2);
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;
}
}
}

View 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>

View 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
}

View File

@@ -9,6 +9,7 @@ import ch.psi.plot.utils.SwingUtils;
import ch.psi.plot.xy.generator.Sinus;
import ch.psi.plot.xy.generator.XYGenerator;
import javax.swing.JFrame;
import javax.swing.JPanel;
/**
* Test for the LinePlot class
@@ -20,19 +21,22 @@ public class LinePlotTest {
{
//LinePlot linePlot = ServiceLoader.load(LinePlot.class).iterator().next();
//LinePlot linePlot = new ch.psi.plot.jlchart.LinePlot();
//LinePlot linePlot = new ch.psi.plot.jfree.LinePlot();
LinePlot linePlot = new ch.psi.plot.javafx.LinePlot() ;
LinePlot linePlot = new ch.psi.plot.jfree.LinePlot();
//LinePlot linePlot = new ch.psi.plot.javafx.LinePlot() ;
linePlot.setTitle("Title");
//linePlot.getAxis(Plot.AxisId.X).setLabel("aaa");
//linePlot.getAxis(Plot.AxisId.Y).setLabel("bbb");
//linePlot.setRangeX(0,10000);
//linePlot.setRangeY(0,10);
//linePlot.setData(getDataFromGenerator(1));
addDataFromGenerator(0, 10, 1000, linePlot);
JFrame frame = new JFrame();
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(linePlot.getChartPanel());
//frame.setContentPane(linePlot.getChartPanel());
frame.setContentPane((JPanel)linePlot);
frame.pack();
SwingUtils.centerOnScreen(frame);
frame.setVisible(true);

View File

@@ -3,11 +3,10 @@
*/
import ch.psi.plot.MatrixPlotSeries;
import ch.psi.plot.Plot;
import ch.psi.plot.PlotBase;
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.JPanel;
import javax.swing.WindowConstants;
/**
@@ -26,6 +25,7 @@ public class MatrixPlotTest {
final static Gauss2D generator = new Gauss2D(50, 500, 40, 800, 2);
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.jfree.MatrixPlot();
@@ -35,9 +35,12 @@ public class MatrixPlotTest {
plot.setTitle("Matrix Plot Test");
//plot.getAxis(Plot.AxisId.Z).setRange(2.0, 3.0);
//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("");
frame.setContentPane(plot.getChartPanel());
frame.setContentPane((JPanel)plot);
frame.pack();
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); // Close application if frame is closed

View File

@@ -5,10 +5,8 @@ import ch.psi.plot.MatrixPlotSeries;
import ch.psi.plot.Plot;
import ch.psi.plot.xyz.generator.Gauss2D;
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.JPanel;
import javax.swing.WindowConstants;
/**
@@ -47,7 +45,7 @@ public class MatrixPlotTest2 {
final JFrame frame = new JFrame("");
frame.setContentPane(plot.getChartPanel());
frame.setContentPane((JPanel)plot);
frame.pack();
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); // Close application if frame is closed
java.awt.EventQueue.invokeLater(new Runnable() {

View File

@@ -73,7 +73,7 @@ public class LinePlotTest {
//addDataFromGenerator(0, 10, 1000, linePlot);
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(linePlot.getChartPanel());
frame.setContentPane((JPanel)linePlot);
frame.pack();
SwingUtils.centerOnScreen(frame);
frame.setVisible(true);
@@ -94,7 +94,7 @@ public class LinePlotTest {
for (int i = 0; i < 1; i++) {
LinePlotSeries[] d = loadDataFromGenerator(linePlot);
//linePlot.addSeries(d);
JPanel chartPanel = linePlot.getChartPanel();
JPanel chartPanel = (JPanel) linePlot;
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(chartPanel);
@@ -120,7 +120,7 @@ public class LinePlotTest {
linePlot.addSeries(getDataFromGenerator(1, linePlot));
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(linePlot.getChartPanel());
frame.setContentPane((JPanel)linePlot);
frame.pack();
SwingUtils.centerOnScreen(frame);
frame.setVisible(true);
@@ -149,7 +149,7 @@ public class LinePlotTest {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(linePlot.getChartPanel());
frame.setContentPane((JPanel)linePlot);
frame.pack();
SwingUtils.centerOnScreen(frame);
frame.setVisible(true);
@@ -170,7 +170,7 @@ public class LinePlotTest {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(linePlot.getChartPanel());
frame.setContentPane((JPanel)linePlot);
frame.pack();
SwingUtils.centerOnScreen(frame);
frame.setVisible(true);
@@ -197,7 +197,7 @@ public class LinePlotTest {
linePlot.addSeries(getDataFromFile());
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(linePlot.getChartPanel());
frame.setContentPane((JPanel)linePlot);
frame.pack();
SwingUtils.centerOnScreen(frame);
frame.setVisible(true);