Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » GEF Custom Figure / Draw2D / Label Problem
GEF Custom Figure / Draw2D / Label Problem [message #247913] Wed, 25 March 2009 16:43 Go to next message
Eclipse UserFriend
Originally posted by: Unripe.web.de

This is a multi-part message in MIME format.
--------------050700090906040508020709
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Hi everyone,

i have a stupid problem right know. I tried to write my own CustomFigure
instead of composing it. So far no problem everything works fine. But
when i try to create a label, add it to my Parent Figure and set the
setConstraint() Method either the damn thing wont show or the complete
thing blows up. I tried to test an example from an Eclipse-Plug-In book
and some from the net, nothing works.

The code in my paint Method looks like this, the add(label) is placed in
the constructor.

// draw the label
Rectangle r = getClientArea();
setConstraint(label, new Rectangle(r.x + 10, r.y + 10, r.width - 21,
r.height - 21));

--------------050700090906040508020709
Content-Type: text/plain;
name="TestCustomFigure.txt"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="TestCustomFigure.txt"

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.FreeformLayout;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.PositionConstants;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.PointList;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.graphics.Image;

public class TestCustomFigure extends Figure
{
private static final int FOLDED_CORNER_LENGTH = 12;

private Label label;

public TestCustomFigure() {
super();
label = new Label();
label.setTextAlignment(PositionConstants.LEFT);
add(label);
setLayoutManager(new FreeformLayout());
}

public void setText(String text) {
label.setText(text);
}

public void setImage(Image icon) {
label.setIcon(icon);
}

protected void paintFigure(Graphics g) {
super.paintFigure(g);

Rectangle r = getClientArea();

// draw the rectangle without the top left corner
g.drawLine(r.x, r.y, r.x + r.width - FOLDED_CORNER_LENGTH - 1, r.y); // top
g.drawLine(r.x, r.y, r.x, r.y + r.height - 1); // left
g.drawLine(r.x, r.y + r.height - 1, r.x + r.width - 1, r.y + r.height - 1); // bottom
g.drawLine(r.x + r.width - 1, r.y + FOLDED_CORNER_LENGTH - 1, r.x + r.width - 1,
r.y + r.height - 1); // right

// draw the label

setConstraint(label, new Rectangle(r.x + 10, r.y + 10, r.width - 21, r.height - 21));

// draw the folded corner
Point topLeftCorner, bottomLeftCorner, bottomRightCorner;
PointList trianglePolygon;
topLeftCorner = new Point(r.x + r.width - FOLDED_CORNER_LENGTH - 1, r.y);
bottomLeftCorner =
new Point(r.x + r.width - FOLDED_CORNER_LENGTH - 1, r.y
+ FOLDED_CORNER_LENGTH);
bottomRightCorner = new Point(r.x + r.width - 1, r.y + FOLDED_CORNER_LENGTH);
trianglePolygon = new PointList(3);
trianglePolygon.addPoint(topLeftCorner);
trianglePolygon.addPoint(bottomLeftCorner);
trianglePolygon.addPoint(bottomRightCorner);

g.setBackgroundColor(ColorConstants.lightGray);
g.fillPolygon(trianglePolygon);

g.drawLine(topLeftCorner, bottomLeftCorner);
g.drawLine(bottomLeftCorner, bottomRightCorner);
g.setLineDash(new int[] { 1 });
g.drawLine(bottomRightCorner, topLeftCorner);
}
}












--------------050700090906040508020709--
Re: GEF Custom Figure / Draw2D / Label Problem [message #247923 is a reply to message #247913] Thu, 26 March 2009 14:29 Go to previous message
Eclipse UserFriend
Originally posted by: Unripe.web.de

Ok, solved the "Not showing the Label" Problem...now the only thing is
that when i try to move the Figure, its getting begin to eternity.

Kevin schrieb:
> Hi everyone,
>
> i have a stupid problem right know. I tried to write my own CustomFigure
> instead of composing it. So far no problem everything works fine. But
> when i try to create a label, add it to my Parent Figure and set the
> setConstraint() Method either the damn thing wont show or the complete
> thing blows up. I tried to test an example from an Eclipse-Plug-In book
> and some from the net, nothing works.
>
> The code in my paint Method looks like this, the add(label) is placed in
> the constructor.
>
> // draw the label
> Rectangle r = getClientArea();
> setConstraint(label, new Rectangle(r.x + 10, r.y + 10, r.width - 21,
> r.height - 21));
>
Previous Topic:Palette Viewer
Next Topic:How to zoom in/out SVG(vector image) images like PowerPoint with using GEF
Goto Forum:
  


Current Time: Thu Jul 25 06:12:55 GMT 2024

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

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

Back to the top