Skip to main content



      Home
Home » Eclipse Projects » GEF » draw2d.Label.getPreferredSize() throws Null Pointer on second run
draw2d.Label.getPreferredSize() throws Null Pointer on second run [message #70190] Thu, 13 March 2003 16:19 Go to next message
Eclipse UserFriend
Originally posted by: a_shishkov.yahoo.com

Hi,

I have a simple Eclipse plugin view with a draw2d.Label in it. I set some
text in the Label and then setBounds using its preferred size. This works
fine when I open the view the first time, the Label shows up with the text.
But if I close the view and open it again, I get a Null pointer exception.

Here is my code sample:

public class ArtifactDependencyView extends ViewPart {
Canvas viewer;
LightweightSystem lws;
IFigure panel;
Label frame;
......
public void createPartControl(Composite parent) {
viewer = new Canvas(parent, SWT.NONE);
lws = new LightweightSystem(viewer);
panel = new Figure();
lws.setContents(panel);
frame = new Label("Frame: 0000");
frame.setBounds(new Rectangle(DIMENSION_X + 10, 10,
frame.getPreferredSize().width, frame.getPreferredSize().height));
frame.setTextAlignment(Label.LEFT);
panel.add(frame);
}


When I close the view and open it a second time, this is the exception I
get:

java.version=1.4.1
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=en_US
Command-line arguments: -dev bin,bin -data
D:\Software\Eclipse\runtime-workspace -os win32 -ws win32 -arch x86 -nl
en_US
!ENTRY org.eclipse.ui.workbench 4 2 Mar 13, 2003 14:51:53.881
!MESSAGE Problems occurred when invoking code from plug-in:
"org.eclipse.ui.workbench".
!STACK 0
java.lang.NullPointerException
at org.eclipse.draw2d.FigureUtilities.setFont(FigureUtilities.j ava:246)
at
org.eclipse.draw2d.FigureUtilities.getTextDimension(FigureUt ilities.java:72)
at
org.eclipse.draw2d.FigureUtilities.getTextExtents(FigureUtil ities.java:125)
at org.eclipse.draw2d.Label.calculateTextSize(Label.java:211)
at org.eclipse.draw2d.Label.getTextSize(Label.java:398)
at org.eclipse.draw2d.Label.getPreferredSize(Label.java:285)
at org.eclipse.draw2d.Figure.getPreferredSize(Figure.java:594)

at
edu.depaul.fluid.ui.eclipse.dependency.ArtifactDependencyVie w.createPartCont
rol(ArtifactDependencyView.java:96)

at org.eclipse.ui.internal.PartPane$4.run(PartPane.java:135)
at
org.eclipse.core.internal.runtime.InternalPlatform.run(Inter nalPlatform.java
:839)
at org.eclipse.core.runtime.Platform.run(Platform.java:413)
at org.eclipse.ui.internal.PartPane.createChildControl(PartPane .java:133)
at org.eclipse.ui.internal.ViewPane.createChildControl(ViewPane .java:201)
at org.eclipse.ui.internal.PartPane.createControl(PartPane.java :177)
at org.eclipse.ui.internal.ViewPane.createControl(ViewPane.java :180)
at
org.eclipse.ui.internal.PartSashContainer.replace(PartSashCo ntainer.java:414
)
at
org.eclipse.ui.internal.PerspectivePresentation.addPart(Pers pectivePresentat
ion.java:186)
at org.eclipse.ui.internal.Perspective.showView(Perspective.jav a:1316)
at
org.eclipse.ui.internal.WorkbenchPage.busyShowView(Workbench Page.java:555)
at org.eclipse.ui.internal.WorkbenchPage.access$6(WorkbenchPage .java:534)
at org.eclipse.ui.internal.WorkbenchPage$12.run(WorkbenchPage.j ava:2409)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator .java:65)
at org.eclipse.ui.internal.WorkbenchPage.showView(WorkbenchPage .java:2406)
at org.eclipse.ui.internal.WorkbenchPage.showView(WorkbenchPage .java:2396)
at org.eclipse.ui.internal.ShowViewMenu.showOther(ShowViewMenu. java:181)
at org.eclipse.ui.internal.ShowViewMenu.access$2(ShowViewMenu.j ava:167)
at org.eclipse.ui.internal.ShowViewMenu$2.run(ShowViewMenu.java :41)
at org.eclipse.jface.action.Action.runWithEvent(Action.java:769 )
at
org.eclipse.jface.action.ActionContributionItem.handleWidget Selection(Action
ContributionItem.java:411)
at
org.eclipse.jface.action.ActionContributionItem.handleWidget Event(ActionCont
ributionItem.java:365)
at
org.eclipse.jface.action.ActionContributionItem.access$0(Act ionContributionI
tem.java:356)
at
org.eclipse.jface.action.ActionContributionItem$ActionListen er.handleEvent(A
ctionContributionItem.java:48)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java :77)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:825)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.ja va:1692)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :1410)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.jav a:1435)
at org.eclipse.ui.internal.Workbench.run(Workbench.java:1418)
at
org.eclipse.core.internal.boot.InternalBootLoader.run(Intern alBootLoader.jav
a:831)
at org.eclipse.core.boot.BootLoader.run(BootLoader.java:432)
at EclipseRuntimeLauncher.main(EclipseRuntimeLauncher.java:24)

