Compare commits
2 Commits
master
...
thobaben_d
Author | SHA1 | Date |
---|---|---|
Niclas Thobaben | a5f3bc3781 | |
Niclas Thobaben | d86830f119 |
|
@ -0,0 +1,76 @@
|
|||
package org.hwo.ui;
|
||||
|
||||
import javax.swing.Action;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JToggleButton;
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
|
||||
public class JColoredToggleButton extends JToggleButton {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
private Color colorOff, colorOn;
|
||||
private boolean state = false;
|
||||
|
||||
public JColoredToggleButton(Color on, Color off) {
|
||||
this.colorOn = on;
|
||||
this.colorOff = off;
|
||||
}
|
||||
|
||||
public JColoredToggleButton(String text, Color on, Color off) {
|
||||
super(text);
|
||||
this.colorOn = on;
|
||||
this.colorOff = off;
|
||||
}
|
||||
|
||||
public JColoredToggleButton(Action a) {
|
||||
super(a);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public JColoredToggleButton(Icon icon, boolean selected) {
|
||||
super(icon, selected);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public JColoredToggleButton(String text, boolean selected) {
|
||||
super(text, selected);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public JColoredToggleButton(String text, Icon icon) {
|
||||
super(text, icon);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public JColoredToggleButton(String text, Icon icon, boolean selected) {
|
||||
super(text, icon, selected);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public void toggle(boolean tgl) {
|
||||
this.state = tgl;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void paint(Graphics g) {
|
||||
super.paint(g);
|
||||
|
||||
if(state) {
|
||||
super.setBackground(colorOff);
|
||||
super.setForeground(colorOff);
|
||||
}
|
||||
else {
|
||||
super.setBackground(colorOn);
|
||||
super.setForeground(colorOn);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -6,6 +6,7 @@ import java.awt.Font;
|
|||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.geom.Point2D;
|
||||
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JPanel;
|
||||
|
@ -22,6 +23,11 @@ import org.hwo.ui.diagram.SimplePlotProvider;
|
|||
|
||||
public class JDiagram extends JComponent implements PlotProviderListener {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private PlotProvider2
|
||||
plotProvider;
|
||||
|
||||
|
@ -48,9 +54,13 @@ public class JDiagram extends JComponent implements PlotProviderListener {
|
|||
private int plotHeight,
|
||||
plotWidth;
|
||||
|
||||
|
||||
private double abszissMinimum,
|
||||
abszissMaximum,
|
||||
abszissWindow;
|
||||
//Positions of first and last abszisslabel
|
||||
private int firstAbszissPos;
|
||||
private int lastAbszissPos;
|
||||
|
||||
|
||||
private int screenDPI;
|
||||
|
@ -59,7 +69,7 @@ public class JDiagram extends JComponent implements PlotProviderListener {
|
|||
private boolean autoOrdinateLabeling;
|
||||
private boolean drawHorizontalGrid;
|
||||
private boolean drawVerticalGrid;
|
||||
private boolean logarithmic;
|
||||
//private boolean logarithmic;
|
||||
private boolean preferLabelHints;
|
||||
private boolean autoScale;
|
||||
private boolean autoScaleMargins;
|
||||
|
@ -74,6 +84,14 @@ public class JDiagram extends JComponent implements PlotProviderListener {
|
|||
|
||||
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(){
|
||||
setMinimumSize(new Dimension(80, 80));
|
||||
|
@ -105,6 +123,8 @@ public class JDiagram extends JComponent implements PlotProviderListener {
|
|||
if (this.plotProvider != null)
|
||||
this.plotProvider.addPlotProviderListener(this);
|
||||
|
||||
this.setFocus(this.plotProvider.getPositionMinimum(), this.plotProvider.getPositionMaximum());
|
||||
|
||||
fundamentalsChanged();
|
||||
}
|
||||
public PlotProvider2 getPlotProvider() {
|
||||
|
@ -149,6 +169,7 @@ public class JDiagram extends JComponent implements PlotProviderListener {
|
|||
plotPainters = new PlotPainter[plotProvider.getNumGraphs()];
|
||||
for (int n=0;n<plotProvider.getNumGraphs();n++)
|
||||
plotPainters[n] = pp;
|
||||
|
||||
} else {
|
||||
ordinateViews = new OrdinateView[0];
|
||||
plotPainters = new PlotPainter[0];
|
||||
|
@ -223,8 +244,19 @@ public class JDiagram extends JComponent implements PlotProviderListener {
|
|||
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;
|
||||
Double[] max,min;
|
||||
|
||||
|
@ -234,6 +266,7 @@ public class JDiagram extends JComponent implements PlotProviderListener {
|
|||
min = new Double[this.plotProvider.getMaxOrdinate()+1];
|
||||
|
||||
for (int graph=0; graph < this.plotProvider.getNumGraphs(); graph++){
|
||||
|
||||
ordinate = this.plotProvider.getOrdinate(graph);
|
||||
for (int n=0;n<this.plotProvider.getLength(); n++){
|
||||
Float value = this.plotProvider.getValue(n, graph);
|
||||
|
@ -244,9 +277,15 @@ public class JDiagram extends JComponent implements PlotProviderListener {
|
|||
if ((max[ordinate] == null) || (value > max[ordinate]))
|
||||
max[ordinate] = value.doubleValue();
|
||||
};
|
||||
|
||||
//autoscale x-axis
|
||||
if(this.plotProvider.getValueCount(graph) >= this.plotProvider.getMaxSamples())
|
||||
{
|
||||
this.plotProvider.setMaxSamples(this.plotProvider.getMaxSamples() + 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (int i=0;i<this.plotProvider.getMaxOrdinate()+1;i++){
|
||||
if (min[i] == null)
|
||||
min[i] = 0.0;
|
||||
|
@ -256,8 +295,58 @@ public class JDiagram extends JComponent implements PlotProviderListener {
|
|||
|
||||
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
|
||||
|
@ -275,15 +364,15 @@ public class JDiagram extends JComponent implements PlotProviderListener {
|
|||
g.setColor(getBackground());
|
||||
g.fillRect(0, 0, getWidth(), getHeight());
|
||||
|
||||
if (plotProvider != null){
|
||||
|
||||
if (autoScale)
|
||||
this.autoscale();
|
||||
|
||||
if(plotProvider != null){
|
||||
if(this.autoScale) {
|
||||
autoscale();
|
||||
}
|
||||
paintOrdinates ((Graphics2D) g);
|
||||
paintAbszisse ((Graphics2D) g);
|
||||
paintGraphs ((Graphics2D) g);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public double[] getordinateLabelHints(int ordinate){
|
||||
|
@ -301,7 +390,11 @@ public class JDiagram extends JComponent implements PlotProviderListener {
|
|||
for (n = 0; n < hints.length; n++){
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -315,12 +408,12 @@ public class JDiagram extends JComponent implements PlotProviderListener {
|
|||
d = null;
|
||||
|
||||
for (int ordinate=0; ordinate < ordinateViews.length; ordinate++){
|
||||
labelValues[ ordinate ] = getordinateLabelHints(ordinate);
|
||||
labelValues[ ordinate ] = getordinateLabelHints(ordinate);
|
||||
int nMarkers = labelValues[ ordinate ].length - 1;
|
||||
|
||||
int maxWidth = 0;
|
||||
String[] labels = new String[ nMarkers + 1 ];
|
||||
int[] labelWidths = new int[ nMarkers + 1 ];
|
||||
int[] labelWidths = new int[ nMarkers + 1 ];
|
||||
|
||||
|
||||
this.ordinateViews[ ordinate ].scaler.setHeight( plotHeight );
|
||||
|
@ -363,7 +456,6 @@ public class JDiagram extends JComponent implements PlotProviderListener {
|
|||
}
|
||||
|
||||
plotWidth -= axMarkerLength;
|
||||
|
||||
};
|
||||
|
||||
g.drawLine(
|
||||
|
@ -397,9 +489,7 @@ public class JDiagram extends JComponent implements PlotProviderListener {
|
|||
g.setColor( this.ordinateViews[ ordinate ].colDraw );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void paintAbszisse(Graphics2D g){
|
||||
|
@ -415,8 +505,10 @@ public class JDiagram extends JComponent implements PlotProviderListener {
|
|||
nMarker = plotWidth / (w*8/7);
|
||||
}
|
||||
|
||||
abszissMinimum = this.plotProvider.getPositionMinimum();
|
||||
abszissMaximum = this.plotProvider.getPositionMaximum();
|
||||
//abszissMinimum = this.plotProvider.getPositionMinimum();
|
||||
//abszissMaximum = this.plotProvider.getPositionMaximum();
|
||||
abszissMinimum = this.focusPoint;
|
||||
abszissMaximum = this.focusPoint + this.focusRange;
|
||||
abszissWindow = abszissMaximum - abszissMinimum;
|
||||
|
||||
g.setColor(getForeground());
|
||||
|
@ -454,7 +546,9 @@ public class JDiagram extends JComponent implements PlotProviderListener {
|
|||
);
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
Float value = this.plotProvider.getValue(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);
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -515,7 +609,7 @@ public class JDiagram extends JComponent implements PlotProviderListener {
|
|||
this.colDraw = Color.BLACK;
|
||||
this.colGrid = Color.LIGHT_GRAY;
|
||||
|
||||
this.scaler = new LinearScaler();
|
||||
this.scaler = new LinearScaler();
|
||||
}
|
||||
|
||||
Scaler getScaler(){
|
||||
|
@ -524,13 +618,24 @@ public class JDiagram extends JComponent implements PlotProviderListener {
|
|||
void setScaler(Scaler scaler){
|
||||
this.scaler = scaler;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void fundamentalsChanged(PlotProvider2 plotProvider) {
|
||||
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 int getMaxOrdinate();
|
||||
public void setMaxOrdinate(int maxOrd);
|
||||
public int getLength();
|
||||
public int getNumGraphs();
|
||||
public String getLabel(int graph);
|
||||
public Float getValue(int x,int graph);
|
||||
public int getValueCount(int graph);
|
||||
public Float getPosition(int x,int graph);
|
||||
public int getOrdinate(int graph);
|
||||
|
||||
public Float getPositionMinimum();
|
||||
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 void addPlotProviderListener(PlotProviderListener listener);
|
||||
public void removePlotProviderListener(PlotProviderListener listener);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -117,8 +117,27 @@ public class SimplePlotProvider implements PlotProvider2 {
|
|||
plotProviderListeners.remove(listener);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private void fireFundamentalsChanged(){
|
||||
for (PlotProviderListener l: plotProviderListeners)
|
||||
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