You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by gb...@apache.org on 2009/09/15 20:11:25 UTC

svn commit: r815432 - in /incubator/pivot/trunk/wtk: src/org/apache/pivot/wtk/media/ src/org/apache/pivot/wtk/media/drawing/ test/org/apache/pivot/wtk/test/

Author: gbrown
Date: Tue Sep 15 18:11:22 2009
New Revision: 815432

URL: http://svn.apache.org/viewvc?rev=815432&view=rev
Log:
Add an abstract Shape2D class that other shapes can extend.

Added:
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/Shape2D.java
Modified:
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/Drawing.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/Arc.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/CubicCurve.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/Ellipse.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/Group.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/Line.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/QuadCurve.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/Rectangle.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/Shape.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/Text.java
    incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/drawing_test.wtkx

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/Drawing.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/Drawing.java?rev=815432&r1=815431&r2=815432&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/Drawing.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/Drawing.java Tue Sep 15 18:11:22 2009
@@ -99,8 +99,8 @@
                 height = 0;
             } else {
                 Bounds canvasBounds = canvas.getBounds();
-                width = canvasBounds.x + canvasBounds.width;
-                height = canvasBounds.y + canvasBounds.height;
+                width = Math.max(canvasBounds.x + canvasBounds.width, 0);
+                height = Math.max(canvasBounds.y + canvasBounds.height, 0);
             }
 
             size = new Dimensions(width, height);

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/Arc.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/Arc.java?rev=815432&r1=815431&r2=815432&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/Arc.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/Arc.java Tue Sep 15 18:11:22 2009
@@ -16,9 +16,6 @@
  */
 package org.apache.pivot.wtk.media.drawing;
 
-import java.awt.BasicStroke;
-import java.awt.Graphics2D;
-import java.awt.Paint;
 import java.awt.geom.Arc2D;
 
 import org.apache.pivot.util.ListenerList;
@@ -26,7 +23,7 @@
 /**
  * Shape representing an arc.
  */
