diff options
author | Artur Signell <artur.signell@itmill.com> | 2012-04-10 12:46:38 +0000 |
---|---|---|
committer | Artur Signell <artur.signell@itmill.com> | 2012-04-10 12:46:38 +0000 |
commit | 7691b19584d06dd78fc094bb23cfe10df8ad2cde (patch) | |
tree | 2a4bab444dfc5f58b791e327df7cb7caf2367fe1 /src/com/vaadin/ui | |
parent | 18dd267cfe3757adee20aaae556b64746c677683 (diff) | |
download | vaadin-framework-7691b19584d06dd78fc094bb23cfe10df8ad2cde.tar.gz vaadin-framework-7691b19584d06dd78fc094bb23cfe10df8ad2cde.zip |
Allow splitter position to be float to avoid rounding errors (#4296)
svn changeset:23419/svn branch:6.8
Diffstat (limited to 'src/com/vaadin/ui')
-rw-r--r-- | src/com/vaadin/ui/AbstractSplitPanel.java | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/src/com/vaadin/ui/AbstractSplitPanel.java b/src/com/vaadin/ui/AbstractSplitPanel.java index adb84f9d9d..b507b88478 100644 --- a/src/com/vaadin/ui/AbstractSplitPanel.java +++ b/src/com/vaadin/ui/AbstractSplitPanel.java @@ -35,7 +35,7 @@ public abstract class AbstractSplitPanel extends AbstractLayout { private Component secondComponent; - private int pos = 50; + private float pos = 50; private int posUnit = UNITS_PERCENTAGE; @@ -250,9 +250,10 @@ public abstract class AbstractSplitPanel extends AbstractLayout { * * @param pos * the new size of the first region in the unit that was last - * used (default is percentage) + * used (default is percentage). Fractions are only allowed when + * unit is percentage. */ - public void setSplitPosition(int pos) { + public void setSplitPosition(float pos) { setSplitPosition(pos, posUnit, true, false); } @@ -261,12 +262,14 @@ public abstract class AbstractSplitPanel extends AbstractLayout { * * @param pos * the new size of the region in the unit that was last used - * (default is percentage) + * (default is percentage). Fractions are only allowed when unit + * is percentage. + * * @param reverse * if set to true the split splitter position is measured by the * second region else it is measured by the first region */ - public void setSplitPosition(int pos, boolean reverse) { + public void setSplitPosition(float pos, boolean reverse) { setSplitPosition(pos, posUnit, true, reverse); } @@ -274,11 +277,12 @@ public abstract class AbstractSplitPanel extends AbstractLayout { * Moves the position of the splitter with given position and unit. * * @param pos - * size of the first region + * the new size of the first region. Fractions are only allowed + * when unit is percentage. * @param unit * the unit (from {@link Sizeable}) in which the size is given. */ - public void setSplitPosition(int pos, int unit) { + public void setSplitPosition(float pos, int unit) { setSplitPosition(pos, unit, true, false); } @@ -286,7 +290,8 @@ public abstract class AbstractSplitPanel extends AbstractLayout { * Moves the position of the splitter with given position and unit. * * @param pos - * size of the first region + * the new size of the first region. Fractions are only allowed + * when unit is percentage. * @param unit * the unit (from {@link Sizeable}) in which the size is given. * @param reverse @@ -294,7 +299,7 @@ public abstract class AbstractSplitPanel extends AbstractLayout { * second region else it is measured by the first region * */ - public void setSplitPosition(int pos, int unit, boolean reverse) { + public void setSplitPosition(float pos, int unit, boolean reverse) { setSplitPosition(pos, unit, true, reverse); } @@ -304,7 +309,7 @@ public abstract class AbstractSplitPanel extends AbstractLayout { * * @return position of the splitter */ - public int getSplitPosition() { + public float getSplitPosition() { return pos; } @@ -321,7 +326,8 @@ public abstract class AbstractSplitPanel extends AbstractLayout { * Moves the position of the splitter. * * @param pos - * the new size of the first region + * the new size of the first region. Fractions are only allowed + * when unit is percentage. * @param unit * the unit (from {@link Sizeable}) in which the size is given. * @param repaintNotNeeded @@ -329,12 +335,15 @@ public abstract class AbstractSplitPanel extends AbstractLayout { * position info has come from the client side, thus it already * knows the position. */ - private void setSplitPosition(int pos, int unit, boolean repaintNeeded, + private void setSplitPosition(float pos, int unit, boolean repaintNeeded, boolean reverse) { if (unit != UNITS_PERCENTAGE && unit != UNITS_PIXELS) { throw new IllegalArgumentException( "Only percentage and pixel units are allowed"); } + if (unit != UNITS_PERCENTAGE) { + pos = Math.round(pos); + } this.pos = pos; posUnit = unit; posReversed = reverse; @@ -377,7 +386,7 @@ public abstract class AbstractSplitPanel extends AbstractLayout { super.changeVariables(source, variables); if (variables.containsKey("position") && !isLocked()) { - Integer newPos = (Integer) variables.get("position"); + Float newPos = (Float) variables.get("position"); setSplitPosition(newPos, posUnit, posReversed); } |