Home » Eclipse Projects » GEF » RoundedRectangle
RoundedRectangle [message #92448] |
Thu, 04 September 2003 16:40 |
Alex Selkov 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 #92509 is a reply to message #92448] |
Thu, 04 September 2003 18:03 |
Eclipse User |
|
|
|
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 #92641 is a reply to message #92509] |
Thu, 04 September 2003 20:07 |
Alex Selkov 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();
> >
> > }
> >
> > }
> >
> > }
> >
> >
> >
>
>
|
|
|
Goto Forum:
Current Time: Tue Sep 24 15:17:19 GMT 2024
Powered by FUDForum. Page generated in 0.05507 seconds
|