ArtifactDependencyView.java:96 is this line:
frame.setBounds(new Rectangle(DIMENSION_X + 10, 10,
frame.getPreferredSize().width, frame.getPreferredSize().height));

It seems the exception is thrown by the getPreferredSize method. I can't
understand why that is, since it works the first time I start the view.
I have tried disposing of the components in the dispose() method:

public void dispose() {
super.dispose();
viewer.dispose();
lws = null;
panel = null;
frame = null;
}

With no effect. Any help would be greatly appreciated, thanks!

Angel Shishkov
DePaul University
Chicago, IL
Re: draw2d.Label.getPreferredSize() throws Null Pointer on second run [message #70210 is a reply to message #70190] Thu, 13 March 2003 16:35 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

> public void createPartControl(Composite parent) {
> viewer = new Canvas(parent, SWT.NONE);
> lws = new LightweightSystem(viewer);
> panel = new Figure();
> lws.setContents(panel);
> frame = new Label("Frame: 0000");
> frame.setBounds(new Rectangle(DIMENSION_X + 10, 10,
> frame.getPreferredSize().width, frame.getPreferredSize().height));

you cannot call getPreferredSize() on a figure unless it knows its Font. It
will know after you call panel.add(frame) below. Reorder the code to fix.

> frame.setTextAlignment(Label.LEFT);
> panel.add(frame);
> }
Re: draw2d.Label.getPreferredSize() throws Null Pointer on second run [message #70489 is a reply to message #70210] Fri, 14 March 2003 11:41 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: a_shishkov.yahoo.com

Thank you Randy, that fixed it. Weird that it would work the first time
though...

Angel

"Randy Hudson" <none@us.ibm.com> wrote in message
news:b4qtms$cnr$1@rogue.oti.com...
> > public void createPartControl(Composite parent) {
> > viewer = new Canvas(parent, SWT.NONE);
> > lws = new LightweightSystem(viewer);
> > panel = new Figure();
> > lws.setContents(panel);
> > frame = new Label("Frame: 0000");
> > frame.setBounds(new Rectangle(DIMENSION_X + 10, 10,
> > frame.getPreferredSize().width, frame.getPreferredSize().height));
>
> you cannot call getPreferredSize() on a figure unless it knows its Font.
It
> will know after you call panel.add(frame) below. Reorder the code to fix.
>
> > frame.setTextAlignment(Label.LEFT);
> > panel.add(frame);
> > }
>
>
>
Re: draw2d.Label.getPreferredSize() throws Null Pointer on second run [message #70507 is a reply to message #70489] Fri, 14 March 2003 11:49 Go to previous message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

I found the reason:

protected static void setFont(Font f){

if (appliedFont == f || f.equals(appliedFont))

return;

getGC().setFont(f);

appliedFont = f;

metrics = null;

}


The first time you call it, "appliedFont" == null, which == f, so setFont
doesn't do anything.
I've changed it to initialize appliedFont in getGC();

"Angel Shishkov" <a_shishkov@yahoo.com> wrote in message
news:b4t0oh$p4i$1@rogue.oti.com...
> Thank you Randy, that fixed it. Weird that it would work the first time
> though...
>
> Angel
>
> "Randy Hudson" <none@us.ibm.com> wrote in message
> news:b4qtms$cnr$1@rogue.oti.com...
> > > public void createPartControl(Composite parent) {
> > > viewer = new Canvas(parent, SWT.NONE);
> > > lws = new LightweightSystem(viewer);
> > > panel = new Figure();
> > > lws.setContents(panel);
> > > frame = new Label("Frame: 0000");
> > > frame.setBounds(new Rectangle(DIMENSION_X + 10, 10,
> > > frame.getPreferredSize().width, frame.getPreferredSize().height));
> >
> > you cannot call getPreferredSize() on a figure unless it knows its Font.
> It
> > will know after you call panel.add(frame) below. Reorder the code to
fix.
> >
> > > frame.setTextAlignment(Label.LEFT);
> > > panel.add(frame);
> > > }
> >
> >
> >
>
>
Previous Topic:Newbie question: Using gef in standalone application?
Next Topic:Use JTree as a figure in the GEF editor
Goto Forum:
  


Current Time: Sat May 10 18:07:42 EDT 2025

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

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

Back to the top