forked from LupusNobilis/java-org.hwo.ui
Compare commits
24 Commits
thobaben_d
...
master
Author | SHA1 | Date |
---|---|---|
|
b6b1770ce5 | |
|
8cebc3644c | |
|
c545d64984 | |
|
53eafa9b4b | |
|
d6f43f3608 | |
|
266212489f | |
|
daab8c34d8 | |
|
b8bfe0c52c | |
|
63c73abedd | |
|
595839ca40 | |
|
7004f6ef5a | |
|
632781caad | |
|
49871c0fb3 | |
|
ac96878a66 | |
|
f45db5f242 | |
|
7e95a9d4f0 | |
|
79109885b5 | |
|
3a0c558911 | |
|
e75b8cee72 | |
|
34b6b52d43 | |
|
6b36943144 | |
|
f38b9ce93a | |
|
1753db1ef9 | |
|
03f1363ec9 |
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,136 @@
|
|||
package org.hwo.ui;
|
||||
|
||||
import javax.swing.Action;
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JToggleButton;
|
||||
import javax.swing.plaf.basic.BasicBorders;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import javax.swing.SwingConstants;
|
||||
|
||||
public class JColoredToggleButton extends JLabel {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
private Color colorOff = getBackground();
|
||||
private Color colorOn = Color.ORANGE;
|
||||
private Color textColorOff = Color.BLACK;
|
||||
private Color textColorOn = Color.GREEN;
|
||||
|
||||
private boolean selected = false;
|
||||
|
||||
boolean mouseDown = false;
|
||||
|
||||
private LinkedList<ActionListener> actionListeners = new LinkedList<>();
|
||||
|
||||
public JColoredToggleButton() {
|
||||
setHorizontalAlignment(SwingConstants.CENTER);
|
||||
setBorder(BorderFactory.createRaisedSoftBevelBorder());
|
||||
setOpaque(true);
|
||||
setFocusable(true);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public void addActionListener(ActionListener listener) {
|
||||
this.actionListeners.add(listener);
|
||||
}
|
||||
public void removeActionListener(ActionListener listener) {
|
||||
this.actionListeners.remove(listener);
|
||||
}
|
||||
public void fireAction() {
|
||||
for (ActionListener al: this.actionListeners) {
|
||||
al.actionPerformed(new ActionEvent(this, 0, ""));
|
||||
}
|
||||
}
|
||||
|
||||
public void toggle() {
|
||||
setSelected(!isSelected());
|
||||
}
|
||||
|
||||
public boolean isSelected()
|
||||
{
|
||||
return this.selected;
|
||||
}
|
||||
public void setSelected(boolean selected){
|
||||
if (this.selected != selected) {
|
||||
this.selected = selected;
|
||||
fireAction();
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void paint(Graphics g) {
|
||||
if (this.selected) {
|
||||
setBackground(colorOn);
|
||||
setForeground(textColorOn);
|
||||
}
|
||||
else {
|
||||
setBackground(colorOff);
|
||||
setForeground(textColorOff);
|
||||
}
|
||||
super.paint(g);
|
||||
}
|
||||
|
||||
public Color getColorOff() {
|
||||
return colorOff;
|
||||
}
|
||||
public void setColorOff(Color colorOff) {
|
||||
this.colorOff = colorOff;
|
||||
}
|
||||
|
||||
public Color getTextColorOff() {
|
||||
return this.textColorOff;
|
||||
}
|
||||
public void setTextColorOff(Color textColorOff) {
|
||||
this.textColorOff = textColorOff;
|
||||
}
|
||||
|
||||
public Color getColorOn() {
|
||||
return colorOn;
|
||||
}
|
||||
public void setColorOn(Color colorOn) {
|
||||
this.colorOn = colorOn;
|
||||
}
|
||||
|
||||
public Color getTextColorOn() {
|
||||
return this.textColorOn;
|
||||
}
|
||||
public void setTextColorOn(Color textColorOn) {
|
||||
this.textColorOn = textColorOn;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,17 +1,40 @@
|
|||
package org.hwo.ui;
|
||||
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
import java.awt.Cursor;
|
||||
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;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.KeyListener;
|
||||
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.JLabel;
|
||||
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;
|
||||
|
@ -19,8 +42,18 @@ import org.hwo.ui.diagram.PlotProviderListener;
|
|||
import org.hwo.ui.diagram.Scaler;
|
||||
import org.hwo.ui.diagram.SimplePlotLabeler;
|
||||
import org.hwo.ui.diagram.SimplePlotProvider;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Stroke;
|
||||
|
||||
public class JDiagram extends JComponent implements PlotProviderListener {
|
||||
import javax.swing.border.LineBorder;
|
||||
import java.awt.FlowLayout;
|
||||
|
||||
public class JDiagram extends JComponent implements PlotProviderListener, BoundedRangeModel {
|
||||
|
||||
private enum DDragMode { NONE, PAN, CROSSHAIR }
|
||||
|
||||
private LinkedList<DiagramListener> diagramListeners = new LinkedList<>();
|
||||
private LinkedList<ChangeListener> changeListeners = new LinkedList<>();
|
||||
|
||||
private PlotProvider2
|
||||
plotProvider;
|
||||
|
@ -49,7 +82,6 @@ public class JDiagram extends JComponent implements PlotProviderListener {
|
|||
plotWidth;
|
||||
|
||||
private double abszissMinimum,
|
||||
abszissMaximum,
|
||||
abszissWindow;
|
||||
|
||||
|
||||
|
@ -74,16 +106,30 @@ public class JDiagram extends JComponent implements PlotProviderListener {
|
|||
|
||||
private Integer selectedPlot;
|
||||
|
||||
|
||||
private DDragMode dragMode;
|
||||
private Point2D dragPoint;
|
||||
private Point dragMousePoint;
|
||||
|
||||
private double dragPanStart;
|
||||
|
||||
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));
|
||||
setDoubleBuffered(true);
|
||||
|
||||
|
||||
defaultLabeler = new SimplePlotLabeler();
|
||||
abszissLabeler = defaultLabeler;
|
||||
|
||||
bTop = bBottom = bLeft = 10;
|
||||
bTop = 40;
|
||||
bBottom = bLeft = 10;
|
||||
bRight = 30;
|
||||
axMarkerLength = 3;
|
||||
|
||||
|
@ -92,11 +138,156 @@ public class JDiagram extends JComponent implements PlotProviderListener {
|
|||
|
||||
drawHorizontalGrid = true;
|
||||
|
||||
verticalGridColor = new Color(192, 192, 192);
|
||||
this.dragMode = DDragMode.NONE;
|
||||
|
||||
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) {
|
||||
dragMousePoint = e.getPoint();
|
||||
dragPoint = mapMouseToDiagram(dragMousePoint);
|
||||
|
||||
|
||||
switch (e.getButton()) {
|
||||
case MouseEvent.BUTTON2:
|
||||
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
dragMode = DDragMode.PAN;
|
||||
dragPanStart = getAbszissMinimum();
|
||||
break;
|
||||
case MouseEvent.BUTTON1:
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
dragMode = DDragMode.NONE;
|
||||
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
|
||||
repaint();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e) {
|
||||
mousePos = null;
|
||||
}
|
||||
});
|
||||
|
||||
addMouseMotionListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseDragged(MouseEvent e) {
|
||||
if(dragMousePoint != null) {
|
||||
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;
|
||||
case CROSSHAIR:
|
||||
break;
|
||||
default:
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseMoved(MouseEvent e) {
|
||||
if(e.isControlDown()) {
|
||||
mousePos = e.getPoint();
|
||||
}
|
||||
else {
|
||||
mousePos = null;
|
||||
}
|
||||
|
||||
repaint();
|
||||
}
|
||||
});
|
||||
|
||||
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();
|
||||
}
|
||||
});
|
||||
|
||||
addKeyListener(new KeyListener() {
|
||||
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
System.out.println("CONTROL");
|
||||
|
||||
if((e.getModifiers() & KeyEvent.ALT_DOWN_MASK) != 0) {
|
||||
setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
|
||||
dragMode = DDragMode.CROSSHAIR;
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
this.abzissSpacing = 1.2;
|
||||
}
|
||||
|
||||
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);
|
||||
|
@ -144,8 +335,10 @@ public class JDiagram extends JComponent implements PlotProviderListener {
|
|||
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;
|
||||
|
@ -223,27 +416,37 @@ public class JDiagram extends JComponent implements PlotProviderListener {
|
|||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -252,7 +455,6 @@ public class JDiagram extends JComponent implements PlotProviderListener {
|
|||
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);
|
||||
}
|
||||
|
@ -280,10 +482,22 @@ public class JDiagram extends JComponent implements PlotProviderListener {
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
||||
public double[] getordinateLabelHints(int ordinate){
|
||||
|
@ -399,9 +613,7 @@ public class JDiagram extends JComponent implements PlotProviderListener {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void paintAbszisse(Graphics2D g){
|
||||
int nMarker = nAbszissLabels;
|
||||
|
||||
|
@ -412,12 +624,13 @@ public class JDiagram extends JComponent implements PlotProviderListener {
|
|||
|
||||
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);
|
||||
}
|
||||
|
||||
abszissMinimum = this.plotProvider.getPositionMinimum();
|
||||
abszissMaximum = this.plotProvider.getPositionMaximum();
|
||||
abszissWindow = abszissMaximum - abszissMinimum;
|
||||
// TODO change for zoom
|
||||
//abszissMinimum = this.plotProvider.getPositionMinimum();
|
||||
//abszissMaximum = this.plotProvider.getPositionMaximum();
|
||||
//abszissWindow = abszissMaximum - abszissMinimum;
|
||||
|
||||
g.setColor(getForeground());
|
||||
|
||||
|
@ -443,7 +656,7 @@ public class JDiagram extends JComponent implements PlotProviderListener {
|
|||
getWidth() - bRight - plotWidth + xpos,
|
||||
bTop + plotHeight + axMarkerLength
|
||||
);
|
||||
|
||||
|
||||
if (drawVerticalGrid){
|
||||
g.setColor(verticalGridColor);
|
||||
g.drawLine(
|
||||
|
@ -464,6 +677,8 @@ public class JDiagram extends JComponent implements PlotProviderListener {
|
|||
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));
|
||||
|
||||
|
@ -481,22 +696,146 @@ public class JDiagram extends JComponent implements PlotProviderListener {
|
|||
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) )
|
||||
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);
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void paintMouseCrosshair(Graphics2D g) {
|
||||
if(mousePos != null) {
|
||||
g.setColor(Color.WHITE);
|
||||
int x = getWidth() - bRight - plotWidth;
|
||||
int y = bTop + plotHeight;
|
||||
int xmax = getWidth() - bRight;
|
||||
int ymax = bTop;
|
||||
int mx = mousePos.x <= x? x : mousePos.x >= xmax? xmax : mousePos.x;
|
||||
int my = mousePos.y >= y? y : mousePos.y <= ymax? ymax : mousePos.y;
|
||||
|
||||
Point mp = new Point(mx,my);
|
||||
|
||||
drawDashedLine(g, new Point(x, my),mp);
|
||||
drawDashedLine(g, new Point(mx, y), mp);
|
||||
|
||||
Point2D mmd = mapMouseToDiagram(mp);
|
||||
|
||||
String display = String.format("[%.2f/%.2f]", mmd.getX(), mmd.getY());
|
||||
|
||||
int strSize = g.getFontMetrics().stringWidth(display);
|
||||
|
||||
mx = mx + strSize + 10 >= getWidth()? mx - (strSize + 10) : mx + 10;
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawString(display, mx, my);
|
||||
}
|
||||
}
|
||||
|
||||
public void drawDashedLine(Graphics2D g, Point a, Point b){
|
||||
//float dash[] = {10.0f};
|
||||
Stroke dashed = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[]{9}, 0);
|
||||
g.setStroke(dashed);
|
||||
g.drawLine(a.x, a.y, b.x, b.y);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* 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);
|
||||
|
||||
ordinate = ordinate >= ordinateViews.length? ordinateViews.length - 1 : ordinate;
|
||||
|
||||
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;
|
||||
|
@ -527,10 +866,80 @@ public class JDiagram extends JComponent implements PlotProviderListener {
|
|||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void fundamentalsChanged(PlotProvider2 plotProvider) {
|
||||
fundamentalsChanged();
|
||||
|
||||
}
|
||||
|
||||
/*+++++++++++++++++++++++++BOUNDEND RANGE MODEL+++++++++++++++++++++++++++++*/
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
public List<ColoredBackground> getColoredBackgrounds() {
|
||||
return coloredBackgrounds;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,112 @@
|
|||
package org.hwo.ui;
|
||||
|
||||
import javax.swing.JInternalFrame;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
|
||||
public class JExtendedInternalFrame extends JInternalFrame
|
||||
{
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private boolean keepInDesktopPane;
|
||||
|
||||
|
||||
public JExtendedInternalFrame() {
|
||||
this.putClientProperty("JInternalFrame.frameType", "normal");
|
||||
|
||||
addComponentListener(new ComponentAdapter() {
|
||||
@Override
|
||||
public void componentMoved(ComponentEvent e) {
|
||||
Component dp = getParent();
|
||||
|
||||
Dimension dpr = dp.getSize();
|
||||
Rectangle b = getBounds();
|
||||
boolean reset = false;
|
||||
|
||||
if (b.x < 0) {
|
||||
reset = true;
|
||||
b.x = 0;
|
||||
}
|
||||
if (b.y < 0) {
|
||||
reset = true;
|
||||
b.y = 0;
|
||||
}
|
||||
|
||||
if (b.x + b.width > dpr.width) {
|
||||
b.x = dpr.width - b.width;
|
||||
reset = true;
|
||||
}
|
||||
|
||||
if (b.y + b.height > dpr.height){
|
||||
b.y = dpr.height - b.height;
|
||||
reset = true;
|
||||
}
|
||||
|
||||
if (reset) {
|
||||
setBounds(b);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void componentResized(ComponentEvent e) {
|
||||
Component dp = getParent();
|
||||
|
||||
if(dp != null) {
|
||||
Dimension dpr = dp.getSize();
|
||||
Rectangle b = getBounds();
|
||||
boolean reset = false;
|
||||
|
||||
if (b.x < 0) {
|
||||
reset = true;
|
||||
b.width += b.x;
|
||||
b.x = 0;
|
||||
}
|
||||
if (b.y < 0) {
|
||||
reset = true;
|
||||
b.height += b.y;
|
||||
b.y = 0;
|
||||
}
|
||||
|
||||
if (b.x + b.width > dpr.width) {
|
||||
b.width = dpr.width - b.x;
|
||||
reset = true;
|
||||
}
|
||||
|
||||
if (b.y + b.height > dpr.height){
|
||||
b.height = dpr.height - b.y;
|
||||
reset = true;
|
||||
}
|
||||
|
||||
if (reset) {
|
||||
setBounds(b);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public boolean isKeepInDesktopPane() {
|
||||
return keepInDesktopPane;
|
||||
}
|
||||
|
||||
public void setKeepInDesktopPane(boolean keepInDesktopPane) {
|
||||
this.keepInDesktopPane = keepInDesktopPane;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package org.hwo.ui;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Image;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JButton;
|
||||
|
||||
public class JIconButton extends JButton{
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
private ImageIcon icon;
|
||||
|
||||
private int iconWidth, iconHeight;
|
||||
|
||||
public JIconButton(){
|
||||
super();
|
||||
}
|
||||
|
||||
|
||||
public JIconButton(ImageIcon icon) {
|
||||
super(icon);
|
||||
this.icon = icon;
|
||||
this.iconWidth = icon.getIconWidth();
|
||||
this.iconHeight = icon.getIconHeight();
|
||||
}
|
||||
|
||||
|
||||
public Dimension getIconDimension() {
|
||||
return new Dimension(this.iconWidth, this.iconHeight);
|
||||
}
|
||||
public void setIconDimension(Dimension dim) {
|
||||
resizeIcon(dim.width, dim.height);
|
||||
}
|
||||
|
||||
private void resizeIcon(int width, int height) {
|
||||
if(this.icon != null) {
|
||||
Image img = this.icon.getImage();
|
||||
BufferedImage bimg = new BufferedImage(this.iconWidth, this.iconHeight, BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D g = bimg.createGraphics();
|
||||
g.drawImage(img, 0, 0, width, height, null, null);
|
||||
this.icon = new ImageIcon(bimg);
|
||||
setIcon(this.icon);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
package org.hwo.ui.diagram;
|
||||
|
||||
public interface DiagramListener {
|
||||
|
||||
void ViewWindowChanged(DiagramViewEvent e);
|
||||
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package org.hwo.ui.diagram;
|
||||
|
||||
import org.hwo.ui.JDiagram;
|
||||
|
||||
public class DiagramViewEvent {
|
||||
|
||||
private JDiagram diagram;
|
||||
|
||||
public DiagramViewEvent(JDiagram d) {
|
||||
this.diagram = d;
|
||||
}
|
||||
|
||||
public JDiagram getDiagram() {
|
||||
return diagram;
|
||||
}
|
||||
|
||||
}
|
|
@ -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