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/05/11 16:01:39 UTC
svn commit: r773566 - in /incubator/pivot/trunk/wtk:
src/pivot/wtk/media/drawing/Rectangle.java
src/pivot/wtk/media/drawing/RectangleListener.java
test/pivot/wtk/media/drawing/test/drawing_test.wtkx
test/pivot/wtk/media/drawing/test/sample.wtkd
Author: gbrown
Date: Mon May 11 14:01:38 2009
New Revision: 773566
URL: http://svn.apache.org/viewvc?rev=773566&view=rev
Log:
Add a cornerRadius property to Rectangle class.
Modified:
incubator/pivot/trunk/wtk/src/pivot/wtk/media/drawing/Rectangle.java
incubator/pivot/trunk/wtk/src/pivot/wtk/media/drawing/RectangleListener.java
incubator/pivot/trunk/wtk/test/pivot/wtk/media/drawing/test/drawing_test.wtkx
incubator/pivot/trunk/wtk/test/pivot/wtk/media/drawing/test/sample.wtkd
Modified: incubator/pivot/trunk/wtk/src/pivot/wtk/media/drawing/Rectangle.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtk/media/drawing/Rectangle.java?rev=773566&r1=773565&r2=773566&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtk/media/drawing/Rectangle.java (original)
+++ incubator/pivot/trunk/wtk/src/pivot/wtk/media/drawing/Rectangle.java Mon May 11 14:01:38 2009
@@ -20,13 +20,13 @@
import java.awt.Graphics2D;
import java.awt.Paint;
import java.awt.geom.Rectangle2D;
+import java.awt.geom.RectangularShape;
+import java.awt.geom.RoundRectangle2D;
import pivot.util.ListenerList;
/**
* Shape representing a rectangle.
- * <p>
- * TODO Add a corner radii property.
*
* @author gbrown
*/
@@ -38,45 +38,83 @@
listener.sizeChanged(rectangle, previousWidth, previousHeight);
}
}
+
+ public void cornerRadiusChanged(Rectangle rectangle, int previousCornerRadius) {
+ for (RectangleListener listener : this) {
+ listener.cornerRadiusChanged(rectangle, previousCornerRadius);
+ }
+ }
}
- private Rectangle2D.Float rectangle2D = new Rectangle2D.Float();
+ private RectangularShape rectangularShape = new Rectangle2D.Float();
+ private int cornerRadius = 0;
private RectangleListenerList rectangleListeners = new RectangleListenerList();
public int getWidth() {
- return (int)rectangle2D.width;
+ return (int)rectangularShape.getWidth();
}
public void setWidth(int width) {
- setSize(width, (int)rectangle2D.height);
+ setSize(width, getHeight());
}
public int getHeight() {
- return (int)rectangle2D.height;
+ return (int)rectangularShape.getHeight();
}
public void setHeight(int height) {
- setSize((int)rectangle2D.width, height);
+ setSize(getWidth(), height);
}
public void setSize(int width, int height) {
- int previousWidth = (int)rectangle2D.width;
- int previousHeight = (int)rectangle2D.height;
+ int previousWidth = getWidth();
+ int previousHeight = getHeight();
if (previousWidth != width
|| previousHeight != height) {
- rectangle2D.width = width;
- rectangle2D.height = height;
+ if (cornerRadius == 0) {
+ Rectangle2D.Float rectangle2D
+ = (Rectangle2D.Float)rectangularShape;
+ rectangle2D.width = width;
+ rectangle2D.height = height;
+ } else {
+ RoundRectangle2D.Float roundRectangle2D
+ = (RoundRectangle2D.Float)rectangularShape;
+ roundRectangle2D.width = width;
+ roundRectangle2D.height = height;
+ }
+
invalidate();
rectangleListeners.sizeChanged(this, previousWidth, previousHeight);
}
}
+ public int getCornerRadius() {
+ return cornerRadius;
+ }
+
+ public void setCornerRadius(int cornerRadius) {
+ int previousCornerRadius = this.cornerRadius;
+ if (previousCornerRadius != cornerRadius) {
+ this.cornerRadius = cornerRadius;
+
+ if (cornerRadius == 0) {
+ rectangularShape = new Rectangle2D.Float(0, 0, getWidth(), getHeight());
+ } else {
+ rectangularShape = new RoundRectangle2D.Float(0, 0, getWidth(), getHeight(),
+ cornerRadius, cornerRadius);
+ }
+
+ update();
+ rectangleListeners.cornerRadiusChanged(this, previousCornerRadius);
+ }
+ }
+
public void draw(Graphics2D graphics) {
Paint fill = getFill();
if (fill != null) {
graphics.setPaint(fill);
- graphics.fill(rectangle2D);
+ graphics.fill(rectangularShape);
}
Paint stroke = getStroke();
@@ -84,7 +122,7 @@
int strokeThickness = getStrokeThickness();
graphics.setPaint(stroke);
graphics.setStroke(new BasicStroke(strokeThickness));
- graphics.draw(rectangle2D);
+ graphics.draw(rectangularShape);
}
}
@@ -93,8 +131,8 @@
if (!isValid()) {
int strokeThickness = getStrokeThickness();
setBounds(-strokeThickness / 2, -strokeThickness / 2,
- (int)rectangle2D.width + strokeThickness,
- (int)rectangle2D.height + strokeThickness);
+ (int)rectangularShape.getWidth() + strokeThickness,
+ (int)rectangularShape.getHeight() + strokeThickness);
}
super.validate();
Modified: incubator/pivot/trunk/wtk/src/pivot/wtk/media/drawing/RectangleListener.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtk/media/drawing/RectangleListener.java?rev=773566&r1=773565&r2=773566&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtk/media/drawing/RectangleListener.java (original)
+++ incubator/pivot/trunk/wtk/src/pivot/wtk/media/drawing/RectangleListener.java Mon May 11 14:01:38 2009
@@ -30,4 +30,12 @@
* @param previousHeight
*/
public void sizeChanged(Rectangle rectangle, int previousWidth, int previousHeight);
+
+ /**
+ * Called when a rectangle's corner radius has changed.
+ *
+ * @param rectangle
+ * @param previousCornerRadius
+ */
+ public void cornerRadiusChanged(Rectangle rectangle, int previousCornerRadius);
}
Modified: incubator/pivot/trunk/wtk/test/pivot/wtk/media/drawing/test/drawing_test.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/test/pivot/wtk/media/drawing/test/drawing_test.wtkx?rev=773566&r1=773565&r2=773566&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/test/pivot/wtk/media/drawing/test/drawing_test.wtkx (original)
+++ incubator/pivot/trunk/wtk/test/pivot/wtk/media/drawing/test/drawing_test.wtkx Mon May 11 14:01:38 2009
@@ -19,6 +19,6 @@
<ScrollPane xmlns:wtkx="http://incubator.apache.org/pivot/wtkx/1.1"
xmlns="pivot.wtk">
<view>
- <ImageView styles="{backgroundColor:'#999999'}" image="@activity.wtkd"/>
+ <ImageView styles="{backgroundColor:'#999999'}" image="@sample.wtkd"/>
</view>
</ScrollPane>
Modified: incubator/pivot/trunk/wtk/test/pivot/wtk/media/drawing/test/sample.wtkd
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/test/pivot/wtk/media/drawing/test/sample.wtkd?rev=773566&r1=773565&r2=773566&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/test/pivot/wtk/media/drawing/test/sample.wtkd (original)
+++ incubator/pivot/trunk/wtk/test/pivot/wtk/media/drawing/test/sample.wtkd Mon May 11 14:01:38 2009
@@ -54,7 +54,8 @@
<Rectangle x="0" y="0"
width="160" height="120" fill="#0000ff"
- stroke="#00ff00" strokeThickness="4"/>
+ stroke="#00ff00" strokeThickness="4"
+ cornerRadius="20"/>
<Arc x="-10" y="10" width="50" height="50" start="90.0" extent="90.0"
fill="#ffff00" stroke="#ff0000" strokeThickness="4" type="pie"/>
<Arc x="0" y="10" width="50" height="50" start="0.0" extent="90.0"