Skip to main content



      Home
Home » Eclipse Projects » GEF » Switch figure of a model
Switch figure of a model [message #176101] Thu, 07 April 2005 21:00 Go to next message
Eclipse UserFriend
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
Re: Switch figure of a model [message #176128 is a reply to message #176101] Fri, 08 April 2005 01:38 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Switch figure of a model [message #176246 is a reply to message #176128] Fri, 08 April 2005 13:51 Go to previous messageGo to next message
Eclipse UserFriend
Yikes, that's dangerous. Better would be that you return a simple Figure
object with a stack layout from your createFigure() method. You can then
switch between setting the ellipse and rectangle as the child of this
figure.

"Angel Roman" <Angel.Roman@prismtech.com> wrote in message
news:d355l1$iq2$1@news.eclipse.org...
> 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
Re: Switch figure of a model [message #176619 is a reply to message #176246] Mon, 11 April 2005 06:06 Go to previous message
Eclipse UserFriend
Thank you both.

"Pratik Shah" <ppshah@us.ibm.com> д
Previous Topic:How to use arrow key to adjust figure's position slightly
Next Topic:ImageFigure
Goto Forum:
  


Current Time: Sun Jul 13 08:53:54 EDT 2025

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

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

Back to the top