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.
Thanks

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.setBackgroundColor(ColorConstants.lightGreen);
f.setLayoutManager( new ToolbarLayout() );
f.setPreferredSize(100,70);
f.add( new Label( name ) );

//Listner

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() );

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

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

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
shell.open();
while( !shell.isDisposed() )
while( !display.readAndDispatch() )
display.sleep();
}
private void draw(Figure root) {
String text= "first";
Figure first= myBlockFigure(text);


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

Figure second= myBlockFigure("Second");
root.add(second,
new Rectangle( new Point(10, 100),
second.getPreferredSize() ) );
Figure dritte= myBlockFigure("dritte");
root.add(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);
pl.addPoint(-2,-2);
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 ) );
//Decoration
conn.setTargetDecoration(myPolygonDecoration());
return conn;
}

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

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

// insantiate a canvas on which to draw
canvas = new Canvas(parent, SWT.DOUBLE_BUFFERED);
canvas.setBackground(ColorConstants.white);
LightweightSystem lws = new LightweightSystem(canvas);
lws.setContents(root);
draw(root);
//
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: 230
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] How to print diagram
Next Topic:GEF-based editors are crashing on latest GTK
Goto Forum:
  


Current Time: Mon Jan 22 02:45:29 GMT 2018

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

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