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 20:29:46 UTC

svn commit: r834182 - in /incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin: ./ terra/

Author: gbrown
Date: Mon Nov  9 19:29:45 2009
New Revision: 834182

URL: http://svn.apache.org/viewvc?rev=834182&view=rev
Log:
Update baseline calculations.

Modified:
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/BoxPaneSkin.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ComponentSkin.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/LabelSkin.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraCalendarButtonSkin.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraColorChooserButtonSkin.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraFormSkin.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraListButtonSkin.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraListViewSkin.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraMenuButtonSkin.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraMeterSkin.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraTextInputSkin.java

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=834182&r1=834181&r2=834182&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 19:29:45 2009
@@ -138,24 +138,6 @@
     }
 
     @Override
-    public int getBaseline(int width, int height) {
-        BoxPane boxPane = (BoxPane)getComponent();
-
-        int baseline = -1;
-
-        // TODO Return the baseline of the first component that has a valid baseline
-        // NOTE For vertical box panes, be sure to constrain width appropriately when fill
-        // is set to true
-
-        // Include top and bottom padding values
-        if (baseline != -1) {
-            baseline += padding.top;
-        }
-
-        return baseline;
-    }
-
-    @Override
     public Dimensions getPreferredSize() {
         BoxPane boxPane = (BoxPane)getComponent();
 
@@ -216,6 +198,86 @@
     }
 
     @Override
