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 02:45:58 UTC
svn commit: r814945 - in /incubator/pivot/trunk:
demos/src/org/apache/pivot/demos/clock/
tutorials/src/org/apache/pivot/tutorials/drawing/
tutorials/src/org/apache/pivot/tutorials/layout/
tutorials/src/org/apache/pivot/tutorials/menus/ wtk/src/org/apac...
Author: gbrown
Date: Tue Sep 15 00:45:57 2009
New Revision: 814945
URL: http://svn.apache.org/viewvc?rev=814945&view=rev
Log:
Change definition of Drawing's size such that it is determined by the bounds of the drawing's canvas rather than explicitly set.
Modified:
incubator/pivot/trunk/demos/src/org/apache/pivot/demos/clock/clock.wtkd
incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/drawing/rotate_line.wtkd
incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/layout/panels.wtkx
incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/menus/MenuButtons.java
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/Drawing.java
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/Canvas.java
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/CanvasListener.java
incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/activity.wtkd
incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/drawing_test.wtkx
incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/sample_drawing.wtkd
Modified: incubator/pivot/trunk/demos/src/org/apache/pivot/demos/clock/clock.wtkd
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/demos/src/org/apache/pivot/demos/clock/clock.wtkd?rev=814945&r1=814944&r2=814945&view=diff
==============================================================================
--- incubator/pivot/trunk/demos/src/org/apache/pivot/demos/clock/clock.wtkd (original)
+++ incubator/pivot/trunk/demos/src/org/apache/pivot/demos/clock/clock.wtkd Tue Sep 15 00:45:57 2009
@@ -16,8 +16,7 @@
limitations under the License.
-->
-<Drawing width="320" height="240"
- xmlns:wtkx="http://pivot.apache.org/wtkx"
+<Drawing xmlns:wtkx="http://pivot.apache.org/wtkx"
xmlns="org.apache.pivot.wtk.media">
<canvas>
<Canvas xmlns="org.apache.pivot.wtk.media.drawing">
Modified: incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/drawing/rotate_line.wtkd
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/drawing/rotate_line.wtkd?rev=814945&r1=814944&r2=814945&view=diff
==============================================================================
--- incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/drawing/rotate_line.wtkd (original)
+++ incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/drawing/rotate_line.wtkd Tue Sep 15 00:45:57 2009
@@ -16,11 +16,12 @@
limitations under the License.
-->
-<Drawing width="320" height="320" background="#cccccc"
+<Drawing background="#cccccc"
xmlns:wtkx="http://pivot.apache.org/wtkx"
xmlns="org.apache.pivot.wtk.media">
<canvas>
<Canvas xmlns="org.apache.pivot.wtk.media.drawing">
+ <Rectangle width="320" height="320"/>
<Line x1="0" y1="0" x2="0" y2="-160" strokeThickness="4">
<transforms>
<Shape.Translate x="160" y="160"/>
Modified: incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/layout/panels.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/layout/panels.wtkx?rev=814945&r1=814944&r2=814945&view=diff
==============================================================================
--- incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/layout/panels.wtkx (original)
+++ incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/layout/panels.wtkx Tue Sep 15 00:45:57 2009
@@ -25,7 +25,7 @@
<StackPane>
<ImageView styles="{horizontalAlignment:'left', verticalAlignment:'top'}">
<image>
- <media:Drawing width="400" height="320">
+ <media:Drawing>
<canvas>
<drawing:Canvas>
<drawing:Rectangle x="20" y="20" width="320" height="240"
Modified: incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/menus/MenuButtons.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/menus/MenuButtons.java?rev=814945&r1=814944&r2=814945&view=diff
==============================================================================
--- incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/menus/MenuButtons.java (original)
+++ incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/menus/MenuButtons.java Tue Sep 15 00:45:57 2009
@@ -95,10 +95,10 @@
colorListButton = (ListButton)wtkxSerializer.get("colorListButton");
imageView = (ImageView)wtkxSerializer.get("imageView");
- drawing = new Drawing(480, 360);
+ drawing = new Drawing();
Rectangle border = new Rectangle();
- border.setSize(479, 359);
+ border.setSize(480, 360);
border.setFill((Paint)null);
border.setStrokeThickness(1);
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=814945&r1=814944&r2=814945&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 00:45:57 2009
@@ -22,6 +22,7 @@
import org.apache.pivot.util.ListenerList;
import org.apache.pivot.wtk.Bounds;
+import org.apache.pivot.wtk.Dimensions;
import org.apache.pivot.wtk.GraphicsUtilities;
import org.apache.pivot.wtk.media.drawing.Canvas;
import org.apache.pivot.wtk.media.drawing.CanvasListener;
@@ -48,29 +49,62 @@
}
}
- private Canvas canvas;
+ private Canvas canvas = null;
private Paint background = null;
- private int width = 0;
- private int height = 0;
+
+ private Dimensions size = null;
private CanvasListener canvasListener = new CanvasListener() {
@Override
public void regionUpdated(Canvas canvas, int x, int y, int width, int height) {
- Bounds bounds = new Bounds(0, 0, Drawing.this.width, Drawing.this.height);
- bounds = bounds.intersect(new Bounds(x, y, width, height));
- imageListeners.regionUpdated(Drawing.this, bounds.x, bounds.y, bounds.width, bounds.height);
+ imageListeners.regionUpdated(Drawing.this, x, y, width, height);
+ }
+
+ @Override
+ public void canvasInvalidated(Canvas canvas) {
+ int previousWidth = size.width;
+ int previousHeight = size.height;
+
+ invalidate();
+
+ imageListeners.sizeChanged(Drawing.this, previousWidth, previousHeight);
}
};
private DrawingListenerList drawingListeners = new DrawingListenerList();
public Drawing() {
- this(640, 480);
+ setCanvas(new Canvas());
}
- public Drawing(int width, int height) {
- setCanvas(new Canvas());
- setSize(width, height);
+ public int getWidth() {
+ validate();
+ return size.width;
+ }
+
+ public int getHeight() {
+ validate();
+ return size.height;
+ }
+
+ private void invalidate() {
+ size = null;
+ }
+
+ private void validate() {
+ if (size == null) {
+ int width, height;
+ if (canvas == null) {
+ width = 0;
+ height = 0;
+ } else {
+ Bounds canvasBounds = canvas.getBounds();
+ width = Math.max(canvasBounds.x, 0) + canvasBounds.width;
+ height = Math.max(canvasBounds.y, 0) + canvasBounds.height;
+ }
+
+ size = new Dimensions(width, height);
+ }
}
public Canvas getCanvas() {
@@ -91,38 +125,9 @@
canvas.getCanvasListeners().add(canvasListener);
}
- drawingListeners.canvasChanged(this, previousCanvas);
- imageListeners.regionUpdated(this, 0, 0, width, height);
- }
- }
-
- @Override
- public int getWidth() {
- return width;
- }
-
- public void setWidth(int width) {
- setSize(width, height);
- }
+ size = null;
- @Override
- public int getHeight() {
- return height;
- }
-
- public void setHeight(int height) {
- setSize(width, height);
- }
-
- public void setSize(int width, int height) {
- int previousWidth = this.width;
- int previousHeight = this.height;
-
- if (previousWidth != width
- || previousHeight != height) {
- this.width = width;
- this.height = height;
- imageListeners.sizeChanged(this, previousWidth, previousHeight);
+ drawingListeners.canvasChanged(this, previousCanvas);
}
}
@@ -134,7 +139,6 @@
Paint previousBackground = this.background;
if (previousBackground != background) {
this.background = background;
- imageListeners.regionUpdated(this, 0, 0, width, height);
drawingListeners.backgroundChanged(this, previousBackground);
}
}
@@ -149,6 +153,9 @@
@Override
public void paint(Graphics2D graphics) {
+ int width = getWidth();
+ int height = getHeight();
+
graphics.clipRect(0, 0, width, height);
if (background != null) {
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/Canvas.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/Canvas.java?rev=814945&r1=814944&r2=814945&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/Canvas.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/Canvas.java Tue Sep 15 00:45:57 2009
@@ -17,20 +17,11 @@
package org.apache.pivot.wtk.media.drawing;
import org.apache.pivot.util.ListenerList;
-import org.apache.pivot.wtk.ApplicationContext;
-
/**
* Shape representing the root of a shape hierarchy.
*/
public class Canvas extends Group {
- private class ValidateCallback implements Runnable {
- public void run() {
- validate();
- validateCallback = null;
- }
- }
-
private static class CanvasListenerList extends ListenerList<CanvasListener>
implements CanvasListener {
public void regionUpdated(Canvas canvas, int x, int y, int width, int height) {
@@ -38,9 +29,14 @@
listener.regionUpdated(canvas, x, y, width, height);
}
}
- }
- private ValidateCallback validateCallback = null;
+ @Override
+ public void canvasInvalidated(Canvas canvas) {
+ for (CanvasListener listener : this) {
+ listener.canvasInvalidated(canvas);
+ }
+ }
+ }
@Override
protected void setParent(Group parent) {
@@ -59,12 +55,10 @@
@Override
public void invalidate() {
- if (validateCallback == null) {
- validateCallback = new ValidateCallback();
- ApplicationContext.queueCallback(validateCallback);
+ if (isValid()) {
+ super.invalidate();
+ canvasListeners.canvasInvalidated(this);
}
-
- super.invalidate();
}
@Override
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/CanvasListener.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/CanvasListener.java?rev=814945&r1=814944&r2=814945&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/CanvasListener.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/media/drawing/CanvasListener.java Tue Sep 15 00:45:57 2009
@@ -30,4 +30,11 @@
* @param height
*/
public void regionUpdated(Canvas canvas, int x, int y, int width, int height);
+
+ /**
+ * Called when a canvas has been invalidated.
+ *
+ * @param canvas
+ */
+ public void canvasInvalidated(Canvas canvas);
}
Modified: incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/activity.wtkd
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/activity.wtkd?rev=814945&r1=814944&r2=814945&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/activity.wtkd (original)
+++ incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/activity.wtkd Tue Sep 15 00:45:57 2009
@@ -16,11 +16,12 @@
limitations under the License.
-->
-<Drawing width="256" height="256" background="#ffffff"
+<Drawing background="#ffffff"
xmlns:wtkx="http://pivot.apache.org/wtkx"
xmlns="org.apache.pivot.wtk.media">
<canvas>
<Canvas xmlns="org.apache.pivot.wtk.media.drawing">
+ <Rectangle width="256" height="256"/>
<Group>
<transforms>
<Shape.Translate x="128" y="128"/>
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=814945&r1=814944&r2=814945&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 00:45:57 2009
@@ -24,13 +24,11 @@
<ImageView wtkx:id="imageView"
styles="{horizontalAlignment:'left', verticalAlignment:'top', backgroundColor:'#999999'}">
<image>
- <media:Drawing width="640" height="480">
+ <media:Drawing>
<canvas>
<drawing:Canvas>
- <!--
<drawing:Rectangle x="0" y="0" width="120" height="60"
fill="#ff0000" stroke=""/>
- -->
<drawing:Ellipse x="60" y="30" width="120" height="60"
fill="#00ff00" stroke="#000000" strokeThickness="10">
<!--
Modified: incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/sample_drawing.wtkd
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/sample_drawing.wtkd?rev=814945&r1=814944&r2=814945&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/sample_drawing.wtkd (original)
+++ incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/sample_drawing.wtkd Tue Sep 15 00:45:57 2009
@@ -16,11 +16,12 @@
limitations under the License.
-->
-<Drawing width="640" height="480" background="#ffff00"
+<Drawing background="#ffff00"
xmlns:wtkx="http://pivot.apache.org/wtkx"
xmlns="org.apache.pivot.wtk.media">
<canvas>
<Canvas xmlns="org.apache.pivot.wtk.media.drawing">
+ <Rectangle width="640" height="480"/>
<Rectangle x="10" y="20"
width="320" height="240" fill="#ff0000"
stroke="#0000ff" strokeThickness="6"/>