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/06/26 14:42:18 UTC

svn commit: r788678 - in /incubator/pivot/trunk: demos/www/ tools/src/org/apache/pivot/tools/json/ wtk/src/org/apache/pivot/wtk/ wtk/src/org/apache/pivot/wtk/effects/

Author: gbrown
Date: Fri Jun 26 12:42:18 2009
New Revision: 788678

URL: http://svn.apache.org/viewvc?rev=788678&view=rev
Log:
Ensure that DesktopApplicationContext title bar changes in response to active root window title changes; include dropped file name in title bar in JSON Viewer; add a JSON Viewer HTML page to the demos project.

Added:
    incubator/pivot/trunk/demos/www/json_viewer.template.html
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/effects/OverlayDecorator.java
Modified:
    incubator/pivot/trunk/tools/src/org/apache/pivot/tools/json/JSONViewer.java
    incubator/pivot/trunk/tools/src/org/apache/pivot/tools/json/json_viewer.wtkx
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/DesktopApplicationContext.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/effects/ShadeDecorator.java

Added: incubator/pivot/trunk/demos/www/json_viewer.template.html
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/demos/www/json_viewer.template.html?rev=788678&view=auto
==============================================================================
--- incubator/pivot/trunk/demos/www/json_viewer.template.html (added)
+++ incubator/pivot/trunk/demos/www/json_viewer.template.html Fri Jun 26 12:42:18 2009
@@ -0,0 +1,40 @@
+<!--
+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.
+-->
+
+<html>
+<head>
+<title>Pivot JSON Viewer</title>
+</head>
+<body>
+<p>Allows users to visually browse a JSON structure using a TreeView component.</p>
+
+<script src="http://java.com/js/deployJava.js"></script>
+<script>
+var attributes = {code:"org.apache.pivot.wtk.BrowserApplicationContext$HostApplet",
+    archive:"lib/@project_name@-core-@version@.signed.jar,lib/@project_name@-wtk-@version@.signed.jar,lib/@project_name@-wtk-@version@.terra.signed.jar,lib/@project_name@-tools-@version@.signed.jar",
+    width:360,
+    height:480,
+    styles:"border:solid 1px #999999"
+};
+var parameters = {application_class_name:"org.apache.pivot.tools.json.JSONViewer",
+    codebase_lookup:false
+};
+var version = "1.6";
+deployJava.runApplet(attributes, parameters, version);
+</script>
+</body>
+</html>

Modified: incubator/pivot/trunk/tools/src/org/apache/pivot/tools/json/JSONViewer.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tools/src/org/apache/pivot/tools/json/JSONViewer.java?rev=788678&r1=788677&r2=788678&view=diff
==============================================================================
--- incubator/pivot/trunk/tools/src/org/apache/pivot/tools/json/JSONViewer.java (original)
+++ incubator/pivot/trunk/tools/src/org/apache/pivot/tools/json/JSONViewer.java Fri Jun 26 12:42:18 2009
@@ -31,19 +31,25 @@
 import org.apache.pivot.wtk.DesktopApplicationContext;
 import org.apache.pivot.wtk.Display;
 import org.apache.pivot.wtk.DropAction;
+import org.apache.pivot.wtk.HorizontalAlignment;
+import org.apache.pivot.wtk.Label;
 import org.apache.pivot.wtk.Manifest;
 import org.apache.pivot.wtk.Prompt;
 import org.apache.pivot.wtk.TreeView;
+import org.apache.pivot.wtk.VerticalAlignment;
 import org.apache.pivot.wtk.Window;
 import org.apache.pivot.wtk.content.TreeBranch;
 import org.apache.pivot.wtk.content.TreeNode;
+import org.apache.pivot.wtk.effects.OverlayDecorator;
 import org.apache.pivot.wtkx.WTKXSerializer;
 
 public class JSONViewer implements Application {
     private Window window = null;
     private TreeView treeView = null;
+    private OverlayDecorator promptDecorator = new OverlayDecorator();
 
     public static final String APPLICATION_KEY = "application";
+    public static final String WINDOW_TITLE = "JSON Viewer";
 
     @Override
     public void startup(Display display, Map<String, String> properties)
@@ -54,6 +60,13 @@
         window = (Window)wtkxSerializer.readObject(this, "json_viewer.wtkx");
         treeView = (TreeView)wtkxSerializer.get("treeView");
 
+        Label prompt = new Label("Drag or paste JSON here");
+        prompt.getStyles().put("horizontalAlignment", HorizontalAlignment.CENTER);
+        prompt.getStyles().put("verticalAlignment", VerticalAlignment.CENTER);
+        promptDecorator.setOverlay(prompt);
+        treeView.getDecorators().add(promptDecorator);
+
+        window.setTitle(WINDOW_TITLE);
         window.open(display);
         window.requestFocus();
     }
