Adding a constructor override to SplitLayoutPanel so users can specify the width of the splitter.
Review at http://gwt-code-reviews.appspot.com/1001801
Review by: jgw@google.com
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@9061 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/user/client/ui/SplitLayoutPanel.java b/user/src/com/google/gwt/user/client/ui/SplitLayoutPanel.java
index 9bd75d5..6997d1d 100644
--- a/user/src/com/google/gwt/user/client/ui/SplitLayoutPanel.java
+++ b/user/src/com/google/gwt/user/client/ui/SplitLayoutPanel.java
@@ -15,10 +15,11 @@
*/
package com.google.gwt.user.client.ui;
+import com.google.gwt.core.client.Scheduler;
+import com.google.gwt.core.client.Scheduler.ScheduledCommand;
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.user.client.Command;
-import com.google.gwt.user.client.DeferredCommand;
import com.google.gwt.user.client.Event;
/**
@@ -56,7 +57,7 @@
class HSplitter extends Splitter {
public HSplitter(Widget target, boolean reverse) {
super(target, reverse);
- getElement().getStyle().setPropertyPx("width", SPLITTER_SIZE);
+ getElement().getStyle().setPropertyPx("width", splitterSize);
setStyleName("gwt-SplitLayoutPanel-HDragger");
}
@@ -86,7 +87,7 @@
private int offset;
private boolean mouseDown;
- private Command layoutCommand;
+ private ScheduledCommand layoutCommand;
private final boolean reverse;
private int minSize;
@@ -170,7 +171,7 @@
forceLayout();
}
};
- DeferredCommand.addCommand(layoutCommand);
+ Scheduler.get().scheduleDeferred(layoutCommand);
}
}
}
@@ -178,7 +179,7 @@
class VSplitter extends Splitter {
public VSplitter(Widget target, boolean reverse) {
super(target, reverse);
- getElement().getStyle().setPropertyPx("height", SPLITTER_SIZE);
+ getElement().getStyle().setPropertyPx("height", splitterSize);
setStyleName("gwt-SplitLayoutPanel-VDragger");
}
@@ -203,13 +204,39 @@
}
}
- private static final int SPLITTER_SIZE = 8;
+ private static final int DEFAULT_SPLITTER_SIZE = 8;
+ private final int splitterSize;
+
+ /**
+ * Construct a new {@link SplitLayoutPanel} with the default splitter size of
+ * 8px.
+ */
public SplitLayoutPanel() {
+ this(DEFAULT_SPLITTER_SIZE);
+ }
+
+ /**
+ * Construct a new {@link SplitLayoutPanel} with the specified splitter size
+ * in pixels.
+ *
+ * @param splitterSize the size of the splitter in pixels
+ */
+ public SplitLayoutPanel(int splitterSize) {
super(Unit.PX);
+ this.splitterSize = splitterSize;
setStyleName("gwt-SplitLayoutPanel");
}
+ /**
+ * Return the size of the splitter in pixels.
+ *
+ * @return the splitter size
+ */
+ public int getSplitterSize() {
+ return splitterSize;
+ }
+
@Override
public void insert(Widget child, Direction direction, double size, Widget before) {
super.insert(child, direction, size, before);
@@ -291,6 +318,6 @@
assert false : "Unexpected direction";
}
- super.insert(splitter, layout.direction, SPLITTER_SIZE, before);
+ super.insert(splitter, layout.direction, splitterSize, before);
}
}
diff --git a/user/test/com/google/gwt/user/client/ui/SplitLayoutPanelTest.java b/user/test/com/google/gwt/user/client/ui/SplitLayoutPanelTest.java
index 8b90ade..41a1d39 100644
--- a/user/test/com/google/gwt/user/client/ui/SplitLayoutPanelTest.java
+++ b/user/test/com/google/gwt/user/client/ui/SplitLayoutPanelTest.java
@@ -89,6 +89,16 @@
assertEquals(l4, children.get(8));
}
+ public void testSplitterSize() {
+ SplitLayoutPanel p = new SplitLayoutPanel(5);
+ assertEquals(5, p.getSplitterSize());
+ WidgetCollection children = p.getChildren();
+
+ p.addWest(new Label("foo"), 64);
+ assertEquals("5px",
+ children.get(1).getElement().getStyle().getWidth().toLowerCase());
+ }
+
public void testRemoveInsert() {
SplitLayoutPanel p = new SplitLayoutPanel();
WidgetCollection children = p.getChildren();