05 February 2008

SWT / Java2D setTransform() problems!!!!

I will post one of the problems that i faced while i was in the design phase and was really confused about the strange features of RCP. That time, i wasnt knowing the solution and only few may have come across one. Eventually, i found the answer.



I may not know how many have you have come across this bug or error or impotentness..
Its between Java2d and swt..

Here is the snippet of java2d version

public void paint(Graphics g){
AffineTransform transform = new AffineTransform();
transform.scale(10,10);//any scale value am specifying
transform.translate(100,100);//any translation value

((Graphics2D)g).setStroke(new BasicStroke(0.0001f));
((Graphics2D)g).setTransform(transform);

g.draw( );//say a general path
}


Here is the swt version for the same
public void paintControl(PaintEvent e){
Transform transform = new Transform(e.getDevice());
transform.scale(10,10);//any scale value am specifying
transform.translate(100,100);//any translation value

e.gc.setLineWidth(1);//This is the least am able to specify
e.gc.draw(path);//Here path is org.eclipse.swt.graphics.Path
}


Both code looks almost the same. The basic problem here is this. In the former case, say i am giving a state boundary for the path and i am scaling the same. It is working just fine. (State boundary is the boundary of say Florida which might have latitude and longitude values like -83.45645631, 22.45646413)

But not so in SWT. In swt, the value of path variables are rounded off or casted to int and then the scale is applied which is a serious problem!!!!. Whereas, i need a mechanism where the scale is first applied and then it is casted to int. Moerover, the setLineWidth() method is taking a value of minimum 1 which when scaled to say 10 times, the thickness also is proportionately increasing.

This is killing me for the past one week and i cannot make any progress in this issue. If someone knows the internals or how to overcome this issue, kindly reply!!!!

Thanks in advance.

Braga




The solution to the above problem was simple : There is no solution.

Yes, At the time i was trying to create the application in RCP, it wont support Vector graphic features, which means you will not be able to draw images on the screen with double precision values. This was a huge setback for me. I thought of designing my full application in RCP and had a thorough understanding of the beautiful eclipse framework until i saw an IEEE paper presented by some college grads claiming the cons of RCP being its lack supportive towards Eclipse's RCP.

No comments: