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/11/09 23:26:00 UTC

svn commit: r834258 - in /incubator/pivot/trunk: tutorials/www/ wtk/src/org/apache/pivot/wtk/skin/ wtk/src/org/apache/pivot/wtk/skin/terra/ wtk/test/org/apache/pivot/wtk/test/

Author: gbrown
Date: Mon Nov  9 22:26:00 2009
New Revision: 834258

URL: http://svn.apache.org/viewvc?rev=834258&view=rev
Log:
Add baseline support to TextArea, TableView, and TableViewHeader; fix bugs in BoxPane baseline calculations.

Modified:
    incubator/pivot/trunk/tutorials/www/flow_panes.html
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/BoxPaneSkin.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraTableViewHeaderSkin.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraTableViewSkin.java
    incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/FormTest.java
    incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/form_test.wtkx

Modified: incubator/pivot/trunk/tutorials/www/flow_panes.html
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/www/flow_panes.html?rev=834258&r1=834257&r2=834258&view=diff
==============================================================================
--- incubator/pivot/trunk/tutorials/www/flow_panes.html (original)
+++ incubator/pivot/trunk/tutorials/www/flow_panes.html Mon Nov  9 22:26:00 2009
@@ -59,22 +59,33 @@
 <pre class="brush:xml">
 &lt;Window title="Flow Panes" maximized="true"
     xmlns:wtkx="http://pivot.apache.org/wtkx"
+    xmlns:effects="org.apache.pivot.wtk.effects"
     xmlns="org.apache.pivot.wtk"&gt;
     &lt;content&gt;
         &lt;SplitPane splitRatio="0.75"&gt;
             &lt;left&gt;
-                &lt;Border&gt;
+                &lt;Border styles="{padding:4}"&gt;
                     &lt;content&gt;
