Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » RoundedRectangle
RoundedRectangle [message #92448] Thu, 04 September 2003 16:40 Go to next message
Alex Selkov is currently offline Alex SelkovFriend
Messages: 73
Registered: July 2009
Member
RoundedRectangle depicts incorrectly.

I also found useful if setLineWidth(0) has the same effect as
setOutline(false). Is it possible to incorporate such behavior into the
Shape?


Index: Shape.java
============================================================ =======
RCS file: /home/tools/org.eclipse.draw2d/src/org/eclipse/draw2d/Shape. java,v
retrieving revision 1.4
diff -u -r1.4 Shape.java
--- Shape.java 3 Jun 2003 19:05:55 -0000 1.4
+++ Shape.java 4 Sep 2003 16:35:44 -0000
@@ -25,6 +25,7 @@
private boolean
fill = true,
outline = true,
+ suppressOutline = false,
xorFill,
xorOutline;

@@ -89,7 +90,7 @@
graphics.setXORMode(xorFill);
fillShape(graphics);
}
- if (outline) {
+ if (outline && !suppressOutline) {
graphics.setXORMode(xorOutline);
graphics.setLineStyle(lineStyle);
graphics.setLineWidth(lineWidth);
@@ -103,7 +104,7 @@
graphics.setXORMode(xorFill);
fillShape(graphics);
}
- if (outline) {
+ if (outline && !suppressOutline) {
graphics.setXORMode(xorOutline);
graphics.setLineStyle(lineStyle);
graphics.setLineWidth(lineWidth);
@@ -147,6 +148,11 @@
if (lineWidth == w)
return;
lineWidth = w;
+ if (lineWidth == 0) {
+ suppressOutline = true;
+ } else {
+ suppressOutline = false;
+ };
repaint();
}


------------------------------------------------------------ ----------------
------------------------------------------------------------ -
import org.eclipse.draw2d.ColorConstants;

import org.eclipse.draw2d.Ellipse;

import org.eclipse.draw2d.Figure;

import org.eclipse.draw2d.IFigure;

import org.eclipse.draw2d.Label;

import org.eclipse.draw2d.LightweightSystem;

import org.eclipse.draw2d.LineBorder;

import org.eclipse.draw2d.Polyline;

import org.eclipse.draw2d.RectangleFigure;

import org.eclipse.draw2d.RoundedRectangle;

import org.eclipse.draw2d.geometry.Dimension;

import org.eclipse.draw2d.geometry.Point;

import org.eclipse.swt.graphics.Color;

import org.eclipse.swt.widgets.Display;

import org.eclipse.swt.widgets.Shell;

public class Demo4 {

private static final int GAP = 20;

private static final Dimension SIZE = new Dimension(75, 50);

private static final Dimension CORNER = new Dimension(30, 25);

private static final int COUNT = 20;

public static void main(String args[]) {

Shell shell = new Shell();

shell.setSize(800, 750);

shell.open();

shell.setText("Figures");

LightweightSystem lws = new LightweightSystem(shell);

IFigure panel = new Figure();

lws.setContents(panel);

final Color BG_COLOR = ColorConstants.white;

final Color PANEL_COLOR = ColorConstants.blue;

final Color FG_COLOR = ColorConstants.red;

final Color GRID_COLOR = ColorConstants.black;

panel.setBackgroundColor(PANEL_COLOR);

panel.setOpaque(true);

for (int i = 0; i < COUNT; i++) {

if (i % 2 == 0) {

Polyline p = new Polyline();

p.setForegroundColor(GRID_COLOR);

p.setStart(

new Point(0, GAP + (GAP + SIZE.height) * (i / 2) - 1));

p.setEnd(

new Point(

GAP + 8 * (GAP + SIZE.width),

GAP + (GAP + SIZE.height) * (i / 2) - 1));

panel.add(p);

p = new Polyline();

p.setForegroundColor(GRID_COLOR);

p.setStart(new Point(0, (GAP + SIZE.height) * (i / 2 + 1) - 1));

p.setEnd(

new Point(

GAP + 8 * (GAP + SIZE.width),

(GAP + SIZE.height) * (i / 2 + 1) - 1));

panel.add(p);

}

RoundedRectangle rr = new RoundedRectangle();

rr.setBackgroundColor(BG_COLOR);

rr.setForegroundColor(FG_COLOR);

rr.setCornerDimensions(CORNER);

rr.setSize(SIZE);

rr.setLineWidth(i);

rr.setLocation(

new Point(

GAP + (i % 2) * (SIZE.width + GAP),

GAP + (i / 2) * (SIZE.height + GAP)));

panel.add(rr);

RectangleFigure rf = new RectangleFigure();

rf.setBackgroundColor(BG_COLOR);

rf.setForegroundColor(FG_COLOR);

rf.setSize(SIZE);

rf.setLineWidth(i);

rf.setLocation(

new Point(

GAP * 3 + SIZE.width * 2 + (i % 2) * (SIZE.width + GAP),

GAP + (i / 2) * (SIZE.height + GAP)));

panel.add(rf);

Ellipse el = new Ellipse();

el.setBackgroundColor(BG_COLOR);

el.setForegroundColor(FG_COLOR);

el.setSize(SIZE);

el.setLineWidth(i);

el.setLocation(

new Point(

GAP * 5 + SIZE.width * 4 + (i % 2) * (SIZE.width + GAP),

GAP + (i / 2) * (SIZE.height + GAP)));

panel.add(el);

Label l = new Label("Label #" + i);

l.setBackgroundColor(BG_COLOR);

l.setForegroundColor(FG_COLOR);

l.setOpaque(true);

l.setSize(SIZE);

if (i != 0)

l.setBorder(new LineBorder(i));

l.setLocation(

new Point(

GAP * 7 + SIZE.width * 6 + (i % 2) * (SIZE.width + GAP),

GAP + (i / 2) * (SIZE.height + GAP)));

panel.add(l);

}

Display display = Display.getDefault();

while (!shell.isDisposed()) {

if (!display.readAndDispatch())

display.sleep();

}

}

}
Re: RoundedRectangle [message #92464 is a reply to message #92448] Thu, 04 September 2003 16:48 Go to previous messageGo to next message
Alex Selkov is currently offline Alex SelkovFriend
Messages: 73
Registered: July 2009
Member
"Alex Selkov" <as@empproject.com> wrote in message
news:bj7psm$g6d$1@eclipse.org...
> RoundedRectangle depicts incorrectly.

And one pixel smaller comparing with other draw2d figures...
Re: RoundedRectangle [message #92494 is a reply to message #92464] Thu, 04 September 2003 17:48 Go to previous messageGo to next message
Eric Bordeau is currently offline Eric BordeauFriend
Messages: 259
Registered: July 2009
Senior Member
We draw RoundRectangle the same way we draw RectangleFigure. It has to
do with the way SWT's GC draws draws rounded rectangles. There's a
thread on the SWT newsgroup (GC#drawRoundRectangle() Eclipse R3.0 !=
R2.1) discussing this problem. Here's an excerpt:

<quote>
The width and height of drawRoundRectangle() was changed in 3.0 to make
it consistent with other drawing operations and other platforms.

The width and height of the rounded rectangle should be the same as the
normal rectangle (drawn with drawRectangle()). The same should be true
with fillRoundRectangle() and fillRectangle().
</quote>


Alex Selkov wrote:
> "Alex Selkov" <as@empproject.com> wrote in message
> news:bj7psm$g6d$1@eclipse.org...
>
>>RoundedRectangle depicts incorrectly.
>
>
> And one pixel smaller comparing with other draw2d figures...
>
>
Re: RoundedRectangle [message #92509 is a reply to message #92448] Thu, 04 September 2003 18:03 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

Line width of 0 is a valid line width. Contrary to common sense, width of 0
is still visible, and it has slightly different behavior than line width of
1. There is a bug open on this:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=38073

Thanks for the suggestion,
-Randy

"Alex Selkov" <as@empproject.com> wrote in message
news:bj7psm$g6d$1@eclipse.org...
> RoundedRectangle depicts incorrectly.
>
> I also found useful if setLineWidth(0) has the same effect as
> setOutline(false). Is it possible to incorporate such behavior into the
> Shape?
>
>
> Index: Shape.java
> ============================================================ =======
> RCS file:
/home/tools/org.eclipse.draw2d/src/org/eclipse/draw2d/Shape. java,v
> retrieving revision 1.4
> diff -u -r1.4 Shape.java
> --- Shape.java 3 Jun 2003 19:05:55 -0000 1.4
> +++ Shape.java 4 Sep 2003 16:35:44 -0000
> @@ -25,6 +25,7 @@
> private boolean
> fill = true,
> outline = true,
> + suppressOutline = false,
> xorFill,
> xorOutline;
>
> @@ -89,7 +90,7 @@
> graphics.setXORMode(xorFill);
> fillShape(graphics);
> }
> - if (outline) {
> + if (outline && !suppressOutline) {
> graphics.setXORMode(xorOutline);
> graphics.setLineStyle(lineStyle);
> graphics.setLineWidth(lineWidth);
> @@ -103,7 +104,7 @@
> graphics.setXORMode(xorFill);
> fillShape(graphics);
> }
> - if (outline) {
> + if (outline && !suppressOutline) {
> graphics.setXORMode(xorOutline);
> graphics.setLineStyle(lineStyle);
> graphics.setLineWidth(lineWidth);
> @@ -147,6 +148,11 @@
> if (lineWidth == w)
> return;
> lineWidth = w;
> + if (lineWidth == 0) {
> + suppressOutline = true;
> + } else {
> + suppressOutline = false;
> + };
> repaint();
> }
>
>
> ------------------------------------------------------------ --------------
--
> ------------------------------------------------------------ -
> import org.eclipse.draw2d.ColorConstants;
>
> import org.eclipse.draw2d.Ellipse;
>
> import org.eclipse.draw2d.Figure;
>
> import org.eclipse.draw2d.IFigure;
>
> import org.eclipse.draw2d.Label;
>
> import org.eclipse.draw2d.LightweightSystem;
>
> import org.eclipse.draw2d.LineBorder;
>
> import org.eclipse.draw2d.Polyline;
>
> import org.eclipse.draw2d.RectangleFigure;
>
> import org.eclipse.draw2d.RoundedRectangle;
>
> import org.eclipse.draw2d.geometry.Dimension;
>
> import org.eclipse.draw2d.geometry.Point;
>
> import org.eclipse.swt.graphics.Color;
>
> import org.eclipse.swt.widgets.Display;
>
> import org.eclipse.swt.widgets.Shell;
>
> public class Demo4 {
>
> private static final int GAP = 20;
>
> private static final Dimension SIZE = new Dimension(75, 50);
>
> private static final Dimension CORNER = new Dimension(30, 25);
>
> private static final int COUNT = 20;
>
> public static void main(String args[]) {
>
> Shell shell = new Shell();
>
> shell.setSize(800, 750);
>
> shell.open();
>
> shell.setText("Figures");
>
> LightweightSystem lws = new LightweightSystem(shell);
>
> IFigure panel = new Figure();
>
> lws.setContents(panel);
>
> final Color BG_COLOR = ColorConstants.white;
>
> final Color PANEL_COLOR = ColorConstants.blue;
>
> final Color FG_COLOR = ColorConstants.red;
>
> final Color GRID_COLOR = ColorConstants.black;
>
> panel.setBackgroundColor(PANEL_COLOR);
>
> panel.setOpaque(true);
>
> for (int i = 0; i < COUNT; i++) {
>
> if (i % 2 == 0) {
>
> Polyline p = new Polyline();
>
> p.setForegroundColor(GRID_COLOR);
>
> p.setStart(
>
> new Point(0, GAP + (GAP + SIZE.height) * (i / 2) - 1));
>
> p.setEnd(
>
> new Point(
>
> GAP + 8 * (GAP + SIZE.width),
>
> GAP + (GAP + SIZE.height) * (i / 2) - 1));
>
> panel.add(p);
>
> p = new Polyline();
>
> p.setForegroundColor(GRID_COLOR);
>
> p.setStart(new Point(0, (GAP + SIZE.height) * (i / 2 + 1) - 1));
>
> p.setEnd(
>
> new Point(
>
> GAP + 8 * (GAP + SIZE.width),
>
> (GAP + SIZE.height) * (i / 2 + 1) - 1));
>
> panel.add(p);
>
> }
>
> RoundedRectangle rr = new RoundedRectangle();
>
> rr.setBackgroundColor(BG_COLOR);
>
> rr.setForegroundColor(FG_COLOR);
>
> rr.setCornerDimensions(CORNER);
>
> rr.setSize(SIZE);
>
> rr.setLineWidth(i);
>
> rr.setLocation(
>
> new Point(
>
> GAP + (i % 2) * (SIZE.width + GAP),
>
> GAP + (i / 2) * (SIZE.height + GAP)));
>
> panel.add(rr);
>
> RectangleFigure rf = new RectangleFigure();
>
> rf.setBackgroundColor(BG_COLOR);
>
> rf.setForegroundColor(FG_COLOR);
>
> rf.setSize(SIZE);
>
> rf.setLineWidth(i);
>
> rf.setLocation(
>
> new Point(
>
> GAP * 3 + SIZE.width * 2 + (i % 2) * (SIZE.width + GAP),
>
> GAP + (i / 2) * (SIZE.height + GAP)));
>
> panel.add(rf);
>
> Ellipse el = new Ellipse();
>
> el.setBackgroundColor(BG_COLOR);
>
> el.setForegroundColor(FG_COLOR);
>
> el.setSize(SIZE);
>
> el.setLineWidth(i);
>
> el.setLocation(
>
> new Point(
>
> GAP * 5 + SIZE.width * 4 + (i % 2) * (SIZE.width + GAP),
>
> GAP + (i / 2) * (SIZE.height + GAP)));
>
> panel.add(el);
>
> Label l = new Label("Label #" + i);
>
> l.setBackgroundColor(BG_COLOR);
>
> l.setForegroundColor(FG_COLOR);
>
> l.setOpaque(true);
>
> l.setSize(SIZE);
>
> if (i != 0)
>
> l.setBorder(new LineBorder(i));
>
> l.setLocation(
>
> new Point(
>
> GAP * 7 + SIZE.width * 6 + (i % 2) * (SIZE.width + GAP),
>
> GAP + (i / 2) * (SIZE.height + GAP)));
>
> panel.add(l);
>
> }
>
> Display display = Display.getDefault();
>
> while (!shell.isDisposed()) {
>
> if (!display.readAndDispatch())
>
> display.sleep();
>
> }
>
> }
>
> }
>
>
>
Re: RoundedRectangle [message #92625 is a reply to message #92494] Thu, 04 September 2003 20:00 Go to previous messageGo to next message
Alex Selkov is currently offline Alex SelkovFriend
Messages: 73
Registered: July 2009
Member
OK. I can see that minor problem with figure size solved in 3.0.

But what about problem with RoundedRectangle if LineWidth > 1? See picture
attached.

"Eric Bordeau" <ebordeau@us.ibm.com> wrote in message
news:bj7tsd$7e5$1@eclipse.org...
> We draw RoundRectangle the same way we draw RectangleFigure. It has to
> do with the way SWT's GC draws draws rounded rectangles. There's a
> thread on the SWT newsgroup (GC#drawRoundRectangle() Eclipse R3.0 !=
> R2.1) discussing this problem. Here's an excerpt:
>
> <quote>
> The width and height of drawRoundRectangle() was changed in 3.0 to make
> it consistent with other drawing operations and other platforms.
>
> The width and height of the rounded rectangle should be the same as the
> normal rectangle (drawn with drawRectangle()). The same should be true
> with fillRoundRectangle() and fillRectangle().
> </quote>
>
>
> Alex Selkov wrote:
> > "Alex Selkov" <as@empproject.com> wrote in message
> > news:bj7psm$g6d$1@eclipse.org...
> >
> >>RoundedRectangle depicts incorrectly.
> >
> >
> > And one pixel smaller comparing with other draw2d figures...
> >
> >
>


  • Attachment: image002.jpg
    (Size: 69.71KB, Downloaded 111 times)
Re: RoundedRectangle [message #92641 is a reply to message #92509] Thu, 04 September 2003 20:07 Go to previous message
Alex Selkov is currently offline Alex SelkovFriend
Messages: 73
Registered: July 2009
Member
If so, that means that draw2d renders figures with width 0 incorrectly (as
shown in example above - missing left and lower part of the rectangle
outline).

Actually, for my taste using width = 0 as optimisation hint (only at
specific platform) is misleading.

Regards,

as

"Randy Hudson" <none@us.ibm.com> wrote in message
news:bj7unh$lfm$1@eclipse.org...
> Line width of 0 is a valid line width. Contrary to common sense, width of
0
> is still visible, and it has slightly different behavior than line width
of
> 1. There is a bug open on this:
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=38073
>
> Thanks for the suggestion,
> -Randy
>
> "Alex Selkov" <as@empproject.com> wrote in message
> news:bj7psm$g6d$1@eclipse.org...
> > RoundedRectangle depicts incorrectly.
> >
> > I also found useful if setLineWidth(0) has the same effect as
> > setOutline(false). Is it possible to incorporate such behavior into the
> > Shape?
> >
> >
> > Index: Shape.java
> > ============================================================ =======
> > RCS file:
> /home/tools/org.eclipse.draw2d/src/org/eclipse/draw2d/Shape. java,v
> > retrieving revision 1.4
> > diff -u -r1.4 Shape.java
> > --- Shape.java 3 Jun 2003 19:05:55 -0000 1.4
> > +++ Shape.java 4 Sep 2003 16:35:44 -0000
> > @@ -25,6 +25,7 @@
> > private boolean
> > fill = true,
> > outline = true,
> > + suppressOutline = false,
> > xorFill,
> > xorOutline;
> >
> > @@ -89,7 +90,7 @@
> > graphics.setXORMode(xorFill);
> > fillShape(graphics);
> > }
> > - if (outline) {
> > + if (outline && !suppressOutline) {
> > graphics.setXORMode(xorOutline);
> > graphics.setLineStyle(lineStyle);
> > graphics.setLineWidth(lineWidth);
> > @@ -103,7 +104,7 @@
> > graphics.setXORMode(xorFill);
> > fillShape(graphics);
> > }
> > - if (outline) {
> > + if (outline && !suppressOutline) {
> > graphics.setXORMode(xorOutline);
> > graphics.setLineStyle(lineStyle);
> > graphics.setLineWidth(lineWidth);
> > @@ -147,6 +148,11 @@
> > if (lineWidth == w)
> > return;
> > lineWidth = w;
> > + if (lineWidth == 0) {
> > + suppressOutline = true;
> > + } else {
> > + suppressOutline = false;
> > + };
> > repaint();
> > }
> >
> >
>
> ------------------------------------------------------------ --------------
> --
> > ------------------------------------------------------------ -
> > import org.eclipse.draw2d.ColorConstants;
> >
> > import org.eclipse.draw2d.Ellipse;
> >
> > import org.eclipse.draw2d.Figure;
> >
> > import org.eclipse.draw2d.IFigure;
> >
> > import org.eclipse.draw2d.Label;
> >
> > import org.eclipse.draw2d.LightweightSystem;
> >
> > import org.eclipse.draw2d.LineBorder;
> >
> > import org.eclipse.draw2d.Polyline;
> >
> > import org.eclipse.draw2d.RectangleFigure;
> >
> > import org.eclipse.draw2d.RoundedRectangle;
> >
> > import org.eclipse.draw2d.geometry.Dimension;
> >
> > import org.eclipse.draw2d.geometry.Point;
> >
> > import org.eclipse.swt.graphics.Color;
> >
> > import org.eclipse.swt.widgets.Display;
> >
> > import org.eclipse.swt.widgets.Shell;
> >
> > public class Demo4 {
> >
> > private static final int GAP = 20;
> >
> > private static final Dimension SIZE = new Dimension(75, 50);
> >
> > private static final Dimension CORNER = new Dimension(30, 25);
> >
> > private static final int COUNT = 20;
> >
> > public static void main(String args[]) {
> >
> > Shell shell = new Shell();
> >
> > shell.setSize(800, 750);
> >
> > shell.open();
> >
> > shell.setText("Figures");
> >
> > LightweightSystem lws = new LightweightSystem(shell);
> >
> > IFigure panel = new Figure();
> >
> > lws.setContents(panel);
> >
> > final Color BG_COLOR = ColorConstants.white;
> >
> > final Color PANEL_COLOR = ColorConstants.blue;
> >
> > final Color FG_COLOR = ColorConstants.red;
> >
> > final Color GRID_COLOR = ColorConstants.black;
> >
> > panel.setBackgroundColor(PANEL_COLOR);
> >
> > panel.setOpaque(true);
> >
> > for (int i = 0; i < COUNT; i++) {
> >
> > if (i % 2 == 0) {
> >
> > Polyline p = new Polyline();
> >
> > p.setForegroundColor(GRID_COLOR);
> >
> > p.setStart(
> >
> > new Point(0, GAP + (GAP + SIZE.height) * (i / 2) - 1));
> >
> > p.setEnd(
> >
> > new Point(
> >
> > GAP + 8 * (GAP + SIZE.width),
> >
> > GAP + (GAP + SIZE.height) * (i / 2) - 1));
> >
> > panel.add(p);
> >
> > p = new Polyline();
> >
> > p.setForegroundColor(GRID_COLOR);
> >
> > p.setStart(new Point(0, (GAP + SIZE.height) * (i / 2 + 1) - 1));
> >
> > p.setEnd(
> >
> > new Point(
> >
> > GAP + 8 * (GAP + SIZE.width),
> >
> > (GAP + SIZE.height) * (i / 2 + 1) - 1));
> >
> > panel.add(p);
> >
> > }
> >
> > RoundedRectangle rr = new RoundedRectangle();
> >
> > rr.setBackgroundColor(BG_COLOR);
> >
> > rr.setForegroundColor(FG_COLOR);
> >
> > rr.setCornerDimensions(CORNER);
> >
> > rr.setSize(SIZE);
> >
> > rr.setLineWidth(i);
> >
> > rr.setLocation(
> >
> > new Point(
> >
> > GAP + (i % 2) * (SIZE.width + GAP),
> >
> > GAP + (i / 2) * (SIZE.height + GAP)));
> >
> > panel.add(rr);
> >
> > RectangleFigure rf = new RectangleFigure();
> >
> > rf.setBackgroundColor(BG_COLOR);
> >
> > rf.setForegroundColor(FG_COLOR);
> >
> > rf.setSize(SIZE);
> >
> > rf.setLineWidth(i);
> >
> > rf.setLocation(
> >
> > new Point(
> >
> > GAP * 3 + SIZE.width * 2 + (i % 2) * (SIZE.width + GAP),
> >
> > GAP + (i / 2) * (SIZE.height + GAP)));
> >
> > panel.add(rf);
> >
> > Ellipse el = new Ellipse();
> >
> > el.setBackgroundColor(BG_COLOR);
> >
> > el.setForegroundColor(FG_COLOR);
> >
> > el.setSize(SIZE);
> >
> > el.setLineWidth(i);
> >
> > el.setLocation(
> >
> > new Point(
> >
> > GAP * 5 + SIZE.width * 4 + (i % 2) * (SIZE.width + GAP),
> >
> > GAP + (i / 2) * (SIZE.height + GAP)));
> >
> > panel.add(el);
> >
> > Label l = new Label("Label #" + i);
> >
> > l.setBackgroundColor(BG_COLOR);
> >
> > l.setForegroundColor(FG_COLOR);
> >
> > l.setOpaque(true);
> >
> > l.setSize(SIZE);
> >
> > if (i != 0)
> >
> > l.setBorder(new LineBorder(i));
> >
> > l.setLocation(
> >
> > new Point(
> >
> > GAP * 7 + SIZE.width * 6 + (i % 2) * (SIZE.width + GAP),
> >
> > GAP + (i / 2) * (SIZE.height + GAP)));
> >
> > panel.add(l);
> >
> > }
> >
> > Display display = Display.getDefault();
> >
> > while (!shell.isDisposed()) {
> >
> > if (!display.readAndDispatch())
> >
> > display.sleep();
> >
> > }
> >
> > }
> >
> > }
> >
> >
> >
>
>
Previous Topic:How can I stretch my contents figure to a preferred size?
Next Topic:Re: Problems with v4all_2.1.0
Goto Forum:
  


Current Time: Thu Apr 25 03:33:03 GMT 2024

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

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

Back to the top