Vertical Labels [message #872574] |
Wed, 16 May 2012 07:32  |
Eclipse User |
|
|
|
Dear Folks,
I am developing a GEF application with a underlying
EMF data structure for a railway system, here
I do have horizontal and vertical lines, providing
a Label for horizontal lines was easy since the
text is als "drawn" in a horizonal fasion from left
to right, however for the vertical lines I do not
know how to get the text writen or drawn parallel
to the vertical line, in other words from bottom
to top, basicly I do have rotate 90 degrees to the left.
How can I do that with GEF or draw2d?
Yours,
Karl
|
|
|
|
|
|
Re: Vertical Labels still no clue [message #876916 is a reply to message #876883] |
Fri, 25 May 2012 10: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 0.06198 seconds