Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Polyline does not appear
Polyline does not appear [message #193071] Wed, 24 August 2005 09:33 Go to next message
Jens Bartelheimer is currently offline Jens BartelheimerFriend
Messages: 44
Registered: July 2009
Member
Hello,

I have got a problem with a Polyline.

I have added a polyline to the draw2d demo 4 (eclipse help), but this
line does not appear. What's wrong?

Here my code.

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Display;
import org.eclipse.draw2d.*;
import org.eclipse.draw2d.geometry.*;

public class Demo4 {

public static void main(String args[]){
Shell shell = new Shell();
shell.setSize(350,350);
shell.open();
shell.setText("Demo 4");
LightweightSystem lws = new LightweightSystem(shell);
IFigure panel = new Figure();
//panel.setLayoutManager(new XYLayout());
lws.setContents(panel);
RectangleFigure
node1 = new RectangleFigure(),
node2 = new RectangleFigure();
RectangleFigure node3 = new RectangleFigure();


Polyline line=new Polyline();
PointList list = new PointList();

//NEW
list.addPoint(10,10);
list.addPoint(20,120);
line.setBackgroundColor(ColorConstants.black);
line.setLineWidth(10);
line.setPoints(new PointList());
line.setLineWidth(10);
//
node1.setBackgroundColor(ColorConstants.red);
node1.setSize(64, 36);
node2.setBackgroundColor(ColorConstants.blue);
//node2.setLocation(new Rectangle(100, 100, 64, 36));
node2.setSize(40,50);
//node3.setSize(100,100);
//node3.setLocation(new Point(200,200));


PolylineConnection conn = new PolylineConnection();
conn.setSourceAnchor(new ChopboxAnchor(node1));
conn.setTargetAnchor(new ChopboxAnchor(node2));
conn.setTargetDecoration(new PolygonDecoration());

Label label = new Label("MidpointAAAA");
label.setOpaque(true);
label.setBackgroundColor(ColorConstants.buttonLightest);
label.setBorder(new LineBorder());
conn.add(label, new MidpointLocator(conn, 0));

panel.add(node1);
panel.add(node2);
//panel.add(node3);
//New
panel.add(line);
//
panel.add(conn);
new Dragger(node1);
new Dragger(node2);
Display display = Display.getDefault();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep ();
}

}
static class Dragger extends MouseMotionListener.Stub implements
MouseListener {
public Dragger(IFigure figure){
figure.addMouseMotionListener(this);
figure.addMouseListener(this);
}
Point last;
public void mouseReleased(MouseEvent e){}
public void mouseClicked(MouseEvent e){}
public void mouseDoubleClicked(MouseEvent e){}
public void mousePressed(MouseEvent e){
last = e.getLocation();
}
public void mouseDragged(MouseEvent e){
Point p = e.getLocation();
Dimension delta = p.getDifference(last);
last = p;
Figure f = ((Figure)e.getSource());
f.setBounds(f.getBounds().getTranslated(delta.width,
delta.height));
}
};

}
Re: Polyline does not appear [message #193081 is a reply to message #193071] Wed, 24 August 2005 10:59 Go to previous messageGo to next message
Michael Strothjohann is currently offline Michael StrothjohannFriend
Messages: 52
Registered: July 2009
Member
Your polyline doesn't know were to appear. Use: line.setPoints(list);
Welcome to draw2D.
michael

"Jens" <jens.bartelheimer@gmx.de> schrieb im Newsbeitrag
news:deheud$sm1$1@news.eclipse.org...
> Hello,
>
> I have got a problem with a Polyline.
>
> I have added a polyline to the draw2d demo 4 (eclipse help), but this
> line does not appear. What's wrong?
>
> Here my code.
>
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.widgets.Shell;
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.draw2d.*;
> import org.eclipse.draw2d.geometry.*;
>
> public class Demo4 {
>
> public static void main(String args[]){
> Shell shell = new Shell();
> shell.setSize(350,350);
> shell.open();
> shell.setText("Demo 4");
> LightweightSystem lws = new LightweightSystem(shell);
> IFigure panel = new Figure();
> //panel.setLayoutManager(new XYLayout());
> lws.setContents(panel);
> RectangleFigure
> node1 = new RectangleFigure(),
> node2 = new RectangleFigure();
> RectangleFigure node3 = new RectangleFigure();
>
>
> Polyline line=new Polyline();
> PointList list = new PointList();
>
> //NEW
> list.addPoint(10,10);
> list.addPoint(20,120);
> line.setBackgroundColor(ColorConstants.black);
> line.setLineWidth(10);
> line.setPoints(new PointList());
> line.setLineWidth(10);
> //
> node1.setBackgroundColor(ColorConstants.red);
> node1.setSize(64, 36);
> node2.setBackgroundColor(ColorConstants.blue);
> //node2.setLocation(new Rectangle(100, 100, 64, 36));
> node2.setSize(40,50);
> //node3.setSize(100,100);
> //node3.setLocation(new Point(200,200));
>
>
> PolylineConnection conn = new PolylineConnection();
> conn.setSourceAnchor(new ChopboxAnchor(node1));
> conn.setTargetAnchor(new ChopboxAnchor(node2));
> conn.setTargetDecoration(new PolygonDecoration());
>
> Label label = new Label("MidpointAAAA");
> label.setOpaque(true);
> label.setBackgroundColor(ColorConstants.buttonLightest);
> label.setBorder(new LineBorder());
> conn.add(label, new MidpointLocator(conn, 0));
>
> panel.add(node1);
> panel.add(node2);
> //panel.add(node3);
> //New
> panel.add(line);
> //
> panel.add(conn);
> new Dragger(node1);
> new Dragger(node2);
> Display display = Display.getDefault();
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch())
> display.sleep ();
> }
>
> }
> static class Dragger extends MouseMotionListener.Stub implements
> MouseListener {
> public Dragger(IFigure figure){
> figure.addMouseMotionListener(this);
> figure.addMouseListener(this);
> }
> Point last;
> public void mouseReleased(MouseEvent e){}
> public void mouseClicked(MouseEvent e){}
> public void mouseDoubleClicked(MouseEvent e){}
> public void mousePressed(MouseEvent e){
> last = e.getLocation();
> }
> public void mouseDragged(MouseEvent e){
> Point p = e.getLocation();
> Dimension delta = p.getDifference(last);
> last = p;
> Figure f = ((Figure)e.getSource());
> f.setBounds(f.getBounds().getTranslated(delta.width,
> delta.height));
> }
> };
>
> }
>
Re: Polyline does not appear [message #193301 is a reply to message #193081] Wed, 24 August 2005 20:52 Go to previous message
Jens Bartelheimer is currently offline Jens BartelheimerFriend
Messages: 44
Registered: July 2009
Member
thanks,

stupid mistake ;-)

