aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJouni Koivuviita <jouni.koivuviita@itmill.com>2010-03-05 12:09:04 +0000
committerJouni Koivuviita <jouni.koivuviita@itmill.com>2010-03-05 12:09:04 +0000
commit2b1deeeced6d098a22d6e52b70e94dbb9e96df57 (patch)
tree9e2f573638d7868c677411c3549c461b97f4e5b9
parent7f8f3e5f3675470e8927ac5a85340cd483e63913 (diff)
downloadvaadin-framework-2b1deeeced6d098a22d6e52b70e94dbb9e96df57.tar.gz
vaadin-framework-2b1deeeced6d098a22d6e52b70e94dbb9e96df57.zip
Fixes #3322: SplitPanel with split position 100% doesn't resize correctly
* Percentage sizes now remain percentages, even if the end user drags the split handle to a new position. An rounding to nearest percentage is done at that point. svn changeset:11661/svn branch:6.3
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VSplitPanel.java71
-rw-r--r--src/com/vaadin/ui/SplitPanel.java14
2 files changed, 63 insertions, 22 deletions
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VSplitPanel.java b/src/com/vaadin/terminal/gwt/client/ui/VSplitPanel.java
index d7a11427fb..101c1e9848 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VSplitPanel.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VSplitPanel.java
@@ -122,6 +122,9 @@ public class VSplitPanel extends ComplexPanel implements Container,
private boolean rendering = false;
+ /* The current position of the split handle in either percentages or pixels */
+ private String position;
+
public VSplitPanel() {
this(ORIENTATION_HORIZONTAL);
}
@@ -208,7 +211,8 @@ public class VSplitPanel extends ComplexPanel implements Container,
setStylenames();
- setSplitPosition(uidl.getStringAttribute("position"));
+ position = uidl.getStringAttribute("position");
+ setSplitPosition(position);
final Paintable newFirstChild = client.getPaintable(uidl
.getChildUIDL(0));
@@ -257,14 +261,26 @@ public class VSplitPanel extends ComplexPanel implements Container,
}
private void setSplitPosition(String pos) {
+ if (pos == null) {
+ return;
+ }
+
+ // Convert percentage values to pixels
+ if (pos.indexOf("%") > 0) {
+ pos = Float.parseFloat(pos.substring(0, pos.length() - 1))
+ / 100
+ * (orientation == ORIENTATION_HORIZONTAL ? getOffsetWidth()
+ : getOffsetHeight()) + "px";
+ }
+
if (orientation == ORIENTATION_HORIZONTAL) {
DOM.setStyleAttribute(splitter, "left", pos);
} else {
DOM.setStyleAttribute(splitter, "top", pos);
}
+
iLayout();
client.runDescendentsLayout(this);
-
}
/*
@@ -441,9 +457,6 @@ public class VSplitPanel extends ComplexPanel implements Container,
onVerticalMouseMove(y);
break;
}
- iLayout();
- // TODO Check if this is needed
- client.runDescendentsLayout(this);
}
@@ -455,7 +468,18 @@ public class VSplitPanel extends ComplexPanel implements Container,
if (newX + getSplitterSize() > getOffsetWidth()) {
newX = getOffsetWidth() - getSplitterSize();
}
- DOM.setStyleAttribute(splitter, "left", newX + "px");
+
+ if (position.indexOf("%") > 0) {
+ float pos = newX;
+ // 100% needs special handling
+ if (newX + getSplitterSize() >= getOffsetWidth()) {
+ pos = getOffsetWidth();
+ }
+ position = pos / getOffsetWidth() * 100 + "%";
+ }
+
+ setSplitPosition(newX + "px");
+
if (origX != newX) {
resized = true;
}
@@ -470,7 +494,18 @@ public class VSplitPanel extends ComplexPanel implements Container,
if (newY + getSplitterSize() > getOffsetHeight()) {
newY = getOffsetHeight() - getSplitterSize();
}
- DOM.setStyleAttribute(splitter, "top", newY + "px");
+
+ if (position.indexOf("%") > 0) {
+ float pos = newY;
+ // 100% needs special handling
+ if (newY + getSplitterSize() >= getOffsetHeight()) {
+ pos = getOffsetHeight();
+ }
+ position = pos / getOffsetHeight() * 100 + "%";
+ }
+
+ setSplitPosition(newY + "px");
+
if (origY != newY) {
resized = true;
}
@@ -554,9 +589,9 @@ public class VSplitPanel extends ComplexPanel implements Container,
this.height = height;
super.setHeight(height);
+
if (!rendering && client != null) {
- iLayout();
- client.runDescendentsLayout(this);
+ setSplitPosition(position);
}
}
@@ -568,9 +603,9 @@ public class VSplitPanel extends ComplexPanel implements Container,
this.width = width;
super.setWidth(width);
+
if (!rendering && client != null) {
- iLayout();
- client.runDescendentsLayout(this);
+ setSplitPosition(position);
}
}
@@ -627,12 +662,14 @@ public class VSplitPanel extends ComplexPanel implements Container,
* Updates the new split position back to server.
*/
private void updateSplitPositionToServer() {
- // We always send pixel values to server
- final String position = orientation == ORIENTATION_HORIZONTAL ? splitter
- .getStyle().getProperty("left")
- : splitter.getStyle().getProperty("top");
- final int pos = Integer.parseInt(position.substring(0, position
- .length() - 2));
+ int pos = 0;
+ if (position.indexOf("%") > 0) {
+ pos = Float.valueOf(position.substring(0, position.length() - 1))
+ .intValue();
+ } else {
+ pos = Integer
+ .parseInt(position.substring(0, position.length() - 2));
+ }
client.updateVariable(id, "position", pos, immediate);
}
diff --git a/src/com/vaadin/ui/SplitPanel.java b/src/com/vaadin/ui/SplitPanel.java
index 5e67b93369..1a149d7394 100644
--- a/src/com/vaadin/ui/SplitPanel.java
+++ b/src/com/vaadin/ui/SplitPanel.java
@@ -281,10 +281,11 @@ public class SplitPanel extends AbstractLayout {
* Moves the position of the splitter.
*
* @param pos
- * the new size of the first region in percentage
+ * the new size of the first region in the unit that was last
+ * used (default is percentage)
*/
public void setSplitPosition(int pos) {
- setSplitPosition(pos, UNITS_PERCENTAGE, true);
+ setSplitPosition(pos, posUnit, true);
}
/**
@@ -303,7 +304,7 @@ public class SplitPanel extends AbstractLayout {
* Moves the position of the splitter.
*
* @param pos
- * the new size of the first region in percentage
+ * the new size of the first region
* @param unit
* the unit (from {@link Sizeable}) in which the size is given.
* @param repaintNotNeeded
@@ -312,6 +313,10 @@ public class SplitPanel extends AbstractLayout {
* knows the position.
*/
private void setSplitPosition(int pos, int unit, boolean repaintNeeded) {
+ if (unit != UNITS_PERCENTAGE && unit != UNITS_PIXELS) {
+ throw new IllegalArgumentException(
+ "Only percentage and pixel units are allowed");
+ }
this.pos = pos;
posUnit = unit;
if (repaintNeeded) {
@@ -353,8 +358,7 @@ public class SplitPanel extends AbstractLayout {
if (variables.containsKey("position") && !isLocked()) {
Integer newPos = (Integer) variables.get("position");
- // Client always sends pixel values. Repaint is not needed.
- setSplitPosition(newPos, UNITS_PIXELS, false);
+ setSplitPosition(newPos, posUnit, false);
}
if (variables.containsKey(SPLITTER_CLICK_EVENT)) {