|
Re: Switch figure of a model [message #176128 is a reply to message #176101] |
Fri, 08 April 2005 05:38   |
Eclipse User |
|
|
|
Originally posted by: Angel.Roman.prismtech.com
Hao Zhang wrote:
> Hi, In my application, when I double click an editpart in diagram,
> the figure should switch between an ellipse and a rectangle, how can
> I do this with two separate figure?
>
> Wishes Hao
>
>
This should help you get on your way: preformRequest gets called
whenever the user double clicks on the figure with a request of type
REQ_OPEN.
Implement this in your editpart.
public void performRequest(Request req)
{
if (req.getType() == RequestConstants.REQ_OPEN)
{
IFigure fig = getFigure();
if(fig instanceof RectangleFigure)
{
Ellipse el = new Ellipse();
el.setSize(new Dimension(100, 100));
el.setBackgroundColor(ColorConstants.red);
((GraphicalEditPart)getParent()).getFigure().remove(fig);
setFigure(el);
((GraphicalEditPart) getParent()).getFigure().add(el);
}
else if (fig instanceof Ellipse)
{
RectangleFigure rect = new RectangleFigure();
rect.setSize(new Dimension(100,100));
rect.setBackgroundColor(ColorConstants.blue);
((GraphicalEditPart)getParent()).getFigure().remove(getFigur e());
setFigure(rect);
((GraphicalEditPart) getParent()).getFigure().add(rect);
}
refreshVisuals();
}
Regards,
Angel
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.11626 seconds