Community
Participate
Working Groups
- There is an API to set the line style on a shape: Shape#setLineStyle() and this could be Graphics.LINE_CUSTOM as one of the values. However, this is no corresponding api to set the lineDash values which the LINE_CUSTOM literal relies on. - Only way is to override the paintFigure routine which defeats the purpose of having those api available.
Here's some suggested code to work-around issue in a PolylineConnection subclass: private int[] dashes = null; /** * Workaround for bugzilla 105358 * @param dashes <code>int[]</code> array of dash lengths * @see Graphics#setLineDash(int[]) */ public void setLineDash(int[] dashes) { if (dashes != null) { this.dashes = new int[dashes.length]; for (int i = 0; i < dashes.length; i++) { int dash = dashes[i]; if (dash <= 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT); this.dashes[i] = dash; } } } public void paintFigure(Graphics graphics) { graphics.pushState(); if (dashes != null) graphics.setLineDash(dashes); super.paintFigure(graphics); graphics.popState(); }
This would mean adding (yet another) field that doesn't get used 99% of the time. It would be great if there were a way to do this without adding a field to clients that don't use the function. Hmmm...
Hey Marc, not sure if your line enhancement solve this issue.
It does, the LineAttributes structure that all shapes now use includes custom line dash data, and there's a setLineDash(float[] dash) method on Shape to access it.
Fixed with Bug 168311