forked from LupusNobilis/java-org.hwo.ui
806 lines
19 KiB
Java
806 lines
19 KiB
Java
package org.hwo.ui;
|
|
|
|
import java.awt.Color;
|
|
import java.awt.Dimension;
|
|
import java.awt.Font;
|
|
import java.awt.Graphics;
|
|
import java.awt.Graphics2D;
|
|
import java.awt.Point;
|
|
import java.awt.Toolkit;
|
|
import java.awt.event.MouseAdapter;
|
|
import java.awt.event.MouseEvent;
|
|
import java.awt.event.MouseMotionListener;
|
|
import java.awt.event.MouseWheelEvent;
|
|
import java.awt.event.MouseWheelListener;
|
|
import java.awt.geom.Point2D;
|
|
import java.util.LinkedList;
|
|
|
|
import javax.swing.BoundedRangeModel;
|
|
import javax.swing.JComponent;
|
|
import javax.swing.JPanel;
|
|
import javax.swing.event.ChangeEvent;
|
|
import javax.swing.event.ChangeListener;
|
|
|
|
import org.hwo.ui.diagram.DiagramListener;
|
|
import org.hwo.ui.diagram.DiagramViewEvent;
|
|
import org.hwo.ui.diagram.LinePlotPainter;
|
|
import org.hwo.ui.diagram.LinearScaler;
|
|
import org.hwo.ui.diagram.PlotLabeler;
|
|
import org.hwo.ui.diagram.PlotPainter;
|
|
import org.hwo.ui.diagram.PlotProvider2;
|
|
import org.hwo.ui.diagram.PlotProviderListener;
|
|
import org.hwo.ui.diagram.Scaler;
|
|
import org.hwo.ui.diagram.SimplePlotLabeler;
|
|
import org.hwo.ui.diagram.SimplePlotProvider;
|
|
|
|
public class JDiagram extends JComponent implements PlotProviderListener, BoundedRangeModel {
|
|
|
|
private enum DDragMode { NONE, PAN }
|
|
|
|
private LinkedList<DiagramListener> diagramListeners = new LinkedList<>();
|
|
private LinkedList<ChangeListener> changeListeners = new LinkedList<>();
|
|
|
|
private PlotProvider2
|
|
plotProvider;
|
|
|
|
private PlotLabeler
|
|
defaultLabeler,
|
|
abszissLabeler;
|
|
|
|
// Innenabstand zu Zeichnungselementen
|
|
private int bTop,
|
|
bBottom,
|
|
bLeft,
|
|
bRight;
|
|
|
|
// Länge der Achsenmarkierungen
|
|
private int axMarkerLength;
|
|
|
|
// Anzahl der Achsenmarkierungen - 1
|
|
private int nOrdinateLabels,
|
|
nAbszissLabels;
|
|
|
|
|
|
|
|
// Layout Merker
|
|
private int plotHeight,
|
|
plotWidth;
|
|
|
|
private double abszissMinimum,
|
|
abszissWindow;
|
|
|
|
|
|
private int screenDPI;
|
|
private int fontLineHeight;
|
|
|
|
private boolean autoOrdinateLabeling;
|
|
private boolean drawHorizontalGrid;
|
|
private boolean drawVerticalGrid;
|
|
private boolean logarithmic;
|
|
private boolean preferLabelHints;
|
|
private boolean autoScale;
|
|
private boolean autoScaleMargins;
|
|
|
|
private Color verticalGridColor;
|
|
|
|
private OrdinateView[]
|
|
ordinateViews;
|
|
|
|
private PlotPainter[]
|
|
plotPainters;
|
|
|
|
private Integer selectedPlot;
|
|
|
|
private DDragMode dragMode;
|
|
private Point2D dragPoint;
|
|
private Point dragMousePoint;
|
|
|
|
private double dragPanStart;
|
|
|
|
private double mouseWheelZoom = 1.03;
|
|
|
|
|
|
public JDiagram(){
|
|
setMinimumSize(new Dimension(80, 80));
|
|
setDoubleBuffered(true);
|
|
|
|
|
|
defaultLabeler = new SimplePlotLabeler();
|
|
abszissLabeler = defaultLabeler;
|
|
|
|
bTop = bBottom = bLeft = 10;
|
|
bRight = 30;
|
|
axMarkerLength = 3;
|
|
|
|
nOrdinateLabels = 11;
|
|
nAbszissLabels = 0;
|
|
|
|
drawHorizontalGrid = true;
|
|
|
|
verticalGridColor = new Color(192, 192, 192);
|
|
setBackground(Color.black);
|
|
setForeground(Color.WHITE);
|
|
|
|
setPlotProvider(new SimplePlotProvider(1, 0));
|
|
|
|
addMouseListener(new MouseAdapter() {
|
|
@Override
|
|
public void mousePressed(MouseEvent e) {
|
|
switch (e.getButton()) {
|
|
case MouseEvent.BUTTON2:
|
|
dragMode = DDragMode.PAN;
|
|
dragMousePoint = e.getPoint();
|
|
dragPoint = mapMouseToDiagram(dragMousePoint);
|
|
dragPanStart = getAbszissMinimum();
|
|
break;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void mouseReleased(MouseEvent e) {
|
|
dragMode = DDragMode.NONE;
|
|
}
|
|
});
|
|
|
|
addMouseMotionListener(new MouseAdapter() {
|
|
@Override
|
|
public void mouseDragged(MouseEvent e) {
|
|
Point2D p = mapMouseToDiagram(dragMousePoint);
|
|
Point2D np = mapMouseToDiagram(e.getPoint());
|
|
double dx = np.getX() - p.getX();
|
|
|
|
switch (dragMode) {
|
|
case PAN:
|
|
double nmin = dragPanStart - dx;
|
|
|
|
nmin = limitAbszissMinimum(nmin);
|
|
|
|
setAbszissMinimum(nmin);
|
|
repaint();
|
|
break;
|
|
}
|
|
}
|
|
});
|
|
|
|
addMouseWheelListener(new MouseWheelListener() {
|
|
|
|
@Override
|
|
public void mouseWheelMoved(MouseWheelEvent e) {
|
|
|
|
double newwindow = getAbszissWindow() * Math.pow(mouseWheelZoom,e.getPreciseWheelRotation());
|
|
Point2D mp = mapMouseToDiagram(e.getPoint());
|
|
|
|
double pmin = plotProvider.getPositionMinimum();
|
|
double pmax = plotProvider.getPositionMaximum();
|
|
|
|
double maxwindow = pmax - pmin;
|
|
|
|
newwindow = newwindow > maxwindow ? maxwindow : newwindow;
|
|
|
|
setAbszissWindow(newwindow);
|
|
|
|
Point2D mp2 = mapMouseToDiagram(e.getPoint());
|
|
double nmin = getAbszissMinimum() + mp.getX() - mp2.getX();
|
|
|
|
nmin = limitAbszissMinimum(nmin);
|
|
setAbszissMinimum( nmin );
|
|
|
|
repaint();
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
private void fireViewWindowChanged(){
|
|
for (DiagramListener l: diagramListeners) {
|
|
l.ViewWindowChanged(new DiagramViewEvent(this));
|
|
}
|
|
for (ChangeListener l: changeListeners) {
|
|
l.stateChanged(new ChangeEvent(this));
|
|
}
|
|
}
|
|
|
|
public void addDiagramListener(DiagramListener l) {
|
|
this.diagramListeners.add(l);
|
|
}
|
|
public void removeDiagramListener(DiagramListener l) {
|
|
this.diagramListeners.remove(l);
|
|
}
|
|
|
|
public void setPlotProvider(PlotProvider2 plotProvider) {
|
|
if (this.plotProvider != null)
|
|
this.plotProvider.removePlotProviderListener(this);
|
|
|
|
this.plotProvider = plotProvider;
|
|
if (this.plotProvider != null)
|
|
this.plotProvider.addPlotProviderListener(this);
|
|
|
|
fundamentalsChanged();
|
|
}
|
|
public PlotProvider2 getPlotProvider() {
|
|
return plotProvider;
|
|
}
|
|
|
|
public boolean isAutoOrdinateLabeling() {
|
|
return autoOrdinateLabeling;
|
|
}
|
|
public void setAutoOrdinateLabeling(boolean autoOrdinateLabeling) {
|
|
this.autoOrdinateLabeling = autoOrdinateLabeling;
|
|
}
|
|
|
|
public boolean isDrawHorizontalGrid() {
|
|
return drawHorizontalGrid;
|
|
}
|
|
public void setDrawHorizontalGrid(boolean drawHorizontalGrid) {
|
|
this.drawHorizontalGrid = drawHorizontalGrid;
|
|
}
|
|
|
|
public boolean isDrawVerticalGrid() {
|
|
return drawVerticalGrid;
|
|
}
|
|
public void setDrawVerticalGrid(boolean drawVerticalGrid) {
|
|
this.drawVerticalGrid = drawVerticalGrid;
|
|
}
|
|
|
|
public Integer getSelectedPlot() {
|
|
return selectedPlot;
|
|
}
|
|
public void setSelectedPlot(Integer selectedPlot) {
|
|
this.selectedPlot = selectedPlot;
|
|
}
|
|
|
|
private void fundamentalsChanged(){
|
|
if (plotProvider != null){
|
|
ordinateViews = new OrdinateView[ plotProvider.getMaxOrdinate() + 1 ];
|
|
for (int n=0; n < plotProvider.getMaxOrdinate() + 1; n++)
|
|
ordinateViews[n] = new OrdinateView(n);
|
|
|
|
PlotPainter pp = new LinePlotPainter();
|
|
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];
|
|
}
|
|
}
|
|
|
|
public Scaler getScaler(int ordinate){
|
|
return this.ordinateViews[ordinate].scaler;
|
|
}
|
|
public void setScaler(int ordinate,Scaler scaler){
|
|
this.ordinateViews[ordinate].scaler = scaler;
|
|
}
|
|
|
|
public PlotPainter getPlotPainter(int graph){
|
|
return this.plotPainters[graph];
|
|
}
|
|
public void setPlotPainter(int graph,PlotPainter plotPainter){
|
|
this.plotPainters[graph] = plotPainter;
|
|
}
|
|
|
|
public int getAbszissLabels() {
|
|
return nAbszissLabels;
|
|
}
|
|
public void setAbszissLabels(int nAbszissLabels) {
|
|
this.nAbszissLabels = nAbszissLabels;
|
|
}
|
|
|
|
public int getOrdinateLabels() {
|
|
return nOrdinateLabels;
|
|
}
|
|
public void setOrdinateLabels(int nOrdinateLabels) {
|
|
this.nOrdinateLabels = nOrdinateLabels;
|
|
}
|
|
|
|
public Color getOrdinateColor(int ordinate){
|
|
return this.ordinateViews[ ordinate ].colDraw;
|
|
}
|
|
public void setOrdinateColor(int ordinate,Color color){
|
|
int r,g,b;
|
|
this.ordinateViews[ ordinate ].colDraw = color;
|
|
r = (color.getRed() + 768)/4;
|
|
g = (color.getGreen() + 768)/4;
|
|
b = (color.getBlue() + 768)/4;
|
|
this.ordinateViews[ ordinate ].colGrid = new Color(r,g,b);
|
|
}
|
|
|
|
public boolean isPreferLabelHints() {
|
|
return preferLabelHints;
|
|
}
|
|
public void setPreferLabelHints(boolean preferLabelHints) {
|
|
this.preferLabelHints = preferLabelHints;
|
|
}
|
|
|
|
public boolean isAutoScale() {
|
|
return autoScale;
|
|
}
|
|
public void setAutoScale(boolean autoScale) {
|
|
this.autoScale = autoScale;
|
|
}
|
|
|
|
public boolean isAutoScaleMargins() {
|
|
return autoScaleMargins;
|
|
}
|
|
public void setAutoScaleMargins(boolean autoScaleMargins) {
|
|
this.autoScaleMargins = autoScaleMargins;
|
|
}
|
|
|
|
public PlotLabeler getAbszissLabeler() {
|
|
return abszissLabeler;
|
|
}
|
|
public void setAbszissLabeler(PlotLabeler abszissLabeler) {
|
|
this.abszissLabeler = abszissLabeler;
|
|
}
|
|
|
|
|
|
public void autoscale(){
|
|
int ordinate;
|
|
Double[] max,min;
|
|
|
|
System.err.println("AutoScale...");
|
|
|
|
max = new Double[this.plotProvider.getMaxOrdinate()+1];
|
|
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);
|
|
if (value != null)
|
|
{
|
|
if ((min[ordinate] == null) || (value < min[ordinate]))
|
|
min[ordinate] = value.doubleValue();
|
|
if ((max[ordinate] == null) || (value > max[ordinate]))
|
|
max[ordinate] = value.doubleValue();
|
|
};
|
|
}
|
|
}
|
|
|
|
for (int i=0;i<this.plotProvider.getMaxOrdinate()+1;i++){
|
|
if (min[i] == null)
|
|
min[i] = 0.0;
|
|
if (max[i] == null)
|
|
max[i] = 1.0;
|
|
System.err.format("MIN: %f Max: %f\n", min[i], max[i]);
|
|
|
|
this.ordinateViews[i].scaler.scale(min[i], max[i], autoScaleMargins);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
@Override
|
|
public void paint(Graphics g) {
|
|
screenDPI = Toolkit.getDefaultToolkit().getScreenResolution();
|
|
|
|
fontLineHeight = getFont().getSize() * screenDPI / 72;
|
|
|
|
plotHeight = getHeight() - bTop - bBottom - fontLineHeight - axMarkerLength;
|
|
plotWidth = getWidth() - bLeft - bRight;
|
|
|
|
g.setFont( getFont() );
|
|
|
|
// Hintergrund zeichnen
|
|
g.setColor(getBackground());
|
|
g.fillRect(0, 0, getWidth(), getHeight());
|
|
|
|
if (plotProvider != null){
|
|
|
|
if (autoScale)
|
|
this.autoscale();
|
|
|
|
paintOrdinates ((Graphics2D) g);
|
|
paintAbszisse ((Graphics2D) g);
|
|
paintGraphs ((Graphics2D) g);
|
|
}
|
|
}
|
|
|
|
public double[] getordinateLabelHints(int ordinate){
|
|
double[] scalerHints = this.ordinateViews[ordinate].scaler.getMarkerHints();
|
|
double[] hints = null;
|
|
int nHints = autoOrdinateLabeling ? plotHeight / (fontLineHeight * 2) : nOrdinateLabels;
|
|
int n;
|
|
|
|
if ((nHints > 0) && ((scalerHints == null) || (!preferLabelHints))) {
|
|
if (nHints < 2)
|
|
nHints = 2;
|
|
|
|
hints = new double[nHints];
|
|
|
|
for (n = 0; n < hints.length; n++){
|
|
hints[n] = this.ordinateViews[ordinate].scaler.getMinValue() + (this.ordinateViews[ordinate].scaler.getWindow() * n / (hints.length-1));
|
|
}
|
|
} else {
|
|
hints = scalerHints;
|
|
}
|
|
|
|
return hints;
|
|
}
|
|
|
|
public void paintOrdinates(Graphics2D g){
|
|
double[][] labelValues = new double[ ordinateViews.length ][];
|
|
Integer last_y = null,
|
|
y = null,
|
|
d = null;
|
|
|
|
for (int ordinate=0; ordinate < ordinateViews.length; 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 ];
|
|
|
|
|
|
this.ordinateViews[ ordinate ].scaler.setHeight( plotHeight );
|
|
|
|
g.setColor( this.ordinateViews[ ordinate ].colDraw );
|
|
|
|
for (int i=0;i<=nMarkers;i++){
|
|
labels[i] = this.defaultLabeler.getOrdinateLabel(
|
|
this,
|
|
ordinate,
|
|
labelValues[ordinate][i]
|
|
);
|
|
labelWidths[i] = g.getFontMetrics().stringWidth(labels[i]);
|
|
|
|
if (labelWidths[i] > maxWidth)
|
|
maxWidth = labelWidths[i];
|
|
}
|
|
|
|
plotWidth -= maxWidth + 5;
|
|
last_y = null;
|
|
|
|
for (int i=0; i<=nMarkers ;i++){
|
|
y = bTop + plotHeight - this.ordinateViews[ ordinate ].scaler.getPosition(labelValues[ordinate][i]) + (fontLineHeight/4);
|
|
if (last_y == null){
|
|
d = null;
|
|
} else {
|
|
d = y -last_y;
|
|
if (d<0)
|
|
d = -d;
|
|
};
|
|
|
|
if ((d == null) || (d > fontLineHeight )) {
|
|
g.drawString(
|
|
labels[i],
|
|
getWidth() - bRight - plotWidth - labelWidths[i],
|
|
y
|
|
);
|
|
last_y = y;
|
|
}
|
|
}
|
|
|
|
plotWidth -= axMarkerLength;
|
|
|
|
};
|
|
|
|
g.drawLine(
|
|
getWidth() - bRight - plotWidth,
|
|
bTop,
|
|
getWidth() - bRight - plotWidth,
|
|
bTop + plotHeight
|
|
);
|
|
|
|
for (int ordinate=0; ordinate < ordinateViews.length; ordinate++){
|
|
int nMarkers = labelValues[ ordinate ].length - 1;
|
|
|
|
for (int i=0;i<=nMarkers;i++){
|
|
int yp = bTop + plotHeight - this.ordinateViews[ ordinate ].scaler.getPosition(labelValues[ordinate][i]);
|
|
|
|
g.drawLine(
|
|
getWidth() - bRight - plotWidth,
|
|
yp,
|
|
getWidth() - bRight - plotWidth - axMarkerLength,
|
|
yp
|
|
);
|
|
|
|
if (drawHorizontalGrid){
|
|
g.setColor( this.ordinateViews[ ordinate ].colGrid );
|
|
g.drawLine(
|
|
getWidth() - bRight - plotWidth + 1,
|
|
yp,
|
|
getWidth() - bRight,
|
|
yp
|
|
);
|
|
g.setColor( this.ordinateViews[ ordinate ].colDraw );
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void paintAbszisse(Graphics2D g){
|
|
int nMarker = nAbszissLabels;
|
|
|
|
PlotLabeler labeler = this.defaultLabeler;
|
|
|
|
if (this.abszissLabeler != null)
|
|
labeler = this.abszissLabeler;
|
|
|
|
if (nMarker == 0){
|
|
int w = g.getFontMetrics().stringWidth( labeler.getAbzisseLabel(this, (double)this.plotProvider.getPositionMaximum()));
|
|
nMarker = plotWidth / (w*8/7);
|
|
}
|
|
|
|
// TODO change for zoom
|
|
//abszissMinimum = this.plotProvider.getPositionMinimum();
|
|
//abszissMaximum = this.plotProvider.getPositionMaximum();
|
|
//abszissWindow = abszissMaximum - abszissMinimum;
|
|
|
|
g.setColor(getForeground());
|
|
|
|
g.drawLine(
|
|
getWidth() - bRight - plotWidth,
|
|
bTop + plotHeight,
|
|
getWidth() - bRight,
|
|
bTop + plotHeight
|
|
);
|
|
|
|
if (nMarker > 0)
|
|
for (int n=0;n <= nMarker; n++){
|
|
int xpos = plotWidth * n / nMarker;
|
|
double pos = abszissMinimum + (abszissWindow * n / nMarker);
|
|
|
|
String xlabel = labeler.getAbzisseLabel(this, pos);
|
|
int xlwidth = g.getFontMetrics().stringWidth(xlabel);
|
|
|
|
g.drawString(xlabel, getWidth() - bRight - plotWidth + xpos - (xlwidth / 2) , getHeight() - bBottom);
|
|
g.drawLine(
|
|
getWidth() - bRight - plotWidth + xpos,
|
|
bTop + plotHeight,
|
|
getWidth() - bRight - plotWidth + xpos,
|
|
bTop + plotHeight + axMarkerLength
|
|
);
|
|
|
|
if (drawVerticalGrid){
|
|
g.setColor(verticalGridColor);
|
|
g.drawLine(
|
|
getWidth() - bRight - plotWidth + xpos,
|
|
bTop,
|
|
getWidth() - bRight - plotWidth + xpos,
|
|
bTop + plotHeight
|
|
);
|
|
g.setColor(getForeground());
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void paintGraphs(Graphics2D g){
|
|
int ordinate;
|
|
Color graphColor;
|
|
Color[] graphColors = this.plotProvider.getColors();
|
|
|
|
double amax = this.getAbszissMaximum();
|
|
|
|
for (int graph=0; graph < this.plotProvider.getNumGraphs(); graph++){
|
|
boolean isSelected = ((selectedPlot != null) && selectedPlot.equals(graph));
|
|
|
|
this.plotPainters[ graph ].reset();
|
|
ordinate = this.plotProvider.getOrdinate(graph);
|
|
graphColor = graphColors[graph];
|
|
|
|
if (graphColor == null){
|
|
graphColor = this.ordinateViews[ordinate].colDraw;
|
|
}
|
|
if (graphColor == null){
|
|
graphColor = Color.BLACK;
|
|
}
|
|
|
|
for (int n=0;n<this.plotProvider.getLength(); n++){
|
|
int x,y;
|
|
Float value = this.plotProvider.getValue(n, graph);
|
|
Float position = this.plotProvider.getPosition(n, graph);
|
|
|
|
if ((value != null) && (position != null) && (position >= this.abszissMinimum) && (position <= amax))
|
|
{
|
|
x = getWidth() - bRight - plotWidth + (int)((position - abszissMinimum) * plotWidth / abszissWindow);
|
|
y = bTop + plotHeight - this.ordinateViews[ ordinate ].scaler.getPosition(value);
|
|
|
|
this.plotPainters[ graph ].paintPoint(g, graphColor, x, y, isSelected);
|
|
};
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
* Pan and Zoom
|
|
*/
|
|
|
|
public double getAbszissWindow() {
|
|
return this.abszissWindow;
|
|
}
|
|
|
|
public void setAbszissWindow(double width){
|
|
setAbszissWindow(width, true);
|
|
}
|
|
private void setAbszissWindow(double width,boolean fireEvent){
|
|
this.abszissWindow = width;
|
|
if (fireEvent) {
|
|
fireViewWindowChanged();
|
|
}
|
|
repaint();
|
|
}
|
|
|
|
public double getAbszissMinimum() {
|
|
return this.abszissMinimum;
|
|
}
|
|
public void setAbszissMinimum(double x) {
|
|
this.abszissMinimum = x;
|
|
fireViewWindowChanged();
|
|
repaint();
|
|
}
|
|
|
|
public double getAbszissMaximum() {
|
|
return this.abszissMinimum + this.abszissWindow;
|
|
}
|
|
public void setAbszissMaximum(double x) {
|
|
this.abszissWindow = x - this.abszissMinimum;
|
|
fireViewWindowChanged();
|
|
repaint();
|
|
}
|
|
|
|
public double getMouseWheelZoom() {
|
|
return mouseWheelZoom;
|
|
}
|
|
public void setMouseWheelZoom(double mouseWheelZoom) {
|
|
this.mouseWheelZoom = mouseWheelZoom;
|
|
}
|
|
|
|
/*
|
|
* Tool methods
|
|
*/
|
|
|
|
public Point2D mapMouseToDiagram(Point p) {
|
|
return this.mapMouseToDiagram(p,0);
|
|
}
|
|
public Point2D mapMouseToDiagram(Point p,int ordinate) {
|
|
double x,y;
|
|
|
|
int xl = (getWidth() - bRight - plotWidth);
|
|
|
|
|
|
x = this.abszissMinimum + (((p.getX() - xl) / plotWidth) * this.abszissWindow);
|
|
// TODO implement reverse mapping into scaler interface ??!!
|
|
y = this.ordinateViews[ ordinate ].scaler.getMinValue() - ((p.getY() - bTop - plotHeight) / plotHeight * this.ordinateViews[ ordinate ].scaler.getWindow());
|
|
|
|
return new Point2D.Double(x, y);
|
|
}
|
|
|
|
public Point mapDiagramToMouse(Point2D p){
|
|
return mapDiagramToMouse(p, 0);
|
|
}
|
|
public Point mapDiagramToMouse(Point2D p,int ordinate) {
|
|
int x,y;
|
|
|
|
x = getWidth() - bRight - plotWidth + (int)((p.getX() - abszissMinimum) * plotWidth / abszissWindow);
|
|
y = bTop + plotHeight - this.ordinateViews[ ordinate ].scaler.getPosition(p.getY());
|
|
|
|
return new Point(x, y);
|
|
}
|
|
|
|
public double limitAbszissMinimum(double nmin) {
|
|
double pmin,pmax;
|
|
|
|
pmin = plotProvider.getPositionMinimum();
|
|
pmax = plotProvider.getPositionMaximum();
|
|
|
|
nmin = nmin < pmin ? pmin : nmin;
|
|
nmin = (nmin + getAbszissWindow()) > pmax ? pmax - getAbszissWindow() : nmin;
|
|
|
|
return nmin;
|
|
}
|
|
|
|
|
|
|
|
class OrdinateView {
|
|
|
|
int num;
|
|
|
|
Color colDraw,
|
|
colGrid;
|
|
|
|
int ordinateLabelWidth;
|
|
|
|
Scaler scaler;
|
|
|
|
|
|
public OrdinateView(int num) {
|
|
this.num = num;
|
|
|
|
this.colDraw = Color.BLACK;
|
|
this.colGrid = Color.LIGHT_GRAY;
|
|
|
|
this.scaler = new LinearScaler();
|
|
}
|
|
|
|
Scaler getScaler(){
|
|
return this.scaler;
|
|
}
|
|
void setScaler(Scaler scaler){
|
|
this.scaler = scaler;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
public void fundamentalsChanged(PlotProvider2 plotProvider) {
|
|
fundamentalsChanged();
|
|
|
|
}
|
|
|
|
@Override
|
|
public int getMinimum() {
|
|
return (int)(plotProvider.getPositionMinimum() * 1000.0f);
|
|
}
|
|
|
|
@Override
|
|
public void setMinimum(int newMinimum) {
|
|
}
|
|
|
|
@Override
|
|
public int getMaximum() {
|
|
return (int)(plotProvider.getPositionMaximum() * 1000.0f);
|
|
}
|
|
|
|
@Override
|
|
public void setMaximum(int newMaximum) {
|
|
}
|
|
|
|
@Override
|
|
public int getValue() {
|
|
return (int)(getAbszissMinimum() * 1000.0f);
|
|
}
|
|
|
|
@Override
|
|
public void setValue(int newValue) {
|
|
setAbszissMinimum( ((double)newValue / 1000.0f) );
|
|
}
|
|
|
|
@Override
|
|
public void setValueIsAdjusting(boolean b) {
|
|
}
|
|
|
|
@Override
|
|
public boolean getValueIsAdjusting() {
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public int getExtent() {
|
|
return (int)(getAbszissWindow() * 1000.0f);
|
|
}
|
|
|
|
@Override
|
|
public void setExtent(int newExtent) {
|
|
setAbszissWindow( ((double)newExtent / 1000.0f) );
|
|
}
|
|
|
|
@Override
|
|
public void setRangeProperties(int value, int extent, int min, int max, boolean adjusting) {
|
|
setMinimum(min);
|
|
setMaximum(max);
|
|
setExtent(extent);
|
|
setValue(value);
|
|
}
|
|
|
|
@Override
|
|
public void addChangeListener(ChangeListener x) {
|
|
this.changeListeners.add(x);
|
|
}
|
|
|
|
@Override
|
|
public void removeChangeListener(ChangeListener x) {
|
|
this.changeListeners.remove(x);
|
|
}
|
|
}
|