@@ -89,6 +102,8 @@
             } catch(SerializationException exception) {
                 Prompt.prompt(exception.getMessage(), window);
             }
+
+            window.setTitle(WINDOW_TITLE);
         }
     }
 
@@ -117,6 +132,8 @@
                     Prompt.prompt(exception.getMessage(), window);
                 }
 
+                window.setTitle(WINDOW_TITLE + " - " + file.getName());
+
                 dropAction = DropAction.COPY;
             } else {
                 Prompt.prompt("Multiple files not supported.", window);
@@ -131,6 +148,12 @@
     private void setValue(Object value) {
         assert (value instanceof Map<?, ?>
             || value instanceof List<?>);
+        // Remove prompt decorator
+        if (promptDecorator != null) {
+            treeView.getDecorators().remove(promptDecorator);
+            promptDecorator = null;
+        }
+
         TreeBranch treeData = new TreeBranch();
         treeData.add(build(value));
         treeView.setTreeData(treeData);

Modified: incubator/pivot/trunk/tools/src/org/apache/pivot/tools/json/json_viewer.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tools/src/org/apache/pivot/tools/json/json_viewer.wtkx?rev=788678&r1=788677&r2=788678&view=diff
==============================================================================
--- incubator/pivot/trunk/tools/src/org/apache/pivot/tools/json/json_viewer.wtkx (original)
+++ incubator/pivot/trunk/tools/src/org/apache/pivot/tools/json/json_viewer.wtkx Fri Jun 26 12:42:18 2009
@@ -16,7 +16,7 @@
 limitations under the License.
 -->
 
-<Window title="JSON Viewer" maximized="true"
+<Window maximized="true"
     xmlns:wtkx="http://pivot.apache.org/wtkx"
     xmlns:content="org.apache.pivot.wtk.content"
     xmlns="org.apache.pivot.wtk">

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/DesktopApplicationContext.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/DesktopApplicationContext.java?rev=788678&r1=788677&r2=788678&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/DesktopApplicationContext.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/DesktopApplicationContext.java Fri Jun 26 12:42:18 2009
@@ -137,6 +137,8 @@
     private static HostFrame windowedHostFrame = null;
     private static HostFrame fullScreenHostFrame = null;
 
+    private static Runnable updateFrameTitleBarCallback = null;
+
     private static final String DEFAULT_HOST_FRAME_TITLE = "Pivot";
 
     private static final String X_ARGUMENT = "x";
@@ -369,26 +371,50 @@
         // Open the windowed host
         windowedHostFrame.setVisible(true);
 
+        final WindowListener rootOwnerListener = new WindowListener.Adapter() {
+            @Override
+            public void titleChanged(Window window, String previousTitle) {
+                updateFrameTitleBar(window);
+            }
+
+            @Override
+            public void iconChanged(Window window, Image previousIcon) {
+                updateFrameTitleBar(window);
+            }
+        };
+
         Window.getWindowClassListeners().add(new WindowClassListener() {
             public void activeWindowChanged(Window previousActiveWindow) {
-                ApplicationContext.queueCallback(new Runnable() {
-                    public void run() {
-                        Window activeWindow = Window.getActiveWindow();
-
-                        if (activeWindow == null) {
-                            windowedHostFrame.setTitle(DEFAULT_HOST_FRAME_TITLE);
-                        } else {
-                            Window rootOwner = activeWindow.getRootOwner();
-                            windowedHostFrame.setTitle(rootOwner.getTitle());
-
-                            Image rootIcon = rootOwner.getIcon();
-                            if (rootIcon instanceof Picture) {
-                                Picture rootPicture = (Picture)rootIcon;
-                                windowedHostFrame.setIconImage(rootPicture.getBufferedImage());
+                if (previousActiveWindow != null) {
+                    Window previousRootOwner = previousActiveWindow.getRootOwner();
+                    previousRootOwner.getWindowListeners().remove(rootOwnerListener);
+                }
+
+                Window activeWindow = Window.getActiveWindow();
+
+                if (activeWindow != null) {
+                    Window rootOwner = activeWindow.getRootOwner();
+                    rootOwner.getWindowListeners().add(rootOwnerListener);
+                }
+
+                if (updateFrameTitleBarCallback == null) {
+                    updateFrameTitleBarCallback = new Runnable() {
+                        public void run() {
+                            Window activeWindow = Window.getActiveWindow();
+                            if (activeWindow == null) {
+                                windowedHostFrame.setTitle(DEFAULT_HOST_FRAME_TITLE);
+                                windowedHostFrame.setIconImage(null);
+                            } else {
+                                Window rootOwner = activeWindow.getRootOwner();
+                                updateFrameTitleBar(rootOwner);
                             }
+
+                            updateFrameTitleBarCallback = null;
                         }
-                    }
-                });
+                    };
+
+                    queueCallback(updateFrameTitleBarCallback);
+                }
             }
         });
 
@@ -396,27 +422,14 @@
         setFullScreen(fullScreen);
     }
 
-    /**
-     * Utility method to make it easier to define <tt>main()</tt> entry-points
-     * into applications. For example:
-     *
-     * <code>
-     * public class MyApp implements Application {
-     *   public static void main(String[] args) throws Exception {
-     *     DesktopApplicationContext.main(MyApp.class, args);
-     *   }
-     * }
-     * </code>
-     *
-     * @param applicationClass
-     * @param applicationArgs
-     */
-    public static final void main(Class<? extends Application> applicationClass,
-        String[] applicationArgs) {
-        String[] args = new String[applicationArgs.length + 1];
-        System.arraycopy(applicationArgs, 0, args, 1, applicationArgs.length);
-        args[0] = applicationClass.getName();
-        main(args);
+    private static void updateFrameTitleBar(Window rootOwner) {
+        windowedHostFrame.setTitle(rootOwner.getTitle());
+
+        Image icon = rootOwner.getIcon();
+        if (icon instanceof Picture) {
+            Picture rootPicture = (Picture)icon;
+            windowedHostFrame.setIconImage(rootPicture.getBufferedImage());
+        }
     }
 
     /**
@@ -473,4 +486,27 @@
             displayHost.requestFocus();
         }
     }
+
+    /**
+     * Utility method to make it easier to define <tt>main()</tt> entry-points
+     * into applications. For example:
+     *
+     * <code>
+     * public class MyApp implements Application {
+     *   public static void main(String[] args) throws Exception {
+     *     DesktopApplicationContext.main(MyApp.class, args);
+     *   }
+     * }
+     * </code>
+     *
+     * @param applicationClass
+     * @param applicationArgs
+     */
+    public static final void main(Class<? extends Application> applicationClass,
+        String[] applicationArgs) {
+        String[] args = new String[applicationArgs.length + 1];
+        System.arraycopy(applicationArgs, 0, args, 1, applicationArgs.length);
+        args[0] = applicationClass.getName();
+        main(args);
+    }
 }

Added: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/effects/OverlayDecorator.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/effects/OverlayDecorator.java?rev=788678&view=auto
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/effects/OverlayDecorator.java (added)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/effects/OverlayDecorator.java Fri Jun 26 12:42:18 2009
@@ -0,0 +1,75 @@
+/*
+ * 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.effects;
+
+import java.awt.Graphics2D;
+import java.awt.geom.AffineTransform;
+
+import org.apache.pivot.wtk.Bounds;
+import org.apache.pivot.wtk.Component;
+
+/**
+ * Decorator that overlays a component on top of another component. The
+ * overlay component is strictly visual and does not respond to user input.
+ *
+ * @author gbrown
+ */
+public class OverlayDecorator implements Decorator {
+    private Component overlay;
+    private Graphics2D graphics = null;
+
+    public OverlayDecorator() {
+        this(null);
+    }
+
+    public OverlayDecorator(Component overlay) {
+        this.overlay = overlay;
+    }
+
+    public Component getOverlay() {
+        return overlay;
+    }
+
+    public void setOverlay(Component overlay) {
+        this.overlay = overlay;
+    }
+
+    @Override
+    public Graphics2D prepare(Component component, Graphics2D graphics) {
+        this.graphics = graphics;
+
+        overlay.setSize(component.getSize());
+        overlay.validate();
+
+        return graphics;
+    }
+
+    @Override
+    public void update() {
+        overlay.paint(graphics);
+    }
+
+    @Override
+    public Bounds getBounds(Component component) {
+        return new Bounds(0, 0, component.getWidth(), component.getHeight());
+    }
+
+    @Override
+    public AffineTransform getTransform(Component component) {
+        return new AffineTransform();
+    }
+}

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/effects/ShadeDecorator.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/effects/ShadeDecorator.java?rev=788678&r1=788677&r2=788678&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/effects/ShadeDecorator.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/effects/ShadeDecorator.java Fri Jun 26 12:42:18 2009
@@ -24,7 +24,6 @@
 import org.apache.pivot.wtk.Bounds;
 import org.apache.pivot.wtk.Component;
 
-
 /**
  * Decorator that applies a "shade" to a component. The shade is a rectangle
  * of the same size as the component that is painted over the component using a