Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Strange behaviour of a Label with a Border ?
Strange behaviour of a Label with a Border ? [message #136378] Sat, 05 June 2004 01:28 Go to next message
Eclipse UserFriend
Originally posted by: rlemaigr.ulb.ac.be

Hello,

the text and icon locations in a Label seem to be calculated based on th=
e =

bounds. I don't understand why and I would have expected it would have =

been based on the client area instead.

I've written a BottomLineBorder class to add a line at the bottom of som=
e =

figures and I've tried to use it with Labels, but if the line is large, =
=

the text is covered by my line. I've had the same problem with margin =

border. When I add a Margin border like new MarginBorder(10,0,0,0), the =
=

text stays at the center of the bounds and the only effect of my =

MarginBorder is to change the preferred size of the label.

In fact it's the same with other Figures like RectangleFigure...

The paintFigure method of RectangleFigure is

protected void outlineShape(Graphics graphics) {
Rectangle r =3D getBounds();
int x =3D r.x + lineWidth / 2;
int y =3D r.y + lineWidth / 2;
int w =3D r.width - lineWidth;
int h =3D r.height - lineWidth;
graphics.drawRectangle(x, y, w, h);
}

So if I add a border to my rectangle, the outline of the rectangle will =
be =

coverd by the border...I think it is strange and unexpected...

Is it some kind of mistake ? Or is it me that don't understand something=
?

Thanks for your answers,

r=E9gis



-- =

Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
Re: Strange behaviour of a Label with a Border ? [message #136643 is a reply to message #136378] Mon, 07 June 2004 13:44 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: rlemaigr.ulb.ac.be

Another strange thing I've just noticied:

In the IFigure interface, the description of the getPreferredSize method=
=

says:

" Returns the desireable size for this IFigure using the provided width =
=

and height hints.
Returned Dimension is by value. If a hint is less than or equal to 0 =
=

(usually, it's
set to -1), it means that hint should be ignored."

But the implementation of this method in the Figure class begins with:
public Dimension getPreferredSize(int wHint, int hHint)
{
if (prefSize !=3D null)
return prefSize;
....
}
So the preferred size seems to be return by referrence and not by value,=
=

so I can't modify the result without copy it before.

(In one of my Figure classes, I've redifined the getPreferredSize and th=
e =

layout methods and in the getPreferredSize method if I don't return a co=
py =

of my cached preferredSize, it don't work at all. The parent layout =

manager is ToolbarLayout.)

Is that a bug in the getPreferredSize method or a problem in its =

definition in the IFigure interface ? Or it is me that don't understand =
=

smthg ?

r=E9gis
Re: Strange behaviour of a Label with a Border ? [message #136689 is a reply to message #136378] Mon, 07 June 2004 14:43 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

the text and icon locations in a Label seem to be calculated based on the
bounds. I don't understand why and I would have expected it would have
been based on the client area instead.

RH> There are several places where Label calls getInsets(), this should be
equivalent to using the client area.

I've written a BottomLineBorder class to add a line at the bottom of some
figures and I've tried to use it with Labels, but if the line is large,
the text is covered by my line. I've had the same problem with margin
border. When I add a Margin border like new MarginBorder(10,0,0,0), the
text stays at the center of the bounds and the only effect of my
MarginBorder is to change the preferred size of the label.

In fact it's the same with other Figures like RectangleFigure...

RH> RectangleFigure is just a silly shape. If you want a rectangular border
which nests, use LineBorder().

The paintFigure method of RectangleFigure is

protected void outlineShape(Graphics graphics) {
Rectangle r = getBounds();
int x = r.x + lineWidth / 2;
int y = r.y + lineWidth / 2;
int w = r.width - lineWidth;
int h = r.height - lineWidth;
graphics.drawRectangle(x, y, w, h);
}

So if I add a border to my rectangle, the outline of the rectangle will be
coverd by the border...I think it is strange and unexpected...

Is it some kind of mistake ? Or is it me that don't understand something ?

Thanks for your answers,

r
Re: Strange behaviour of a Label with a Border ? [message #136702 is a reply to message #136643] Mon, 07 June 2004 14:45 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

RH> You are correct, getPreferredSize may return a Dimension by *reference*,
and it should never be modified by the caller. If you see a case where this
happens, please report a bugzilla. Caching is common and it is what all of
our LayoutManagers do by default. So there should be lots of examples of a
cached preferred size being returned.

<rlemaigr@ulb.ac.be> wrote in message
news:opr878foukxn9g2u@xn--pcrgis-dva.mshome.net...
Another strange thing I've just noticied:

In the IFigure interface, the description of the getPreferredSize method
says:

" Returns the desireable size for this IFigure using the provided width
and height hints.
Returned Dimension is by value. If a hint is less than or equal to 0
(usually, it's
set to -1), it means that hint should be ignored."

But the implementation of this method in the Figure class begins with:
public Dimension getPreferredSize(int wHint, int hHint)
{
if (prefSize != null)
return prefSize;
....
}
So the preferred size seems to be return by referrence and not by value,
so I can't modify the result without copy it before.

(In one of my Figure classes, I've redifined the getPreferredSize and the
layout methods and in the getPreferredSize method if I don't return a copy
of my cached preferredSize, it don't work at all. The parent layout
manager is ToolbarLayout.)

Is that a bug in the getPreferredSize method or a problem in its
definition in the IFigure interface ? Or it is me that don't understand
smthg ?

r
Re: Strange behaviour of a Label with a Border ? [message #136749 is a reply to message #136689] Mon, 07 June 2004 15:17 Go to previous message
Eclipse UserFriend
Originally posted by: rlemaigr.ulb.ac.be

> RH> There are several places where Label calls getInsets(), this shoul=
d =

> be equivalent to using the client area.

Ok I didn't noticed that. But no it seems not equivalent and that's my =

problem, see my example here:

> I've written a BottomLineBorder class to add a line at the bottom of s=
ome
> figures and I've tried to use it with Labels, but if the line is large=
,
> the text is covered by my line. I've had the same problem with margin
> border. When I add a Margin border like new MarginBorder(10,0,0,0), th=
e
> text stays at the center of the bounds and the only effect of my
> MarginBorder is to change the preferred size of the label.

Please try a Label with a border with an asymetrical MarginBorder like n=
ew =

CompoundBorder(new LineBorder(1), new MarginBorder (20,0,0,0)) , put the=
=

Label in a parent figure with a layout manager which gives the Label its=
=

preferred size and you will see that the text stays at the center of the=
=

bounds and not in the center of the client area. And if the border is =

large, the text is covered by the border...

With this border:
Label lab =3D new Label("qsdfqsdf");
lab.setBorder(new CompoundBorder(new LineBorder(1), new CompoundBorder(n=
ew =

MarginBorder (50,0,0,0), new LineBorder(1))));

I have this:
http://users.skynet.be/mon.mignon.petit.site/lab.gif ( the text should b=
e =

in the little black rectangle )


And with this border:
Label lab =3D new Label("qsdfqsdf");
lab.setBorder(new CompoundBorder(new LineBorder(1),new =

BottomLineBorder(10)));

I have this
http://users.skynet.be/mon.mignon.petit.site/lab2.gif (the text should n=
ot =

be partially hidden by the black line)


r=E9gis
Previous Topic:How to create Nodes in HalloGef Examples
Next Topic:[Draw2d] Max dimension, layout & BlocFlow
Goto Forum:
  


Current Time: Fri Apr 26 01:28:51 GMT 2024

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

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

Back to the top