forked from LupusNobilis/java-org.hwo.ui
added functions to jdiagram and plotprovider
parent
39c548a13f
commit
d86830f119
|
@ -6,6 +6,7 @@ import java.awt.Font;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Toolkit;
|
import java.awt.Toolkit;
|
||||||
|
import java.awt.geom.Point2D;
|
||||||
|
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
|
@ -22,6 +23,11 @@ import org.hwo.ui.diagram.SimplePlotProvider;
|
||||||
|
|
||||||
public class JDiagram extends JComponent implements PlotProviderListener {
|
public class JDiagram extends JComponent implements PlotProviderListener {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private PlotProvider2
|
private PlotProvider2
|
||||||
plotProvider;
|
plotProvider;
|
||||||
|
|
||||||
|
@ -48,9 +54,13 @@ public class JDiagram extends JComponent implements PlotProviderListener {
|
||||||
private int plotHeight,
|
private int plotHeight,
|
||||||
plotWidth;
|
plotWidth;
|
||||||
|
|
||||||
|
|
||||||
private double abszissMinimum,
|
private double abszissMinimum,
|
||||||
abszissMaximum,
|
abszissMaximum,
|
||||||
abszissWindow;
|
abszissWindow;
|
||||||
|
//Positions of first and last abszisslabel
|
||||||
|
private int firstAbszissPos;
|
||||||
|
private int lastAbszissPos;
|
||||||
|
|
||||||
|
|
||||||
private int screenDPI;
|
private int screenDPI;
|
||||||
|
@ -59,7 +69,7 @@ public class JDiagram extends JComponent implements PlotProviderListener {
|
||||||
private boolean autoOrdinateLabeling;
|
private boolean autoOrdinateLabeling;
|
||||||
private boolean drawHorizontalGrid;
|
private boolean drawHorizontalGrid;
|
||||||
private boolean drawVerticalGrid;
|
private boolean drawVerticalGrid;
|
||||||
private boolean logarithmic;
|
//private boolean logarithmic;
|
||||||
private boolean preferLabelHints;
|
private boolean preferLabelHints;
|
||||||
private boolean autoScale;
|
private boolean autoScale;
|
||||||
private boolean autoScaleMargins;
|
private boolean autoScaleMargins;
|
||||||
|
@ -74,6 +84,14 @@ public class JDiagram extends JComponent implements PlotProviderListener {
|
||||||
|
|
||||||
private Integer selectedPlot;
|
private Integer selectedPlot;
|
||||||
|
|
||||||
|
//fields for zooming/ section selection
|
||||||
|
private float lastFocusPoint;
|
||||||
|
private float focusPoint;
|
||||||
|
private float focusRange;
|
||||||
|
private boolean inZoom;
|
||||||
|
//private int yMin, yMax;
|
||||||
|
|
||||||
|
//private float average = 0;
|
||||||
|
|
||||||
public JDiagram(){
|
public JDiagram(){
|
||||||
setMinimumSize(new Dimension(80, 80));
|
setMinimumSize(new Dimension(80, 80));
|
||||||
|
@ -105,6 +123,8 @@ public class JDiagram extends JComponent implements PlotProviderListener {
|
||||||
if (this.plotProvider != null)
|
if (this.plotProvider != null)
|
||||||
this.plotProvider.addPlotProviderListener(this);
|
this.plotProvider.addPlotProviderListener(this);
|
||||||
|
|
||||||
|
this.setFocus(this.plotProvider.getPositionMinimum(), this.plotProvider.getPositionMaximum());
|
||||||
|
|
||||||
fundamentalsChanged();
|
fundamentalsChanged();
|
||||||
}
|
}
|
||||||
public PlotProvider2 getPlotProvider() {
|
public PlotProvider2 getPlotProvider() {
|
||||||
|
@ -149,6 +169,7 @@ public class JDiagram extends JComponent implements PlotProviderListener {
|
||||||
plotPainters = new PlotPainter[plotProvider.getNumGraphs()];
|
plotPainters = new PlotPainter[plotProvider.getNumGraphs()];
|
||||||
for (int n=0;n<plotProvider.getNumGraphs();n++)
|
for (int n=0;n<plotProvider.getNumGraphs();n++)
|
||||||
plotPainters[n] = pp;
|
plotPainters[n] = pp;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
ordinateViews = new OrdinateView[0];
|
ordinateViews = new OrdinateView[0];
|
||||||
plotPainters = new PlotPainter[0];
|
plotPainters = new PlotPainter[0];
|
||||||
|
@ -223,6 +244,17 @@ public class JDiagram extends JComponent implements PlotProviderListener {
|
||||||
this.abszissLabeler = abszissLabeler;
|
this.abszissLabeler = abszissLabeler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Point2D mapMouseToGraph(int mx, int my, int graph) {
|
||||||
|
Point2D p = new Point2D.Float();
|
||||||
|
int graphArea = getGraphWidth();
|
||||||
|
float x = ((((float)mx - getGraphDrawStart()) / graphArea) * this.focusRange) + this.focusPoint;
|
||||||
|
Float y = 0.0f;
|
||||||
|
if(graph >= 0 && graph < this.plotProvider.getNumGraphs() && this.plotProvider.getNumGraphs() != 0)
|
||||||
|
y = this.plotProvider.getValue(Math.round(x), graph);
|
||||||
|
y = y == null?0.0f : y;
|
||||||
|
p.setLocation(x, y);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
public void autoscale(){
|
public void autoscale(){
|
||||||
int ordinate;
|
int ordinate;
|
||||||
|
@ -234,6 +266,7 @@ public class JDiagram extends JComponent implements PlotProviderListener {
|
||||||
min = new Double[this.plotProvider.getMaxOrdinate()+1];
|
min = new Double[this.plotProvider.getMaxOrdinate()+1];
|
||||||
|
|
||||||
for (int graph=0; graph < this.plotProvider.getNumGraphs(); graph++){
|
for (int graph=0; graph < this.plotProvider.getNumGraphs(); graph++){
|
||||||
|
|
||||||
ordinate = this.plotProvider.getOrdinate(graph);
|
ordinate = this.plotProvider.getOrdinate(graph);
|
||||||
for (int n=0;n<this.plotProvider.getLength(); n++){
|
for (int n=0;n<this.plotProvider.getLength(); n++){
|
||||||
Float value = this.plotProvider.getValue(n, graph);
|
Float value = this.plotProvider.getValue(n, graph);
|
||||||
|
@ -244,6 +277,12 @@ public class JDiagram extends JComponent implements PlotProviderListener {
|
||||||
if ((max[ordinate] == null) || (value > max[ordinate]))
|
if ((max[ordinate] == null) || (value > max[ordinate]))
|
||||||
max[ordinate] = value.doubleValue();
|
max[ordinate] = value.doubleValue();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//autoscale x-axis
|
||||||
|
if(this.plotProvider.getValueCount(graph) >= this.plotProvider.getMaxSamples())
|
||||||
|
{
|
||||||
|
this.plotProvider.setMaxSamples(this.plotProvider.getMaxSamples() + 2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -256,8 +295,58 @@ public class JDiagram extends JComponent implements PlotProviderListener {
|
||||||
|
|
||||||
this.ordinateViews[i].scaler.scale(min[i], max[i], autoScaleMargins);
|
this.ordinateViews[i].scaler.scale(min[i], max[i], autoScaleMargins);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//sets point in middle of zoom area
|
||||||
|
public void setFocusPoint(float x) {
|
||||||
|
setFocus(x, x + this.focusRange);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFocusRange(float range) {
|
||||||
|
this.focusRange = range;
|
||||||
|
}
|
||||||
|
public float getFocusRange() {
|
||||||
|
return this.focusRange;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFocus(float xMin, float xMax) {
|
||||||
|
|
||||||
|
float min = plotProvider.getPositionMinimum();
|
||||||
|
float max = plotProvider.getPositionMaximum();
|
||||||
|
|
||||||
|
this.focusPoint = min >= xMin? min : xMin;
|
||||||
|
float focusMax = max <= xMax? max : xMax;
|
||||||
|
|
||||||
|
this.focusRange = this.focusPoint + focusMax;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getFocusMin() {
|
||||||
|
return this.focusPoint;
|
||||||
|
}
|
||||||
|
public float getFocusMax() {
|
||||||
|
return this.focusPoint + this.focusRange;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zoom(float zoomFactor, float focusVal) {
|
||||||
|
float z = ((zoomFactor / -100.0f) * 1.0f) + 1.0f;
|
||||||
|
float leftX = 0, rightX = 0;
|
||||||
|
float width = this.plotProvider.getPositionMaximum() - focusVal;
|
||||||
|
float widthL = this.plotProvider.getPositionMaximum() - width;
|
||||||
|
leftX = (widthL * z) - focusVal;
|
||||||
|
rightX = focusVal + (width * z);
|
||||||
|
setFocus(leftX, rightX);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getGraphDrawStart() {
|
||||||
|
return this.firstAbszissPos;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getGraphDrawEnd() {
|
||||||
|
return this.lastAbszissPos;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getGraphWidth() {
|
||||||
|
return this.lastAbszissPos - this.firstAbszissPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -276,14 +365,14 @@ public class JDiagram extends JComponent implements PlotProviderListener {
|
||||||
g.fillRect(0, 0, getWidth(), getHeight());
|
g.fillRect(0, 0, getWidth(), getHeight());
|
||||||
|
|
||||||
if(plotProvider != null){
|
if(plotProvider != null){
|
||||||
|
if(this.autoScale) {
|
||||||
if (autoScale)
|
autoscale();
|
||||||
this.autoscale();
|
}
|
||||||
|
|
||||||
paintOrdinates ((Graphics2D) g);
|
paintOrdinates ((Graphics2D) g);
|
||||||
paintAbszisse ((Graphics2D) g);
|
paintAbszisse ((Graphics2D) g);
|
||||||
paintGraphs ((Graphics2D) g);
|
paintGraphs ((Graphics2D) g);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public double[] getordinateLabelHints(int ordinate){
|
public double[] getordinateLabelHints(int ordinate){
|
||||||
|
@ -301,7 +390,11 @@ public class JDiagram extends JComponent implements PlotProviderListener {
|
||||||
for (n = 0; n < hints.length; n++){
|
for (n = 0; n < hints.length; n++){
|
||||||
hints[n] = this.ordinateViews[ordinate].scaler.getMinValue() + (this.ordinateViews[ordinate].scaler.getWindow() * n / (hints.length-1));
|
hints[n] = this.ordinateViews[ordinate].scaler.getMinValue() + (this.ordinateViews[ordinate].scaler.getWindow() * n / (hints.length-1));
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
|
} else if(nHints == 0) {
|
||||||
|
hints = new double[0];
|
||||||
|
}
|
||||||
|
else {
|
||||||
hints = scalerHints;
|
hints = scalerHints;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -363,7 +456,6 @@ public class JDiagram extends JComponent implements PlotProviderListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
plotWidth -= axMarkerLength;
|
plotWidth -= axMarkerLength;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
g.drawLine(
|
g.drawLine(
|
||||||
|
@ -397,9 +489,7 @@ public class JDiagram extends JComponent implements PlotProviderListener {
|
||||||
g.setColor( this.ordinateViews[ ordinate ].colDraw );
|
g.setColor( this.ordinateViews[ ordinate ].colDraw );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void paintAbszisse(Graphics2D g){
|
void paintAbszisse(Graphics2D g){
|
||||||
|
@ -415,8 +505,10 @@ public class JDiagram extends JComponent implements PlotProviderListener {
|
||||||
nMarker = plotWidth / (w*8/7);
|
nMarker = plotWidth / (w*8/7);
|
||||||
}
|
}
|
||||||
|
|
||||||
abszissMinimum = this.plotProvider.getPositionMinimum();
|
//abszissMinimum = this.plotProvider.getPositionMinimum();
|
||||||
abszissMaximum = this.plotProvider.getPositionMaximum();
|
//abszissMaximum = this.plotProvider.getPositionMaximum();
|
||||||
|
abszissMinimum = this.focusPoint;
|
||||||
|
abszissMaximum = this.focusPoint + this.focusRange;
|
||||||
abszissWindow = abszissMaximum - abszissMinimum;
|
abszissWindow = abszissMaximum - abszissMinimum;
|
||||||
|
|
||||||
g.setColor(getForeground());
|
g.setColor(getForeground());
|
||||||
|
@ -454,6 +546,8 @@ public class JDiagram extends JComponent implements PlotProviderListener {
|
||||||
);
|
);
|
||||||
g.setColor(getForeground());
|
g.setColor(getForeground());
|
||||||
};
|
};
|
||||||
|
if(n == 0)this.firstAbszissPos = getWidth() - bRight - plotWidth + xpos;
|
||||||
|
if(n == nMarker)this.lastAbszissPos = getWidth() - bRight - plotWidth + xpos;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -478,7 +572,9 @@ public class JDiagram extends JComponent implements PlotProviderListener {
|
||||||
graphColor = Color.BLACK;
|
graphColor = Color.BLACK;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int n=0;n<this.plotProvider.getLength(); n++){
|
int xMax = (int)this.focusPoint + (int)this.focusRange;
|
||||||
|
|
||||||
|
for (int n=0 + (int)this.focusPoint ;n<xMax; n++){
|
||||||
int x,y;
|
int x,y;
|
||||||
Float value = this.plotProvider.getValue(n, graph);
|
Float value = this.plotProvider.getValue(n, graph);
|
||||||
Float position = this.plotProvider.getPosition(n, graph);
|
Float position = this.plotProvider.getPosition(n, graph);
|
||||||
|
@ -491,9 +587,7 @@ public class JDiagram extends JComponent implements PlotProviderListener {
|
||||||
this.plotPainters[ graph ].paintPoint(g, graphColor, x, y, isSelected);
|
this.plotPainters[ graph ].paintPoint(g, graphColor, x, y, isSelected);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -524,7 +618,6 @@ public class JDiagram extends JComponent implements PlotProviderListener {
|
||||||
void setScaler(Scaler scaler){
|
void setScaler(Scaler scaler){
|
||||||
this.scaler = scaler;
|
this.scaler = scaler;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -533,4 +626,16 @@ public class JDiagram extends JComponent implements PlotProviderListener {
|
||||||
fundamentalsChanged();
|
fundamentalsChanged();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float getAverage(int graph) {
|
||||||
|
return this.plotProvider.getAverage(graph);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Float getMinValue(int graph) {
|
||||||
|
return this.plotProvider.getMinValue(graph);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Float getMaxValue(int graph) {
|
||||||
|
return this.plotProvider.getMaxValue(graph);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,20 +5,29 @@ import java.awt.Color;
|
||||||
public interface PlotProvider2 {
|
public interface PlotProvider2 {
|
||||||
|
|
||||||
public int getMaxOrdinate();
|
public int getMaxOrdinate();
|
||||||
|
public void setMaxOrdinate(int maxOrd);
|
||||||
public int getLength();
|
public int getLength();
|
||||||
public int getNumGraphs();
|
public int getNumGraphs();
|
||||||
public String getLabel(int graph);
|
public String getLabel(int graph);
|
||||||
public Float getValue(int x,int graph);
|
public Float getValue(int x,int graph);
|
||||||
|
public int getValueCount(int graph);
|
||||||
public Float getPosition(int x,int graph);
|
public Float getPosition(int x,int graph);
|
||||||
public int getOrdinate(int graph);
|
public int getOrdinate(int graph);
|
||||||
|
|
||||||
public Float getPositionMinimum();
|
public Float getPositionMinimum();
|
||||||
public Float getPositionMaximum();
|
public Float getPositionMaximum();
|
||||||
|
|
||||||
|
public int getMaxSamples();
|
||||||
|
public void setMaxSamples(int maxSamples);
|
||||||
|
|
||||||
|
public float getAverage(int graph);
|
||||||
|
public Float getMinValue(int graph);
|
||||||
|
public Float getMaxValue(int graph);
|
||||||
|
|
||||||
public Color[] getColors();
|
public Color[] getColors();
|
||||||
|
|
||||||
public void addPlotProviderListener(PlotProviderListener listener);
|
public void addPlotProviderListener(PlotProviderListener listener);
|
||||||
public void removePlotProviderListener(PlotProviderListener listener);
|
public void removePlotProviderListener(PlotProviderListener listener);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,8 +117,27 @@ public class SimplePlotProvider implements PlotProvider2 {
|
||||||
plotProviderListeners.remove(listener);
|
plotProviderListeners.remove(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
private void fireFundamentalsChanged(){
|
private void fireFundamentalsChanged(){
|
||||||
for (PlotProviderListener l: plotProviderListeners)
|
for (PlotProviderListener l: plotProviderListeners)
|
||||||
l.fundamentalsChanged(this);
|
l.fundamentalsChanged(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getValueCount(int graph) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxSamples() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMaxSamples(int maxSamples) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue