Home » Eclipse Projects » GEF » new Font() problem
new Font() problem [message #195730] |
Tue, 13 September 2005 08:53 |
Eclipse User |
|
|
|
Originally posted by: radicr.stop.spam.gmail.com
Hello,
I am new to this newsgroup, and my question is related to draw2d but i didnt
find group that would suit it so i am posting it here.
I am transferring one of my views from SWT (Composite) to GraphicalViewer
and Figure
Method for setting for in SWT was
protected void setFontStyle(Control control, int style, boolean on) {
FontData fd = control.getFont().getFontData()[0];
if (on) {
fd.setStyle(fd.getStyle() | style);
} else {
fd.setStyle(fd.getStyle() | ~style);
}
control.setFont(new Font(getDisplay(), fd));
}
i intended to use similar method in Figure world but, i dont know how to do
this
figure.setFont(new Font(getDisplay(), fd));
since i dont have Display instance here, or at least i dont know how to
obtain it. I have seen examples instancing font new Font(null, fd) but it
gives me NullPointerException.
Any ideas?
--
Pozdrav,
Radovan
|
|
|
Re: new Font() problem [message #195738 is a reply to message #195730] |
Tue, 13 September 2005 09:27 |
Eclipse User |
|
|
|
Originally posted by: radicr.stop.spam.gmail.com
Sorry folks, my mistake. I am using method below like this:
public class DisplayItem extends Panel {
// Constructor
public DisplayItem() {
super();
initComponents();
}
private void initComponents() {
labelValue = new Label("0.0");
setFontStyle(labelValue, true, SWT.BOLD);
...
}
public void setFontStyle(IFigure figure, boolean on, int style) {
// It seems getFont is returning null, WHY? This is when an
exception is really raised
FontData fd = figure.getFont().getFontData()[0];
if (on) {
fd.setStyle(fd.getStyle() | style);
} else {
fd.setStyle(fd.getStyle() | ~style);
}
figure.setFont(new Font(null, fd));
}
....
}
"Radovan Radic" <radicr.stop.spam@gmail.com> wrote in message
news:dg642q$o8e$1@news.eclipse.org...
> Hello,
>
> I am new to this newsgroup, and my question is related to draw2d but i
didnt
> find group that would suit it so i am posting it here.
> I am transferring one of my views from SWT (Composite) to GraphicalViewer
> and Figure
> Method for setting for in SWT was
>
> protected void setFontStyle(Control control, int style, boolean on) {
> FontData fd = control.getFont().getFontData()[0];
> if (on) {
> fd.setStyle(fd.getStyle() | style);
> } else {
> fd.setStyle(fd.getStyle() | ~style);
> }
> control.setFont(new Font(getDisplay(), fd));
> }
>
> i intended to use similar method in Figure world but, i dont know how to
do
> this
>
> figure.setFont(new Font(getDisplay(), fd));
>
> since i dont have Display instance here, or at least i dont know how to
> obtain it. I have seen examples instancing font new Font(null, fd) but it
> gives me NullPointerException.
> Any ideas?
>
> --
> Pozdrav,
> Radovan
>
>
|
|
|
Re: new Font() problem [message #195782 is a reply to message #195738] |
Tue, 13 September 2005 15:39 |
Eclipse User |
|
|
|
Originally posted by: none.unknown.com
Because the figure doesn't have a parent yet. If a font is not explicitly
set on the figure, it returns the font of its parent. Debugging getFont()
would have told you that.
"Radovan Radic" <radicr.stop.spam@gmail.com> wrote in message
news:dg663f$rbi$1@news.eclipse.org...
> Sorry folks, my mistake. I am using method below like this:
>
> public class DisplayItem extends Panel {
> // Constructor
> public DisplayItem() {
> super();
> initComponents();
> }
>
> private void initComponents() {
> labelValue = new Label("0.0");
> setFontStyle(labelValue, true, SWT.BOLD);
> ...
> }
>
> public void setFontStyle(IFigure figure, boolean on, int style) {
> // It seems getFont is returning null, WHY? This is when an
> exception is really raised
> FontData fd = figure.getFont().getFontData()[0];
> if (on) {
> fd.setStyle(fd.getStyle() | style);
> } else {
> fd.setStyle(fd.getStyle() | ~style);
> }
> figure.setFont(new Font(null, fd));
> }
> ...
> }
>
> "Radovan Radic" <radicr.stop.spam@gmail.com> wrote in message
> news:dg642q$o8e$1@news.eclipse.org...
> > Hello,
> >
> > I am new to this newsgroup, and my question is related to draw2d but i
> didnt
> > find group that would suit it so i am posting it here.
> > I am transferring one of my views from SWT (Composite) to
GraphicalViewer
> > and Figure
> > Method for setting for in SWT was
> >
> > protected void setFontStyle(Control control, int style, boolean on) {
> > FontData fd = control.getFont().getFontData()[0];
> > if (on) {
> > fd.setStyle(fd.getStyle() | style);
> > } else {
> > fd.setStyle(fd.getStyle() | ~style);
> > }
> > control.setFont(new Font(getDisplay(), fd));
> > }
> >
> > i intended to use similar method in Figure world but, i dont know how to
> do
> > this
> >
> > figure.setFont(new Font(getDisplay(), fd));
> >
> > since i dont have Display instance here, or at least i dont know how to
> > obtain it. I have seen examples instancing font new Font(null, fd) but
it
> > gives me NullPointerException.
> > Any ideas?
> >
> > --
> > Pozdrav,
> > Radovan
> >
> >
>
>
|
|
|
Re: new Font() problem [message #195808 is a reply to message #195738] |
Tue, 13 September 2005 16:02 |
Fabian Wolf Messages: 96 Registered: July 2009 |
Member |
|
|
Radovan Radic wrote:
> Sorry folks, my mistake. I am using method below like this:
>
> public class DisplayItem extends Panel {
> // Constructor
> public DisplayItem() {
> super();
> initComponents();
> }
>
> private void initComponents() {
> labelValue = new Label("0.0");
> setFontStyle(labelValue, true, SWT.BOLD);
> ...
> }
>
> public void setFontStyle(IFigure figure, boolean on, int style) {
> // It seems getFont is returning null, WHY? This is when an
> exception is really raised
> FontData fd = figure.getFont().getFontData()[0];
> if (on) {
> fd.setStyle(fd.getStyle() | style);
> } else {
> fd.setStyle(fd.getStyle() | ~style);
> }
> figure.setFont(new Font(null, fd));
> }
> ...
> }
Hi,
do I get that right, that upon each call of setFontStyle() you're creating a
new Font object? How often does that get called? Have you run Sleak on
that,... it just feels like they never get cleaned up.
|
|
|
Re: new Font() problem [message #195898 is a reply to message #195808] |
Wed, 14 September 2005 07:02 |
Eclipse User |
|
|
|
Originally posted by: radicr.stop.spam.gmail.com
I have resource manager, this was just simplified code.
Thanks to Pratik i realize what seems to be the problem. I didnt expect that
parent's font or figure's font was not set in that moment.
Thanks,
Radovan
"Fabian Wolf" <Fabian.Wolf@informatik.uni-ulm.de> wrote in message
news:dg6t78$75q$1@news.eclipse.org...
> Radovan Radic wrote:
>
> > Sorry folks, my mistake. I am using method below like this:
> >
> > public class DisplayItem extends Panel {
> > // Constructor
> > public DisplayItem() {
> > super();
> > initComponents();
> > }
> >
> > private void initComponents() {
> > labelValue = new Label("0.0");
> > setFontStyle(labelValue, true, SWT.BOLD);
> > ...
> > }
> >
> > public void setFontStyle(IFigure figure, boolean on, int style) {
> > // It seems getFont is returning null, WHY? This is when an
> > exception is really raised
> > FontData fd = figure.getFont().getFontData()[0];
> > if (on) {
> > fd.setStyle(fd.getStyle() | style);
> > } else {
> > fd.setStyle(fd.getStyle() | ~style);
> > }
> > figure.setFont(new Font(null, fd));
> > }
> > ...
> > }
>
> Hi,
>
> do I get that right, that upon each call of setFontStyle() you're creating
a
> new Font object? How often does that get called? Have you run Sleak on
> that,... it just feels like they never get cleaned up.
>
|
|
|
Goto Forum:
Current Time: Sat Jan 18 08:15:02 GMT 2025
Powered by FUDForum. Page generated in 0.03173 seconds
|