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/08/17 22:20:19 UTC

svn commit: r805124 - in /incubator/pivot/trunk: core/src/org/apache/pivot/collections/ core/src/org/apache/pivot/serialization/ core/test/org/apache/pivot/collections/test/ wtk/src/org/apache/pivot/wtk/skin/terra/ wtk/test/org/apache/pivot/wtk/test/

Author: gbrown
Date: Mon Aug 17 20:20:19 2009
New Revision: 805124

URL: http://svn.apache.org/viewvc?rev=805124&view=rev
Log:
Minor code formatting cleanup; add support for additional escape characters in JSONSerializer; automatically hide title bar when a Frame is maximized and no window controls are enabled.

Modified:
    incubator/pivot/trunk/core/src/org/apache/pivot/collections/MapList.java
    incubator/pivot/trunk/core/src/org/apache/pivot/serialization/JSONSerializer.java
    incubator/pivot/trunk/core/test/org/apache/pivot/collections/test/MapListTest.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraFrameSkin.java
    incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/MenuBarTest.java
    incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/menu_bar_test.wtkx

Modified: incubator/pivot/trunk/core/src/org/apache/pivot/collections/MapList.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/core/src/org/apache/pivot/collections/MapList.java?rev=805124&r1=805123&r2=805124&view=diff
==============================================================================
--- incubator/pivot/trunk/core/src/org/apache/pivot/collections/MapList.java (original)
+++ incubator/pivot/trunk/core/src/org/apache/pivot/collections/MapList.java Mon Aug 17 20:20:19 2009
@@ -26,12 +26,10 @@
  * Decorates a {@link Map} to look like a {@link List} of key/value pairs. This
  * facilitates the use of a <tt>Map</tt> as table data in a
  * {@link org.apache.pivot.wtk.TableView}.
