import com.itmill.toolkit.terminal.gwt.client.ui.IUpload;
import com.itmill.toolkit.terminal.gwt.client.ui.IWindow;
import com.itmill.toolkit.terminal.gwt.client.ui.absolutegrid.ISizeableGridLayout;
-import com.itmill.toolkit.terminal.gwt.client.ui.absolutegrid.ISizeableOrderedLayout;
import com.itmill.toolkit.terminal.gwt.client.ui.richtextarea.IRichTextArea;
public class DefaultWidgetSet implements WidgetSet {
} else if ("com.itmill.toolkit.terminal.gwt.client.ui.IWindow"
.equals(className)) {
return new IWindow();
- } else if ("com.itmill.toolkit.terminal.gwt.client.ui.absolutegrid.ISizeableOrderedLayout"
- .equals(className)) {
- return new ISizeableOrderedLayout();
} else if ("com.itmill.toolkit.terminal.gwt.client.ui.IOrderedLayoutVertical"
.equals(className)) {
return new IOrderedLayoutVertical();
return "com.itmill.toolkit.terminal.gwt.client.ui.IWindow";
} else if ("orderedlayout".equals(tag)) {
if ("horizontal".equals(uidl.getStringAttribute("orientation"))) {
- if (uidl.hasAttribute("height") && uidl.hasAttribute("width")) {
- return "com.itmill.toolkit.terminal.gwt.client.ui.absolutegrid.ISizeableOrderedLayout";
- } else {
- return "com.itmill.toolkit.terminal.gwt.client.ui.IOrderedLayoutHorizontal";
- }
+ return "com.itmill.toolkit.terminal.gwt.client.ui.IOrderedLayoutHorizontal";
} else {
- if (uidl.hasAttribute("height")) {
- return "com.itmill.toolkit.terminal.gwt.client.ui.absolutegrid.ISizeableOrderedLayout";
- } else {
- return "com.itmill.toolkit.terminal.gwt.client.ui.IOrderedLayoutVertical";
- }
+ return "com.itmill.toolkit.terminal.gwt.client.ui.IOrderedLayoutVertical";
}
} else if ("label".equals(tag)) {
return "com.itmill.toolkit.terminal.gwt.client.ui.ILabel";
public static final int ORIENTATION_VERTICAL = 0;
public static final int ORIENTATION_HORIZONTAL = 1;
+ // TODO Read this from CSS as in #1904
+ private static final int SPACING_SIZE = 8;
+
int orientationMode = ORIENTATION_VERTICAL;
protected ApplicationConnection client;
*/
private final Vector childWidgets = new Vector();
+ /**
+ * Fixed cell-size mode is used when height/width is explicitly given for
+ * vertical/horizontal orderedlayout.
+ */
+ private boolean fixedCellSize = false;
+
/**
* List of child widget wrappers. These wrappers are in exact same indexes
* as the widgets in childWidgets list.
/** Whether the component has spacing enabled. */
private boolean hasComponentSpacing;
+ /** Whether the component has spacing enabled. */
+ private int previouslyAppliedFixedSize = -1;
+
/** Information about margin states. */
private MarginInfo margins = new MarginInfo(0);
// Handle component alignments
handleAlignments(uidl);
+
+ updateFixedSizes();
+ }
+
+ public void setWidth(String width) {
+ super.setWidth(width);
+ if (ORIENTATION_VERTICAL == orientationMode) {
+ return;
+ }
+ if (width == null || "".equals(width)) {
+
+ // Removing fixed size is needed only when it is in use
+ if (fixedCellSize) {
+ removeFixedSizes();
+ }
+ } else {
+ fixedCellSize = true;
+ }
+ }
+
+ public void setHeight(String height) {
+ super.setHeight(height);
+ if (ORIENTATION_HORIZONTAL == orientationMode) {
+ return;
+ }
+ if (height == null || "".equals(height)) {
+
+ // Removing fixed size is needed only when it is in use
+ if (fixedCellSize) {
+ removeFixedSizes();
+ }
+ } else {
+ fixedCellSize = true;
+ }
+ }
+
+ /** Remove fixed sizes from use */
+ private void removeFixedSizes() {
+
+ // If already removed, do not do it twice
+ if (!fixedCellSize) {
+ return;
+ }
+
+ // Remove unneeded attributes from each wrapper
+ String wh = (orientationMode == ORIENTATION_HORIZONTAL) ? "width"
+ : "height";
+ String overflow = (orientationMode == ORIENTATION_HORIZONTAL) ? (BrowserInfo
+ .get().isFF2() ? "overflow" : "overflowX")
+ : "overflowY";
+ for (Iterator i = childWidgetWrappers.iterator(); i.hasNext();) {
+ Element we = ((WidgetWrapper) i.next()).getElement();
+ DOM.setStyleAttribute(we, wh, "");
+ DOM.setStyleAttribute(we, overflow, "");
+ }
+
+ // margin
+ DOM.setStyleAttribute(margin,
+ (orientationMode == ORIENTATION_HORIZONTAL) ? "overflowX"
+ : "overflowY", "");
+ DOM.setStyleAttribute(margin,
+ (orientationMode == ORIENTATION_HORIZONTAL) ? "width"
+ : "height", "");
+
+ // Remove unneeded attributes from horizontal layouts table
+ if (orientationMode == ORIENTATION_HORIZONTAL) {
+ Element table = DOM.getParent(DOM.getParent(wrappedChildContainer));
+ DOM.setStyleAttribute(table, "tableLayout", "auto");
+ DOM.setStyleAttribute(table, "width", "");
+ }
+
+ fixedCellSize = false;
+ previouslyAppliedFixedSize = -1;
+
+ }
+
+ /** Reset the fixed cell-sizes for children. */
+ private void updateFixedSizes() {
+
+ // Do not do anything if we really should not be doing this
+ if (!fixedCellSize) {
+ return;
+ }
+
+ DOM.setStyleAttribute(margin,
+ (orientationMode == ORIENTATION_HORIZONTAL) ? "overflowX"
+ : "overflowY", "hidden");
+ DOM.setStyleAttribute(margin,
+ (orientationMode == ORIENTATION_HORIZONTAL) ? "width"
+ : "height", "100%");
+
+ int size = DOM.getElementPropertyInt(margin,
+ (orientationMode == ORIENTATION_HORIZONTAL) ? "offsetWidth"
+ : "offsetHeight");
+
+ // Horizontal layouts need fixed mode tables
+ if (orientationMode == ORIENTATION_HORIZONTAL) {
+ Element table = DOM.getParent(DOM.getParent(wrappedChildContainer));
+ DOM.setStyleAttribute(table, "tableLayout", "fixed");
+ DOM.setStyleAttribute(table, "width", "" + size + "px");
+ }
+
+ // Reduce spacing from the size
+ int numChild = childWidgets.size();
+ if (hasComponentSpacing) {
+ size -= SPACING_SIZE * (numChild - 1);
+ }
+
+ // Have we set fixed sizes before?
+ boolean firstTime = (previouslyAppliedFixedSize < 0);
+
+ // If so, are they already correct?
+ if (size == previouslyAppliedFixedSize) {
+ return;
+ }
+ previouslyAppliedFixedSize = size;
+
+ // Set the sizes for each child
+ String wh = (orientationMode == ORIENTATION_HORIZONTAL) ? "width"
+ : "height";
+ String overflow = (orientationMode == ORIENTATION_HORIZONTAL) ? (BrowserInfo
+ .get().isFF2() ? "overflow" : "overflowX")
+ : "overflowY";
+ for (Iterator i = childWidgetWrappers.iterator(); i.hasNext();) {
+ Element we = ((WidgetWrapper) i.next()).getElement();
+ final int ws = Math.round(((float) size) / (numChild--));
+ size -= ws;
+ DOM.setStyleAttribute(we, wh, "" + ws + "px");
+ if (firstTime) {
+ DOM.setStyleAttribute(we, overflow, "hidden");
+ }
+ }
+
+ fixedCellSize = true;
}
protected void handleMargins(UIDL uidl) {
+++ /dev/null
-package com.itmill.toolkit.terminal.gwt.client.ui.absolutegrid;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-
-import com.google.gwt.user.client.ui.Widget;
-import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
-import com.itmill.toolkit.terminal.gwt.client.Caption;
-import com.itmill.toolkit.terminal.gwt.client.Container;
-import com.itmill.toolkit.terminal.gwt.client.Paintable;
-import com.itmill.toolkit.terminal.gwt.client.UIDL;
-import com.itmill.toolkit.terminal.gwt.client.ui.MarginInfo;
-
-/**
- * Proto level implementation of GridLayout.
- *
- * All cell's will be equally sized.
- *
- */
-public class ISizeableOrderedLayout extends AbsoluteGrid implements Paintable,
- Container {
- public static final String CLASSNAME = "i-orderedlayout";
- private static final int ORIENTETION_HORIZONTAL = 1;
- private int spacing;
- private HashMap paintableToCellMap = new HashMap();
- private ApplicationConnection client;
- private int orientation;
-
- public ISizeableOrderedLayout() {
- super();
- setStyleName(CLASSNAME);
- }
-
- protected int getSpacingSize() {
- return spacing;
- }
-
- public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
- this.client = client;
-
- if (client.updateComponent(this, uidl, false)) {
- return;
- }
-
- orientation = (uidl.hasAttribute("orientation") ? ORIENTETION_HORIZONTAL
- : 0);
-
- if (uidl.hasAttribute("caption")) {
- setTitle(uidl.getStringAttribute("caption"));
- }
-
- handleMargins(uidl);
- spacing = uidl.getBooleanAttribute("spacing") ? detectSpacingSize() : 0;
-
- final int[] alignments = uidl.getIntArrayAttribute("alignments");
- int alignmentIndex = 0;
-
- // Update contained components
-
- final ArrayList uidlWidgets = new ArrayList();
- for (final Iterator it = uidl.getChildIterator(); it.hasNext();) {
- final UIDL uidlForChild = (UIDL) it.next();
- final Paintable child = client.getPaintable(uidlForChild);
- uidlWidgets.add(child);
- }
-
- if (orientation == ORIENTETION_HORIZONTAL) {
- setCols(uidlWidgets.size());
- setRows(1);
- } else {
- setCols(1);
- setRows(uidlWidgets.size());
- }
-
- final ArrayList oldWidgets = getPaintables();
-
- final HashMap oldCaptions = new HashMap();
-
- final Iterator newIt = uidlWidgets.iterator();
- final Iterator newUidl = uidl.getChildIterator();
-
- int row = 0, column = 0;
- while (newIt.hasNext()) {
- final Widget child = (Widget) newIt.next();
- final UIDL childUidl = (UIDL) newUidl.next();
-
- AbsoluteGridCell cell = getCell(column, row);
-
- Widget oldChild = cell.getWidget();
- if (oldChild != null) {
- if (oldChild != child) {
- oldCaptions.put(oldChild, cell.getCaption());
- cell.clear();
- cell.setWidget(child);
- paintableToCellMap.remove(oldChild);
- Caption newCaption = (Caption) oldCaptions.get(child);
- if (newCaption == null) {
- newCaption = new Caption((Paintable) child, client);
- }
- cell.setCaption(newCaption);
- }
- } else {
- cell.setWidget(child);
- }
-
- paintableToCellMap.put(child, cell);
-
- cell.setAlignment(alignments[alignmentIndex++]);
-
- cell.render();
-
- ((Paintable) child).updateFromUIDL(childUidl, client);
-
- cell.vAling();
-
- if (orientation == ORIENTETION_HORIZONTAL) {
- column++;
- } else {
- row++;
- }
- oldWidgets.remove(child);
- }
- // remove possibly remaining old Paintable object which were not updated
- Iterator oldIt = oldWidgets.iterator();
- while (oldIt.hasNext()) {
- final Paintable p = (Paintable) oldIt.next();
- if (!uidlWidgets.contains(p)) {
- removePaintable(p);
- }
- }
- }
-
- private void removePaintable(Paintable oldChild) {
- AbsoluteGridCell cell = (AbsoluteGridCell) paintableToCellMap
- .get(oldChild);
- if (cell != null) {
- cell.clear();
- }
- client.unregisterPaintable(oldChild);
- }
-
- private ArrayList getPaintables() {
- ArrayList paintables = new ArrayList();
- Iterator it = paintableToCellMap.keySet().iterator();
- while (it.hasNext()) {
- Paintable p = (Paintable) it.next();
- paintables.add(p);
- }
- return paintables;
- }
-
- protected void handleMargins(UIDL uidl) {
- final MarginInfo margins = new MarginInfo(uidl
- .getIntAttribute("margins"));
- // TODO build CSS detector to make margins configurable through css
- marginTop = margins.hasTop() ? 15 : 0;
- marginRight = margins.hasRight() ? 15 : 0;
- marginBottom = margins.hasBottom() ? 15 : 0;
- marginLeft = margins.hasLeft() ? 15 : 0;
- }
-
- private int detectSpacingSize() {
- // TODO Auto-generated method stub
- return 15;
- }
-
- public boolean hasChildComponent(Widget component) {
- if (paintableToCellMap.containsKey(component)) {
- return true;
- } else {
- return false;
- }
- }
-
- public void replaceChildComponent(Widget oldComponent, Widget newComponent) {
- // TODO Auto-generated method stub
-
- }
-
- public void updateCaption(Paintable component, UIDL uidl) {
- AbsoluteGridCell cell = (AbsoluteGridCell) paintableToCellMap
- .get(component);
- Caption c = cell.getCaption();
- if (c == null) {
- c = new Caption(component, client);
- cell.setCaption(c);
- }
- c.updateCaption(uidl);
- }
-
-}