Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Making a figure stretch to fill its parent
Making a figure stretch to fill its parent [message #200509] Tue, 25 October 2005 08:27 Go to next message
Rune Froysa is currently offline Rune FroysaFriend
Messages: 3
Registered: July 2009
Junior Member
I have a GEF utility with a Figure similar to the Circuit in the
"logic diagram example" except that the Figure has some labels on top
(it's a StateMachine with concurrent regions). How can I convince the
child-figure that it should fill the available space in the parent
figure? What I have now looks something like this:

ParentFigure:
setLayoutManager(layout = new ToolbarLayout());
Label lab = new Label("test");
add(lab); layout.setConstraint(lab, new Rectangle(2,2,-1,-1));
pane = new FreeformLayer();
pane.setLayoutManager(new ToolbarLayout());
pane.setBorder(new GroupBoxBorder("Parent-figure-border"));
add(pane); layout.setConstraint(pane, new Rectangle(2,2,-1,-1));

public IFigure getContentsPane() { return pane; }

ChildFigure:
pane = new FreeformLayer();
pane.setLayoutManager(new FreeformLayout());
pane.setBorder(new GroupBoxBorder("Child-figure-border"));
setLayoutManager(new StackLayout());
ScrollPane scrollpane = new ScrollPane();
scrollpane.setViewport(new FreeformViewport());
scrollpane.setContents(pane);
add(scrollpane);

public IFigure getContentsPane() { return pane; }

Both figures have EditParts. The ChildFigures EditPart defines the
EditPolicy.CONTAINER_ROLE.

When I resize the ParentFigure, I would like the ChildFigure to be
resized accordingly, i.e. so that the distance between the two
GroupBoxBorders allways is constant. This works in the X direction,
but the size in the Y direction is constant (it only grows if I add
contents to the ChildFigures ContentPane).

It should be legal for the ParentFigures ContentPane to contain
multiple ChildFigures. When multple ChildFigures exists, the user
should be able to resize them (like a SplitPane). Does this mean that
the ParentFigure must set the CONTAINER_ROLE?

Any hints would be greately appreciated.

Regards,
Rune Frøysa
Re: Making a figure stretch to fill its parent [message #200573 is a reply to message #200509] Tue, 25 October 2005 14:26 Go to previous messageGo to next message
Felix L J Mayer is currently offline Felix L J MayerFriend
Messages: 202
Registered: July 2009
Senior Member
I don't understand why you are setting a constraint on the layout on the
ParentFigure.

"Rune Froysa" <rune.froysa@usit.uio.no> wrote in message
news:svlk6g2ovc9.fsf@dresden.uio.no...
>I have a GEF utility with a Figure similar to the Circuit in the
> "logic diagram example" except that the Figure has some labels on top
> (it's a StateMachine with concurrent regions). How can I convince the
> child-figure that it should fill the available space in the parent
> figure? What I have now looks something like this:
>
> ParentFigure:
> setLayoutManager(layout = new ToolbarLayout());
> Label lab = new Label("test");
> add(lab); layout.setConstraint(lab, new Rectangle(2,2,-1,-1));
> pane = new FreeformLayer();
> pane.setLayoutManager(new ToolbarLayout());
> pane.setBorder(new GroupBoxBorder("Parent-figure-border"));
> add(pane); layout.setConstraint(pane, new Rectangle(2,2,-1,-1));
>
> public IFigure getContentsPane() { return pane; }
>
> ChildFigure:
> pane = new FreeformLayer();
> pane.setLayoutManager(new FreeformLayout());
> pane.setBorder(new GroupBoxBorder("Child-figure-border"));
> setLayoutManager(new StackLayout());
> ScrollPane scrollpane = new ScrollPane();
> scrollpane.setViewport(new FreeformViewport());
> scrollpane.setContents(pane);
> add(scrollpane);
>
> public IFigure getContentsPane() { return pane; }
>
> Both figures have EditParts. The ChildFigures EditPart defines the
> EditPolicy.CONTAINER_ROLE.
>
> When I resize the ParentFigure, I would like the ChildFigure to be
> resized accordingly, i.e. so that the distance between the two
> GroupBoxBorders allways is constant. This works in the X direction,
> but the size in the Y direction is constant (it only grows if I add
> contents to the ChildFigures ContentPane).
>
> It should be legal for the ParentFigures ContentPane to contain
> multiple ChildFigures. When multple ChildFigures exists, the user
> should be able to resize them (like a SplitPane). Does this mean that
> the ParentFigure must set the CONTAINER_ROLE?
>
> Any hints would be greately appreciated.
>
> Regards,
> Rune Fr
Re: Making a figure stretch to fill its parent [message #200623 is a reply to message #200573] Tue, 25 October 2005 17:29 Go to previous messageGo to next message
Rune Froysa is currently offline Rune FroysaFriend
Messages: 3
Registered: July 2009
Junior Member
"Felix L J Mayer" <felix.mayer@objectaid.com> writes:

> I don't understand why you are setting a constraint on the layout on the
> ParentFigure.

The parent figure will have a number of labels on top. Afaik the
ToolbarLayout is useful for this, and according to the javadoc one has
to call LayoutManager.setConstraint(IFigure, Object) after adding
Figures to a Figure with a LayoutManager. Without the LayoutManager,
the ParentFigure.pane becomes 0x0 pixels, making the ChildFigure
invisible.

Below these labels there should be ChildFigure(s) that should be
stretched to fill the remaining area. It looks like this:

+-----------------------+
| <some label> |
| <some label> |
|+---------------------+|
||<CONTAINER_ROLE ||
|| area w/Free- || <- This area currently only grows in X direction,
|| FormLayout> || resulting in unwanted whitespace when the height
|+---------------------+| increases
| <unwanted whitespace> |
+-----------------------+

> "Rune Froysa" <rune.froysa@usit.uio.no> wrote in message
> news:svlk6g2ovc9.fsf@dresden.uio.no...
> >I have a GEF utility with a Figure similar to the Circuit in the
> > "logic diagram example" except that the Figure has some labels on top
> > (it's a StateMachine with concurrent regions). How can I convince the
> > child-figure that it should fill the available space in the parent
> > figure? What I have now looks something like this:
> >
> > ParentFigure:
> > setLayoutManager(layout = new ToolbarLayout());
> > Label lab = new Label("test");
> > add(lab); layout.setConstraint(lab, new Rectangle(2,2,-1,-1));
> > pane = new FreeformLayer();
> > pane.setLayoutManager(new ToolbarLayout());
> > pane.setBorder(new GroupBoxBorder("Parent-figure-border"));
> > add(pane); layout.setConstraint(pane, new Rectangle(2,2,-1,-1));
> >
> > public IFigure getContentsPane() { return pane; }
> >
> > ChildFigure:
> > pane = new FreeformLayer();
> > pane.setLayoutManager(new FreeformLayout());
> > pane.setBorder(new GroupBoxBorder("Child-figure-border"));
> > setLayoutManager(new StackLayout());
> > ScrollPane scrollpane = new ScrollPane();
> > scrollpane.setViewport(new FreeformViewport());
> > scrollpane.setContents(pane);
> > add(scrollpane);
> >
> > public IFigure getContentsPane() { return pane; }
> >
> > Both figures have EditParts. The ChildFigures EditPart defines the
> > EditPolicy.CONTAINER_ROLE.
> >
> > When I resize the ParentFigure, I would like the ChildFigure to be
> > resized accordingly, i.e. so that the distance between the two
> > GroupBoxBorders allways is constant. This works in the X direction,
> > but the size in the Y direction is constant (it only grows if I add
> > contents to the ChildFigures ContentPane).
> >
> > It should be legal for the ParentFigures ContentPane to contain
> > multiple ChildFigures. When multple ChildFigures exists, the user
> > should be able to resize them (like a SplitPane). Does this mean that
> > the ParentFigure must set the CONTAINER_ROLE?
> >
> > Any hints would be greately appreciated.
> >
> > Regards,
> > Rune Frøysa
Re: Making a figure stretch to fill its parent [message #200663 is a reply to message #200509] Tue, 25 October 2005 18:44 Go to previous messageGo to next message
venkataramana m is currently offline venkataramana mFriend
Messages: 86
Registered: July 2009
Member
Rune, I was working on a similar problem yesterday.

My problem definition:
-------------------
Whenever a parent figure with XYLayout resizes, child figure should also resize OR in other words scale accordingly.

Solution:
---------
XYLayoutEditPolicy::createChangeConstraintCommand(ChangeBoun dsRequest request, ....) handles REQ_RESIZE_CHILDREN on the parent differently.
i.e, it creates a CompoundCommand which has resize-command for self(parent) as well as resize-command for whichever child expressing a desire to resize along with its parent.

Just change the topLeft and bottomLeft points of child in resize-command by scaling them w.r.t parent figure.

The code goes something like this ...

public class CompositeDiagramElementResizeCommand extends CompoundCommand
{
	private ICompositeDiagramElement fCompositeDiagramElement = null;
	private Rectangle fConstraint = null;
	private Rectangle fOldConstraint = null;
	
	public CompositeDiagramElementResizeCommand(ICompositeDiagramElement compositeDiagramElement, Rectangle constraint)
	{
		super("RESIZE_COMPOSITE_DIAGRAM_ELEMENT");
		fCompositeDiagramElement = compositeDiagramElement;
		fConstraint = constraint;
		
		prepareSelfResizeCommand();
		prepareChildResizeCommands();
	}
	
	private void prepareSelfResizeCommand()
	{
		add(new DiagramElementResizeCommand(fCompositeDiagramElement, fConstraint));
	}
	
	private void prepareChildResizeCommands()
	{
		Rectangle oldContainerRect = fCompositeDiagramElement.getConstraint().getCopy();
		Rectangle newContainerRect = fConstraint.getCopy();		
		
		Iterator childIter = fCompositeDiagramElement.get_contained_DiagramElement_iter();
		while (childIter.hasNext())
		{
			IDiagramElement childDiagramElem = (IDiagramElement)childIter.next();
			if( !childDiagramElem.resizesWithContainer() )
				continue;
			
			Rectangle oldChildConstraint = childDiagramElem.getConstraint().getCopy();
			Rectangle newChildConstraint = getNewChildConstraint(oldChildConstraint, oldContainerRect, newContainerRect);
						
			if( childDiagramElem instanceof ICompositeDiagramElement )
				add(new CompositeDiagramElementResizeCommand((ICompositeDiagramElement)childDiagramElem, newChildConstraint));
			else
				add(new DiagramElementResizeCommand(childDiagramElem, newChildConstraint));
		}
	}
	
	private Rectangle getNewChildConstraint(Rectangle oldChildConstraint, Rectangle oldContainerRect, Rectangle newContainerRect)
	{				
		Point newTopLeft = getScaledPoint(oldChildConstraint.getTopLeft(), oldContainerRect, newContainerRect);		
		Point newBottomRight = getScaledPoint(oldChildConstraint.getBottomRight(), oldContainerRect, newContainerRect);
		
		Rectangle newChildConstraint = new Rectangle();
		newChildConstraint.setLocation(newTopLeft);
		newChildConstraint.setSize(Math.abs(newBottomRight.x - newTopLeft.x), Math.abs(newBottomRight.y - newTopLeft.y));		
		
		return newChildConstraint;
	}
	
	public static Point getScaledPoint(Point point, Rectangle oldRect, Rectangle newRect)
	{		
		double newX = (((double)point.x)/((double)oldRect.width))*newRect.width;
		double newY = (((double)point.y)/((double)oldRect.height))*newRect.height;
						
		Point newBottomRight = new Point(newX, newY);
		return newBottomRight;
	}
}


Hope that helps.
Thanks
Venkat
Re: Making a figure stretch to fill its parent [message #200686 is a reply to message #200623] Tue, 25 October 2005 22:59 Go to previous message
Eclipse UserFriend
Originally posted by: none.unknown.com

ToolbarLayout doesn't have any constraints, so you don't need to set
anything.

The real cause of your problem is the layout of the parent figure of the one
that has the ToolbarLayout. Why is it stretching your ToolbarLayout figure
to be taller than it wants to be? If you can make it avoid that, that'll
fix your problem of unwanted empty space.

If you can't do that, or if you want to make the FreeformLayout bigger,
there are two things you can do (ToolbarLayout is not very conducive to
containing xylayouts):
1) Override ToolbarLayout#layout() and give the remaining vertical space to
the last child (ie, the FreeformLayout figure)
2) Have your freeform figure return a bigger preferred height.



"Rune Froysa" <rune.froysa@usit.uio.no> wrote in message
news:svlbr1dpkt1.fsf@dresden.uio.no...
> "Felix L J Mayer" <felix.mayer@objectaid.com> writes:
>
> > I don't understand why you are setting a constraint on the layout on the
> > ParentFigure.
>
> The parent figure will have a number of labels on top. Afaik the
> ToolbarLayout is useful for this, and according to the javadoc one has
> to call LayoutManager.setConstraint(IFigure, Object) after adding
> Figures to a Figure with a LayoutManager. Without the LayoutManager,
> the ParentFigure.pane becomes 0x0 pixels, making the ChildFigure
> invisible.
>
> Below these labels there should be ChildFigure(s) that should be
> stretched to fill the remaining area. It looks like this:
>
> +-----------------------+
> | <some label> |
> | <some label> |
> |+---------------------+|
> ||<CONTAINER_ROLE ||
> || area w/Free- || <- This area currently only grows in X
direction,
> || FormLayout> || resulting in unwanted whitespace when the
height
> |+---------------------+| increases
> | <unwanted whitespace> |
> +-----------------------+
>
> > "Rune Froysa" <rune.froysa@usit.uio.no> wrote in message
> > news:svlk6g2ovc9.fsf@dresden.uio.no...
> > >I have a GEF utility with a Figure similar to the Circuit in the
> > > "logic diagram example" except that the Figure has some labels on top
> > > (it's a StateMachine with concurrent regions). How can I convince the
> > > child-figure that it should fill the available space in the parent
> > > figure? What I have now looks something like this:
> > >
> > > ParentFigure:
> > > setLayoutManager(layout = new ToolbarLayout());
> > > Label lab = new Label("test");
> > > add(lab); layout.setConstraint(lab, new Rectangle(2,2,-1,-1));
> > > pane = new FreeformLayer();
> > > pane.setLayoutManager(new ToolbarLayout());
> > > pane.setBorder(new GroupBoxBorder("Parent-figure-border"));
> > > add(pane); layout.setConstraint(pane, new Rectangle(2,2,-1,-1));
> > >
> > > public IFigure getContentsPane() { return pane; }
> > >
> > > ChildFigure:
> > > pane = new FreeformLayer();
> > > pane.setLayoutManager(new FreeformLayout());
> > > pane.setBorder(new GroupBoxBorder("Child-figure-border"));
> > > setLayoutManager(new StackLayout());
> > > ScrollPane scrollpane = new ScrollPane();
> > > scrollpane.setViewport(new FreeformViewport());
> > > scrollpane.setContents(pane);
> > > add(scrollpane);
> > >
> > > public IFigure getContentsPane() { return pane; }
> > >
> > > Both figures have EditParts. The ChildFigures EditPart defines the
> > > EditPolicy.CONTAINER_ROLE.
> > >
> > > When I resize the ParentFigure, I would like the ChildFigure to be
> > > resized accordingly, i.e. so that the distance between the two
> > > GroupBoxBorders allways is constant. This works in the X direction,
> > > but the size in the Y direction is constant (it only grows if I add
> > > contents to the ChildFigures ContentPane).
> > >
> > > It should be legal for the ParentFigures ContentPane to contain
> > > multiple ChildFigures. When multple ChildFigures exists, the user
> > > should be able to resize them (like a SplitPane). Does this mean that
> > > the ParentFigure must set the CONTAINER_ROLE?
> > >
> > > Any hints would be greately appreciated.
> > >
> > > Regards,
> > > Rune Fr
Previous Topic:separating business model from view model
Next Topic:Background image
Goto Forum:
  


Current Time: Mon Dec 09 08:23:52 GMT 2024

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

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

Back to the top