diff options
author | John Alhroos <john.ahlroos@itmill.com> | 2010-10-29 07:19:38 +0000 |
---|---|---|
committer | John Alhroos <john.ahlroos@itmill.com> | 2010-10-29 07:19:38 +0000 |
commit | 49b67ef018c03370220857b6d55cbc9f928f7581 (patch) | |
tree | 7a876da84c4321d4772077409033307d6138f1e0 | |
parent | ccd94db68dffb2e8d4562199b718325298a0e80c (diff) | |
download | vaadin-framework-49b67ef018c03370220857b6d55cbc9f928f7581.tar.gz vaadin-framework-49b67ef018c03370220857b6d55cbc9f928f7581.zip |
Adds possibility to set split position from the opposite side in a SplitPanel. #1588
svn changeset:15767/svn branch:6.5
-rw-r--r-- | src/com/vaadin/terminal/gwt/client/ui/VSplitPanel.java | 67 | ||||
-rw-r--r-- | src/com/vaadin/ui/SplitPanel.java | 46 |
2 files changed, 99 insertions, 14 deletions
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VSplitPanel.java b/src/com/vaadin/terminal/gwt/client/ui/VSplitPanel.java index 0b0a9befa3..28feb6c1db 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VSplitPanel.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VSplitPanel.java @@ -1,4 +1,4 @@ -/* +/* @ITMillApache2LicenseForJavaFiles@ */ @@ -107,6 +107,8 @@ public class VSplitPanel extends ComplexPanel implements Container, private boolean locked = false; + private boolean positionReversed = false; + private String[] componentStyleNames; private Element draggingCurtain; @@ -215,6 +217,10 @@ public class VSplitPanel extends ComplexPanel implements Container, setLocked(uidl.getBooleanAttribute("locked")); + if (uidl.hasAttribute("reversed")) { + setPositionReversed(uidl.getBooleanAttribute("reversed")); + } + setStylenames(); position = uidl.getStringAttribute("position"); @@ -266,6 +272,10 @@ public class VSplitPanel extends ComplexPanel implements Container, } } + private void setPositionReversed(boolean reversed) { + positionReversed = reversed; + } + private void setSplitPosition(String pos) { if (pos == null) { return; @@ -280,9 +290,17 @@ public class VSplitPanel extends ComplexPanel implements Container, } if (orientation == ORIENTATION_HORIZONTAL) { - DOM.setStyleAttribute(splitter, "left", pos); + if (positionReversed) { + DOM.setStyleAttribute(splitter, "right", pos); + } else { + DOM.setStyleAttribute(splitter, "left", pos); + } } else { - DOM.setStyleAttribute(splitter, "top", pos); + if (positionReversed) { + DOM.setStyleAttribute(splitter, "bottom", pos); + } else { + DOM.setStyleAttribute(splitter, "top", pos); + } } iLayout(); @@ -310,8 +328,8 @@ public class VSplitPanel extends ComplexPanel implements Container, pixelPosition = DOM.getElementPropertyInt(splitter, "offsetLeft"); // reposition splitter in case it is out of box - if (pixelPosition > 0 - && pixelPosition + getSplitterSize() > wholeSize) { + if ((pixelPosition > 0 && pixelPosition + getSplitterSize() > wholeSize) + || (positionReversed && pixelPosition < 0)) { pixelPosition = wholeSize - getSplitterSize(); if (pixelPosition < 0) { pixelPosition = 0; @@ -342,8 +360,8 @@ public class VSplitPanel extends ComplexPanel implements Container, pixelPosition = DOM.getElementPropertyInt(splitter, "offsetTop"); // reposition splitter in case it is out of box - if (pixelPosition > 0 - && pixelPosition + getSplitterSize() > wholeSize) { + if ((pixelPosition > 0 && pixelPosition + getSplitterSize() > wholeSize) + || (positionReversed && pixelPosition < 0)) { pixelPosition = wholeSize - getSplitterSize(); if (pixelPosition < 0) { pixelPosition = 0; @@ -479,9 +497,23 @@ public class VSplitPanel extends ComplexPanel implements Container, if (newX + getSplitterSize() >= getOffsetWidth()) { pos = getOffsetWidth(); } - position = pos / getOffsetWidth() * 100 + "%"; + // Reversed position + if (positionReversed) { + pos = getOffsetWidth() - pos; + } + position = (pos / getOffsetWidth() * 100) + "%"; } else { - position = newX + "px"; + // Reversed position + if (positionReversed) { + position = (getOffsetWidth() - newX - getSplitterSize()) + "px"; + } else { + position = newX + "px"; + } + } + + // Reversed position + if (positionReversed) { + newX = getOffsetWidth() - newX - getSplitterSize(); } setSplitPosition(newX + "px"); @@ -507,9 +539,24 @@ public class VSplitPanel extends ComplexPanel implements Container, if (newY + getSplitterSize() >= getOffsetHeight()) { pos = getOffsetHeight(); } + // Reversed position + if(positionReversed){ + pos = getOffsetHeight() - pos - getSplitterSize(); + } position = pos / getOffsetHeight() * 100 + "%"; } else { - position = newY + "px"; + // Reversed position + if (positionReversed) { + position = (getOffsetHeight() - newY - getSplitterSize()) + + "px"; + } else { + position = newY + "px"; + } + } + + // Reversed position + if (positionReversed) { + newY = getOffsetHeight() - newY - getSplitterSize(); } setSplitPosition(newY + "px"); diff --git a/src/com/vaadin/ui/SplitPanel.java b/src/com/vaadin/ui/SplitPanel.java index 2fe5f43d97..27dd8b1c98 100644 --- a/src/com/vaadin/ui/SplitPanel.java +++ b/src/com/vaadin/ui/SplitPanel.java @@ -1,4 +1,4 @@ -/* +/* @ITMillApache2LicenseForJavaFiles@ */ @@ -60,6 +60,8 @@ public class SplitPanel extends AbstractLayout { private int posUnit = UNITS_PERCENTAGE; + private boolean posReversed = false; + private boolean locked = false; private static final String SPLITTER_CLICK_EVENT = VSplitPanel.SPLITTER_CLICK_EVENT_IDENTIFIER; @@ -269,6 +271,10 @@ public class SplitPanel extends AbstractLayout { if (isLocked()) { target.addAttribute("locked", true); } + + if (posReversed) { + target.addAttribute("reversed", true); + } if (firstComponent != null) { firstComponent.paint(target); @@ -341,7 +347,21 @@ public class SplitPanel extends AbstractLayout { * used (default is percentage) */ public void setSplitPosition(int pos) { - setSplitPosition(pos, posUnit, true); + setSplitPosition(pos, posUnit, true, false); + } + + /** + * Moves the position of the splitter. + * + * @param pos + * the new size of the region in the unit that was last used + * (default 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) { + setSplitPosition(pos, posUnit, true, reverse); } /** @@ -353,7 +373,23 @@ public class SplitPanel extends AbstractLayout { * the unit (from {@link Sizeable}) in which the size is given. */ public void setSplitPosition(int pos, int unit) { - setSplitPosition(pos, unit, true); + setSplitPosition(pos, unit, true, false); + } + + /** + * Moves the position of the splitter with given position and unit. + * + * @param pos + * size of the first region + * @param unit + * the unit (from {@link Sizeable}) in which the size is given. + * @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, int unit, boolean reverse) { + setSplitPosition(pos, unit, true, reverse); } /** @@ -387,13 +423,15 @@ public class SplitPanel 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(int pos, int unit, boolean repaintNeeded, + boolean reverse) { if (unit != UNITS_PERCENTAGE && unit != UNITS_PIXELS) { throw new IllegalArgumentException( "Only percentage and pixel units are allowed"); } this.pos = pos; posUnit = unit; + posReversed = reverse; if (repaintNeeded) { requestRepaint(); } |