* function on its ancestors that implement NeedsLayout in case their
* container has resized. runAnchestorsLayout(HasWidgets parent) function
* from Util class may be a good helper for this.
+ *
+ * The width and height parameters specifies the space available for the
+ * component (in pixels) if the parent container can or want to produce
+ * these numbers. If the parent container does not know (has not calculated)
+ * or cannot produce (undefined dimensions) one of these numbers -1 is
+ * passed.
*/
- public void iLayout();
+ public void iLayout(int availableWidth, int availableHeight);
}
while (childWidgets.hasNext()) {
final Widget child = (Widget) childWidgets.next();
if (child instanceof ContainerResizedListener) {
- ((ContainerResizedListener) child).iLayout();
+ int w = -1, h = -1;
+
+ if (container instanceof WidgetSpaceAllocator) {
+ w = ((WidgetSpaceAllocator) container)
+ .getAllocatedWidth(child);
+ h = ((WidgetSpaceAllocator) container)
+ .getAllocatedHeight(child);
+ }
+
+ ((ContainerResizedListener) child).iLayout(w, h);
} else if (child instanceof HasWidgets) {
final HasWidgets childContainer = (HasWidgets) child;
runDescendentsLayout(childContainer);
}
}
+ public interface WidgetSpaceAllocator {
+ int getAllocatedWidth(Widget child);
+
+ int getAllocatedHeight(Widget child);
+ }
+
/**
* Returns closest parent Widget in hierarchy that implements Container
* interface
this.height = height;
}
- public void iLayout() {
+ private void iLayout() {
+ iLayout(-1, -1);
+ }
+
+ public void iLayout(int availableWidth, int availableHeight) {
StackItem item = getSelectedStack();
if (item == null) {
return;
widgetToCaptionWrapper.clear();
}
- public void iLayout() {
+ private void iLayout() {
+ iLayout(-1, -1);
+ }
+
+ public void iLayout(int availableWidth, int availableHeight) {
if (!iLayoutJS(DOM.getFirstChild(getElement()))) {
Util.runDescendentsLayout(this);
}
return getWidgetIndex(component) >= 0;
}
- public void iLayout() {
+ private void iLayout() {
+ iLayout(-1, -1);
+ }
+
+ public void iLayout(int availableWidth, int availableHeight) {
if (orientationMode == ORIENTATION_HORIZONTAL) {
int pixels;
if ("".equals(height)) {
DOM.setInnerHTML(desc, "");\r
}\r
\r
- iLayout();\r
+ iLayout(-1, -1);\r
\r
final UIDL layoutUidl = uidl.getChildUIDL(0);\r
Container newLo = (Container) client.getPaintable(layoutUidl);\r
}\r
}\r
\r
- public void iLayout() {\r
+ public void iLayout(int availableWidth, int availableHeight) {\r
Util.runDescendentsLayout(this);\r
}\r
\r
}
- public void iLayout() {
+ private void iLayout() {
+ iLayout(-1, -1);
+ }
+
+ public void iLayout(int availableWidth, int availableHeight) {
if (needsLayout) {
super.setWidth(width);
if (meterElement == null) {
import com.itmill.toolkit.terminal.gwt.client.Paintable;
import com.itmill.toolkit.terminal.gwt.client.UIDL;
import com.itmill.toolkit.terminal.gwt.client.Util;
+import com.itmill.toolkit.terminal.gwt.client.Util.WidgetSpaceAllocator;
/**
* Full implementation of OrderedLayout client peer.
* @author IT Mill Ltd
*/
public class IOrderedLayout extends Panel implements Container,
- ContainerResizedListener {
+ ContainerResizedListener, WidgetSpaceAllocator {
public static final String CLASSNAME = "i-orderedlayout";
* List of child widget wrappers. These wrappers are in exact same indexes
* as the widgets in childWidgets list.
*/
- private final Vector childWidgetWrappers = new Vector();
+ private final Vector<WidgetWrapper> childWidgetWrappers = new Vector<WidgetWrapper>();
/** Whether the component has spacing enabled. */
private boolean hasComponentSpacing;
// Reinsert all widget wrappers to this container
final int currentOrientationMode = orientationMode;
for (int i = 0; i < childWidgetWrappers.size(); i++) {
- WidgetWrapper wr = (WidgetWrapper) childWidgetWrappers.get(i);
+ WidgetWrapper wr = childWidgetWrappers.get(i);
orientationMode = oldOrientationMode;
tableMode = oldTableMode;
Element oldWrElement = wr.getElementWrappingWidgetAndCaption();
&& margins.hasBottom() ? marginBottom + "px" : "");
}
}
+
+ public int getAllocatedHeight() {
+ if (lastForcedPixelHeight == -1) {
+ return -1;
+ }
+
+ int available = lastForcedPixelHeight;
+ // Must remove caption height to report correct size to child
+ if (caption != null) {
+ available -= caption.getOffsetHeight();
+ }
+ return available;
+ }
+
+ public int getAllocatedWidth() {
+ return lastForcedPixelWidth;
+ }
}
/* documented at super */
}
final int removeFromIndex = childWidgets.indexOf(child);
- final WidgetWrapper wrapper = (WidgetWrapper) childWidgetWrappers
+ final WidgetWrapper wrapper = childWidgetWrappers
.get(removeFromIndex);
Element wrapperElement = wrapper.getElement();
final int nonWidgetChildElements = DOM
* from the DOM.
*/
final int index = childWidgets.indexOf(child);
- final WidgetWrapper wrapper = (WidgetWrapper) childWidgetWrappers
- .get(index);
+ final WidgetWrapper wrapper = childWidgetWrappers.get(index);
DOM.removeChild(wrappedChildContainer, wrapper.getElement());
childWidgetWrappers.remove(index);
public void updateCaption(Paintable component, UIDL uidl) {
final int index = childWidgets.indexOf(component);
if (index >= 0) {
- ((WidgetWrapper) childWidgetWrappers.get(index)).updateCaption(
- uidl, component);
+ childWidgetWrappers.get(index).updateCaption(uidl, component);
}
}
}
/* documented at super */
- public void iLayout() {
+ public void iLayout(int availableWidth, int availableHeight) {
updateChildSizes();
Util.runDescendentsLayout(this);
childLayoutsHaveChanged = false;
}
+
+ public int getAllocatedHeight(Widget child) {
+ final int index = childWidgets.indexOf(child);
+ if (index >= 0) {
+ WidgetWrapper wrapper = childWidgetWrappers.get(index);
+ return wrapper.getAllocatedHeight();
+ }
+
+ return -1;
+ }
+
+ public int getAllocatedWidth(Widget child) {
+ final int index = childWidgets.indexOf(child);
+ if (index >= 0) {
+ WidgetWrapper wrapper = childWidgetWrappers.get(index);
+ return wrapper.getAllocatedWidth();
+ }
+
+ return -1;
+ }
}
}
}
- public void iLayout() {
+ public void iLayout(int availableWidth, int availableHeight) {
iLayout(true);
}
initializedAndAttached = true;
}
- public void iLayout() {
+ private void iLayout() {
+ iLayout(-1, -1);
+ }
+
+ public void iLayout(int availableWidth, int availableHeight) {
if (height != null) {
if (height.equals("100%")) {
/*
setValue(new Double(v), animate, roundup);\r
}\r
\r
- public void iLayout() {\r
+ public void iLayout(int availableWidth, int availableHeight) {\r
if (vertical) {\r
setHeight();\r
}\r
iLayout();
}
+ private void iLayout() {
+ iLayout(-1, -1);
+ }
+
/*
* Calculates absolutely positioned container places/sizes (non-Javadoc)
*
* @see com.itmill.toolkit.terminal.gwt.client.NeedsLayout#layout()
*/
- public void iLayout() {
+ public void iLayout(int availableWidth, int availableHeight) {
if (!isAttached()) {
return;
}
}
}
- public void iLayout() {
+ private void iLayout() {
+ iLayout(-1, -1);
+ }
+
+ public void iLayout(int availableWidth, int availableHeight) {
if (height != null && height != "") {
super.setHeight(height);
}
}
- public void iLayout() {
+ private void iLayout() {
+ iLayout(-1, -1);
+ }
+
+ public void iLayout(int availableWidth, int availableHeight) {
if (proportionalWidth >= 0) {
- int availPixels = (int) (DOM.getElementPropertyInt(DOM
- .getParent(getElement()), "clientWidth") * proportionalWidth);
+ int availPixels = availableWidth;
+ if (availPixels < 0) {
+ availPixels = (DOM.getElementPropertyInt(DOM
+ .getParent(getElement()), "clientWidth"));
+ }
+ availPixels *= proportionalWidth;
+
availPixels -= getExtraHorizontalPixels();
if (availPixels >= 0) {
super.setWidth(availPixels + "px");
}
}
if (proportionalHeight >= 0) {
- int availPixels = (int) (DOM.getElementPropertyInt(DOM
- .getParent(getElement()), "clientHeight") * proportionalHeight);
+ int availPixels = availableHeight;
+ if (availPixels < 0) {
+ availPixels = (DOM.getElementPropertyInt(DOM
+ .getParent(getElement()), "clientHeight"));
+ }
+ availPixels *= proportionalHeight;
availPixels -= getExtraVerticalPixels();
- super.setHeight(availPixels + "px");
+
+ if (availPixels >= 0) {
+ super.setHeight(availPixels + "px");
+ }
}
}
return fieldExtraWidth;\r
}\r
\r
- public void iLayout() {\r
+ private void iLayout() {\r
+ iLayout(-1, -1);\r
+ }\r
+\r
+ public void iLayout(int availableWidth, int availableHeight) {\r
if (needLayout) {\r
text.setWidth((getOffsetWidth() - getFieldExtraWidth()) + "px");\r
}\r
}
}
- public void iLayout() {
+ public void iLayout(int availableWidth, int availableHeight) {
boolean sizeChanged = false;
int newWidth = getOffsetWidth();
if (offsetWidth != newWidth) {