Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Switch figure of a model
Switch figure of a model [message #176101] Fri, 08 April 2005 01:00 Go to next message
Hao Zhang is currently offline Hao ZhangFriend
Messages: 161
Registered: July 2009
Senior Member
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 05: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 17:51 Go to previous messageGo to next message
Pratik Shah is currently offline Pratik ShahFriend
Messages: 1077
Registered: July 2009
Senior Member
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 10:06 Go to previous message
Hao Zhang is currently offline Hao ZhangFriend
Messages: 161
Registered: July 2009
Senior Member
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 Jan 29 20:17:15 GMT 2023

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

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

Back to the top