Dashed line

A discussion forum for FXGraphics2D (adds a Java2D API to the JavaFX Canvas).
Locked
SophieL
Posts: 1
Joined: Mon Jul 06, 2015 8:50 am
antibot: No, of course not.

Dashed line

Post by SophieL » Mon Jul 06, 2015 9:51 am

I test to draw a value marker on dashed line on XYPlot under JavaFX.

Since Java 8u40, the org.jfree.chart.fx.FXGraphics2D managed the dashed lines.
So I modified the bridge fx on FXGraphics2D.java

Code: Select all

    public void setStroke(Stroke s) {
        nullNotPermitted(s, "s");
        this.stroke = s;
        if (stroke instanceof BasicStroke) {
            BasicStroke bs = (BasicStroke) s;
            double lineWidth = bs.getLineWidth();
            if (lineWidth == 0.0) {
                lineWidth = this.zeroStrokeWidth;
            }
           
            this.gc.setLineWidth(lineWidth);
            this.gc.setLineCap(awtToJavaFXLineCap(bs.getEndCap()));
            this.gc.setLineJoin(awtToJavaFXLineJoin(bs.getLineJoin()));
            this.gc.setMiterLimit(bs.getMiterLimit());
            
            //Dasehd lines management
            float[] dash = bs.getDashArray();
            if (dash != null && dash.length > 1){
            	for (int i=0; i<dash.length; i++){
            		this.gc.setLineDashes(dash[i]);
            	}
            	this.gc.setLineDashOffset(bs.getDashPhase());
            }
            else{
            	double[] actualDash = this.gc.getLineDashes();
            	if (actualDash != null){
            		for (int i=0; i<actualDash.length; i++){
                		this.gc.setLineDashes(0);
                	}
            		this.gc.setLineDashOffset(0);
            	}
            }
            
        }
    }
Notice that the dashed line is the default behavior for grid lines of XYPlot.

Thanks again for your work.

Best regards,
Sophie

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: Dashed line

Post by david.gilbert » Sat Jul 25, 2015 9:44 am

Thanks Sophie. Previously I updated the code to use reflection so that dashed lines would work in 8u40 upwards but code would still run in earlier releases of JavaFX. You can see the code here:

https://github.com/jfree/fxgraphics2d/b ... ics2D.java

I guess by now, though, most people using JavaFX will be on 8u51, so perhaps I can remove the use of reflection and support dashed lines directly.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

Locked