-                        &lt;FlowPane wtkx:id="flowPane" styles="{padding:2}"&gt;
-                            &lt;PushButton buttonData="0" styles="{minimumAspectRatio:1.5}"/&gt;
-                            &lt;PushButton buttonData="1" styles="{minimumAspectRatio:1.5}"/&gt;
-                            &lt;PushButton buttonData="2" styles="{minimumAspectRatio:1.5}"/&gt;
-                            &lt;PushButton buttonData="3" preferredWidth="20" preferredHeight="20"/&gt;
-                            &lt;PushButton buttonData="4" preferredWidth="30" preferredHeight="30"/&gt;
-                            &lt;PushButton buttonData="5" preferredWidth="40" preferredHeight="40"/&gt;
-                            &lt;PushButton buttonData="6" styles="{minimumAspectRatio:1.5}"/&gt;
-                            &lt;PushButton buttonData="7" styles="{minimumAspectRatio:1.5}"/&gt;
-                        &lt;/FlowPane&gt;
+                        &lt;BoxPane orientation="vertical" styles="{verticalAlignment:'center', fill:true}"&gt;
+                            &lt;Border&gt;
+                                &lt;content&gt;
+                                    &lt;FlowPane wtkx:id="flowPane" styles="{padding:2}"&gt;
+                                        &lt;decorators&gt;
+                                            &lt;effects:BaselineDecorator/&gt;
+                                        &lt;/decorators&gt;
+
+                                        &lt;PushButton buttonData="0" styles="{minimumAspectRatio:1.5}"/&gt;
+                                        &lt;PushButton buttonData="1" styles="{minimumAspectRatio:1.5}"/&gt;
+                                        &lt;PushButton buttonData="2" styles="{minimumAspectRatio:1.5}"/&gt;
+                                        &lt;PushButton buttonData="3" preferredWidth="20" preferredHeight="20"/&gt;
+                                        &lt;PushButton buttonData="4" preferredWidth="30" preferredHeight="30"/&gt;
+                                        &lt;PushButton buttonData="5" preferredWidth="40" preferredHeight="40"/&gt;
+                                        &lt;PushButton buttonData="6" styles="{minimumAspectRatio:1.5}"/&gt;
+                                        &lt;PushButton buttonData="7" styles="{minimumAspectRatio:1.5}"/&gt;
+                                    &lt;/FlowPane&gt;
+                                &lt;/content&gt;
+                            &lt;/Border&gt;
+                        &lt;/BoxPane&gt;
                     &lt;/content&gt;
                 &lt;/Border&gt;
             &lt;/left&gt;

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/BoxPaneSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/BoxPaneSkin.java?rev=834258&r1=834257&r2=834258&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/BoxPaneSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/BoxPaneSkin.java Mon Nov  9 22:26:00 2009
@@ -214,7 +214,7 @@
                     if (component.isVisible()) {
                         Dimensions size;
                         if (fill) {
-                            size = new Dimensions(component.getPreferredHeight(height), height);
+                            size = new Dimensions(component.getPreferredWidth(height), height);
                         } else {
                             size = component.getPreferredSize();
                         }
@@ -232,7 +232,7 @@
                     if (component.isVisible()) {
                         Dimensions size;
                         if (fill) {
-                            size = new Dimensions(component.getPreferredHeight(height), height);
+                            size = new Dimensions(width, component.getPreferredHeight(width));
                         } else {
                             size = component.getPreferredSize();
                         }

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin.java?rev=834258&r1=834257&r2=834258&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin.java Mon Nov  9 22:26:00 2009
@@ -1480,9 +1480,10 @@
     }
 
     @Override
-    public boolean isOpaque() {
-        return (backgroundColor != null
-            && backgroundColor.getTransparency() == Transparency.OPAQUE);
+    public int getBaseline(int width, int height) {
+        LineMetrics lm = font.getLineMetrics("", FONT_RENDER_CONTEXT);
+        float ascent = lm.getAscent();
+        return margin.top + Math.round(ascent);
     }
 
     @Override
@@ -1541,6 +1542,12 @@
     }
 
     @Override
+    public boolean isOpaque() {
+        return (backgroundColor != null
+            && backgroundColor.getTransparency() == Transparency.OPAQUE);
+    }
+
+    @Override
     public int getInsertionPoint(int x, int y) {
         int offset;
 

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraTableViewHeaderSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraTableViewHeaderSkin.java?rev=834258&r1=834257&r2=834258&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraTableViewHeaderSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraTableViewHeaderSkin.java Mon Nov  9 22:26:00 2009
@@ -208,18 +208,45 @@
     }
 
     @Override
+    public int getBaseline(int width, int height) {
+        int baseline = -1;
+
+        TableViewHeader tableViewHeader = (TableViewHeader)getComponent();
+        TableView tableView = tableViewHeader.getTableView();
+
+        if (tableView != null) {
+            TableView.ColumnSequence columns = tableView.getColumns();
+            TableViewHeader.DataRenderer dataRenderer = tableViewHeader.getDataRenderer();
+
+            for (int i = 0, n = columns.getLength(); i < n; i++) {
+                TableView.Column column = columns.get(i);
+                dataRenderer.render(column.getHeaderData(), tableViewHeader, false);
+
+                Dimensions size = dataRenderer.getPreferredSize();
+                baseline = Math.max(baseline, dataRenderer.getBaseline(size.width, size.height));
+            }
+
+            baseline += 1;
+        }
+
+        return baseline;
+    }
+
+    @Override
     public void layout() {
         TableViewHeader tableViewHeader = (TableViewHeader)getComponent();
         TableView tableView = tableViewHeader.getTableView();
 
-        TableView.ColumnSequence columns = tableView.getColumns();
-        int n = columns.getLength();
+        if (tableView != null) {
+            TableView.ColumnSequence columns = tableView.getColumns();
+            int n = columns.getLength();
 
-        columnWidths = new ArrayList<Integer>(n);
+            columnWidths = new ArrayList<Integer>(n);
 
-        for (int i = 0; i < n; i++) {
-            Bounds columnBounds = tableView.getColumnBounds(i);
-            columnWidths.add(columnBounds.width);
+            for (int i = 0; i < n; i++) {
+                Bounds columnBounds = tableView.getColumnBounds(i);
+                columnWidths.add(columnBounds.width);
+            }
         }
     }
 

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraTableViewSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraTableViewSkin.java?rev=834258&r1=834257&r2=834258&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraTableViewSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraTableViewSkin.java Mon Nov  9 22:26:00 2009
@@ -78,7 +78,6 @@
     private boolean includeTrailingHorizontalGridLine;
 
     private ArrayList<Integer> columnWidths = null;
-    private int rowHeight = -1;
 
     private int highlightedIndex = -1;
     private int editIndex = -1;
@@ -192,6 +191,26 @@
     }
 
     @Override
+    public int getBaseline(int width, int height) {
+        TableView tableView = (TableView)getComponent();
+
+        int baseline = -1;
+
+        TableView.ColumnSequence columns = tableView.getColumns();
+
+        for (int i = 0, n = columns.getLength(); i < n; i++) {
+            TableView.Column column = columns.get(i);
+            TableView.CellRenderer cellRenderer = column.getCellRenderer();
+            cellRenderer.render(null, -1, i, tableView, column.getName(), false, false, false);
+
+            Dimensions size = cellRenderer.getPreferredSize();
+            baseline = Math.max(baseline, cellRenderer.getBaseline(size.width, size.height));
+        }
+
+        return baseline;
+    }
+
+    @Override
     public void layout() {
         // Recalculate column widths
         TableView tableView = (TableView)getComponent();
@@ -249,16 +268,6 @@
                     column.getMaximumWidth()));
             }
         }
