Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Find a figure by Label draw2d
Find a figure by Label draw2d [message #1744018] Wed, 21 September 2016 13:08 Go to next message
bacem hel is currently offline bacem helFriend
Messages: 1
Registered: September 2016
Junior Member
How can i find a figure by a Label? pls help me.

public class MainView {

private Canvas canvas;
/** Application entry point */
public static void main(String[] args) {
new MainView().open();
public Figure myBlockFigure(String name){
RectangleFigure f = new RectangleFigure();
f.setLayoutManager( new ToolbarLayout() );
f.add( new Label( name ) );


new MyListener(f);

return f;

/** Open a Shell call a method for drawing */
public void open(){
Shell shell = new Shell(new Display());
shell.setSize(400, 400);
shell.setText("My Main View");
shell.setLayout( new GridLayout() );

org.eclipse.swt.widgets.Button button1 = new org.eclipse.swt.widgets.Button( shell, SWT.PUSH);
button1.setLayoutData(new GridData());
button1.addSelectionListener(new SelectionListener() {

public void widgetSelected(SelectionEvent arg0) {
// TODO Auto-generated method stub
SimpleExample ex = new SimpleExample();;

public void widgetDefaultSelected(SelectionEvent arg0) {
// TODO Auto-generated method stub


// build diagram
canvas = buildDiagram( shell );

// canvas.setLayoutData(new GridData(GridData.FILL_BOTH));
canvas.setLayoutData(new GridData(GridData.FILL_BOTH));

Display display = shell.getDisplay();
// open and wait until closing;
while( !shell.isDisposed() )
while( !display.readAndDispatch() )
private void draw(Figure root) {
String text= "first";
Figure first= myBlockFigure(text);

new Rectangle( new Point(10, 10),
first.getPreferredSize() ) );

Figure second= myBlockFigure("Second");
new Rectangle( new Point(10, 100),
second.getPreferredSize() ) );
Figure dritte= myBlockFigure("dritte");
new Rectangle( new Point(200, 100),
dritte.getPreferredSize() ) );
// Figure test = Figure.getlabel("first");
root.add((myConnection(first, second)));
//root.add((myConnection(test, dritte)));
root.add((myConnection(first, dritte)));

public PolygonDecoration myPolygonDecoration(){
PolygonDecoration deco = new PolygonDecoration();
PointList pl = new PointList();
pl.addPoint( 0, 0 );
pl.addPoint(-2, 2);
// pl.addPoint(-4, 0);
deco.setTemplate( pl );
return deco;
public Connection myConnection(IFigure fig1, IFigure fig2){
PolylineConnection conn = new PolylineConnection();
conn.setSourceAnchor( new ChopboxAnchor( fig1 ) );
conn.setTargetAnchor( new ChopboxAnchor( fig2 ) );
return conn;

/** Instantiate the root figure, where we draw figures*/
private Canvas buildDiagram( Composite parent ){

// instantiate root figure
Figure root = new Figure();
root.setLayoutManager( new XYLayout() );

// insantiate a canvas on which to draw
canvas = new Canvas(parent, SWT.DOUBLE_BUFFERED);
LightweightSystem lws = new LightweightSystem(canvas);
return canvas;

Re: Find a figure by Label draw2d [message #1744122 is a reply to message #1744018] Thu, 22 September 2016 13:38 Go to previous message
Alexander Nyssen is currently offline Alexander NyssenFriend
Messages: 244
Registered: July 2009
Location: Lünen
Senior Member
What you want to achieve is basically a search operation on the figure graph. You can traverse it using getParent() and getChildren(), while the root can be accessed via the LightweightSystem.
Previous Topic:GEF4 Add extra visual elements
Next Topic:GEF-based editors are crashing on latest GTK
Goto Forum:

Current Time: Sat Mar 02 20:17:36 GMT 2024

Powered by FUDForum. Page generated in 0.02558 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top