#1085 AWT/SWT constants conversion in SWTGraphics2D class

1.0.x
closed-fixed
General (896)
5
2012-09-18
2012-04-03
olivier
No

Sample code from org.jfree.experimental.SWTGraphics2D (v1.0.13 but this code part is identical in v1.0.14):
-----------------------------------------------------------
public Stroke getStroke() {
return new BasicStroke(this.gc.getLineWidth(), this.gc.getLineCap(),
this.gc.getLineJoin());
}

public void setStroke(Stroke stroke) {
if (stroke instanceof BasicStroke) {
BasicStroke bs = (BasicStroke) stroke;
// linewidth
this.gc.setLineWidth((int) bs.getLineWidth());

// line join
switch (bs.getLineJoin()) {
case BasicStroke.JOIN_BEVEL :
this.gc.setLineJoin(SWT.JOIN_BEVEL);
break;
case BasicStroke.JOIN_MITER :
this.gc.setLineJoin(SWT.JOIN_MITER);
break;
case BasicStroke.JOIN_ROUND :
this.gc.setLineJoin(SWT.JOIN_ROUND);
break;
}

// line cap
switch (bs.getEndCap()) {
case BasicStroke.CAP_BUTT :
this.gc.setLineCap(SWT.CAP_FLAT);
break;
case BasicStroke.CAP_ROUND :
this.gc.setLineCap(SWT.CAP_ROUND);
break;
case BasicStroke.CAP_SQUARE :
this.gc.setLineCap(SWT.CAP_SQUARE);
break;
}

// set the line style to solid by default
this.gc.setLineStyle(SWT.LINE_SOLID);

// apply dash style if any
float[] dashes = bs.getDashArray();
if (dashes != null) {
int[] swtDashes = new int[dashes.length];
for (int i = 0; i < swtDashes.length; i++) {
swtDashes[i] = (int) dashes[i];
}
this.gc.setLineDash(swtDashes);
}
}
else {
throw new RuntimeException(
"Can only handle 'Basic Stroke' at present.");
}
}
-----------------------------------------------------------

PROBLEM:
In the setStroke method, BasicStroke line join and line cap constant values are converted to SWT constant values before being stored into the SWT GC, but
in the getStroke method, the GC line cap and line join values are passed to the AWT BasicStroke class constructor without any conversion.

It causes an "illegal end cap value" or an "illegal line join value" in the BasicStroke class initialization, depending on the initialization context.

Discussion

  • David Gilbert

    David Gilbert - 2012-09-18

    This has been fixed for the upcoming 1.0.15 release.

     
  • David Gilbert

    David Gilbert - 2012-09-18
    • assigned_to: nobody --> mungady
    • status: open --> closed-fixed
     

Log in to post a comment.