]> source.dussan.org Git - vaadin-framework.git/commitdiff
Adds possibility to set split position from the opposite side in a SplitPanel. #1588
authorJohn Alhroos <john.ahlroos@itmill.com>
Fri, 29 Oct 2010 07:19:38 +0000 (07:19 +0000)
committerJohn Alhroos <john.ahlroos@itmill.com>
Fri, 29 Oct 2010 07:19:38 +0000 (07:19 +0000)
svn changeset:15767/svn branch:6.5

src/com/vaadin/terminal/gwt/client/ui/VSplitPanel.java
src/com/vaadin/ui/SplitPanel.java

index 0b0a9befa3f8cfee34e5419efda221618d9e7665..28feb6c1dbb3a0917026ea20b430fad9ba2bb120 100644 (file)
@@ -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");
index 2fe5f43d97140a98b4d97400e9bd6e22ef9e4e09..27dd8b1c98a1ccbec213e5b63a7b6a71e3c39396 100644 (file)
@@ -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();
         }