-public class Arc extends Shape {
+public class Arc extends Shape2D {
     /**
      * Enum representing an arc closure type.
      */
@@ -178,36 +175,8 @@
     }
 
     @Override
-    public boolean contains(int x, int y) {
-        // TODO
-        return false;
-    }
-
-    @Override
-    public void draw(Graphics2D graphics) {
-        Paint fill = getFill();
-        if (fill != null) {
-            graphics.setPaint(fill);
-            graphics.fill(arc2D);
-        }
-
-        Paint stroke = getStroke();
-        if (stroke != null) {
-            int strokeThickness = getStrokeThickness();
-            graphics.setPaint(stroke);
-            graphics.setStroke(new BasicStroke(strokeThickness));
-            graphics.draw(arc2D);
-        }
-    }
-
-    @Override
-    protected void validate() {
-        if (!isValid()) {
-            int strokeThickness = getStrokeThickness();
-            setBounds(-strokeThickness / 2, -strokeThickness / 2,
-                (int)arc2D.width + strokeThickness,
-                (int)arc2D.height + strokeThickness);
-        }
+    protected java.awt.Shape getShape2D() {
+        return arc2D;
     }
 
     public ListenerList<ArcListener> getArcListeners() {

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/CubicCurve.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/CubicCurve.java?rev=815432&r1=815431&r2=815432&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/CubicCurve.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/CubicCurve.java Tue Sep 15 18:11:22 2009
@@ -16,19 +16,14 @@
  */
 package org.apache.pivot.wtk.media.drawing;
 
-import java.awt.BasicStroke;
-import java.awt.Graphics2D;
-import java.awt.Paint;
 import java.awt.geom.CubicCurve2D;
-import java.awt.geom.Rectangle2D;
 
 import org.apache.pivot.util.ListenerList;
 
-
 /**
  * Shape representing a cubic curve.
  */
-public class CubicCurve extends Shape {
+public class CubicCurve extends Shape2D {
     private static class CubicCurveListenerList extends ListenerList<CubicCurveListener>
         implements CubicCurveListener {
         public void endpointsChanged(CubicCurve cubicCurve, int previousX1, int previousY1,
@@ -157,41 +152,8 @@
     }
 
     @Override
-    public boolean contains(int x, int y) {
-        // TODO
-        return false;
-    }
-
-    @Override
-    public void draw(Graphics2D graphics) {
-        Paint fill = getFill();
-        if (fill != null) {
-            graphics.setPaint(fill);
-            graphics.fill(cubicCurve2D);
-        }
-
-        Paint stroke = getStroke();
-        if (stroke != null) {
-            int strokeThickness = getStrokeThickness();
-            graphics.setPaint(stroke);
-            graphics.setStroke(new BasicStroke(strokeThickness));
-            graphics.draw(cubicCurve2D);
-        }
-    }
-
-    @Override
-    protected void validate() {
-        if (!isValid()) {
-            // Over-estimate the bounds to keep the logic simple
-            int strokeThickness = getStrokeThickness();
-            double radius = (strokeThickness / Math.cos(Math.PI / 4)) / 2;
-
-            Rectangle2D boundingRectangle = cubicCurve2D.getBounds2D();
-            setBounds((int)Math.floor(boundingRectangle.getX() - radius),
-                (int)Math.floor(boundingRectangle.getY() - radius),
-                (int)Math.ceil(boundingRectangle.getWidth() + radius * 2),
-                (int)Math.ceil(boundingRectangle.getHeight() + radius * 2));
-        }
+    protected java.awt.Shape getShape2D() {
+        return cubicCurve2D;
     }
 
     public ListenerList<CubicCurveListener> getCubicCurveListeners() {

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/Ellipse.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/Ellipse.java?rev=815432&r1=815431&r2=815432&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/Ellipse.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/Ellipse.java Tue Sep 15 18:11:22 2009
@@ -16,19 +16,14 @@
  */
 package org.apache.pivot.wtk.media.drawing;
 
-import java.awt.BasicStroke;
-import java.awt.Graphics2D;
-import java.awt.Paint;
 import java.awt.geom.Ellipse2D;
 
 import org.apache.pivot.util.ListenerList;
-import org.apache.pivot.wtk.Point;
-
 
 /**
  * Shape representing an ellipse.
  */
-public class Ellipse extends Shape {
+public class Ellipse extends Shape2D {
     private static class EllipseListenerList extends ListenerList<EllipseListener>
         implements EllipseListener {
         public void sizeChanged(Ellipse ellipse, int previousWidth, int previousHeight) {
@@ -39,7 +34,6 @@
     }
 
     private Ellipse2D.Float ellipse2D = new Ellipse2D.Float();
-    private java.awt.Shape strokeShape = null;
 
     private EllipseListenerList ellipseListeners = new EllipseListenerList();
 
@@ -62,57 +56,21 @@
     public void setSize(int width, int height) {
         int previousWidth = (int)ellipse2D.width;
         int previousHeight = (int)ellipse2D.height;
+
         if (previousWidth != width
             || previousHeight != height) {
             ellipse2D.width = width;
             ellipse2D.height = height;
-            invalidate();
-            ellipseListeners.sizeChanged(this, previousWidth, previousHeight);
-        }
-    }
-
-    @Override
-    public boolean contains(int x, int y) {
-        return (ellipse2D.contains(x, y)
-            || (strokeShape != null
-                && strokeShape.contains(x, y)));
-    }
 
-    @Override
-    public void draw(Graphics2D graphics) {
-        Paint fill = getFill();
-        if (fill != null) {
-            graphics.setPaint(fill);
-            graphics.fill(ellipse2D);
-        }
+            invalidate();
 
-        Paint stroke = getStroke();
-        if (stroke != null) {
-            graphics.setPaint(stroke);
-            graphics.fill(strokeShape);
+            ellipseListeners.sizeChanged(this, previousWidth, previousHeight);
         }
     }
 
     @Override
-    protected void validate() {
-        if (!isValid()) {
-            java.awt.Shape boundingShape;
-
-            if (getStroke() == null) {
-                strokeShape = null;
-                boundingShape = ellipse2D;
-            } else {
-                int strokeThickness = getStrokeThickness();
-                BasicStroke basicStroke = new BasicStroke(strokeThickness);
-                strokeShape = basicStroke.createStrokedShape(ellipse2D);
-                boundingShape = strokeShape;
-            }
-
-            java.awt.Rectangle bounds = boundingShape.getBounds();
-
-            Point origin = getOrigin();
-            setBounds(origin.x + bounds.x, origin.y + bounds.y, bounds.width, bounds.height);
-        }
+    protected java.awt.Shape getShape2D() {
+        return ellipse2D;
     }
 
     public ListenerList<EllipseListener> getEllipseListeners() {

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/Group.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/Group.java?rev=815432&r1=815431&r2=815432&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/Group.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/Group.java Tue Sep 15 18:11:22 2009
@@ -70,8 +70,16 @@
 
     @Override
     public boolean contains(int x, int y) {
-        // TODO
-        return false;
+        boolean contains = false;
+
+        for (Shape shape : shapes) {
+            if (shape.contains(x - shape.getX(), y - shape.getY())) {
+                contains = true;
+                break;
+            }
+        }
+
+        return contains;
     }
 
     public Shape getShapeAt(int x, int y) {
@@ -197,6 +205,7 @@
         }
     }
 
+    @Override
     public int add(Shape shape) {
         int index = shapes.getLength();
         insert(shape, index);
@@ -204,6 +213,7 @@
         return index;
     }
 
+    @Override
     public void insert(Shape shape, int index) {
         if (shape.getParent() != null) {
             throw new IllegalArgumentException();
@@ -215,10 +225,12 @@
         groupListeners.shapeInserted(this, index);
     }
 
+    @Override
     public Shape update(int index, Shape shape) {
         throw new UnsupportedOperationException();
     }
 
+    @Override
     public int remove(Shape shape) {
         int index = shapes.indexOf(shape);
         if (index != -1) {
@@ -228,6 +240,7 @@
         return index;
     }
 
+    @Override
     public Sequence<Shape> remove(int index, int count) {
         Sequence<Shape> removed = shapes.remove(index, count);
 
@@ -244,18 +257,22 @@
         return removed;
     }
 
+    @Override
     public Shape get(int index) {
         return shapes.get(index);
     }
 
+    @Override
     public int indexOf(Shape shape) {
         return shapes.indexOf(shape);
     }
 
+    @Override
     public int getLength() {
         return shapes.getLength();
     }
 
+    @Override
     public Iterator<Shape> iterator() {
         return new ImmutableIterator<Shape>(shapes.iterator());
     }

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/Line.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/Line.java?rev=815432&r1=815431&r2=815432&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/Line.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/Line.java Tue Sep 15 18:11:22 2009
@@ -16,19 +16,16 @@
  */
 package org.apache.pivot.wtk.media.drawing;
 
-import java.awt.BasicStroke;
-import java.awt.Graphics2D;
 import java.awt.Paint;
 import java.awt.geom.Line2D;
 
 import org.apache.pivot.util.ListenerList;
 import org.apache.pivot.wtk.Point;
 
-
 /**
  * Shape representing a line.
  */
-public class Line extends Shape {
+public class Line extends Shape2D {
     private static class LineListenerList extends ListenerList<LineListener>
         implements LineListener {
         public void endpointsChanged(Line line, int previousX1, int previousY1,
@@ -121,37 +118,8 @@
     }
 
     @Override
-    public boolean contains(int x, int y) {
-        // TODO
-        return false;
-    }
-
-    @Override
-    public void draw(Graphics2D graphics) {
-        Paint stroke = getStroke();
-        int strokeThickness = getStrokeThickness();
-        graphics.setPaint(stroke);
-        graphics.setStroke(new BasicStroke(strokeThickness));
-        graphics.draw(line2D);
-    }
-
-    @Override
-    protected void validate() {
-        if (!isValid()) {
-            // Over-estimate the bounds to keep the logic simple
-            int strokeThickness = getStrokeThickness();
-            double radius = (strokeThickness / Math.cos(Math.PI / 4)) / 2;
-
-            double top = Math.min(line2D.y1, line2D.y2);
-            double left = Math.min(line2D.x1, line2D.x2);
-            double bottom = Math.max(line2D.y1, line2D.y2);
-            double right = Math.max(line2D.x1, line2D.x2);
-
-            setBounds((int)Math.floor(left - radius),
-                (int)Math.floor(top - radius),
-                (int)Math.ceil(right - left + radius * 2 + 1),
-                (int)Math.ceil(bottom - top + radius * 2 + 1));
-        }
+    protected java.awt.Shape getShape2D() {
+        return line2D;
     }
 
     public ListenerList<LineListener> getLineListeners() {

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/QuadCurve.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/QuadCurve.java?rev=815432&r1=815431&r2=815432&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/QuadCurve.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/QuadCurve.java Tue Sep 15 18:11:22 2009
@@ -16,19 +16,14 @@
  */
 package org.apache.pivot.wtk.media.drawing;
 
-import java.awt.BasicStroke;
-import java.awt.Graphics2D;
-import java.awt.Paint;
 import java.awt.geom.QuadCurve2D;
-import java.awt.geom.Rectangle2D;
 
 import org.apache.pivot.util.ListenerList;
 
-
 /**
  * Shape representing a quad curve.
  */
-public class QuadCurve extends Shape {
+public class QuadCurve extends Shape2D {
     private static class QuadCurveListenerList extends ListenerList<QuadCurveListener>
         implements QuadCurveListener {
         public void endpointsChanged(QuadCurve quadCurve, int previousX1, int previousY1,
@@ -135,41 +130,8 @@
     }
 
     @Override
-    public boolean contains(int x, int y) {
-        // TODO
-        return false;
-    }
-
-    @Override
-    public void draw(Graphics2D graphics) {
-        Paint fill = getFill();
-        if (fill != null) {
-            graphics.setPaint(fill);
-            graphics.fill(quadCurve2D);
-        }
-
-        Paint stroke = getStroke();
-        if (stroke != null) {
-            int strokeThickness = getStrokeThickness();
-            graphics.setPaint(stroke);
-            graphics.setStroke(new BasicStroke(strokeThickness));
-            graphics.draw(quadCurve2D);
-        }
-    }
-
-    @Override
-    protected void validate() {
-        if (!isValid()) {
-            // Over-estimate the bounds to keep the logic simple
-            int strokeThickness = getStrokeThickness();
-            double radius = (strokeThickness / Math.cos(Math.PI / 4)) / 2;
-
-            Rectangle2D boundingRectangle = quadCurve2D.getBounds2D();
-            setBounds((int)Math.floor(boundingRectangle.getX() - radius),
-                (int)Math.floor(boundingRectangle.getY() - radius),
-                (int)Math.ceil(boundingRectangle.getWidth() + radius * 2),
-                (int)Math.ceil(boundingRectangle.getHeight() + radius * 2));
-        }
+    protected java.awt.Shape getShape2D() {
+        return quadCurve2D;
     }
 
     public ListenerList<QuadCurveListener> getQuadCurveListeners() {

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/Rectangle.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/Rectangle.java?rev=815432&r1=815431&r2=815432&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/Rectangle.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/Rectangle.java Tue Sep 15 18:11:22 2009
@@ -16,20 +16,16 @@
  */
 package org.apache.pivot.wtk.media.drawing;
 
-import java.awt.BasicStroke;
-import java.awt.Graphics2D;
-import java.awt.Paint;
 import java.awt.geom.Rectangle2D;
 import java.awt.geom.RectangularShape;
 import java.awt.geom.RoundRectangle2D;
 
 import org.apache.pivot.util.ListenerList;
-import org.apache.pivot.wtk.Point;
 
 /**
  * Shape representing a rectangle.
  */
-public class Rectangle extends Shape {
+public class Rectangle extends Shape2D {
     private static class RectangleListenerList extends ListenerList<RectangleListener>
         implements RectangleListener {
         public void sizeChanged(Rectangle rectangle, int previousWidth, int previousHeight) {
@@ -48,7 +44,6 @@
     // TODO Use only RoundRectangle2D.Float when Sun fixes rendering issues with zero-value
     // arc width and height
     private RectangularShape rectangularShape = new Rectangle2D.Float();
-    private java.awt.Shape strokeShape = null;
 
     private RectangleListenerList rectangleListeners = new RectangleListenerList();
 
@@ -128,47 +123,8 @@
     }
 
     @Override
-    public boolean contains(int x, int y) {
-        return (rectangularShape.contains(x, y)
-            || (strokeShape != null
-                && strokeShape.contains(x, y)));
-    }
-
-    @Override
-    public void draw(Graphics2D graphics) {
-        Paint fill = getFill();
-        if (fill != null) {
-            graphics.setPaint(fill);
-            graphics.fill(rectangularShape);
-        }
-
-        Paint stroke = getStroke();
-        if (stroke != null) {
-            graphics.setPaint(stroke);
-            graphics.fill(strokeShape);
-        }
-    }
-
-    @Override
-    protected void validate() {
-        if (!isValid()) {
-            java.awt.Shape boundingShape;
-
-            if (getStroke() == null) {
-                strokeShape = null;
-                boundingShape = rectangularShape;
-            } else {
-                int strokeThickness = getStrokeThickness();
-                BasicStroke basicStroke = new BasicStroke(strokeThickness);
-                strokeShape = basicStroke.createStrokedShape(rectangularShape);
-                boundingShape = strokeShape;
-            }
-
-            java.awt.Rectangle bounds = boundingShape.getBounds();
-
-            Point origin = getOrigin();
-            setBounds(origin.x + bounds.x, origin.y + bounds.y, bounds.width, bounds.height);
-        }
+    protected java.awt.Shape getShape2D() {
+        return rectangularShape;
     }
 
     public ListenerList<RectangleListener> getRectangleListeners() {

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/Shape.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/Shape.java?rev=815432&r1=815431&r2=815432&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/Shape.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/Shape.java Tue Sep 15 18:11:22 2009
@@ -31,7 +31,6 @@
 import org.apache.pivot.wtk.GraphicsUtilities;
 import org.apache.pivot.wtk.Point;
 
-
 /**
  * Abstract base class for shapes.
  * <p>

Added: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/Shape2D.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/Shape2D.java?rev=815432&view=auto
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/Shape2D.java (added)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/Shape2D.java Tue Sep 15 18:11:22 2009
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pivot.wtk.media.drawing;
+
+import java.awt.BasicStroke;
+import java.awt.Graphics2D;
+import java.awt.Paint;
+
+import org.apache.pivot.wtk.Point;
+
+/**
+ * Abstract base class for shapes that encapsulate a Java2D shape.
+ */
+public abstract class Shape2D extends Shape {
+    @Override
+    public boolean contains(int x, int y) {
+        boolean contains = false;
+
+        java.awt.Shape shape2D = getShape2D();
+
+        if (getFill() != null) {
+            contains = shape2D.contains(x, y);
+        }
+
+        if (getStroke() != null) {
+            BasicStroke basicStroke = new BasicStroke(getStrokeThickness());
+            java.awt.Shape strokeShape = basicStroke.createStrokedShape(shape2D);
+            contains |= strokeShape.contains(x, y);
+        }
+
+        return contains;
+    }
+
+    @Override
+    public void draw(Graphics2D graphics) {
+        java.awt.Shape shape2D = getShape2D();
+
+        Paint fill = getFill();
+        if (fill != null) {
+            graphics.setPaint(fill);
+            graphics.fill(shape2D);
+        }
+
+        Paint stroke = getStroke();
+        if (stroke != null) {
+            graphics.setPaint(stroke);
+            BasicStroke basicStroke = new BasicStroke(getStrokeThickness());
+            java.awt.Shape strokeShape = basicStroke.createStrokedShape(shape2D);
+            graphics.fill(strokeShape);
+        }
+    }
+
+    @Override
+    protected void validate() {
+        if (!isValid()) {
+            java.awt.Shape shape2D = getShape2D();
+
+            java.awt.Shape boundingShape;
+            if (getStroke() == null) {
+                boundingShape = shape2D;
+            } else {
+                int strokeThickness = getStrokeThickness();
+                BasicStroke basicStroke = new BasicStroke(strokeThickness);
+                java.awt.Shape strokeShape = basicStroke.createStrokedShape(shape2D);
+                boundingShape = strokeShape;
+            }
+
+            java.awt.Rectangle bounds = boundingShape.getBounds();
+
+            Point origin = getOrigin();
+            setBounds(origin.x + bounds.x, origin.y + bounds.y, bounds.width, bounds.height);
+        }
+    }
+
+    protected abstract java.awt.Shape getShape2D();
+}

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/Text.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/Text.java?rev=815432&r1=815431&r2=815432&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/Text.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/Text.java Tue Sep 15 18:11:22 2009
@@ -218,8 +218,12 @@
 
     @Override
     public boolean contains(int x, int y) {
-        // TODO
-        return false;
+        Bounds bounds = getBounds();
+
+        return (x >= 0
+            && x < bounds.width
+            && y >= 0
+            && y < bounds.height);
     }
 
     @Override

Modified: incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/drawing_test.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/drawing_test.wtkx?rev=815432&r1=815431&r2=815432&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/drawing_test.wtkx (original)
+++ incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/drawing_test.wtkx Tue Sep 15 18:11:22 2009
@@ -36,6 +36,12 @@
                                     <drawing:Shape.Scale x="0.5" y="0.5"/>
                                 </transforms>
                             </drawing:Ellipse>
+                            <drawing:Line x1="50" y1="100" x2="150" y2="100" strokeThickness="10">
+                                <transforms>
+                                    <drawing:Shape.Translate x="40" y="40"/>
+                                    <drawing:Shape.Scale x="0.5" y="0.5"/>
+                                </transforms>
+                            </drawing:Line>
                         </drawing:Canvas>
                     </canvas>
                 </media:Drawing>