Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Problem with rotating a Draw2D Label
Problem with rotating a Draw2D Label [message #243975] Tue, 01 July 2008 11:01
Eclipse UserFriend
Originally posted by: benni5000.yahoo.de

Hi,

I am trying to rotate a Draw2D Label. I read that I have to override the
paintFigure() method of the Label class so that I call graphics.rotate()
before super.paintFigure(). My problem is that I get an
NullPointerException
at
org.eclipse.draw2d.SWTGraphics.checkSharedClipping(SWTGraphi cs.java:309)
when I call super.paintFigure(graphics).

Can anyone tell me, where I am wrong?

This is the code I used:

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.FigureCanvas;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.LightweightSystem;
import org.eclipse.draw2d.XYLayout;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;

public class Window extends ApplicationWindow {

public Window() {
super(null);
}

public static void main(String[] args) {
Window window = new Window();
window.setBlockOnOpen(true);
window.open();
Display.getCurrent().dispose();
}

protected Control createContents(Composite parent) {
FigureCanvas canvas = new FigureCanvas(parent);
LightweightSystem lws = new LightweightSystem(canvas);
IFigure contents = new Figure();
contents.setLayoutManager(new XYLayout());

Label lbl = new VerticalLabel("Text");
lbl.setOpaque(true);
lbl.setBackgroundColor(ColorConstants.red);
contents.add(lbl, new Rectangle(10, 10, -1, -1));
lws.setContents(contents);
return canvas;
}
}

class VerticalLabel extends Label
{
public VerticalLabel() {}

public VerticalLabel(String str) {
super(str);
}

@Override
protected void paintFigure(Graphics graphics) {
graphics.rotate(90);
super.paintFigure(graphics);
}
}


Thanks,

Benhorn
Previous Topic:How to get layer to fill it's pane?
Next Topic:Getting Started
Goto Forum:
  


Current Time: Thu Sep 20 01:49:23 GMT 2018

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

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

Back to the top