forked from LupusNobilis/java-org.hwo.ui
Compare commits
15 Commits
JDiaAutoSc
...
master
Author | SHA1 | Date |
---|---|---|
Harald Wolff | b6b1770ce5 | |
Harald Wolff | 8cebc3644c | |
Harald Wolff | c545d64984 | |
Harald Wolff | 53eafa9b4b | |
Harald Wolff | d6f43f3608 | |
Niclas Thobaben | 266212489f | |
Harald Wolff | daab8c34d8 | |
Niclas Thobaben | b8bfe0c52c | |
Harald Wolff | 63c73abedd | |
Harald Wolff | 595839ca40 | |
Niclas Thobaben | 7004f6ef5a | |
Niclas Thobaben | 632781caad | |
Niclas Thobaben | 49871c0fb3 | |
Niclas Thobaben | ac96878a66 | |
Niclas Thobaben | f45db5f242 |
|
@ -0,0 +1,131 @@
|
|||
package org.hwo.models;
|
||||
|
||||
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>,HistoryListener<E> {
|
||||
|
||||
private LinkedList<ListDataListener> listDataListeners = new LinkedList<>();
|
||||
private History<E> history;
|
||||
|
||||
private E selectedItem;
|
||||
|
||||
|
||||
public ComboBoxHistoryModel()
|
||||
{
|
||||
this.setHistory(new History<>());
|
||||
this.selectedItem = null;
|
||||
}
|
||||
public ComboBoxHistoryModel(int historySize)
|
||||
{
|
||||
this.setHistory(new History<E>(historySize));
|
||||
this.selectedItem = null;
|
||||
}
|
||||
public ComboBoxHistoryModel(History<E> history){
|
||||
this.setHistory(history);
|
||||
}
|
||||
|
||||
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());
|
||||
for (ListDataListener l: listDataListeners) {
|
||||
l.contentsChanged(lde);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addListDataListener(ListDataListener arg0) {
|
||||
listDataListeners.add(arg0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public E getElementAt(int arg0) {
|
||||
return history.get(arg0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return history.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeListDataListener(ListDataListener arg0) {
|
||||
listDataListeners.remove(arg0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getSelectedItem() {
|
||||
return selectedItem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelectedItem(Object arg0) {
|
||||
selectedItem = (E)arg0;
|
||||
if (selectedItem != null) {
|
||||
this.history.add(selectedItem);
|
||||
}
|
||||
}
|
||||
|
||||
public int getHistorySize() {
|
||||
return history.getHistorySize();
|
||||
}
|
||||
|
||||
public void setHistorySize(int historySize) {
|
||||
this.history.setHistorySize(historySize);
|
||||
}
|
||||
|
||||
public Object[] getItems(){
|
||||
return history.getItems();
|
||||
}
|
||||
|
||||
public E[] getItems(E[] at) {
|
||||
return history.getItems(at);
|
||||
}
|
||||
|
||||
public void setItems(E[] items) {
|
||||
history.setItems(items);
|
||||
}
|
||||
|
||||
|
||||
public void addElement(E element) {
|
||||
this.history.add(element);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
this.history.clear();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,120 @@
|
|||
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,6 +31,8 @@ public class JColoredToggleButton extends JLabel {
|
|||
|
||||
private boolean selected = false;
|
||||
|
||||
boolean mouseDown = false;
|
||||
|
||||
private LinkedList<ActionListener> actionListeners = new LinkedList<>();
|
||||
|
||||
public JColoredToggleButton() {
|
||||
|
@ -39,14 +41,24 @@ public class JColoredToggleButton extends JLabel {
|
|||
setOpaque(true);
|
||||
setFocusable(true);
|
||||
|
||||
addMouseListener(new MouseAdapter() {
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
toggle();
|
||||
addMouseListener(new MouseAdapter() {
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent arg0) {
|
||||
mouseDown = true;
|
||||
}
|
||||
|
||||
});
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent arg0) {
|
||||
if (mouseDown) {
|
||||
toggle();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void mouseExited(MouseEvent arg0) {
|
||||
mouseDown = false;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
setSelected(false);
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ 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;
|
||||
|
@ -27,10 +28,13 @@ 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;
|
||||
|
@ -111,6 +115,11 @@ 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));
|
||||
|
@ -119,7 +128,8 @@ public class JDiagram extends JComponent implements PlotProviderListener, Bounde
|
|||
defaultLabeler = new SimplePlotLabeler();
|
||||
abszissLabeler = defaultLabeler;
|
||||
|
||||
bTop = bBottom = bLeft = 10;
|
||||
bTop = 40;
|
||||
bBottom = bLeft = 10;
|
||||
bRight = 30;
|
||||
axMarkerLength = 3;
|
||||
|
||||
|
@ -258,6 +268,8 @@ public class JDiagram extends JComponent implements PlotProviderListener, Bounde
|
|||
|
||||
}
|
||||
});
|
||||
|
||||
this.abzissSpacing = 1.2;
|
||||
}
|
||||
|
||||
private void fireViewWindowChanged(){
|
||||
|
@ -323,8 +335,10 @@ 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);
|
||||
|
||||
PlotPainter pp = new LinePlotPainter();
|
||||
|
||||
|
||||
//Plot Painter is always set to LinePlotPainter?!?!
|
||||
PlotPainter pp = new MultiPlotPainter( new PlotPainter[]{new LinePlotPainter(), new CirclePlotPainter(2)} );//new LinePlotPainter();
|
||||
plotPainters = new PlotPainter[plotProvider.getNumGraphs()];
|
||||
for (int n=0;n<plotProvider.getNumGraphs();n++)
|
||||
plotPainters[n] = pp;
|
||||
|
@ -402,27 +416,37 @@ 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];
|
||||
|
||||
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 n=0;n<this.plotProvider.getLength(); n++){
|
||||
for (int graph=0; graph < this.plotProvider.getNumGraphs(); graph++){
|
||||
double pos = this.plotProvider.getPosition(n,graph);
|
||||
|
||||
if ((pos >= abszissMinimum) && (pos < (abszissMinimum + abszissWindow))){
|
||||
ordinate = this.plotProvider.getOrdinate(graph);
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -431,7 +455,6 @@ 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);
|
||||
}
|
||||
|
@ -459,12 +482,22 @@ 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){
|
||||
|
@ -591,7 +624,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 / (w*8/7);
|
||||
nMarker = plotWidth / (int)(w*this.abzissSpacing);
|
||||
}
|
||||
|
||||
// TODO change for zoom
|
||||
|
@ -623,7 +656,7 @@ public class JDiagram extends JComponent implements PlotProviderListener, Bounde
|
|||
getWidth() - bRight - plotWidth + xpos,
|
||||
bTop + plotHeight + axMarkerLength
|
||||
);
|
||||
|
||||
|
||||
if (drawVerticalGrid){
|
||||
g.setColor(verticalGridColor);
|
||||
g.drawLine(
|
||||
|
@ -663,7 +696,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);
|
||||
Float position = this.plotProvider.getPosition(n, graph);
|
||||
Double position = this.plotProvider.getPosition(n, graph);
|
||||
|
||||
if ((value != null) && (position != null) && (position >= this.abszissMinimum) && (position <= amax))
|
||||
{
|
||||
|
@ -833,7 +866,6 @@ public class JDiagram extends JComponent implements PlotProviderListener, Bounde
|
|||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void fundamentalsChanged(PlotProvider2 plotProvider) {
|
||||
fundamentalsChanged();
|
||||
|
@ -907,4 +939,7 @@ 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 Float getPosition(int x, int graph) {
|
||||
return (float)x;
|
||||
public Double getPosition(int x, int graph) {
|
||||
return (double)x;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Float getPositionMinimum() {
|
||||
return 0.0f;
|
||||
public Double getPositionMinimum() {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Float getPositionMaximum() {
|
||||
return this.values.size()-1.0f;
|
||||
public Double getPositionMaximum() {
|
||||
return this.values.size()-1.0;
|
||||
}
|
||||
|
||||
private LinkedList<PlotProviderListener> plotProviderListeners = new LinkedList<PlotProviderListener>();
|
||||
|
|
|
@ -6,13 +6,16 @@ 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
|
||||
|
@ -21,9 +24,22 @@ public class CirclePlotPainter implements PlotPainter {
|
|||
|
||||
@Override
|
||||
public void paintPoint(Graphics2D g, Color color, int x, int y,boolean isSelected) {
|
||||
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);
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ public class LinePlotPainter implements PlotPainter {
|
|||
|
||||
int lx,ly;
|
||||
float width;
|
||||
boolean enabled;
|
||||
|
||||
Stroke stroke,
|
||||
selectedStroke;
|
||||
|
@ -17,6 +18,7 @@ public class LinePlotPainter implements PlotPainter {
|
|||
|
||||
public LinePlotPainter() {
|
||||
setWidth(1.0f);
|
||||
this.enabled = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -27,16 +29,18 @@ public class LinePlotPainter implements PlotPainter {
|
|||
|
||||
@Override
|
||||
public void paintPoint(Graphics2D g, Color color, int x, int y,boolean isSelected) {
|
||||
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);
|
||||
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;
|
||||
}
|
||||
|
||||
lx = x;
|
||||
ly = y;
|
||||
}
|
||||
|
||||
public void setWidth(float width) {
|
||||
|
@ -54,5 +58,15 @@ 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
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,5 +7,7 @@ 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 Float getPosition(int x,int graph);
|
||||
public Double getPosition(int x,int graph);
|
||||
public int getOrdinate(int graph);
|
||||
|
||||
public Float getPositionMinimum();
|
||||
public Float getPositionMaximum();
|
||||
public Double getPositionMinimum();
|
||||
public Double getPositionMaximum();
|
||||
|
||||
|
||||
public Color[] getColors();
|
||||
|
|
|
@ -83,8 +83,8 @@ public class SimplePlotProvider implements PlotProvider2 {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Float getPosition(int x, int graph) {
|
||||
return (float)x;
|
||||
public Double getPosition(int x, int graph) {
|
||||
return x * 1.0;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -97,12 +97,12 @@ public class SimplePlotProvider implements PlotProvider2 {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Float getPositionMaximum() {
|
||||
return (float)(this.points-1);
|
||||
public Double getPositionMaximum() {
|
||||
return (double)(this.points-1);
|
||||
}
|
||||
@Override
|
||||
public Float getPositionMinimum() {
|
||||
return (float)0;
|
||||
public Double getPositionMinimum() {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
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