Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » figure with fixed width variable height
figure with fixed width variable height [message #150099] Wed, 08 September 2004 23:50 Go to next message
Michael Permana is currently offline Michael PermanaFriend
Messages: 23
Registered: July 2009
Junior Member
Hi, I'm trying to create a figure that'll have a flow layout. It has fixed
width, but the height is not fixed. The height is calculated based on the
children.
And it looked like the attached picture.

So my approach is like this, I was wondering if this approach is ok, or if
there is a better one.

So first you have a
PageFigure. PageFigure will draw a paper look a like thing using
graphics.fillRectangle, it uses XYLayout. Then PageFigure has a
ContentFigure. Then the ContentFigure uses a FlowLayout and figures can be
added to ContentFigure.

Basically I'm trying to create something that will look like an HTML Editor.

Please give comments on my approach
many thanks,
Michael

/**
* The bound of this figure is set after the layout is done.

* The layout is done using ContentLayout which is a FlowLayout.

* It layouts the children with a flow layout.

* Then the bound is set:

* width=specifed fixed size,

* height=calculated based on its children height

*/

public class ContentFigure extends Figure {

ContentLayout layoutManager;

int width;

public ContentFigure(int width) {

this.width = width;

setBackgroundColor(ColorConstants.white);

setOpaque(true);

layoutManager = new ContentLayout();

setLayoutManager(layoutManager);

// setBorder(new LineBorder(1));

}

/**

* @return Returns the width.

*/

public int getWidth() {

return width;

}

/**

* @param width The width to set.

*/

public void setWidth(int width) {

this.width = width;

}


/* (non-Javadoc)

* @see
org.eclipse.draw2d.Figure#getClientArea(org.eclipse.draw2d.g eometry.Rectangle)

*/

public Rectangle getClientArea(Rectangle rect) {

Rectangle clientArea = super.getClientArea(rect);

println("ContentFigure.getClientArea" + clientArea);

if (clientArea.width > width)

clientArea.width = width;

return clientArea;

}


/* (non-Javadoc)

* @see org.eclipse.draw2d.Figure#layout()

*/

protected void layout() {

Dimension dimension = layoutManager.getPreferredHeight(this,width);

println("ContentFigure.layout:"+dimension);

setBounds(new Rectangle(0,0,width,dimension.height));

layoutManager.layout(this);

}

/**

* @param string

*/

private void println(String string) {

System.out.println(string);

}

}



/**

*/

public class ContentLayout extends FlowLayout {

public ContentLayout() {

super();

setMajorSpacing(0);

setMinorSpacing(0);

}

/* (non-Javadoc)

* @see
org.eclipse.draw2d.AbstractLayout#getPreferredSize(org.eclip se.draw2d.IFigure,
int, int)

*/

public Dimension getPreferredHeight(IFigure container, int wHint) {

return super.getPreferredSize(container, wHint, -1);

}


}





/**

*/

public class PageFigure extends Figure {

int pageWidth;

XYLayout layout;

ContentFigure contentFigure;

public PageFigure(int pageWidth) {

setOpaque(true);


layout = new XYLayout();

setLayoutManager(layout);

this.pageWidth = pageWidth;


contentFigure = new ContentFigure(pageWidth);

// contentFigure.setBorder(new LineBorder(1));


add(contentFigure);

}

/* (non-Javadoc)

* @see org.eclipse.draw2d.Figure#paintFigure(org.eclipse.draw2d.Gra phics)

*/

protected void paintFigure(Graphics graphics) {

Rectangle bounds = getBounds();

System.out.println("PageFigure.paintFigure " + bounds);

graphics.setBackgroundColor(ColorConstants.gray);

graphics.fillRectangle(getBounds());


int x = (bounds.width - pageWidth)/2;

if (x < 0) x = 0;


int contentHeight = contentFigure.getBounds().height;

Rectangle contentBounds = new Rectangle(x,0,pageWidth,contentHeight);


contentFigure.setBounds(contentBounds);

// contentArea

// graphics.setBackgroundColor(ColorConstants.white);

// graphics.fillRectangle(contentBounds);


graphics.setBackgroundColor(ColorConstants.black);

graphics.fillRectangle(x-1,0,1,bounds.height);

graphics.fillRectangle(x+pageWidth,0,3,bounds.height);

graphics.setBackgroundColor(ColorConstants.lightGray);

graphics.fillRectangle(x,contentHeight,pageWidth,bounds.heig ht-contentHeight);

}

/**

* @return Returns the pageWidth.

*/

public int getPageWidth() {

return pageWidth;

}

/**

* @param pageWidth The pageWidth to set.

*/

public void setPageWidth(int pageWidth) {

this.pageWidth = pageWidth;

}



/**

* @return Returns the contentFigure.

*/

public ContentFigure getContentFigure() {

return contentFigure;

}

}


Re: figure with fixed width variable height [message #150378 is a reply to message #150099] Thu, 09 September 2004 22:56 Go to previous messageGo to next message
Pratik Shah is currently offline Pratik ShahFriend
Messages: 1077
Registered: July 2009
Senior Member
> So first you have a
> PageFigure. PageFigure will draw a paper look a like thing using
> graphics.fillRectangle, it uses XYLayout. Then PageFigure has a
> ContentFigure. Then the ContentFigure uses a FlowLayout and figures can be
> added to ContentFigure.

Something different to try:

Let's call what you have as PageFigure a DocumentFigure. The DocumentFigure
can have one or more PageFigures (this is the actual visible page, including
empty space) in ToolbarLayout. Each PageFigure will have two children in a
border layout: a content figure (north) and a shaded figure (center), which
shades the empty space. As the content figure grows, the shaded figure
shrinks.

A better/simpler option would be to not have the shaded area. Then your
PageFigure can have the content figure in a stack layout. Adding stuff to
the content figure would work similar to adding parts to the FlowContainer
in the logic example. When you run out of space, you can add another
PageFigure to the DocumentFigure.

"Michael Permana" <mpermana@hotmail.com> wrote in message
news:cho5k9$5hf$1@eclipse.org...
> Hi, I'm trying to create a figure that'll have a flow layout. It has fixed
> width, but the height is not fixed. The height is calculated based on the
> children.
> And it looked like the attached picture.
>
> So my approach is like this, I was wondering if this approach is ok, or if
> there is a better one.
>
> So first you have a
> PageFigure. PageFigure will draw a paper look a like thing using
> graphics.fillRectangle, it uses XYLayout. Then PageFigure has a
> ContentFigure. Then the ContentFigure uses a FlowLayout and figures can be
> added to ContentFigure.
>
> Basically I'm trying to create something that will look like an HTML
Editor.
>
> Please give comments on my approach
> many thanks,
> Michael
>
> /**
> * The bound of this figure is set after the layout is done.
>
> * The layout is done using ContentLayout which is a FlowLayout.
>
> * It layouts the children with a flow layout.
>
> * Then the bound is set:
>
> * width=specifed fixed size,
>
> * height=calculated based on its children height
>
> */
>
> public class ContentFigure extends Figure {
>
> ContentLayout layoutManager;
>
> int width;
>
> public ContentFigure(int width) {
>
> this.width = width;
>
> setBackgroundColor(ColorConstants.white);
>
> setOpaque(true);
>
> layoutManager = new ContentLayout();
>
> setLayoutManager(layoutManager);
>
> // setBorder(new LineBorder(1));
>
> }
>
> /**
>
> * @return Returns the width.
>
> */
>
> public int getWidth() {
>
> return width;
>
> }
>
> /**
>
> * @param width The width to set.
>
> */
>
> public void setWidth(int width) {
>
> this.width = width;
>
> }
>
>
> /* (non-Javadoc)
>
> * @see
>
org.eclipse.draw2d.Figure#getClientArea(org.eclipse.draw2d.g eometry.Rectangl
e)
>
> */
>
> public Rectangle getClientArea(Rectangle rect) {
>
> Rectangle clientArea = super.getClientArea(rect);
>
> println("ContentFigure.getClientArea" + clientArea);
>
> if (clientArea.width > width)
>
> clientArea.width = width;
>
> return clientArea;
>
> }
>
>
> /* (non-Javadoc)
>
> * @see org.eclipse.draw2d.Figure#layout()
>
> */
>
> protected void layout() {
>
> Dimension dimension = layoutManager.getPreferredHeight(this,width);
>
> println("ContentFigure.layout:"+dimension);
>
> setBounds(new Rectangle(0,0,width,dimension.height));
>
> layoutManager.layout(this);
>
> }
>
> /**
>
> * @param string
>
> */
>
> private void println(String string) {
>
> System.out.println(string);
>
> }
>
> }
>
>
>
> /**
>
> */
>
> public class ContentLayout extends FlowLayout {
>
> public ContentLayout() {
>
> super();
>
> setMajorSpacing(0);
>
> setMinorSpacing(0);
>
> }
>
> /* (non-Javadoc)
>
> * @see
>
org.eclipse.draw2d.AbstractLayout#getPreferredSize(org.eclip se.draw2d.IFigur
e,
> int, int)
>
> */
>
> public Dimension getPreferredHeight(IFigure container, int wHint) {
>
> return super.getPreferredSize(container, wHint, -1);
>
> }
>
>
> }
>
>
>
>
>
> /**
>
> */
>
> public class PageFigure extends Figure {
>
> int pageWidth;
>
> XYLayout layout;
>
> ContentFigure contentFigure;
>
> public PageFigure(int pageWidth) {
>
> setOpaque(true);
>
>
> layout = new XYLayout();
>
> setLayoutManager(layout);
>
> this.pageWidth = pageWidth;
>
>
> contentFigure = new ContentFigure(pageWidth);
>
> // contentFigure.setBorder(new LineBorder(1));
>
>
> add(contentFigure);
>
> }
>
> /* (non-Javadoc)
>
> * @see org.eclipse.draw2d.Figure#paintFigure(org.eclipse.draw2d.Gra phics)
>
> */
>
> protected void paintFigure(Graphics graphics) {
>
> Rectangle bounds = getBounds();
>
> System.out.println("PageFigure.paintFigure " + bounds);
>
> graphics.setBackgroundColor(ColorConstants.gray);
>
> graphics.fillRectangle(getBounds());
>
>
> int x = (bounds.width - pageWidth)/2;
>
> if (x < 0) x = 0;
>
>
> int contentHeight = contentFigure.getBounds().height;
>
> Rectangle contentBounds = new Rectangle(x,0,pageWidth,contentHeight);
>
>
> contentFigure.setBounds(contentBounds);
>
> // contentArea
>
> // graphics.setBackgroundColor(ColorConstants.white);
>
> // graphics.fillRectangle(contentBounds);
>
>
> graphics.setBackgroundColor(ColorConstants.black);
>
> graphics.fillRectangle(x-1,0,1,bounds.height);
>
> graphics.fillRectangle(x+pageWidth,0,3,bounds.height);
>
> graphics.setBackgroundColor(ColorConstants.lightGray);
>
>
graphics.fillRectangle(x,contentHeight,pageWidth,bounds.heig ht-contentHeight
);
>
> }
>
> /**
>
> * @return Returns the pageWidth.
>
> */
>
> public int getPageWidth() {
>
> return pageWidth;
>
> }
>
> /**
>
> * @param pageWidth The pageWidth to set.
>
> */
>
> public void setPageWidth(int pageWidth) {
>
> this.pageWidth = pageWidth;
>
> }
>
>
>
> /**
>
> * @return Returns the contentFigure.
>
> */
>
> public ContentFigure getContentFigure() {
>
> return contentFigure;
>
> }
>
> }
>
>
>
Re: figure with fixed width variable height [message #150387 is a reply to message #150378] Thu, 09 September 2004 23:00 Go to previous message
Pratik Shah is currently offline Pratik ShahFriend
Messages: 1077
Registered: July 2009
Senior Member
Hmm, I didn't realize you were creating an HTML editor (just went by the
picture). In that case, why do you want your editor to look like Word
rather than FrontPage?

"Pratik Shah" <ppshah@us.ibm.com> wrote in message
news:chqms7$8sd$1@eclipse.org...
> > So first you have a
> > PageFigure. PageFigure will draw a paper look a like thing using
> > graphics.fillRectangle, it uses XYLayout. Then PageFigure has a
> > ContentFigure. Then the ContentFigure uses a FlowLayout and figures can
be
> > added to ContentFigure.
>
> Something different to try:
>
> Let's call what you have as PageFigure a DocumentFigure. The
DocumentFigure
> can have one or more PageFigures (this is the actual visible page,
including
> empty space) in ToolbarLayout. Each PageFigure will have two children in
a
> border layout: a content figure (north) and a shaded figure (center),
which
> shades the empty space. As the content figure grows, the shaded figure
> shrinks.
>
> A better/simpler option would be to not have the shaded area. Then your
> PageFigure can have the content figure in a stack layout. Adding stuff to
> the content figure would work similar to adding parts to the FlowContainer
> in the logic example. When you run out of space, you can add another
> PageFigure to the DocumentFigure.
>
> "Michael Permana" <mpermana@hotmail.com> wrote in message
> news:cho5k9$5hf$1@eclipse.org...
> > Hi, I'm trying to create a figure that'll have a flow layout. It has
fixed
> > width, but the height is not fixed. The height is calculated based on
the
> > children.
> > And it looked like the attached picture.
> >
> > So my approach is like this, I was wondering if this approach is ok, or
if
> > there is a better one.
> >
> > So first you have a
> > PageFigure. PageFigure will draw a paper look a like thing using
> > graphics.fillRectangle, it uses XYLayout. Then PageFigure has a
> > ContentFigure. Then the ContentFigure uses a FlowLayout and figures can
be
> > added to ContentFigure.
> >
> > Basically I'm trying to create something that will look like an HTML
> Editor.
> >
> > Please give comments on my approach
> > many thanks,
> > Michael
> >
> > /**
> > * The bound of this figure is set after the layout is done.
> >
> > * The layout is done using ContentLayout which is a FlowLayout.
> >
> > * It layouts the children with a flow layout.
> >
> > * Then the bound is set:
> >
> > * width=specifed fixed size,
> >
> > * height=calculated based on its children height
> >
> > */
> >
> > public class ContentFigure extends Figure {
> >
> > ContentLayout layoutManager;
> >
> > int width;
> >
> > public ContentFigure(int width) {
> >
> > this.width = width;
> >
> > setBackgroundColor(ColorConstants.white);
> >
> > setOpaque(true);
> >
> > layoutManager = new ContentLayout();
> >
> > setLayoutManager(layoutManager);
> >
> > // setBorder(new LineBorder(1));
> >
> > }
> >
> > /**
> >
> > * @return Returns the width.
> >
> > */
> >
> > public int getWidth() {
> >
> > return width;
> >
> > }
> >
> > /**
> >
> > * @param width The width to set.
> >
> > */
> >
> > public void setWidth(int width) {
> >
> > this.width = width;
> >
> > }
> >
> >
> > /* (non-Javadoc)
> >
> > * @see
> >
>
org.eclipse.draw2d.Figure#getClientArea(org.eclipse.draw2d.g eometry.Rectangl
> e)
> >
> > */
> >
> > public Rectangle getClientArea(Rectangle rect) {
> >
> > Rectangle clientArea = super.getClientArea(rect);
> >
> > println("ContentFigure.getClientArea" + clientArea);
> >
> > if (clientArea.width > width)
> >
> > clientArea.width = width;
> >
> > return clientArea;
> >
> > }
> >
> >
> > /* (non-Javadoc)
> >
> > * @see org.eclipse.draw2d.Figure#layout()
> >
> > */
> >
> > protected void layout() {
> >
> > Dimension dimension = layoutManager.getPreferredHeight(this,width);
> >
> > println("ContentFigure.layout:"+dimension);
> >
> > setBounds(new Rectangle(0,0,width,dimension.height));
> >
> > layoutManager.layout(this);
> >
> > }
> >
> > /**
> >
> > * @param string
> >
> > */
> >
> > private void println(String string) {
> >
> > System.out.println(string);
> >
> > }
> >
> > }
> >
> >
> >
> > /**
> >
> > */
> >
> > public class ContentLayout extends FlowLayout {
> >
> > public ContentLayout() {
> >
> > super();
> >
> > setMajorSpacing(0);
> >
> > setMinorSpacing(0);
> >
> > }
> >
> > /* (non-Javadoc)
> >
> > * @see
> >
>
org.eclipse.draw2d.AbstractLayout#getPreferredSize(org.eclip se.draw2d.IFigur
> e,
> > int, int)
> >
> > */
> >
> > public Dimension getPreferredHeight(IFigure container, int wHint) {
> >
> > return super.getPreferredSize(container, wHint, -1);
> >
> > }
> >
> >
> > }
> >
> >
> >
> >
> >
> > /**
> >
> > */
> >
> > public class PageFigure extends Figure {
> >
> > int pageWidth;
> >
> > XYLayout layout;
> >
> > ContentFigure contentFigure;
> >
> > public PageFigure(int pageWidth) {
> >
> > setOpaque(true);
> >
> >
> > layout = new XYLayout();
> >
> > setLayoutManager(layout);
> >
> > this.pageWidth = pageWidth;
> >
> >
> > contentFigure = new ContentFigure(pageWidth);
> >
> > // contentFigure.setBorder(new LineBorder(1));
> >
> >
> > add(contentFigure);
> >
> > }
> >
> > /* (non-Javadoc)
> >
> > * @see
org.eclipse.draw2d.Figure#paintFigure(org.eclipse.draw2d.Gra phics)
> >
> > */
> >
> > protected void paintFigure(Graphics graphics) {
> >
> > Rectangle bounds = getBounds();
> >
> > System.out.println("PageFigure.paintFigure " + bounds);
> >
> > graphics.setBackgroundColor(ColorConstants.gray);
> >
> > graphics.fillRectangle(getBounds());
> >
> >
> > int x = (bounds.width - pageWidth)/2;
> >
> > if (x < 0) x = 0;
> >
> >
> > int contentHeight = contentFigure.getBounds().height;
> >
> > Rectangle contentBounds = new Rectangle(x,0,pageWidth,contentHeight);
> >
> >
> > contentFigure.setBounds(contentBounds);
> >
> > // contentArea
> >
> > // graphics.setBackgroundColor(ColorConstants.white);
> >
> > // graphics.fillRectangle(contentBounds);
> >
> >
> > graphics.setBackgroundColor(ColorConstants.black);
> >
> > graphics.fillRectangle(x-1,0,1,bounds.height);
> >
> > graphics.fillRectangle(x+pageWidth,0,3,bounds.height);
> >
> > graphics.setBackgroundColor(ColorConstants.lightGray);
> >
> >
>
graphics.fillRectangle(x,contentHeight,pageWidth,bounds.heig ht-contentHeight
> );
> >
> > }
> >
> > /**
> >
> > * @return Returns the pageWidth.
> >
> > */
> >
> > public int getPageWidth() {
> >
> > return pageWidth;
> >
> > }
> >
> > /**
> >
> > * @param pageWidth The pageWidth to set.
> >
> > */
> >
> > public void setPageWidth(int pageWidth) {
> >
> > this.pageWidth = pageWidth;
> >
> > }
> >
> >
> >
> > /**
> >
> > * @return Returns the contentFigure.
> >
> > */
> >
> > public ContentFigure getContentFigure() {
> >
> > return contentFigure;
> >
> > }
> >
> > }
> >
> >
> >
>
>
Previous Topic:1-2 mth contract in Redwood City, CA
Next Topic:How to use GEF Treeviewer
Goto Forum:
  


Current Time: Fri Jan 24 04:46:47 GMT 2025

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

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

Back to the top