diff options
author | Leif Åstrand <leif@vaadin.com> | 2012-07-30 13:21:45 +0000 |
---|---|---|
committer | Leif Åstrand <leif@vaadin.com> | 2012-07-30 13:21:45 +0000 |
commit | 64c7bbb569d5194eb9c5c083726a8c96053368e8 (patch) | |
tree | 19f2ea30f8cdc48d84ab0f03f8e0e5b51b1d21c3 /src | |
parent | 7635949eb052473472fbe9a50e563f6ef8730e2f (diff) | |
download | vaadin-framework-64c7bbb569d5194eb9c5c083726a8c96053368e8.tar.gz vaadin-framework-64c7bbb569d5194eb9c5c083726a8c96053368e8.zip |
Avoid int parse error in VSplitPanel and clean up the code (#9154)
svn changeset:24034/svn branch:6.8
Diffstat (limited to 'src')
-rw-r--r-- | src/com/vaadin/terminal/gwt/client/ui/VSplitPanel.java | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VSplitPanel.java b/src/com/vaadin/terminal/gwt/client/ui/VSplitPanel.java index 00d76e3a45..e8c9b87ce0 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VSplitPanel.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VSplitPanel.java @@ -385,23 +385,22 @@ public class VSplitPanel extends ComplexPanel implements Container, * @return */ private float convertToPercentage(String pos) { - float posAsFloat = 0; - - if (pos.indexOf("px") > 0) { - int posAsInt = Integer.parseInt(pos.substring(0, pos.length() - 2)); + if (pos.endsWith("px")) { + float pixelPosition = Float.parseFloat(pos.substring(0, + pos.length() - 2)); int offsetLength = orientation == ORIENTATION_HORIZONTAL ? getOffsetWidth() : getOffsetHeight(); - // 100% needs special handling - if (posAsInt + getSplitterSize() >= offsetLength) { - posAsInt = offsetLength; + // Take splitter size into account at the edge + if (pixelPosition + getSplitterSize() >= offsetLength) { + return 100; } - posAsFloat = ((float) posAsInt / (float) offsetLength * 100); + return pixelPosition / offsetLength * 100; } else { - posAsFloat = Float.parseFloat(pos.substring(0, pos.length() - 1)); + assert pos.endsWith("%"); + return Float.parseFloat(pos.substring(0, pos.length() - 1)); } - return posAsFloat; } private String checkSplitPositionLimits(String pos) { |