private boolean rendering = false;
+ /* The current position of the split handle in either percentages or pixels */
+ private String position;
+
public VSplitPanel() {
this(ORIENTATION_HORIZONTAL);
}
setStylenames();
- setSplitPosition(uidl.getStringAttribute("position"));
+ position = uidl.getStringAttribute("position");
+ setSplitPosition(position);
final Paintable newFirstChild = client.getPaintable(uidl
.getChildUIDL(0));
}
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);
-
}
/*
onVerticalMouseMove(y);
break;
}
- iLayout();
- // TODO Check if this is needed
- client.runDescendentsLayout(this);
}
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;
}
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;
}
this.height = height;
super.setHeight(height);
+
if (!rendering && client != null) {
- iLayout();
- client.runDescendentsLayout(this);
+ setSplitPosition(position);
}
}
this.width = width;
super.setWidth(width);
+
if (!rendering && client != null) {
- iLayout();
- client.runDescendentsLayout(this);
+ setSplitPosition(position);
}
}
* 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);
}
* 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);
}
/**
* 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
* 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) {
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)) {