Michael wrote:
> Your polyline doesn't know were to appear. Use: line.setPoints(list);
> Welcome to draw2D.
> michael
>
> "Jens" <jens.bartelheimer@gmx.de> schrieb im Newsbeitrag
> news:deheud$sm1$1@news.eclipse.org...
>
>>Hello,
>>
>>I have got a problem with a Polyline.
>>
>>I have added a polyline to the draw2d demo 4 (eclipse help), but this
>>line does not appear. What's wrong?
>>
>>Here my code.
>>
>>import org.eclipse.swt.SWT;
>>import org.eclipse.swt.widgets.Shell;
>>import org.eclipse.swt.widgets.Display;
>>import org.eclipse.draw2d.*;
>>import org.eclipse.draw2d.geometry.*;
>>
>>public class Demo4 {
>>
>>public static void main(String args[]){
>> Shell shell = new Shell();
>> shell.setSize(350,350);
>> shell.open();
>> shell.setText("Demo 4");
>> LightweightSystem lws = new LightweightSystem(shell);
>> IFigure panel = new Figure();
>> //panel.setLayoutManager(new XYLayout());
>> lws.setContents(panel);
>> RectangleFigure
>> node1 = new RectangleFigure(),
>> node2 = new RectangleFigure();
>> RectangleFigure node3 = new RectangleFigure();
>>
>>
>> Polyline line=new Polyline();
>> PointList list = new PointList();
>>
>>//NEW
>> list.addPoint(10,10);
>> list.addPoint(20,120);
>> line.setBackgroundColor(ColorConstants.black);
>> line.setLineWidth(10);
>> line.setPoints(new PointList());
>> line.setLineWidth(10);
>>//
>> node1.setBackgroundColor(ColorConstants.red);
>> node1.setSize(64, 36);
>> node2.setBackgroundColor(ColorConstants.blue);
>> //node2.setLocation(new Rectangle(100, 100, 64, 36));
>> node2.setSize(40,50);
>> //node3.setSize(100,100);
>> //node3.setLocation(new Point(200,200));
>>
>>
>> PolylineConnection conn = new PolylineConnection();
>> conn.setSourceAnchor(new ChopboxAnchor(node1));
>> conn.setTargetAnchor(new ChopboxAnchor(node2));
>> conn.setTargetDecoration(new PolygonDecoration());
>>
>> Label label = new Label("MidpointAAAA");
>> label.setOpaque(true);
>> label.setBackgroundColor(ColorConstants.buttonLightest);
>> label.setBorder(new LineBorder());
>> conn.add(label, new MidpointLocator(conn, 0));
>>
>> panel.add(node1);
>> panel.add(node2);
>> //panel.add(node3);
>>//New
>> panel.add(line);
>>//
>> panel.add(conn);
>> new Dragger(node1);
>> new Dragger(node2);
>> Display display = Display.getDefault();
>> while (!shell.isDisposed()) {
>> if (!display.readAndDispatch())
>> display.sleep ();
>>}
>>
>>}
>>static class Dragger extends MouseMotionListener.Stub implements
>>MouseListener {
>> public Dragger(IFigure figure){
>> figure.addMouseMotionListener(this);
>> figure.addMouseListener(this);
>> }
>> Point last;
>> public void mouseReleased(MouseEvent e){}
>> public void mouseClicked(MouseEvent e){}
>> public void mouseDoubleClicked(MouseEvent e){}
>> public void mousePressed(MouseEvent e){
>> last = e.getLocation();
>> }
>> public void mouseDragged(MouseEvent e){
>> Point p = e.getLocation();
>> Dimension delta = p.getDifference(last);
>> last = p;
>> Figure f = ((Figure)e.getSource());
>> f.setBounds(f.getBounds().getTranslated(delta.width,
>>delta.height));
>> }
>>};
>>
>>}
>>
>
>
>
Previous Topic:Controlling order in which selected items are processed
Next Topic:position and reposition Figure’s children
Goto Forum:
  


Current Time: Sun Jan 19 21:17:34 GMT 2025

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

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

Back to the top