added some more new classes
fixed pom
This commit is contained in:
@@ -55,12 +55,12 @@
|
||||
<snapshotRepository>
|
||||
<id>i.snapshots</id>
|
||||
<name>Artifactory Snapshots</name>
|
||||
<url>http://slsyoke1/artifactory/libs-snapshots-local</url>
|
||||
<url>http://yoke/artifactory/libs-snapshots-local</url>
|
||||
</snapshotRepository>
|
||||
<repository>
|
||||
<id>i.releases</id>
|
||||
<name>Atrifactory Releases</name>
|
||||
<url>http://slsyoke1/artifactory/libs-releases-local</url>
|
||||
<url>http://yoke/artifactory/libs-releases-local</url>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
</project>
|
||||
@@ -179,6 +179,8 @@ public class LinePlot implements Plot {
|
||||
// Up arrow
|
||||
chartPanel.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0), moveUpKey);
|
||||
chartPanel.getActionMap().put(moveUpKey, new AbstractAction() {
|
||||
// Default serial id
|
||||
private static final long serialVersionUID = 1L;
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
moverOverPlot(new XYDataItem(0.0, ((NumberAxis)chart.getXYPlot().getRangeAxis()).getTickUnit().getSize()));
|
||||
@@ -188,6 +190,8 @@ public class LinePlot implements Plot {
|
||||
// Down arrow
|
||||
chartPanel.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0),moveDownKey);
|
||||
chartPanel.getActionMap().put(moveDownKey, new AbstractAction() {
|
||||
// Default serial id
|
||||
private static final long serialVersionUID = 1L;
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
moverOverPlot(new XYDataItem(0.0, - ((NumberAxis)chart.getXYPlot().getRangeAxis()).getTickUnit().getSize()));
|
||||
@@ -197,6 +201,8 @@ public class LinePlot implements Plot {
|
||||
// Right arrow
|
||||
chartPanel.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0),moveRightKey);
|
||||
chartPanel.getActionMap().put(moveRightKey, new AbstractAction() {
|
||||
// Default serial id
|
||||
private static final long serialVersionUID = 1L;
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
moverOverPlot(new XYDataItem(((NumberAxis)chart.getXYPlot().getDomainAxis()).getTickUnit().getSize(), 0.0));
|
||||
@@ -206,6 +212,8 @@ public class LinePlot implements Plot {
|
||||
// Left arrow
|
||||
chartPanel.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0),moveLeftKey);
|
||||
chartPanel.getActionMap().put(moveLeftKey, new AbstractAction() {
|
||||
// Default serial id
|
||||
private static final long serialVersionUID = 1L;
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
moverOverPlot(new XYDataItem(- ((NumberAxis)chart.getXYPlot().getDomainAxis()).getTickUnit().getSize(), 0.0));
|
||||
|
||||
409
ch.psi.plot/src/main/java/ch/psi/plot/xyz/DynamicXYZDataset.java
Normal file
409
ch.psi.plot/src/main/java/ch/psi/plot/xyz/DynamicXYZDataset.java
Normal file
@@ -0,0 +1,409 @@
|
||||
/**
|
||||
*
|
||||
* Copyright 2011 Paul Scherrer Institute. All rights reserved.
|
||||
*
|
||||
* This code is free software: you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation, either version 3 of the License, or (at your option) any
|
||||
* later version.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but without any
|
||||
* warranty; without even the implied warranty of merchantability or fitness for
|
||||
* a particular purpose. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this code. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package ch.psi.plot.xyz;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.jfree.chart.axis.NumberAxis;
|
||||
import org.jfree.chart.renderer.xy.XYBlockRenderer;
|
||||
import org.jfree.data.DomainOrder;
|
||||
import org.jfree.data.general.DatasetChangeEvent;
|
||||
import org.jfree.data.general.DatasetChangeListener;
|
||||
import org.jfree.data.general.DatasetGroup;
|
||||
import org.jfree.data.xy.XYZDataset;
|
||||
import org.jfree.ui.RectangleAnchor;
|
||||
|
||||
/**
|
||||
* Dynamic dataset
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class DynamicXYZDataset implements XYZDataset{
|
||||
|
||||
private final double xResolution;
|
||||
private final double yResolution;
|
||||
private final double incX;
|
||||
private final double incY;
|
||||
|
||||
private final NumberAxis xAxis = new NumberAxis();
|
||||
private double xLowerBound = Double.NaN;
|
||||
private double xUpperBound = Double.NaN;
|
||||
private final NumberAxis yAxis = new NumberAxis();
|
||||
private double yLowerBound = Double.NaN;
|
||||
private double yUpperBound = Double.NaN;
|
||||
private double zLowerBound = Double.NaN;
|
||||
|
||||
|
||||
private double zUpperBound = Double.NaN;
|
||||
|
||||
private final XYBlockRenderer renderer = new XYBlockRenderer();
|
||||
|
||||
|
||||
private final List<DatasetChangeListener> listeners = new ArrayList<DatasetChangeListener>();
|
||||
private List<DynamicXYZDataset.Vector> items = new ArrayList<DynamicXYZDataset.Vector>();
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
public DynamicXYZDataset(){
|
||||
xResolution = 1.0;
|
||||
yResolution = 1.0;
|
||||
incX = xResolution/2;
|
||||
incY = yResolution/2;
|
||||
|
||||
xAxis.setRange(xLowerBound, xUpperBound);
|
||||
yAxis.setRange(yLowerBound, yUpperBound);
|
||||
|
||||
renderer.setBlockWidth(xResolution); // If this is not set the default block size is 1
|
||||
renderer.setBlockHeight(yResolution); // If this is not set the default block size is 1
|
||||
renderer.setBlockAnchor(RectangleAnchor.CENTER);
|
||||
renderer.setBaseCreateEntities(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add datapoint
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
*/
|
||||
public void addData(double x, double y, double z){
|
||||
items.add(new DynamicXYZDataset.Vector(x,y,z));
|
||||
|
||||
// Update axis
|
||||
|
||||
|
||||
// if(Double.isNaN(xLowerBound) && Double.isNaN(xUpperBound)){
|
||||
// xLowerBound = x-incX;
|
||||
// xUpperBound = x+incX;
|
||||
// xAxis.setRange(xLowerBound, xUpperBound);
|
||||
// }
|
||||
// else{
|
||||
// if(x>(xUpperBound+incX)){
|
||||
// xUpperBound = x+incX;
|
||||
// xAxis.setUpperBound(xUpperBound);
|
||||
// }
|
||||
// else if(x<xLowerBound-incX){
|
||||
// xLowerBound = x-incX;
|
||||
// xAxis.setLowerBound(xLowerBound);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if(Double.isNaN(yLowerBound) && Double.isNaN(yUpperBound)){
|
||||
// yLowerBound = y-incY;
|
||||
// yUpperBound = y+incY;
|
||||
// yAxis.setRange(yLowerBound, yUpperBound);
|
||||
// }
|
||||
// else{
|
||||
// if(y>(yUpperBound+incY)){
|
||||
// yUpperBound = y+incY;
|
||||
// yAxis.setUpperBound(yUpperBound);
|
||||
// }
|
||||
// else if(y<yLowerBound-incY){
|
||||
// yLowerBound = y-incY;
|
||||
// yAxis.setLowerBound(yLowerBound);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if(Double.isNaN(zLowerBound) && Double.isNaN(zUpperBound)){
|
||||
// zLowerBound = z;
|
||||
// zUpperBound = z;
|
||||
// }
|
||||
// else{
|
||||
// if(z>zUpperBound){
|
||||
// zUpperBound = z;
|
||||
// }
|
||||
// else if(z<zLowerBound){
|
||||
// zLowerBound = z;
|
||||
// }
|
||||
// }
|
||||
|
||||
// Inform change listeners
|
||||
// DatasetChangeEvent event = new DatasetChangeEvent(this, this);
|
||||
// for(DatasetChangeListener l: listeners){
|
||||
// l.datasetChanged(event );
|
||||
// }
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.jfree.data.xy.XYDataset#getItemCount(int)
|
||||
*/
|
||||
@Override
|
||||
public int getItemCount(int series) {
|
||||
return items.size();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.jfree.data.xy.XYDataset#getX(int, int)
|
||||
*/
|
||||
@Override
|
||||
public Number getX(int series, int item) {
|
||||
return items.get(item).getX();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.jfree.data.xy.XYDataset#getXValue(int, int)
|
||||
*/
|
||||
@Override
|
||||
public double getXValue(int series, int item) {
|
||||
return items.get(item).getX();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.jfree.data.xy.XYDataset#getY(int, int)
|
||||
*/
|
||||
@Override
|
||||
public Number getY(int series, int item) {
|
||||
return items.get(item).getY();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.jfree.data.xy.XYDataset#getYValue(int, int)
|
||||
*/
|
||||
@Override
|
||||
public double getYValue(int series, int item) {
|
||||
return items.get(item).getY();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.jfree.data.xy.XYZDataset#getZ(int, int)
|
||||
*/
|
||||
@Override
|
||||
public Number getZ(int series, int item) {
|
||||
return items.get(item).getZ();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.jfree.data.xy.XYZDataset#getZValue(int, int)
|
||||
*/
|
||||
@Override
|
||||
public double getZValue(int series, int item) {
|
||||
return items.get(item).getZ();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.jfree.data.xy.XYDataset#getDomainOrder()
|
||||
*/
|
||||
@Override
|
||||
public DomainOrder getDomainOrder() {
|
||||
return DomainOrder.NONE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.jfree.data.general.SeriesDataset#getSeriesCount()
|
||||
*/
|
||||
@Override
|
||||
public int getSeriesCount() {
|
||||
// Series not implemented/used - dataset only holds one series
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.jfree.data.general.SeriesDataset#getSeriesKey(int)
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public Comparable getSeriesKey(int series) {
|
||||
// Series not implemented/used
|
||||
return "";
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.jfree.data.general.SeriesDataset#indexOf(java.lang.Comparable)
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public int indexOf(Comparable seriesKey) {
|
||||
// Series not implemented/used
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.jfree.data.general.Dataset#getGroup()
|
||||
*/
|
||||
@Override
|
||||
public DatasetGroup getGroup() {
|
||||
// Not implemented/used
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.jfree.data.general.Dataset#setGroup(org.jfree.data.general.DatasetGroup)
|
||||
*/
|
||||
@Override
|
||||
public void setGroup(DatasetGroup group) {
|
||||
// Not implemented/used
|
||||
}
|
||||
|
||||
// Listener concept implementation
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.jfree.data.general.Dataset#addChangeListener(org.jfree.data.general.DatasetChangeListener)
|
||||
*/
|
||||
@Override
|
||||
public void addChangeListener(DatasetChangeListener listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.jfree.data.general.Dataset#removeChangeListener(org.jfree.data.general.DatasetChangeListener)
|
||||
*/
|
||||
@Override
|
||||
public void removeChangeListener(DatasetChangeListener listener) {
|
||||
listeners.remove(listener);
|
||||
}
|
||||
|
||||
|
||||
// Convenient methods
|
||||
|
||||
/**
|
||||
* @return the zLowerBound
|
||||
*/
|
||||
public double getzLowerBound() {
|
||||
return zLowerBound;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the zUpperBound
|
||||
*/
|
||||
public double getzUpperBound() {
|
||||
return zUpperBound;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the xAxis
|
||||
*/
|
||||
public NumberAxis getxAxis() {
|
||||
return xAxis;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the yAxis
|
||||
*/
|
||||
public NumberAxis getyAxis() {
|
||||
return yAxis;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the renderer
|
||||
*/
|
||||
public XYBlockRenderer getRenderer() {
|
||||
return renderer;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return the xLowerBound
|
||||
*/
|
||||
public double getxLowerBound() {
|
||||
return xLowerBound;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the xUpperBound
|
||||
*/
|
||||
public double getxUpperBound() {
|
||||
return xUpperBound;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the yLowerBound
|
||||
*/
|
||||
public double getyLowerBound() {
|
||||
return yLowerBound;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the yUpperBound
|
||||
*/
|
||||
public double getyUpperBound() {
|
||||
return yUpperBound;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
class Vector{
|
||||
private double x;
|
||||
private double y;
|
||||
private double z;
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
public Vector(){
|
||||
}
|
||||
|
||||
/**
|
||||
* @param x2
|
||||
* @param y2
|
||||
* @param z2
|
||||
*/
|
||||
public Vector(double x, double y, double z) {
|
||||
// Right now x and xvalue are the same. This might change if we introduce a virtual grid ...
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
/**
|
||||
* @return the x
|
||||
*/
|
||||
public double getX() {
|
||||
return x;
|
||||
}
|
||||
/**
|
||||
* @param x the x to set
|
||||
*/
|
||||
public void setX(double x) {
|
||||
this.x = x;
|
||||
}
|
||||
/**
|
||||
* @return the y
|
||||
*/
|
||||
public double getY() {
|
||||
return y;
|
||||
}
|
||||
/**
|
||||
* @param y the y to set
|
||||
*/
|
||||
public void setY(double y) {
|
||||
this.y = y;
|
||||
}
|
||||
/**
|
||||
* @return the z
|
||||
*/
|
||||
public double getZ() {
|
||||
return z;
|
||||
}
|
||||
/**
|
||||
* @param z the z to set
|
||||
*/
|
||||
public void setZ(double z) {
|
||||
this.z = z;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,388 @@
|
||||
/**
|
||||
*
|
||||
* Copyright 2011 Paul Scherrer Institute. All rights reserved.
|
||||
*
|
||||
* This code is free software: you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation, either version 3 of the License, or (at your option) any
|
||||
* later version.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but without any
|
||||
* warranty; without even the implied warranty of merchantability or fitness for
|
||||
* a particular purpose. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this code. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package ch.psi.plot.xyz;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.jfree.chart.axis.NumberAxis;
|
||||
import org.jfree.chart.renderer.xy.XYBlockRenderer;
|
||||
import org.jfree.data.DomainOrder;
|
||||
import org.jfree.data.general.DatasetChangeEvent;
|
||||
import org.jfree.data.general.DatasetChangeListener;
|
||||
import org.jfree.data.general.DatasetGroup;
|
||||
import org.jfree.data.xy.XYZDataset;
|
||||
import org.jfree.ui.RectangleAnchor;
|
||||
|
||||
/**
|
||||
* Dynamic dataset
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class DynamicXYZDatasetList implements XYZDataset{
|
||||
|
||||
private final double xResolution;
|
||||
private final double yResolution;
|
||||
private final double incX;
|
||||
private final double incY;
|
||||
|
||||
private final NumberAxis xAxis = new NumberAxis();
|
||||
private double xLowerBound = Double.NaN;
|
||||
private double xUpperBound = Double.NaN;
|
||||
private final NumberAxis yAxis = new NumberAxis();
|
||||
private double yLowerBound = Double.NaN;
|
||||
private double yUpperBound = Double.NaN;
|
||||
private double zLowerBound = Double.NaN;
|
||||
|
||||
|
||||
private double zUpperBound = Double.NaN;
|
||||
|
||||
private final XYBlockRenderer renderer = new XYBlockRenderer();
|
||||
|
||||
|
||||
private final List<DatasetChangeListener> listeners = new ArrayList<DatasetChangeListener>();
|
||||
private List<Double> xitems = new ArrayList<Double>(100000);
|
||||
private List<Double> yitems = new ArrayList<Double>(100000);
|
||||
private List<Double> zitems = new ArrayList<Double>(100000);
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
public DynamicXYZDatasetList(){
|
||||
xResolution = 1.0;
|
||||
yResolution = 1.0;
|
||||
incX = xResolution/2;
|
||||
incY = yResolution/2;
|
||||
|
||||
xAxis.setRange(0, 100);
|
||||
yAxis.setRange(0, 100);
|
||||
|
||||
renderer.setBlockWidth(xResolution); // If this is not set the default block size is 1
|
||||
renderer.setBlockHeight(yResolution); // If this is not set the default block size is 1
|
||||
renderer.setBlockAnchor(RectangleAnchor.CENTER);
|
||||
// renderer.setBaseCreateEntities(true, false);
|
||||
// renderer.setBaseCreateEntities(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add datapoint
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
*/
|
||||
public void addData(Double x, Double y, Double z){
|
||||
System.out.println(x +" "+ y +" "+ z);
|
||||
xitems.add(x);
|
||||
yitems.add(y);
|
||||
zitems.add(z);
|
||||
// items.add(new DynamicXYZDatasetList.Vector(x,y,z));
|
||||
|
||||
// Update axis
|
||||
|
||||
// final double xv = x.doubleValue();
|
||||
// final double yv = y.doubleValue();
|
||||
// final double zv = z.doubleValue();
|
||||
//
|
||||
// if(Double.isNaN(xLowerBound) && Double.isNaN(xUpperBound)){
|
||||
// xLowerBound = xv-incX;
|
||||
// xUpperBound = xv+incX;
|
||||
// xAxis.setRange(xLowerBound, xUpperBound);
|
||||
// }
|
||||
// else{
|
||||
// if(xv>(xUpperBound+incX)){
|
||||
// xUpperBound = xv+incX;
|
||||
// xAxis.setUpperBound(xUpperBound);
|
||||
// }
|
||||
// else if(xv<xLowerBound-incX){
|
||||
// xLowerBound = xv-incX;
|
||||
// xAxis.setLowerBound(xLowerBound);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if(Double.isNaN(yLowerBound) && Double.isNaN(yUpperBound)){
|
||||
// yLowerBound = y.doubleValue()-incY;
|
||||
// yUpperBound = y.doubleValue()+incY;
|
||||
// yAxis.setRange(yLowerBound, yUpperBound);
|
||||
// }
|
||||
// else{
|
||||
// if(yv>(yUpperBound+incY)){
|
||||
// yUpperBound = yv+incY;
|
||||
// yAxis.setUpperBound(yUpperBound);
|
||||
// }
|
||||
// else if(yv<yLowerBound-incY){
|
||||
// yLowerBound = yv-incY;
|
||||
// yAxis.setLowerBound(yLowerBound);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if(Double.isNaN(zLowerBound) && Double.isNaN(zUpperBound)){
|
||||
// zLowerBound = zv;
|
||||
// zUpperBound = zv;
|
||||
// }
|
||||
// else{
|
||||
// if(zv>zUpperBound){
|
||||
// zUpperBound = zv;
|
||||
// }
|
||||
// else if(zv<zLowerBound){
|
||||
// zLowerBound = zv;
|
||||
// }
|
||||
// }
|
||||
|
||||
// Inform change listeners
|
||||
// DatasetChangeEvent event = new DatasetChangeEvent(this, this);
|
||||
// for(DatasetChangeListener l: listeners){
|
||||
// l.datasetChanged(event );
|
||||
// }
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.jfree.data.xy.XYDataset#getItemCount(int)
|
||||
*/
|
||||
@Override
|
||||
public int getItemCount(int series) {
|
||||
return xitems.size();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.jfree.data.xy.XYDataset#getX(int, int)
|
||||
*/
|
||||
@Override
|
||||
public Number getX(int series, int item) {
|
||||
return xitems.get(item);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.jfree.data.xy.XYDataset#getXValue(int, int)
|
||||
*/
|
||||
@Override
|
||||
public double getXValue(int series, int item) {
|
||||
return xitems.get(item);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.jfree.data.xy.XYDataset#getY(int, int)
|
||||
*/
|
||||
@Override
|
||||
public Number getY(int series, int item) {
|
||||
return yitems.get(item);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.jfree.data.xy.XYDataset#getYValue(int, int)
|
||||
*/
|
||||
@Override
|
||||
public double getYValue(int series, int item) {
|
||||
return yitems.get(item);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.jfree.data.xy.XYZDataset#getZ(int, int)
|
||||
*/
|
||||
@Override
|
||||
public Number getZ(int series, int item) {
|
||||
return zitems.get(item);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.jfree.data.xy.XYZDataset#getZValue(int, int)
|
||||
*/
|
||||
@Override
|
||||
public double getZValue(int series, int item) {
|
||||
return zitems.get(item);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.jfree.data.xy.XYDataset#getDomainOrder()
|
||||
*/
|
||||
@Override
|
||||
public DomainOrder getDomainOrder() {
|
||||
return DomainOrder.NONE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.jfree.data.general.SeriesDataset#getSeriesCount()
|
||||
*/
|
||||
@Override
|
||||
public int getSeriesCount() {
|
||||
// Series not implemented/used - dataset only holds one series
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.jfree.data.general.SeriesDataset#getSeriesKey(int)
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public Comparable getSeriesKey(int series) {
|
||||
// Series not implemented/used
|
||||
return "";
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.jfree.data.general.SeriesDataset#indexOf(java.lang.Comparable)
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public int indexOf(Comparable seriesKey) {
|
||||
// Series not implemented/used
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.jfree.data.general.Dataset#getGroup()
|
||||
*/
|
||||
@Override
|
||||
public DatasetGroup getGroup() {
|
||||
// Not implemented/used
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.jfree.data.general.Dataset#setGroup(org.jfree.data.general.DatasetGroup)
|
||||
*/
|
||||
@Override
|
||||
public void setGroup(DatasetGroup group) {
|
||||
// Not implemented/used
|
||||
}
|
||||
|
||||
// Listener concept implementation
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.jfree.data.general.Dataset#addChangeListener(org.jfree.data.general.DatasetChangeListener)
|
||||
*/
|
||||
@Override
|
||||
public void addChangeListener(DatasetChangeListener listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.jfree.data.general.Dataset#removeChangeListener(org.jfree.data.general.DatasetChangeListener)
|
||||
*/
|
||||
@Override
|
||||
public void removeChangeListener(DatasetChangeListener listener) {
|
||||
listeners.remove(listener);
|
||||
}
|
||||
|
||||
|
||||
// Convenient methods
|
||||
|
||||
/**
|
||||
* @return the zLowerBound
|
||||
*/
|
||||
public double getzLowerBound() {
|
||||
return zLowerBound;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the zUpperBound
|
||||
*/
|
||||
public double getzUpperBound() {
|
||||
return zUpperBound;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the xAxis
|
||||
*/
|
||||
public NumberAxis getxAxis() {
|
||||
return xAxis;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the yAxis
|
||||
*/
|
||||
public NumberAxis getyAxis() {
|
||||
return yAxis;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the renderer
|
||||
*/
|
||||
public XYBlockRenderer getRenderer() {
|
||||
return renderer;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
class Vector{
|
||||
private Number x;
|
||||
private Number y;
|
||||
private Number z;
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
public Vector(){
|
||||
}
|
||||
|
||||
/**
|
||||
* @param x2
|
||||
* @param y2
|
||||
* @param z2
|
||||
*/
|
||||
public Vector(Number x, Number y, Number z) {
|
||||
// Right now x and xvalue are the same. This might change if we introduce a virtual grid ...
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
/**
|
||||
* @return the x
|
||||
*/
|
||||
public Number getX() {
|
||||
return x;
|
||||
}
|
||||
/**
|
||||
* @param x the x to set
|
||||
*/
|
||||
public void setX(Number x) {
|
||||
this.x = x;
|
||||
}
|
||||
/**
|
||||
* @return the y
|
||||
*/
|
||||
public Number getY() {
|
||||
return y;
|
||||
}
|
||||
/**
|
||||
* @param y the y to set
|
||||
*/
|
||||
public void setY(Number y) {
|
||||
this.y = y;
|
||||
}
|
||||
/**
|
||||
* @return the z
|
||||
*/
|
||||
public Number getZ() {
|
||||
return z;
|
||||
}
|
||||
/**
|
||||
* @param z the z to set
|
||||
*/
|
||||
public void setZ(Number z) {
|
||||
this.z = z;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,381 @@
|
||||
/**
|
||||
*
|
||||
* Copyright 2011 Paul Scherrer Institute. All rights reserved.
|
||||
*
|
||||
* This code is free software: you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation, either version 3 of the License, or (at your option) any
|
||||
* later version.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but without any
|
||||
* warranty; without even the implied warranty of merchantability or fitness for
|
||||
* a particular purpose. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this code. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package ch.psi.plot.xyz;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.jfree.chart.axis.NumberAxis;
|
||||
import org.jfree.chart.renderer.xy.XYBlockRenderer;
|
||||
import org.jfree.data.DomainOrder;
|
||||
import org.jfree.data.general.DatasetChangeEvent;
|
||||
import org.jfree.data.general.DatasetChangeListener;
|
||||
import org.jfree.data.general.DatasetGroup;
|
||||
import org.jfree.data.xy.XYZDataset;
|
||||
import org.jfree.ui.RectangleAnchor;
|
||||
|
||||
/**
|
||||
* Dynamic dataset
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class DynamicXYZDatasetNumber implements XYZDataset{
|
||||
|
||||
private final double xResolution;
|
||||
private final double yResolution;
|
||||
private final double incX;
|
||||
private final double incY;
|
||||
|
||||
private final NumberAxis xAxis = new NumberAxis();
|
||||
private double xLowerBound = Double.NaN;
|
||||
private double xUpperBound = Double.NaN;
|
||||
private final NumberAxis yAxis = new NumberAxis();
|
||||
private double yLowerBound = Double.NaN;
|
||||
private double yUpperBound = Double.NaN;
|
||||
private double zLowerBound = Double.NaN;
|
||||
|
||||
|
||||
private double zUpperBound = Double.NaN;
|
||||
|
||||
private final XYBlockRenderer renderer = new XYBlockRenderer();
|
||||
|
||||
|
||||
private final List<DatasetChangeListener> listeners = new ArrayList<DatasetChangeListener>();
|
||||
private List<DynamicXYZDatasetNumber.Vector> items = new ArrayList<DynamicXYZDatasetNumber.Vector>();
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
public DynamicXYZDatasetNumber(){
|
||||
xResolution = 1.0;
|
||||
yResolution = 1.0;
|
||||
incX = xResolution/2;
|
||||
incY = yResolution/2;
|
||||
|
||||
xAxis.setRange(xLowerBound, xUpperBound);
|
||||
yAxis.setRange(yLowerBound, yUpperBound);
|
||||
|
||||
renderer.setBlockWidth(xResolution); // If this is not set the default block size is 1
|
||||
renderer.setBlockHeight(yResolution); // If this is not set the default block size is 1
|
||||
renderer.setBlockAnchor(RectangleAnchor.CENTER);
|
||||
renderer.setBaseCreateEntities(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add datapoint
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
*/
|
||||
public void addData(Number x, Number y, Number z){
|
||||
items.add(new DynamicXYZDatasetNumber.Vector(x,y,z));
|
||||
|
||||
// Update axis
|
||||
|
||||
final double xv = x.doubleValue();
|
||||
final double yv = y.doubleValue();
|
||||
final double zv = z.doubleValue();
|
||||
|
||||
if(Double.isNaN(xLowerBound) && Double.isNaN(xUpperBound)){
|
||||
xLowerBound = xv-incX;
|
||||
xUpperBound = xv+incX;
|
||||
xAxis.setRange(xLowerBound, xUpperBound);
|
||||
}
|
||||
else{
|
||||
if(xv>(xUpperBound+incX)){
|
||||
xUpperBound = xv+incX;
|
||||
xAxis.setUpperBound(xUpperBound);
|
||||
}
|
||||
else if(xv<xLowerBound-incX){
|
||||
xLowerBound = xv-incX;
|
||||
xAxis.setLowerBound(xLowerBound);
|
||||
}
|
||||
}
|
||||
|
||||
if(Double.isNaN(yLowerBound) && Double.isNaN(yUpperBound)){
|
||||
yLowerBound = y.doubleValue()-incY;
|
||||
yUpperBound = y.doubleValue()+incY;
|
||||
yAxis.setRange(yLowerBound, yUpperBound);
|
||||
}
|
||||
else{
|
||||
if(yv>(yUpperBound+incY)){
|
||||
yUpperBound = yv+incY;
|
||||
yAxis.setUpperBound(yUpperBound);
|
||||
}
|
||||
else if(yv<yLowerBound-incY){
|
||||
yLowerBound = yv-incY;
|
||||
yAxis.setLowerBound(yLowerBound);
|
||||
}
|
||||
}
|
||||
|
||||
if(Double.isNaN(zLowerBound) && Double.isNaN(zUpperBound)){
|
||||
zLowerBound = zv;
|
||||
zUpperBound = zv;
|
||||
}
|
||||
else{
|
||||
if(zv>zUpperBound){
|
||||
zUpperBound = zv;
|
||||
}
|
||||
else if(zv<zLowerBound){
|
||||
zLowerBound = zv;
|
||||
}
|
||||
}
|
||||
|
||||
// Inform change listeners
|
||||
// DatasetChangeEvent event = new DatasetChangeEvent(this, this);
|
||||
// for(DatasetChangeListener l: listeners){
|
||||
// l.datasetChanged(event );
|
||||
// }
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.jfree.data.xy.XYDataset#getItemCount(int)
|
||||
*/
|
||||
@Override
|
||||
public int getItemCount(int series) {
|
||||
return items.size();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.jfree.data.xy.XYDataset#getX(int, int)
|
||||
*/
|
||||
@Override
|
||||
public Number getX(int series, int item) {
|
||||
return items.get(item).getX();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.jfree.data.xy.XYDataset#getXValue(int, int)
|
||||
*/
|
||||
@Override
|
||||
public double getXValue(int series, int item) {
|
||||
return items.get(item).getX().doubleValue();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.jfree.data.xy.XYDataset#getY(int, int)
|
||||
*/
|
||||
@Override
|
||||
public Number getY(int series, int item) {
|
||||
return items.get(item).getY();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.jfree.data.xy.XYDataset#getYValue(int, int)
|
||||
*/
|
||||
@Override
|
||||
public double getYValue(int series, int item) {
|
||||
return items.get(item).getY().doubleValue();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.jfree.data.xy.XYZDataset#getZ(int, int)
|
||||
*/
|
||||
@Override
|
||||
public Number getZ(int series, int item) {
|
||||
return items.get(item).getZ();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.jfree.data.xy.XYZDataset#getZValue(int, int)
|
||||
*/
|
||||
@Override
|
||||
public double getZValue(int series, int item) {
|
||||
return items.get(item).getZ().doubleValue();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.jfree.data.xy.XYDataset#getDomainOrder()
|
||||
*/
|
||||
@Override
|
||||
public DomainOrder getDomainOrder() {
|
||||
return DomainOrder.NONE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.jfree.data.general.SeriesDataset#getSeriesCount()
|
||||
*/
|
||||
@Override
|
||||
public int getSeriesCount() {
|
||||
// Series not implemented/used - dataset only holds one series
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.jfree.data.general.SeriesDataset#getSeriesKey(int)
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public Comparable getSeriesKey(int series) {
|
||||
// Series not implemented/used
|
||||
return "";
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.jfree.data.general.SeriesDataset#indexOf(java.lang.Comparable)
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public int indexOf(Comparable seriesKey) {
|
||||
// Series not implemented/used
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.jfree.data.general.Dataset#getGroup()
|
||||
*/
|
||||
@Override
|
||||
public DatasetGroup getGroup() {
|
||||
// Not implemented/used
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.jfree.data.general.Dataset#setGroup(org.jfree.data.general.DatasetGroup)
|
||||
*/
|
||||
@Override
|
||||
public void setGroup(DatasetGroup group) {
|
||||
// Not implemented/used
|
||||
}
|
||||
|
||||
// Listener concept implementation
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.jfree.data.general.Dataset#addChangeListener(org.jfree.data.general.DatasetChangeListener)
|
||||
*/
|
||||
@Override
|
||||
public void addChangeListener(DatasetChangeListener listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.jfree.data.general.Dataset#removeChangeListener(org.jfree.data.general.DatasetChangeListener)
|
||||
*/
|
||||
@Override
|
||||
public void removeChangeListener(DatasetChangeListener listener) {
|
||||
listeners.remove(listener);
|
||||
}
|
||||
|
||||
|
||||
// Convenient methods
|
||||
|
||||
/**
|
||||
* @return the zLowerBound
|
||||
*/
|
||||
public double getzLowerBound() {
|
||||
return zLowerBound;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the zUpperBound
|
||||
*/
|
||||
public double getzUpperBound() {
|
||||
return zUpperBound;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the xAxis
|
||||
*/
|
||||
public NumberAxis getxAxis() {
|
||||
return xAxis;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the yAxis
|
||||
*/
|
||||
public NumberAxis getyAxis() {
|
||||
return yAxis;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the renderer
|
||||
*/
|
||||
public XYBlockRenderer getRenderer() {
|
||||
return renderer;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
class Vector{
|
||||
private Number x;
|
||||
private Number y;
|
||||
private Number z;
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
public Vector(){
|
||||
}
|
||||
|
||||
/**
|
||||
* @param x2
|
||||
* @param y2
|
||||
* @param z2
|
||||
*/
|
||||
public Vector(Number x, Number y, Number z) {
|
||||
// Right now x and xvalue are the same. This might change if we introduce a virtual grid ...
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
/**
|
||||
* @return the x
|
||||
*/
|
||||
public Number getX() {
|
||||
return x;
|
||||
}
|
||||
/**
|
||||
* @param x the x to set
|
||||
*/
|
||||
public void setX(Number x) {
|
||||
this.x = x;
|
||||
}
|
||||
/**
|
||||
* @return the y
|
||||
*/
|
||||
public Number getY() {
|
||||
return y;
|
||||
}
|
||||
/**
|
||||
* @param y the y to set
|
||||
*/
|
||||
public void setY(Number y) {
|
||||
this.y = y;
|
||||
}
|
||||
/**
|
||||
* @return the z
|
||||
*/
|
||||
public Number getZ() {
|
||||
return z;
|
||||
}
|
||||
/**
|
||||
* @param z the z to set
|
||||
*/
|
||||
public void setZ(Number z) {
|
||||
this.z = z;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -38,6 +38,8 @@ import java.awt.event.ActionEvent;
|
||||
*
|
||||
*/
|
||||
public class ManualScaleDialog extends JDialog {
|
||||
// Default serial id
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final JPanel contentPanel = new JPanel();
|
||||
private JTextField textFieldHighValue;
|
||||
|
||||
361
ch.psi.plot/src/main/java/ch/psi/plot/xyz/MatrixPlot2.java
Normal file
361
ch.psi.plot/src/main/java/ch/psi/plot/xyz/MatrixPlot2.java
Normal file
@@ -0,0 +1,361 @@
|
||||
package ch.psi.plot.xyz;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.WindowConstants;
|
||||
|
||||
import org.jfree.chart.ChartPanel;
|
||||
import org.jfree.chart.JFreeChart;
|
||||
import org.jfree.chart.axis.NumberAxis;
|
||||
import org.jfree.chart.axis.ValueAxis;
|
||||
import org.jfree.chart.event.AxisChangeEvent;
|
||||
import org.jfree.chart.event.AxisChangeListener;
|
||||
import org.jfree.chart.labels.StandardXYZToolTipGenerator;
|
||||
import org.jfree.chart.labels.XYZToolTipGenerator;
|
||||
import org.jfree.chart.plot.XYPlot;
|
||||
import org.jfree.chart.renderer.LookupPaintScale;
|
||||
import org.jfree.chart.renderer.PaintScale;
|
||||
import org.jfree.chart.renderer.xy.XYBlockRenderer;
|
||||
import org.jfree.chart.title.PaintScaleLegend;
|
||||
import org.jfree.data.Range;
|
||||
import org.jfree.ui.RectangleAnchor;
|
||||
import org.jfree.ui.RectangleEdge;
|
||||
import org.jfree.ui.RectangleInsets;
|
||||
|
||||
import ch.psi.plot.Plot;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a matrix plot panel
|
||||
*/
|
||||
public class MatrixPlot2 implements Plot {
|
||||
|
||||
private static final int chartPanelWidth = 500;
|
||||
private static final int chartPanelHeight = 270;
|
||||
|
||||
private String title;
|
||||
private String xAxisLabel = "X";
|
||||
private String yAxisLabel = "Y";
|
||||
|
||||
private boolean grayScale = false;
|
||||
|
||||
private DynamicXYZDatasetList data;
|
||||
private JFreeChart chart;
|
||||
private ChartPanel chartPanel;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param title
|
||||
* @param data
|
||||
*/
|
||||
public MatrixPlot2(String title, final DynamicXYZDatasetList data) {
|
||||
this.title = title;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
// Action Classes that implement methods called after keyboard input
|
||||
|
||||
/**
|
||||
* Adapt the context menu of the chart panel
|
||||
*/
|
||||
private void adaptContextMenu(final ChartPanel chartPanel){
|
||||
|
||||
// Show hide tooltips
|
||||
final String tooltipsMenuLabel = "Tooltips";
|
||||
final String hideTooltipsMenuLabel = "Hide Tooltips";
|
||||
JMenuItem contextMenuItemToolTip = new JMenuItem(tooltipsMenuLabel);
|
||||
contextMenuItemToolTip.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
JMenuItem source = (JMenuItem)(e.getSource());
|
||||
if (source.getText() == tooltipsMenuLabel){
|
||||
showTooltip();
|
||||
source.setText(hideTooltipsMenuLabel);
|
||||
}
|
||||
|
||||
else if (source.getText() == hideTooltipsMenuLabel){
|
||||
hideTooltip();
|
||||
source.setText(tooltipsMenuLabel);
|
||||
}
|
||||
}
|
||||
});
|
||||
chartPanel.getPopupMenu().add(contextMenuItemToolTip);
|
||||
|
||||
// Update colormap
|
||||
JMenuItem contextMenuItemAdaptScale = new JMenuItem("Update Scale");
|
||||
contextMenuItemAdaptScale.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
adaptColorMapScale();
|
||||
}
|
||||
});
|
||||
|
||||
// Set gray scale colormap
|
||||
JMenuItem contextMenuItemGrayScale = new JMenuItem("Gray Scale");
|
||||
contextMenuItemGrayScale.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
grayScale = true;
|
||||
adaptColorMapScale();
|
||||
}
|
||||
});
|
||||
|
||||
// Set color colormap
|
||||
JMenuItem contextMenuItemTemperatureColor = new JMenuItem("Color Scale");
|
||||
contextMenuItemTemperatureColor.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
grayScale = false;
|
||||
adaptColorMapScale();
|
||||
}
|
||||
});
|
||||
|
||||
// // Set color colormap
|
||||
// JMenuItem menuItemScale = new JMenuItem("Manual Scale");
|
||||
// menuItemScale.addActionListener(new ActionListener() {
|
||||
// @Override
|
||||
// public void actionPerformed(ActionEvent e) {
|
||||
// ManualScaleDialog d = new ManualScaleDialog();
|
||||
// d.setLocationRelativeTo(chartPanel);
|
||||
// d.setLow(((PaintScaleLegend) chart.getSubtitles().get(0)).getScale().getLowerBound());
|
||||
// d.setHigh(((PaintScaleLegend) chart.getSubtitles().get(0)).getScale().getUpperBound());
|
||||
// d.setMatrixPlot(MatrixPlot2.this);
|
||||
//
|
||||
// d.showDialog();
|
||||
// if(d.getSelectedOption()==JOptionPane.OK_OPTION){
|
||||
// setColorScale(d.getLow(), d.getHigh());
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
|
||||
// Group colormap related menu items
|
||||
JMenuItem contextMenuChooseColorMap = new JMenu("ColorMap");
|
||||
contextMenuChooseColorMap.add(contextMenuItemAdaptScale);
|
||||
// contextMenuChooseColorMap.add(menuItemScale);
|
||||
contextMenuChooseColorMap.add(contextMenuItemGrayScale);
|
||||
contextMenuChooseColorMap.add(contextMenuItemTemperatureColor);
|
||||
chartPanel.getPopupMenu().add(contextMenuChooseColorMap);
|
||||
|
||||
// Add separator
|
||||
chartPanel.getPopupMenu().addSeparator();
|
||||
|
||||
// Detach plot into an own frame
|
||||
JMenuItem contextMenuItemDetach = new JMenuItem("Detach Plot");
|
||||
contextMenuItemDetach.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
MatrixPlot2 p = new MatrixPlot2(title, data);
|
||||
|
||||
final JFrame frame = new JFrame(title);
|
||||
frame.getContentPane();
|
||||
frame.setContentPane(p.getChartPanel());
|
||||
frame.pack();
|
||||
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); // Close application if frame is closed
|
||||
|
||||
// Set color scale
|
||||
p.adaptColorMapScale();
|
||||
|
||||
java.awt.EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
frame.setVisible(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
chartPanel.getPopupMenu().add(contextMenuItemDetach);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Show Tooltips. This is not done per default since it makes the app slow for datasize >= 1M
|
||||
*/
|
||||
private void showTooltip(){
|
||||
//Tooltips are quit expensive
|
||||
DecimalFormat dm = new DecimalFormat("0.##########");
|
||||
XYZToolTipGenerator xYZToolTipGenerator = new StandardXYZToolTipGenerator("{0}: ({1} / {2} / {3})", dm, dm, dm);
|
||||
|
||||
chart.getXYPlot().getRenderer().setBaseToolTipGenerator(xYZToolTipGenerator);
|
||||
((XYBlockRenderer)chart.getXYPlot().getRenderer()).setBaseCreateEntities(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear Tooltips
|
||||
*/
|
||||
private void hideTooltip(){
|
||||
//Tooltips are quit expensive
|
||||
((XYBlockRenderer)chart.getXYPlot().getRenderer()).setBaseToolTipGenerator(null);
|
||||
((XYBlockRenderer)chart.getXYPlot().getRenderer()).setBaseCreateEntities(false);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adapt the lower and upper color map scale to the min and max data values of the currently selected region
|
||||
* Need to be called AFTER the chart panel is created
|
||||
*/
|
||||
public void adaptColorMapScale(){
|
||||
if(!Double.isNaN(data.getzLowerBound()) && !Double.isNaN(data.getzUpperBound())){
|
||||
setColorScale(data.getzLowerBound(),data.getzUpperBound());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the min and max of color map scale to scaleMin and scaleMax
|
||||
* @param scaleMin min value of scale
|
||||
* @param scaleMax max value of scale
|
||||
*/
|
||||
public void setColorScale(double scaleMin, double scaleMax){
|
||||
|
||||
// Create scale for legend
|
||||
LookupPaintScale legendScale = new LookupPaintScale(scaleMin, scaleMax, Color.GRAY);
|
||||
setScaleColors(legendScale, scaleMin, scaleMax);
|
||||
|
||||
// Create legend
|
||||
PaintScaleLegend legend = new PaintScaleLegend(legendScale, new NumberAxis());
|
||||
legend.setPadding(new RectangleInsets(5, 5, 5, 5));
|
||||
// Width of the legend (colorbar)
|
||||
legend.setStripWidth(20);
|
||||
// Position of the legend
|
||||
legend.setPosition(RectangleEdge.RIGHT);
|
||||
// Remove background paint/color
|
||||
legend.setBackgroundPaint(null);
|
||||
|
||||
// Add legend to plot panel
|
||||
chart.clearSubtitles();
|
||||
chart.addSubtitle(legend);
|
||||
|
||||
|
||||
//We need a second scale for rendering only, where the 'infinities' are in correct color
|
||||
LookupPaintScale rendererScale = new LookupPaintScale(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, Color.GRAY);
|
||||
setScaleColors(rendererScale, scaleMin, scaleMax);
|
||||
// Make the paint scale range from - to + infinity
|
||||
if (grayScale) {
|
||||
rendererScale.add(Double.NEGATIVE_INFINITY, ColorManager.getGrayForValue(scaleMin, scaleMin, scaleMax));
|
||||
rendererScale.add(Double.POSITIVE_INFINITY, ColorManager.getGrayForValue(scaleMax, scaleMin, scaleMax));
|
||||
} else {
|
||||
rendererScale.add(Double.NEGATIVE_INFINITY, ColorManager.getColourForValue(scaleMin, scaleMin, scaleMax));
|
||||
rendererScale.add(Double.POSITIVE_INFINITY, ColorManager.getColourForValue(scaleMax, scaleMin, scaleMax));
|
||||
}
|
||||
((XYBlockRenderer) chart.getXYPlot().getRenderer()).setPaintScale(rendererScale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the colors for the colored Paint Scale (either single color or temperature color)
|
||||
* @param paintScale
|
||||
* @param scaleMin
|
||||
* @param scaleMax
|
||||
*/
|
||||
private void setScaleColors(PaintScale paintScale, double scaleMin, double scaleMax){
|
||||
if (grayScale) {
|
||||
for (int i = 0; i < 256; i++) {
|
||||
double value = scaleMin + (i / 255.0) * (scaleMax - scaleMin);
|
||||
((LookupPaintScale) paintScale).add(value, ColorManager.getGrayForValue(value, scaleMin, scaleMax));
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < 256; i++) {
|
||||
double value = scaleMin + (i / 255.0) * (scaleMax - scaleMin);
|
||||
((LookupPaintScale) paintScale).add(value, ColorManager.getColourForValue(value, scaleMin, scaleMax));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get plot data
|
||||
* @return
|
||||
*/
|
||||
public DynamicXYZDatasetList getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the chart panel
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public ChartPanel getChartPanel() {
|
||||
if(chartPanel == null){
|
||||
|
||||
XYPlot plot = new XYPlot(data, data.getxAxis(), data.getyAxis(), data.getRenderer());
|
||||
|
||||
|
||||
// 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) {
|
||||
// ValueAxis axis = ((ValueAxis)event.getAxis());
|
||||
// if(axis.getLowerBound() < data.getyLowerBound() || axis.getUpperBound() > data.getyUpperBound()){
|
||||
// Range range = new Range(data.getyLowerBound(), data.getyUpperBound());
|
||||
// axis.setRange(range, true, false);
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// plot.getDomainAxis().addChangeListener(new AxisChangeListener() {
|
||||
// @Override
|
||||
// public void axisChanged(AxisChangeEvent event) {
|
||||
// ValueAxis axis = ((ValueAxis)event.getAxis());
|
||||
// if(axis.getLowerBound() < data.getxLowerBound() || axis.getUpperBound() > data.getxUpperBound()){
|
||||
// Range range = new Range(data.getxLowerBound(), data.getxUpperBound());
|
||||
// axis.setRange(range, true, false);
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
|
||||
|
||||
|
||||
chart = new JFreeChart(title, plot);
|
||||
|
||||
//Remove the series label (also called legend)
|
||||
chart.removeLegend();
|
||||
//AntiAliasing is used to speed up rendering
|
||||
// chart.setAntiAlias(false);
|
||||
|
||||
// Init PaintScale
|
||||
setColorScale(0,1);
|
||||
|
||||
|
||||
|
||||
//Create the Chartpanel where the chart will be plotted
|
||||
chartPanel = new ChartPanel(chart);
|
||||
|
||||
chartPanel.setPreferredSize(new java.awt.Dimension(chartPanelWidth, chartPanelHeight));
|
||||
|
||||
//All interactive menu items
|
||||
adaptContextMenu(chartPanel);
|
||||
}
|
||||
|
||||
|
||||
return chartPanel;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.plot.Plot#update()
|
||||
*/
|
||||
@Override
|
||||
public void update() {
|
||||
chart.fireChartChanged();
|
||||
adaptColorMapScale();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.plot.Plot#getChart()
|
||||
*/
|
||||
@Override
|
||||
public JFreeChart getChart() {
|
||||
return chart;
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,9 @@ import org.jfree.ui.ApplicationFrame;
|
||||
import org.jfree.ui.RefineryUtilities;
|
||||
|
||||
public class DualAxisChart extends ApplicationFrame {
|
||||
|
||||
// Default serial id
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
final String team1 = "1st Team";
|
||||
final String team2 = "2nd Team";
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@ import org.jfree.ui.ApplicationFrame;
|
||||
import org.jfree.ui.RefineryUtilities;
|
||||
|
||||
public class DualAxisChart2 extends ApplicationFrame {
|
||||
// Default serial id
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
final String team1 = "1st Team";
|
||||
final String team2 = "2nd Team";
|
||||
|
||||
212
ch.psi.plot/src/test/java/ch/psi/plot/xyz/MatrixPlot2Test.java
Normal file
212
ch.psi.plot/src/test/java/ch/psi/plot/xyz/MatrixPlot2Test.java
Normal file
@@ -0,0 +1,212 @@
|
||||
/**
|
||||
*
|
||||
* Copyright 2010 Paul Scherrer Institute. All rights reserved.
|
||||
*
|
||||
* This code is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful,
|
||||
* but without any warranty; without even the implied warranty of
|
||||
* merchantability or fitness for a particular purpose. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this code. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package ch.psi.plot.xyz;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.WindowConstants;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
//import ch.psi.sls.xasec.data.DataSet;
|
||||
//import ch.psi.sls.xasec.data.DataSetUtils;
|
||||
import ch.psi.plot.xyz.MatrixPlot;
|
||||
import ch.psi.plot.xyz.MatrixPlotData;
|
||||
import ch.psi.plot.xyz.generator.DataGenerator;
|
||||
import ch.psi.plot.xyz.generator.Sinus2D;
|
||||
import ch.psi.plot.xyz.generator.XYZGenerator;
|
||||
|
||||
|
||||
/**
|
||||
* Test case for MatrixPlot class
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class MatrixPlot2Test {
|
||||
|
||||
// Get Logger
|
||||
private static final Logger logger = Logger.getLogger(MatrixPlot2Test.class.getName());
|
||||
|
||||
private final long timeToClose = 7200000; // 2 hours
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test case for MatrixPlot (getting data from a generator)
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
@Test
|
||||
public void testMatrixPlot() throws InterruptedException {
|
||||
double startX = 0;
|
||||
double stepSizeX = 1;
|
||||
int stepsX = 50;
|
||||
double startY = 0;
|
||||
double stepSizeY = 1;
|
||||
int stepsY = 50;
|
||||
|
||||
final DynamicXYZDatasetList data = new DynamicXYZDatasetList();
|
||||
|
||||
final XYZGenerator generator = new XYZGenerator(new Sinus2D(2,4), startX, stepSizeX, stepsX, startY, stepSizeY, stepsY, false);
|
||||
final MatrixPlot2 plot = new MatrixPlot2("Matrix Plot Test", data);
|
||||
|
||||
final JFrame frame = new JFrame("");
|
||||
frame.setContentPane(plot.getChartPanel());
|
||||
frame.pack();
|
||||
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); // Close application if frame is closed
|
||||
|
||||
java.awt.EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
frame.setVisible(true);
|
||||
}
|
||||
});
|
||||
|
||||
Thread t = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// for(int t=0;t<200;t++){
|
||||
// // Reset generator
|
||||
// generator.reset();
|
||||
|
||||
// int count = 0;
|
||||
double[] xyz;
|
||||
while((xyz=generator.getNewPoint())!=null){
|
||||
data.addData(xyz[0], xyz[1], xyz[2]);
|
||||
|
||||
try {
|
||||
Thread.sleep(10);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
|
||||
// or set matrixChart.setNotify(false); in MatrixPlot Line 431 ...
|
||||
// if(count==10){
|
||||
// plot.update();
|
||||
// count=0;
|
||||
// }
|
||||
// else{
|
||||
// count++;
|
||||
// }
|
||||
}
|
||||
System.out.println("Generator done");
|
||||
|
||||
// }
|
||||
|
||||
}
|
||||
});
|
||||
t.start();
|
||||
|
||||
Thread.sleep(timeToClose);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPlotConverterGeneratorMatrixPlot() throws InterruptedException {
|
||||
DataGenerator generator = new DataGenerator(new Sinus2D(2,4));
|
||||
generator.generateData();
|
||||
|
||||
MatrixPlot plot = new MatrixPlot("Matrix Plot Test", generator.getData());
|
||||
|
||||
// converter.generateData();
|
||||
//// Thread t = new Thread(converter);
|
||||
//// t.start();
|
||||
|
||||
final JFrame frame = new JFrame("");
|
||||
frame.setContentPane(plot.getChartPanel());
|
||||
frame.pack();
|
||||
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); // Close application if frame is closed
|
||||
|
||||
java.awt.EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
frame.setVisible(true);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Thread.sleep(timeToClose);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPlotMatrixPlot() throws InterruptedException {
|
||||
MatrixPlotData data = new MatrixPlotData(-10, -1, 10, -10, -1, 10);
|
||||
|
||||
Random r = new Random();
|
||||
|
||||
for (double i = data.getMinX(); i <= data.getMaxX(); i++) {
|
||||
for (double t = data.getMinY(); t <= data.getMaxY(); t++) {
|
||||
data.addData(i, t, r.nextDouble() * 10);
|
||||
}
|
||||
}
|
||||
|
||||
MatrixPlot plot = new MatrixPlot("Matrix Plot Test", data);
|
||||
final JFrame frame = new JFrame("");
|
||||
frame.setContentPane(plot.getChartPanel());
|
||||
frame.pack();
|
||||
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); // Close application if frame is closed
|
||||
|
||||
java.awt.EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
frame.setVisible(true);
|
||||
}
|
||||
});
|
||||
|
||||
Thread.sleep(timeToClose);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testPlotMatrixPlot2() throws InterruptedException {
|
||||
MatrixPlotData data = new MatrixPlotData(-11.5, -11.0, 6, -10.5, -10.0, 6);
|
||||
|
||||
Random r = new Random();
|
||||
|
||||
for (double i = data.getMinX(); i <= data.getMaxX(); i=i+0.1) {
|
||||
for (double t = data.getMinY(); t <= data.getMaxY(); t=t+0.1) {
|
||||
logger.info("Add data: "+i+" "+t);
|
||||
if(t==data.getMinY()){
|
||||
continue;
|
||||
}
|
||||
data.addData(i, t, r.nextDouble() * 10);
|
||||
}
|
||||
}
|
||||
|
||||
MatrixPlot plot = new MatrixPlot("Matrix Plot Test", data);
|
||||
final JFrame frame = new JFrame("");
|
||||
frame.setContentPane(plot.getChartPanel());
|
||||
frame.pack();
|
||||
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); // Close application if frame is closed
|
||||
|
||||
java.awt.EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
frame.setVisible(true);
|
||||
}
|
||||
});
|
||||
|
||||
Thread.sleep(timeToClose);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user