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/10/09 17:53:54 UTC

svn commit: r823597 - in /incubator/pivot/trunk/wtk: src/org/apache/pivot/wtk/skin/ test/org/apache/pivot/wtk/test/

Author: tvolkert
Date: Fri Oct  9 15:53:53 2009
New Revision: 823597

URL: http://svn.apache.org/viewvc?rev=823597&view=rev
Log:
Added baseline calculations to BorderSkin, ScrollPaneSkin, and TablePaneSkin; updated baseline test to show these use cases.

Modified:
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/BorderSkin.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/FlowPaneSkin.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ScrollPaneSkin.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TablePaneSkin.java
    incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/baseline_test.wtkx

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/BorderSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/BorderSkin.java?rev=823597&r1=823596&r2=823597&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/BorderSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/BorderSkin.java Fri Oct  9 15:53:53 2009
@@ -38,7 +38,6 @@
 import org.apache.pivot.wtk.Platform;
 import org.apache.pivot.wtk.Theme;
 
-
 /**
  * Border skin.
  * <p>
@@ -146,6 +145,39 @@
     }
 
     @Override
+    public int getBaseline(int width) {
+        int baseline = -1;
+
+        Border border = (Border)getComponent();
+        int topThickness = thickness;
+
+        // Delegate baseline calculation to the content component
+        Component content = border.getContent();
+        if (content != null) {
+            String title = border.getTitle();
+            if (title != null
+                && title.length() > 0) {
+                LineMetrics lm = font.getLineMetrics(title, fontRenderContext);
+                topThickness = Math.max((int)Math.ceil(lm.getAscent() + lm.getDescent()
+                    + lm.getLeading()), topThickness);
+            }
+
+            if (width != -1) {
+                width = Math.max(width - (thickness * 2) - padding.left - padding.right, 0);
+            }
+
+            baseline = content.getBaseline(width);
+        }
+
+        // Include top padding value and top border thickness
+        if (baseline != -1) {
+            baseline += (padding.top + topThickness);
+        }
+
+        return baseline;
+    }
+
+    @Override
     public void layout() {
         int width = getWidth();
         int height = getHeight();

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/FlowPaneSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/FlowPaneSkin.java?rev=823597&r1=823596&r2=823597&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/FlowPaneSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/FlowPaneSkin.java Fri Oct  9 15:53:53 2009
@@ -188,10 +188,11 @@
             }
         }
 
-        // Include top and bottom padding values
+        // Include top padding value
         if (baseline != -1) {
             baseline += padding.top;
         }
+
         return baseline;
     }
 

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ScrollPaneSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ScrollPaneSkin.java?rev=823597&r1=823596&r2=823597&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ScrollPaneSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ScrollPaneSkin.java Fri Oct  9 15:53:53 2009
@@ -38,7 +38,6 @@
 import org.apache.pivot.wtk.ScrollPane.Corner;
 import org.apache.pivot.wtk.ScrollPane.ScrollBarPolicy;
 
-
 /**
  * Scroll pane skin.
  */
@@ -309,6 +308,21 @@
     }
 
     @Override
+    public int getBaseline(int width) {
+        int baseline = -1;
+
+        ScrollPane scrollPane = (ScrollPane)getComponent();
+        Component view = scrollPane.getView();
+
+        // Delegate baseline calculation to the view component
+        if (view != null) {
+            baseline = view.getBaseline(width);
+        }
+
+        return baseline;
+    }
+
+    @Override
     public boolean mouseWheel(Component component, Mouse.ScrollType scrollType, int scrollAmount,
         int wheelRotation, int x, int y) {
         boolean consumed = false;

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TablePaneSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TablePaneSkin.java?rev=823597&r1=823596&r2=823597&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TablePaneSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TablePaneSkin.java Fri Oct  9 15:53:53 2009
@@ -452,6 +452,46 @@
     }
 
     @Override
+    public int getBaseline(int width) {
+        int baseline = -1;
+
+        TablePane tablePane = (TablePane)getComponent();
+
+        TablePane.RowSequence rows = tablePane.getRows();
+        TablePane.ColumnSequence columns = tablePane.getColumns();
+
+        int columnCount = columns.getLength();
+
+        if (width < 0) {
+            width = getPreferredWidth(-1);
+        }
+
+        int[] columnWidths = getColumnWidths(width);
+
+        // Baseline is the maximum baseline of all components in the first row,
+        // excluding non-visible components and row-spanning components.
+        if (rows.getLength() > 0) {
+            TablePane.Row row = rows.get(0);
+
+            for (int j = 0, n = row.getLength(); j < n && j < columnCount; j++) {
+                Component component = row.get(j);
+
+                if (TablePane.getRowSpan(component) == 1
+                    && component.isVisible()) {
+                    baseline = Math.max(baseline, component.getBaseline(columnWidths[j]));
+                }
+            }
+        }
+
+        // Include top padding value
+        if (baseline != -1) {
+            baseline += padding.top;
+        }
+
+        return baseline;
+    }
+
+    @Override
     public void layout() {
         TablePane tablePane = (TablePane)getComponent();
 

Modified: incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/baseline_test.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/baseline_test.wtkx?rev=823597&r1=823596&r2=823597&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/baseline_test.wtkx (original)
+++ incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/baseline_test.wtkx Fri Oct  9 15:53:53 2009
@@ -30,7 +30,9 @@
                 styles="{wrapText:true}"/>
         </Form.Section>
         <Form.Section heading="Test Section">
-            <TextInput Form.label="Text Input Field" text="Some sample text"/>
+            <TextInput Form.label="Text Input Field"
+                Form.Flag="{messageType:'error', message:'Error message'}"
+                text="Some sample text"/>
             <Checkbox Form.label="Checkbox" buttonData="Bell"/>
             <LinkButton Form.label="LinkButton" buttonData="Previous"/>
             <RadioButton Form.label="RadioButton" buttonData="Crossfade" selected="true"/>
@@ -41,7 +43,39 @@
                     <content:NumericSpinnerData lowerBound="0" upperBound="9" increment="1"/>
                 </spinnerData>
             </Spinner>
-            <ListView Form.label="ListView" listData="['Item 1', 'Item 2', 'Item 3', 'Item 4', 'Item 5']"/>
+            <Border Form.label="ListView"
+                Form.Flag="{messageType:'error', message:'Error message'}"
+                styles="{padding:0}">
+                <content>
+                    <ScrollPane horizontalScrollBarPolicy="fill_to_capacity">
+                        <view>
+                            <ListView listData="['Item 1', 'Item 2', 'Item 3', 'Item 4', 'Item 5']"/>
+                        </view>
+                    </ScrollPane>
+                </content>
+            </Border>
+            <FlowPane Form.label="FlowPane"
+                styles="{padding:0, horizontalSpacing:4, alignToBaseline:true}">
+                <TextInput text=""/>
+                <Label text="(optional)"/>
+            </FlowPane>
+            <TablePane Form.label="TablePane"
+                styles="{padding:{top:8}, horizontalSpacing:12, verticalSpacing:6}">
+                <columns>
+                    <TablePane.Column/>
+                    <TablePane.Column width="1*"/>
+                </columns>
+                <rows>
+                    <TablePane.Row>
+                        <Label text="Left 1"/>
+                        <Label text="Right 1"/>
+                    </TablePane.Row>
+                    <TablePane.Row>
+                        <Label text="Long Left 2"/>
+                        <Label text="Right 2"/>
+                    </TablePane.Row>
+                </rows>
+            </TablePane>
         </Form.Section>
     </sections>
 </Form>