Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Rhombus with centered text
Rhombus with centered text [message #151286] Thu, 16 September 2004 22:51 Go to next message
Eclipse UserFriend
Originally posted by: seasnake.gmx.li

Hi,

now I want to draw a rhombus with text centered in bounds of the figure.
Currently I'm using a Polygon with BorderLayout and I'm adding a FlowPage
with BorderLayout.CENTER constraint. Like this:

f.add(flowPage, BorderLayout.CENTER);

This FlowPage has a TextFlow as child and its horizontal alignment is set
to CENTER, too.

There is no problem in displying this figure until the whole figure is
moved. Then the rhombus (Polygon) is moved and the FlowPage stay still in
place. I've solved this problem by creating a new FlowPage each time the
whole figure is moved and adding a new FlowPage again. Like this:

outline.setPoints(vertices);

FlowPage flowPage = new FlowPage();
TextFlow textFlow = new TextFlow();
// adding LayoutManager and text to textFlow here
flowPage.setHorizontalAligment(PositionConstants.CENTER);
flowPage.add(textFlow);

outline.add(flowPage, BorderLayout.CENTER);

Could anyone explain this behavior or make a suggestion how a could solve
this problem in anothor way? I'm asking because there is the same problem
with the CellEditor when I add the direct edit capability to my Edit part.

Thanks in advance!

Best regards
Ilja
Re: Rhombus with centered text [message #151439 is a reply to message #151286] Mon, 20 September 2004 14:33 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

Don't use Polygon figure. It is not intended to be used in this way.

"Ilja" <seasnake@gmx.li> wrote in message news:cid5e8$t1j$1@eclipse.org...
> Hi,
>
> now I want to draw a rhombus with text centered in bounds of the figure.
> Currently I'm using a Polygon with BorderLayout and I'm adding a FlowPage
> with BorderLayout.CENTER constraint. Like this:
>
> f.add(flowPage, BorderLayout.CENTER);
>
> This FlowPage has a TextFlow as child and its horizontal alignment is set
> to CENTER, too.
>
> There is no problem in displying this figure until the whole figure is
> moved. Then the rhombus (Polygon) is moved and the FlowPage stay still in
> place. I've solved this problem by creating a new FlowPage each time the
> whole figure is moved and adding a new FlowPage again. Like this:
>
> outline.setPoints(vertices);
>
> FlowPage flowPage = new FlowPage();
> TextFlow textFlow = new TextFlow();
> // adding LayoutManager and text to textFlow here
> flowPage.setHorizontalAligment(PositionConstants.CENTER);
> flowPage.add(textFlow);
>
> outline.add(flowPage, BorderLayout.CENTER);
>
> Could anyone explain this behavior or make a suggestion how a could solve
> this problem in anothor way? I'm asking because there is the same problem
> with the CellEditor when I add the direct edit capability to my Edit part.
>
> Thanks in advance!
>
> Best regards
> Ilja
>
Re: Rhombus with centered text [message #151892 is a reply to message #151439] Thu, 23 September 2004 23:23 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: seasnake.gmx.li

Hi Randy,

what should I do? I need a rhombus with a label inside. What would you
suggest?

Additionally I need a rectagele with a rhomubs and a label inside. I
solved the letter problem by putting a rhombus as a child of a Figure with
a XYLayout.

Best regards.
Ilja
Re: Rhombus with centered text [message #151930 is a reply to message #151892] Fri, 24 September 2004 15:00 Go to previous message
Alex Selkov is currently offline Alex SelkovFriend
Messages: 73
Registered: July 2009
Member
"Ilja" <seasnake@gmx.li> ???????/???????? ? ???????? ?????????:
news:civlt0$6jv$1@eclipse.org...
> Hi Randy,
>
> what should I do? I need a rhombus with a label inside. What would you
> suggest?
>
> Additionally I need a rectagele with a rhomubs and a label inside. I
> solved the letter problem by putting a rhombus as a child of a Figure with
> a XYLayout.
>
> Best regards.
> Ilja
>

1. If you need some kind of shape then subclass Shape and implement needed
methods. Something like this:

import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.Shape;
import org.eclipse.draw2d.geometry.PointList;
import org.eclipse.draw2d.geometry.Rectangle;

public class DiamondFigure extends Shape {
static PointList points = new PointList();

protected void fillShape(Graphics graphics) {
graphics.fillPolygon(getPoints(getBounds()));
}

protected void outlineShape(Graphics graphics) {
graphics.drawPolygon(getPoints(getBounds()));
}

private static PointList getPoints(Rectangle r) {
points.removeAllPoints();
points.addPoint(r.getTop());
points.addPoint(r.getRight());
points.addPoint(r.getBottom());
points.addPoint(r.getLeft());
return points;
}
}

2. Combine figures to achieve the result:

RectangleFigure rectangle = new RectangleFigure();
rectangle.setBackgroundColor(ColorConstants.green);
rectangle.setLayoutManager(new StackLayout());
DiamondFigure diamond = new DiamondFigure();
diamond.setBackgroundColor(ColorConstants.yellow);
Label label = new Label("Text");
label.setForegroundColor(ColorConstants.red);
rectangle.add(diamond);
rectangle.add(label);


3. You may need to have additional inner Figure and maybe custom layout
manager to place Label inside Diamond nicely. Have a nice play with D2D :)

Regards,

as
Previous Topic:How to extend RulerProvider
Next Topic:Dificulties using scroll bar
Goto Forum:
  


Current Time: Fri Apr 19 14:14:31 GMT 2024

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

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

Back to the top