Bug 105358 - No way to utilize Graphics.LINE_CUSTOM from Shape hierarchy
Summary: No way to utilize Graphics.LINE_CUSTOM from Shape hierarchy
Status: RESOLVED FIXED
Alias: None
Product: GEF
Classification: Tools
Component: GEF-Legacy Draw2d (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: 3.5.0 (Galileo) M4   Edit
Assignee: Marc Gobeil CLA
QA Contact:
URL:
Whiteboard:
Keywords: api
Depends on:
Blocks:
 
Reported: 2005-07-27 14:25 EDT by Steven R. Shaw CLA
Modified: 2009-01-26 13:29 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Steven R. Shaw CLA 2005-07-27 14:25:52 EDT
- 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.
Comment 1 Steven R. Shaw CLA 2005-07-27 14:46:19 EDT
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();
	}
Comment 2 Randy Hudson CLA 2005-12-23 14:42:00 EST
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...
Comment 3 Anthony Hunter CLA 2009-01-23 16:21:05 EST
Hey Marc, not sure if your line enhancement solve this issue.
Comment 4 Marc Gobeil CLA 2009-01-26 11:23:28 EST
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.
Comment 5 Anthony Hunter CLA 2009-01-26 13:29:55 EST
Fixed with Bug 168311