From: Jouni Koivuviita Date: Tue, 18 Dec 2007 08:41:04 +0000 (+0000) Subject: Proper implementation of alignments in IOrderedLayout + small fixes to css-files... X-Git-Tag: 6.7.0.beta1~5227 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=3b5319487e4f6d2dd0eddab5f07adb92025197bc;p=vaadin-framework.git Proper implementation of alignments in IOrderedLayout + small fixes to css-files and some typos corrected svn changeset:3251/svn branch:trunk --- diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/IAccordion.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/IAccordion.java index e19f9eb674..ed2831bc38 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IAccordion.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IAccordion.java @@ -80,9 +80,9 @@ public class IAccordion extends ITabsheetBase implements public void onSelectTab(StackItem item) { final int index = stack.indexOf(item); if (index != activeTabIndex && !disabled && !readonly) { - if (getSelectedStack() == null) - return; - getSelectedStack().close(); + if (getSelectedStack() != null) { + getSelectedStack().close(); + } addStyleDependentName("loading"); // run updating variables in deferred command to bypass some FF // optimization issues @@ -113,20 +113,22 @@ public class IAccordion extends ITabsheetBase implements return; if (height != null && height != "") { - // Detach visible widget from document flow for a while to calculate used height correctly + // Detach visible widget from document flow for a while to calculate + // used height correctly Widget w = item.getContent().getContainedWidget(); String originalPositioning = ""; - if(w != null) { - originalPositioning = DOM.getStyleAttribute(w.getElement(), "position"); + if (w != null) { + originalPositioning = DOM.getStyleAttribute(w.getElement(), + "position"); DOM.setStyleAttribute(w.getElement(), "visibility", "hidden"); DOM.setStyleAttribute(w.getElement(), "position", "absolute"); } item.getContent().setHeight(""); - // Calculate target height super.setHeight(height); - int targetHeight = getOffsetHeight(); + int targetHeight = DOM.getElementPropertyInt(DOM + .getParent(getElement()), "offsetHeight"); super.setHeight(""); // Calculate used height @@ -136,10 +138,11 @@ public class IAccordion extends ITabsheetBase implements if (h < 0) h = 0; item.getContent().setHeight(h + "px"); - + // Put widget back into normal flow - if(w != null) { - DOM.setStyleAttribute(w.getElement(), "position", originalPositioning); + if (w != null) { + DOM.setStyleAttribute(w.getElement(), "position", + originalPositioning); DOM.setStyleAttribute(w.getElement(), "visibility", ""); } } else { @@ -232,7 +235,7 @@ public class IAccordion extends ITabsheetBase implements protected class StackContent extends UIObject { private Widget widget; - + protected StackContent() { setElement(DOM.createDiv()); setVisible(false); @@ -259,7 +262,7 @@ public class IAccordion extends ITabsheetBase implements (content).updateFromUIDL(contentUidl, client); widget = (Widget) content; } - + public Widget getContainedWidget() { return widget; } diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/IExpandLayout.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/IExpandLayout.java index 6f9290c7bc..c80816ba5f 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IExpandLayout.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IExpandLayout.java @@ -253,7 +253,7 @@ public class IExpandLayout extends ComplexPanel implements } } - public Element getContainerElementu() { + public Element getContainerElement() { if (td == null) { return super.getContainerElement(); } else { diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/IOrderedLayout.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/IOrderedLayout.java index 3a4b5d6f89..85ae828ce6 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IOrderedLayout.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IOrderedLayout.java @@ -223,29 +223,15 @@ public abstract class IOrderedLayout extends ComplexPanel implements Container { final Caption c = (Caption) w; // captions go into same container element as their // owners - final Element container = DOM.getParent(((UIObject) c.getOwner()) - .getElement()); + final Element container = getWidgetWrapperFor((Widget) c.getOwner()) + .getContainerElement(); final Element captionContainer = DOM.createDiv(); DOM.insertChild(container, captionContainer, 0); insert(w, captionContainer, beforeIndex, false); } else { - final Element wrapper = createWidgetWrappper(); - DOM.insertChild(childContainer, wrapper, beforeIndex); - insert(w, wrapper, beforeIndex, false); - } - } - - /** - * creates an Element which will contain child widget - */ - protected Element createWidgetWrappper() { - switch (orientationMode) { - case ORIENTATION_HORIZONTAL: - final Element td = DOM.createTD(); - return td; - default: - final Element div = DOM.createDiv(); - return div; + WidgetWrapper wr = new WidgetWrapper(); + DOM.insertChild(childContainer, wr.getElement(), beforeIndex); + insert(w, wr.getContainerElement(), beforeIndex, false); } } @@ -282,9 +268,9 @@ public abstract class IOrderedLayout extends ComplexPanel implements Container { } public void add(Widget w) { - final Element wrapper = createWidgetWrappper(); - DOM.appendChild(childContainer, wrapper); - super.add(w, wrapper); + WidgetWrapper wr = new WidgetWrapper(); + DOM.appendChild(childContainer, wr.getElement()); + super.add(w, wr.getContainerElement()); } public boolean remove(int index) { @@ -292,7 +278,7 @@ public abstract class IOrderedLayout extends ComplexPanel implements Container { } public boolean remove(Widget w) { - final Element wrapper = DOM.getParent(w.getElement()); + final Element wrapper = getWidgetWrapperFor(w).getElement(); final boolean removed = super.remove(w); if (removed) { if (!(w instanceof Caption)) { @@ -343,40 +329,126 @@ public abstract class IOrderedLayout extends ComplexPanel implements Container { final AlignmentInfo ai = new AlignmentInfo( alignments[alignmentIndex++]); - final Element wrapper = DOM.getParent(((Widget) it.next()) - .getElement()); - if (Util.isIE()) { - DOM.setElementAttribute(wrapper, "vAlign", ai - .getVerticalAlignment()); + final WidgetWrapper wr = getWidgetWrapperFor((Widget) it.next()); + wr.setAlignment(ai.getVerticalAlignment(), ai + .getHorizontalAlignment()); + + // Handle spacing in this loop as well + if (first) { + wr.setSpacingEnabled(false); + first = false; } else { - DOM.setStyleAttribute(wrapper, "verticalAlign", ai - .getVerticalAlignment()); + wr.setSpacingEnabled(hasComponentSpacing); } - // TODO use one-cell table to implement horizontal alignments - if (Util.isIE()) { - DOM.setElementAttribute(wrapper, "align", ai - .getHorizontalAlignment()); + } + } + + /** + * WidgetWrapper classe. Helper classe for spacing and alignment handling. + * + */ + class WidgetWrapper extends UIObject { + + Element td; + + public WidgetWrapper() { + if (orientationMode == ORIENTATION_VERTICAL) { + setElement(DOM.createDiv()); + // Apply 'hasLayout' for IE (needed to get accurate dimension + // calculations) + if (Util.isIE()) { + DOM.setStyleAttribute(getElement(), "zoom", "1"); + } } else { - DOM.setStyleAttribute(wrapper, "textAlign", ai - .getHorizontalAlignment()); + setElement(DOM.createTD()); } + } - if (first) { - setSpacingEnabled(wrapper, false); - first = false; + public WidgetWrapper(Element element) { + if (DOM.getElementProperty(element, "className").equals("i_align")) { + td = element; + setElement(DOM.getParent(DOM.getParent(DOM.getParent(DOM + .getParent(td))))); } else { - setSpacingEnabled(wrapper, hasComponentSpacing); + setElement(element); } } + + Element getContainerElement() { + if (td != null) { + return td; + } else { + return getElement(); + } + } + + void setAlignment(String verticalAlignment, String horizontalAlignment) { + + // Set vertical alignment + if (Util.isIE()) { + DOM.setElementAttribute(getElement(), "vAlign", + verticalAlignment); + } else { + DOM.setStyleAttribute(getElement(), "verticalAlign", + verticalAlignment); + } + + // Set horizontal alignment + if (Util.isIE()) { + DOM.setElementAttribute(getElement(), "align", + horizontalAlignment); + } else if (!horizontalAlignment.equals("left")) { + // use one-cell table to implement horizontal alignments, only + // for values other than "left" (which is default) + // build one cell table + if (td == null) { + final Element table = DOM.createTable(); + final Element tBody = DOM.createTBody(); + final Element tr = DOM.createTR(); + td = DOM.createTD(); + DOM.appendChild(table, tBody); + DOM.appendChild(tBody, tr); + DOM.appendChild(tr, td); + DOM.setElementAttribute(table, "cellpadding", "0"); + DOM.setElementAttribute(table, "cellspacing", "0"); + DOM.setStyleAttribute(table, "width", "100%"); + // use className for identification + DOM.setElementProperty(td, "className", "i_align"); + // move possible content to cell + while (DOM.getChildCount(getElement()) > 0) { + final Element content = DOM.getFirstChild(getElement()); + if (content != null) { + DOM.removeChild(getElement(), content); + DOM.appendChild(td, content); + } + } + DOM.appendChild(getElement(), table); + } + // set alignment + DOM.setElementAttribute(td, "align", horizontalAlignment); + } + } + + void setSpacingEnabled(boolean b) { + setStyleName( + getElement(), + CLASSNAME + + "-" + + (orientationMode == ORIENTATION_HORIZONTAL ? StyleConstants.HORIZONTAL_SPACING + : StyleConstants.VERTICAL_SPACING), b); + } + } - private void setSpacingEnabled(Element e, boolean b) { - setStyleName( - e, - CLASSNAME - + "-" - + (orientationMode == ORIENTATION_HORIZONTAL ? StyleConstants.HORIZONTAL_SPACING - : StyleConstants.VERTICAL_SPACING), b); + /** + * Returns given widgets WidgetWrapper + * + * @param child + * @return + */ + public WidgetWrapper getWidgetWrapperFor(Widget child) { + final Element containerElement = DOM.getParent(child.getElement()); + return new WidgetWrapper(containerElement); } } diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/ITabsheetBase.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/ITabsheetBase.java index c3cf0e6a56..ed1083eabe 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/ITabsheetBase.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/ITabsheetBase.java @@ -25,9 +25,9 @@ abstract class ITabsheetBase extends FlowPanel implements Paintable { public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - // Ensure correct implementation and let ApplicationConnection handle - // component caption - if (client.updateComponent(this, uidl, true)) { + // Ensure correct implementation and don't let ApplicationConnection + // handle component caption + if (client.updateComponent(this, uidl, false)) { return; } diff --git a/src/com/itmill/toolkit/terminal/gwt/public/default/accordion/accordion.css b/src/com/itmill/toolkit/terminal/gwt/public/default/accordion/accordion.css index bb18b70e50..b4e728963e 100644 --- a/src/com/itmill/toolkit/terminal/gwt/public/default/accordion/accordion.css +++ b/src/com/itmill/toolkit/terminal/gwt/public/default/accordion/accordion.css @@ -1,6 +1,7 @@ .i-accordion { outline: none; overflow: hidden; + text-align: left /* Force default alignment */ } .i-accordion-item-caption { diff --git a/src/com/itmill/toolkit/terminal/gwt/public/default/caption/caption.css b/src/com/itmill/toolkit/terminal/gwt/public/default/caption/caption.css index 4ffff80769..ddea358265 100644 --- a/src/com/itmill/toolkit/terminal/gwt/public/default/caption/caption.css +++ b/src/com/itmill/toolkit/terminal/gwt/public/default/caption/caption.css @@ -3,6 +3,7 @@ they aren't even handling their own caption) */ .i-captionwrapper { margin: 0.3em 0 0 0; + text-align: left /* Force default alignment */ } .i-errorindicator { diff --git a/src/com/itmill/toolkit/terminal/gwt/public/default/panel/panel.css b/src/com/itmill/toolkit/terminal/gwt/public/default/panel/panel.css index 2182009fa8..7d0dc4789b 100644 --- a/src/com/itmill/toolkit/terminal/gwt/public/default/panel/panel.css +++ b/src/com/itmill/toolkit/terminal/gwt/public/default/panel/panel.css @@ -7,6 +7,7 @@ .i-panel-content-light, .i-panel-deco-light { outline: none; /* Prevent selection outline which might break layouts or cause scrollbars */ + text-align: left /* Force default alignment */ } .i-panel:before { diff --git a/src/com/itmill/toolkit/terminal/gwt/public/default/select/filterselect.css b/src/com/itmill/toolkit/terminal/gwt/public/default/select/filterselect.css index 9e92eb7d0f..bef2b160fb 100644 --- a/src/com/itmill/toolkit/terminal/gwt/public/default/select/filterselect.css +++ b/src/com/itmill/toolkit/terminal/gwt/public/default/select/filterselect.css @@ -3,6 +3,7 @@ background: transparent url(img/bg-left-filter.png) no-repeat; margin-right: 1px; white-space: nowrap; + text-align: left /* Force default alignment */ } .i-filterselect-input { diff --git a/src/com/itmill/toolkit/terminal/gwt/public/default/select/select.css b/src/com/itmill/toolkit/terminal/gwt/public/default/select/select.css index 5998c55f85..335d77277e 100644 --- a/src/com/itmill/toolkit/terminal/gwt/public/default/select/select.css +++ b/src/com/itmill/toolkit/terminal/gwt/public/default/select/select.css @@ -1,5 +1,5 @@ -.i-select { - +.i-select { + text-align: left /* Force default alignment */ } .i-select-option { diff --git a/src/com/itmill/toolkit/terminal/gwt/public/default/table/table.css b/src/com/itmill/toolkit/terminal/gwt/public/default/table/table.css index 3a437a9c0e..745a451338 100644 --- a/src/com/itmill/toolkit/terminal/gwt/public/default/table/table.css +++ b/src/com/itmill/toolkit/terminal/gwt/public/default/table/table.css @@ -1,6 +1,7 @@ .i-table { border: 1px solid #b6bbbc; overflow: hidden; + text-align: left /* Force default alignment */ } .i-table.table-inline { @@ -162,14 +163,16 @@ /* disabled row in column selector */ .i-off { font-style: italic; + color: } /* IE specific styles */ * html .i-table-scrollposition { background: transparent; - /* We need two different filters because we cannot be sure of the context + /* We need multiple different filters because we cannot be sure of the context the browser is currently in (i.e. with ending slash or without). */ + filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src="../../ITMILL/widgetsets/com.itmill.toolkit.terminal.gwt.DefaultWidgetSet/default/table/img/scroll-position-bg.png", sizingMethod="scale"); filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src="../ITMILL/widgetsets/com.itmill.toolkit.terminal.gwt.DefaultWidgetSet/default/table/img/scroll-position-bg.png", sizingMethod="scale"); filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src="ITMILL/widgetsets/com.itmill.toolkit.terminal.gwt.DefaultWidgetSet/default/table/img/scroll-position-bg.png", sizingMethod="scale"); } \ No newline at end of file diff --git a/src/com/itmill/toolkit/terminal/gwt/public/default/tabsheet/tabsheet.css b/src/com/itmill/toolkit/terminal/gwt/public/default/tabsheet/tabsheet.css index 3c6bf001a9..1aa1a874f5 100644 --- a/src/com/itmill/toolkit/terminal/gwt/public/default/tabsheet/tabsheet.css +++ b/src/com/itmill/toolkit/terminal/gwt/public/default/tabsheet/tabsheet.css @@ -2,6 +2,7 @@ .i-tabsheet-content, .i-tabsheet-deco { outline: none; /* Prevent selection outline which might break layouts or cause scrollbars */ + text-align: left /* Force default alignment */ } diff --git a/src/com/itmill/toolkit/terminal/gwt/public/default/textfield/textfield.css b/src/com/itmill/toolkit/terminal/gwt/public/default/textfield/textfield.css index f567b537c9..10aa9811f4 100644 --- a/src/com/itmill/toolkit/terminal/gwt/public/default/textfield/textfield.css +++ b/src/com/itmill/toolkit/terminal/gwt/public/default/textfield/textfield.css @@ -8,6 +8,7 @@ margin: 0; font-size: 13px; height: 18px; + text-align: left /* Force default alignment */ } .i-textarea { diff --git a/src/com/itmill/toolkit/terminal/gwt/public/default/tree/tree.css b/src/com/itmill/toolkit/terminal/gwt/public/default/tree/tree.css index f627e082c3..f905658f63 100644 --- a/src/com/itmill/toolkit/terminal/gwt/public/default/tree/tree.css +++ b/src/com/itmill/toolkit/terminal/gwt/public/default/tree/tree.css @@ -1,3 +1,7 @@ +.i-tree { + text-align: left /* Force default alignment */ +} + .i-tree-node { background: transparent url(img/collapsed.png) no-repeat 2px 1px; } diff --git a/src/com/itmill/toolkit/ui/OrderedLayout.java b/src/com/itmill/toolkit/ui/OrderedLayout.java index 55eac04fce..e720caf619 100644 --- a/src/com/itmill/toolkit/ui/OrderedLayout.java +++ b/src/com/itmill/toolkit/ui/OrderedLayout.java @@ -320,6 +320,7 @@ public class OrderedLayout extends AbstractLayout { int horizontalAlignment, int verticalAlignment) { componentToAlignment.put(childComponent, new Integer( horizontalAlignment + verticalAlignment)); + requestRepaint(); } public int getComponentAlignment(Component childComponent) {