You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by tv...@apache.org on 2009/05/01 23:26:00 UTC

svn commit: r770825 - in /incubator/pivot/trunk/wtk/test/pivot/wtk/test: MovieViewTest.java clock.wtkd

Author: tvolkert
Date: Fri May  1 21:25:55 2009
New Revision: 770825

URL: http://svn.apache.org/viewvc?rev=770825&view=rev
Log:
Updated MovieViewTest to show an accurate clock

Added:
    incubator/pivot/trunk/wtk/test/pivot/wtk/test/clock.wtkd
Modified:
    incubator/pivot/trunk/wtk/test/pivot/wtk/test/MovieViewTest.java

Modified: incubator/pivot/trunk/wtk/test/pivot/wtk/test/MovieViewTest.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/test/pivot/wtk/test/MovieViewTest.java?rev=770825&r1=770824&r2=770825&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/test/pivot/wtk/test/MovieViewTest.java (original)
+++ incubator/pivot/trunk/wtk/test/pivot/wtk/test/MovieViewTest.java Fri May  1 21:25:55 2009
@@ -16,8 +16,8 @@
  */
 package pivot.wtk.test;
 
-import java.awt.Color;
 import java.awt.Graphics2D;
+import java.util.Calendar;
 
 import pivot.collections.Dictionary;
 import pivot.wtk.Application;
@@ -25,86 +25,89 @@
 import pivot.wtk.Display;
 import pivot.wtk.MovieView;
 import pivot.wtk.Window;
-import pivot.wtk.media.Drawing;
+import pivot.wtk.media.Image;
+import pivot.wtk.media.ImageListener;
 import pivot.wtk.media.Movie;
-import pivot.wtk.media.drawing.Line;
 import pivot.wtk.media.drawing.Shape;
+import pivot.wtkx.WTKXSerializer;
 
 public class MovieViewTest implements Application {
-    private Window window;
-
-    private Movie movie = new Movie() {
-        private int angle = 6;
-        private Drawing drawing = new Drawing();
-            private Shape.Rotate rotateTransform = new Shape.Rotate(0, 320, 240);
+    private class Clock extends Movie {
+        private Calendar calendar = Calendar.getInstance();
+        private WTKXSerializer wtkxSerializer;
+        private Image image = null;
 
         {
-            setLooping(true);
-            setFrameRate(1);
+            wtkxSerializer = new WTKXSerializer();
+            try {
+                image = (Image)wtkxSerializer.readObject(getClass().getResource("clock.wtkd"));
+            } catch (Exception ex) {
+                throw new RuntimeException(ex);
+            }
 
-            drawing.setSize(640, 480);
+            image.getImageListeners().add(new ImageListener() {
+                public void sizeChanged(Image image, int previousWidth, int previousHeight) {
+                }
+
+                public void regionUpdated(Image image, int x, int y, int width, int height) {
+                    movieListeners.regionUpdated(Clock.this, 0, 0, width, height);
+                }
+            });
 
-            Line line = new Line();
-            line.setX1(220);
-            line.setY1(240);
-            line.setX2(220);
-            line.setY2(40);
-            /*
-            line.setOrigin(320, 240);
-            line.setX1(0);
-            line.setY1(0);
-            line.setX2(0);
-            line.setY2(-200);
-            */
-
-            line.setStroke(Color.BLACK);
-            line.setStrokeThickness(5);
-            line.getTransforms().add(rotateTransform);
-            drawing.getCanvas().add(line);
+            setLooping(true);
+            setFrameRate(1);
         }
 
         public void setCurrentFrame(int currentFrame) {
-            if (currentFrame == 0) {
-                System.out.println(currentFrame);
-            }
-            rotateTransform.setAngle(currentFrame * angle);
-
-            movieListeners.regionUpdated(this, 0, 0, getWidth(), getHeight());
+            Shape.Rotate secondsRotation = (Shape.Rotate)wtkxSerializer.getObjectByName("secondsRotation");
+            Shape.Rotate minutesRotation = (Shape.Rotate)wtkxSerializer.getObjectByName("minutesRotation");
+            Shape.Rotate hoursRotation = (Shape.Rotate)wtkxSerializer.getObjectByName("hoursRotation");
+
+            calendar.setTimeInMillis(System.currentTimeMillis());
+
+            int seconds = calendar.get(Calendar.SECOND);
+            int minutes = calendar.get(Calendar.MINUTE);
+            int hours = calendar.get(Calendar.HOUR) + 1;
+
+            secondsRotation.setAngle(seconds * 6);
+            minutesRotation.setAngle(minutes * 6 + seconds * (6d / 60));
+            hoursRotation.setAngle(hours * 30 + minutes * (6d / 12));
 
             super.setCurrentFrame(currentFrame);
         }
 
         public int getWidth() {
-            return drawing.getWidth();
+            return image.getWidth();
         }
 
         public int getHeight() {
-            return drawing.getHeight();
+            return image.getHeight();
         }
 
         public void paint(Graphics2D graphics) {
-            drawing.paint(graphics);
+            image.paint(graphics);
         }
 
         public int getTotalFrames() {
-            return (360 / angle);
+            return 60;
         }
-    };
-
-    public static void main(String[] args) {
-        DesktopApplicationContext.main(MovieViewTest.class, args);
     }
 
+    private Window window;
+    private Clock clock = new Clock();
+
     public void startup(Display display, Dictionary<String, String> properties) {
-        window = new Window();
+        window = new Window(new MovieView(clock));
         window.setMaximized(true);
-        window.setContent(new MovieView(movie));
         window.open(display);
-        movie.play();
+        clock.play();
     }
 
     public boolean shutdown(boolean optional) {
-        window.close();
+        if (window != null) {
+            window.close();
+        }
+
         return true;
     }
 
@@ -113,4 +116,8 @@
 
     public void resume() {
     }
+
+    public static void main(String[] args) {
+        DesktopApplicationContext.main(MovieViewTest.class, args);
+    }
 }

Added: incubator/pivot/trunk/wtk/test/pivot/wtk/test/clock.wtkd
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/test/pivot/wtk/test/clock.wtkd?rev=770825&view=auto
==============================================================================
--- incubator/pivot/trunk/wtk/test/pivot/wtk/test/clock.wtkd (added)
+++ incubator/pivot/trunk/wtk/test/pivot/wtk/test/clock.wtkd Fri May  1 21:25:55 2009
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+-->
+
+<Drawing width="320" height="240"
+    xmlns="pivot.wtk.media"
+    xmlns:wtkx="http://incubator.apache.org/pivot/wtkx/1.1">
+    <canvas>
+        <Canvas xmlns="pivot.wtk.media.drawing">
+            <Ellipse x="41" y="1" width="238" height="238" stroke="#777777" strokeThickness="1" fill="#eeeeee"/>
+            <Line x="160" y="120" x1="0" y1="1" x2="0" y2="-60" strokeThickness="5">
+                <transforms>
+                    <Shape.Rotate wtkx:id="hoursRotation"/>
+                </transforms>
+            </Line>
+            <Line x="160" y="120" x1="0" y1="3" x2="0" y2="-100" stroke="#0000dd" strokeThickness="3">
+                <transforms>
+                    <Shape.Rotate wtkx:id="minutesRotation"/>
+                </transforms>
+            </Line>
+            <Line x="160" y="120" x1="0" y1="10" x2="0" y2="-110" stroke="#dd0000" strokeThickness="2">
+                <transforms>
+                    <Shape.Rotate wtkx:id="secondsRotation"/>
+                </transforms>
+            </Line>
+        </Canvas>
+    </canvas>
+</Drawing>