Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Use Draw2D on top of a StyledText
Use Draw2D on top of a StyledText [message #249454] Tue, 30 June 2009 06:46 Go to next message
Kai Schlamp is currently offline Kai Schlamp
Messages: 344
Registered: July 2009
Senior Member
Hi.

I want to use Draw2D on top of a StyledText. It should be possible as StyledText implements Canvas.
But I have two problems.

1) When adding a Figure the text is not visible anymore as the background gets white.

2) When using the scrollbars the drawn figures get corrupted.

Any suggestions how to solve the above issues?

Here is the simple test code I use to draw on the StyledText:

LightweightSystem system = new LightweightSystem(textViewer.getTextWidget());
Figure figure = new Figure();
XYLayout layout = new XYLayout();
figure.setLayoutManager(layout);
system.setContents(figure);
PolylineConnection conn = new PolylineConnection();
figure.add(conn);
conn.setLineWidth(10);
conn.setForegroundColor(ColorConstants.black);
conn.setBackgroundColor(ColorConstants.black);
conn.setStart(new Point(10, 10));
conn.setEnd(new Point(40, 40));

Regards,
Kai
Re: Use Draw2D on top of a StyledText [message #512892 is a reply to message #249454] Mon, 08 February 2010 05:07 Go to previous message
David Forbes is currently offline David Forbes
Messages: 1
Registered: February 2010
Junior Member
Hi Kai,

this is what I found out: When defining a LightweightSystem, the constructor builds internally a Rootfigure with opaque = true!

Here is a way, that worked for me:

public void createControl(final Composite parent) {
...
cc = (StyledText) sourceviewer.getControl();
...
Canvas canvas = new Canvas(parent, SWT.TRANSPARENT);

canvas.moveAbove(cc);
// you'll have to add a way to set the bounds of your canvas
//e.g. PaintListener or so
canvas.setBounds(0,0,200,200);

LightweightSystem myLWS = new LightweightSystem();
IFigure root = myLWS.getRootFigure();
root.setOpaque(false);
root.setLayoutManager(new BorderLayout());
myLWS.setControl(canvas);

//now add your shapes here
...
}

Of course, there is still a lot to do (synchro Canvas and StyledText, etc.) this makes it possible to use Draw2d on StyledText!

Best regards,
David

Previous Topic:[Zest] Custom connection label position
Next Topic:How to implement selection zoom for my ScalableFreeformRootEditPart
Goto Forum:
  


Current Time: Thu Jul 24 06:58:11 EDT 2014

Powered by FUDForum. Page generated in 0.04797 seconds