List of usage examples for com.google.gwt.user.client.ui Widget setLayoutData
public void setLayoutData(Object layoutData)
From source file:com.ritchey.client.view.DockPanel.java
License:Apache License
/** * Adds a widget to the specified edge of the dock. If the widget is already a * child of this panel, this method behaves as though {@link #remove(Widget)} * had already been called./*from www. j a v a 2s .c om*/ * * @param widget the widget to be added * @param direction the widget's direction in the dock * * @throws IllegalArgumentException when adding to the {@link #CENTER} and * there is already a different widget there */ public void add(Widget widget, DockLayoutConstant direction) { // Validate if (direction == CENTER) { // Early out on the case of reinserting the center at the center. if (widget == center) { return; } else if (center != null) { // Ensure a second 'center' widget is not being added. throw new IllegalArgumentException("Only one CENTER widget may be added"); } } // Detach new child. widget.removeFromParent(); // Logical attach. getChildren().add(widget); if (direction == CENTER) { center = widget; } // Physical attach. LayoutData layout = new LayoutData(direction); widget.setLayoutData(layout); setCellHorizontalAlignment(widget, horzAlign); setCellVerticalAlignment(widget, vertAlign); realizeTable(); // Adopt. adopt(widget); }
From source file:com.sencha.gxt.widget.core.client.container.HBoxLayoutContainer.java
License:sencha.com license
@Override protected void doLayout() { Size size = getElement().getStyleSize(); if (GXTLogConfiguration.loggingIsEnabled()) { logger.finest(getId() + " doLayout size: " + size); }/* ww w. java 2 s. c o m*/ if ((size.getHeight() == 0 && size.getWidth() == 0) || size.getWidth() == 0) { return; } int w = size.getWidth() - getScrollOffset(); int h = size.getHeight(); int styleHeight = Util.parseInt(getElement().getStyle().getProperty("height"), Style.DEFAULT); int styleWidth = Util.parseInt(getElement().getStyle().getProperty("width"), Style.DEFAULT); boolean findWidth = styleWidth == -1; boolean findHeight = styleHeight == -1; if (GXTLogConfiguration.loggingIsEnabled()) { logger.finest(getId() + " findWidth: " + findWidth + " findHeight: " + findHeight); } int calculateWidth = 0; int maxWidgetHeight = 0; int maxMarginTop = 0; int maxMarginBottom = 0; for (int i = 0, len = getWidgetCount(); i < len; i++) { Widget widget = getWidget(i); BoxLayoutData layoutData = null; Object d = widget.getLayoutData(); if (d instanceof BoxLayoutData) { layoutData = (BoxLayoutData) d; } else { layoutData = new BoxLayoutData(); widget.setLayoutData(layoutData); } Margins cm = layoutData.getMargins(); if (cm == null) { cm = new Margins(0); layoutData.setMargins(cm); } } if (findWidth || findHeight) { for (int i = 0, len = getWidgetCount(); i < len; i++) { Widget widget = getWidget(i); if (!widget.isVisible()) { continue; } BoxLayoutData layoutData = (BoxLayoutData) widget.getLayoutData(); Margins cm = layoutData.getMargins(); calculateWidth += widget.getOffsetWidth(); maxWidgetHeight = Math.max(maxWidgetHeight, widget.getOffsetHeight()); calculateWidth += (cm.getLeft() + cm.getRight()); maxMarginTop = Math.max(maxMarginTop, cm.getTop()); maxMarginBottom = Math.max(maxMarginBottom, cm.getBottom()); } maxWidgetHeight += (maxMarginTop + maxMarginBottom); if (findWidth) { w = calculateWidth; } if (findHeight) { h = maxWidgetHeight; } } int pl = 0; int pt = 0; int pb = 0; int pr = 0; if (getPadding() != null) { pl = getPadding().getLeft(); pt = getPadding().getTop(); pb = getPadding().getBottom(); pr = getPadding().getRight(); } if (findHeight) { h += pt + pb; } if (findWidth) { w += pl + pr; } int stretchHeight = h - pt - pb; int totalFlex = 0; int totalWidth = 0; int maxHeight = 0; for (int i = 0, len = getWidgetCount(); i < len; i++) { Widget widget = getWidget(i); widget.addStyleName(CommonStyles.get().positionable()); widget.getElement().getStyle().setMargin(0, Unit.PX); if (!widget.isVisible()) { continue; } if (widget == more) { triggerWidth = widget.getOffsetWidth() + 10; } BoxLayoutData layoutData = (BoxLayoutData) widget.getLayoutData(); Margins cm = layoutData.getMargins(); // TODO strange issue where getOffsetWidth call in 2nd loop is returning smaller number than actual offset // when packing CENTER or END so we cache the offsetWidth for use in 2nd loop // with buttons, the button is word wrapping causing the button to be narrower and taller int ww = widget.getOffsetWidth(); loopWidthMap.put(widget, ww); loopHeightMap.put(widget, widget.getOffsetHeight()); totalFlex += layoutData.getFlex(); totalWidth += (ww + cm.getLeft() + cm.getRight()); maxHeight = Math.max(maxHeight, widget.getOffsetHeight() + cm.getTop() + cm.getBottom()); } int innerCtHeight = maxHeight + pt + pb; if (hBoxLayoutAlign.equals(HBoxLayoutAlign.STRETCH)) { getContainerTarget().setSize(w, h, true); } else if (hBoxLayoutAlign.equals(HBoxLayoutAlign.MIDDLE) || hBoxLayoutAlign.equals(HBoxLayoutAlign.BOTTOM)) { getContainerTarget().setSize(w, h = Math.max(h, innerCtHeight), true); } else { getContainerTarget().setSize(w, innerCtHeight, true); } int extraWidth = w - totalWidth - pl - pr; int allocated = 0; int componentWidth, componentHeight, componentTop; int availableHeight = h - pt - pb; if (getPack().equals(BoxLayoutPack.CENTER)) { pl += extraWidth / 2; } else if (getPack().equals(BoxLayoutPack.END)) { pl += extraWidth; } for (int i = 0, len = getWidgetCount(); i < len; i++) { Widget widget = getWidget(i); if (!widget.isVisible()) { continue; } BoxLayoutData layoutData = (BoxLayoutData) widget.getLayoutData(); Margins cm = layoutData.getMargins(); componentWidth = loopWidthMap.remove(widget); componentHeight = loopHeightMap.remove(widget); pl += cm.getLeft(); pl = Math.max(0, pl); if (hBoxLayoutAlign.equals(HBoxLayoutAlign.MIDDLE)) { int diff = availableHeight - (componentHeight + cm.getTop() + cm.getBottom()); if (diff == 0) { componentTop = pt + cm.getTop(); } else { componentTop = pt + cm.getTop() + (diff / 2); } } else { if (hBoxLayoutAlign.equals(HBoxLayoutAlign.BOTTOM)) { componentTop = h - (pb + cm.getBottom() + componentHeight); } else { componentTop = pt + cm.getTop(); } } boolean component = widget instanceof Component; Component c = null; if (component) { c = (Component) widget; } int width = -1; if (component) { c.setPosition(pl, componentTop); } else { XElement.as(widget.getElement()).setLeftTop(pl, componentTop); } if (getPack().equals(BoxLayoutPack.START) && layoutData.getFlex() > 0) { int add = (int) Math.floor(extraWidth * (layoutData.getFlex() / totalFlex)); allocated += add; if (isAdjustForFlexRemainder() && i == getWidgetCount() - 1) { add += (extraWidth - allocated); } componentWidth += add; width = componentWidth; } if (hBoxLayoutAlign.equals(HBoxLayoutAlign.STRETCH)) { applyLayout(widget, width, Util.constrain(stretchHeight - cm.getTop() - cm.getBottom(), layoutData.getMinSize(), layoutData.getMaxSize())); } else if (hBoxLayoutAlign.equals(HBoxLayoutAlign.STRETCHMAX)) { applyLayout(widget, width, Util.constrain(maxHeight - cm.getTop() - cm.getBottom(), layoutData.getMinSize(), layoutData.getMaxSize())); } else if (width > 0) { applyLayout(widget, width, -1); } pl += componentWidth + cm.getRight(); } // do we need overflow if (enableOverflow) { int runningWidth = 0; for (int i = 0, len = getWidgetCount(); i < len; i++) { Widget widget = getWidget(i); if (widget == more) { continue; } BoxLayoutData layoutData = null; Object d = widget.getLayoutData(); if (d instanceof BoxLayoutData) { layoutData = (BoxLayoutData) d; } else { layoutData = new BoxLayoutData(); } Margins cm = layoutData.getMargins(); if (cm == null) { cm = new Margins(0); } runningWidth += getWidgetWidth(widget); runningWidth += cm.getLeft(); runningWidth += cm.getRight(); } if (runningWidth > w) { hasOverflow = true; onOverflow(); } else { hasOverflow = false; if (more != null && more.getParent() == this) { onUnoverflow(); } } } }
From source file:com.sencha.gxt.widget.core.client.container.SimpleContainer.java
License:sencha.com license
/** * Adds a widget to the simple layout container with the specified layout * parameters.// w w w. ja va 2 s . c o m * * @param child the widget to add to the layout container * @param layoutData the parameters that describe how to lay out the widget */ @UiChild(limit = 1, tagname = "child") public void add(Widget child, MarginData layoutData) { child.setLayoutData(layoutData); setWidget(child); }
From source file:com.sencha.gxt.widget.core.client.container.VBoxLayoutContainer.java
License:sencha.com license
@Override protected void doLayout() { Size size = getElement().getStyleSize(); if (GXTLogConfiguration.loggingIsEnabled()) { logger.finest(getId() + " doLayout size: " + size); }/*w w w. j av a 2s . c o m*/ int w = size.getWidth() - getScrollOffset(); int h = size.getHeight(); int styleHeight = Util.parseInt(getElement().getStyle().getProperty("height"), Style.DEFAULT); int styleWidth = Util.parseInt(getElement().getStyle().getProperty("width"), Style.DEFAULT); boolean findWidth = styleWidth == -1; boolean findHeight = styleHeight == -1; if (GXTLogConfiguration.loggingIsEnabled()) { logger.finest(getId() + " findWidth: " + findWidth + " findHeight: " + findHeight); } int calculateHeight = 0; int maxWidgetWidth = 0; int maxMarginLeft = 0; int maxMarginRight = 0; for (int i = 0, len = getWidgetCount(); i < len; i++) { Widget widget = getWidget(i); BoxLayoutData layoutData = null; Object d = widget.getLayoutData(); if (d instanceof BoxLayoutData) { layoutData = (BoxLayoutData) d; } else { layoutData = new BoxLayoutData(); widget.setLayoutData(layoutData); } Margins cm = layoutData.getMargins(); if (cm == null) { cm = new Margins(0); layoutData.setMargins(cm); } } if (findWidth || findHeight) { for (int i = 0, len = getWidgetCount(); i < len; i++) { Widget widget = getWidget(i); if (!widget.isVisible()) { continue; } BoxLayoutData layoutData = (BoxLayoutData) widget.getLayoutData(); Margins cm = layoutData.getMargins(); calculateHeight += widget.getOffsetHeight(); maxWidgetWidth = Math.max(maxWidgetWidth, widget.getOffsetWidth()); calculateHeight += (cm.getTop() + cm.getBottom()); maxMarginLeft = Math.max(maxMarginLeft, cm.getLeft()); maxMarginRight = Math.max(maxMarginRight, cm.getRight()); } maxWidgetWidth += (maxMarginLeft + maxMarginRight); if (findHeight) { h = calculateHeight; } if (findWidth) { w = maxWidgetWidth; } } int pl = 0; int pt = 0; int pb = 0; int pr = 0; if (getPadding() != null) { pl = getPadding().getLeft(); pt = getPadding().getTop(); pb = getPadding().getBottom(); pr = getPadding().getRight(); } if (findHeight) { h += pt + pb; } if (findWidth) { w += pl + pr; } int stretchWidth = w - pl - pr; int totalFlex = 0; int totalHeight = 0; int maxWidth = 0; for (int i = 0, len = getWidgetCount(); i < len; i++) { Widget widget = getWidget(i); widget.addStyleName(CommonStyles.get().positionable()); widget.getElement().getStyle().setMargin(0, Unit.PX); // callLayout(widget, false); BoxLayoutData layoutData = (BoxLayoutData) widget.getLayoutData(); Margins cm = layoutData.getMargins(); totalFlex += layoutData.getFlex(); totalHeight += widget.getOffsetHeight() + cm.getTop() + cm.getBottom(); maxWidth = Math.max(maxWidth, widget.getOffsetWidth() + cm.getLeft() + cm.getRight()); } int innerCtWidth = maxWidth + pl + pr; if (vBoxLayoutAlign.equals(VBoxLayoutAlign.STRETCH)) { getContainerTarget().setSize(w, h, true); } else { getContainerTarget().setSize(w = Math.max(w, innerCtWidth), h, true); } int extraHeight = h - totalHeight - pt - pb; int allocated = 0; int cw, ch, cl; int availableWidth = w - pl - pr; if (getPack().equals(BoxLayoutPack.CENTER)) { pt += extraHeight / 2; } else if (getPack().equals(BoxLayoutPack.END)) { pt += extraHeight; } for (int i = 0, len = getWidgetCount(); i < len; i++) { Widget widget = getWidget(i); BoxLayoutData layoutData = (BoxLayoutData) widget.getLayoutData(); Margins cm = layoutData.getMargins(); cw = widget.getOffsetWidth(); ch = widget.getOffsetHeight(); pt += cm.getTop(); if (vBoxLayoutAlign.equals(VBoxLayoutAlign.CENTER)) { int diff = availableWidth - (cw + cm.getLeft() + cm.getRight()); if (diff == 0) { cl = pl + cm.getLeft(); } else { cl = pl + cm.getLeft() + (diff / 2); } } else { if (vBoxLayoutAlign.equals(VBoxLayoutAlign.RIGHT)) { cl = w - (pr + cm.getRight() + cw); } else { cl = pl + cm.getLeft(); } } boolean component = widget instanceof Component; Component c = null; if (component) { c = (Component) widget; } int height = -1; if (component) { c.setPosition(cl, pt); } else { XElement.as(widget.getElement()).setLeftTop(cl, pt); } if (getPack().equals(BoxLayoutPack.START) && layoutData.getFlex() > 0) { int add = (int) Math.floor(extraHeight * (layoutData.getFlex() / totalFlex)); allocated += add; if (isAdjustForFlexRemainder() && i == getWidgetCount() - 1) { add += extraHeight - allocated; } ch += add; height = ch; } if (vBoxLayoutAlign.equals(VBoxLayoutAlign.STRETCH)) { applyLayout(widget, Util.constrain(stretchWidth - cm.getLeft() - cm.getRight(), layoutData.getMinSize(), layoutData.getMaxSize()), height); } else if (vBoxLayoutAlign.equals(VBoxLayoutAlign.STRETCHMAX)) { applyLayout(widget, Util.constrain(maxWidth - cm.getLeft() - cm.getRight(), layoutData.getMinSize(), layoutData.getMaxSize()), height); } else if (height > 0) { applyLayout(widget, -1, height); } pt += ch + cm.getBottom(); } }
From source file:com.sencha.gxt.widget.core.client.toolbar.ToolBar.java
License:sencha.com license
private void setSpacingLayoutData(Widget child) { if (verticalSpacing == -1 && horizontalSpacing == -1) { return;// w ww . j ava2 s. c o m } Object data = child.getLayoutData(); HasMargins hasMargins = null; if (!(data instanceof HasMargins)) { hasMargins = new BoxLayoutData(); child.setLayoutData(hasMargins); } else { hasMargins = (HasMargins) data; } Margins m = hasMargins.getMargins(); if (m == null) { m = new Margins(); hasMargins.setMargins(m); } if (verticalSpacing != -1) { int vs = (int) Math.round(verticalSpacing / 2d); m.setTop(vs); m.setBottom(vs); } if (horizontalSpacing != -1) { int hs = (int) Math.round(horizontalSpacing / 2d); m.setLeft(hs); m.setRight(hs); } }
From source file:geogebra.web.gui.app.docklayout.MyDockLayoutPanel.java
License:Apache License
/** * Adds a widget to the specified edge of the dock. If the widget is already * a child of this panel, this method behaves as though * {@link #remove(Widget)} had already been called. * /*from w w w . j a va2 s . c o m*/ * @param widget * the widget to be added * @param direction * the widget's direction in the dock * @param before * the widget before which to insert the new child, or * <code>null</code> to append */ protected void insert(Widget widget, Direction direction, double size, Widget before) { assertIsChild(before); // Validation. if (before == null) { assert center == null : "No widget may be added after the CENTER widget"; } else { assert direction != Direction.CENTER : "A CENTER widget must always be added last"; } // Detach new child. widget.removeFromParent(); // Logical attach. WidgetCollection children = getChildren(); if (before == null) { children.add(widget); } else { int index = children.indexOf(before); children.insert(widget, index); } if (direction == Direction.CENTER) { center = widget; } // Physical attach. Layer layer = layout.attachChild(widget.getElement(), (before != null) ? before.getElement() : null, widget); LayoutData data = new LayoutData(direction, size, layer); widget.setLayoutData(data); // Adopt. adopt(widget); // Update the layout. animate(0); }
From source file:org.gwt.mosaic.ui.client.layout.CustomGridLayout.java
License:Apache License
private GridLayoutData getLayoutData(Widget widget) { Object layoutDataObject = widget.getLayoutData(); if (layoutDataObject == null || !(layoutDataObject instanceof GridLayoutData)) { layoutDataObject = new GridLayoutData(); widget.setLayoutData(layoutDataObject); }//from w ww . j a va 2 s . c om return (GridLayoutData) layoutDataObject; }
From source file:org.jrydberg.ui.client.LayoutPanel.java
License:Apache License
public Layer add(Widget widget) { basePanel.add(widget);//from w w w. j a va 2 s .c o m Layer layer = new Layer(widget); widget.addStyleName(resources.layoutPanelCss().layout()); widget.setLayoutData(layer); return layer; }
From source file:org.kaaproject.kaa.server.admin.client.layout.CustomDeckLayoutPanel.java
License:Apache License
/** * Insert a widget before the specified widget. If the widget is already a * child of this panel, this method behaves as though {@link #remove(Widget)} * had already been called.//from w w w . j av a 2s.co m * * @param widget the widget to be added * @param before the widget before which to insert the new child, or * <code>null</code> to append */ public void insert(Widget widget, Widget before) { assertIsChild(before); // Detach new child. widget.removeFromParent(); // Logical attach. WidgetCollection children = getChildren(); if (before == null) { children.add(widget); } else { int index = children.indexOf(before); children.insert(widget, index); } // Physical attach. Layer layer = layout.attachChild(widget.getElement(), (before != null) ? before.getElement() : null, widget); setWidgetVisible(widget, layer, false); widget.setLayoutData(layer); // Adopt. adopt(widget); // Update the layout. animate(0); }
From source file:org.kaaproject.kaa.server.admin.client.layout.CustomDeckLayoutPanel.java
License:Apache License
@Override public boolean remove(Widget w) { boolean removed = super.remove(w); if (removed) { Layer layer = (Layer) w.getLayoutData(); layout.removeChild(layer);//from w w w. j av a 2s . c o m w.setLayoutData(null); if (visibleWidget == w) { visibleWidget = null; } if (hidingWidget == w) { hidingWidget = null; } if (lastVisibleWidget == w) { lastVisibleWidget = null; } } return removed; }