forked from LupusNobilis/java-org.hwo.ui
added enable functionality to all PlotPainters
changed PlotPainters to MultiPlotPainters in JDiagram added enabling of Sample Points in JDiagrammaster
parent
49871c0fb3
commit
632781caad
|
@ -32,6 +32,7 @@ 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;
|
||||
|
@ -98,7 +99,7 @@ public class JDiagram extends JComponent implements PlotProviderListener, Bounde
|
|||
private OrdinateView[]
|
||||
ordinateViews;
|
||||
|
||||
private PlotPainter[]
|
||||
private MultiPlotPainter[]
|
||||
plotPainters;
|
||||
|
||||
private Integer selectedPlot;
|
||||
|
@ -331,14 +332,14 @@ 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 CirclePlotPainter();
|
||||
plotPainters = new PlotPainter[plotProvider.getNumGraphs()];
|
||||
|
||||
MultiPlotPainter pp = new MultiPlotPainter(new PlotPainter[] { new LinePlotPainter(), new CirclePlotPainter(2) });
|
||||
plotPainters = new MultiPlotPainter[plotProvider.getNumGraphs()];
|
||||
for (int n=0;n<plotProvider.getNumGraphs();n++)
|
||||
plotPainters[n] = pp;
|
||||
} else {
|
||||
ordinateViews = new OrdinateView[0];
|
||||
plotPainters = new PlotPainter[0];
|
||||
plotPainters = new MultiPlotPainter[0];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -353,7 +354,7 @@ public class JDiagram extends JComponent implements PlotProviderListener, Bounde
|
|||
return this.plotPainters[graph];
|
||||
}
|
||||
public void setPlotPainter(int graph,PlotPainter plotPainter){
|
||||
this.plotPainters[graph] = plotPainter;
|
||||
this.plotPainters[graph] = new MultiPlotPainter(new PlotPainter[] { plotPainter });
|
||||
}
|
||||
|
||||
public int getAbszissLabels() {
|
||||
|
@ -417,6 +418,14 @@ public class JDiagram extends JComponent implements PlotProviderListener, Bounde
|
|||
this.abzissSpacing = spacing;
|
||||
}
|
||||
|
||||
public void enableSamplePoints(boolean enable) {
|
||||
for(MultiPlotPainter mp : this.plotPainters) {
|
||||
mp.enablePainter(1, enable);
|
||||
}
|
||||
repaint();
|
||||
fireViewWindowChanged();
|
||||
}
|
||||
|
||||
public void autoscale(){
|
||||
int ordinate;
|
||||
Double[] max,min;
|
||||
|
@ -847,7 +856,6 @@ public class JDiagram extends JComponent implements PlotProviderListener, Bounde
|
|||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void fundamentalsChanged(PlotProvider2 plotProvider) {
|
||||
fundamentalsChanged();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,12 +7,14 @@ 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
|
||||
|
@ -43,4 +45,17 @@ public class MultiPlotPainter implements PlotPainter{
|
|||
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();
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue