Home » Eclipse Projects » GEF » figure in Swing or awt container ?
figure in Swing or awt container ? [message #135281] |
Tue, 01 June 2004 04:30  |
Eclipse User |
|
|
|
Originally posted by: paype77.caramail.com
Is it possible to put Figure in Swing Container?
For a software, i need to build a graphical editor, draw, move, delete
figures...
i have almost done this but i need to put my application in a complex GUI
(i already have a swing made), but i don't manage to put figures in a
swing or awt container such as Panel or internal frame...
Please help ;)
my code :
public class Test {
public static void main(String args[]){
Display d = new Display();
final Shell shell = new Shell(d);
shell.setSize(400, 400);
shell.setText("Test");
final LightweightSystem lws = new LightweightSystem(shell);
final XYLayout contentsLayout = new XYLayout();
final FigureTest contents = new FigureTest(contentsLayout);
contents.setLayoutManager(contentsLayout);
Font classFont = new Font(null, "Arial", 12, SWT.BOLD);
Label label1 = new Label("Par", new Image(d,
Test.class.getResourceAsStream("class_obj.gif")));
label1.setFont(classFont);
Label label2 = new Label("Migrate", new Image(d,
Test.class.getResourceAsStream("class_obj.gif")));
label2.setFont(classFont);
final FonctionPar figure = new FonctionPar(label1);
final FonctionMigrate figure2 = new FonctionMigrate(label2, new
Label("GenInputVector"),new Label("VInput[i]"),new Label("i"), new
Label("blockSize"));
//final FonctionMigrate figure2 = new FonctionMigrate(label2);
figure2.setSaContrainteX(200);
figure2.setSaContrainteY(200);
contentsLayout.setConstraint(figure, new Rectangle(10,10,-1,-1));
contentsLayout.setConstraint(figure2, new
Rectangle(figure2.getSaContrainteX(), figure2.getSaContrainteY(), -1, -1));
/* Creating the connection */
PolylineConnection c = new PolylineConnection();
ChopboxAnchor sourceAnchor = new ChopboxAnchor(figure);
ChopboxAnchor targetAnchor = new ChopboxAnchor(figure2);
c.setSourceAnchor(sourceAnchor);
c.setTargetAnchor(targetAnchor);
/* Creating the decoration */
PolygonDecoration decoration = new PolygonDecoration();
PointList decorationPointList = new PointList();
decorationPointList.addPoint(0,0);
decorationPointList.addPoint(-2,2);
decorationPointList.addPoint(-4,0);
decorationPointList.addPoint(-2,-2);
decoration.setTemplate(decorationPointList);
c.setSourceDecoration(decoration);
final MouseListener listenerFigure= new MouseListener() {
public void mousePressed(MouseEvent me) {
contents.setFigurePressed((Figure)me.getSource());
((Figure)me.getSource()).setVisible(false);
contents.remove((Figure)me.getSource());
}
public void mouseReleased(MouseEvent me) {}
public void mouseDoubleClicked(MouseEvent me) { }
};
figure2.addMouseListener(listenerFigure);
figure.addMouseListener(listenerFigure);
MouseMotionListener listenerMotionFigure = new MouseMotionListener() {
public void mouseDragged(MouseEvent me) {
if(contents.getFigurePressed()!=null) {
contentsLayout.setConstraint(contents.getFigurePressed(), new
Rectangle(me.x,me.y,-1,-1));
contents.add(contents.getFigurePressed());
}
}
public void mouseEntered(MouseEvent me) {}
public void mouseExited(MouseEvent me) {}
public void mouseHover(MouseEvent me) {}
public void mouseMoved(MouseEvent me) {}
};
//contents.addMouseMotionListener(listenerMotionFigure);
MouseListener listenerContents= new MouseListener() {
public void mousePressed(MouseEvent me) {}
public void mouseReleased(MouseEvent me) {
if(contents.getFigurePressed()!=null) {
contentsLayout.setConstraint(contents.getFigurePressed(), new
Rectangle(me.x,me.y,-1,-1));
contents.add(contents.getFigurePressed());
contents.getFigurePressed().setVisible(true);
contents.setFigurePressed(null);
}
}
public void mouseDoubleClicked(MouseEvent me) {
FonctionMigrate figure = new FonctionMigrate(new Label("salut"), new
Label("GenInputVector"),new Label("VInput[i]"),new Label("i"), new
Label("blockSize"));
figure.setSaContrainteX(me.x);
figure.setSaContrainteY(me.y);
contentsLayout.setConstraint(figure, new Rectangle(me.x, me.y, -1, -1));
contents.add(figure);
figure.addMouseListener(listenerFigure);
}
};
contents.addMouseListener(listenerContents);
contents.add(figure);
contents.add(figure2);
contents.add(c);
lws.setContents(contents);
shell.open();
while (!shell.isDisposed())
while (!d.readAndDispatch())
d.sleep();
shell.dispose();
}
}
|
|
|
Re: figure in Swing or awt container ? [message #135294 is a reply to message #135281] |
Tue, 01 June 2004 06:26  |
Eclipse User |
|
|
|
Originally posted by: rlemaigr.ulb.ac.be
I may be wrong but I don't think it is possible because draw2d is build =
on =
top of SWT, so you probably can't use it in AWT...
I would be very surprised if it was possible...
Sorry for you...:(
r=E9gis
On Tue, 1 Jun 2004 08:30:56 +0000 (UTC), Antoine <paype77@caramail.com> =
=
wrote:
> Is it possible to put Figure in Swing Container?
>
> For a software, i need to build a graphical editor, draw, move, delete=
> figures...
> i have almost done this but i need to put my application in a complex =
GUI
> (i already have a swing made), but i don't manage to put figures in a
> swing or awt container such as Panel or internal frame...
>
> Please help ;)
>
> my code :
>
> public class Test {
> public static void main(String args[]){
> Display d =3D new Display();
> final Shell shell =3D new Shell(d);
> shell.setSize(400, 400);
> shell.setText("Test");
> final LightweightSystem lws =3D new LightweightSystem(shell);
> final XYLayout contentsLayout =3D new XYLayout();
> final FigureTest contents =3D new FigureTest(contentsLayout);
> contents.setLayoutManager(contentsLayout);
> =
> Font classFont =3D new Font(null, "Arial", 12, SWT.BOLD);
> Label label1 =3D new Label("Par", new Image(d,
> Test.class.getResourceAsStream("class_obj.gif")));
> label1.setFont(classFont);
> =
> Label label2 =3D new Label("Migrate", new Image(d,
> Test.class.getResourceAsStream("class_obj.gif")));
> label2.setFont(classFont);
>
> final FonctionPar figure =3D new FonctionPar(label1);
> final FonctionMigrate figure2 =3D new FonctionMigrate(label2, new
> Label("GenInputVector"),new Label("VInput[i]"),new Label("i"), new
> Label("blockSize"));
> //final FonctionMigrate figure2 =3D new FonctionMigrate(label2);
> =
> figure2.setSaContrainteX(200);
> figure2.setSaContrainteY(200);
> contentsLayout.setConstraint(figure, new Rectangle(10,10,-1,-1));
> contentsLayout.setConstraint(figure2, new
> Rectangle(figure2.getSaContrainteX(), figure2.getSaContrainteY(), -1, =
=
> -1));
> =
> =
> /* Creating the connection */
> PolylineConnection c =3D new PolylineConnection();
> ChopboxAnchor sourceAnchor =3D new ChopboxAnchor(figure);
> ChopboxAnchor targetAnchor =3D new ChopboxAnchor(figure2);
> c.setSourceAnchor(sourceAnchor);
> c.setTargetAnchor(targetAnchor);
> =
> /* Creating the decoration */
> PolygonDecoration decoration =3D new PolygonDecoration();
> PointList decorationPointList =3D new PointList();
> decorationPointList.addPoint(0,0);
> decorationPointList.addPoint(-2,2);
> decorationPointList.addPoint(-4,0);
> decorationPointList.addPoint(-2,-2);
> decoration.setTemplate(decorationPointList);
> c.setSourceDecoration(decoration);
> =
> =
> final MouseListener listenerFigure=3D new MouseListener() {
> public void mousePressed(MouseEvent me) {
> contents.setFigurePressed((Figure)me.getSource());
> ((Figure)me.getSource()).setVisible(false);
> contents.remove((Figure)me.getSource());
> }
> public void mouseReleased(MouseEvent me) {}
> public void mouseDoubleClicked(MouseEvent me) { }
> };
> =
> figure2.addMouseListener(listenerFigure);
> figure.addMouseListener(listenerFigure);
> =
> MouseMotionListener listenerMotionFigure =3D new MouseMotionListener(=
) {
> public void mouseDragged(MouseEvent me) {
> if(contents.getFigurePressed()!=3Dnull) {
> contentsLayout.setConstraint(contents.getFigurePressed(), new
> Rectangle(me.x,me.y,-1,-1));
> contents.add(contents.getFigurePressed());
> }
> }
> public void mouseEntered(MouseEvent me) {}
> public void mouseExited(MouseEvent me) {}
> public void mouseHover(MouseEvent me) {}
> public void mouseMoved(MouseEvent me) {}
> =
> };
> =
> //contents.addMouseMotionListener(listenerMotionFigure);
> =
> MouseListener listenerContents=3D new MouseListener() {
>
> public void mousePressed(MouseEvent me) {}
> public void mouseReleased(MouseEvent me) {
> if(contents.getFigurePressed()!=3Dnull) {
> contentsLayout.setConstraint(contents.getFigurePressed(), new
> Rectangle(me.x,me.y,-1,-1));
> contents.add(contents.getFigurePressed());
> contents.getFigurePressed().setVisible(true);
> contents.setFigurePressed(null);
> } =
> }
> public void mouseDoubleClicked(MouseEvent me) {
> FonctionMigrate figure =3D new FonctionMigrate(new Label("salut"), =
new
> Label("GenInputVector"),new Label("VInput[i]"),new Label("i"), new
> Label("blockSize"));
> figure.setSaContrainteX(me.x);
> figure.setSaContrainteY(me.y);
> contentsLayout.setConstraint(figure, new Rectangle(me.x, me.y, -1, =
=
> -1));
> contents.add(figure);
> figure.addMouseListener(listenerFigure);
> }
> };
> =
> contents.addMouseListener(listenerContents);
> =
> =
> contents.add(figure);
> contents.add(figure2);
> contents.add(c);
> =
> lws.setContents(contents);
> shell.open();
> while (!shell.isDisposed())
> while (!d.readAndDispatch())
> d.sleep();
> shell.dispose();
> }
> }
>
>
>
-- =
Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
|
|
|
Goto Forum:
Current Time: Fri Jul 18 11:55:48 EDT 2025
Powered by FUDForum. Page generated in 0.07129 seconds
|