+    public int getBaseline(int width, int height) {
+        BoxPane boxPane = (BoxPane)getComponent();
+
+        int baseline = -1;
+
+        width = Math.max(width - (padding.left + padding.right), 0);
+        height = Math.max(height - (padding.top + padding.bottom), 0);
+
+        int contentHeight = 0;
+
+        switch (boxPane.getOrientation()) {
+            case HORIZONTAL: {
+                for (Component component : boxPane) {
+                    if (component.isVisible()) {
+                        Dimensions size;
+                        if (fill) {
+                            size = new Dimensions(component.getPreferredHeight(height), height);
+                        } else {
+                            size = component.getPreferredSize();
+                        }
+
+                        contentHeight = Math.max(contentHeight, size.height);
+                        baseline = Math.max(baseline, component.getBaseline(size.width, size.height));
+                    }
+                }
+
+                break;
+            }
+
+            case VERTICAL: {
+                for (Component component : boxPane) {
+                    if (component.isVisible()) {
+                        Dimensions size;
+                        if (fill) {
+                            size = new Dimensions(component.getPreferredHeight(height), height);
+                        } else {
+                            size = component.getPreferredSize();
+                        }
+
+                        if (baseline == -1) {
+                            baseline = component.getBaseline(size.width, size.height) + contentHeight;
+                        }
+
+                        contentHeight += size.height + spacing;
+                    }
+                }
+
+                contentHeight -= spacing;
+
+                break;
+            }
+        }
+
+        if (baseline != -1) {
+            if (fill) {
+                baseline += padding.top;
+            } else {
+                switch (verticalAlignment) {
+                    case TOP: {
+                        baseline += padding.top;
+                        break;
+                    }
+
+                    case CENTER: {
+                        baseline += (height - contentHeight) / 2;
+                        break;
+                    }
+
+                    case BOTTOM: {
+                        baseline += height - (contentHeight + padding.bottom);
+                        break;
+                    }
+                }
+            }
+        }
+
+        return baseline;
+    }
+
+    @Override
     public void layout() {
         BoxPane boxPane = (BoxPane)getComponent();
         int n = boxPane.getLength();

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ComponentSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ComponentSkin.java?rev=834182&r1=834181&r2=834182&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ComponentSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ComponentSkin.java Mon Nov  9 19:29:45 2009
@@ -92,15 +92,7 @@
 
     public static final int SHOW_TOOLTIP_TIMEOUT = 1000;
 
-    /** if true, draw red lines over components to indicate where the baselines are */
-    protected static boolean debugBaseline = false;
-    static {
-        try {
-            debugBaseline = Boolean.parseBoolean(System.getProperty("pivot.wtk.debugBaseline"));
-        } catch (Exception ex) {
-            // ignore exception when running in applet
-        }
-    }
+    protected static boolean debugBaseline = true;
 
     @Override
     public int getWidth() {

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/LabelSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/LabelSkin.java?rev=834182&r1=834181&r2=834182&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/LabelSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/LabelSkin.java Mon Nov  9 19:29:45 2009
@@ -179,9 +179,35 @@
 
     @Override
     public int getBaseline(int width, int height) {
-        // TODO
         LineMetrics lm = font.getLineMetrics("", FONT_RENDER_CONTEXT);
-        return (int)Math.ceil(lm.getAscent() - 2);
+        float ascent = lm.getAscent();
+        float textHeight = lm.getHeight();
+
+        if (wrapText) {
+            textHeight = Math.max(getPreferredHeight(width) - (padding.top + padding.bottom), 0);
+        } else {
+            textHeight = (int)Math.ceil(lm.getHeight());
+        }
+
+        int baseline = -1;
+        switch (verticalAlignment) {
+            case TOP: {
+                baseline = Math.round(padding.top + ascent);
+                break;
+            }
+
+            case CENTER: {
+                baseline = Math.round((height - textHeight) / 2 + ascent);
+                break;
+            }
+
+            case BOTTOM: {
+                baseline = Math.round(height - (textHeight + padding.bottom) + ascent);
+                break;
+            }
+        }
+
+        return baseline;
     }
 
     @Override

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraCalendarButtonSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraCalendarButtonSkin.java?rev=834182&r1=834181&r2=834182&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraCalendarButtonSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraCalendarButtonSkin.java Mon Nov  9 19:29:45 2009
@@ -151,9 +151,8 @@
     public int getPreferredWidth(int height) {
         CalendarButton calendarButton = (CalendarButton) getComponent();
 
-        Object buttonData = calendarButton.getButtonData();
         Button.DataRenderer dataRenderer = calendarButton.getDataRenderer();
-        dataRenderer.render(buttonData, calendarButton, false);
+        dataRenderer.render(calendarButton.getButtonData(), calendarButton, false);
 
         int preferredWidth = dataRenderer.getPreferredWidth(-1) + TRIGGER_WIDTH
             + padding.left + padding.right + 2;
@@ -165,9 +164,8 @@
     public int getPreferredHeight(int width) {
         CalendarButton calendarButton = (CalendarButton) getComponent();
 
-        Object buttonData = calendarButton.getButtonData();
         Button.DataRenderer dataRenderer = calendarButton.getDataRenderer();
-        dataRenderer.render(buttonData, calendarButton, false);
+        dataRenderer.render(calendarButton.getButtonData(), calendarButton, false);
 
         int preferredHeight = dataRenderer.getPreferredHeight(-1)
             + padding.top + padding.bottom + 2;
@@ -177,18 +175,28 @@
 
     @Override
     public Dimensions getPreferredSize() {
-        // TODO Optimize by performing calcuations locally
-        return new Dimensions(getPreferredWidth(-1), getPreferredHeight(-1));
+        CalendarButton calendarButton = (CalendarButton) getComponent();
+
+        Button.DataRenderer dataRenderer = calendarButton.getDataRenderer();
+        dataRenderer.render(calendarButton.getButtonData(), calendarButton, false);
+
+        Dimensions contentSize = dataRenderer.getPreferredSize();
+        int preferredWidth = contentSize.width + TRIGGER_WIDTH + padding.left + padding.right + 2;
+        int preferredHeight = contentSize.height + padding.top + padding.bottom + 2;
+
+        return new Dimensions(preferredWidth, preferredHeight);
     }
 
     @Override
     public int getBaseline(int width, int height) {
         CalendarButton calendarButton = (CalendarButton) getComponent();
 
-        // TODO Adjust width and height for padding/border/trigger
-
         Button.DataRenderer dataRenderer = calendarButton.getDataRenderer();
         dataRenderer.render(calendarButton.getButtonData(), calendarButton, false);
+
+        width = Math.max(width - (TRIGGER_WIDTH + padding.left + padding.right + 2), 0);
+        height = Math.max(height - (padding.top + padding.bottom + 2), 0);
+
         int baseline = dataRenderer.getBaseline(width, height);
 
         if (baseline != -1) {

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraColorChooserButtonSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraColorChooserButtonSkin.java?rev=834182&r1=834181&r2=834182&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraColorChooserButtonSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraColorChooserButtonSkin.java Mon Nov  9 19:29:45 2009
@@ -99,8 +99,8 @@
 
         dataRenderer.render(colorChooserButton.getButtonData(), colorChooserButton, false);
 
-        int preferredWidth = dataRenderer.getPreferredWidth(-1) + TRIGGER_WIDTH + padding.left
-            + padding.right + 2;
+        int preferredWidth = dataRenderer.getPreferredWidth(-1) + TRIGGER_WIDTH
+            + padding.left + padding.right + 2;
 
         return preferredWidth;
     }
@@ -119,13 +119,29 @@
     }
 
     @Override
-    public int getBaseline(int width, int height) {
+    public Dimensions getPreferredSize() {
         ColorChooserButton colorChooserButton = (ColorChooserButton)getComponent();
 
-        // TODO Adjust width and height for padding/border/trigger
+        Button.DataRenderer dataRenderer = colorChooserButton.getDataRenderer();
+        dataRenderer.render(colorChooserButton.getButtonData(), colorChooserButton, false);
+
+        Dimensions contentSize = dataRenderer.getPreferredSize();
+        int preferredWidth = contentSize.width + TRIGGER_WIDTH + padding.left + padding.right + 2;
+        int preferredHeight = contentSize.height + padding.top + padding.bottom + 2;
+
+        return new Dimensions(preferredWidth, preferredHeight);
+    }
+
+    @Override
+    public int getBaseline(int width, int height) {
+        ColorChooserButton colorChooserButton = (ColorChooserButton)getComponent();
 
         Button.DataRenderer dataRenderer = colorChooserButton.getDataRenderer();
         dataRenderer.render(colorChooserButton.getButtonData(), colorChooserButton, false);
+
+        width = Math.max(width - (TRIGGER_WIDTH + padding.left + padding.right + 2), 0);
+        height = Math.max(height - (padding.top + padding.bottom + 2), 0);
+
         int baseline = dataRenderer.getBaseline(width, height);
 
         if (baseline != -1) {

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraFormSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraFormSkin.java?rev=834182&r1=834181&r2=834182&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraFormSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraFormSkin.java Mon Nov  9 19:29:45 2009
@@ -305,8 +305,7 @@
                             labelY = rowY + (baseline - labelBaseLine);
                             fieldY = rowY + (baseline - fieldBaseLine);
                         } else {
-                            // if they don't both have baselines, default to
-                            // non-baseline behaviour
+                            // If they don't both have baselines, default to non-baseline behaviour
                             rowHeight = Math.max(label.getHeight(), Math.max(field.getHeight(),
                                 FLAG_IMAGE_SIZE));
                             fieldY = rowY;

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraListButtonSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraListButtonSkin.java?rev=834182&r1=834181&r2=834182&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraListButtonSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraListButtonSkin.java Mon Nov  9 19:29:45 2009
@@ -158,17 +158,15 @@
     @Override
     public int getPreferredWidth(int height) {
         ListButton listButton = (ListButton)getComponent();
-        List<?> listData = listButton.getListData();
-
         Button.DataRenderer dataRenderer = listButton.getDataRenderer();
 
         // Determine the preferred width of the current button data
-        dataRenderer.render(listButton.getButtonData(),
-            listButton, false);
+        dataRenderer.render(listButton.getButtonData(), listButton, false);
         int preferredWidth = dataRenderer.getPreferredWidth(-1);
 
         // The preferred width of the button is the max. width of the rendered
         // content plus padding and the trigger width
+        List<?> listData = listButton.getListData();
         for (Object item : listData) {
             dataRenderer.render(item, listButton, false);
             preferredWidth = Math.max(preferredWidth, dataRenderer.getPreferredWidth(-1));
@@ -182,8 +180,8 @@
     @Override
     public int getPreferredHeight(int width) {
         ListButton listButton = (ListButton)getComponent();
-        Button.DataRenderer dataRenderer = listButton.getDataRenderer();
 
+        Button.DataRenderer dataRenderer = listButton.getDataRenderer();
         dataRenderer.render(listButton.getButtonData(), listButton, false);
 
         int preferredHeight = dataRenderer.getPreferredHeight(-1)
@@ -194,18 +192,38 @@
 
     @Override
     public Dimensions getPreferredSize() {
-        // TODO Optimize by performing calcuations locally
-        return new Dimensions(getPreferredWidth(-1), getPreferredHeight(-1));
+        ListButton listButton = (ListButton)getComponent();
+        Button.DataRenderer dataRenderer = listButton.getDataRenderer();
+
+        // Determine the preferred width and height of the current button data
+        dataRenderer.render(listButton.getButtonData(), listButton, false);
+        Dimensions contentSize = dataRenderer.getPreferredSize();
+        int preferredWidth = contentSize.width;
+        int preferredHeight = contentSize.height + padding.top + padding.bottom + 2;
+
+        // The preferred width of the button is the max. width of the rendered
+        // content plus padding and the trigger width
+        List<?> listData = listButton.getListData();
+        for (Object item : listData) {
+            dataRenderer.render(item, listButton, false);
+            preferredWidth = Math.max(preferredWidth, dataRenderer.getPreferredWidth(-1));
+        }
+
+        preferredWidth += TRIGGER_WIDTH + padding.left + padding.right + 2;
+
+        return new Dimensions(preferredWidth, preferredHeight);
     }
 
     @Override
     public int getBaseline(int width, int height) {
         ListButton listButton = (ListButton)getComponent();
 
-        // TODO Adjust width and height for padding/border/trigger
-
         Button.DataRenderer dataRenderer = listButton.getDataRenderer();
         dataRenderer.render(listButton.getButtonData(), listButton, false);
+
+        width = Math.max(width - (TRIGGER_WIDTH + padding.left + padding.right + 2), 0);
+        height = Math.max(height - (padding.top + padding.bottom + 2), 0);
+
         int baseline = dataRenderer.getBaseline(width, height);
 
         if (baseline != -1) {

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraListViewSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraListViewSkin.java?rev=834182&r1=834181&r2=834182&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraListViewSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraListViewSkin.java Mon Nov  9 19:29:45 2009
@@ -142,7 +142,10 @@
 
         int baseline = -1;
 
-        // TODO Adjust width for checkbox width and checkbox padding
+        if (listView.getCheckmarksEnabled()) {
+            width = Math.max(width - (CHECKBOX.getWidth() + (checkboxPadding.left
+                + checkboxPadding.right)), 0);
+        }
 
         ListView.ItemRenderer renderer = listView.getItemRenderer();
         renderer.render(null, -1, listView, false, false, false, false);

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraMenuButtonSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraMenuButtonSkin.java?rev=834182&r1=834181&r2=834182&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraMenuButtonSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraMenuButtonSkin.java Mon Nov  9 19:29:45 2009
@@ -95,8 +95,8 @@
     @Override
     public int getPreferredWidth(int height) {
         MenuButton menuButton = (MenuButton)getComponent();
-        Button.DataRenderer dataRenderer = menuButton.getDataRenderer();
 
+        Button.DataRenderer dataRenderer = menuButton.getDataRenderer();
         dataRenderer.render(menuButton.getButtonData(), menuButton, false);
 
         int preferredWidth = dataRenderer.getPreferredWidth(-1) + TRIGGER_WIDTH
@@ -108,8 +108,8 @@
     @Override
     public int getPreferredHeight(int width) {
         MenuButton menuButton = (MenuButton)getComponent();
-        Button.DataRenderer dataRenderer = menuButton.getDataRenderer();
 
+        Button.DataRenderer dataRenderer = menuButton.getDataRenderer();
         dataRenderer.render(menuButton.getButtonData(), menuButton, false);
 
         int preferredHeight = dataRenderer.getPreferredHeight(-1)
@@ -120,18 +120,28 @@
 
     @Override
     public Dimensions getPreferredSize() {
-        // TODO Optimize by performing calcuations locally
-        return new Dimensions(getPreferredWidth(-1), getPreferredHeight(-1));
+        MenuButton menuButton = (MenuButton)getComponent();
+
+        Button.DataRenderer dataRenderer = menuButton.getDataRenderer();
+        dataRenderer.render(menuButton.getButtonData(), menuButton, false);
+
+        Dimensions contentSize = dataRenderer.getPreferredSize();
+        int preferredWidth = contentSize.width + TRIGGER_WIDTH + padding.left + padding.right + 2;
+        int preferredHeight = contentSize.height + padding.top + padding.bottom + 2;
+
+        return new Dimensions(preferredWidth, preferredHeight);
     }
 
     @Override
     public int getBaseline(int width, int height) {
         MenuButton menuButton = (MenuButton) getComponent();
 
-        // TODO Adjust width and height for padding/border/trigger
-
         Button.DataRenderer dataRenderer = menuButton.getDataRenderer();
         dataRenderer.render(menuButton.getButtonData(), menuButton, false);
+
+        width = Math.max(width - (TRIGGER_WIDTH + padding.left + padding.right + 2), 0);
+        height = Math.max(height - (padding.top + padding.bottom + 2), 0);
+
         int baseline = dataRenderer.getBaseline(width, height);
 
         if (baseline != -1) {

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraMeterSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraMeterSkin.java?rev=834182&r1=834181&r2=834182&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraMeterSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraMeterSkin.java Mon Nov  9 19:29:45 2009
@@ -91,8 +91,8 @@
             preferredWidth = 0;
         }
 
-        // If Meter has no content, its preferred width is hard coded in the
-        // class and is not affected by the height constraint.
+        // If the meter has no content, its preferred width is hard-coded by the
+        // class and is not affected by the height constraint
         preferredWidth = Math.max(preferredWidth, DEFAULT_WIDTH);
 
         return preferredWidth;
@@ -110,8 +110,8 @@
             preferredHeight = (int)Math.ceil(lm.getHeight()) + 2;
         }
 
-        // If Meter has no content, its preferred height is hard coded in the
-        // class and is not affected by the width constraint.
+        // If the meter has no content, its preferred height is hard-coded by the
+        // class and is not affected by the width constraint
         preferredHeight = Math.max(preferredHeight, DEFAULT_HEIGHT);
 
         return preferredHeight;
@@ -128,11 +128,12 @@
             && text.length() > 0) {
             Rectangle2D stringBounds = font.getStringBounds(text, FONT_RENDER_CONTEXT);
             preferredWidth = (int)Math.ceil(stringBounds.getWidth()) + 2;
+
             LineMetrics lm = font.getLineMetrics("", FONT_RENDER_CONTEXT);
             preferredHeight = (int)Math.ceil(lm.getHeight()) + 2;
         }
 
-        // If Meter has no content, its preferred size is hard coded in the class.
+        // If meter has no content, its preferred size is hard coded by the class
         preferredWidth = Math.max(preferredWidth, DEFAULT_WIDTH);
         preferredHeight = Math.max(preferredHeight, DEFAULT_HEIGHT);
 
@@ -149,9 +150,10 @@
         if (text != null
             && text.length() > 0) {
             LineMetrics lm = font.getLineMetrics("", FONT_RENDER_CONTEXT);
+            float ascent = lm.getAscent();
+            float textHeight = lm.getHeight();
 
-            // TODO Adjust for height
-            baseline = (int)Math.ceil(lm.getAscent() - 2);
+            baseline = Math.round((height - textHeight) / 2 + ascent);
         }
 
         return baseline;
@@ -172,10 +174,12 @@
 
         graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
             RenderingHints.VALUE_ANTIALIAS_ON);
+
         if (FONT_RENDER_CONTEXT.isAntiAliased()) {
             graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                 Platform.getTextAntialiasingHint());
         }
+
         if (FONT_RENDER_CONTEXT.usesFractionalMetrics()) {
             graphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
                 RenderingHints.VALUE_FRACTIONALMETRICS_ON);
@@ -197,25 +201,36 @@
         }
 
         String text = meter.getText();
-        if (text!=null && text.length()>0) {
+        if (text != null
+            && text.length() > 0) {
             LineMetrics lm = font.getLineMetrics("", FONT_RENDER_CONTEXT);
-            int ascent = Math.round(lm.getAscent());
+            float ascent = lm.getAscent();
+
             Rectangle2D stringBounds = font.getStringBounds(text, FONT_RENDER_CONTEXT);
-            int textWidth = (int)Math.ceil(stringBounds.getWidth());
-            int textX = (width - textWidth - 2) / 2 + 1;
+            float textWidth = (float)stringBounds.getWidth();
+            float textHeight = (float)stringBounds.getHeight();
+
+            float textX = (width - textWidth) / 2;
+            float textY = (height - textHeight) / 2;
 
             // Paint the text
-            Shape previousClip = graphics.getClip();
+            Shape clip = graphics.getClip();
             graphics.clipRect(0, 0, meterStop, height);
             graphics.setPaint(textFillColor);
             graphics.setFont(font);
-            graphics.drawString(meter.getText(), textX, ascent+1);
-            graphics.setClip(previousClip);
+            graphics.drawString(meter.getText(), textX, textY + ascent);
+
+            graphics.setClip(clip);
             graphics.clipRect(meterStop, 0, width, height);
             graphics.setPaint(textColor);
             graphics.setFont(font);
-            graphics.drawString(meter.getText(), textX, ascent+1);
-            graphics.setClip(previousClip);
+            graphics.drawString(meter.getText(), textX, textY + ascent);
+
+            graphics.setClip(clip);
+        }
+
+        if (debugBaseline) {
+            drawBaselineDebug(graphics);
         }
     }
 

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraTextInputSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraTextInputSkin.java?rev=834182&r1=834181&r2=834182&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraTextInputSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraTextInputSkin.java Mon Nov  9 19:29:45 2009
@@ -219,9 +219,13 @@
 
     @Override
     public int getBaseline(int width, int height) {
-        // TODO
         LineMetrics lm = font.getLineMetrics("", FONT_RENDER_CONTEXT);
-        return (int)Math.ceil(lm.getAscent()) + (padding.top + 1) - 2;
+        float ascent = lm.getAscent();
+        float textHeight = lm.getHeight();
+
+        int baseline = Math.round((height - textHeight) / 2 + ascent);
+
+        return baseline;
     }
 
     @Override
@@ -330,7 +334,8 @@
         }
 
         LineMetrics lm = font.getLineMetrics("", FONT_RENDER_CONTEXT);
-        int ascent = Math.round(lm.getAscent());
+        float ascent = lm.getAscent();
+        float textHeight = lm.getHeight();
 
         String prompt = textInput.getPrompt();
 
@@ -339,7 +344,8 @@
             && !textInput.isFocused()) {
             graphics.setFont(font);
             graphics.setColor(promptColor);
-            graphics.drawString(prompt, padding.left - scrollLeft + 1, padding.top + ascent + 1);
+            graphics.drawString(prompt, padding.left - scrollLeft + 1,
+                (height - textHeight) / 2 + ascent);
         } else {
             boolean textValid = textInput.isTextValid();
 
@@ -360,7 +366,8 @@
                 if (selection == null) {
                     // Paint the text
                     graphics.setColor(color);
-                    graphics.drawGlyphVector(glyphVector, padding.left - scrollLeft + 1, padding.top + ascent + 1);
+                    graphics.drawGlyphVector(glyphVector, padding.left - scrollLeft + 1,
+                        (height - textHeight) / 2 + ascent);
                 } else {
                     // Paint the unselected text
                     Area unselectedArea = new Area();
@@ -370,7 +377,8 @@
                     Graphics2D textGraphics = (Graphics2D)graphics.create();
                     textGraphics.setColor(color);
                     textGraphics.clip(unselectedArea);
-                    textGraphics.drawGlyphVector(glyphVector, padding.left - scrollLeft + 1, padding.top + ascent + 1);
+                    textGraphics.drawGlyphVector(glyphVector, padding.left - scrollLeft + 1,
+                        (height - textHeight) / 2 + ascent);
                     textGraphics.dispose();
 
                     // Paint the selection
@@ -391,12 +399,13 @@
                     Graphics2D selectedTextGraphics = (Graphics2D)graphics.create();
                     selectedTextGraphics.setColor(selectionColor);
                     selectedTextGraphics.clip(selection.getBounds());
-                    selectedTextGraphics.drawGlyphVector(glyphVector, padding.left - scrollLeft + 1, padding.top + ascent + 1);
+                    selectedTextGraphics.drawGlyphVector(glyphVector, padding.left - scrollLeft + 1,
+                        (height - textHeight) / 2 + ascent);
                     selectedTextGraphics.dispose();
                 }
             }
 
-            if (caret != null
+            if (selection == null
                 && caretOn
                 && textInput.isFocused()) {
                 graphics.setColor(color);
@@ -1400,6 +1409,8 @@
     private void updateSelection() {
         TextInput textInput = (TextInput)getComponent();
 
+        int height = getHeight();
+
         int selectionStart = textInput.getSelectionStart();
         int selectionLength = textInput.getSelectionLength();
 
@@ -1407,33 +1418,34 @@
         int n = textNode.getCharacterCount();
 
         Bounds leadingSelectionBounds;
-        if (n == 0) {
-            int x = padding.left - scrollLeft + 1;
-            int y = padding.top + 1;
-            leadingSelectionBounds = new Bounds(x, y, 0, averageCharacterSize.height);
-        } else if (selectionStart < n) {
+        if (selectionStart < n) {
             leadingSelectionBounds = getCharacterBounds(selectionStart);
         } else {
             // The insertion point is after the last character
-            Rectangle2D textBounds = glyphVector.getLogicalBounds();
-            int x = (int)Math.ceil(textBounds.getWidth()) + (padding.left - scrollLeft + 1);
+            int x;
+            if (n == 0) {
+                x = padding.left - scrollLeft + 1;
+            } else {
+                Rectangle2D textBounds = glyphVector.getLogicalBounds();
+                x = (int)Math.ceil(textBounds.getWidth()) + (padding.left - scrollLeft + 1);
+            }
+
             int y = padding.top + 1;
-            leadingSelectionBounds = new Bounds(x, y, 0, averageCharacterSize.height);
-        }
 
-        if (selectionLength == 0) {
-            caret = leadingSelectionBounds.toRectangle();
-            caret.width = 1;
+            leadingSelectionBounds = new Bounds(x, y, 0, height - (padding.top + padding.bottom + 2));
+        }
 
-            selection = null;
-        } else {
-            caret = null;
+        caret = leadingSelectionBounds.toRectangle();
+        caret.width = 1;
 
+        if (selectionLength > 0) {
             Bounds trailingSelectionBounds = getCharacterBounds(selectionStart
                 + selectionLength - 1);
             selection = new Rectangle(leadingSelectionBounds.x, leadingSelectionBounds.y,
                 trailingSelectionBounds.x + trailingSelectionBounds.width - leadingSelectionBounds.x,
                 trailingSelectionBounds.y + trailingSelectionBounds.height - leadingSelectionBounds.y);
+        } else {
+            selection = null;
         }
     }