forked from LupusNobilis/java-org.hwo.ui
Compare commits
2 Commits
master
...
JDiaAutoSc
Author | SHA1 | Date |
---|---|---|
Harald Wolff | f3382684ba | |
Harald Wolff | 059163730f |
|
@ -1,50 +1,36 @@
|
|||
package org.hwo.models;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import javax.swing.ComboBoxModel;
|
||||
import javax.swing.event.ListDataEvent;
|
||||
import javax.swing.event.ListDataListener;
|
||||
|
||||
import org.hwo.models.History.HistoryListener;
|
||||
public class ComboBoxHistoryModel<E> implements ComboBoxModel<E> {
|
||||
|
||||
public class ComboBoxHistoryModel<E> implements ComboBoxModel<E>,HistoryListener<E> {
|
||||
|
||||
private LinkedList<ListDataListener> listDataListeners = new LinkedList<>();
|
||||
private History<E> history;
|
||||
private LinkedList<ListDataListener> listDataListeners = new LinkedList();
|
||||
private LinkedList<E> items = new LinkedList();
|
||||
|
||||
private E selectedItem;
|
||||
private int historySize;
|
||||
|
||||
|
||||
public ComboBoxHistoryModel()
|
||||
{
|
||||
this.setHistory(new History<>());
|
||||
this.selectedItem = null;
|
||||
this.historySize = 10;
|
||||
}
|
||||
public ComboBoxHistoryModel(int historySize)
|
||||
{
|
||||
this.setHistory(new History<E>(historySize));
|
||||
this.selectedItem = null;
|
||||
}
|
||||
public ComboBoxHistoryModel(History<E> history){
|
||||
this.setHistory(history);
|
||||
this.historySize = historySize;
|
||||
}
|
||||
|
||||
public History<E> getHistory() {
|
||||
return history;
|
||||
}
|
||||
public void setHistory(History<E> history) {
|
||||
if (this.history != null) {
|
||||
this.history.removeHistoryListener(this);
|
||||
}
|
||||
this.history = history;
|
||||
if (this.history != null) {
|
||||
this.history.addHistoryListener(this);
|
||||
fireContentsChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void fireContentsChanged()
|
||||
{
|
||||
ListDataEvent lde = new ListDataEvent(this, ListDataEvent.CONTENTS_CHANGED, 0, this.history.size());
|
||||
ListDataEvent lde = new ListDataEvent(this, ListDataEvent.CONTENTS_CHANGED, 0, this.items.size());
|
||||
for (ListDataListener l: listDataListeners) {
|
||||
l.contentsChanged(lde);
|
||||
}
|
||||
|
@ -57,12 +43,12 @@ public class ComboBoxHistoryModel<E> implements ComboBoxModel<E>,HistoryListener
|
|||
|
||||
@Override
|
||||
public E getElementAt(int arg0) {
|
||||
return history.get(arg0);
|
||||
return items.get(arg0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return history.size();
|
||||
return items.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -78,54 +64,63 @@ public class ComboBoxHistoryModel<E> implements ComboBoxModel<E>,HistoryListener
|
|||
@Override
|
||||
public void setSelectedItem(Object arg0) {
|
||||
selectedItem = (E)arg0;
|
||||
if (selectedItem != null) {
|
||||
this.history.add(selectedItem);
|
||||
if (items.contains(selectedItem)) {
|
||||
items.remove(selectedItem);
|
||||
}
|
||||
items.add(0,selectedItem);
|
||||
clampHistory();
|
||||
}
|
||||
|
||||
public int getHistorySize() {
|
||||
return history.getHistorySize();
|
||||
return historySize;
|
||||
}
|
||||
|
||||
public void setHistorySize(int historySize) {
|
||||
this.history.setHistorySize(historySize);
|
||||
this.historySize = historySize;
|
||||
}
|
||||
|
||||
public Object[] getItems(){
|
||||
return history.getItems();
|
||||
return items.toArray();
|
||||
}
|
||||
|
||||
public E[] getItems(E[] at) {
|
||||
return history.getItems(at);
|
||||
return items.toArray(at);
|
||||
}
|
||||
|
||||
public void setItems(E[] items) {
|
||||
history.setItems(items);
|
||||
this.items.clear();
|
||||
this.items.addAll(Arrays.asList(items));
|
||||
if (!this.items.contains(selectedItem)) {
|
||||
selectedItem = null;
|
||||
}
|
||||
if (!clampHistory())
|
||||
fireContentsChanged();
|
||||
}
|
||||
|
||||
private boolean clampHistory() {
|
||||
if (items.size() > historySize) {
|
||||
while (items.size() > historySize) {
|
||||
items.removeLast();
|
||||
}
|
||||
fireContentsChanged();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void addElement(E element) {
|
||||
this.history.add(element);
|
||||
this.items.add(0,element);
|
||||
if (!clampHistory())
|
||||
fireContentsChanged();
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
this.history.clear();
|
||||
items.clear();
|
||||
fireContentsChanged();
|
||||
}
|
||||
|
||||
public boolean contains(E val) {
|
||||
return history.contains(val);
|
||||
}
|
||||
@Override
|
||||
public void HistoryChanged(History<E> history) {
|
||||
fireContentsChanged();
|
||||
}
|
||||
@Override
|
||||
public void HistoryItemAdded(History<E> history, E item) {
|
||||
fireContentsChanged();
|
||||
}
|
||||
@Override
|
||||
public void HistoryItemRemoved(History<E> history, E item) {
|
||||
fireContentsChanged();
|
||||
return items.contains(val);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,120 +0,0 @@
|
|||
package org.hwo.models;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
|
||||
public class History<E> {
|
||||
private LinkedList<HistoryListener<E>> historyListeners = new LinkedList<>();
|
||||
private LinkedList<E> items = new LinkedList<>();
|
||||
private int historySize = 10;
|
||||
|
||||
public History(){
|
||||
}
|
||||
|
||||
public History(int historySize) {
|
||||
this.historySize = historySize;
|
||||
}
|
||||
|
||||
public void addHistoryListener(HistoryListener<E> listener) {
|
||||
historyListeners.add(listener);
|
||||
}
|
||||
public void removeHistoryListener(HistoryListener<E> listener) {
|
||||
historyListeners.remove(listener);
|
||||
}
|
||||
|
||||
protected void fireHistoryChanged() {
|
||||
for (HistoryListener<E> historyListener : historyListeners) {
|
||||
historyListener.HistoryChanged(this);
|
||||
}
|
||||
}
|
||||
protected void fireHistoryItemAdded(E item) {
|
||||
for (HistoryListener<E> historyListener : historyListeners) {
|
||||
historyListener.HistoryItemAdded(this,item);
|
||||
}
|
||||
}
|
||||
protected void fireHistoryItemRemoved(E item) {
|
||||
for (HistoryListener<E> historyListener : historyListeners) {
|
||||
historyListener.HistoryItemRemoved(this, item);
|
||||
}
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
items.clear();
|
||||
fireHistoryChanged();
|
||||
}
|
||||
|
||||
public boolean contains(E item) {
|
||||
return items.contains(item);
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return this.items.size();
|
||||
}
|
||||
|
||||
public E get(int index) {
|
||||
return this.items.get(index);
|
||||
}
|
||||
|
||||
public Object[] getItems(){
|
||||
return items.toArray();
|
||||
}
|
||||
|
||||
public E[] getItems(E[] at) {
|
||||
return items.toArray(at);
|
||||
}
|
||||
|
||||
public void setItems(E[] items) {
|
||||
this.items.clear();
|
||||
this.items.addAll(Arrays.asList(items));
|
||||
fireHistoryChanged();
|
||||
|
||||
clampHistory();
|
||||
}
|
||||
|
||||
public void add(E item) {
|
||||
if (this.items.contains(item)) {
|
||||
if (this.items.indexOf(item) > 0) {
|
||||
this.items.remove(item);
|
||||
this.items.add(0,item);
|
||||
fireHistoryChanged();
|
||||
clampHistory();
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
this.items.add(0,item);
|
||||
fireHistoryItemAdded(item);
|
||||
clampHistory();
|
||||
}
|
||||
}
|
||||
|
||||
public void remove(E item) {
|
||||
this.items.remove(item);
|
||||
fireHistoryItemRemoved(item);
|
||||
}
|
||||
|
||||
private void clampHistory() {
|
||||
if (items.size() > historySize) {
|
||||
while (items.size() > historySize) {
|
||||
fireHistoryItemRemoved(items.removeLast());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public int getHistorySize() {
|
||||
return historySize;
|
||||
}
|
||||
|
||||
public void setHistorySize(int historySize) {
|
||||
this.historySize = historySize;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static interface HistoryListener<T> {
|
||||
void HistoryChanged(History<T> history);
|
||||
void HistoryItemAdded(History<T> history,T item);
|
||||
void HistoryItemRemoved(History<T> history,T item);
|
||||
}
|
||||
}
|
|
@ -31,8 +31,6 @@ public class JColoredToggleButton extends JLabel {
|
|||
|
||||
private boolean selected = false;
|
||||
|
||||
boolean mouseDown = false;
|
||||
|
||||
private LinkedList<ActionListener> actionListeners = new LinkedList<>();
|
||||
|
||||
public JColoredToggleButton() {
|
||||
|
@ -41,24 +39,14 @@ public class JColoredToggleButton extends JLabel {
|
|||
setOpaque(true);
|
||||
setFocusable(true);
|
||||
|
||||
addMouseListener(new MouseAdapter() {
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent arg0) {
|
||||
mouseDown = true;
|
||||
}
|
||||
addMouseListener(new MouseAdapter() {
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent arg0) {
|
||||
if (mouseDown) {
|
||||
toggle();
|
||||
}
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
toggle();
|
||||
}
|
||||
@Override
|
||||
public void mouseExited(MouseEvent arg0) {
|
||||
mouseDown = false;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
setSelected(false);
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ import java.awt.Dimension;
|
|||
import java.awt.Font;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.util.List;
|
||||
import java.awt.MouseInfo;
|
||||
import java.awt.Point;
|
||||
import java.awt.Toolkit;
|
||||
|
@ -28,13 +27,10 @@ import javax.swing.JPanel;
|
|||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
|
||||
import org.hwo.ui.diagram.CirclePlotPainter;
|
||||
import org.hwo.ui.diagram.ColoredBackground;
|
||||
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.MultiPlotPainter;
|
||||
import org.hwo.ui.diagram.PlotLabeler;
|
||||
import org.hwo.ui.diagram.PlotPainter;
|
||||
import org.hwo.ui.diagram.PlotProvider2;
|
||||
|
@ -115,11 +111,6 @@ public class JDiagram extends JComponent implements PlotProviderListener, Bounde
|
|||
private Point mousePos;
|
||||
|
||||
private double mouseWheelZoom = 1.03;
|
||||
|
||||
private double abzissSpacing;
|
||||
private boolean pointsEnabled;
|
||||
|
||||
private LinkedList<ColoredBackground> coloredBackgrounds = new LinkedList<>();
|
||||
|
||||
public JDiagram(){
|
||||
setMinimumSize(new Dimension(80, 80));
|
||||
|
@ -128,8 +119,7 @@ public class JDiagram extends JComponent implements PlotProviderListener, Bounde
|
|||
defaultLabeler = new SimplePlotLabeler();
|
||||
abszissLabeler = defaultLabeler;
|
||||
|
||||
bTop = 40;
|
||||
bBottom = bLeft = 10;
|
||||
bTop = bBottom = bLeft = 10;
|
||||
bRight = 30;
|
||||
axMarkerLength = 3;
|
||||
|
||||
|
@ -268,8 +258,6 @@ public class JDiagram extends JComponent implements PlotProviderListener, Bounde
|
|||
|
||||
}
|
||||
});
|
||||
|
||||
this.abzissSpacing = 1.2;
|
||||
}
|
||||
|
||||
private void fireViewWindowChanged(){
|
||||
|
@ -335,10 +323,8 @@ public class JDiagram extends JComponent implements PlotProviderListener, Bounde
|
|||
ordinateViews = new OrdinateView[ plotProvider.getMaxOrdinate() + 1 ];
|
||||
for (int n=0; n < plotProvider.getMaxOrdinate() + 1; n++)
|
||||
ordinateViews[n] = new OrdinateView(n);
|
||||
|
||||
|
||||
//Plot Painter is always set to LinePlotPainter?!?!
|
||||
PlotPainter pp = new MultiPlotPainter( new PlotPainter[]{new LinePlotPainter(), new CirclePlotPainter(2)} );//new LinePlotPainter();
|
||||
|
||||
PlotPainter pp = new LinePlotPainter();
|
||||
plotPainters = new PlotPainter[plotProvider.getNumGraphs()];
|
||||
for (int n=0;n<plotProvider.getNumGraphs();n++)
|
||||
plotPainters[n] = pp;
|
||||
|
@ -416,18 +402,13 @@ public class JDiagram extends JComponent implements PlotProviderListener, Bounde
|
|||
this.abszissLabeler = abszissLabeler;
|
||||
}
|
||||
|
||||
public double getAbzissSpacing() {
|
||||
return this.abzissSpacing;
|
||||
}
|
||||
public void setAbszissSpacing(double spacing) {
|
||||
this.abzissSpacing = spacing;
|
||||
}
|
||||
|
||||
|
||||
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];
|
||||
|
||||
|
@ -455,6 +436,7 @@ public class JDiagram extends JComponent implements PlotProviderListener, Bounde
|
|||
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);
|
||||
}
|
||||
|
@ -482,22 +464,12 @@ public class JDiagram extends JComponent implements PlotProviderListener, Bounde
|
|||
if (autoScale)
|
||||
this.autoscale();
|
||||
|
||||
for (ColoredBackground bg: coloredBackgrounds){
|
||||
Point2D pmin = mapDiagramToMouse(new Point2D.Double(0, bg.getMin()));
|
||||
Point2D pmax = mapDiagramToMouse(new Point2D.Double(0, bg.getMax()));
|
||||
|
||||
g.setColor(bg.getColor());
|
||||
g.fillRect(0, (int)pmax.getY(), getWidth(), (int)(pmax.getY() - pmin.getX()));
|
||||
}
|
||||
|
||||
paintOrdinates ((Graphics2D) g);
|
||||
paintAbszisse ((Graphics2D) g);
|
||||
paintGraphs ((Graphics2D) g);
|
||||
}
|
||||
|
||||
if(mousePos != null) {
|
||||
paintMouseCrosshair((Graphics2D) g);
|
||||
}
|
||||
if(mousePos != null)
|
||||
paintMouseCrosshair((Graphics2D) g);
|
||||
}
|
||||
|
||||
public double[] getordinateLabelHints(int ordinate){
|
||||
|
@ -624,7 +596,7 @@ public class JDiagram extends JComponent implements PlotProviderListener, Bounde
|
|||
|
||||
if (nMarker == 0){
|
||||
int w = g.getFontMetrics().stringWidth( labeler.getAbzisseLabel(this, (double)this.plotProvider.getPositionMaximum()));
|
||||
nMarker = plotWidth / (int)(w*this.abzissSpacing);
|
||||
nMarker = plotWidth / (w*8/7);
|
||||
}
|
||||
|
||||
// TODO change for zoom
|
||||
|
@ -656,7 +628,7 @@ public class JDiagram extends JComponent implements PlotProviderListener, Bounde
|
|||
getWidth() - bRight - plotWidth + xpos,
|
||||
bTop + plotHeight + axMarkerLength
|
||||
);
|
||||
|
||||
|
||||
if (drawVerticalGrid){
|
||||
g.setColor(verticalGridColor);
|
||||
g.drawLine(
|
||||
|
@ -696,7 +668,7 @@ public class JDiagram extends JComponent implements PlotProviderListener, Bounde
|
|||
for (int n=0;n<this.plotProvider.getLength(); n++){
|
||||
int x,y;
|
||||
Float value = this.plotProvider.getValue(n, graph);
|
||||
Double position = this.plotProvider.getPosition(n, graph);
|
||||
Float position = this.plotProvider.getPosition(n, graph);
|
||||
|
||||
if ((value != null) && (position != null) && (position >= this.abszissMinimum) && (position <= amax))
|
||||
{
|
||||
|
@ -866,6 +838,7 @@ public class JDiagram extends JComponent implements PlotProviderListener, Bounde
|
|||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void fundamentalsChanged(PlotProvider2 plotProvider) {
|
||||
fundamentalsChanged();
|
||||
|
@ -939,7 +912,4 @@ public class JDiagram extends JComponent implements PlotProviderListener, Bounde
|
|||
this.changeListeners.remove(x);
|
||||
}
|
||||
|
||||
public List<ColoredBackground> getColoredBackgrounds() {
|
||||
return coloredBackgrounds;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -291,18 +291,18 @@ public class AnnotatedPlotProvider implements PlotProvider2{
|
|||
}
|
||||
|
||||
@Override
|
||||
public Double getPosition(int x, int graph) {
|
||||
return (double)x;
|
||||
public Float getPosition(int x, int graph) {
|
||||
return (float)x;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double getPositionMinimum() {
|
||||
return 0.0;
|
||||
public Float getPositionMinimum() {
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double getPositionMaximum() {
|
||||
return this.values.size()-1.0;
|
||||
public Float getPositionMaximum() {
|
||||
return this.values.size()-1.0f;
|
||||
}
|
||||
|
||||
private LinkedList<PlotProviderListener> plotProviderListeners = new LinkedList<PlotProviderListener>();
|
||||
|
|
|
@ -6,16 +6,13 @@ import java.awt.Graphics2D;
|
|||
public class CirclePlotPainter implements PlotPainter {
|
||||
|
||||
int radius;
|
||||
boolean enabled;
|
||||
|
||||
public CirclePlotPainter() {
|
||||
this.radius = 3;
|
||||
this.enabled = true;
|
||||
}
|
||||
|
||||
public CirclePlotPainter(int radius){
|
||||
this.radius = radius;
|
||||
this.enabled = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -24,22 +21,9 @@ public class CirclePlotPainter implements PlotPainter {
|
|||
|
||||
@Override
|
||||
public void paintPoint(Graphics2D g, Color color, int x, int y,boolean isSelected) {
|
||||
if(this.enabled) {
|
||||
g.setColor(color);
|
||||
g.drawArc(x - radius, y - radius, 2*radius, 2*radius, 0, 360);
|
||||
g.fillArc(x - radius, y - radius, 2*radius, 2*radius, 0, 360);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnabled(boolean enable) {
|
||||
this.enabled = enable;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return this.enabled;
|
||||
g.setColor(color);
|
||||
g.drawArc(x - radius, y - radius, 2*radius, 2*radius, 0, 360);
|
||||
g.fillArc(x - radius, y - radius, 2*radius, 2*radius, 0, 360);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ public class LinePlotPainter implements PlotPainter {
|
|||
|
||||
int lx,ly;
|
||||
float width;
|
||||
boolean enabled;
|
||||
|
||||
Stroke stroke,
|
||||
selectedStroke;
|
||||
|
@ -18,7 +17,6 @@ public class LinePlotPainter implements PlotPainter {
|
|||
|
||||
public LinePlotPainter() {
|
||||
setWidth(1.0f);
|
||||
this.enabled = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -29,18 +27,16 @@ public class LinePlotPainter implements PlotPainter {
|
|||
|
||||
@Override
|
||||
public void paintPoint(Graphics2D g, Color color, int x, int y,boolean isSelected) {
|
||||
if(this.enabled) {
|
||||
if (lx != -1){
|
||||
g.setColor(this.color != null ? this.color : color);
|
||||
Stroke s = isSelected ? this.selectedStroke : g.getStroke();
|
||||
g.setStroke(stroke);
|
||||
g.drawLine(lx, ly, x, y);
|
||||
g.setStroke(s);
|
||||
}
|
||||
|
||||
lx = x;
|
||||
ly = y;
|
||||
if (lx != -1){
|
||||
g.setColor(this.color != null ? this.color : color);
|
||||
Stroke s = isSelected ? this.selectedStroke : g.getStroke();
|
||||
g.setStroke(stroke);
|
||||
g.drawLine(lx, ly, x, y);
|
||||
g.setStroke(s);
|
||||
}
|
||||
|
||||
lx = x;
|
||||
ly = y;
|
||||
}
|
||||
|
||||
public void setWidth(float width) {
|
||||
|
@ -58,15 +54,5 @@ public class LinePlotPainter implements PlotPainter {
|
|||
public void setColor(Color color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnabled(boolean enable) {
|
||||
this.enabled = enable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,61 +0,0 @@
|
|||
package org.hwo.ui.diagram;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.util.LinkedList;
|
||||
|
||||
public class MultiPlotPainter implements PlotPainter{
|
||||
|
||||
private LinkedList<PlotPainter> painters;
|
||||
private boolean enabled;
|
||||
|
||||
public MultiPlotPainter(PlotPainter[] painters) {
|
||||
this.painters = new LinkedList<>();
|
||||
for(PlotPainter p : painters) {
|
||||
this.painters.add(p);
|
||||
}
|
||||
this.enabled = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
for(PlotPainter p : this.painters) {
|
||||
p.reset();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintPoint(Graphics2D g, Color color, int x, int y, boolean isSelected) {
|
||||
for(PlotPainter p : this.painters) {
|
||||
p.paintPoint(g, color, x, y, isSelected);
|
||||
}
|
||||
}
|
||||
|
||||
public PlotPainter getPainter(int index) {
|
||||
return this.painters.get(index);
|
||||
}
|
||||
public void removePainter(int index) {
|
||||
this.painters.remove(index);
|
||||
}
|
||||
public void removePainter(PlotPainter painter) {
|
||||
this.painters.remove(painter);
|
||||
}
|
||||
|
||||
public void addPainter(PlotPainter painter) {
|
||||
this.painters.add(painter);
|
||||
}
|
||||
|
||||
public void enablePainter(int painter, boolean enable) {
|
||||
this.painters.get(painter).setEnabled(enable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnabled(boolean enable) {
|
||||
this.enabled = enable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
}
|
|
@ -7,7 +7,5 @@ public interface PlotPainter {
|
|||
|
||||
void reset();
|
||||
void paintPoint(Graphics2D g,Color color,int x,int y,boolean isSelected);
|
||||
void setEnabled(boolean enable);
|
||||
boolean isEnabled();
|
||||
|
||||
}
|
||||
|
|
|
@ -9,11 +9,11 @@ public interface PlotProvider2 {
|
|||
public int getNumGraphs();
|
||||
public String getLabel(int graph);
|
||||
public Float getValue(int x,int graph);
|
||||
public Double getPosition(int x,int graph);
|
||||
public Float getPosition(int x,int graph);
|
||||
public int getOrdinate(int graph);
|
||||
|
||||
public Double getPositionMinimum();
|
||||
public Double getPositionMaximum();
|
||||
public Float getPositionMinimum();
|
||||
public Float getPositionMaximum();
|
||||
|
||||
|
||||
public Color[] getColors();
|
||||
|
|
|
@ -83,8 +83,8 @@ public class SimplePlotProvider implements PlotProvider2 {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Double getPosition(int x, int graph) {
|
||||
return x * 1.0;
|
||||
public Float getPosition(int x, int graph) {
|
||||
return (float)x;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -97,12 +97,12 @@ public class SimplePlotProvider implements PlotProvider2 {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Double getPositionMaximum() {
|
||||
return (double)(this.points-1);
|
||||
public Float getPositionMaximum() {
|
||||
return (float)(this.points-1);
|
||||
}
|
||||
@Override
|
||||
public Double getPositionMinimum() {
|
||||
return 0.0;
|
||||
public Float getPositionMinimum() {
|
||||
return (float)0;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,65 +0,0 @@
|
|||
package org.hwo.ui.diagram;
|
||||
|
||||
import org.hwo.ui.JDiagram;
|
||||
|
||||
public class TimePlotLabeler implements PlotLabeler{
|
||||
|
||||
@Override
|
||||
public String getOrdinateLabel(JDiagram diagram, int ordinate, Double value) {
|
||||
if (value == null)
|
||||
return "";
|
||||
if (value.isNaN())
|
||||
return "";
|
||||
|
||||
Double window = diagram.getScaler(ordinate).getWindow();
|
||||
int digits = ((Double)Math.log10(window)).intValue();
|
||||
digits -= 4;
|
||||
|
||||
if (digits < 0){
|
||||
return String.format(
|
||||
String.format("%%.%df",-digits),
|
||||
value
|
||||
);
|
||||
} else if (digits == 0){
|
||||
return String.format("%1.2f",value);
|
||||
} else {
|
||||
return String.format(
|
||||
String.format("%%%d.2f",digits),
|
||||
value
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAbzisseLabel(JDiagram diagram, Double pos) {
|
||||
return doubleSecToString(pos);
|
||||
}
|
||||
|
||||
public static String doubleSecToString(Double pos) {
|
||||
//pos == seconds
|
||||
int hour, minute, second, millisecond;
|
||||
hour = (int)(pos / 3600);
|
||||
minute = ((int)(pos / 60) % 60);
|
||||
second = (int)(pos * 1) % 60;
|
||||
millisecond = (int)(pos * 1000) % 1000;
|
||||
String sh, sm, ss, sms;
|
||||
sh = String.format("%02d", hour);
|
||||
sm = String.format("%02d", minute);
|
||||
ss = String.format("%02d", second);
|
||||
sms = String.format("%03d", millisecond);
|
||||
return sh + ":" + sm + ":" + ss + "." + sms;
|
||||
}
|
||||
|
||||
public static Double stringToDoubleSec(String stringTime) {
|
||||
double ret = 0;
|
||||
String val = stringTime.substring(0, 2);
|
||||
ret = Double.parseDouble(val) * 3600.0; //hour
|
||||
val = stringTime.substring(3,5);
|
||||
ret += Double.parseDouble(val) * 60.0; //minutes
|
||||
val = stringTime.substring(6,8);
|
||||
ret += Double.parseDouble(val); //seconds
|
||||
val = stringTime.substring(9,12);
|
||||
ret += Double.parseDouble(val) / 1000.0; //milliseconds
|
||||
return ret;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue