Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 102429 Details for
Bug 234417
FigureCanvas always mixes in styles which aren't necessarily needed
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Patch to FigureCanvas and new draw2d example
patch.txt (text/plain), 8.06 KB, created by
Randy Hudson
on 2008-05-28 12:36:48 EDT
(
hide
)
Description:
Patch to FigureCanvas and new draw2d example
Filename:
MIME Type:
Creator:
Randy Hudson
Created:
2008-05-28 12:36:48 EDT
Size:
8.06 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.draw2d.examples >Index: src/org/eclipse/draw2d/examples/swt/InheritBackgroundExample.java >=================================================================== >RCS file: src/org/eclipse/draw2d/examples/swt/InheritBackgroundExample.java >diff -N src/org/eclipse/draw2d/examples/swt/InheritBackgroundExample.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/draw2d/examples/swt/InheritBackgroundExample.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,80 @@ >+package org.eclipse.draw2d.examples.swt; >+ >+import org.eclipse.draw2d.ColorConstants; >+import org.eclipse.draw2d.FigureCanvas; >+import org.eclipse.draw2d.Label; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.graphics.GC; >+import org.eclipse.swt.graphics.Image; >+import org.eclipse.swt.layout.FillLayout; >+import org.eclipse.swt.layout.GridData; >+import org.eclipse.swt.layout.GridLayout; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Display; >+import org.eclipse.swt.widgets.Group; >+import org.eclipse.swt.widgets.Shell; >+ >+public class InheritBackgroundExample { >+ >+ static Shell shell; >+ static Image bg; >+ >+ static { >+ bg = new Image(null, 10, 800); >+ GC gc = new GC(bg); >+ gc.setForeground(ColorConstants.white); >+ gc.setBackground(ColorConstants.lightGreen); >+ gc.fillGradientRectangle(0, 0, 300, 400, true); >+ gc.setForeground(ColorConstants.lightGreen); >+ gc.setBackground(ColorConstants.white); >+ gc.fillGradientRectangle(0, 400, 300, 400, true); >+ gc.dispose(); >+ } >+ >+ public static void main(String[] args) { >+ Display d = Display.getDefault(); >+ shell = new Shell(d, SWT.SHELL_TRIM); >+ shell.setText("Figure Canvas inheriting background from parent Composite"); >+ shell.setLayout(new GridLayout(2, false)); >+ shell.setBackgroundImage(bg); >+ shell.setBackgroundMode(SWT.INHERIT_FORCE); >+ >+ FigureCanvas canvas; >+ >+ canvas = createCanvas(shell, >+ SWT.DOUBLE_BUFFERED | SWT.BORDER | SWT.NO_REDRAW_RESIZE | SWT.V_SCROLL | SWT.H_SCROLL, >+ "Paints Background"); >+ canvas.setBackground(ColorConstants.orange); >+ >+ canvas = createCanvas(shell, >+ SWT.DOUBLE_BUFFERED | SWT.BORDER | SWT.NO_REDRAW_RESIZE | SWT.V_SCROLL | SWT.H_SCROLL, >+ "Inherits Background"); >+ canvas.getLightweightSystem().getRootFigure().setOpaque(false); >+ >+ shell.pack(); >+ shell.open(); >+ while (!shell.isDisposed()) >+ while (!d.readAndDispatch()) >+ d.sleep(); >+ } >+ >+ private static FigureCanvas createCanvas(Composite parent, int style, String text) { >+ Group group = new Group(parent, SWT.NONE); >+ group.setLayoutData(new GridData(GridData.FILL_BOTH)); >+ group.setText(text); >+ parent = group; >+ group.setLayout(new FillLayout()); >+ >+ FigureCanvas canvas = new FigureCanvas(style, parent); >+ canvas.setContents(new Label( >+ "This is a figure canvas\n" + >+ "with a label. The background\n" + >+ "is either painted by the root\n" + >+ "figure, or by the operating system.\n" + >+ "Note that vertical scrolling may not be\n" + >+ "as fast when the background from the\n" + >+ "parent is inherited.")); >+ return canvas; >+ } >+ >+} >#P org.eclipse.draw2d >Index: src/org/eclipse/draw2d/FigureCanvas.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.gef/plugins/org.eclipse.draw2d/src/org/eclipse/draw2d/FigureCanvas.java,v >retrieving revision 1.39 >diff -u -r1.39 FigureCanvas.java >--- src/org/eclipse/draw2d/FigureCanvas.java 11 Jan 2008 22:19:10 -0000 1.39 >+++ src/org/eclipse/draw2d/FigureCanvas.java 28 May 2008 16:36:20 -0000 >@@ -28,6 +28,12 @@ > /** > * A Canvas that contains {@link Figure Figures}. > * >+ * <dl> >+ * <dt><b>Required Styles (when using certain constructors):</b></dt> >+ * <dd>V_SCROLL, H_SCROLL, NO_REDRAW_RESIZE</dd> >+ * <dt><b>Optional Styles:</b></dt> >+ * <dd>DOUBLE_BUFFERED, RIGHT_TO_LEFT, LEFT_TO_RIGHT, NO_BACKGROUND, BORDER</dd> >+ * </dl> > * <p> > * Note: Only one of the styles RIGHT_TO_LEFT, LEFT_TO_RIGHT may be specified. > * </p> >@@ -36,6 +42,35 @@ > extends Canvas > { > >+private static final int ACCEPTED_STYLES = >+ SWT.RIGHT_TO_LEFT | SWT.LEFT_TO_RIGHT >+ | SWT.V_SCROLL | SWT.H_SCROLL >+ | SWT.NO_BACKGROUND >+ | SWT.NO_REDRAW_RESIZE >+ | SWT.DOUBLE_BUFFERED >+ | SWT.BORDER; >+ >+/** >+ * The default styles are mixed in when certain constructors are used. This >+ * constant is a bitwise OR of the following SWT style constants: >+ * <UL> >+ * <LI>{@link SWT#NO_REDRAW_RESIZE}</LI> >+ * <LI>{@link SWT#NO_BACKGROUND}</LI> >+ * <LI>{@link SWT#V_SCROLL}</LI> >+ * <LI>{@link SWT#H_SCROLL}</LI> >+ * </UL> >+ */ >+static final int DEFAULT_STYLES = >+ SWT.NO_REDRAW_RESIZE >+ | SWT.NO_BACKGROUND >+ | SWT.V_SCROLL >+ | SWT.H_SCROLL; >+ >+private static final int REQUIRED_STYLES = >+ SWT.NO_REDRAW_RESIZE >+ | SWT.V_SCROLL >+ | SWT.H_SCROLL; >+ > /** Never show scrollbar */ > public static int NEVER = 0; > /** Automatically show scrollbar when needed */ >@@ -81,7 +116,7 @@ > private final LightweightSystem lws; > > /** >- * Creates a new FigureCanvas with the given parent. >+ * Creates a new FigureCanvas with the given parent and the {@link #DEFAULT_STYLES}. > * > * @param parent the parent > */ >@@ -90,9 +125,9 @@ > } > > /** >- * Constructor >+ * Constructor which applies the default styles plus any optional styles indicated. > * @param parent the parent composite >- * @param style look at class javadoc for valid styles >+ * @param style see the class javadoc for optional styles > * @since 3.1 > */ > public FigureCanvas(Composite parent, int style) { >@@ -100,7 +135,19 @@ > } > > /** >- * Constructs a new FigureCanvas with the given parent and LightweightSystem. >+ * Constructor which uses the given styles verbatim. Certain styles must be used >+ * with this class. Refer to the class javadoc for more details. >+ * @param style see the class javadoc for <b>required</b> and optional styles >+ * @param parent the parent composite >+ * @since 3.4 >+ */ >+public FigureCanvas(int style, Composite parent) { >+ this(style, parent, new LightweightSystem()); >+} >+ >+/** >+ * Constructs a new FigureCanvas with the given parent and LightweightSystem, using >+ * the {@link #DEFAULT_STYLES}. > * @param parent the parent > * @param lws the LightweightSystem > */ >@@ -109,15 +156,16 @@ > } > > /** >- * Constructor >+ * Constructor taking a lightweight system and SWT style, which is used verbatim. >+ * Certain styles must be used with this class. Refer to the class javadoc for >+ * more details. >+ * @param style see the class javadoc for <b>required</b> and optional styles > * @param parent the parent composite >- * @param style look at class javadoc for valid styles >- * @param lws the lightweight system >- * @since 3.1 >+ * @param lws the LightweightSystem >+ * @since 3.4 > */ >-public FigureCanvas(Composite parent, int style, LightweightSystem lws) { >- super(parent, checkStyle(style | SWT.NO_REDRAW_RESIZE | SWT.NO_BACKGROUND >- | SWT.V_SCROLL | SWT.H_SCROLL)); >+public FigureCanvas(int style, Composite parent, LightweightSystem lws) { >+ super(parent, checkStyle(style)); > getHorizontalBar().setVisible(false); > getVerticalBar().setVisible(false); > this.lws = lws; >@@ -125,10 +173,21 @@ > hook(); > } > >+/** >+ * Constructor >+ * @param parent the parent composite >+ * @param style look at class javadoc for valid styles >+ * @param lws the lightweight system >+ * @since 3.1 >+ */ >+public FigureCanvas(Composite parent, int style, LightweightSystem lws) { >+ this(style | DEFAULT_STYLES, parent, lws); >+} >+ > private static int checkStyle(int style) { >- int validStyles = SWT.RIGHT_TO_LEFT | SWT.LEFT_TO_RIGHT | SWT.V_SCROLL | SWT.H_SCROLL >- | SWT.NO_BACKGROUND | SWT.NO_REDRAW_RESIZE | SWT.DOUBLE_BUFFERED | SWT.BORDER; >- if ((style & ~validStyles) != 0) >+ if ((style & REQUIRED_STYLES) != REQUIRED_STYLES) >+ throw new IllegalArgumentException("Required style missing on FigureCanvas"); //$NON-NLS-1$ >+ if ((style & ~ACCEPTED_STYLES) != 0) > throw new IllegalArgumentException("Invalid style being set on FigureCanvas"); //$NON-NLS-1$ > return style; > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 234417
: 102429