diff options
author | Jeff Brown | 2001-06-22 05:00:24 +0000 |
---|---|---|
committer | Jeff Brown | 2001-06-22 05:00:24 +0000 |
commit | 15f1eee3a8ec2620bed875ba9786fc1d8ffa28db (patch) | |
tree | 94f6080ff24a0c775f5434d138253dd5aa92c95c /examples | |
parent | 4dfad5a97535c7282afa88210ebbd2164a5fb922 (diff) | |
download | eclipse.platform.swt-15f1eee3a8ec2620bed875ba9786fc1d8ffa28db.tar.gz eclipse.platform.swt-15f1eee3a8ec2620bed875ba9786fc1d8ffa28db.tar.xz eclipse.platform.swt-15f1eee3a8ec2620bed875ba9786fc1d8ffa28db.zip |
*** empty log message ***
Diffstat (limited to 'examples')
57 files changed, 744 insertions, 745 deletions
diff --git a/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/AirbrushTool.java b/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/AirbrushTool.java index 3480f3a3b2..8eeabb9920 100755 --- a/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/AirbrushTool.java +++ b/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/AirbrushTool.java @@ -11,11 +11,10 @@ import java.util.Random;
import org.eclipse.swt.graphics.*; * An airbrush tool.
*/
public class AirbrushTool extends ContinuousPaintSession implements PaintTool {
+ private ToolSettings settings;
private Random random;
- private int airbrushRadius;
private int cachedRadiusSquared;
private int cachedNumPoints;
- private Color airbrushColor;
/**
* Constructs a Tool.
@@ -26,8 +25,8 @@ public class AirbrushTool extends ContinuousPaintSession implements PaintTool { public AirbrushTool(ToolSettings toolSettings, PaintSurface paintSurface) {
super(paintSurface);
random = new Random();
- set(toolSettings);
setRetriggerTimer(10);
+ set(toolSettings);
}
/**
@@ -36,13 +35,11 @@ public class AirbrushTool extends ContinuousPaintSession implements PaintTool { * @param toolSettings the new tool settings
*/
public void set(ToolSettings toolSettings) {
- airbrushRadius = toolSettings.airbrushRadius;
- airbrushColor = toolSettings.commonForegroundColor;
-
// compute things we need to know for drawing
- cachedRadiusSquared = toolSettings.airbrushRadius * toolSettings.airbrushRadius;
- cachedNumPoints = 314 * toolSettings.airbrushIntensity * cachedRadiusSquared / 250000;
- if (cachedNumPoints == 0 && toolSettings.airbrushIntensity != 0)
+ settings = toolSettings;
+ cachedRadiusSquared = settings.airbrushRadius * settings.airbrushRadius;
+ cachedNumPoints = 314 * settings.airbrushIntensity * cachedRadiusSquared / 250000;
+ if (cachedNumPoints == 0 && settings.airbrushIntensity != 0)
cachedNumPoints = 1;
}
@@ -60,22 +57,16 @@ public class AirbrushTool extends ContinuousPaintSession implements PaintTool { */
protected void render(Point point) {
// Draws a bunch (cachedNumPoints) of random pixels within a specified circle (cachedRadiusSquared).
- final PaintSurface ps = getPaintSurface();
- final GC igc = ps.getImageGC();
- final Point ioff = ps.getImageOffset();
- final int x = point.x + ioff.x, y = point.y + ioff.y;
-
- igc.setBackground(airbrushColor);
+ ContainerFigure cfig = new ContainerFigure();
+
for (int i = 0; i < cachedNumPoints; ++i) {
int randX, randY;
do {
- randX = (int) ((random.nextDouble() - 0.5) * airbrushRadius * 2.0);
- randY = (int) ((random.nextDouble() - 0.5) * airbrushRadius * 2.0);
+ randX = (int) ((random.nextDouble() - 0.5) * settings.airbrushRadius * 2.0);
+ randY = (int) ((random.nextDouble() - 0.5) * settings.airbrushRadius * 2.0);
} while (randX * randX + randY * randY > cachedRadiusSquared);
-
- igc.fillRectangle(x + randX, y + randY, 1, 1);
+ cfig.add(new PointFigure(settings.commonForegroundColor, point.x + randX, point.y + randY));
}
- ps.redrawArea(point.x - airbrushRadius, point.y - airbrushRadius,
- airbrushRadius * 2, airbrushRadius * 2);
+ getPaintSurface().drawFigure(cfig);
}
}
diff --git a/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/ContainerFigure.java b/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/ContainerFigure.java index ac36901c7c..0c2d64996a 100755 --- a/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/ContainerFigure.java +++ b/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/ContainerFigure.java @@ -38,6 +38,13 @@ public class ContainerFigure extends Figure { ++nextIndex;
}
/**
+ * Determines if the container is empty.
+ * @return true if the container is empty
+ */
+ public boolean isEmpty() {
+ return nextIndex == 0;
+ }
+ /**
* Adds an object to the container and draws its preview then updates the supplied preview state.
*
* @param object the object to add to the drawing list
@@ -47,19 +54,19 @@ public class ContainerFigure extends Figure { * using this Container, may be null if there was no such previous call
* @return object state that must be passed to erasePreview() later to erase this object
*/
- public Object addAndPreview(Figure object, GC gc, Point offset, Object rememberedState) {
- Object[] stateStack = (Object[]) rememberedState;
- if (stateStack == null) {
- stateStack = new Object[INITIAL_ARRAY_SIZE];
- } else if (stateStack.length <= nextIndex) {
- Object[] newStateStack = new Object[stateStack.length * 2];
- System.arraycopy(stateStack, 0, newStateStack, 0, stateStack.length);
- stateStack = newStateStack;
- }
- add(object);
- stateStack[nextIndex - 1] = object.drawPreview(gc, offset);
- return stateStack;
- }
+// public Object addAndPreview(Figure object, GC gc, Point offset, Object rememberedState) {
+// Object[] stateStack = (Object[]) rememberedState;
+// if (stateStack == null) {
+// stateStack = new Object[INITIAL_ARRAY_SIZE];
+// } else if (stateStack.length <= nextIndex) {
+// Object[] newStateStack = new Object[stateStack.length * 2];
+// System.arraycopy(stateStack, 0, newStateStack, 0, stateStack.length);
+// stateStack = newStateStack;
+// }
+// add(object);
+// stateStack[nextIndex - 1] = object.drawPreview(gc, offset);
+// return stateStack;
+// }
/**
* Clears the container.
* <p>
@@ -71,24 +78,10 @@ public class ContainerFigure extends Figure { while (--nextIndex > 0) objectStack[nextIndex] = null;
nextIndex = 0;
}
- public void draw(GC gc, Point offset) {
- for (int i = 0; i < nextIndex; ++i) objectStack[i].draw(gc, offset);
+ public void draw(FigureDrawContext fdc) {
+ for (int i = 0; i < nextIndex; ++i) objectStack[i].draw(fdc);
}
- public Object drawPreview(GC gc, Point offset) {
- if (nextIndex == 0) return null;
-
- Object[] stateStack = new Object[nextIndex];
- for (int i = 0; i < nextIndex; ++i) stateStack[i] = objectStack[i].drawPreview(gc, offset);
- return stateStack;
+ public void addDamagedRegion(FigureDrawContext fdc, Region region) {
+ for (int i = 0; i < nextIndex; ++i) objectStack[i].addDamagedRegion(fdc, region);
}
- public void erasePreview(GC gc, Point offset, Object rememberedState) {
- if (rememberedState == null) return;
-
- final Object[] stateStack = (Object[]) rememberedState;
- int i = nextIndex;
- while (--i >= 0) {
- objectStack[i].erasePreview(gc, offset, stateStack[i]);
- stateStack[i] = null;
- }
- }
}
diff --git a/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/ContinuousPaintSession.java b/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/ContinuousPaintSession.java index 428dd2e981..abbe320b64 100755 --- a/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/ContinuousPaintSession.java +++ b/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/ContinuousPaintSession.java @@ -57,8 +57,8 @@ public abstract class ContinuousPaintSession extends BasicPaintSession { * Activates the tool.
*/
public void beginSession() {
- getPaintSurface().getPaintStatus().
- setMessage(PaintPlugin.getResourceString("session.ContinuousPaint.message"));
+ getPaintSurface().
+ setStatusMessage(PaintPlugin.getResourceString("session.ContinuousPaint.message"));
dragInProgress = false;
}
@@ -119,7 +119,8 @@ public abstract class ContinuousPaintSession extends BasicPaintSession { * @param event the mouse event detail information
*/
public final void mouseMove(MouseEvent event) {
- getPaintSurface().showCurrentPositionStatus();
+ final PaintSurface ps = getPaintSurface();
+ ps.setStatusCoord(ps.getCurrentPosition());
if (! dragInProgress) return;
mouseSegmentFinished(event);
prepareRetrigger();
diff --git a/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/DragPaintSession.java b/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/DragPaintSession.java index 2f89450de0..78b9fe6bd7 100755 --- a/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/DragPaintSession.java +++ b/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/DragPaintSession.java @@ -40,8 +40,8 @@ public abstract class DragPaintSession extends BasicPaintSession { * Activates the tool.
*/
public void beginSession() {
- getPaintSurface().getPaintStatus().
- setMessage(PaintPlugin.getResourceString("session.DragInteractivePaint.message"));
+ getPaintSurface().
+ setStatusMessage(PaintPlugin.getResourceString("session.DragInteractivePaint.message"));
anchorPosition.x = -1;
dragInProgress = false;
}
@@ -109,10 +109,10 @@ public abstract class DragPaintSession extends BasicPaintSession { public void mouseMove(MouseEvent event) {
final PaintSurface ps = getPaintSurface();
if (! dragInProgress) {
- ps.showCurrentPositionStatus();
+ ps.setStatusCoord(ps.getCurrentPosition());
return;
}
- ps.showCurrentRangeStatus(anchorPosition);
+ ps.setStatusCoordRange(anchorPosition, ps.getCurrentPosition());
ps.clearRubberbandSelection();
tempPosition.x = event.x;
tempPosition.y = event.y;
diff --git a/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/EllipseFigure.java b/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/EllipseFigure.java index 7bcb7c4021..a28105e9fb 100755 --- a/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/EllipseFigure.java +++ b/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/EllipseFigure.java @@ -5,34 +5,39 @@ package org.eclipse.swt.examples.paint; * All Rights Reserved
*/
+import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
/**
* 2D Ellipse object
*/
-public class EllipseFigure extends StatelessXORFigureHelper {
+public class EllipseFigure extends Figure {
private Color color;
- private int x1, y1, x2, y2;
+ private int lineStyle, x1, y1, x2, y2;
/**
* Constructs an Ellipse
* These objects are defined by any two diametrically opposing corners of a box
* bounding the ellipse.
*
* @param color the color for this object
+ * @param lineStyle the line style for this object
* @param x1 the virtual X coordinate of the first corner
* @param y1 the virtual Y coordinate of the first corner
* @param x2 the virtual X coordinate of the second corner
* @param y2 the virtual Y coordinate of the second corner
*/
- public EllipseFigure(Color color, int x1, int y1, int x2, int y2) {
- this.color = color; this.x1 = x1; this.y1 = y1; this.x2 = x2; this.y2 = y2;
+ public EllipseFigure(Color color, int lineStyle, int x1, int y1, int x2, int y2) {
+ this.color = color; this.lineStyle = lineStyle;
+ this.x1 = x1; this.y1 = y1; this.x2 = x2; this.y2 = y2;
}
- public void draw(GC gc, Point offset) {
- gc.setForeground(color);
- gcDraw(gc, offset);
+ public void draw(FigureDrawContext fdc) {
+ Rectangle r = fdc.toClientRectangle(x1, y1, x2, y2);
+ fdc.gc.setForeground(color);
+ fdc.gc.setLineStyle(lineStyle);
+ fdc.gc.drawOval(r.x, r.y, r.width - 1, r.height - 1);
+ fdc.gc.setLineStyle(SWT.LINE_SOLID);
+ }
+ public void addDamagedRegion(FigureDrawContext fdc, Region region) {
+ region.add(fdc.toClientRectangle(x1, y1, x2, y2));
}
- protected void gcDraw(GC gc, Point offset) {
- gc.drawOval(Math.min(x1, x2) + offset.x, Math.min(y1, y2) + offset.y,
- Math.abs(x2 - x1), Math.abs(y2 - y1));
- }
}
diff --git a/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/EllipseTool.java b/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/EllipseTool.java index ab41a10713..cfd26997d6 100755 --- a/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/EllipseTool.java +++ b/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/EllipseTool.java @@ -11,9 +11,7 @@ import org.eclipse.swt.graphics.*; * A drawing tool.
*/
public class EllipseTool extends DragPaintSession implements PaintTool {
- private Color drawFGColor;
- private Color drawBGColor;
- private int fillType;
+ private ToolSettings settings;
/**
* Constructs a EllipseTool.
@@ -25,18 +23,16 @@ public class EllipseTool extends DragPaintSession implements PaintTool { super(paintSurface);
set(toolSettings);
}
-
+
/**
* Sets the tool's settings.
*
* @param toolSettings the new tool settings
*/
public void set(ToolSettings toolSettings) {
- drawFGColor = toolSettings.commonForegroundColor;
- drawBGColor = toolSettings.commonBackgroundColor;
- fillType = toolSettings.commonFillType;
+ settings = toolSettings;
}
-
+
/**
* Returns name associated with this tool.
*
@@ -51,10 +47,11 @@ public class EllipseTool extends DragPaintSession implements PaintTool { */
protected Figure createFigure(Point a, Point b) {
ContainerFigure container = new ContainerFigure();
- if (fillType != ToolSettings.ftNone)
- container.add(new SolidEllipseFigure(drawBGColor, a.x, a.y, b.x, b.y));
- if (fillType != ToolSettings.ftSolid)
- container.add(new EllipseFigure(drawFGColor, a.x, a.y, b.x, b.y));
+ if (settings.commonFillType != ToolSettings.ftNone)
+ container.add(new SolidEllipseFigure(settings.commonBackgroundColor, a.x, a.y, b.x, b.y));
+ if (settings.commonFillType != ToolSettings.ftSolid)
+ container.add(new EllipseFigure(settings.commonForegroundColor, settings.commonLineStyle,
+ a.x, a.y, b.x, b.y));
return container;
}
}
diff --git a/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/Figure.java b/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/Figure.java index e5d97a2e93..9a57aa5aa8 100755 --- a/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/Figure.java +++ b/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/Figure.java @@ -15,49 +15,18 @@ import org.eclipse.swt.graphics.*; */
public abstract class Figure {
/**
- * Draws an object to the specified GC
- * <p>
- * The GC must be set up as follows (and must be returned to this state before returning)
- * <ul>
- * <li>setXORMode(false)
- * </ul>
- * </p>
+ * Draws this object.
*
- * @param gc the GC to draw on
- * @param offset the offset to add to virtual coordinates to get display coordinates
+ * @param fdc a parameter block specifying drawing-related information
*/
- public abstract void draw(GC gc, Point offset);
+ public abstract void draw(FigureDrawContext fdc);
/**
- * Draws a preview copy of the object to the specified GC
- * <p>
- * The GC must be set up as follows (and must be returned to this state before returning)
- * <ul>
- * <li>setXORMode(true)
- * <li>setForeground(new Color(display, 255, 255, 255))
- * <li>setBackground(new Color(display, 127, 127, 127))
- * </ul>
- * </p>
+ * Computes the damaged screen region caused by drawing this object (imprecise), then
+ * appends it to the supplied region.
*
- * @param gc the GC to draw on
- * @param offset the offset to add to virtual coordinates to get display coordinates
- * @return object state that must be passed to erasePreview() later to erase this object
+ * @param fdc a parameter block specifying drawing-related information
+ * @param region a region to which additional damage areas will be added
*/
- public abstract Object drawPreview(GC gc, Point offset);
-
- /**
- * Erases a preview copy of the object to the specified GC
- * <p>
- * Note that erasures are guaranteed to occur in the reverse order to the original drawing
- * order and that the GC's contents will be as they were when the drawPreview() that supplied
- * <code>rememberedState</code>returned.
- * </p><p>
- * The GC must be set up and restored as with drawPreview().
- * </p>
- *
- * @param gc the GC to draw on
- * @param offset the offset to add to virtual coordinates to get display coordinates
- * @param rememberedState the state returned by a previous drawPreview() using this instance
- */
- public abstract void erasePreview(GC gc, Point offset, Object rememberedState);
+ public abstract void addDamagedRegion(FigureDrawContext fdc, Region region);
}
diff --git a/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/FigureDrawContext.java b/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/FigureDrawContext.java new file mode 100644 index 0000000000..eda60d25b8 --- /dev/null +++ b/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/FigureDrawContext.java @@ -0,0 +1,34 @@ +package org.eclipse.swt.examples.paint;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import org.eclipse.swt.graphics.*;
+
+public class FigureDrawContext {
+ /*
+ * <p>
+ * The GC must be set up as follows
+ * (it will be returned to this state upon completion of drawing operations)
+ * <ul>
+ * <li>setXORMode(false)
+ * </ul>
+ * </p>
+ */
+ public GC gc = null;
+ public int xOffset = 0, yOffset = 0; // substract to get GC coords
+ public int xScale = 1, yScale = 1;
+
+ public Rectangle toClientRectangle(int x1, int y1, int x2, int y2) {
+ return new Rectangle(
+ Math.min(x1, x2) * xScale - xOffset,
+ Math.min(y1, y2) * yScale - yOffset,
+ (Math.abs(x2 - x1) + 1) * xScale,
+ (Math.abs(y2 - y1) + 1) * yScale);
+ }
+ public Point toClientPoint(int x, int y) {
+ return new Point(x * xScale - xOffset, y * yScale - yOffset);
+ }
+}
diff --git a/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/LineFigure.java b/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/LineFigure.java index bce1421a0b..221f4eefc7 100755 --- a/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/LineFigure.java +++ b/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/LineFigure.java @@ -5,32 +5,39 @@ package org.eclipse.swt.examples.paint; * All Rights Reserved
*/
+import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
/**
* 2D Line object
*/
-public class LineFigure extends StatelessXORFigureHelper {
+public class LineFigure extends Figure {
private Color color;
- private int x1, y1, x2, y2;
+ private int lineStyle, x1, y1, x2, y2;
/**
* Constructs a Line
* These objects are defined by their two end-points.
*
* @param color the color for this object
+ * @param lineStyle the line style for this object
* @param x1 the virtual X coordinate of the first end-point
* @param y1 the virtual Y coordinate of the first end-point
* @param x2 the virtual X coordinate of the second end-point
* @param y2 the virtual Y coordinate of the second end-point
*/
- public LineFigure(Color color, int x1, int y1, int x2, int y2) {
- this.color = color; this.x1 = x1; this.y1 = y1; this.x2 = x2; this.y2 = y2;
+ public LineFigure(Color color, int lineStyle, int x1, int y1, int x2, int y2) {
+ this.color = color; this.lineStyle = lineStyle;
+ this.x1 = x1; this.y1 = y1; this.x2 = x2; this.y2 = y2;
}
- public void draw(GC gc, Point offset) {
- gc.setForeground(color);
- gcDraw(gc, offset);
+ public void draw(FigureDrawContext fdc) {
+ Point p1 = fdc.toClientPoint(x1, y1);
+ Point p2 = fdc.toClientPoint(x2, y2);
+ fdc.gc.setForeground(color);
+ fdc.gc.setLineStyle(lineStyle);
+ fdc.gc.drawLine(p1.x, p1.y, p2.x, p2.y);
+ fdc.gc.setLineStyle(SWT.LINE_SOLID);
+ }
+ public void addDamagedRegion(FigureDrawContext fdc, Region region) {
+ region.add(fdc.toClientRectangle(x1, y1, x2, y2));
}
- protected void gcDraw(GC gc, Point offset) {
- gc.drawLine(x1 + offset.x, y1 + offset.y, x2 + offset.x, y2 + offset.y);
- }
}
diff --git a/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/LineTool.java b/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/LineTool.java index 895155db45..ab9e9e598c 100755 --- a/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/LineTool.java +++ b/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/LineTool.java @@ -11,8 +11,7 @@ import org.eclipse.swt.graphics.*; * A line drawing tool
*/
public class LineTool extends DragPaintSession implements PaintTool {
- private Color temporaryColor;
- private Color drawColor;
+ private ToolSettings settings;
/**
* Constructs a LineTool.
@@ -23,7 +22,6 @@ public class LineTool extends DragPaintSession implements PaintTool { public LineTool(ToolSettings toolSettings, PaintSurface paintSurface) {
super(paintSurface);
set(toolSettings);
- temporaryColor = new Color(null, 255, 255, 255);
}
/**
@@ -32,7 +30,7 @@ public class LineTool extends DragPaintSession implements PaintTool { * @param toolSettings the new tool settings
*/
public void set(ToolSettings toolSettings) {
- drawColor = toolSettings.commonForegroundColor;
+ settings = toolSettings;
}
/**
@@ -48,6 +46,7 @@ public class LineTool extends DragPaintSession implements PaintTool { * Template methods for drawing
*/
protected Figure createFigure(Point a, Point b) {
- return new LineFigure(drawColor, a.x, a.y, b.x, b.y);
+ return new LineFigure(settings.commonForegroundColor, settings.commonLineStyle,
+ a.x, a.y, b.x, b.y);
}
}
diff --git a/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/PaintStatus.java b/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/PaintStatus.java deleted file mode 100755 index 32a07bcb1f..0000000000 --- a/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/PaintStatus.java +++ /dev/null @@ -1,91 +0,0 @@ -package org.eclipse.swt.examples.paint;
/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved
*/
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Text;
-
-public class PaintStatus {
- private Text statusText;
- private String actionInfo, messageInfo, coordInfo;
- /**
- * Constructs a PaintStatus.
- *
- * @param statusText the handle of status bar text widget to use
- */
- public PaintStatus(Text statusText) {
- this.statusText = statusText;
- clear();
- }
-
- /**
- * Clears the status bar.
- */
- public void clear() {
- clearAction();
- clearMessage();
- clearCoord();
- }
-
- /**
- * Sets the status bar action text.
- *
- * @param action the action in progress
- */
- public void setAction(String action) {
- actionInfo = action;
- update();
- }
-
- /**
- * Clears the status bar action text.
- */
- public void clearAction() {
- actionInfo = "";
- update();
- }
-
- /**
- * Sets the status bar message text.
- *
- * @param message the message to display
- */
- public void setMessage(String message) {
- messageInfo = message;
- update();
- }
-
- /**
- * Clears the status bar message text.
- */
- public void clearMessage() {
- messageInfo = "";
- update();
- }
-
- /**
- * Sets the coordinates in the status bar.
- *
- * @param coord the coordinates to display
- */
- public void setCoord(Point coord) {
coordInfo = PaintPlugin.getResourceString("status.Coord.format", new Object[]
{ new Integer(coord.x), new Integer(coord.y)});
update();
- }
-
- /**
- * Sets the coordinate range in the status bar.
- *
- * @param a the "from" coordinate
- * @param b the "to" coordinate
- */
- public void setCoordRange(Point a, Point b) {
- coordInfo = PaintPlugin.getResourceString("status.CoordRange.format", new Object[]
{ new Integer(a.x), new Integer(a.y), new Integer(b.x), new Integer(b.y)});
update();
- }
-
- /**
- * Clears the coordinates in the status bar.
- */
- public void clearCoord() {
- coordInfo = "";
update();
- }
-
- /**
- * Updates the display.
- */
- private void update() {
- statusText.setText(
PaintPlugin.getResourceString("status.Bar.format", new Object[]
{ actionInfo, messageInfo, coordInfo }));
}
-}
diff --git a/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/PaintSurface.java b/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/PaintSurface.java index 149a7abcfe..52d6526792 100755 --- a/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/PaintSurface.java +++ b/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/PaintSurface.java @@ -6,16 +6,8 @@ package org.eclipse.swt.examples.paint;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
/**
* Manages a simple drawing surface.
*/
public class PaintSurface {
private Point currentPosition = new Point(0, 0);
- private Canvas paintCanvas;
private PaintStatus paintStatus;
private PaintSession paintSession;
private Image image;
private Rectangle visibleRect;
private Rectangle imageRect;
private GC displayGC; // the GC used for drawing to the display
private GC rubberbandGC; // the GC used exclusively for rubberband drawing
private GC imageGC; // the GC used as a permanent backing store
private Color rubberbandFGColor, rubberbandBGColor;
private ContainerFigure rubberband; // the active rubberband selection
private Object rubberbandState; // the active rubberband selection previewing state
private int rubberbandHiddenNestingCount; // always >= 0, if > 0 rubberband has been hidden
/**
* Constructs a PaintSurface.
* <p>
* paintCanvas must have SWT.NO_REDRAW_RESIZE style, and may have SWT.V_SCROLL and/or SWT.H_SCROLL.
* </p>
* @param paintCanvas the Canvas object in which to render
* @param paintStatus the PaintStatus object to use for providing user feedback
*/
- public PaintSurface(Canvas paintCanvas, PaintStatus paintStatus) {
this.paintCanvas = paintCanvas;
this.paintStatus = paintStatus;
/* Set up the drawing surface */
visibleRect = paintCanvas.getClientArea();
imageRect = paintCanvas.getDisplay().getClientArea();
image = new Image(paintCanvas.getDisplay(), imageRect.width, imageRect.height);
imageGC = new GC(image);
displayGC = new GC(paintCanvas);
rubberbandGC = new GC(paintCanvas);
rubberbandGC.setXORMode(true);
rubberbandFGColor = new Color(paintCanvas.getDisplay(), 255, 255, 255);
rubberbandBGColor = new Color(paintCanvas.getDisplay(), 127, 127, 127);
rubberbandGC.setForeground(rubberbandFGColor);
rubberbandGC.setBackground(rubberbandBGColor);
rubberbandHiddenNestingCount = 0;
rubberbandState = null;
rubberband = new ContainerFigure();
/* Initialize the session */
setPaintSession(null);
/* Add our listeners */
paintCanvas.addMouseListener(new MouseAdapter() {
public void mouseDown(MouseEvent event) {
processMouseEventCoordinates(event);
if (paintSession != null) paintSession.mouseDown(event);
}
public void mouseUp(MouseEvent event) {
processMouseEventCoordinates(event);
if (paintSession != null) paintSession.mouseUp(event);
}
public void mouseDoubleClick(MouseEvent event) {
processMouseEventCoordinates(event);
if (paintSession != null) paintSession.mouseDoubleClick(event);
}
});
paintCanvas.addMouseMoveListener(new MouseMoveListener() {
public void mouseMove(MouseEvent event) {
processMouseEventCoordinates(event);
if (paintSession != null) paintSession.mouseMove(event);
}
});
paintCanvas.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent event) {
hideRubberband();
displayGC.drawImage(image,
visibleRect.x - imageRect.x, visibleRect.y - imageRect.y,
visibleRect.width, visibleRect.height, 0, 0, visibleRect.width, visibleRect.height);
showRubberband();
}
});
paintCanvas.addControlListener(new ControlAdapter() {
public void controlResized(ControlEvent event) {
handleResize();
}
});
/* Set up the paint canvas scroll bars */
ScrollBar horizontal = paintCanvas.getHorizontalBar();
horizontal.setVisible(true);
horizontal.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
scrollHorizontally((ScrollBar)event.widget);
}
});
ScrollBar vertical = paintCanvas.getVerticalBar();
vertical.setVisible(true);
vertical.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
scrollVertically((ScrollBar)event.widget);
}
});
handleResize();
}
/**
* Disposes of the PaintSurface's resources.
*/
public void dispose() {
imageGC.dispose();
displayGC.dispose();
rubberbandGC.dispose();
rubberbandFGColor.dispose();
rubberbandBGColor.dispose();
image.dispose();
}
/**
* Called when we must grab focus.
*/
public void setFocus() {
paintCanvas.setFocus();
}
/**
* Returns the Display on which the PaintSurface resides.
* @return the Display
*/
public Display getDisplay() {
return paintCanvas.getDisplay();
}
/**
* Returns the Shell in which the PaintSurface resides.
* @return the Shell
*/
public Shell getShell() {
return paintCanvas.getShell();
}
/**
- * Returns the display Graphics Context associated with this surface.
* <p>
* Use this GC to draw rubberband line and other temporary entities to the screen.
* They will not be committed to the backing store and hence will not be refreshed
* should the paint surface become obscured.
* </p>
- *
- * @return the display GC associated with this surface
- */
- public GC getDisplayGC() {
- return displayGC;
- }
-
/**
* Returns the image Graphics Context associated with this surface.
* <p>
* Use this GC to draw entities that are to be committed to the backing store.
* Anything drawn in this manner will persist and be refreshed as appropriate.
* </p>
*
* @return the image GC associated with this surface
*/
public GC getImageGC() {
return imageGC;
}
/**
* Returns the offset to be added to x and y coordinates in order to transform
* virtual paint surface coordinates into Display coordinates
*
* @return the offset
*/
public Point getDisplayOffset() {
return new Point(- visibleRect.x, - visibleRect.y);
}
/**
* Returns the offset to be added to x and y coordinates in order to transform
* virtual paint surface coordinates into Image coordinates
*
* @return the offset
*/
public Point getImageOffset() {
return new Point(- imageRect.x, - imageRect.y);
}
/**
+ private final Canvas paintCanvas;
private PaintSession paintSession;
private Image image;
private int imageWidth, imageHeight;
private int visibleWidth, visibleHeight;
private FigureDrawContext displayFDC = new FigureDrawContext();
private FigureDrawContext imageFDC = new FigureDrawContext();
/* Rubberband */
private ContainerFigure rubberband = new ContainerFigure();
// the active rubberband selection
private int rubberbandHiddenNestingCount = 0;
// always >= 0, if > 0 rubberband has been hidden
/* Status */
private final Text statusText;
private String statusActionInfo, statusMessageInfo, statusCoordInfo;
/**
* Constructs a PaintSurface.
* <p>
* paintCanvas must have SWT.NO_REDRAW_RESIZE and SWT.NO_BACKGROUND styles,
* and may have SWT.V_SCROLL and/or SWT.H_SCROLL.
* </p>
* @param paintCanvas the Canvas object in which to render
* @param paintStatus the PaintStatus object to use for providing user feedback
*/
+ public PaintSurface(Canvas paintCanvas, Text statusText) {
this.paintCanvas = paintCanvas;
this.statusText = statusText;
clearStatus();
/* Set up the drawing surface */
Rectangle displayRect = paintCanvas.getDisplay().getClientArea();
imageWidth = displayRect.width;
imageHeight = displayRect.height;
image = new Image(paintCanvas.getDisplay(), imageWidth, imageHeight);
imageFDC.gc = new GC(image);
displayFDC.gc = new GC(paintCanvas);
/* Initialize the session */
setPaintSession(null);
/* Add our listeners */
paintCanvas.addMouseListener(new MouseAdapter() {
public void mouseDown(MouseEvent event) {
processMouseEventCoordinates(event);
if (paintSession != null) paintSession.mouseDown(event);
}
public void mouseUp(MouseEvent event) {
processMouseEventCoordinates(event);
if (paintSession != null) paintSession.mouseUp(event);
}
public void mouseDoubleClick(MouseEvent event) {
processMouseEventCoordinates(event);
if (paintSession != null) paintSession.mouseDoubleClick(event);
}
});
paintCanvas.addMouseMoveListener(new MouseMoveListener() {
public void mouseMove(MouseEvent event) {
processMouseEventCoordinates(event);
if (paintSession != null) paintSession.mouseMove(event);
}
});
paintCanvas.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent event) {
if (rubberband.isEmpty()) {
event.gc.drawImage(image,
displayFDC.xOffset, displayFDC.yOffset, visibleWidth, visibleHeight,
0, 0, visibleWidth, visibleHeight);
} else {
// avoid flicker
Rectangle clip = event.gc.getClipping();
Image blitImage = new Image(getDisplay(), event.width, event.height);
FigureDrawContext fdc = new FigureDrawContext();
fdc.gc = new GC(blitImage);
fdc.xOffset = displayFDC.xOffset + clip.x;
fdc.yOffset = displayFDC.yOffset + clip.y;
fdc.gc.drawImage(image,
clip.x + displayFDC.xOffset, clip.y + displayFDC.yOffset, clip.width, clip.height,
0, 0, clip.width, clip.height);
rubberband.draw(fdc);
fdc.gc.dispose();
event.gc.drawImage(blitImage, clip.x, clip.y);
blitImage.dispose();
}
}
});
paintCanvas.addControlListener(new ControlAdapter() {
public void controlResized(ControlEvent event) {
handleResize();
}
});
/* Set up the paint canvas scroll bars */
ScrollBar horizontal = paintCanvas.getHorizontalBar();
horizontal.setVisible(true);
horizontal.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
scrollHorizontally((ScrollBar)event.widget);
}
});
ScrollBar vertical = paintCanvas.getVerticalBar();
vertical.setVisible(true);
vertical.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
scrollVertically((ScrollBar)event.widget);
}
});
handleResize();
}
/**
* Disposes of the PaintSurface's resources.
*/
public void dispose() {
imageFDC.gc.dispose();
displayFDC.gc.dispose();
image.dispose();
}
/**
* Called when we must grab focus.
*/
public void setFocus() {
paintCanvas.setFocus();
}
/**
* Returns the Display on which the PaintSurface resides.
* @return the Display
*/
public Display getDisplay() {
return paintCanvas.getDisplay();
}
/**
* Returns the Shell in which the PaintSurface resides.
* @return the Shell
*/
public Shell getShell() {
return paintCanvas.getShell();
}
/**
* Sets the current paint session.
* <p>
* If oldPaintSession != paintSession calls oldPaintSession.end()
* and paintSession.begin()
* </p>
*
* @param paintSession the paint session to activate; null to disable all sessions
@@ -24,7 +16,7 @@ public class PaintSurface {
private Point currentPosition = new Point(0, 0); if (this.paintSession != null) {
if (this.paintSession == paintSession) return;
this.paintSession.endSession();
}
this.paintSession = paintSession;
- paintStatus.clear();
if (paintSession != null) {
paintStatus.setAction(paintSession.getDisplayName());
paintSession.beginSession();
} else {
paintStatus.setAction(PaintPlugin.getResourceString("tool.Null.displayname"));
paintStatus.setMessage(PaintPlugin.getResourceString("session.Null.message"));
}
}
+ clearStatus();
if (paintSession != null) {
setStatusAction(paintSession.getDisplayName());
paintSession.beginSession();
} else {
setStatusAction(PaintPlugin.getResourceString("tool.Null.displayname"));
setStatusMessage(PaintPlugin.getResourceString("session.Null.message"));
}
}
/**
* Returns the current paint session.
@@ -34,5 +26,4 @@ public class PaintSurface {
private Point currentPosition = new Point(0, 0); public PaintSession getPaintSession() {
return paintSession;
}
-
/**
* Returns the current paint status object.
*
* @return the current paint status object
*/
public PaintStatus getPaintStatus() {
return paintStatus;
}
/**
* Returns the current paint tool.
*
* @return the current paint tool, null if none is active (though some other session
* might be)
*/
public PaintTool getPaintTool() {
return (paintSession != null && paintSession instanceof PaintTool) ?
(PaintTool)paintSession : null;
}
/**
* Returns the current position in an interactive operation.
*
* @return the last known position of the pointer
*/
public Point getCurrentPosition() {
return currentPosition;
}
/**
* Redraws a specified rectangular area using the backing store
*
* @param x the left X virtual coordinate of the region
* @param y the top Y virtual coordinate of the region
* @param width the width of the region
* @param height the height of the region
* @see getImageGC()
*/
public void redrawArea(int x, int y, int width, int height) {
// Clip to image and screen [computes intersection of the rectangles]
final int clipX = Math.max(imageRect.x, visibleRect.x);
if (x < clipX) {
width -= clipX - x;
x = clipX;
}
final int clipY = Math.max(imageRect.y, visibleRect.y);
if (y < clipY) {
height -= clipY - y;
y = clipY;
}
final int clipWidth = Math.min(imageRect.width, visibleRect.width) + clipX - x;
if (width > clipWidth) width = clipWidth;
final int clipHeight = Math.min(imageRect.height, visibleRect.height) + clipY - y;
if (height > clipHeight) height = clipHeight;
if (width < 0 || height < 0) return;
// Redraw the region
hideRubberband();
displayGC.drawImage(image, x - imageRect.x, y - imageRect.y, width, height,
x - visibleRect.x, y - visibleRect.y, width, height);
showRubberband();
}
-
/**
* Draws a Figure object to the screen and to the backing store permanently.
*
* @param object the object to draw onscreen
*/
public void drawFigure(Figure object) {
object.draw(getImageGC(), getImageOffset());
object.draw(getDisplayGC(), getDisplayOffset());
}
/**
* Adds a Figure object to the active rubberband selection.
* <p>
* This object will be drawn to the screen as a preview and refreshed appropriately
* until the selection is either cleared or committed.
* </p>
*
* @param object the object to add to the selection
*/
public void addRubberbandSelection(Figure object) {
if (isRubberbandHidden()) {
rubberband.add(object);
} else {
rubberbandState = rubberband.addAndPreview(object, rubberbandGC,
getDisplayOffset(), rubberbandState);
}
}
/**
* Clears the active rubberband selection.
* <p>
* Erases any rubberband objects on the screen then clears the selection.
* </p>
*/
public void clearRubberbandSelection() {
if (! isRubberbandHidden()) {
rubberband.erasePreview(rubberbandGC, getDisplayOffset(), rubberbandState);
rubberbandState = null;
}
rubberband.clear();
}
/**
* Commits the active rubberband selection.
* <p>
* Redraws any rubberband objects on the screen as permanent objects then clears the selection.
* </p>
*/
public void commitRubberbandSelection() {
if (! isRubberbandHidden()) {
rubberband.erasePreview(rubberbandGC, getDisplayOffset(), rubberbandState);
rubberbandState = null;
}
drawFigure(rubberband);
rubberband.clear();
}
/**
* Hides the rubberband (but does not eliminate it).
* <p>
* Increments by one the rubberband "hide" nesting count. The rubberband
* is hidden from view (but remains active) if it wasn't already hidden.
* </p>
*/
public void hideRubberband() {
if (rubberbandHiddenNestingCount++ <= 0) {
rubberband.erasePreview(rubberbandGC, getDisplayOffset(), rubberbandState);
rubberbandState = null;
}
}
/**
* Shows (un-hides) the rubberband.
* <p>
* Decrements by one the rubberband "hide" nesting count. The rubberband
* is only made visible when showRubberband() has been called once for each
* previous hideRubberband(). It is not permitted to call showRubberband() if
* the rubber band is not presently hidden.
* </p>
*/
public void showRubberband() {
if (rubberbandHiddenNestingCount <= 0)
throw new IllegalStateException("rubberbandHiddenNestingCount > 0");
if (--rubberbandHiddenNestingCount == 0) {
rubberbandState = rubberband.drawPreview(rubberbandGC, getDisplayOffset());
}
}
/**
* Determines if the rubberband is hidden.
*
* @return true iff the rubber is hidden
*/
public boolean isRubberbandHidden() {
return rubberbandHiddenNestingCount > 0;
}
/**
* Displays the current position in the status bar.
*/
public void showCurrentPositionStatus() {
paintStatus.setCoord(currentPosition);
}
/**
* Displays the current position in the status bar.
*/
public void showCurrentRangeStatus(Point anchorPosition) {
paintStatus.setCoordRange(anchorPosition, currentPosition);
}
/**
* Handles a horizontal scroll event
*
* @param scrollbar the horizontal scroll bar that posted this event
*/
public void scrollHorizontally(ScrollBar scrollBar) {
if (image == null) return;
if (imageRect.width > visibleRect.width) {
final int oldx = visibleRect.x;
visibleRect.x = Math.min(scrollBar.getSelection(), imageRect.width - visibleRect.width);
paintCanvas.scroll(Math.max(oldx - visibleRect.x, 0), 0, Math.max(visibleRect.x - oldx, 0), 0,
visibleRect.width, visibleRect.height, false);
}
}
/**
* Handles a vertical scroll event
*
* @param scrollbar the vertical scroll bar that posted this event
*/
public void scrollVertically(ScrollBar scrollBar) {
if (image == null) return;
if (imageRect.height > visibleRect.height) {
final int oldy = visibleRect.y;
visibleRect.y = Math.min(scrollBar.getSelection(), imageRect.height - visibleRect.height);
paintCanvas.scroll(0, Math.max(oldy - visibleRect.y, 0), 0, Math.max(visibleRect.y - oldy, 0),
visibleRect.width, visibleRect.height, false);
}
}
/**
* Handles resize events
*/
private void handleResize() {
visibleRect = paintCanvas.getClientArea();
ScrollBar horizontal = paintCanvas.getHorizontalBar();
if (horizontal != null) {
visibleRect.x = Math.min(horizontal.getSelection(), imageRect.width - visibleRect.width);
if (imageRect.width <= visibleRect.width) {
horizontal.setEnabled(false);
horizontal.setSelection(0);
} else {
final int max = imageRect.width - visibleRect.width;
horizontal.setEnabled(true);
horizontal.setValues(visibleRect.x, 0, imageRect.width, visibleRect.width,
8, visibleRect.width);
}
}
ScrollBar vertical = paintCanvas.getVerticalBar();
if (vertical != null) {
visibleRect.y = Math.min(vertical.getSelection(), imageRect.height - visibleRect.height);
if (imageRect.height <= visibleRect.height) {
vertical.setEnabled(false);
vertical.setSelection(0);
} else {
final int max = imageRect.height - visibleRect.height;
vertical.setEnabled(true);
vertical.setValues(visibleRect.y, 0, imageRect.height, visibleRect.height,
8, visibleRect.height);
}
}
}
/**
* Virtualizes MouseEvent coordinates and stores the current position.
*/
private void processMouseEventCoordinates(MouseEvent event) {
currentPosition.x = event.x =
Math.min(Math.max(event.x, 0), visibleRect.width - 1) + visibleRect.x;
currentPosition.y = event.y =
Math.min(Math.max(event.y, 0), visibleRect.height - 1) + visibleRect.y;
}
}
+
/**
* Returns the current paint tool.
*
* @return the current paint tool, null if none is active (though some other session
* might be)
*/
public PaintTool getPaintTool() {
return (paintSession != null && paintSession instanceof PaintTool) ?
(PaintTool)paintSession : null;
}
/**
* Returns the current position in an interactive operation.
*
* @return the last known position of the pointer
*/
public Point getCurrentPosition() {
return currentPosition;
}
/**
* Draws a Figure object to the screen and to the backing store permanently.
*
* @param object the object to draw onscreen
*/
public void drawFigure(Figure object) {
object.draw(imageFDC);
object.draw(displayFDC);
}
/**
* Adds a Figure object to the active rubberband selection.
* <p>
* This object will be drawn to the screen as a preview and refreshed appropriately
* until the selection is either cleared or committed.
* </p>
*
* @param object the object to add to the selection
*/
public void addRubberbandSelection(Figure object) {
rubberband.add(object);
if (! isRubberbandHidden()) object.draw(displayFDC);
}
/**
* Clears the active rubberband selection.
* <p>
* Erases any rubberband objects on the screen then clears the selection.
* </p>
*/
public void clearRubberbandSelection() {
if (! isRubberbandHidden()) {
Region region = new Region();
rubberband.addDamagedRegion(displayFDC, region);
Rectangle r = region.getBounds();
paintCanvas.redraw(r.x, r.y, r.width, r.height, true);
region.dispose();
}
rubberband.clear();
}
/**
* Commits the active rubberband selection.
* <p>
* Redraws any rubberband objects on the screen as permanent objects then clears the selection.
* </p>
*/
public void commitRubberbandSelection() {
rubberband.draw(imageFDC);
if (isRubberbandHidden()) rubberband.draw(displayFDC);
rubberband.clear();
}
/**
* Hides the rubberband (but does not eliminate it).
* <p>
* Increments by one the rubberband "hide" nesting count. The rubberband
* is hidden from view (but remains active) if it wasn't already hidden.
* </p>
*/
public void hideRubberband() {
if (rubberbandHiddenNestingCount++ <= 0) {
Region region = new Region();
rubberband.addDamagedRegion(displayFDC, region);
Rectangle r = region.getBounds();
paintCanvas.redraw(r.x, r.y, r.width, r.height, true);
region.dispose();
}
}
/**
* Shows (un-hides) the rubberband.
* <p>
* Decrements by one the rubberband "hide" nesting count. The rubberband
* is only made visible when showRubberband() has been called once for each
* previous hideRubberband(). It is not permitted to call showRubberband() if
* the rubber band is not presently hidden.
* </p>
*/
public void showRubberband() {
if (rubberbandHiddenNestingCount <= 0)
throw new IllegalStateException("rubberbandHiddenNestingCount > 0");
if (--rubberbandHiddenNestingCount == 0) {
rubberband.draw(displayFDC);
}
}
/**
* Determines if the rubberband is hidden.
*
* @return true iff the rubber is hidden
*/
public boolean isRubberbandHidden() {
return rubberbandHiddenNestingCount > 0;
}
/**
* Handles a horizontal scroll event
*
* @param scrollbar the horizontal scroll bar that posted this event
*/
public void scrollHorizontally(ScrollBar scrollBar) {
if (image == null) return;
if (imageWidth > visibleWidth) {
final int oldx = displayFDC.xOffset;
displayFDC.xOffset = Math.min(scrollBar.getSelection(), imageWidth - visibleWidth);
paintCanvas.scroll(Math.max(oldx - displayFDC.xOffset, 0), 0, Math.max(displayFDC.xOffset - oldx, 0), 0,
visibleWidth, visibleHeight, false);
}
}
/**
* Handles a vertical scroll event
*
* @param scrollbar the vertical scroll bar that posted this event
*/
public void scrollVertically(ScrollBar scrollBar) {
if (image == null) return;
if (imageHeight > visibleHeight) {
final int oldy = displayFDC.yOffset;
displayFDC.yOffset = Math.min(scrollBar.getSelection(), imageHeight - visibleHeight);
paintCanvas.scroll(0, Math.max(oldy - displayFDC.yOffset, 0), 0, Math.max(displayFDC.yOffset - oldy, 0),
visibleWidth, visibleHeight, false);
}
}
/**
* Handles resize events
*/
private void handleResize() {
Rectangle visibleRect = paintCanvas.getClientArea();
visibleWidth = visibleRect.width;
visibleHeight = visibleRect.height;
ScrollBar horizontal = paintCanvas.getHorizontalBar();
if (horizontal != null) {
displayFDC.xOffset = Math.min(horizontal.getSelection(), imageWidth - visibleWidth);
if (imageWidth <= visibleWidth) {
horizontal.setEnabled(false);
horizontal.setSelection(0);
} else {
final int max = imageWidth - visibleWidth;
horizontal.setEnabled(true);
horizontal.setValues(displayFDC.xOffset, 0, imageWidth, visibleWidth,
8, visibleWidth);
}
}
ScrollBar vertical = paintCanvas.getVerticalBar();
if (vertical != null) {
displayFDC.yOffset = Math.min(vertical.getSelection(), imageHeight - visibleHeight);
if (imageHeight <= visibleHeight) {
vertical.setEnabled(false);
vertical.setSelection(0);
} else {
final int max = imageHeight - visibleHeight;
vertical.setEnabled(true);
vertical.setValues(displayFDC.yOffset, 0, imageHeight, visibleHeight,
8, visibleHeight);
}
}
}
/**
* Virtualizes MouseEvent coordinates and stores the current position.
*/
private void processMouseEventCoordinates(MouseEvent event) {
currentPosition.x = event.x =
Math.min(Math.max(event.x, 0), visibleWidth - 1) + displayFDC.xOffset;
currentPosition.y = event.y =
Math.min(Math.max(event.y, 0), visibleHeight - 1) + displayFDC.yOffset;
}
/**
* Clears the status bar.
*/
public void clearStatus() {
statusActionInfo = "";
statusMessageInfo = "";
statusCoordInfo = "";
updateStatus();
}
/**
* Sets the status bar action text.
*
* @param action the action in progress, null to clear
*/
public void setStatusAction(String action) {
statusActionInfo = (action != null) ? action : "";
updateStatus();
}
/**
* Sets the status bar message text.
*
* @param message the message to display, null to clear
*/
public void setStatusMessage(String message) {
statusMessageInfo = (message != null) ? message : "";
updateStatus();
}
/**
* Sets the coordinates in the status bar.
*
* @param coord the coordinates to display, null to clear
*/
public void setStatusCoord(Point coord) {
statusCoordInfo = (coord != null) ? PaintPlugin.getResourceString("status.Coord.format", new Object[]
{ new Integer(coord.x), new Integer(coord.y)}) : "";
updateStatus();
}
/**
* Sets the coordinate range in the status bar.
*
* @param a the "from" coordinate, must not be null
* @param b the "to" coordinate, must not be null
*/
public void setStatusCoordRange(Point a, Point b) {
statusCoordInfo = PaintPlugin.getResourceString("status.CoordRange.format", new Object[]
{ new Integer(a.x), new Integer(a.y), new Integer(b.x), new Integer(b.y)});
updateStatus();
}
/**
* Updates the display.
*/
private void updateStatus() {
statusText.setText(
PaintPlugin.getResourceString("status.Bar.format", new Object[]
{ statusActionInfo, statusMessageInfo, statusCoordInfo }));
}
}
diff --git a/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/PaintView.java b/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/PaintView.java index 4ac8af08ea..6f7ecdb4bc 100755 --- a/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/PaintView.java +++ b/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/PaintView.java @@ -33,18 +33,18 @@ public class PaintView extends ViewPart { // paint surface for drawing
private PaintSurface paintSurface;
- // status information
- private PaintStatus paintStatus;
-
// map action ids to useful data
private HashMap /* of String to PaintTool */ paintToolMap;
private HashMap /* of String to Integer */ paintFillTypeMap;
+ private HashMap /* of String to Integer */ paintLineStyleMap;
/** UI data **/
// handle of currently active tool IAction on the UI
private IAction activeToolAction;
// handle of currently active filltype IAction on the UI
private IAction activeFillTypeAction;
+ // handle of currently active linetype IAction on the UI
+ private IAction activeLineStyleAction;
// handle of active foreground color box Canvas widget
private Canvas activeForegroundColorCanvas;
@@ -87,7 +87,7 @@ public class PaintView extends ViewPart { *
* @see org.eclipse.ui.part.ViewPart#setFocus
*/
- public void setFocus() {
+ public void setFocus() {
paintSurface.setFocus();
}
@@ -132,11 +132,18 @@ public class PaintView extends ViewPart { toolbarManager.appendToGroup("group.tools", new SelectPaintToolAction("tool.Ellipse"));
toolbarManager.appendToGroup("group.tools", new SelectPaintToolAction("tool.Text"));
toolbarManager.add(new Separator());
- toolbarManager.add(new GroupMarker("group.options"));
- toolbarManager.appendToGroup("group.options", new SelectFillTypeAction("fill.None"));
- toolbarManager.appendToGroup("group.options", new SelectFillTypeAction("fill.Outline"));
- toolbarManager.appendToGroup("group.options", new SelectFillTypeAction("fill.Solid"));
+ toolbarManager.add(new GroupMarker("group.options.fill"));
+ toolbarManager.appendToGroup("group.options.fill", new SelectFillTypeAction("fill.None"));
+ toolbarManager.appendToGroup("group.options.fill", new SelectFillTypeAction("fill.Outline"));
+ toolbarManager.appendToGroup("group.options.fill", new SelectFillTypeAction("fill.Solid"));
toolbarManager.add(new Separator());
+ toolbarManager.add(new GroupMarker("group.options.linestyle"));
+ toolbarManager.appendToGroup("group.options.linestyle", new SelectLineStyleAction("linestyle.Solid"));
+ toolbarManager.appendToGroup("group.options.linestyle", new SelectLineStyleAction("linestyle.Dash"));
+ toolbarManager.appendToGroup("group.options.linestyle", new SelectLineStyleAction("linestyle.Dot"));
+ toolbarManager.appendToGroup("group.options.linestyle", new SelectLineStyleAction("linestyle.DashDot"));
+ toolbarManager.add(new Separator());
+ toolbarManager.add(new GroupMarker("group.options"));
toolbarManager.appendToGroup("group.options", new SelectFontAction("options.Font"));
actionBars.updateActionBars();
@@ -146,6 +153,7 @@ public class PaintView extends ViewPart { /*** Set defaults ***/
setPaintToolByID("tool.Pencil");
setFillTypeByID("fill.None");
+ setLineStyleByID("linestyle.Solid");
setForegroundColor(paintColorBlack);
setBackgroundColor(paintColorWhite);
}
@@ -172,7 +180,7 @@ public class PaintView extends ViewPart { // paint canvas
final Canvas paintCanvas = new Canvas(displayArea, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL |
- SWT.NO_REDRAW_RESIZE);
+ SWT.NO_REDRAW_RESIZE | SWT.NO_BACKGROUND);
gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
paintCanvas.setLayoutData(gridData);
paintCanvas.setBackground(paintColorWhite);
@@ -193,11 +201,8 @@ public class PaintView extends ViewPart { statusText.setLayoutData(gridData);
/*** Create the remaining application elements inside the principal GUI layout elements ***/
- // paintStatus
- paintStatus = new PaintStatus(statusText);
-
// paintSurface
- paintSurface = new PaintSurface(paintCanvas, paintStatus);
+ paintSurface = new PaintSurface(paintCanvas, statusText);
// paintToolMap
paintToolMap = new HashMap();
@@ -217,6 +222,13 @@ public class PaintView extends ViewPart { paintFillTypeMap.put("fill.Outline", new Integer(ToolSettings.ftOutline));
paintFillTypeMap.put("fill.Solid", new Integer(ToolSettings.ftSolid));
+ // paintLineStyleMap
+ paintLineStyleMap = new HashMap();
+ paintLineStyleMap.put("linestyle.Solid", new Integer(SWT.LINE_SOLID));
+ paintLineStyleMap.put("linestyle.Dash", new Integer(SWT.LINE_DASH));
+ paintLineStyleMap.put("linestyle.Dot", new Integer(SWT.LINE_DOT));
+ paintLineStyleMap.put("linestyle.DashDot", new Integer(SWT.LINE_DASHDOT));
+
// colorFrame
gridLayout = new GridLayout();
gridLayout.numColumns = 3;
@@ -238,7 +250,7 @@ public class PaintView extends ViewPart { activeBackgroundColorCanvas.setLayoutData(gridData);
// paletteCanvas
- final Canvas paletteCanvas = new Canvas(colorFrame, SWT.BORDER);
+ final Canvas paletteCanvas = new Canvas(colorFrame, SWT.BORDER | SWT.NO_BACKGROUND);
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.heightHint = 24;
paletteCanvas.setLayoutData(gridData);
@@ -355,12 +367,7 @@ public class PaintView extends ViewPart { * Selects a tool given its ID.
*/
public void setPaintToolByID(String id) {
- if (activeToolAction != null) activeToolAction.setChecked(false);
- IAction action = getActionByID(id);
- if (action != null) {
- activeToolAction = action;
- if (! action.isChecked()) action.setChecked(true);
- }
+ activeToolAction = handleRadioAction(activeToolAction, id);
final PaintTool paintTool = (PaintTool) paintToolMap.get(id);
paintSurface.setPaintSession(paintTool);
@@ -371,12 +378,7 @@ public class PaintView extends ViewPart { * Selects a filltype given its ID.
*/
public void setFillTypeByID(String id) {
- if (activeFillTypeAction != null) activeFillTypeAction.setChecked(false);
- IAction action = getActionByID(id);
- if (action != null) {
- activeFillTypeAction = action;
- if (! action.isChecked()) action.setChecked(true);
- }
+ activeFillTypeAction = handleRadioAction(activeFillTypeAction, id);
final Integer fillType = (Integer) paintFillTypeMap.get(id);
toolSettings.commonFillType = fillType.intValue();
@@ -384,6 +386,31 @@ public class PaintView extends ViewPart { }
/**
+ * Selects line type given its ID.
+ */
+ public void setLineStyleByID(String id) {
+ activeLineStyleAction = handleRadioAction(activeLineStyleAction, id);
+
+ final Integer lineType = (Integer) paintLineStyleMap.get(id);
+ toolSettings.commonLineStyle = lineType.intValue();
+ updateToolSettings();
+ }
+
+ /**
+ * Gets the IAction for an ID belonging to a set of mutually exclusive actions, and
+ * toggles the old action off if necessary.
+ */
+ private IAction handleRadioAction(IAction oldAction, String id) {
+ IAction action = getActionByID(id);
+ if (action != null) {
+ if (oldAction != null) oldAction.setChecked(false);
+ if (! action.isChecked()) action.setChecked(true);
+ return action;
+ }
+ return oldAction;
+ }
+
+ /**
* Gets the IAction representing the UI toolbar button with the specified ID.
*/
private IAction getActionByID(String id) {
@@ -435,6 +462,11 @@ public class PaintView extends ViewPart { public int getStyle() { return IAction.AS_CHECK_BOX; }
public void run() { setFillTypeByID(getId()); }
}
+ class SelectLineStyleAction extends PaintAction {
+ public SelectLineStyleAction(String id) { super(id); }
+ public int getStyle() { return IAction.AS_CHECK_BOX; }
+ public void run() { setLineStyleByID(getId()); }
+ }
class SelectFontAction extends PaintAction {
public SelectFontAction(String id) { super(id); }
public int getStyle() { return IAction.AS_PUSH_BUTTON; }
diff --git a/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/PencilTool.java b/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/PencilTool.java index c86722fa99..69f52d8612 100755 --- a/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/PencilTool.java +++ b/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/PencilTool.java @@ -11,7 +11,7 @@ import java.util.Random;
import org.eclipse.swt.graphics.*; * A pencil tool.
*/
public class PencilTool extends ContinuousPaintSession implements PaintTool {
- private Color drawColor;
+ private ToolSettings settings;
/**
* Constructs a pencil tool.
@@ -30,7 +30,7 @@ public class PencilTool extends ContinuousPaintSession implements PaintTool { * @param toolSettings the new tool settings
*/
public void set(ToolSettings toolSettings) {
- drawColor = toolSettings.commonForegroundColor;
+ settings = toolSettings;
}
/**
@@ -47,13 +47,6 @@ public class PencilTool extends ContinuousPaintSession implements PaintTool { */
public void render(final Point point) {
final PaintSurface ps = getPaintSurface();
- final GC igc = ps.getImageGC();
- final Point ioff = ps.getImageOffset();
- final GC dgc = ps.getDisplayGC();
- final Point doff = ps.getDisplayOffset();
- igc.setBackground(drawColor);
- igc.fillRectangle(point.x + ioff.x, point.y + ioff.y, 1, 1);
- dgc.setBackground(drawColor);
- dgc.fillRectangle(point.x + doff.x, point.y + doff.y, 1, 1);
+ ps.drawFigure(new PointFigure(settings.commonForegroundColor, point.x, point.y));
}
}
diff --git a/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/PointFigure.java b/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/PointFigure.java new file mode 100644 index 0000000000..a93da19f9c --- /dev/null +++ b/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/PointFigure.java @@ -0,0 +1,34 @@ +package org.eclipse.swt.examples.paint;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import org.eclipse.swt.graphics.*;
+
+/**
+ * 2D Point object
+ */
+public class PointFigure extends Figure {
+ private Color color;
+ private int x, y;
+ /**
+ * Constructs a Point
+ *
+ * @param color the color for this object
+ * @param x the virtual X coordinate of the first end-point
+ * @param y the virtual Y coordinate of the first end-point
+ */
+ public PointFigure(Color color, int x, int y) {
+ this.color = color; this.x = x; this.y = y;
+ }
+ public void draw(FigureDrawContext fdc) {
+ Point p = fdc.toClientPoint(x, y);
+ fdc.gc.setBackground(color);
+ fdc.gc.fillRectangle(p.x, p.y, 1, 1);
+ }
+ public void addDamagedRegion(FigureDrawContext fdc, Region region) {
+ region.add(fdc.toClientRectangle(x, y, x, y));
+ }
+}
diff --git a/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/PolyLineTool.java b/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/PolyLineTool.java index ef5c2c3ee4..28ad66c00e 100755 --- a/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/PolyLineTool.java +++ b/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/PolyLineTool.java @@ -11,9 +11,7 @@ import org.eclipse.swt.graphics.*; * A polyline drawing tool.
*/
public class PolyLineTool extends SegmentedPaintSession implements PaintTool {
- private Color drawFGColor;
- private Color drawBGColor;
- private int fillType;
+ private ToolSettings settings;
/**
* Constructs a PolyLineTool.
@@ -32,9 +30,7 @@ public class PolyLineTool extends SegmentedPaintSession implements PaintTool { * @param toolSettings the new tool settings
*/
public void set(ToolSettings toolSettings) {
- drawFGColor = toolSettings.commonForegroundColor;
- drawBGColor = toolSettings.commonBackgroundColor;
- fillType = toolSettings.commonFillType;
+ settings = toolSettings;
}
/**
@@ -51,19 +47,21 @@ public class PolyLineTool extends SegmentedPaintSession implements PaintTool { */
protected Figure createFigure(Point[] points, int numPoints, boolean closed) {
ContainerFigure container = new ContainerFigure();
- if (closed && fillType != ToolSettings.ftNone && numPoints >= 3) {
- container.add(new SolidPolygonFigure(drawBGColor, points, numPoints));
+ if (closed && settings.commonFillType != ToolSettings.ftNone && numPoints >= 3) {
+ container.add(new SolidPolygonFigure(settings.commonBackgroundColor, points, numPoints));
}
- if (! closed || fillType != ToolSettings.ftSolid || numPoints < 3) {
+ if (! closed || settings.commonFillType != ToolSettings.ftSolid || numPoints < 3) {
for (int i = 0; i < numPoints - 1; ++i) {
final Point a = points[i];
final Point b = points[i + 1];
- container.add(new LineFigure(drawFGColor, a.x, a.y, b.x, b.y));
+ container.add(new LineFigure(settings.commonForegroundColor, settings.commonLineStyle,
+ a.x, a.y, b.x, b.y));
}
if (closed) {
final Point a = points[points.length - 1];
final Point b = points[0];
- container.add(new LineFigure(drawFGColor, a.x, a.y, b.x, b.y));
+ container.add(new LineFigure(settings.commonForegroundColor, settings.commonLineStyle,
+ a.x, a.y, b.x, b.y));
}
}
return container;
diff --git a/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/RectangleFigure.java b/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/RectangleFigure.java index 205f53bf18..d6073f3f31 100755 --- a/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/RectangleFigure.java +++ b/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/RectangleFigure.java @@ -5,33 +5,38 @@ package org.eclipse.swt.examples.paint; * All Rights Reserved
*/
+import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
/**
* 2D Rectangle object
*/
-public class RectangleFigure extends StatelessXORFigureHelper {
+public class RectangleFigure extends Figure {
private Color color;
- private int x1, y1, x2, y2;
+ private int lineStyle, x1, y1, x2, y2;
/**
* Constructs a Rectangle
* These objects are defined by any two diametrically opposing corners.
*
* @param color the color for this object
+ * @param lineStyle the line style for this object
* @param x1 the virtual X coordinate of the first corner
* @param y1 the virtual Y coordinate of the first corner
* @param x2 the virtual X coordinate of the second corner
* @param y2 the virtual Y coordinate of the second corner
*/
- public RectangleFigure(Color color, int x1, int y1, int x2, int y2) {
- this.color = color; this.x1 = x1; this.y1 = y1; this.x2 = x2; this.y2 = y2;
+ public RectangleFigure(Color color, int lineStyle, int x1, int y1, int x2, int y2) {
+ this.color = color; this.lineStyle = lineStyle;
+ this.x1 = x1; this.y1 = y1; this.x2 = x2; this.y2 = y2;
}
- public void draw(GC gc, Point offset) {
- gc.setForeground(color);
- gcDraw(gc, offset);
+ public void draw(FigureDrawContext fdc) {
+ Rectangle r = fdc.toClientRectangle(x1, y1, x2, y2);
+ fdc.gc.setForeground(color);
+ fdc.gc.setLineStyle(lineStyle);
+ fdc.gc.drawRectangle(r.x, r.y, r.width - 1, r.height - 1);
+ fdc.gc.setLineStyle(SWT.LINE_SOLID);
+ }
+ public void addDamagedRegion(FigureDrawContext fdc, Region region) {
+ region.add(fdc.toClientRectangle(x1, y1, x2, y2));
}
- protected void gcDraw(GC gc, Point offset) {
- gc.drawRectangle(Math.min(x1, x2) + offset.x, Math.min(y1, y2) + offset.y,
- Math.abs(x2 - x1), Math.abs(y2 - y1));
- }
}
diff --git a/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/RectangleTool.java b/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/RectangleTool.java index e1281a5555..aa8726a769 100755 --- a/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/RectangleTool.java +++ b/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/RectangleTool.java @@ -11,9 +11,7 @@ import org.eclipse.swt.graphics.*; * A drawing tool.
*/
public class RectangleTool extends DragPaintSession implements PaintTool {
- private Color drawFGColor;
- private Color drawBGColor;
- private int fillType;
+ private ToolSettings settings;
/**
* Constructs a RectangleTool.
@@ -32,9 +30,7 @@ public class RectangleTool extends DragPaintSession implements PaintTool { * @param toolSettings the new tool settings
*/
public void set(ToolSettings toolSettings) {
- drawFGColor = toolSettings.commonForegroundColor;
- drawBGColor = toolSettings.commonBackgroundColor;
- fillType = toolSettings.commonFillType;
+ settings = toolSettings;
}
/**
@@ -50,18 +46,18 @@ public class RectangleTool extends DragPaintSession implements PaintTool { * Template method for drawing
*/
protected Figure createFigure(Point a, Point b) {
- switch (fillType) {
+ switch (settings.commonFillType) {
default:
case ToolSettings.ftNone:
- return new RectangleFigure(drawFGColor, a.x, a.y, b.x, b.y);
+ return new RectangleFigure(settings.commonForegroundColor, settings.commonLineStyle,
+ a.x, a.y, b.x, b.y);
case ToolSettings.ftSolid:
- return new SolidRectangleFigure(drawBGColor, a.x, a.y, b.x, b.y);
+ return new SolidRectangleFigure(settings.commonBackgroundColor, a.x, a.y, b.x, b.y);
case ToolSettings.ftOutline: {
ContainerFigure container = new ContainerFigure();
- container.add(new RectangleFigure(drawFGColor, a.x, a.y, b.x, b.y));
- container.add(new SolidRectangleFigure(drawBGColor,
- Math.min(a.x, b.x) + 1, Math.min(a.y, b.y) + 1,
- Math.max(a.x, b.x) - 1, Math.max(a.y, b.y) - 1));
+ container.add(new SolidRectangleFigure(settings.commonBackgroundColor, a.x, a.y, b.x, b.y));
+ container.add(new RectangleFigure(settings.commonForegroundColor, settings.commonLineStyle,
+ a.x, a.y, b.x, b.y));
return container;
}
}
diff --git a/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/RoundedRectangleFigure.java b/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/RoundedRectangleFigure.java index d8ff9b3f7e..b8e0cd2d28 100755 --- a/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/RoundedRectangleFigure.java +++ b/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/RoundedRectangleFigure.java @@ -5,35 +5,40 @@ package org.eclipse.swt.examples.paint; * All Rights Reserved
*/
+import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
/**
* 2D Rectangle object
*/
-public class RoundedRectangleFigure extends StatelessXORFigureHelper {
+public class RoundedRectangleFigure extends Figure {
private Color color;
- private int x1, y1, x2, y2, diameter;
+ private int lineStyle, x1, y1, x2, y2, diameter;
/**
* Constructs a Rectangle
* These objects are defined by any two diametrically opposing corners.
*
* @param color the color for this object
+ * @param lineStyle the line style for this object
* @param x1 the virtual X coordinate of the first corner
* @param y1 the virtual Y coordinate of the first corner
* @param x2 the virtual X coordinate of the second corner
* @param y2 the virtual Y coordinate of the second corner
* @param diameter the diameter of curvature of all four corners
*/
- public RoundedRectangleFigure(Color color, int x1, int y1, int x2, int y2, int diameter) {
- this.color = color; this.x1 = x1; this.y1 = y1; this.x2 = x2; this.y2 = y2;
+ public RoundedRectangleFigure(Color color, int lineStyle, int x1, int y1, int x2, int y2, int diameter) {
+ this.color = color; this.lineStyle = lineStyle;
+ this.x1 = x1; this.y1 = y1; this.x2 = x2; this.y2 = y2;
this.diameter = diameter;
}
- public void draw(GC gc, Point offset) {
- gc.setForeground(color);
- gcDraw(gc, offset);
+ public void draw(FigureDrawContext fdc) {
+ Rectangle r = fdc.toClientRectangle(x1, y1, x2, y2);
+ fdc.gc.setForeground(color);
+ fdc.gc.setLineStyle(lineStyle);
+ fdc.gc.drawRoundRectangle(r.x, r.y, r.width - 1, r.height - 1, diameter, diameter);
+ fdc.gc.setLineStyle(SWT.LINE_SOLID);
+ }
+ public void addDamagedRegion(FigureDrawContext fdc, Region region) {
+ region.add(fdc.toClientRectangle(x1, y1, x2, y2));
}
- protected void gcDraw(GC gc, Point offset) {
- gc.drawRoundRectangle(Math.min(x1, x2) + offset.x, Math.min(y1, y2) + offset.y,
- Math.abs(x2 - x1), Math.abs(y2 - y1), diameter, diameter);
- }
}
diff --git a/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/RoundedRectangleTool.java b/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/RoundedRectangleTool.java index 73bf168564..5c0311e43c 100755 --- a/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/RoundedRectangleTool.java +++ b/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/RoundedRectangleTool.java @@ -11,10 +11,7 @@ import org.eclipse.swt.graphics.*; * A drawing tool.
*/
public class RoundedRectangleTool extends DragPaintSession implements PaintTool {
- private Color drawFGColor;
- private Color drawBGColor;
- private int fillType;
- private int cornerDiameter;
+ private ToolSettings settings;
/**
* Constructs a RoundedRectangleTool.
@@ -33,10 +30,7 @@ public class RoundedRectangleTool extends DragPaintSession implements PaintTool * @param toolSettings the new tool settings
*/
public void set(ToolSettings toolSettings) {
- drawFGColor = toolSettings.commonForegroundColor;
- drawBGColor = toolSettings.commonBackgroundColor;
- fillType = toolSettings.commonFillType;
- cornerDiameter = toolSettings.roundedRectangleCornerDiameter;
+ settings = toolSettings;
}
/**
@@ -53,10 +47,12 @@ public class RoundedRectangleTool extends DragPaintSession implements PaintTool */
protected Figure createFigure(Point a, Point b) {
ContainerFigure container = new ContainerFigure();
- if (fillType != ToolSettings.ftNone)
- container.add(new SolidRoundedRectangleFigure(drawBGColor, a.x, a.y, b.x, b.y, cornerDiameter));
- if (fillType != ToolSettings.ftSolid)
- container.add(new RoundedRectangleFigure(drawFGColor, a.x, a.y, b.x, b.y, cornerDiameter));
+ if (settings.commonFillType != ToolSettings.ftNone)
+ container.add(new SolidRoundedRectangleFigure(settings.commonBackgroundColor,
+ a.x, a.y, b.x, b.y, settings.roundedRectangleCornerDiameter));
+ if (settings.commonFillType != ToolSettings.ftSolid)
+ container.add(new RoundedRectangleFigure(settings.commonForegroundColor,
+ settings.commonLineStyle, a.x, a.y, b.x, b.y, settings.roundedRectangleCornerDiameter));
return container;
}
}
diff --git a/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/SegmentedPaintSession.java b/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/SegmentedPaintSession.java index 5ca341684f..5085ab1bf2 100755 --- a/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/SegmentedPaintSession.java +++ b/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/SegmentedPaintSession.java @@ -43,7 +43,7 @@ public abstract class SegmentedPaintSession extends BasicPaintSession { * Activates the tool.
*/
public void beginSession() {
- getPaintSurface().getPaintStatus().setMessage(PaintPlugin.getResourceString(
+ getPaintSurface().setStatusMessage(PaintPlugin.getResourceString(
"session.SegmentedInteractivePaint.message.anchorMode"));
previousFigure = null;
currentFigure = null;
@@ -66,7 +66,7 @@ public abstract class SegmentedPaintSession extends BasicPaintSession { getPaintSurface().clearRubberbandSelection();
if (previousFigure != null) getPaintSurface().drawFigure(previousFigure);
- getPaintSurface().getPaintStatus().setMessage(PaintPlugin.getResourceString(
+ getPaintSurface().setStatusMessage(PaintPlugin.getResourceString(
"session.SegmentedInteractivePaint.message.anchorMode"));
previousFigure = null;
currentFigure = null;
@@ -81,7 +81,7 @@ public abstract class SegmentedPaintSession extends BasicPaintSession { public void mouseDown(MouseEvent event) {
if (event.button != 1) return;
- getPaintSurface().getPaintStatus().setMessage(PaintPlugin.getResourceString(
+ getPaintSurface().setStatusMessage(PaintPlugin.getResourceString(
"session.SegmentedInteractivePaint.message.interactiveMode"));
previousFigure = currentFigure;
@@ -128,10 +128,11 @@ public abstract class SegmentedPaintSession extends BasicPaintSession { public void mouseMove(MouseEvent event) {
final PaintSurface ps = getPaintSurface();
if (controlPoints.size() == 0) {
- ps.showCurrentPositionStatus();
+ ps.setStatusCoord(ps.getCurrentPosition());
return; // spurious event
} else {
- ps.showCurrentRangeStatus((Point) controlPoints.elementAt(controlPoints.size() - 1));
+ ps.setStatusCoordRange((Point) controlPoints.elementAt(controlPoints.size() - 1),
+ ps.getCurrentPosition());
}
ps.clearRubberbandSelection();
diff --git a/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/SolidEllipseFigure.java b/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/SolidEllipseFigure.java index 869c3e97cd..8f481eb474 100755 --- a/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/SolidEllipseFigure.java +++ b/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/SolidEllipseFigure.java @@ -10,7 +10,7 @@ import org.eclipse.swt.graphics.*; /**
* 2D Solid Ellipse object
*/
-public class SolidEllipseFigure extends StatelessXORFigureHelper {
+public class SolidEllipseFigure extends Figure {
private Color color;
private int x1, y1, x2, y2;
/**
@@ -27,12 +27,12 @@ public class SolidEllipseFigure extends StatelessXORFigureHelper { public SolidEllipseFigure(Color color, int x1, int y1, int x2, int y2) {
this.color = color; this.x1 = x1; this.y1 = y1; this.x2 = x2; this.y2 = y2;
}
- public void draw(GC gc, Point offset) {
- gc.setBackground(color);
- gcDraw(gc, offset);
+ public void draw(FigureDrawContext fdc) {
+ Rectangle r = fdc.toClientRectangle(x1, y1, x2, y2);
+ fdc.gc.setBackground(color);
+ fdc.gc.fillOval(r.x, r.y, r.width, r.height);
+ }
+ public void addDamagedRegion(FigureDrawContext fdc, Region region) {
+ region.add(fdc.toClientRectangle(x1, y1, x2, y2));
}
- protected void gcDraw(GC gc, Point offset) {
- gc.fillOval(Math.min(x1, x2) + offset.x, Math.min(y1, y2) + offset.y,
- Math.abs(x2 - x1) + 1, Math.abs(y2 - y1) + 1);
- }
}
diff --git a/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/SolidPolygonFigure.java b/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/SolidPolygonFigure.java index a16b1895cf..22b06ca958 100755 --- a/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/SolidPolygonFigure.java +++ b/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/SolidPolygonFigure.java @@ -10,7 +10,7 @@ import org.eclipse.swt.graphics.*; /**
* 2D Line object
*/
-public class SolidPolygonFigure extends StatelessXORFigureHelper {
+public class SolidPolygonFigure extends Figure {
private Color color;
private int[] points;
/**
@@ -29,11 +29,25 @@ public class SolidPolygonFigure extends StatelessXORFigureHelper { points[i * 2 + 1] = vertices[i].y;
}
}
- public void draw(GC gc, Point offset) {
- gc.setBackground(color);
- gcDraw(gc, offset);
+ public void draw(FigureDrawContext fdc) {
+ int[] drawPoints = new int[points.length];
+ for (int i = 0; i < points.length; i += 2) {
+ drawPoints[i] = points[i] * fdc.xScale - fdc.xOffset;
+ drawPoints[i + 1] = points[i + 1] * fdc.yScale - fdc.yOffset;
+ }
+ fdc.gc.setBackground(color);
+ fdc.gc.fillPolygon(drawPoints);
+ }
+ public void addDamagedRegion(FigureDrawContext fdc, Region region) {
+ int xmin = Integer.MAX_VALUE, ymin = Integer.MAX_VALUE;
+ int xmax = Integer.MIN_VALUE, ymax = Integer.MIN_VALUE;
+
+ for (int i = 0; i < points.length; i += 2) {
+ if (points[i] < xmin) xmin = points[i];
+ if (points[i] > xmax) xmax = points[i];
+ if (points[i+1] < ymin) ymin = points[i+1];
+ if (points[i+1] > ymax) ymax = points[i+1];
+ }
+ region.add(fdc.toClientRectangle(xmin, ymin, xmax, ymax));
}
- protected void gcDraw(GC gc, Point offset) {
- gc.fillPolygon(points);
- }
}
diff --git a/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/SolidRectangleFigure.java b/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/SolidRectangleFigure.java index 54d6b758d2..f1146a5736 100755 --- a/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/SolidRectangleFigure.java +++ b/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/SolidRectangleFigure.java @@ -10,7 +10,7 @@ import org.eclipse.swt.graphics.*; /**
* 2D SolidRectangle object
*/
-public class SolidRectangleFigure extends StatelessXORFigureHelper {
+public class SolidRectangleFigure extends Figure {
private Color color;
private int x1, y1, x2, y2;
/**
@@ -26,12 +26,12 @@ public class SolidRectangleFigure extends StatelessXORFigureHelper { public SolidRectangleFigure(Color color, int x1, int y1, int x2, int y2) {
this.color = color; this.x1 = x1; this.y1 = y1; this.x2 = x2; this.y2 = y2;
}
- public void draw(GC gc, Point offset) {
- gc.setBackground(color);
- gcDraw(gc, offset);
+ public void draw(FigureDrawContext fdc) {
+ Rectangle r = fdc.toClientRectangle(x1, y1, x2, y2);
+ fdc.gc.setBackground(color);
+ fdc.gc.fillRectangle(r.x, r.y, r.width, r.height);
+ }
+ public void addDamagedRegion(FigureDrawContext fdc, Region region) {
+ region.add(fdc.toClientRectangle(x1, y1, x2, y2));
}
- protected void gcDraw(GC gc, Point offset) {
- gc.fillRectangle(Math.min(x1, x2) + offset.x, Math.min(y1, y2) + offset.y,
- Math.abs(x2 - x1) + 1, Math.abs(y2 - y1) + 1);
- }
}
diff --git a/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/SolidRoundedRectangleFigure.java b/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/SolidRoundedRectangleFigure.java index 320b29c060..bb57338e75 100755 --- a/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/SolidRoundedRectangleFigure.java +++ b/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/SolidRoundedRectangleFigure.java @@ -10,7 +10,7 @@ import org.eclipse.swt.graphics.*; /**
* 2D SolidRectangle object
*/
-public class SolidRoundedRectangleFigure extends StatelessXORFigureHelper {
+public class SolidRoundedRectangleFigure extends Figure {
private Color color;
private int x1, y1, x2, y2, diameter;
/**
@@ -28,12 +28,12 @@ public class SolidRoundedRectangleFigure extends StatelessXORFigureHelper { this.color = color; this.x1 = x1; this.y1 = y1; this.x2 = x2; this.y2 = y2;
this.diameter = diameter;
}
- public void draw(GC gc, Point offset) {
- gc.setBackground(color);
- gcDraw(gc, offset);
+ public void draw(FigureDrawContext fdc) {
+ Rectangle r = fdc.toClientRectangle(x1, y1, x2, y2);
+ fdc.gc.setBackground(color);
+ fdc.gc.fillRoundRectangle(r.x, r.y, r.width, r.height, diameter, diameter);
+ }
+ public void addDamagedRegion(FigureDrawContext fdc, Region region) {
+ region.add(fdc.toClientRectangle(x1, y1, x2, y2));
}
- protected void gcDraw(GC gc, Point offset) {
- gc.fillRoundRectangle(Math.min(x1, x2) + offset.x, Math.min(y1, y2) + offset.y,
- Math.abs(x2 - x1) + 1, Math.abs(y2 - y1) + 1, diameter, diameter);
- }
}
diff --git a/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/StatelessXORFigureHelper.java b/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/StatelessXORFigureHelper.java deleted file mode 100755 index c5d314ea8f..0000000000 --- a/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/StatelessXORFigureHelper.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.eclipse.swt.examples.paint;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved
- */
-
-import org.eclipse.swt.graphics.*;
-
-/**
- * Superclass for all Figure objects that do not need to store state about preview copies
- * and have self-complementary preview drawing and erasing operations
- * e.g. Those that use XOR drawing operations
- */
-public abstract class StatelessXORFigureHelper extends Figure {
- public Object drawPreview(GC gc, Point offset) {
- gcDraw(gc, offset);
- return null;
- }
- public void erasePreview(GC gc, Point offset, Object rememberedData) {
- gcDraw(gc, offset);
- }
- protected abstract void gcDraw(GC gc, Point offset);
-}
diff --git a/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/TextFigure.java b/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/TextFigure.java index 260f3a04f8..a8f1b077ff 100755 --- a/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/TextFigure.java +++ b/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/TextFigure.java @@ -27,31 +27,17 @@ public class TextFigure extends Figure { public TextFigure(Color color, Font font, String text, int x, int y) {
this.color = color; this.font = font; this.text = text; this.x = x; this.y = y;
}
- public void draw(GC gc, Point offset) {
- gc.setFont(font);
- gc.setForeground(color);
- gc.drawText(text, x + offset.x, y + offset.y, true);
+ public void draw(FigureDrawContext fdc) {
+ Point p = fdc.toClientPoint(x, y);
+ fdc.gc.setFont(font);
+ fdc.gc.setForeground(color);
+ fdc.gc.drawText(text, p.x, p.y, true);
}
- public Object drawPreview(GC gc, Point offset) {
- Color oldColor = gc.getForeground();
- gc.setFont(font);
- gc.setForeground(color);
- gc.setXORMode(false);
-
- Point textExtent = gc.textExtent(text);
- Image backingStore = new Image(null, textExtent.x, textExtent.y);
- gc.copyArea(backingStore, x + offset.x, y + offset.y);
-
- gc.drawText(text, x + offset.x, y + offset.y, true);
- gc.setForeground(oldColor);
- gc.setXORMode(true);
- return backingStore;
- }
- public void erasePreview(GC gc, Point offset, Object rememberedData) {
- Image backingStore = (Image) rememberedData;
- gc.setXORMode(false);
- gc.drawImage(backingStore, x + offset.x, y + offset.y);
- gc.setXORMode(true);
- backingStore.dispose();
+ public void addDamagedRegion(FigureDrawContext fdc, Region region) {
+ Font oldFont = fdc.gc.getFont();
+ fdc.gc.setFont(font);
+ Point textExtent = fdc.gc.textExtent(text);
+ fdc.gc.setFont(oldFont);
+ region.add(fdc.toClientRectangle(x, y, x + textExtent.x, y + textExtent.y));
}
}
diff --git a/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/TextTool.java b/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/TextTool.java index f7403c8263..22831e81bf 100755 --- a/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/TextTool.java +++ b/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/TextTool.java @@ -13,8 +13,7 @@ import org.eclipse.swt.graphics.*; * A text drawing tool.
*/
public class TextTool extends BasicPaintSession implements PaintTool {
- private Color drawColor;
- private Font drawFont;
+ private ToolSettings settings;
private String drawText = PaintPlugin.getResourceString("tool.Text.settings.defaulttext");
/**
@@ -34,8 +33,7 @@ public class TextTool extends BasicPaintSession implements PaintTool { * @param toolSettings the new tool settings
*/
public void set(ToolSettings toolSettings) {
- drawColor = toolSettings.commonForegroundColor;
- drawFont = toolSettings.commonFont;
+ settings = toolSettings;
}
/**
@@ -51,7 +49,7 @@ public class TextTool extends BasicPaintSession implements PaintTool { * Activates the tool.
*/
public void beginSession() {
- getPaintSurface().getPaintStatus().setMessage(PaintPlugin.getResourceString(
+ getPaintSurface().setStatusMessage(PaintPlugin.getResourceString(
"session.Text.message"));
}
@@ -114,9 +112,11 @@ public class TextTool extends BasicPaintSession implements PaintTool { * @param event the mouse event detail information
*/
public void mouseMove(MouseEvent event) {
- getPaintSurface().showCurrentPositionStatus();
- getPaintSurface().clearRubberbandSelection();
- getPaintSurface().addRubberbandSelection(
- new TextFigure(drawColor, drawFont, drawText, event.x, event.y));
+ final PaintSurface ps = getPaintSurface();
+ ps.setStatusCoord(ps.getCurrentPosition());
+ ps.clearRubberbandSelection();
+ ps.addRubberbandSelection(
+ new TextFigure(settings.commonForegroundColor, settings.commonFont,
+ drawText, event.x, event.y));
}
}
diff --git a/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/ToolSettings.java b/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/ToolSettings.java index 3afeba079a..6d41a27dd8 100755 --- a/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/ToolSettings.java +++ b/examples/org.eclipse.swt.examples.paint/org/eclipse/swt/examples/paint/ToolSettings.java @@ -3,7 +3,7 @@ package org.eclipse.swt.examples.paint; * (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved
*/
-
import org.eclipse.swt.graphics.*;
+
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
/**
* Tool Settings objects group tool-related configuration information.
*/
public class ToolSettings {
public static final int ftNone = 0, ftOutline = 1, ftSolid = 2;
/**
@@ -15,7 +15,7 @@ public class ToolSettings { * commonBackgroundColor: current tool background colour
*/
public Color commonBackgroundColor;
-
/**
* commonFont: current font
*/
public Font commonFont;
/**
* commonFillType: current fill type
* <p>
* One of ftNone, ftOutline, ftSolid.
* </p>
*/
public int commonFillType = ftNone;
+
/**
* commonFont: current font
*/
public Font commonFont;
/**
* commonFillType: current fill type
* <p>One of ftNone, ftOutline, ftSolid.</p>
*/
public int commonFillType = ftNone;
/**
* commonLineStyle: current line type
*/
public int commonLineStyle = SWT.LINE_SOLID;
/**
* airbrushRadius: coverage radius in pixels
*/
diff --git a/examples/org.eclipse.swt.examples.paint/plugin.properties b/examples/org.eclipse.swt.examples.paint/plugin.properties index e9877e3fcf..3c8cd6030d 100755 --- a/examples/org.eclipse.swt.examples.paint/plugin.properties +++ b/examples/org.eclipse.swt.examples.paint/plugin.properties @@ -82,6 +82,26 @@ fill.Solid.tooltip = Solid fill mode fill.Solid.image = icons/fill_solid.gif
fill.Solid.description = Selects Solid Fill mode.
+linestyle.Solid.label = Solid Line
+linestyle.Solid.tooltip = Solid line style
+linestyle.Solid.image = icons/linestyle_solid.gif
+linestyle.Solid.description = Select Solid Line style.
+
+linestyle.Dot.label = Dotted Line
+linestyle.Dot.tooltip = Dotted line style
+linestyle.Dot.image = icons/linestyle_dot.gif
+linestyle.Dot.description = Select Dotted Line style.
+
+linestyle.Dash.label = Dashed Line
+linestyle.Dash.tooltip = Dashed line style
+linestyle.Dash.image = icons/linestyle_dash.gif
+linestyle.Dash.description = Select Dashed Line style.
+
+linestyle.DashDot.label = Dash-Dot Line
+linestyle.DashDot.tooltip = Dash-Dot line style
+linestyle.DashDot.image = icons/linestyle_dashdot.gif
+linestyle.DashDot.description = Select Dash-Dot Line style.
+
options.Font.label = Text Tool Font
options.Font.tooltip = Select Text Tool font
options.Font.image = icons/options_font.gif
diff --git a/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/AirbrushTool.java b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/AirbrushTool.java index 3480f3a3b2..8eeabb9920 100755 --- a/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/AirbrushTool.java +++ b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/AirbrushTool.java @@ -11,11 +11,10 @@ import java.util.Random;
import org.eclipse.swt.graphics.*; * An airbrush tool.
*/
public class AirbrushTool extends ContinuousPaintSession implements PaintTool {
+ private ToolSettings settings;
private Random random;
- private int airbrushRadius;
private int cachedRadiusSquared;
private int cachedNumPoints;
- private Color airbrushColor;
/**
* Constructs a Tool.
@@ -26,8 +25,8 @@ public class AirbrushTool extends ContinuousPaintSession implements PaintTool { public AirbrushTool(ToolSettings toolSettings, PaintSurface paintSurface) {
super(paintSurface);
random = new Random();
- set(toolSettings);
setRetriggerTimer(10);
+ set(toolSettings);
}
/**
@@ -36,13 +35,11 @@ public class AirbrushTool extends ContinuousPaintSession implements PaintTool { * @param toolSettings the new tool settings
*/
public void set(ToolSettings toolSettings) {
- airbrushRadius = toolSettings.airbrushRadius;
- airbrushColor = toolSettings.commonForegroundColor;
-
// compute things we need to know for drawing
- cachedRadiusSquared = toolSettings.airbrushRadius * toolSettings.airbrushRadius;
- cachedNumPoints = 314 * toolSettings.airbrushIntensity * cachedRadiusSquared / 250000;
- if (cachedNumPoints == 0 && toolSettings.airbrushIntensity != 0)
+ settings = toolSettings;
+ cachedRadiusSquared = settings.airbrushRadius * settings.airbrushRadius;
+ cachedNumPoints = 314 * settings.airbrushIntensity * cachedRadiusSquared / 250000;
+ if (cachedNumPoints == 0 && settings.airbrushIntensity != 0)
cachedNumPoints = 1;
}
@@ -60,22 +57,16 @@ public class AirbrushTool extends ContinuousPaintSession implements PaintTool { */
protected void render(Point point) {
// Draws a bunch (cachedNumPoints) of random pixels within a specified circle (cachedRadiusSquared).
- final PaintSurface ps = getPaintSurface();
- final GC igc = ps.getImageGC();
- final Point ioff = ps.getImageOffset();
- final int x = point.x + ioff.x, y = point.y + ioff.y;
-
- igc.setBackground(airbrushColor);
+ ContainerFigure cfig = new ContainerFigure();
+
for (int i = 0; i < cachedNumPoints; ++i) {
int randX, randY;
do {
- randX = (int) ((random.nextDouble() - 0.5) * airbrushRadius * 2.0);
- randY = (int) ((random.nextDouble() - 0.5) * airbrushRadius * 2.0);
+ randX = (int) ((random.nextDouble() - 0.5) * settings.airbrushRadius * 2.0);
+ randY = (int) ((random.nextDouble() - 0.5) * settings.airbrushRadius * 2.0);
} while (randX * randX + randY * randY > cachedRadiusSquared);
-
- igc.fillRectangle(x + randX, y + randY, 1, 1);
+ cfig.add(new PointFigure(settings.commonForegroundColor, point.x + randX, point.y + randY));
}
- ps.redrawArea(point.x - airbrushRadius, point.y - airbrushRadius,
- airbrushRadius * 2, airbrushRadius * 2);
+ getPaintSurface().drawFigure(cfig);
}
}
diff --git a/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/ContainerFigure.java b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/ContainerFigure.java index ac36901c7c..0c2d64996a 100755 --- a/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/ContainerFigure.java +++ b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/ContainerFigure.java @@ -38,6 +38,13 @@ public class ContainerFigure extends Figure { ++nextIndex;
}
/**
+ * Determines if the container is empty.
+ * @return true if the container is empty
+ */
+ public boolean isEmpty() {
+ return nextIndex == 0;
+ }
+ /**
* Adds an object to the container and draws its preview then updates the supplied preview state.
*
* @param object the object to add to the drawing list
@@ -47,19 +54,19 @@ public class ContainerFigure extends Figure { * using this Container, may be null if there was no such previous call
* @return object state that must be passed to erasePreview() later to erase this object
*/
- public Object addAndPreview(Figure object, GC gc, Point offset, Object rememberedState) {
- Object[] stateStack = (Object[]) rememberedState;
- if (stateStack == null) {
- stateStack = new Object[INITIAL_ARRAY_SIZE];
- } else if (stateStack.length <= nextIndex) {
- Object[] newStateStack = new Object[stateStack.length * 2];
- System.arraycopy(stateStack, 0, newStateStack, 0, stateStack.length);
- stateStack = newStateStack;
- }
- add(object);
- stateStack[nextIndex - 1] = object.drawPreview(gc, offset);
- return stateStack;
- }
+// public Object addAndPreview(Figure object, GC gc, Point offset, Object rememberedState) {
+// Object[] stateStack = (Object[]) rememberedState;
+// if (stateStack == null) {
+// stateStack = new Object[INITIAL_ARRAY_SIZE];
+// } else if (stateStack.length <= nextIndex) {
+// Object[] newStateStack = new Object[stateStack.length * 2];
+// System.arraycopy(stateStack, 0, newStateStack, 0, stateStack.length);
+// stateStack = newStateStack;
+// }
+// add(object);
+// stateStack[nextIndex - 1] = object.drawPreview(gc, offset);
+// return stateStack;
+// }
/**
* Clears the container.
* <p>
@@ -71,24 +78,10 @@ public class ContainerFigure extends Figure { while (--nextIndex > 0) objectStack[nextIndex] = null;
nextIndex = 0;
}
- public void draw(GC gc, Point offset) {
- for (int i = 0; i < nextIndex; ++i) objectStack[i].draw(gc, offset);
+ public void draw(FigureDrawContext fdc) {
+ for (int i = 0; i < nextIndex; ++i) objectStack[i].draw(fdc);
}
- public Object drawPreview(GC gc, Point offset) {
- if (nextIndex == 0) return null;
-
- Object[] stateStack = new Object[nextIndex];
- for (int i = 0; i < nextIndex; ++i) stateStack[i] = objectStack[i].drawPreview(gc, offset);
- return stateStack;
+ public void addDamagedRegion(FigureDrawContext fdc, Region region) {
+ for (int i = 0; i < nextIndex; ++i) objectStack[i].addDamagedRegion(fdc, region);
}
- public void erasePreview(GC gc, Point offset, Object rememberedState) {
- if (rememberedState == null) return;
-
- final Object[] stateStack = (Object[]) rememberedState;
- int i = nextIndex;
- while (--i >= 0) {
- objectStack[i].erasePreview(gc, offset, stateStack[i]);
- stateStack[i] = null;
- }
- }
}
diff --git a/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/ContinuousPaintSession.java b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/ContinuousPaintSession.java index 428dd2e981..abbe320b64 100755 --- a/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/ContinuousPaintSession.java +++ b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/ContinuousPaintSession.java @@ -57,8 +57,8 @@ public abstract class ContinuousPaintSession extends BasicPaintSession { * Activates the tool.
*/
public void beginSession() {
- getPaintSurface().getPaintStatus().
- setMessage(PaintPlugin.getResourceString("session.ContinuousPaint.message"));
+ getPaintSurface().
+ setStatusMessage(PaintPlugin.getResourceString("session.ContinuousPaint.message"));
dragInProgress = false;
}
@@ -119,7 +119,8 @@ public abstract class ContinuousPaintSession extends BasicPaintSession { * @param event the mouse event detail information
*/
public final void mouseMove(MouseEvent event) {
- getPaintSurface().showCurrentPositionStatus();
+ final PaintSurface ps = getPaintSurface();
+ ps.setStatusCoord(ps.getCurrentPosition());
if (! dragInProgress) return;
mouseSegmentFinished(event);
prepareRetrigger();
diff --git a/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/DragPaintSession.java b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/DragPaintSession.java index 2f89450de0..78b9fe6bd7 100755 --- a/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/DragPaintSession.java +++ b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/DragPaintSession.java @@ -40,8 +40,8 @@ public abstract class DragPaintSession extends BasicPaintSession { * Activates the tool.
*/
public void beginSession() {
- getPaintSurface().getPaintStatus().
- setMessage(PaintPlugin.getResourceString("session.DragInteractivePaint.message"));
+ getPaintSurface().
+ setStatusMessage(PaintPlugin.getResourceString("session.DragInteractivePaint.message"));
anchorPosition.x = -1;
dragInProgress = false;
}
@@ -109,10 +109,10 @@ public abstract class DragPaintSession extends BasicPaintSession { public void mouseMove(MouseEvent event) {
final PaintSurface ps = getPaintSurface();
if (! dragInProgress) {
- ps.showCurrentPositionStatus();
+ ps.setStatusCoord(ps.getCurrentPosition());
return;
}
- ps.showCurrentRangeStatus(anchorPosition);
+ ps.setStatusCoordRange(anchorPosition, ps.getCurrentPosition());
ps.clearRubberbandSelection();
tempPosition.x = event.x;
tempPosition.y = event.y;
diff --git a/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/EllipseFigure.java b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/EllipseFigure.java index 7bcb7c4021..a28105e9fb 100755 --- a/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/EllipseFigure.java +++ b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/EllipseFigure.java @@ -5,34 +5,39 @@ package org.eclipse.swt.examples.paint; * All Rights Reserved
*/
+import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
/**
* 2D Ellipse object
*/
-public class EllipseFigure extends StatelessXORFigureHelper {
+public class EllipseFigure extends Figure {
private Color color;
- private int x1, y1, x2, y2;
+ private int lineStyle, x1, y1, x2, y2;
/**
* Constructs an Ellipse
* These objects are defined by any two diametrically opposing corners of a box
* bounding the ellipse.
*
* @param color the color for this object
+ * @param lineStyle the line style for this object
* @param x1 the virtual X coordinate of the first corner
* @param y1 the virtual Y coordinate of the first corner
* @param x2 the virtual X coordinate of the second corner
* @param y2 the virtual Y coordinate of the second corner
*/
- public EllipseFigure(Color color, int x1, int y1, int x2, int y2) {
- this.color = color; this.x1 = x1; this.y1 = y1; this.x2 = x2; this.y2 = y2;
+ public EllipseFigure(Color color, int lineStyle, int x1, int y1, int x2, int y2) {
+ this.color = color; this.lineStyle = lineStyle;
+ this.x1 = x1; this.y1 = y1; this.x2 = x2; this.y2 = y2;
}
- public void draw(GC gc, Point offset) {
- gc.setForeground(color);
- gcDraw(gc, offset);
+ public void draw(FigureDrawContext fdc) {
+ Rectangle r = fdc.toClientRectangle(x1, y1, x2, y2);
+ fdc.gc.setForeground(color);
+ fdc.gc.setLineStyle(lineStyle);
+ fdc.gc.drawOval(r.x, r.y, r.width - 1, r.height - 1);
+ fdc.gc.setLineStyle(SWT.LINE_SOLID);
+ }
+ public void addDamagedRegion(FigureDrawContext fdc, Region region) {
+ region.add(fdc.toClientRectangle(x1, y1, x2, y2));
}
- protected void gcDraw(GC gc, Point offset) {
- gc.drawOval(Math.min(x1, x2) + offset.x, Math.min(y1, y2) + offset.y,
- Math.abs(x2 - x1), Math.abs(y2 - y1));
- }
}
diff --git a/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/EllipseTool.java b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/EllipseTool.java index ab41a10713..cfd26997d6 100755 --- a/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/EllipseTool.java +++ b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/EllipseTool.java @@ -11,9 +11,7 @@ import org.eclipse.swt.graphics.*; * A drawing tool.
*/
public class EllipseTool extends DragPaintSession implements PaintTool {
- private Color drawFGColor;
- private Color drawBGColor;
- private int fillType;
+ private ToolSettings settings;
/**
* Constructs a EllipseTool.
@@ -25,18 +23,16 @@ public class EllipseTool extends DragPaintSession implements PaintTool { super(paintSurface);
set(toolSettings);
}
-
+
/**
* Sets the tool's settings.
*
* @param toolSettings the new tool settings
*/
public void set(ToolSettings toolSettings) {
- drawFGColor = toolSettings.commonForegroundColor;
- drawBGColor = toolSettings.commonBackgroundColor;
- fillType = toolSettings.commonFillType;
+ settings = toolSettings;
}
-
+
/**
* Returns name associated with this tool.
*
@@ -51,10 +47,11 @@ public class EllipseTool extends DragPaintSession implements PaintTool { */
protected Figure createFigure(Point a, Point b) {
ContainerFigure container = new ContainerFigure();
- if (fillType != ToolSettings.ftNone)
- container.add(new SolidEllipseFigure(drawBGColor, a.x, a.y, b.x, b.y));
- if (fillType != ToolSettings.ftSolid)
- container.add(new EllipseFigure(drawFGColor, a.x, a.y, b.x, b.y));
+ if (settings.commonFillType != ToolSettings.ftNone)
+ container.add(new SolidEllipseFigure(settings.commonBackgroundColor, a.x, a.y, b.x, b.y));
+ if (settings.commonFillType != ToolSettings.ftSolid)
+ container.add(new EllipseFigure(settings.commonForegroundColor, settings.commonLineStyle,
+ a.x, a.y, b.x, b.y));
return container;
}
}
diff --git a/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/Figure.java b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/Figure.java index e5d97a2e93..9a57aa5aa8 100755 --- a/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/Figure.java +++ b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/Figure.java @@ -15,49 +15,18 @@ import org.eclipse.swt.graphics.*; */
public abstract class Figure {
/**
- * Draws an object to the specified GC
- * <p>
- * The GC must be set up as follows (and must be returned to this state before returning)
- * <ul>
- * <li>setXORMode(false)
- * </ul>
- * </p>
+ * Draws this object.
*
- * @param gc the GC to draw on
- * @param offset the offset to add to virtual coordinates to get display coordinates
+ * @param fdc a parameter block specifying drawing-related information
*/
- public abstract void draw(GC gc, Point offset);
+ public abstract void draw(FigureDrawContext fdc);
/**
- * Draws a preview copy of the object to the specified GC
- * <p>
- * The GC must be set up as follows (and must be returned to this state before returning)
- * <ul>
- * <li>setXORMode(true)
- * <li>setForeground(new Color(display, 255, 255, 255))
- * <li>setBackground(new Color(display, 127, 127, 127))
- * </ul>
- * </p>
+ * Computes the damaged screen region caused by drawing this object (imprecise), then
+ * appends it to the supplied region.
*
- * @param gc the GC to draw on
- * @param offset the offset to add to virtual coordinates to get display coordinates
- * @return object state that must be passed to erasePreview() later to erase this object
+ * @param fdc a parameter block specifying drawing-related information
+ * @param region a region to which additional damage areas will be added
*/
- public abstract Object drawPreview(GC gc, Point offset);
-
- /**
- * Erases a preview copy of the object to the specified GC
- * <p>
- * Note that erasures are guaranteed to occur in the reverse order to the original drawing
- * order and that the GC's contents will be as they were when the drawPreview() that supplied
- * <code>rememberedState</code>returned.
- * </p><p>
- * The GC must be set up and restored as with drawPreview().
- * </p>
- *
- * @param gc the GC to draw on
- * @param offset the offset to add to virtual coordinates to get display coordinates
- * @param rememberedState the state returned by a previous drawPreview() using this instance
- */
- public abstract void erasePreview(GC gc, Point offset, Object rememberedState);
+ public abstract void addDamagedRegion(FigureDrawContext fdc, Region region);
}
diff --git a/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/FigureDrawContext.java b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/FigureDrawContext.java new file mode 100644 index 0000000000..eda60d25b8 --- /dev/null +++ b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/FigureDrawContext.java @@ -0,0 +1,34 @@ +package org.eclipse.swt.examples.paint;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import org.eclipse.swt.graphics.*;
+
+public class FigureDrawContext {
+ /*
+ * <p>
+ * The GC must be set up as follows
+ * (it will be returned to this state upon completion of drawing operations)
+ * <ul>
+ * <li>setXORMode(false)
+ * </ul>
+ * </p>
+ */
+ public GC gc = null;
+ public int xOffset = 0, yOffset = 0; // substract to get GC coords
+ public int xScale = 1, yScale = 1;
+
+ public Rectangle toClientRectangle(int x1, int y1, int x2, int y2) {
+ return new Rectangle(
+ Math.min(x1, x2) * xScale - xOffset,
+ Math.min(y1, y2) * yScale - yOffset,
+ (Math.abs(x2 - x1) + 1) * xScale,
+ (Math.abs(y2 - y1) + 1) * yScale);
+ }
+ public Point toClientPoint(int x, int y) {
+ return new Point(x * xScale - xOffset, y * yScale - yOffset);
+ }
+}
diff --git a/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/LineFigure.java b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/LineFigure.java index bce1421a0b..221f4eefc7 100755 --- a/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/LineFigure.java +++ b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/LineFigure.java @@ -5,32 +5,39 @@ package org.eclipse.swt.examples.paint; * All Rights Reserved
*/
+import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
/**
* 2D Line object
*/
-public class LineFigure extends StatelessXORFigureHelper {
+public class LineFigure extends Figure {
private Color color;
- private int x1, y1, x2, y2;
+ private int lineStyle, x1, y1, x2, y2;
/**
* Constructs a Line
* These objects are defined by their two end-points.
*
* @param color the color for this object
+ * @param lineStyle the line style for this object
* @param x1 the virtual X coordinate of the first end-point
* @param y1 the virtual Y coordinate of the first end-point
* @param x2 the virtual X coordinate of the second end-point
* @param y2 the virtual Y coordinate of the second end-point
*/
- public LineFigure(Color color, int x1, int y1, int x2, int y2) {
- this.color = color; this.x1 = x1; this.y1 = y1; this.x2 = x2; this.y2 = y2;
+ public LineFigure(Color color, int lineStyle, int x1, int y1, int x2, int y2) {
+ this.color = color; this.lineStyle = lineStyle;
+ this.x1 = x1; this.y1 = y1; this.x2 = x2; this.y2 = y2;
}
- public void draw(GC gc, Point offset) {
- gc.setForeground(color);
- gcDraw(gc, offset);
+ public void draw(FigureDrawContext fdc) {
+ Point p1 = fdc.toClientPoint(x1, y1);
+ Point p2 = fdc.toClientPoint(x2, y2);
+ fdc.gc.setForeground(color);
+ fdc.gc.setLineStyle(lineStyle);
+ fdc.gc.drawLine(p1.x, p1.y, p2.x, p2.y);
+ fdc.gc.setLineStyle(SWT.LINE_SOLID);
+ }
+ public void addDamagedRegion(FigureDrawContext fdc, Region region) {
+ region.add(fdc.toClientRectangle(x1, y1, x2, y2));
}
- protected void gcDraw(GC gc, Point offset) {
- gc.drawLine(x1 + offset.x, y1 + offset.y, x2 + offset.x, y2 + offset.y);
- }
}
diff --git a/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/LineTool.java b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/LineTool.java index 895155db45..ab9e9e598c 100755 --- a/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/LineTool.java +++ b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/LineTool.java @@ -11,8 +11,7 @@ import org.eclipse.swt.graphics.*; * A line drawing tool
*/
public class LineTool extends DragPaintSession implements PaintTool {
- private Color temporaryColor;
- private Color drawColor;
+ private ToolSettings settings;
/**
* Constructs a LineTool.
@@ -23,7 +22,6 @@ public class LineTool extends DragPaintSession implements PaintTool { public LineTool(ToolSettings toolSettings, PaintSurface paintSurface) {
super(paintSurface);
set(toolSettings);
- temporaryColor = new Color(null, 255, 255, 255);
}
/**
@@ -32,7 +30,7 @@ public class LineTool extends DragPaintSession implements PaintTool { * @param toolSettings the new tool settings
*/
public void set(ToolSettings toolSettings) {
- drawColor = toolSettings.commonForegroundColor;
+ settings = toolSettings;
}
/**
@@ -48,6 +46,7 @@ public class LineTool extends DragPaintSession implements PaintTool { * Template methods for drawing
*/
protected Figure createFigure(Point a, Point b) {
- return new LineFigure(drawColor, a.x, a.y, b.x, b.y);
+ return new LineFigure(settings.commonForegroundColor, settings.commonLineStyle,
+ a.x, a.y, b.x, b.y);
}
}
diff --git a/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/PaintSurface.java b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/PaintSurface.java index 149a7abcfe..52d6526792 100755 --- a/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/PaintSurface.java +++ b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/PaintSurface.java @@ -6,16 +6,8 @@ package org.eclipse.swt.examples.paint;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
/**
* Manages a simple drawing surface.
*/
public class PaintSurface {
private Point currentPosition = new Point(0, 0);
- private Canvas paintCanvas;
private PaintStatus paintStatus;
private PaintSession paintSession;
private Image image;
private Rectangle visibleRect;
private Rectangle imageRect;
private GC displayGC; // the GC used for drawing to the display
private GC rubberbandGC; // the GC used exclusively for rubberband drawing
private GC imageGC; // the GC used as a permanent backing store
private Color rubberbandFGColor, rubberbandBGColor;
private ContainerFigure rubberband; // the active rubberband selection
private Object rubberbandState; // the active rubberband selection previewing state
private int rubberbandHiddenNestingCount; // always >= 0, if > 0 rubberband has been hidden
/**
* Constructs a PaintSurface.
* <p>
* paintCanvas must have SWT.NO_REDRAW_RESIZE style, and may have SWT.V_SCROLL and/or SWT.H_SCROLL.
* </p>
* @param paintCanvas the Canvas object in which to render
* @param paintStatus the PaintStatus object to use for providing user feedback
*/
- public PaintSurface(Canvas paintCanvas, PaintStatus paintStatus) {
this.paintCanvas = paintCanvas;
this.paintStatus = paintStatus;
/* Set up the drawing surface */
visibleRect = paintCanvas.getClientArea();
imageRect = paintCanvas.getDisplay().getClientArea();
image = new Image(paintCanvas.getDisplay(), imageRect.width, imageRect.height);
imageGC = new GC(image);
displayGC = new GC(paintCanvas);
rubberbandGC = new GC(paintCanvas);
rubberbandGC.setXORMode(true);
rubberbandFGColor = new Color(paintCanvas.getDisplay(), 255, 255, 255);
rubberbandBGColor = new Color(paintCanvas.getDisplay(), 127, 127, 127);
rubberbandGC.setForeground(rubberbandFGColor);
rubberbandGC.setBackground(rubberbandBGColor);
rubberbandHiddenNestingCount = 0;
rubberbandState = null;
rubberband = new ContainerFigure();
/* Initialize the session */
setPaintSession(null);
/* Add our listeners */
paintCanvas.addMouseListener(new MouseAdapter() {
public void mouseDown(MouseEvent event) {
processMouseEventCoordinates(event);
if (paintSession != null) paintSession.mouseDown(event);
}
public void mouseUp(MouseEvent event) {
processMouseEventCoordinates(event);
if (paintSession != null) paintSession.mouseUp(event);
}
public void mouseDoubleClick(MouseEvent event) {
processMouseEventCoordinates(event);
if (paintSession != null) paintSession.mouseDoubleClick(event);
}
});
paintCanvas.addMouseMoveListener(new MouseMoveListener() {
public void mouseMove(MouseEvent event) {
processMouseEventCoordinates(event);
if (paintSession != null) paintSession.mouseMove(event);
}
});
paintCanvas.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent event) {
hideRubberband();
displayGC.drawImage(image,
visibleRect.x - imageRect.x, visibleRect.y - imageRect.y,
visibleRect.width, visibleRect.height, 0, 0, visibleRect.width, visibleRect.height);
showRubberband();
}
});
paintCanvas.addControlListener(new ControlAdapter() {
public void controlResized(ControlEvent event) {
handleResize();
}
});
/* Set up the paint canvas scroll bars */
ScrollBar horizontal = paintCanvas.getHorizontalBar();
horizontal.setVisible(true);
horizontal.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
scrollHorizontally((ScrollBar)event.widget);
}
});
ScrollBar vertical = paintCanvas.getVerticalBar();
vertical.setVisible(true);
vertical.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
scrollVertically((ScrollBar)event.widget);
}
});
handleResize();
}
/**
* Disposes of the PaintSurface's resources.
*/
public void dispose() {
imageGC.dispose();
displayGC.dispose();
rubberbandGC.dispose();
rubberbandFGColor.dispose();
rubberbandBGColor.dispose();
image.dispose();
}
/**
* Called when we must grab focus.
*/
public void setFocus() {
paintCanvas.setFocus();
}
/**
* Returns the Display on which the PaintSurface resides.
* @return the Display
*/
public Display getDisplay() {
return paintCanvas.getDisplay();
}
/**
* Returns the Shell in which the PaintSurface resides.
* @return the Shell
*/
public Shell getShell() {
return paintCanvas.getShell();
}
/**
- * Returns the display Graphics Context associated with this surface.
* <p>
* Use this GC to draw rubberband line and other temporary entities to the screen.
* They will not be committed to the backing store and hence will not be refreshed
* should the paint surface become obscured.
* </p>
- *
- * @return the display GC associated with this surface
- */
- public GC getDisplayGC() {
- return displayGC;
- }
-
/**
* Returns the image Graphics Context associated with this surface.
* <p>
* Use this GC to draw entities that are to be committed to the backing store.
* Anything drawn in this manner will persist and be refreshed as appropriate.
* </p>
*
* @return the image GC associated with this surface
*/
public GC getImageGC() {
return imageGC;
}
/**
* Returns the offset to be added to x and y coordinates in order to transform
* virtual paint surface coordinates into Display coordinates
*
* @return the offset
*/
public Point getDisplayOffset() {
return new Point(- visibleRect.x, - visibleRect.y);
}
/**
* Returns the offset to be added to x and y coordinates in order to transform
* virtual paint surface coordinates into Image coordinates
*
* @return the offset
*/
public Point getImageOffset() {
return new Point(- imageRect.x, - imageRect.y);
}
/**
+ private final Canvas paintCanvas;
private PaintSession paintSession;
private Image image;
private int imageWidth, imageHeight;
private int visibleWidth, visibleHeight;
private FigureDrawContext displayFDC = new FigureDrawContext();
private FigureDrawContext imageFDC = new FigureDrawContext();
/* Rubberband */
private ContainerFigure rubberband = new ContainerFigure();
// the active rubberband selection
private int rubberbandHiddenNestingCount = 0;
// always >= 0, if > 0 rubberband has been hidden
/* Status */
private final Text statusText;
private String statusActionInfo, statusMessageInfo, statusCoordInfo;
/**
* Constructs a PaintSurface.
* <p>
* paintCanvas must have SWT.NO_REDRAW_RESIZE and SWT.NO_BACKGROUND styles,
* and may have SWT.V_SCROLL and/or SWT.H_SCROLL.
* </p>
* @param paintCanvas the Canvas object in which to render
* @param paintStatus the PaintStatus object to use for providing user feedback
*/
+ public PaintSurface(Canvas paintCanvas, Text statusText) {
this.paintCanvas = paintCanvas;
this.statusText = statusText;
clearStatus();
/* Set up the drawing surface */
Rectangle displayRect = paintCanvas.getDisplay().getClientArea();
imageWidth = displayRect.width;
imageHeight = displayRect.height;
image = new Image(paintCanvas.getDisplay(), imageWidth, imageHeight);
imageFDC.gc = new GC(image);
displayFDC.gc = new GC(paintCanvas);
/* Initialize the session */
setPaintSession(null);
/* Add our listeners */
paintCanvas.addMouseListener(new MouseAdapter() {
public void mouseDown(MouseEvent event) {
processMouseEventCoordinates(event);
if (paintSession != null) paintSession.mouseDown(event);
}
public void mouseUp(MouseEvent event) {
processMouseEventCoordinates(event);
if (paintSession != null) paintSession.mouseUp(event);
}
public void mouseDoubleClick(MouseEvent event) {
processMouseEventCoordinates(event);
if (paintSession != null) paintSession.mouseDoubleClick(event);
}
});
paintCanvas.addMouseMoveListener(new MouseMoveListener() {
public void mouseMove(MouseEvent event) {
processMouseEventCoordinates(event);
if (paintSession != null) paintSession.mouseMove(event);
}
});
paintCanvas.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent event) {
if (rubberband.isEmpty()) {
event.gc.drawImage(image,
displayFDC.xOffset, displayFDC.yOffset, visibleWidth, visibleHeight,
0, 0, visibleWidth, visibleHeight);
} else {
// avoid flicker
Rectangle clip = event.gc.getClipping();
Image blitImage = new Image(getDisplay(), event.width, event.height);
FigureDrawContext fdc = new FigureDrawContext();
fdc.gc = new GC(blitImage);
fdc.xOffset = displayFDC.xOffset + clip.x;
fdc.yOffset = displayFDC.yOffset + clip.y;
fdc.gc.drawImage(image,
clip.x + displayFDC.xOffset, clip.y + displayFDC.yOffset, clip.width, clip.height,
0, 0, clip.width, clip.height);
rubberband.draw(fdc);
fdc.gc.dispose();
event.gc.drawImage(blitImage, clip.x, clip.y);
blitImage.dispose();
}
}
});
paintCanvas.addControlListener(new ControlAdapter() {
public void controlResized(ControlEvent event) {
handleResize();
}
});
/* Set up the paint canvas scroll bars */
ScrollBar horizontal = paintCanvas.getHorizontalBar();
horizontal.setVisible(true);
horizontal.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
scrollHorizontally((ScrollBar)event.widget);
}
});
ScrollBar vertical = paintCanvas.getVerticalBar();
vertical.setVisible(true);
vertical.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
scrollVertically((ScrollBar)event.widget);
}
});
handleResize();
}
/**
* Disposes of the PaintSurface's resources.
*/
public void dispose() {
imageFDC.gc.dispose();
displayFDC.gc.dispose();
image.dispose();
}
/**
* Called when we must grab focus.
*/
public void setFocus() {
paintCanvas.setFocus();
}
/**
* Returns the Display on which the PaintSurface resides.
* @return the Display
*/
public Display getDisplay() {
return paintCanvas.getDisplay();
}
/**
* Returns the Shell in which the PaintSurface resides.
* @return the Shell
*/
public Shell getShell() {
return paintCanvas.getShell();
}
/**
* Sets the current paint session.
* <p>
* If oldPaintSession != paintSession calls oldPaintSession.end()
* and paintSession.begin()
* </p>
*
* @param paintSession the paint session to activate; null to disable all sessions
@@ -24,7 +16,7 @@ public class PaintSurface {
private Point currentPosition = new Point(0, 0); if (this.paintSession != null) {
if (this.paintSession == paintSession) return;
this.paintSession.endSession();
}
this.paintSession = paintSession;
- paintStatus.clear();
if (paintSession != null) {
paintStatus.setAction(paintSession.getDisplayName());
paintSession.beginSession();
} else {
paintStatus.setAction(PaintPlugin.getResourceString("tool.Null.displayname"));
paintStatus.setMessage(PaintPlugin.getResourceString("session.Null.message"));
}
}
+ clearStatus();
if (paintSession != null) {
setStatusAction(paintSession.getDisplayName());
paintSession.beginSession();
} else {
setStatusAction(PaintPlugin.getResourceString("tool.Null.displayname"));
setStatusMessage(PaintPlugin.getResourceString("session.Null.message"));
}
}
/**
* Returns the current paint session.
@@ -34,5 +26,4 @@ public class PaintSurface {
private Point currentPosition = new Point(0, 0); public PaintSession getPaintSession() {
return paintSession;
}
-
/**
* Returns the current paint status object.
*
* @return the current paint status object
*/
public PaintStatus getPaintStatus() {
return paintStatus;
}
/**
* Returns the current paint tool.
*
* @return the current paint tool, null if none is active (though some other session
* might be)
*/
public PaintTool getPaintTool() {
return (paintSession != null && paintSession instanceof PaintTool) ?
(PaintTool)paintSession : null;
}
/**
* Returns the current position in an interactive operation.
*
* @return the last known position of the pointer
*/
public Point getCurrentPosition() {
return currentPosition;
}
/**
* Redraws a specified rectangular area using the backing store
*
* @param x the left X virtual coordinate of the region
* @param y the top Y virtual coordinate of the region
* @param width the width of the region
* @param height the height of the region
* @see getImageGC()
*/
public void redrawArea(int x, int y, int width, int height) {
// Clip to image and screen [computes intersection of the rectangles]
final int clipX = Math.max(imageRect.x, visibleRect.x);
if (x < clipX) {
width -= clipX - x;
x = clipX;
}
final int clipY = Math.max(imageRect.y, visibleRect.y);
if (y < clipY) {
height -= clipY - y;
y = clipY;
}
final int clipWidth = Math.min(imageRect.width, visibleRect.width) + clipX - x;
if (width > clipWidth) width = clipWidth;
final int clipHeight = Math.min(imageRect.height, visibleRect.height) + clipY - y;
if (height > clipHeight) height = clipHeight;
if (width < 0 || height < 0) return;
// Redraw the region
hideRubberband();
displayGC.drawImage(image, x - imageRect.x, y - imageRect.y, width, height,
x - visibleRect.x, y - visibleRect.y, width, height);
showRubberband();
}
-
/**
* Draws a Figure object to the screen and to the backing store permanently.
*
* @param object the object to draw onscreen
*/
public void drawFigure(Figure object) {
object.draw(getImageGC(), getImageOffset());
object.draw(getDisplayGC(), getDisplayOffset());
}
/**
* Adds a Figure object to the active rubberband selection.
* <p>
* This object will be drawn to the screen as a preview and refreshed appropriately
* until the selection is either cleared or committed.
* </p>
*
* @param object the object to add to the selection
*/
public void addRubberbandSelection(Figure object) {
if (isRubberbandHidden()) {
rubberband.add(object);
} else {
rubberbandState = rubberband.addAndPreview(object, rubberbandGC,
getDisplayOffset(), rubberbandState);
}
}
/**
* Clears the active rubberband selection.
* <p>
* Erases any rubberband objects on the screen then clears the selection.
* </p>
*/
public void clearRubberbandSelection() {
if (! isRubberbandHidden()) {
rubberband.erasePreview(rubberbandGC, getDisplayOffset(), rubberbandState);
rubberbandState = null;
}
rubberband.clear();
}
/**
* Commits the active rubberband selection.
* <p>
* Redraws any rubberband objects on the screen as permanent objects then clears the selection.
* </p>
*/
public void commitRubberbandSelection() {
if (! isRubberbandHidden()) {
rubberband.erasePreview(rubberbandGC, getDisplayOffset(), rubberbandState);
rubberbandState = null;
}
drawFigure(rubberband);
rubberband.clear();
}
/**
* Hides the rubberband (but does not eliminate it).
* <p>
* Increments by one the rubberband "hide" nesting count. The rubberband
* is hidden from view (but remains active) if it wasn't already hidden.
* </p>
*/
public void hideRubberband() {
if (rubberbandHiddenNestingCount++ <= 0) {
rubberband.erasePreview(rubberbandGC, getDisplayOffset(), rubberbandState);
rubberbandState = null;
}
}
/**
* Shows (un-hides) the rubberband.
* <p>
* Decrements by one the rubberband "hide" nesting count. The rubberband
* is only made visible when showRubberband() has been called once for each
* previous hideRubberband(). It is not permitted to call showRubberband() if
* the rubber band is not presently hidden.
* </p>
*/
public void showRubberband() {
if (rubberbandHiddenNestingCount <= 0)
throw new IllegalStateException("rubberbandHiddenNestingCount > 0");
if (--rubberbandHiddenNestingCount == 0) {
rubberbandState = rubberband.drawPreview(rubberbandGC, getDisplayOffset());
}
}
/**
* Determines if the rubberband is hidden.
*
* @return true iff the rubber is hidden
*/
public boolean isRubberbandHidden() {
return rubberbandHiddenNestingCount > 0;
}
/**
* Displays the current position in the status bar.
*/
public void showCurrentPositionStatus() {
paintStatus.setCoord(currentPosition);
}
/**
* Displays the current position in the status bar.
*/
public void showCurrentRangeStatus(Point anchorPosition) {
paintStatus.setCoordRange(anchorPosition, currentPosition);
}
/**
* Handles a horizontal scroll event
*
* @param scrollbar the horizontal scroll bar that posted this event
*/
public void scrollHorizontally(ScrollBar scrollBar) {
if (image == null) return;
if (imageRect.width > visibleRect.width) {
final int oldx = visibleRect.x;
visibleRect.x = Math.min(scrollBar.getSelection(), imageRect.width - visibleRect.width);
paintCanvas.scroll(Math.max(oldx - visibleRect.x, 0), 0, Math.max(visibleRect.x - oldx, 0), 0,
visibleRect.width, visibleRect.height, false);
}
}
/**
* Handles a vertical scroll event
*
* @param scrollbar the vertical scroll bar that posted this event
*/
public void scrollVertically(ScrollBar scrollBar) {
if (image == null) return;
if (imageRect.height > visibleRect.height) {
final int oldy = visibleRect.y;
visibleRect.y = Math.min(scrollBar.getSelection(), imageRect.height - visibleRect.height);
paintCanvas.scroll(0, Math.max(oldy - visibleRect.y, 0), 0, Math.max(visibleRect.y - oldy, 0),
visibleRect.width, visibleRect.height, false);
}
}
/**
* Handles resize events
*/
private void handleResize() {
visibleRect = paintCanvas.getClientArea();
ScrollBar horizontal = paintCanvas.getHorizontalBar();
if (horizontal != null) {
visibleRect.x = Math.min(horizontal.getSelection(), imageRect.width - visibleRect.width);
if (imageRect.width <= visibleRect.width) {
horizontal.setEnabled(false);
horizontal.setSelection(0);
} else {
final int max = imageRect.width - visibleRect.width;
horizontal.setEnabled(true);
horizontal.setValues(visibleRect.x, 0, imageRect.width, visibleRect.width,
8, visibleRect.width);
}
}
ScrollBar vertical = paintCanvas.getVerticalBar();
if (vertical != null) {
visibleRect.y = Math.min(vertical.getSelection(), imageRect.height - visibleRect.height);
if (imageRect.height <= visibleRect.height) {
vertical.setEnabled(false);
vertical.setSelection(0);
} else {
final int max = imageRect.height - visibleRect.height;
vertical.setEnabled(true);
vertical.setValues(visibleRect.y, 0, imageRect.height, visibleRect.height,
8, visibleRect.height);
}
}
}
/**
* Virtualizes MouseEvent coordinates and stores the current position.
*/
private void processMouseEventCoordinates(MouseEvent event) {
currentPosition.x = event.x =
Math.min(Math.max(event.x, 0), visibleRect.width - 1) + visibleRect.x;
currentPosition.y = event.y =
Math.min(Math.max(event.y, 0), visibleRect.height - 1) + visibleRect.y;
}
}
+
/**
* Returns the current paint tool.
*
* @return the current paint tool, null if none is active (though some other session
* might be)
*/
public PaintTool getPaintTool() {
return (paintSession != null && paintSession instanceof PaintTool) ?
(PaintTool)paintSession : null;
}
/**
* Returns the current position in an interactive operation.
*
* @return the last known position of the pointer
*/
public Point getCurrentPosition() {
return currentPosition;
}
/**
* Draws a Figure object to the screen and to the backing store permanently.
*
* @param object the object to draw onscreen
*/
public void drawFigure(Figure object) {
object.draw(imageFDC);
object.draw(displayFDC);
}
/**
* Adds a Figure object to the active rubberband selection.
* <p>
* This object will be drawn to the screen as a preview and refreshed appropriately
* until the selection is either cleared or committed.
* </p>
*
* @param object the object to add to the selection
*/
public void addRubberbandSelection(Figure object) {
rubberband.add(object);
if (! isRubberbandHidden()) object.draw(displayFDC);
}
/**
* Clears the active rubberband selection.
* <p>
* Erases any rubberband objects on the screen then clears the selection.
* </p>
*/
public void clearRubberbandSelection() {
if (! isRubberbandHidden()) {
Region region = new Region();
rubberband.addDamagedRegion(displayFDC, region);
Rectangle r = region.getBounds();
paintCanvas.redraw(r.x, r.y, r.width, r.height, true);
region.dispose();
}
rubberband.clear();
}
/**
* Commits the active rubberband selection.
* <p>
* Redraws any rubberband objects on the screen as permanent objects then clears the selection.
* </p>
*/
public void commitRubberbandSelection() {
rubberband.draw(imageFDC);
if (isRubberbandHidden()) rubberband.draw(displayFDC);
rubberband.clear();
}
/**
* Hides the rubberband (but does not eliminate it).
* <p>
* Increments by one the rubberband "hide" nesting count. The rubberband
* is hidden from view (but remains active) if it wasn't already hidden.
* </p>
*/
public void hideRubberband() {
if (rubberbandHiddenNestingCount++ <= 0) {
Region region = new Region();
rubberband.addDamagedRegion(displayFDC, region);
Rectangle r = region.getBounds();
paintCanvas.redraw(r.x, r.y, r.width, r.height, true);
region.dispose();
}
}
/**
* Shows (un-hides) the rubberband.
* <p>
* Decrements by one the rubberband "hide" nesting count. The rubberband
* is only made visible when showRubberband() has been called once for each
* previous hideRubberband(). It is not permitted to call showRubberband() if
* the rubber band is not presently hidden.
* </p>
*/
public void showRubberband() {
if (rubberbandHiddenNestingCount <= 0)
throw new IllegalStateException("rubberbandHiddenNestingCount > 0");
if (--rubberbandHiddenNestingCount == 0) {
rubberband.draw(displayFDC);
}
}
/**
* Determines if the rubberband is hidden.
*
* @return true iff the rubber is hidden
*/
public boolean isRubberbandHidden() {
return rubberbandHiddenNestingCount > 0;
}
/**
* Handles a horizontal scroll event
*
* @param scrollbar the horizontal scroll bar that posted this event
*/
public void scrollHorizontally(ScrollBar scrollBar) {
if (image == null) return;
if (imageWidth > visibleWidth) {
final int oldx = displayFDC.xOffset;
displayFDC.xOffset = Math.min(scrollBar.getSelection(), imageWidth - visibleWidth);
paintCanvas.scroll(Math.max(oldx - displayFDC.xOffset, 0), 0, Math.max(displayFDC.xOffset - oldx, 0), 0,
visibleWidth, visibleHeight, false);
}
}
/**
* Handles a vertical scroll event
*
* @param scrollbar the vertical scroll bar that posted this event
*/
public void scrollVertically(ScrollBar scrollBar) {
if (image == null) return;
if (imageHeight > visibleHeight) {
final int oldy = displayFDC.yOffset;
displayFDC.yOffset = Math.min(scrollBar.getSelection(), imageHeight - visibleHeight);
paintCanvas.scroll(0, Math.max(oldy - displayFDC.yOffset, 0), 0, Math.max(displayFDC.yOffset - oldy, 0),
visibleWidth, visibleHeight, false);
}
}
/**
* Handles resize events
*/
private void handleResize() {
Rectangle visibleRect = paintCanvas.getClientArea();
visibleWidth = visibleRect.width;
visibleHeight = visibleRect.height;
ScrollBar horizontal = paintCanvas.getHorizontalBar();
if (horizontal != null) {
displayFDC.xOffset = Math.min(horizontal.getSelection(), imageWidth - visibleWidth);
if (imageWidth <= visibleWidth) {
horizontal.setEnabled(false);
horizontal.setSelection(0);
} else {
final int max = imageWidth - visibleWidth;
horizontal.setEnabled(true);
horizontal.setValues(displayFDC.xOffset, 0, imageWidth, visibleWidth,
8, visibleWidth);
}
}
ScrollBar vertical = paintCanvas.getVerticalBar();
if (vertical != null) {
displayFDC.yOffset = Math.min(vertical.getSelection(), imageHeight - visibleHeight);
if (imageHeight <= visibleHeight) {
vertical.setEnabled(false);
vertical.setSelection(0);
} else {
final int max = imageHeight - visibleHeight;
vertical.setEnabled(true);
vertical.setValues(displayFDC.yOffset, 0, imageHeight, visibleHeight,
8, visibleHeight);
}
}
}
/**
* Virtualizes MouseEvent coordinates and stores the current position.
*/
private void processMouseEventCoordinates(MouseEvent event) {
currentPosition.x = event.x =
Math.min(Math.max(event.x, 0), visibleWidth - 1) + displayFDC.xOffset;
currentPosition.y = event.y =
Math.min(Math.max(event.y, 0), visibleHeight - 1) + displayFDC.yOffset;
}
/**
* Clears the status bar.
*/
public void clearStatus() {
statusActionInfo = "";
statusMessageInfo = "";
statusCoordInfo = "";
updateStatus();
}
/**
* Sets the status bar action text.
*
* @param action the action in progress, null to clear
*/
public void setStatusAction(String action) {
statusActionInfo = (action != null) ? action : "";
updateStatus();
}
/**
* Sets the status bar message text.
*
* @param message the message to display, null to clear
*/
public void setStatusMessage(String message) {
statusMessageInfo = (message != null) ? message : "";
updateStatus();
}
/**
* Sets the coordinates in the status bar.
*
* @param coord the coordinates to display, null to clear
*/
public void setStatusCoord(Point coord) {
statusCoordInfo = (coord != null) ? PaintPlugin.getResourceString("status.Coord.format", new Object[]
{ new Integer(coord.x), new Integer(coord.y)}) : "";
updateStatus();
}
/**
* Sets the coordinate range in the status bar.
*
* @param a the "from" coordinate, must not be null
* @param b the "to" coordinate, must not be null
*/
public void setStatusCoordRange(Point a, Point b) {
statusCoordInfo = PaintPlugin.getResourceString("status.CoordRange.format", new Object[]
{ new Integer(a.x), new Integer(a.y), new Integer(b.x), new Integer(b.y)});
updateStatus();
}
/**
* Updates the display.
*/
private void updateStatus() {
statusText.setText(
PaintPlugin.getResourceString("status.Bar.format", new Object[]
{ statusActionInfo, statusMessageInfo, statusCoordInfo }));
}
}
diff --git a/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/PaintView.java b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/PaintView.java index 4ac8af08ea..6f7ecdb4bc 100755 --- a/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/PaintView.java +++ b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/PaintView.java @@ -33,18 +33,18 @@ public class PaintView extends ViewPart { // paint surface for drawing
private PaintSurface paintSurface;
- // status information
- private PaintStatus paintStatus;
-
// map action ids to useful data
private HashMap /* of String to PaintTool */ paintToolMap;
private HashMap /* of String to Integer */ paintFillTypeMap;
+ private HashMap /* of String to Integer */ paintLineStyleMap;
/** UI data **/
// handle of currently active tool IAction on the UI
private IAction activeToolAction;
// handle of currently active filltype IAction on the UI
private IAction activeFillTypeAction;
+ // handle of currently active linetype IAction on the UI
+ private IAction activeLineStyleAction;
// handle of active foreground color box Canvas widget
private Canvas activeForegroundColorCanvas;
@@ -87,7 +87,7 @@ public class PaintView extends ViewPart { *
* @see org.eclipse.ui.part.ViewPart#setFocus
*/
- public void setFocus() {
+ public void setFocus() {
paintSurface.setFocus();
}
@@ -132,11 +132,18 @@ public class PaintView extends ViewPart { toolbarManager.appendToGroup("group.tools", new SelectPaintToolAction("tool.Ellipse"));
toolbarManager.appendToGroup("group.tools", new SelectPaintToolAction("tool.Text"));
toolbarManager.add(new Separator());
- toolbarManager.add(new GroupMarker("group.options"));
- toolbarManager.appendToGroup("group.options", new SelectFillTypeAction("fill.None"));
- toolbarManager.appendToGroup("group.options", new SelectFillTypeAction("fill.Outline"));
- toolbarManager.appendToGroup("group.options", new SelectFillTypeAction("fill.Solid"));
+ toolbarManager.add(new GroupMarker("group.options.fill"));
+ toolbarManager.appendToGroup("group.options.fill", new SelectFillTypeAction("fill.None"));
+ toolbarManager.appendToGroup("group.options.fill", new SelectFillTypeAction("fill.Outline"));
+ toolbarManager.appendToGroup("group.options.fill", new SelectFillTypeAction("fill.Solid"));
toolbarManager.add(new Separator());
+ toolbarManager.add(new GroupMarker("group.options.linestyle"));
+ toolbarManager.appendToGroup("group.options.linestyle", new SelectLineStyleAction("linestyle.Solid"));
+ toolbarManager.appendToGroup("group.options.linestyle", new SelectLineStyleAction("linestyle.Dash"));
+ toolbarManager.appendToGroup("group.options.linestyle", new SelectLineStyleAction("linestyle.Dot"));
+ toolbarManager.appendToGroup("group.options.linestyle", new SelectLineStyleAction("linestyle.DashDot"));
+ toolbarManager.add(new Separator());
+ toolbarManager.add(new GroupMarker("group.options"));
toolbarManager.appendToGroup("group.options", new SelectFontAction("options.Font"));
actionBars.updateActionBars();
@@ -146,6 +153,7 @@ public class PaintView extends ViewPart { /*** Set defaults ***/
setPaintToolByID("tool.Pencil");
setFillTypeByID("fill.None");
+ setLineStyleByID("linestyle.Solid");
setForegroundColor(paintColorBlack);
setBackgroundColor(paintColorWhite);
}
@@ -172,7 +180,7 @@ public class PaintView extends ViewPart { // paint canvas
final Canvas paintCanvas = new Canvas(displayArea, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL |
- SWT.NO_REDRAW_RESIZE);
+ SWT.NO_REDRAW_RESIZE | SWT.NO_BACKGROUND);
gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
paintCanvas.setLayoutData(gridData);
paintCanvas.setBackground(paintColorWhite);
@@ -193,11 +201,8 @@ public class PaintView extends ViewPart { statusText.setLayoutData(gridData);
/*** Create the remaining application elements inside the principal GUI layout elements ***/
- // paintStatus
- paintStatus = new PaintStatus(statusText);
-
// paintSurface
- paintSurface = new PaintSurface(paintCanvas, paintStatus);
+ paintSurface = new PaintSurface(paintCanvas, statusText);
// paintToolMap
paintToolMap = new HashMap();
@@ -217,6 +222,13 @@ public class PaintView extends ViewPart { paintFillTypeMap.put("fill.Outline", new Integer(ToolSettings.ftOutline));
paintFillTypeMap.put("fill.Solid", new Integer(ToolSettings.ftSolid));
+ // paintLineStyleMap
+ paintLineStyleMap = new HashMap();
+ paintLineStyleMap.put("linestyle.Solid", new Integer(SWT.LINE_SOLID));
+ paintLineStyleMap.put("linestyle.Dash", new Integer(SWT.LINE_DASH));
+ paintLineStyleMap.put("linestyle.Dot", new Integer(SWT.LINE_DOT));
+ paintLineStyleMap.put("linestyle.DashDot", new Integer(SWT.LINE_DASHDOT));
+
// colorFrame
gridLayout = new GridLayout();
gridLayout.numColumns = 3;
@@ -238,7 +250,7 @@ public class PaintView extends ViewPart { activeBackgroundColorCanvas.setLayoutData(gridData);
// paletteCanvas
- final Canvas paletteCanvas = new Canvas(colorFrame, SWT.BORDER);
+ final Canvas paletteCanvas = new Canvas(colorFrame, SWT.BORDER | SWT.NO_BACKGROUND);
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.heightHint = 24;
paletteCanvas.setLayoutData(gridData);
@@ -355,12 +367,7 @@ public class PaintView extends ViewPart { * Selects a tool given its ID.
*/
public void setPaintToolByID(String id) {
- if (activeToolAction != null) activeToolAction.setChecked(false);
- IAction action = getActionByID(id);
- if (action != null) {
- activeToolAction = action;
- if (! action.isChecked()) action.setChecked(true);
- }
+ activeToolAction = handleRadioAction(activeToolAction, id);
final PaintTool paintTool = (PaintTool) paintToolMap.get(id);
paintSurface.setPaintSession(paintTool);
@@ -371,12 +378,7 @@ public class PaintView extends ViewPart { * Selects a filltype given its ID.
*/
public void setFillTypeByID(String id) {
- if (activeFillTypeAction != null) activeFillTypeAction.setChecked(false);
- IAction action = getActionByID(id);
- if (action != null) {
- activeFillTypeAction = action;
- if (! action.isChecked()) action.setChecked(true);
- }
+ activeFillTypeAction = handleRadioAction(activeFillTypeAction, id);
final Integer fillType = (Integer) paintFillTypeMap.get(id);
toolSettings.commonFillType = fillType.intValue();
@@ -384,6 +386,31 @@ public class PaintView extends ViewPart { }
/**
+ * Selects line type given its ID.
+ */
+ public void setLineStyleByID(String id) {
+ activeLineStyleAction = handleRadioAction(activeLineStyleAction, id);
+
+ final Integer lineType = (Integer) paintLineStyleMap.get(id);
+ toolSettings.commonLineStyle = lineType.intValue();
+ updateToolSettings();
+ }
+
+ /**
+ * Gets the IAction for an ID belonging to a set of mutually exclusive actions, and
+ * toggles the old action off if necessary.
+ */
+ private IAction handleRadioAction(IAction oldAction, String id) {
+ IAction action = getActionByID(id);
+ if (action != null) {
+ if (oldAction != null) oldAction.setChecked(false);
+ if (! action.isChecked()) action.setChecked(true);
+ return action;
+ }
+ return oldAction;
+ }
+
+ /**
* Gets the IAction representing the UI toolbar button with the specified ID.
*/
private IAction getActionByID(String id) {
@@ -435,6 +462,11 @@ public class PaintView extends ViewPart { public int getStyle() { return IAction.AS_CHECK_BOX; }
public void run() { setFillTypeByID(getId()); }
}
+ class SelectLineStyleAction extends PaintAction {
+ public SelectLineStyleAction(String id) { super(id); }
+ public int getStyle() { return IAction.AS_CHECK_BOX; }
+ public void run() { setLineStyleByID(getId()); }
+ }
class SelectFontAction extends PaintAction {
public SelectFontAction(String id) { super(id); }
public int getStyle() { return IAction.AS_PUSH_BUTTON; }
diff --git a/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/PencilTool.java b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/PencilTool.java index c86722fa99..69f52d8612 100755 --- a/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/PencilTool.java +++ b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/PencilTool.java @@ -11,7 +11,7 @@ import java.util.Random;
import org.eclipse.swt.graphics.*; * A pencil tool.
*/
public class PencilTool extends ContinuousPaintSession implements PaintTool {
- private Color drawColor;
+ private ToolSettings settings;
/**
* Constructs a pencil tool.
@@ -30,7 +30,7 @@ public class PencilTool extends ContinuousPaintSession implements PaintTool { * @param toolSettings the new tool settings
*/
public void set(ToolSettings toolSettings) {
- drawColor = toolSettings.commonForegroundColor;
+ settings = toolSettings;
}
/**
@@ -47,13 +47,6 @@ public class PencilTool extends ContinuousPaintSession implements PaintTool { */
public void render(final Point point) {
final PaintSurface ps = getPaintSurface();
- final GC igc = ps.getImageGC();
- final Point ioff = ps.getImageOffset();
- final GC dgc = ps.getDisplayGC();
- final Point doff = ps.getDisplayOffset();
- igc.setBackground(drawColor);
- igc.fillRectangle(point.x + ioff.x, point.y + ioff.y, 1, 1);
- dgc.setBackground(drawColor);
- dgc.fillRectangle(point.x + doff.x, point.y + doff.y, 1, 1);
+ ps.drawFigure(new PointFigure(settings.commonForegroundColor, point.x, point.y));
}
}
diff --git a/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/PointFigure.java b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/PointFigure.java new file mode 100644 index 0000000000..a93da19f9c --- /dev/null +++ b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/PointFigure.java @@ -0,0 +1,34 @@ +package org.eclipse.swt.examples.paint;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import org.eclipse.swt.graphics.*;
+
+/**
+ * 2D Point object
+ */
+public class PointFigure extends Figure {
+ private Color color;
+ private int x, y;
+ /**
+ * Constructs a Point
+ *
+ * @param color the color for this object
+ * @param x the virtual X coordinate of the first end-point
+ * @param y the virtual Y coordinate of the first end-point
+ */
+ public PointFigure(Color color, int x, int y) {
+ this.color = color; this.x = x; this.y = y;
+ }
+ public void draw(FigureDrawContext fdc) {
+ Point p = fdc.toClientPoint(x, y);
+ fdc.gc.setBackground(color);
+ fdc.gc.fillRectangle(p.x, p.y, 1, 1);
+ }
+ public void addDamagedRegion(FigureDrawContext fdc, Region region) {
+ region.add(fdc.toClientRectangle(x, y, x, y));
+ }
+}
diff --git a/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/PolyLineTool.java b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/PolyLineTool.java index ef5c2c3ee4..28ad66c00e 100755 --- a/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/PolyLineTool.java +++ b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/PolyLineTool.java @@ -11,9 +11,7 @@ import org.eclipse.swt.graphics.*; * A polyline drawing tool.
*/
public class PolyLineTool extends SegmentedPaintSession implements PaintTool {
- private Color drawFGColor;
- private Color drawBGColor;
- private int fillType;
+ private ToolSettings settings;
/**
* Constructs a PolyLineTool.
@@ -32,9 +30,7 @@ public class PolyLineTool extends SegmentedPaintSession implements PaintTool { * @param toolSettings the new tool settings
*/
public void set(ToolSettings toolSettings) {
- drawFGColor = toolSettings.commonForegroundColor;
- drawBGColor = toolSettings.commonBackgroundColor;
- fillType = toolSettings.commonFillType;
+ settings = toolSettings;
}
/**
@@ -51,19 +47,21 @@ public class PolyLineTool extends SegmentedPaintSession implements PaintTool { */
protected Figure createFigure(Point[] points, int numPoints, boolean closed) {
ContainerFigure container = new ContainerFigure();
- if (closed && fillType != ToolSettings.ftNone && numPoints >= 3) {
- container.add(new SolidPolygonFigure(drawBGColor, points, numPoints));
+ if (closed && settings.commonFillType != ToolSettings.ftNone && numPoints >= 3) {
+ container.add(new SolidPolygonFigure(settings.commonBackgroundColor, points, numPoints));
}
- if (! closed || fillType != ToolSettings.ftSolid || numPoints < 3) {
+ if (! closed || settings.commonFillType != ToolSettings.ftSolid || numPoints < 3) {
for (int i = 0; i < numPoints - 1; ++i) {
final Point a = points[i];
final Point b = points[i + 1];
- container.add(new LineFigure(drawFGColor, a.x, a.y, b.x, b.y));
+ container.add(new LineFigure(settings.commonForegroundColor, settings.commonLineStyle,
+ a.x, a.y, b.x, b.y));
}
if (closed) {
final Point a = points[points.length - 1];
final Point b = points[0];
- container.add(new LineFigure(drawFGColor, a.x, a.y, b.x, b.y));
+ container.add(new LineFigure(settings.commonForegroundColor, settings.commonLineStyle,
+ a.x, a.y, b.x, b.y));
}
}
return container;
diff --git a/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/RectangleFigure.java b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/RectangleFigure.java index 205f53bf18..d6073f3f31 100755 --- a/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/RectangleFigure.java +++ b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/RectangleFigure.java @@ -5,33 +5,38 @@ package org.eclipse.swt.examples.paint; * All Rights Reserved
*/
+import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
/**
* 2D Rectangle object
*/
-public class RectangleFigure extends StatelessXORFigureHelper {
+public class RectangleFigure extends Figure {
private Color color;
- private int x1, y1, x2, y2;
+ private int lineStyle, x1, y1, x2, y2;
/**
* Constructs a Rectangle
* These objects are defined by any two diametrically opposing corners.
*
* @param color the color for this object
+ * @param lineStyle the line style for this object
* @param x1 the virtual X coordinate of the first corner
* @param y1 the virtual Y coordinate of the first corner
* @param x2 the virtual X coordinate of the second corner
* @param y2 the virtual Y coordinate of the second corner
*/
- public RectangleFigure(Color color, int x1, int y1, int x2, int y2) {
- this.color = color; this.x1 = x1; this.y1 = y1; this.x2 = x2; this.y2 = y2;
+ public RectangleFigure(Color color, int lineStyle, int x1, int y1, int x2, int y2) {
+ this.color = color; this.lineStyle = lineStyle;
+ this.x1 = x1; this.y1 = y1; this.x2 = x2; this.y2 = y2;
}
- public void draw(GC gc, Point offset) {
- gc.setForeground(color);
- gcDraw(gc, offset);
+ public void draw(FigureDrawContext fdc) {
+ Rectangle r = fdc.toClientRectangle(x1, y1, x2, y2);
+ fdc.gc.setForeground(color);
+ fdc.gc.setLineStyle(lineStyle);
+ fdc.gc.drawRectangle(r.x, r.y, r.width - 1, r.height - 1);
+ fdc.gc.setLineStyle(SWT.LINE_SOLID);
+ }
+ public void addDamagedRegion(FigureDrawContext fdc, Region region) {
+ region.add(fdc.toClientRectangle(x1, y1, x2, y2));
}
- protected void gcDraw(GC gc, Point offset) {
- gc.drawRectangle(Math.min(x1, x2) + offset.x, Math.min(y1, y2) + offset.y,
- Math.abs(x2 - x1), Math.abs(y2 - y1));
- }
}
diff --git a/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/RectangleTool.java b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/RectangleTool.java index e1281a5555..aa8726a769 100755 --- a/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/RectangleTool.java +++ b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/RectangleTool.java @@ -11,9 +11,7 @@ import org.eclipse.swt.graphics.*; * A drawing tool.
*/
public class RectangleTool extends DragPaintSession implements PaintTool {
- private Color drawFGColor;
- private Color drawBGColor;
- private int fillType;
+ private ToolSettings settings;
/**
* Constructs a RectangleTool.
@@ -32,9 +30,7 @@ public class RectangleTool extends DragPaintSession implements PaintTool { * @param toolSettings the new tool settings
*/
public void set(ToolSettings toolSettings) {
- drawFGColor = toolSettings.commonForegroundColor;
- drawBGColor = toolSettings.commonBackgroundColor;
- fillType = toolSettings.commonFillType;
+ settings = toolSettings;
}
/**
@@ -50,18 +46,18 @@ public class RectangleTool extends DragPaintSession implements PaintTool { * Template method for drawing
*/
protected Figure createFigure(Point a, Point b) {
- switch (fillType) {
+ switch (settings.commonFillType) {
default:
case ToolSettings.ftNone:
- return new RectangleFigure(drawFGColor, a.x, a.y, b.x, b.y);
+ return new RectangleFigure(settings.commonForegroundColor, settings.commonLineStyle,
+ a.x, a.y, b.x, b.y);
case ToolSettings.ftSolid:
- return new SolidRectangleFigure(drawBGColor, a.x, a.y, b.x, b.y);
+ return new SolidRectangleFigure(settings.commonBackgroundColor, a.x, a.y, b.x, b.y);
case ToolSettings.ftOutline: {
ContainerFigure container = new ContainerFigure();
- container.add(new RectangleFigure(drawFGColor, a.x, a.y, b.x, b.y));
- container.add(new SolidRectangleFigure(drawBGColor,
- Math.min(a.x, b.x) + 1, Math.min(a.y, b.y) + 1,
- Math.max(a.x, b.x) - 1, Math.max(a.y, b.y) - 1));
+ container.add(new SolidRectangleFigure(settings.commonBackgroundColor, a.x, a.y, b.x, b.y));
+ container.add(new RectangleFigure(settings.commonForegroundColor, settings.commonLineStyle,
+ a.x, a.y, b.x, b.y));
return container;
}
}
diff --git a/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/RoundedRectangleFigure.java b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/RoundedRectangleFigure.java index d8ff9b3f7e..b8e0cd2d28 100755 --- a/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/RoundedRectangleFigure.java +++ b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/RoundedRectangleFigure.java @@ -5,35 +5,40 @@ package org.eclipse.swt.examples.paint; * All Rights Reserved
*/
+import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
/**
* 2D Rectangle object
*/
-public class RoundedRectangleFigure extends StatelessXORFigureHelper {
+public class RoundedRectangleFigure extends Figure {
private Color color;
- private int x1, y1, x2, y2, diameter;
+ private int lineStyle, x1, y1, x2, y2, diameter;
/**
* Constructs a Rectangle
* These objects are defined by any two diametrically opposing corners.
*
* @param color the color for this object
+ * @param lineStyle the line style for this object
* @param x1 the virtual X coordinate of the first corner
* @param y1 the virtual Y coordinate of the first corner
* @param x2 the virtual X coordinate of the second corner
* @param y2 the virtual Y coordinate of the second corner
* @param diameter the diameter of curvature of all four corners
*/
- public RoundedRectangleFigure(Color color, int x1, int y1, int x2, int y2, int diameter) {
- this.color = color; this.x1 = x1; this.y1 = y1; this.x2 = x2; this.y2 = y2;
+ public RoundedRectangleFigure(Color color, int lineStyle, int x1, int y1, int x2, int y2, int diameter) {
+ this.color = color; this.lineStyle = lineStyle;
+ this.x1 = x1; this.y1 = y1; this.x2 = x2; this.y2 = y2;
this.diameter = diameter;
}
- public void draw(GC gc, Point offset) {
- gc.setForeground(color);
- gcDraw(gc, offset);
+ public void draw(FigureDrawContext fdc) {
+ Rectangle r = fdc.toClientRectangle(x1, y1, x2, y2);
+ fdc.gc.setForeground(color);
+ fdc.gc.setLineStyle(lineStyle);
+ fdc.gc.drawRoundRectangle(r.x, r.y, r.width - 1, r.height - 1, diameter, diameter);
+ fdc.gc.setLineStyle(SWT.LINE_SOLID);
+ }
+ public void addDamagedRegion(FigureDrawContext fdc, Region region) {
+ region.add(fdc.toClientRectangle(x1, y1, x2, y2));
}
- protected void gcDraw(GC gc, Point offset) {
- gc.drawRoundRectangle(Math.min(x1, x2) + offset.x, Math.min(y1, y2) + offset.y,
- Math.abs(x2 - x1), Math.abs(y2 - y1), diameter, diameter);
- }
}
diff --git a/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/RoundedRectangleTool.java b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/RoundedRectangleTool.java index 73bf168564..5c0311e43c 100755 --- a/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/RoundedRectangleTool.java +++ b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/RoundedRectangleTool.java @@ -11,10 +11,7 @@ import org.eclipse.swt.graphics.*; * A drawing tool.
*/
public class RoundedRectangleTool extends DragPaintSession implements PaintTool {
- private Color drawFGColor;
- private Color drawBGColor;
- private int fillType;
- private int cornerDiameter;
+ private ToolSettings settings;
/**
* Constructs a RoundedRectangleTool.
@@ -33,10 +30,7 @@ public class RoundedRectangleTool extends DragPaintSession implements PaintTool * @param toolSettings the new tool settings
*/
public void set(ToolSettings toolSettings) {
- drawFGColor = toolSettings.commonForegroundColor;
- drawBGColor = toolSettings.commonBackgroundColor;
- fillType = toolSettings.commonFillType;
- cornerDiameter = toolSettings.roundedRectangleCornerDiameter;
+ settings = toolSettings;
}
/**
@@ -53,10 +47,12 @@ public class RoundedRectangleTool extends DragPaintSession implements PaintTool */
protected Figure createFigure(Point a, Point b) {
ContainerFigure container = new ContainerFigure();
- if (fillType != ToolSettings.ftNone)
- container.add(new SolidRoundedRectangleFigure(drawBGColor, a.x, a.y, b.x, b.y, cornerDiameter));
- if (fillType != ToolSettings.ftSolid)
- container.add(new RoundedRectangleFigure(drawFGColor, a.x, a.y, b.x, b.y, cornerDiameter));
+ if (settings.commonFillType != ToolSettings.ftNone)
+ container.add(new SolidRoundedRectangleFigure(settings.commonBackgroundColor,
+ a.x, a.y, b.x, b.y, settings.roundedRectangleCornerDiameter));
+ if (settings.commonFillType != ToolSettings.ftSolid)
+ container.add(new RoundedRectangleFigure(settings.commonForegroundColor,
+ settings.commonLineStyle, a.x, a.y, b.x, b.y, settings.roundedRectangleCornerDiameter));
return container;
}
}
diff --git a/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/SegmentedPaintSession.java b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/SegmentedPaintSession.java index 5ca341684f..5085ab1bf2 100755 --- a/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/SegmentedPaintSession.java +++ b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/SegmentedPaintSession.java @@ -43,7 +43,7 @@ public abstract class SegmentedPaintSession extends BasicPaintSession { * Activates the tool.
*/
public void beginSession() {
- getPaintSurface().getPaintStatus().setMessage(PaintPlugin.getResourceString(
+ getPaintSurface().setStatusMessage(PaintPlugin.getResourceString(
"session.SegmentedInteractivePaint.message.anchorMode"));
previousFigure = null;
currentFigure = null;
@@ -66,7 +66,7 @@ public abstract class SegmentedPaintSession extends BasicPaintSession { getPaintSurface().clearRubberbandSelection();
if (previousFigure != null) getPaintSurface().drawFigure(previousFigure);
- getPaintSurface().getPaintStatus().setMessage(PaintPlugin.getResourceString(
+ getPaintSurface().setStatusMessage(PaintPlugin.getResourceString(
"session.SegmentedInteractivePaint.message.anchorMode"));
previousFigure = null;
currentFigure = null;
@@ -81,7 +81,7 @@ public abstract class SegmentedPaintSession extends BasicPaintSession { public void mouseDown(MouseEvent event) {
if (event.button != 1) return;
- getPaintSurface().getPaintStatus().setMessage(PaintPlugin.getResourceString(
+ getPaintSurface().setStatusMessage(PaintPlugin.getResourceString(
"session.SegmentedInteractivePaint.message.interactiveMode"));
previousFigure = currentFigure;
@@ -128,10 +128,11 @@ public abstract class SegmentedPaintSession extends BasicPaintSession { public void mouseMove(MouseEvent event) {
final PaintSurface ps = getPaintSurface();
if (controlPoints.size() == 0) {
- ps.showCurrentPositionStatus();
+ ps.setStatusCoord(ps.getCurrentPosition());
return; // spurious event
} else {
- ps.showCurrentRangeStatus((Point) controlPoints.elementAt(controlPoints.size() - 1));
+ ps.setStatusCoordRange((Point) controlPoints.elementAt(controlPoints.size() - 1),
+ ps.getCurrentPosition());
}
ps.clearRubberbandSelection();
diff --git a/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/SolidEllipseFigure.java b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/SolidEllipseFigure.java index 869c3e97cd..8f481eb474 100755 --- a/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/SolidEllipseFigure.java +++ b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/SolidEllipseFigure.java @@ -10,7 +10,7 @@ import org.eclipse.swt.graphics.*; /**
* 2D Solid Ellipse object
*/
-public class SolidEllipseFigure extends StatelessXORFigureHelper {
+public class SolidEllipseFigure extends Figure {
private Color color;
private int x1, y1, x2, y2;
/**
@@ -27,12 +27,12 @@ public class SolidEllipseFigure extends StatelessXORFigureHelper { public SolidEllipseFigure(Color color, int x1, int y1, int x2, int y2) {
this.color = color; this.x1 = x1; this.y1 = y1; this.x2 = x2; this.y2 = y2;
}
- public void draw(GC gc, Point offset) {
- gc.setBackground(color);
- gcDraw(gc, offset);
+ public void draw(FigureDrawContext fdc) {
+ Rectangle r = fdc.toClientRectangle(x1, y1, x2, y2);
+ fdc.gc.setBackground(color);
+ fdc.gc.fillOval(r.x, r.y, r.width, r.height);
+ }
+ public void addDamagedRegion(FigureDrawContext fdc, Region region) {
+ region.add(fdc.toClientRectangle(x1, y1, x2, y2));
}
- protected void gcDraw(GC gc, Point offset) {
- gc.fillOval(Math.min(x1, x2) + offset.x, Math.min(y1, y2) + offset.y,
- Math.abs(x2 - x1) + 1, Math.abs(y2 - y1) + 1);
- }
}
diff --git a/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/SolidPolygonFigure.java b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/SolidPolygonFigure.java index a16b1895cf..22b06ca958 100755 --- a/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/SolidPolygonFigure.java +++ b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/SolidPolygonFigure.java @@ -10,7 +10,7 @@ import org.eclipse.swt.graphics.*; /**
* 2D Line object
*/
-public class SolidPolygonFigure extends StatelessXORFigureHelper {
+public class SolidPolygonFigure extends Figure {
private Color color;
private int[] points;
/**
@@ -29,11 +29,25 @@ public class SolidPolygonFigure extends StatelessXORFigureHelper { points[i * 2 + 1] = vertices[i].y;
}
}
- public void draw(GC gc, Point offset) {
- gc.setBackground(color);
- gcDraw(gc, offset);
+ public void draw(FigureDrawContext fdc) {
+ int[] drawPoints = new int[points.length];
+ for (int i = 0; i < points.length; i += 2) {
+ drawPoints[i] = points[i] * fdc.xScale - fdc.xOffset;
+ drawPoints[i + 1] = points[i + 1] * fdc.yScale - fdc.yOffset;
+ }
+ fdc.gc.setBackground(color);
+ fdc.gc.fillPolygon(drawPoints);
+ }
+ public void addDamagedRegion(FigureDrawContext fdc, Region region) {
+ int xmin = Integer.MAX_VALUE, ymin = Integer.MAX_VALUE;
+ int xmax = Integer.MIN_VALUE, ymax = Integer.MIN_VALUE;
+
+ for (int i = 0; i < points.length; i += 2) {
+ if (points[i] < xmin) xmin = points[i];
+ if (points[i] > xmax) xmax = points[i];
+ if (points[i+1] < ymin) ymin = points[i+1];
+ if (points[i+1] > ymax) ymax = points[i+1];
+ }
+ region.add(fdc.toClientRectangle(xmin, ymin, xmax, ymax));
}
- protected void gcDraw(GC gc, Point offset) {
- gc.fillPolygon(points);
- }
}
diff --git a/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/SolidRectangleFigure.java b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/SolidRectangleFigure.java index 54d6b758d2..f1146a5736 100755 --- a/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/SolidRectangleFigure.java +++ b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/SolidRectangleFigure.java @@ -10,7 +10,7 @@ import org.eclipse.swt.graphics.*; /**
* 2D SolidRectangle object
*/
-public class SolidRectangleFigure extends StatelessXORFigureHelper {
+public class SolidRectangleFigure extends Figure {
private Color color;
private int x1, y1, x2, y2;
/**
@@ -26,12 +26,12 @@ public class SolidRectangleFigure extends StatelessXORFigureHelper { public SolidRectangleFigure(Color color, int x1, int y1, int x2, int y2) {
this.color = color; this.x1 = x1; this.y1 = y1; this.x2 = x2; this.y2 = y2;
}
- public void draw(GC gc, Point offset) {
- gc.setBackground(color);
- gcDraw(gc, offset);
+ public void draw(FigureDrawContext fdc) {
+ Rectangle r = fdc.toClientRectangle(x1, y1, x2, y2);
+ fdc.gc.setBackground(color);
+ fdc.gc.fillRectangle(r.x, r.y, r.width, r.height);
+ }
+ public void addDamagedRegion(FigureDrawContext fdc, Region region) {
+ region.add(fdc.toClientRectangle(x1, y1, x2, y2));
}
- protected void gcDraw(GC gc, Point offset) {
- gc.fillRectangle(Math.min(x1, x2) + offset.x, Math.min(y1, y2) + offset.y,
- Math.abs(x2 - x1) + 1, Math.abs(y2 - y1) + 1);
- }
}
diff --git a/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/SolidRoundedRectangleFigure.java b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/SolidRoundedRectangleFigure.java index 320b29c060..bb57338e75 100755 --- a/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/SolidRoundedRectangleFigure.java +++ b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/SolidRoundedRectangleFigure.java @@ -10,7 +10,7 @@ import org.eclipse.swt.graphics.*; /**
* 2D SolidRectangle object
*/
-public class SolidRoundedRectangleFigure extends StatelessXORFigureHelper {
+public class SolidRoundedRectangleFigure extends Figure {
private Color color;
private int x1, y1, x2, y2, diameter;
/**
@@ -28,12 +28,12 @@ public class SolidRoundedRectangleFigure extends StatelessXORFigureHelper { this.color = color; this.x1 = x1; this.y1 = y1; this.x2 = x2; this.y2 = y2;
this.diameter = diameter;
}
- public void draw(GC gc, Point offset) {
- gc.setBackground(color);
- gcDraw(gc, offset);
+ public void draw(FigureDrawContext fdc) {
+ Rectangle r = fdc.toClientRectangle(x1, y1, x2, y2);
+ fdc.gc.setBackground(color);
+ fdc.gc.fillRoundRectangle(r.x, r.y, r.width, r.height, diameter, diameter);
+ }
+ public void addDamagedRegion(FigureDrawContext fdc, Region region) {
+ region.add(fdc.toClientRectangle(x1, y1, x2, y2));
}
- protected void gcDraw(GC gc, Point offset) {
- gc.fillRoundRectangle(Math.min(x1, x2) + offset.x, Math.min(y1, y2) + offset.y,
- Math.abs(x2 - x1) + 1, Math.abs(y2 - y1) + 1, diameter, diameter);
- }
}
diff --git a/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/TextFigure.java b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/TextFigure.java index 260f3a04f8..a8f1b077ff 100755 --- a/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/TextFigure.java +++ b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/TextFigure.java @@ -27,31 +27,17 @@ public class TextFigure extends Figure { public TextFigure(Color color, Font font, String text, int x, int y) {
this.color = color; this.font = font; this.text = text; this.x = x; this.y = y;
}
- public void draw(GC gc, Point offset) {
- gc.setFont(font);
- gc.setForeground(color);
- gc.drawText(text, x + offset.x, y + offset.y, true);
+ public void draw(FigureDrawContext fdc) {
+ Point p = fdc.toClientPoint(x, y);
+ fdc.gc.setFont(font);
+ fdc.gc.setForeground(color);
+ fdc.gc.drawText(text, p.x, p.y, true);
}
- public Object drawPreview(GC gc, Point offset) {
- Color oldColor = gc.getForeground();
- gc.setFont(font);
- gc.setForeground(color);
- gc.setXORMode(false);
-
- Point textExtent = gc.textExtent(text);
- Image backingStore = new Image(null, textExtent.x, textExtent.y);
- gc.copyArea(backingStore, x + offset.x, y + offset.y);
-
- gc.drawText(text, x + offset.x, y + offset.y, true);
- gc.setForeground(oldColor);
- gc.setXORMode(true);
- return backingStore;
- }
- public void erasePreview(GC gc, Point offset, Object rememberedData) {
- Image backingStore = (Image) rememberedData;
- gc.setXORMode(false);
- gc.drawImage(backingStore, x + offset.x, y + offset.y);
- gc.setXORMode(true);
- backingStore.dispose();
+ public void addDamagedRegion(FigureDrawContext fdc, Region region) {
+ Font oldFont = fdc.gc.getFont();
+ fdc.gc.setFont(font);
+ Point textExtent = fdc.gc.textExtent(text);
+ fdc.gc.setFont(oldFont);
+ region.add(fdc.toClientRectangle(x, y, x + textExtent.x, y + textExtent.y));
}
}
diff --git a/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/TextTool.java b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/TextTool.java index f7403c8263..22831e81bf 100755 --- a/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/TextTool.java +++ b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/TextTool.java @@ -13,8 +13,7 @@ import org.eclipse.swt.graphics.*; * A text drawing tool.
*/
public class TextTool extends BasicPaintSession implements PaintTool {
- private Color drawColor;
- private Font drawFont;
+ private ToolSettings settings;
private String drawText = PaintPlugin.getResourceString("tool.Text.settings.defaulttext");
/**
@@ -34,8 +33,7 @@ public class TextTool extends BasicPaintSession implements PaintTool { * @param toolSettings the new tool settings
*/
public void set(ToolSettings toolSettings) {
- drawColor = toolSettings.commonForegroundColor;
- drawFont = toolSettings.commonFont;
+ settings = toolSettings;
}
/**
@@ -51,7 +49,7 @@ public class TextTool extends BasicPaintSession implements PaintTool { * Activates the tool.
*/
public void beginSession() {
- getPaintSurface().getPaintStatus().setMessage(PaintPlugin.getResourceString(
+ getPaintSurface().setStatusMessage(PaintPlugin.getResourceString(
"session.Text.message"));
}
@@ -114,9 +112,11 @@ public class TextTool extends BasicPaintSession implements PaintTool { * @param event the mouse event detail information
*/
public void mouseMove(MouseEvent event) {
- getPaintSurface().showCurrentPositionStatus();
- getPaintSurface().clearRubberbandSelection();
- getPaintSurface().addRubberbandSelection(
- new TextFigure(drawColor, drawFont, drawText, event.x, event.y));
+ final PaintSurface ps = getPaintSurface();
+ ps.setStatusCoord(ps.getCurrentPosition());
+ ps.clearRubberbandSelection();
+ ps.addRubberbandSelection(
+ new TextFigure(settings.commonForegroundColor, settings.commonFont,
+ drawText, event.x, event.y));
}
}
diff --git a/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/ToolSettings.java b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/ToolSettings.java index 3afeba079a..6d41a27dd8 100755 --- a/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/ToolSettings.java +++ b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/ToolSettings.java @@ -3,7 +3,7 @@ package org.eclipse.swt.examples.paint; * (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved
*/
-
import org.eclipse.swt.graphics.*;
+
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
/**
* Tool Settings objects group tool-related configuration information.
*/
public class ToolSettings {
public static final int ftNone = 0, ftOutline = 1, ftSolid = 2;
/**
@@ -15,7 +15,7 @@ public class ToolSettings { * commonBackgroundColor: current tool background colour
*/
public Color commonBackgroundColor;
-
/**
* commonFont: current font
*/
public Font commonFont;
/**
* commonFillType: current fill type
* <p>
* One of ftNone, ftOutline, ftSolid.
* </p>
*/
public int commonFillType = ftNone;
+
/**
* commonFont: current font
*/
public Font commonFont;
/**
* commonFillType: current fill type
* <p>One of ftNone, ftOutline, ftSolid.</p>
*/
public int commonFillType = ftNone;
/**
* commonLineStyle: current line type
*/
public int commonLineStyle = SWT.LINE_SOLID;
/**
* airbrushRadius: coverage radius in pixels
*/
|