From cf7426b593acb2674e6c64dd3c7393213e24f1c6 Mon Sep 17 00:00:00 2001 From: Harald Wolff Date: Mon, 21 Nov 2016 16:08:52 +0100 Subject: [PATCH] jDiagram Updates --- src/org/hwo/ui/JDiagram.java | 122 ++++++------------ .../hwo/ui/diagram/AnnotatedPlotProvider.java | 101 +++++++++++++-- src/org/hwo/ui/diagram/CirclePlotPainter.java | 2 +- src/org/hwo/ui/diagram/LinePlotPainter.java | 8 +- src/org/hwo/ui/diagram/PlotPainter.java | 2 +- src/org/hwo/ui/diagram/SimplePlotLabeler.java | 2 +- src/org/hwo/ui/diagram/annotation/Plot.java | 1 + 7 files changed, 143 insertions(+), 95 deletions(-) diff --git a/src/org/hwo/ui/JDiagram.java b/src/org/hwo/ui/JDiagram.java index 0d26ce1..a7b2148 100644 --- a/src/org/hwo/ui/JDiagram.java +++ b/src/org/hwo/ui/JDiagram.java @@ -71,6 +71,9 @@ public class JDiagram extends JComponent implements PlotProviderListener { private PlotPainter[] plotPainters; + + private Integer selectedPlot; + public JDiagram(){ setMinimumSize(new Dimension(80, 80)); @@ -129,16 +132,27 @@ public class JDiagram extends JComponent implements PlotProviderListener { this.drawVerticalGrid = drawVerticalGrid; } + public Integer getSelectedPlot() { + return selectedPlot; + } + public void setSelectedPlot(Integer selectedPlot) { + this.selectedPlot = selectedPlot; + } + private void fundamentalsChanged(){ - ordinateViews = new OrdinateView[ plotProvider.getMaxOrdinate() + 1 ]; - for (int n=0; n < plotProvider.getMaxOrdinate() + 1; n++) - ordinateViews[n] = new OrdinateView(n); - - PlotPainter pp = new LinePlotPainter(); - plotPainters = new PlotPainter[plotProvider.getNumGraphs()]; - for (int n=0;n max[ordinate]) - max[ordinate] = v; - - } else { - plotPainter.reset(); - } - } - } - - for (int i=0;i 0)){ + Float v,l; + v = this.graphDefinitions[graph].getValue(o); + l = this.graphDefinitions[graph].getValue(this.values.get(x-1)); + if ((v != null) && (l!=null)){ + return v - l; + } else { + return null; + } + } else { + return this.graphDefinitions[graph].getValue(o); + } } public int getOrdinate(int graph){ @@ -141,19 +172,43 @@ public class AnnotatedPlotProvider implements PlotProvider2{ int ordinate; Color color; + boolean + isMultiGetter; + int + multiInstance; + + boolean enabled; + boolean differentiated; + public GraphDefinition(Method method){ this.method = method; + this.isMultiGetter = (this.method.getParameterCount() == 1); + this.multiInstance = 0; this.setPlot(method.getAnnotation(Plot.class)); + this.enabled = true; } + public GraphDefinition(Method method,int multiInstance){ + this.method = method; + this.isMultiGetter = (this.method.getParameterCount() == 1); + this.multiInstance = multiInstance; + this.setPlot(method.getAnnotation(Plot.class)); + this.enabled = true; + } + public GraphDefinition(Field field){ this.field = field; this.field.setAccessible(true); this.setPlot(field.getAnnotation(Plot.class)); + this.enabled = true; } private void setPlot(Plot plot){ - this.label = plot.label(); + if (plot.instances()!=1){ + this.label = String.format(plot.label(),multiInstance); + } else { + this.label = plot.label(); + } this.ordinate = plot.ordinate(); this.color = new Color(plot.r(), plot.g(), plot.b()); } @@ -162,14 +217,33 @@ public class AnnotatedPlotProvider implements PlotProvider2{ return ordinate; } public String getLabel() { - return label; + return this.label; } public Color getColor() { return color; } + public boolean isEnabled() { + return enabled; + } + public void setEnabled(boolean enabled) { + this.enabled = enabled; + fireFundamentalsChanged(); + } + + public boolean isDifferentiated() { + return differentiated; + } + public void setDifferentiated(boolean differentiated) { + this.differentiated = differentiated; + fireFundamentalsChanged(); + } + public Float getValue(Object o){ + if (!isEnabled()) + return null; + try { if (field != null){ if (field.getType().equals(Integer.class)){ @@ -183,14 +257,25 @@ public class AnnotatedPlotProvider implements PlotProvider2{ } } if (method != null){ + Object v; + + if (isMultiGetter){ + v = method.invoke(o, multiInstance); + } else { + v = method.invoke(o); + } + if (method.getReturnType().equals(Integer.class)){ - return ((Integer)method.invoke(o, null)).floatValue(); + return ((Integer)v).floatValue(); } if (method.getReturnType().equals(Double.class)){ - return ((Double)method.invoke(o, null)).floatValue(); + return ((Double)v).floatValue(); } if (method.getReturnType().equals(Float.class)){ - return ((Float)method.invoke(o, null)); + return ((Float)v); + } + if (method.getReturnType().equals(float.class)){ + return ((float)v); } } } catch (IllegalAccessException illegalAccessException){ diff --git a/src/org/hwo/ui/diagram/CirclePlotPainter.java b/src/org/hwo/ui/diagram/CirclePlotPainter.java index 923dfe6..2ef5bbc 100644 --- a/src/org/hwo/ui/diagram/CirclePlotPainter.java +++ b/src/org/hwo/ui/diagram/CirclePlotPainter.java @@ -20,7 +20,7 @@ public class CirclePlotPainter implements PlotPainter { } @Override - public void paintPoint(Graphics2D g, Color color, int x, int y) { + 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); diff --git a/src/org/hwo/ui/diagram/LinePlotPainter.java b/src/org/hwo/ui/diagram/LinePlotPainter.java index b248584..1f2b97c 100644 --- a/src/org/hwo/ui/diagram/LinePlotPainter.java +++ b/src/org/hwo/ui/diagram/LinePlotPainter.java @@ -10,7 +10,8 @@ public class LinePlotPainter implements PlotPainter { int lx,ly; float width; - Stroke stroke; + Stroke stroke, + selectedStroke; Color color; @@ -25,10 +26,10 @@ public class LinePlotPainter implements PlotPainter { } @Override - public void paintPoint(Graphics2D g, Color color, int x, int y) { + 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 = g.getStroke(); + Stroke s = isSelected ? this.selectedStroke : g.getStroke(); g.setStroke(stroke); g.drawLine(lx, ly, x, y); g.setStroke(s); @@ -41,6 +42,7 @@ public class LinePlotPainter implements PlotPainter { public void setWidth(float width) { this.width = width; this.stroke = new BasicStroke(width); + this.selectedStroke = new BasicStroke(width * 2); } public float getWidth() { return width; diff --git a/src/org/hwo/ui/diagram/PlotPainter.java b/src/org/hwo/ui/diagram/PlotPainter.java index 0a4578c..44b6028 100644 --- a/src/org/hwo/ui/diagram/PlotPainter.java +++ b/src/org/hwo/ui/diagram/PlotPainter.java @@ -6,6 +6,6 @@ import java.awt.Graphics2D; public interface PlotPainter { void reset(); - void paintPoint(Graphics2D g,Color color,int x,int y); + void paintPoint(Graphics2D g,Color color,int x,int y,boolean isSelected); } diff --git a/src/org/hwo/ui/diagram/SimplePlotLabeler.java b/src/org/hwo/ui/diagram/SimplePlotLabeler.java index cb20e93..e759c79 100644 --- a/src/org/hwo/ui/diagram/SimplePlotLabeler.java +++ b/src/org/hwo/ui/diagram/SimplePlotLabeler.java @@ -43,7 +43,7 @@ public class SimplePlotLabeler implements PlotLabeler { ); } else if (digits == 0){ return String.format("%1.2f",value); - } else if (digits > 0){ + } else { return String.format( String.format("%%%d.2f",digits), value diff --git a/src/org/hwo/ui/diagram/annotation/Plot.java b/src/org/hwo/ui/diagram/annotation/Plot.java index 07803db..155c277 100644 --- a/src/org/hwo/ui/diagram/annotation/Plot.java +++ b/src/org/hwo/ui/diagram/annotation/Plot.java @@ -14,4 +14,5 @@ public @interface Plot { public int b() default 0; public int diagram() default 0; + public int instances() default 1; }