|
|
Re: Vertical Labels still no clue [message #876197 is a reply to message #875367] |
Thu, 24 May 2012 05:41 |
Eclipse User |
|
|
|
try this:
@Override
protected void paintFigure(Graphics graphics) {
graphics.translate(getParent().getSize().width / 2,
getParent().getSize().height / 2);
graphics.rotate(90);
graphics.translate(-(getParent().getSize().width / 2),
-(getParent().getSize().height / 2));
super.paintFigure(graphics);
}
On 05/22/2012 05:54 PM, Karl Schmitt wrote:
> package HelloWorld;
>
> import org.eclipse.draw2d.Graphics;
> import org.eclipse.draw2d.Label;
>
> public class VerticalLabel extends Label {
>
> @Override
> protected void paintFigure(Graphics graphics) {
>
> graphics.rotate(90);
> super.paintFigure(graphics);
> }
> }
|
|
|
|
Re: Vertical Labels still no clue [message #876916 is a reply to message #876883] |
Fri, 25 May 2012 14:17 |
Eclipse User |
|
|
|
I have never done a label on a connection so I cannot help you with
that. I think you should learn how GEF graphics and coordinate system
work, it will make your life easier. At least, this is the code for
ordinary vertical label:
public class VerticalLabel extends Label {
@Override
protected void paintFigure(Graphics graphics) {
Rectangle bounds = getBounds();
graphics.translate(bounds.x, bounds.y);
int textWidth = FigureUtilities.getTextWidth(getText(), getFont());
if (getIcon() != null)
graphics.drawImage(getIcon(), getIconLocation());
if (!isEnabled()) {
graphics.translate(1, 1);
graphics.setForegroundColor(ColorConstants.buttonLightest);
graphics.translate(getSize().width / 2, getSize().height / 2);
graphics.rotate(90);
graphics.translate(-(getSize().width / 2), -(getSize().height / 2));
graphics.drawText(getText(), (getSize().width / 2) - textWidth /
2, (int) (getSize().height / 2 - getFont().getFontData()[0].height));
graphics.translate(-1, -1);
graphics.setForegroundColor(ColorConstants.buttonDarker);
}
graphics.translate(getSize().width / 2, getSize().height / 2);
graphics.rotate(90);
graphics.translate(-(getSize().width / 2), -(getSize().height / 2));
graphics.drawText(getText(), (getSize().width / 2) - textWidth / 2,
(int) (getSize().height / 2 - getFont().getFontData()[0].height));
graphics.translate(-bounds.x, -bounds.y);
}
}
On 05/25/2012 02:51 PM, Karl Schmitt wrote:
> Fist of all the little example works very well now :) Thanks very much.
> However, if I use my litle derived class (Vertical Label) in a bigger
> GEF context
> it doesn't draw any text :( -> do I have to do any other stuff too?
> If I comment the rotation line out the label is drawn horizontaly,
> if I activte the rotation line nothing is drawn :(
>
> here some of the code how I want to use the new vertical label:
>
> trainLabel = new VerticalLabel();
> trainLabel.setText(stringBuffer.toString()); // Some Train Nummber e.g.
> 1001.42
> trainLabelLocator = new ConnectionEndpointLocator(connectionFigure, false);
> connectionFigure.add(trainLabel,trainLabelLocator);
>
> What am I doing wrong? :(
>
>
|
|
|
Powered by
FUDForum. Page generated in 1.98220 seconds