-
-        // Recalculate row height
-        rowHeight = 0;
-        for (int i = 0; i < n; i++) {
-            TableView.Column column = columns.get(i);
-            TableView.CellRenderer cellRenderer = column.getCellRenderer();
-            cellRenderer.render(null, -1, i, tableView, column.getName(), false, false, false);
-
-            rowHeight = Math.max(rowHeight, cellRenderer.getPreferredHeight(-1));
-        }
     }
 
     @Override
@@ -452,8 +461,17 @@
      * The height of one table row.
      */
     public int getRowHeight() {
-        if (rowHeight == -1) {
-            layout();
+        TableView tableView = (TableView)getComponent();
+
+        TableView.ColumnSequence columns = tableView.getColumns();
+        int rowHeight = 0;
+
+        for (int i = 0, n = columns.getLength(); i < n; i++) {
+            TableView.Column column = columns.get(i);
+            TableView.CellRenderer cellRenderer = column.getCellRenderer();
+            cellRenderer.render(null, -1, i, tableView, column.getName(), false, false, false);
+
+            rowHeight = Math.max(rowHeight, cellRenderer.getPreferredHeight(-1));
         }
 
         return rowHeight;
@@ -970,12 +988,6 @@
     }
 
     @Override
-    protected void invalidateComponent() {
-        super.invalidateComponent();
-        columnWidths = null;
-    }
-
-    @Override
     public boolean mouseMove(Component component, int x, int y) {
         boolean consumed = super.mouseMove(component, x, y);
 

Modified: incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/FormTest.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/FormTest.java?rev=834258&r1=834257&r2=834258&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/FormTest.java (original)
+++ incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/FormTest.java Mon Nov  9 22:26:00 2009
@@ -33,7 +33,7 @@
         WTKXSerializer wtkxSerializer = new WTKXSerializer();
         frame = new Frame((Component)wtkxSerializer.readObject(getClass().getResource("form_test.wtkx")));
         frame.setTitle("Form Test");
-        // frame.setPreferredSize(480, 360);
+        frame.setPreferredSize(480, 360);
         frame.open(display);
     }
 

Modified: incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/form_test.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/form_test.wtkx?rev=834258&r1=834257&r2=834258&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/form_test.wtkx (original)
+++ incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/form_test.wtkx Mon Nov  9 22:26:00 2009
@@ -18,17 +18,42 @@
 
 <Form styles="{rightAlignLabels:true, fill:true}"
     xmlns:wtkx="http://pivot.apache.org/wtkx"
+    xmlns:effects="org.apache.pivot.wtk.effects"
     xmlns="org.apache.pivot.wtk">
     <sections>
-        <Form.Section heading="Test Section">
-            <Label Form.label="ABCD" text="Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an AS IS BASIS..."
-                styles="{wrapText:true}"/>
+        <Form.Section heading="Test Section 1">
+            <TextArea Form.label="Text Area" styles="{margin:0}"
+                text="Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an AS IS BASIS...">
+                <decorators>
+                    <effects:BaselineDecorator/>
+                </decorators>
+            </TextArea>
         </Form.Section>
-        <Form.Section heading="Test Section">
-            <Label Form.label="ABCD" text="Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an AS IS BASIS..."
-                styles="{wrapText:true}"/>
+        <Form.Section heading="Test Section 2">
+            <BoxPane orientation="vertical" Form.label="Table View" styles="{fill:true}">
+                <TableViewHeader wtkx:id="tableViewHeader">
+                    <decorators>
+                        <effects:BaselineDecorator/>
+                    </decorators>
+                </TableViewHeader>
+                <TableView wtkx:id="tableView"
+                    tableData="[{a:1, b:2, c:3}, {a:4, b:5, c:6}, {a:7, b:8, c:9}]">
+                    <columns>
+                        <TableView.Column name="a" width="100" headerData="A"/>
+                        <TableView.Column name="b" width="100" headerData="B"/>
+                        <TableView.Column name="c" width="100" headerData="C"/>
+                    </columns>
+                    <decorators>
+                        <effects:BaselineDecorator/>
+                    </decorators>
+                </TableView>
+
+                <wtkx:script>
+                tableViewHeader.setTableView(tableView);
+                </wtkx:script>
+            </BoxPane>
         </Form.Section>
-        <Form.Section heading="Test Section">
+        <Form.Section heading="Test Section 3">
             <Label Form.label="ABCD" text="Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an AS IS BASIS..."
                 styles="{wrapText:true}"/>
         </Form.Section>