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/10 20:17:54 UTC
svn commit: r834608 - in /incubator/pivot/trunk:
tutorials/src/org/apache/pivot/tutorials/layout/ 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: Tue Nov 10 19:17:54 2009
New Revision: 834608
URL: http://svn.apache.org/viewvc?rev=834608&view=rev
Log:
Fix NPE bugs in TextArea and TextInput; fix baseline calculation issue in BoxPane.
Modified:
incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/layout/flow_panes.wtkx
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/FlowPaneSkin.java
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin.java
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraTextInputSkin.java
incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/flow_pane_test.wtkx
Modified: incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/layout/flow_panes.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/layout/flow_panes.wtkx?rev=834608&r1=834607&r2=834608&view=diff
==============================================================================
--- incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/layout/flow_panes.wtkx (original)
+++ incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/layout/flow_panes.wtkx Tue Nov 10 19:17:54 2009
@@ -25,25 +25,21 @@
<left>
<Border styles="{padding:4}">
<content>
- <BoxPane orientation="vertical" styles="{verticalAlignment:'center', fill:true}">
- <Border>
- <content>
- <FlowPane wtkx:id="flowPane" styles="{padding:2}">
- <decorators>
- <effects:BaselineDecorator/>
- </decorators>
+ <BoxPane orientation="vertical" styles="{fill:true}">
+ <FlowPane wtkx:id="flowPane" styles="{padding:2}">
+ <decorators>
+ <effects:BaselineDecorator/>
+ </decorators>
- <PushButton buttonData="0" styles="{minimumAspectRatio:1.5}"/>
- <PushButton buttonData="1" styles="{minimumAspectRatio:1.5}"/>
- <PushButton buttonData="2" styles="{minimumAspectRatio:1.5}"/>
- <PushButton buttonData="3" preferredWidth="20" preferredHeight="20"/>
- <PushButton buttonData="4" preferredWidth="30" preferredHeight="30"/>
- <PushButton buttonData="5" preferredWidth="40" preferredHeight="40"/>
- <PushButton buttonData="6" styles="{minimumAspectRatio:1.5}"/>
- <PushButton buttonData="7" styles="{minimumAspectRatio:1.5}"/>
- </FlowPane>
- </content>
- </Border>
+ <PushButton buttonData="0" styles="{minimumAspectRatio:1.5}"/>
+ <PushButton buttonData="1" styles="{minimumAspectRatio:1.5}"/>
+ <PushButton buttonData="2" styles="{minimumAspectRatio:1.5}"/>
+ <PushButton buttonData="3" preferredWidth="20" preferredHeight="20"/>
+ <PushButton buttonData="4" preferredWidth="30" preferredHeight="30"/>
+ <PushButton buttonData="5" preferredWidth="40" preferredHeight="40"/>
+ <PushButton buttonData="6" styles="{minimumAspectRatio:1.5}"/>
+ <PushButton buttonData="7" styles="{minimumAspectRatio:1.5}"/>
+ </FlowPane>
</BoxPane>
</content>
</Border>
Modified: incubator/pivot/trunk/tutorials/www/flow_panes.html
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/www/flow_panes.html?rev=834608&r1=834607&r2=834608&view=diff
==============================================================================
--- incubator/pivot/trunk/tutorials/www/flow_panes.html (original)
+++ incubator/pivot/trunk/tutorials/www/flow_panes.html Tue Nov 10 19:17:54 2009
@@ -35,7 +35,7 @@
<h1>Flow Panes</h1>
<p>Flow panes arrange components in a horizontal line, wrapping when the contents don't fit on a single line. Components may be horizontally aligned to left, right, or center when there is space left over within a given line, and may optionally be vertically aligned by to their baselines.</p>
-<p>The following example demonstrates the use of the <tt>FlowPane</tt> container. The buttons on the right can be used to modify the alignment properties:</p>
+<p>The following example demonstrates the use of the <tt>FlowPane</tt> container. The buttons on the right can be used to modify the alignment properties. A <tt>BaselineDecorator</tt> is used to highlight the flow pane's baseline. This decorator draws a red line across a component's baseline. If the component does not have a baseline, it draws a blue line across the component's vertical midpoint:</p>
<script src="version.js"></script>
<script>
@@ -66,25 +66,21 @@
<left>
<Border styles="{padding:4}">
<content>
- <BoxPane orientation="vertical" styles="{verticalAlignment:'center', fill:true}">
- <Border>
- <content>
- <FlowPane wtkx:id="flowPane" styles="{padding:2}">
- <decorators>
- <effects:BaselineDecorator/>
- </decorators>
-
- <PushButton buttonData="0" styles="{minimumAspectRatio:1.5}"/>
- <PushButton buttonData="1" styles="{minimumAspectRatio:1.5}"/>
- <PushButton buttonData="2" styles="{minimumAspectRatio:1.5}"/>
- <PushButton buttonData="3" preferredWidth="20" preferredHeight="20"/>
- <PushButton buttonData="4" preferredWidth="30" preferredHeight="30"/>
- <PushButton buttonData="5" preferredWidth="40" preferredHeight="40"/>
- <PushButton buttonData="6" styles="{minimumAspectRatio:1.5}"/>
- <PushButton buttonData="7" styles="{minimumAspectRatio:1.5}"/>
- </FlowPane>
- </content>
- </Border>
+ <BoxPane orientation="vertical" styles="{fill:true}">
+ <FlowPane wtkx:id="flowPane" styles="{padding:2}">
+ <decorators>
+ <effects:BaselineDecorator/>
+ </decorators>
+
+ <PushButton buttonData="0" styles="{minimumAspectRatio:1.5}"/>
+ <PushButton buttonData="1" styles="{minimumAspectRatio:1.5}"/>
+ <PushButton buttonData="2" styles="{minimumAspectRatio:1.5}"/>
+ <PushButton buttonData="3" preferredWidth="20" preferredHeight="20"/>
+ <PushButton buttonData="4" preferredWidth="30" preferredHeight="30"/>
+ <PushButton buttonData="5" preferredWidth="40" preferredHeight="40"/>
+ <PushButton buttonData="6" styles="{minimumAspectRatio:1.5}"/>
+ <PushButton buttonData="7" styles="{minimumAspectRatio:1.5}"/>
+ </FlowPane>
</BoxPane>
</content>
</Border>
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=834608&r1=834607&r2=834608&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 Tue Nov 10 19:17:54 2009
@@ -98,7 +98,17 @@
int preferredHeight = 0;
Orientation orientation = boxPane.getOrientation();
- if (orientation == Orientation.VERTICAL) {
+ if (orientation == Orientation.HORIZONTAL) {
+ // Preferred height is the maximum preferred height of all components
+ for (int i = 0, n = boxPane.getLength(); i < n; i++) {
+ Component component = boxPane.get(i);
+
+ if (component.isVisible()) {
+ preferredHeight = Math.max(preferredHeight,
+ component.getPreferredHeight());
+ }
+ }
+ } else {
// Include padding in constraint
if (width != -1) {
width = Math.max(width - (padding.left + padding.right), 0);
@@ -119,16 +129,6 @@
if (j > 1) {
preferredHeight += spacing * (j - 1);
}
- } else {
- // Preferred height is the maximum preferred height of all components
- for (int i = 0, n = boxPane.getLength(); i < n; i++) {
- Component component = boxPane.get(i);
-
- if (component.isVisible()) {
- preferredHeight = Math.max(preferredHeight,
- component.getPreferredHeight());
- }
- }
}
// Include top and bottom padding values
@@ -206,36 +206,45 @@
switch (boxPane.getOrientation()) {
case HORIZONTAL: {
- int clientHeight = Math.max(height - (padding.top + padding.bottom), 0);
+ if (fill) {
+ int clientHeight = Math.max(height - (padding.top + padding.bottom), 0);
- for (Component component : boxPane) {
- if (component.isVisible()) {
- Dimensions size;
- if (fill) {
- size = new Dimensions(component.getPreferredWidth(clientHeight), clientHeight);
- } else {
- size = component.getPreferredSize();
+ for (Component component : boxPane) {
+ if (component.isVisible()) {
+ int componentWidth = component.getPreferredWidth(clientHeight);
+ baseline = Math.max(baseline, component.getBaseline(componentWidth, clientHeight));
}
+ }
+ } else {
+ contentHeight = 0;
+ for (Component component : boxPane) {
+ if (component.isVisible()) {
+ contentHeight = Math.max(contentHeight, component.getPreferredHeight());
+ }
+ }
- contentHeight = Math.max(contentHeight, size.height);
-
- int componentBaseline = component.getBaseline(size.width, size.height);
-
- if (!fill) {
- switch (verticalAlignment) {
- case CENTER: {
- componentBaseline += (clientHeight - size.height) / 2;
- break;
- }
-
- case BOTTOM: {
- componentBaseline += clientHeight - size.height;
- break;
+ for (Component component : boxPane) {
+ if (component.isVisible()) {
+ Dimensions size = component.getPreferredSize();
+
+ int componentBaseline = component.getBaseline(size.width, size.height);
+
+ if (componentBaseline != -1) {
+ switch (verticalAlignment) {
+ case CENTER: {
+ componentBaseline += (contentHeight - size.height) / 2;
+ break;
+ }
+
+ case BOTTOM: {
+ componentBaseline += contentHeight - size.height;
+ break;
+ }
}
}
- }
- baseline = Math.max(baseline, componentBaseline);
+ baseline = Math.max(baseline, componentBaseline);
+ }
}
}
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=834608&r1=834607&r2=834608&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 Tue Nov 10 19:17:54 2009
@@ -309,18 +309,13 @@
for (Component component : row) {
int y;
+ int componentBaseline = component.getBaseline(component.getWidth(),
+ component.getHeight());
if (alignToBaseline
- && baseline != -1) {
- int componentBaseline = component.getBaseline(component.getWidth(),
- component.getHeight());
-
- if (componentBaseline != -1) {
- // Align to baseline
- y = baseline - componentBaseline;
- } else {
- // Align to bottom
- y = rowHeight - component.getHeight();
- }
+ && baseline != -1
+ && componentBaseline != -1) {
+ // Align to baseline
+ y = baseline - componentBaseline;
} else {
// Align to bottom
y = rowHeight - component.getHeight();
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=834608&r1=834607&r2=834608&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 Tue Nov 10 19:17:54 2009
@@ -401,7 +401,11 @@
}
}
- return characterBounds.intersect(0, 0, getWidth(), getHeight());
+ if (characterBounds != null) {
+ characterBounds = characterBounds.intersect(0, 0, getWidth(), getHeight());
+ }
+
+ return characterBounds;
}
@Override
@@ -1627,8 +1631,11 @@
private void scrollCharacterToVisible(int offset) {
TextArea textArea = (TextArea)getComponent();
Bounds characterBounds = getCharacterBounds(offset);
- textArea.scrollAreaToVisible(0, characterBounds.y, characterBounds.width,
- characterBounds.height);
+
+ if (characterBounds != null) {
+ textArea.scrollAreaToVisible(0, characterBounds.y, characterBounds.width,
+ characterBounds.height);
+ }
}
public Color getColor() {
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=834608&r1=834607&r2=834608&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 Tue Nov 10 19:17:54 2009
@@ -460,15 +460,21 @@
}
public Bounds getCharacterBounds(int offset) {
- Shape glyphBounds = glyphVector.getGlyphLogicalBounds(offset);
- Rectangle2D glyphBounds2D = glyphBounds.getBounds2D();
+ Bounds characterBounds = null;
- int x = (int)Math.floor(glyphBounds2D.getX()) + padding.left - scrollLeft + 1;
- int y = padding.top + 1;
- int width = (int)Math.ceil(glyphBounds2D.getWidth());
- int height = getHeight() - (padding.top + padding.bottom + 2);
+ if (glyphVector != null) {
+ Shape glyphBounds = glyphVector.getGlyphLogicalBounds(offset);
+ Rectangle2D glyphBounds2D = glyphBounds.getBounds2D();
- return new Bounds(x, y, width, height);
+ int x = (int)Math.floor(glyphBounds2D.getX()) + padding.left - scrollLeft + 1;
+ int y = padding.top + 1;
+ int width = (int)Math.ceil(glyphBounds2D.getWidth());
+ int height = getHeight() - (padding.top + padding.bottom + 2);
+
+ characterBounds = new Bounds(x, y, width, height);
+ }
+
+ return characterBounds;
}
private void setScrollLeft(int scrollLeft) {
@@ -480,12 +486,15 @@
private void scrollCharacterToVisible(int offset) {
int width = getWidth();
Bounds characterBounds = getCharacterBounds(offset);
- int glyphX = characterBounds.x - (padding.left + 1) + scrollLeft;
- if (characterBounds.x < padding.left + 1) {
- setScrollLeft(glyphX);
- } else if (characterBounds.x + characterBounds.width > width - (padding.right + 1)) {
- setScrollLeft(glyphX + (padding.left + padding.right + 2) + characterBounds.width - width);
+ if (characterBounds != null) {
+ int glyphX = characterBounds.x - (padding.left + 1) + scrollLeft;
+
+ if (characterBounds.x < padding.left + 1) {
+ setScrollLeft(glyphX);
+ } else if (characterBounds.x + characterBounds.width > width - (padding.right + 1)) {
+ setScrollLeft(glyphX + (padding.left + padding.right + 2) + characterBounds.width - width);
+ }
}
}
Modified: incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/flow_pane_test.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/flow_pane_test.wtkx?rev=834608&r1=834607&r2=834608&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/flow_pane_test.wtkx (original)
+++ incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/flow_pane_test.wtkx Tue Nov 10 19:17:54 2009
@@ -16,12 +16,14 @@
limitations under the License.
-->
-<Frame title="FlowPane Test" preferredWidth="320"
- styles="{padding:0}"
+<Frame title="FlowPane Test" styles="{padding:0}"
xmlns:wtkx="http://pivot.apache.org/wtkx"
+ xmlns:content="org.apache.pivot.wtk.content"
+ xmlns:effects="org.apache.pivot.wtk.effects"
xmlns="org.apache.pivot.wtk">
<content>
- <FlowPane styles="{alignment:'left', backgroundColor:'#ff0000', padding:4}">
+ <FlowPane styles="{alignment:'left', padding:4}">
+ <!--
<PushButton buttonData="0" styles="{minimumAspectRatio:15}"/>
<PushButton buttonData="1" styles="{minimumAspectRatio:1.5}"/>
<PushButton buttonData="2" visible="false" styles="{minimumAspectRatio:1.5}"/>
@@ -39,6 +41,24 @@
<PushButton buttonData="D" styles="{minimumAspectRatio:1.5}"/>
<PushButton buttonData="E" styles="{minimumAspectRatio:1.5}"/>
<PushButton buttonData="F" styles="{minimumAspectRatio:1.5}"/>
+ -->
+ <PushButton buttonData="Hello" preferredHeight="80">
+ <decorators>
+ <effects:BaselineDecorator/>
+ </decorators>
+ <dataRenderer>
+ <content:ButtonDataRenderer styles="{verticalAlignment:'bottom'}"/>
+ </dataRenderer>
+ </PushButton>
+
+ <PushButton buttonData="World" preferredHeight="80">
+ <decorators>
+ <effects:BaselineDecorator/>
+ </decorators>
+ <dataRenderer>
+ <content:ButtonDataRenderer styles="{verticalAlignment:'top'}"/>
+ </dataRenderer>
+ </PushButton>
</FlowPane>
</content>
</Frame>