- * 
  */
 public class MapList<K, V> implements List<Pair<K, V>> {
     /**
      * Map list listener list.
-     * 
      */
     private static class MapListListenerList<K, V> extends ListenerList<MapListListener<K, V>>
         implements MapListListener<K, V> {
@@ -46,7 +44,7 @@
 
     private ArrayList<Pair<K, V>> view = null;
 
-    // this flag is used to prevent recursion if the source is updated
+    // This flag is used to prevent recursion if the source is updated
     // externally
     private boolean updating = false;
 
@@ -120,9 +118,9 @@
 
     /**
      * Creates a new map list that decorates the specified source map.
-     * 
+     *
      * @param source
-     *            The map to present as a list
+     * The map to present as a list
      */
     public MapList(Map<K, V> source) {
         setSource(source);
@@ -130,7 +128,7 @@
 
     /**
      * Gets the source map.
-     * 
+     *
      * @return The source map, or <tt>null</tt> if no source is set
      */
     public Map<K, V> getSource() {
@@ -139,9 +137,9 @@
 
     /**
      * Sets the source map.
-     * 
+     *
      * @param source
-     *            The source map, or <tt>null</tt> to clear the source
+     * The source map, or <tt>null</tt> to clear the source
      */
     public void setSource(Map<K, V> source) {
         if (source == null) {
@@ -327,10 +325,8 @@
     /**
      * Finds the specified pair in the view list by searching linearly and
      * reporting an exact match only (bypasses the list's comparator).
-     * 
-     * @param pair
-     *            The pair to search for
-     * 
+     *
+     * @param pair The pair to search for
      * @return The index of the pair in the list, or <tt>-1</tt> if not found
      */
     private int linearSearch(Pair<K, V> pair) {

Modified: incubator/pivot/trunk/core/src/org/apache/pivot/serialization/JSONSerializer.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/core/src/org/apache/pivot/serialization/JSONSerializer.java?rev=805124&r1=805123&r2=805124&view=diff
==============================================================================
--- incubator/pivot/trunk/core/src/org/apache/pivot/serialization/JSONSerializer.java (original)
+++ incubator/pivot/trunk/core/src/org/apache/pivot/serialization/JSONSerializer.java Mon Aug 17 20:20:19 2009
@@ -263,10 +263,16 @@
             if (c == '\\') {
                 c = reader.read();
 
-                if (c == 't') {
-                    c = '\t';
+                if (c == 'b') {
+                    c = '\b';
+                } else if (c == 'f') {
+                    c = '\f';
                 } else if (c == 'n') {
                     c = '\n';
+                } else if (c == 'r') {
+                    c = '\r';
+                } else if (c == 't') {
+                    c = '\t';
                 } else if (c == 'u') {
                     StringBuilder unicodeBuilder = new StringBuilder();
                     while (unicodeBuilder.length() < 4) {

Modified: incubator/pivot/trunk/core/test/org/apache/pivot/collections/test/MapListTest.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/core/test/org/apache/pivot/collections/test/MapListTest.java?rev=805124&r1=805123&r2=805124&view=diff
==============================================================================
--- incubator/pivot/trunk/core/test/org/apache/pivot/collections/test/MapListTest.java (original)
+++ incubator/pivot/trunk/core/test/org/apache/pivot/collections/test/MapListTest.java Mon Aug 17 20:20:19 2009
@@ -129,16 +129,16 @@
         mapList.add(pair);
         assertEquals(1, mapList.getLength());
         assertEquals(pair, mapList.get(0));
-        
+
         assertEquals(0, mapList.remove(pair));
         assertEquals(0, mapList.getLength());
 
         newSource.put("z", 24);
         assertEquals(1, mapList.getLength());
-        
+
         newSource.put("z", 24);
         assertEquals(1, mapList.getLength());
-        
+
         newSource.clear();
         assertEquals(0, mapList.getLength());
     }

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraFrameSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraFrameSkin.java?rev=805124&r1=805123&r2=805124&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraFrameSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraFrameSkin.java Mon Aug 17 20:20:19 2009
@@ -351,26 +351,44 @@
     public int getPreferredWidth(int height) {
         int preferredWidth = 0;
 
-        Dimensions preferredTitleBarSize = titleBarTablePane.getPreferredSize();
-        preferredWidth = preferredTitleBarSize.width;
-
         Frame frame = (Frame)getComponent();
 
+        // Include title bar width plus left/right title bar borders
+        Dimensions titleBarSize = titleBarTablePane.getPreferredSize();
+        preferredWidth = Math.max(titleBarSize.width + 2, preferredWidth);
+
+        if (height != -1) {
+            // Subtract title bar height and top/bottom title bar borders
+            // from height constraint
+            height -= titleBarSize.height + 2;
+        }
+
+        // Include menu bar width
         MenuBar menuBar = frame.getMenuBar();
         if (menuBar != null) {
-            preferredWidth = Math.max(preferredWidth, menuBar.getPreferredWidth());
+            Dimensions menuBarSize = menuBar.getPreferredSize();
+            preferredWidth = Math.max(preferredWidth, menuBarSize.width);
+
+            if (height != -1) {
+                // Subtract menu bar height from height constraint
+                height -= menuBarSize.height;
+            }
         }
 
         Component content = frame.getContent();
         if (content != null) {
             if (height != -1) {
-                height = Math.max(height - preferredTitleBarSize.height - 5 -
-                    padding.top - padding.bottom, 0);
+                // Subtract padding, top/bottom content borders, and content bevel
+                // from height constraint
+                height -= (padding.top + padding.bottom) + 3;
+
+                height = Math.max(height, 0);
             }
 
             preferredWidth = Math.max(preferredWidth, content.getPreferredWidth(height));
         }
 
+        // Add padding and left/right content borders
         preferredWidth += (padding.left + padding.right) + 2;
 
         return preferredWidth;
@@ -379,14 +397,12 @@
     public int getPreferredHeight(int width) {
         int preferredHeight = 0;
 
-        if (width != -1) {
-            width = Math.max(width - 2, 0);
-        }
-
-        preferredHeight = titleBarTablePane.getPreferredHeight(width);
-
         Frame frame = (Frame)getComponent();
 
+        // Include title bar height plus top/bottom title bar borders
+        preferredHeight += titleBarTablePane.getPreferredHeight() + 2;
+
+        // Include menu bar height
         MenuBar menuBar = frame.getMenuBar();
         if (menuBar != null) {
             preferredHeight += menuBar.getPreferredHeight();
@@ -395,13 +411,17 @@
         Component content = frame.getContent();
         if (content != null) {
             if (width != -1) {
-                width = Math.max(width - padding.left - padding.right, 0);
+                // Subtract padding and left/right content borders from constraint
+                width -= (padding.left + padding.right) + 2;
+
+                width = Math.max(width, 0);
             }
 
             preferredHeight += content.getPreferredHeight(width);
         }
 
-        preferredHeight += (padding.top + padding.bottom) + 5;
+        // Add padding, top/bottom content borders, and content bevel
+        preferredHeight += (padding.top + padding.bottom) + 3;
 
         return preferredHeight;
     }
@@ -410,13 +430,16 @@
         int preferredWidth = 0;
         int preferredHeight = 0;
 
-        Dimensions preferredTitleBarSize = titleBarTablePane.getPreferredSize();
+        Frame frame = (Frame)getComponent();
 
-        preferredWidth = preferredTitleBarSize.width;
-        preferredHeight = preferredTitleBarSize.height;
+        // Include title bar width plus left/right title bar borders
+        Dimensions titleBarSize = titleBarTablePane.getPreferredSize();
+        preferredWidth = Math.max(preferredWidth, titleBarSize.width + 2);
 
-        Frame frame = (Frame)getComponent();
+        // Include title bar height plus top/bottom title bar borders
+        preferredHeight += titleBarSize.height + 2;
 
+        // Include menu bar size
         MenuBar menuBar = frame.getMenuBar();
         if (menuBar != null) {
             Dimensions preferredMenuBarSize = menuBar.getPreferredSize();
@@ -433,63 +456,86 @@
             preferredHeight += preferredContentSize.height;
         }
 
+        // Add padding, borders, and content bevel
         preferredWidth += (padding.left + padding.right) + 2;
-        preferredHeight += (padding.top + padding.bottom) + 5;
+        preferredHeight += (padding.top + padding.bottom) + 3;
 
         return new Dimensions(preferredWidth, preferredHeight);
     }
-
     public void layout() {
         Frame frame = (Frame)getComponent();
 
         int width = getWidth();
         int height = getHeight();
 
-        // Size/position title bar
-        titleBarTablePane.setLocation(1, 1);
-        titleBarTablePane.setSize(Math.max(width - 2, 0),
-            Math.max(titleBarTablePane.getPreferredHeight(width - 2), 0));
-
-        // Size/position resize handle
-        resizeHandle.setSize(resizeHandle.getPreferredSize());
-        resizeHandle.setLocation(width - resizeHandle.getWidth() - 2,
-            height - resizeHandle.getHeight() - 2);
-
         boolean maximized = frame.isMaximized();
-        resizeHandle.setVisible(resizable
-            && !maximized
-            && (frame.isPreferredWidthSet()
-                || frame.isPreferredHeightSet()));
-
-        // Size/position menu bar
-        int contentX = padding.left + 1;
-        int contentY = titleBarTablePane.getHeight() + 4;
-        int contentWidth = Math.max(width - (padding.left + padding.right + 2), 0);
-        int contentHeight = Math.max(height - (titleBarTablePane.getHeight()
-            + padding.top + padding.bottom + 5), 0);
 
-        MenuBar menuBar = frame.getMenuBar();
-        if (menuBar != null) {
-            menuBar.setLocation(1, contentY);
+        if (!maximized
+            || getShowWindowControls()) {
+            int clientX = 1;
+            int clientY = 1;
+            int clientWidth = width - 2;
+            int clientHeight = height - 2;
+
+            // Size/position title bar
+            titleBarTablePane.setLocation(clientX, clientY);
+            titleBarTablePane.setSize(clientWidth, titleBarTablePane.getPreferredHeight());
+            titleBarTablePane.setVisible(true);
+
+            // Add bottom title bar border, top content border, and content bevel
+            clientY += titleBarTablePane.getHeight() + 3;
+
+            // Size/position resize handle
+            resizeHandle.setSize(resizeHandle.getPreferredSize());
+            resizeHandle.setLocation(clientWidth - resizeHandle.getWidth(),
+                clientHeight - resizeHandle.getHeight());
+            resizeHandle.setVisible(resizable
+                && !maximized
+                && (frame.isPreferredWidthSet()
+                    || frame.isPreferredHeightSet()));
+
+            // Size/position menu bar
+            MenuBar menuBar = frame.getMenuBar();
+            if (menuBar != null
+                && menuBar.isVisible()) {
+                menuBar.setLocation(clientX, clientY);
+                menuBar.setSize(clientWidth, menuBar.getPreferredHeight());
 
-            int menuBarWidth = width - 2;
-            if (menuBar.isVisible()) {
-                menuBar.setSize(menuBarWidth, menuBar.getPreferredHeight());
-            } else {
-                menuBar.setSize(menuBarWidth, 0);
+                clientY += menuBar.getHeight();
             }
 
-            contentY += menuBar.getHeight();
-            contentHeight -= menuBar.getHeight();
-        }
+            // Size/position content
+            Component content = frame.getContent();
+            if (content != null) {
+                int contentX = clientX + padding.left;
+                int contentY = clientY + padding.top;
+                int contentWidth = Math.max(clientWidth - (padding.left + padding.right), 0);
+                int contentHeight = Math.max(clientHeight - (clientY + padding.top + padding.bottom), 0);
 
-        contentY += padding.top;
+                content.setLocation(contentX, contentY);
+                content.setSize(contentWidth, contentHeight);
+            }
+        } else {
+            titleBarTablePane.setVisible(false);
+            resizeHandle.setVisible(false);
 
-        // Size/position content
-        Component content = frame.getContent();
-        if (content != null) {
-            content.setLocation(contentX, contentY);
-            content.setSize(contentWidth, contentHeight);
+            // Size/position menu bar
+            int clientY = 0;
+            MenuBar menuBar = frame.getMenuBar();
+            if (menuBar != null
+                && menuBar.isVisible()) {
+                menuBar.setLocation(0, clientY);
+                menuBar.setSize(width, menuBar.getPreferredHeight());
+
+                clientY += menuBar.getHeight();
+            }
+
+            Component content = frame.getContent();
+            if (content != null) {
+                content.setLocation(padding.left, clientY + padding.top);
+                content.setSize(Math.max(width - (padding.left + padding.right), 0),
+                    Math.max(height - (clientY + padding.top + padding.bottom), 0));
+            }
         }
     }
 
@@ -502,34 +548,40 @@
 
         int width = getWidth();
         int height = getHeight();
-        int titleBarHeight = titleBarTablePane.getHeight();
 
-        // Draw the title area
-        Color titleBarBackgroundColor = frame.isActive() ?
-            this.titleBarBackgroundColor : inactiveTitleBarBackgroundColor;
-        Color titleBarBorderColor = frame.isActive() ?
-            this.titleBarBorderColor : inactiveTitleBarBorderColor;
-        Color titleBarBevelColor = frame.isActive() ?
-            this.titleBarBevelColor : inactiveTitleBarBevelColor;
-
-        graphics.setPaint(new GradientPaint(width / 2, 0, titleBarBevelColor,
-            width / 2, titleBarHeight + 1, titleBarBackgroundColor));
-        graphics.fillRect(0, 0, width, titleBarHeight + 1);
-
-        // Draw the border
-        graphics.setPaint(titleBarBorderColor);
-        GraphicsUtilities.drawRect(graphics, 0, 0, width, titleBarHeight + 2);
-
-        // Draw the content area
-        Bounds contentAreaRectangle = new Bounds(0, titleBarHeight + 2,
-            width, height - (titleBarHeight + 2));
-        graphics.setPaint(contentBorderColor);
-        GraphicsUtilities.drawRect(graphics, contentAreaRectangle.x, contentAreaRectangle.y,
-            contentAreaRectangle.width, contentAreaRectangle.height);
-
-        graphics.setPaint(contentBevelColor);
-        GraphicsUtilities.drawLine(graphics, contentAreaRectangle.x + 1,
-            contentAreaRectangle.y + 1, contentAreaRectangle.width - 2, Orientation.HORIZONTAL);
+        boolean maximized = frame.isMaximized();
+
+        if (!maximized
+            || getShowWindowControls()) {
+            int titleBarHeight = titleBarTablePane.getHeight();
+
+            // Draw the title area
+            Color titleBarBackgroundColor = frame.isActive() ?
+                this.titleBarBackgroundColor : inactiveTitleBarBackgroundColor;
+            Color titleBarBorderColor = frame.isActive() ?
+                this.titleBarBorderColor : inactiveTitleBarBorderColor;
+            Color titleBarBevelColor = frame.isActive() ?
+                this.titleBarBevelColor : inactiveTitleBarBevelColor;
+
+            graphics.setPaint(new GradientPaint(width / 2, 0, titleBarBevelColor,
+                width / 2, titleBarHeight + 1, titleBarBackgroundColor));
+            graphics.fillRect(0, 0, width, titleBarHeight + 1);
+
+            // Draw the border
+            graphics.setPaint(titleBarBorderColor);
+            GraphicsUtilities.drawRect(graphics, 0, 0, width, titleBarHeight + 2);
+
+            // Draw the content area
+            Bounds contentAreaRectangle = new Bounds(0, titleBarHeight + 2,
+                width, height - (titleBarHeight + 2));
+            graphics.setPaint(contentBorderColor);
+            GraphicsUtilities.drawRect(graphics, contentAreaRectangle.x, contentAreaRectangle.y,
+                contentAreaRectangle.width, contentAreaRectangle.height);
+
+            graphics.setPaint(contentBevelColor);
+            GraphicsUtilities.drawLine(graphics, contentAreaRectangle.x + 1,
+                contentAreaRectangle.y + 1, contentAreaRectangle.width - 2, Orientation.HORIZONTAL);
+        }
     }
 
     @Override
@@ -567,6 +619,18 @@
         closeButton.setVisible(showCloseButton);
     }
 
+    public boolean getShowWindowControls() {
+        return (getShowMinimizeButton()
+            && getShowMaximizeButton()
+            && getShowCloseButton());
+    }
+
+    public void setShowWindowControls(boolean showWindowControls) {
+        setShowMinimizeButton(showWindowControls);
+        setShowMaximizeButton(showWindowControls);
+        setShowCloseButton(showWindowControls);
+    }
+
     public Insets getPadding() {
         return padding;
     }
@@ -675,7 +739,8 @@
             }
         } else {
             Cursor cursor = null;
-            if (x > resizeHandle.getX()
+            if (resizeHandle.isVisible()
+                && x > resizeHandle.getX()
                 && y > resizeHandle.getY()) {
                 boolean preferredWidthSet = component.isPreferredWidthSet();
                 boolean preferredHeightSet = component.isPreferredHeightSet();

Modified: incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/MenuBarTest.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/MenuBarTest.java?rev=805124&r1=805123&r2=805124&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/MenuBarTest.java (original)
+++ incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/MenuBarTest.java Mon Aug 17 20:20:19 2009
@@ -44,6 +44,7 @@
         boxPane.add(new TextInput());
         boxPane.add(new TextInput());
         frame1 = new Frame(boxPane);
+        frame1.setLocation(50, 50);
         frame1.setPreferredSize(320, 240);
         frame1.open(display);
 
@@ -67,7 +68,6 @@
         textInput2.setMenuHandler(menuHandler);
         textInput3.setMenuHandler(menuHandler);
 
-        frame2.setLocation(40, 40);
         frame2.open(display);
     }
 

Modified: incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/menu_bar_test.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/menu_bar_test.wtkx?rev=805124&r1=805123&r2=805124&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/menu_bar_test.wtkx (original)
+++ incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/menu_bar_test.wtkx Mon Aug 17 20:20:19 2009
@@ -16,8 +16,8 @@
 limitations under the License.
 -->
 
-<Frame title="MenuBar Test" preferredWidth="320" preferredHeight="240"
-    styles="{padding:{top:0, left:4, bottom:4, right:4}}"
+<Frame title="MenuBar Test" maximized="false" preferredWidth="320" preferredHeight="240"
+    styles="{padding:{top:0, left:4, bottom:4, right:4}, showWindowControls:true}"
     xmlns:wtkx="http://pivot.apache.org/wtkx"
     xmlns:content="org.apache.pivot.wtk.content"
     xmlns="org.apache.pivot.wtk">