Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Vertical Labels(Label parallel to vertical lines)
Vertical Labels [message #872574] Wed, 16 May 2012 11:32 Go to next message
Karl Schmitt is currently offline Karl SchmittFriend
Messages: 7
Registered: February 2012
Junior Member
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 #875367 is a reply to message #872574] Tue, 22 May 2012 15:54 Go to previous messageGo to next message
Karl Schmitt is currently offline Karl SchmittFriend
Messages: 7
Registered: February 2012
Junior Member
O.K. I googled arround and some advice recomended
to rotoate via graphics, however , this doesn't work for me Sad
here my example code:

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);
}
}

package HelloWorld;

import org.eclipse.draw2d.BorderLayout;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.LightweightSystem;


import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class TestVerticalLabel {

public static void main(String[] args) {

Display display = new Display();

Shell shell = new Shell(display);

shell.setText("Vertical Label");

shell.setSize(250, 200);

shell.open();

LightweightSystem lws = new LightweightSystem(shell);

Figure parent = new Figure();

parent.setLayoutManager(new BorderLayout());

lws.setContents(parent);

VerticalLabel label = new VerticalLabel();

// Label label = new Label();

label.setText("Vertical Label");

parent.add(label);

parent.getLayoutManager().setConstraint(label, BorderLayout.CENTER);

while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}

}

}
Re: Vertical Labels still no clue [message #876197 is a reply to message #875367] Thu, 24 May 2012 05:41 Go to previous messageGo to next message
Eclipse UserFriend
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 #876883 is a reply to message #876197] Fri, 25 May 2012 12:51 Go to previous messageGo to next message
Karl Schmitt is currently offline Karl SchmittFriend
Messages: 7
Registered: February 2012
Junior Member
Fist of all the little example works very well now Smile Thanks very much.
However, if I use my litle derived class (Vertical Label) in a bigger GEF context
it doesn't draw any text Sad -> 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 Sad

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? Sad

Re: Vertical Labels still no clue [message #876916 is a reply to message #876883] Fri, 25 May 2012 14:17 Go to previous message
Eclipse UserFriend
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? :(
>
>
Previous Topic:Controlling line breaks in Multiline labels
Next Topic:Is this a bug? CreateRequest does not extend LocationRequest
Goto Forum:
  


Current Time: Thu Apr 25 00:54:53 GMT 2024

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

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

Back to the top