From: Matti Tahvonen Date: Thu, 5 Jun 2008 15:18:03 +0000 (+0000) Subject: #1572 : test case and margins X-Git-Tag: 6.7.0.beta1~4656 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=0351f26c187e34eee664425b10ff5e95962dfd0f;p=vaadin-framework.git #1572 : test case and margins svn changeset:4767/svn branch:trunk --- diff --git a/WebContent/ITMILL/themes/default/gridlayout/gridlayout.css b/WebContent/ITMILL/themes/default/gridlayout/gridlayout.css new file mode 100644 index 0000000000..a4634c1e1e --- /dev/null +++ b/WebContent/ITMILL/themes/default/gridlayout/gridlayout.css @@ -0,0 +1,12 @@ +.i-gridlayout-margin-top { + padding-top: 15px; +} +.i-gridlayout-margin-bottom { + padding-bottom: 15px; +} +.i-gridlayout-margin-left { + padding-left: 18px; +} +.i-gridlayout-margin-right { + padding-right: 18px; +} diff --git a/WebContent/ITMILL/themes/default/styles.css b/WebContent/ITMILL/themes/default/styles.css index 86b17c829f..92d2005ca3 100644 --- a/WebContent/ITMILL/themes/default/styles.css +++ b/WebContent/ITMILL/themes/default/styles.css @@ -499,6 +499,18 @@ input.i-modified, * html .i-form-errormessage { height: 20px } +.i-gridlayout-margin-top { + padding-top: 15px; +} +.i-gridlayout-margin-bottom { + padding-bottom: 15px; +} +.i-gridlayout-margin-left { + padding-left: 18px; +} +.i-gridlayout-margin-right { + padding-right: 18px; +} .i-Notification { font-family: "Trebuchet MS", geneva, helvetica, arial, tahoma, verdana, sans-serif; diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/IGridLayout.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/IGridLayout.java index f557ae5b51..e238bbd685 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IGridLayout.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IGridLayout.java @@ -9,9 +9,11 @@ import java.util.HashMap; import java.util.Iterator; import com.google.gwt.user.client.DOM; +import com.google.gwt.user.client.Element; import com.google.gwt.user.client.ui.FlexTable; import com.google.gwt.user.client.ui.HasHorizontalAlignment; import com.google.gwt.user.client.ui.HasVerticalAlignment; +import com.google.gwt.user.client.ui.SimplePanel; import com.google.gwt.user.client.ui.Widget; import com.google.gwt.user.client.ui.HasHorizontalAlignment.HorizontalAlignmentConstant; import com.google.gwt.user.client.ui.HasVerticalAlignment.VerticalAlignmentConstant; @@ -19,18 +21,19 @@ import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection; import com.itmill.toolkit.terminal.gwt.client.CaptionWrapper; import com.itmill.toolkit.terminal.gwt.client.Container; import com.itmill.toolkit.terminal.gwt.client.Paintable; +import com.itmill.toolkit.terminal.gwt.client.StyleConstants; import com.itmill.toolkit.terminal.gwt.client.UIDL; -public class IGridLayout extends FlexTable implements Paintable, Container { +public class IGridLayout extends SimplePanel implements Paintable, Container { public static final String CLASSNAME = "i-gridlayout"; - /** Widget to captionwrapper map */ - private final HashMap widgetToCaptionWrapper = new HashMap(); + private Grid grid = new Grid(); public IGridLayout() { super(); setStyleName(CLASSNAME); + setWidget(grid); } public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { @@ -39,127 +42,171 @@ public class IGridLayout extends FlexTable implements Paintable, Container { return; } - if (uidl.hasAttribute("caption")) { - setTitle(uidl.getStringAttribute("caption")); - } - int row = 0, column = 0; + final MarginInfo margins = new MarginInfo(uidl + .getIntAttribute("margins")); + + // 1572 + Element margin = getElement(); + setStyleName(margin, CLASSNAME + "-" + StyleConstants.MARGIN_TOP, + margins.hasTop()); + setStyleName(margin, CLASSNAME + "-" + StyleConstants.MARGIN_RIGHT, + margins.hasRight()); + setStyleName(margin, CLASSNAME + "-" + StyleConstants.MARGIN_BOTTOM, + margins.hasBottom()); + setStyleName(margin, CLASSNAME + "-" + StyleConstants.MARGIN_LEFT, + margins.hasLeft()); + + grid.updateFromUIDL(uidl, client); + } + + public boolean hasChildComponent(Widget component) { + return grid.hasChildComponent(component); + } + + public void replaceChildComponent(Widget oldComponent, Widget newComponent) { + grid.replaceChildComponent(oldComponent, newComponent); + } + + public void updateCaption(Paintable component, UIDL uidl) { + grid.updateCaption(component, uidl); + } + + public class Grid extends FlexTable implements Paintable, Container { - final ArrayList oldWidgetWrappers = new ArrayList(); - for (final Iterator iterator = iterator(); iterator.hasNext();) { - oldWidgetWrappers.add(iterator.next()); + /** Widget to captionwrapper map */ + private final HashMap widgetToCaptionWrapper = new HashMap(); + + public Grid() { + super(); + setStyleName(CLASSNAME); } - clear(); - - final int[] alignments = uidl.getIntArrayAttribute("alignments"); - int alignmentIndex = 0; - - for (final Iterator i = uidl.getChildIterator(); i.hasNext();) { - final UIDL r = (UIDL) i.next(); - if ("gr".equals(r.getTag())) { - column = 0; - for (final Iterator j = r.getChildIterator(); j.hasNext();) { - final UIDL c = (UIDL) j.next(); - if ("gc".equals(c.getTag())) { - prepareCell(row, column); - - // Set cell width - int w; - if (c.hasAttribute("w")) { - w = c.getIntAttribute("w"); - } else { - w = 1; - } - AlignmentInfo alignmentInfo = new AlignmentInfo( - alignments[alignmentIndex++]); - - VerticalAlignmentConstant va; - if (alignmentInfo.isBottom()) { - va = HasVerticalAlignment.ALIGN_BOTTOM; - } else if (alignmentInfo.isTop()) { - va = HasVerticalAlignment.ALIGN_TOP; - } else { - va = HasVerticalAlignment.ALIGN_MIDDLE; - } - HorizontalAlignmentConstant ha; + public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - if (alignmentInfo.isLeft()) { - ha = HasHorizontalAlignment.ALIGN_LEFT; - } else if (alignmentInfo.isHorizontalCenter()) { - ha = HasHorizontalAlignment.ALIGN_CENTER; - } else { - ha = HasHorizontalAlignment.ALIGN_RIGHT; - } + int row = 0, column = 0; - getCellFormatter().setAlignment(row, column, ha, va); + final ArrayList oldWidgetWrappers = new ArrayList(); + for (final Iterator iterator = iterator(); iterator.hasNext();) { + oldWidgetWrappers.add(iterator.next()); + } + clear(); + + final int[] alignments = uidl.getIntArrayAttribute("alignments"); + int alignmentIndex = 0; + + for (final Iterator i = uidl.getChildIterator(); i.hasNext();) { + final UIDL r = (UIDL) i.next(); + if ("gr".equals(r.getTag())) { + column = 0; + for (final Iterator j = r.getChildIterator(); j.hasNext();) { + final UIDL c = (UIDL) j.next(); + if ("gc".equals(c.getTag())) { + prepareCell(row, column); + + // Set cell width + int w; + if (c.hasAttribute("w")) { + w = c.getIntAttribute("w"); + } else { + w = 1; + } + AlignmentInfo alignmentInfo = new AlignmentInfo( + alignments[alignmentIndex++]); + + VerticalAlignmentConstant va; + if (alignmentInfo.isBottom()) { + va = HasVerticalAlignment.ALIGN_BOTTOM; + } else if (alignmentInfo.isTop()) { + va = HasVerticalAlignment.ALIGN_TOP; + } else { + va = HasVerticalAlignment.ALIGN_MIDDLE; + } - // set col span - ((FlexCellFormatter) getCellFormatter()).setColSpan( - row, column, w); + HorizontalAlignmentConstant ha; - // Set cell height - int h; - if (c.hasAttribute("h")) { - h = c.getIntAttribute("h"); - } else { - h = 1; - } - ((FlexCellFormatter) getCellFormatter()).setRowSpan( - row, column, h); - - final UIDL u = c.getChildUIDL(0); - if (u != null) { - final Paintable child = client.getPaintable(u); - CaptionWrapper wr; - if (widgetToCaptionWrapper.containsKey(child)) { - wr = (CaptionWrapper) widgetToCaptionWrapper - .get(child); - oldWidgetWrappers.remove(wr); + if (alignmentInfo.isLeft()) { + ha = HasHorizontalAlignment.ALIGN_LEFT; + } else if (alignmentInfo.isHorizontalCenter()) { + ha = HasHorizontalAlignment.ALIGN_CENTER; } else { - wr = new CaptionWrapper(child, client); - widgetToCaptionWrapper.put(child, wr); + ha = HasHorizontalAlignment.ALIGN_RIGHT; } - setWidget(row, column, wr); + getCellFormatter() + .setAlignment(row, column, ha, va); - DOM.setStyleAttribute(wr.getElement(), "textAlign", - alignmentInfo.getHorizontalAlignment()); + // set col span + ((FlexCellFormatter) getCellFormatter()) + .setColSpan(row, column, w); - if (!u.getBooleanAttribute("cached")) { - child.updateFromUIDL(u, client); + // Set cell height + int h; + if (c.hasAttribute("h")) { + h = c.getIntAttribute("h"); + } else { + h = 1; } + ((FlexCellFormatter) getCellFormatter()) + .setRowSpan(row, column, h); + + final UIDL u = c.getChildUIDL(0); + if (u != null) { + final Paintable child = client.getPaintable(u); + CaptionWrapper wr; + if (widgetToCaptionWrapper.containsKey(child)) { + wr = (CaptionWrapper) widgetToCaptionWrapper + .get(child); + oldWidgetWrappers.remove(wr); + } else { + wr = new CaptionWrapper(child, client); + widgetToCaptionWrapper.put(child, wr); + } + + setWidget(row, column, wr); + + DOM.setStyleAttribute(wr.getElement(), + "textAlign", alignmentInfo + .getHorizontalAlignment()); + + if (!u.getBooleanAttribute("cached")) { + child.updateFromUIDL(u, client); + } + } + column += w; } - column += w; } + row++; } - row++; } - } - // loop oldWidgetWrappers that where not re-attached and unregister them - for (final Iterator it = oldWidgetWrappers.iterator(); it.hasNext();) { - final CaptionWrapper w = (CaptionWrapper) it.next(); - client.unregisterPaintable(w.getPaintable()); - widgetToCaptionWrapper.remove(w.getPaintable()); + // loop oldWidgetWrappers that where not re-attached and unregister + // them + for (final Iterator it = oldWidgetWrappers.iterator(); it.hasNext();) { + final CaptionWrapper w = (CaptionWrapper) it.next(); + client.unregisterPaintable(w.getPaintable()); + widgetToCaptionWrapper.remove(w.getPaintable()); + } } - } - public boolean hasChildComponent(Widget component) { - if (widgetToCaptionWrapper.containsKey(component)) { - return true; + public boolean hasChildComponent(Widget component) { + if (widgetToCaptionWrapper.containsKey(component)) { + return true; + } + return false; } - return false; - } - public void replaceChildComponent(Widget oldComponent, Widget newComponent) { - // TODO Auto-generated method stub + public void replaceChildComponent(Widget oldComponent, + Widget newComponent) { + // TODO Auto-generated method stub - } + } + + public void updateCaption(Paintable component, UIDL uidl) { + final CaptionWrapper wrapper = (CaptionWrapper) widgetToCaptionWrapper + .get(component); + wrapper.updateCaption(uidl); + } - public void updateCaption(Paintable component, UIDL uidl) { - final CaptionWrapper wrapper = (CaptionWrapper) widgetToCaptionWrapper - .get(component); - wrapper.updateCaption(uidl); } } diff --git a/src/com/itmill/toolkit/tests/tickets/Ticket1572.java b/src/com/itmill/toolkit/tests/tickets/Ticket1572.java new file mode 100644 index 0000000000..4f0791a4e0 --- /dev/null +++ b/src/com/itmill/toolkit/tests/tickets/Ticket1572.java @@ -0,0 +1,108 @@ +package com.itmill.toolkit.tests.tickets; + +import com.itmill.toolkit.ui.Button; +import com.itmill.toolkit.ui.GridLayout; +import com.itmill.toolkit.ui.Label; +import com.itmill.toolkit.ui.OrderedLayout; +import com.itmill.toolkit.ui.Panel; +import com.itmill.toolkit.ui.Window; +import com.itmill.toolkit.ui.Button.ClickEvent; + +public class Ticket1572 extends com.itmill.toolkit.Application { + + private Label state; + private GridLayout gl; + private Label spacingstate; + + public void init() { + + final Window main = new Window(getClass().getName().substring( + getClass().getName().lastIndexOf(".") + 1)); + setMainWindow(main); + + Panel p = new Panel("Test wrapper for gridlayout margin/spacing"); + + p.setLayout(new OrderedLayout(OrderedLayout.ORIENTATION_HORIZONTAL)); + + gl = new GridLayout(3, 3); + gl.setMargin(true); + for (int i = 0; i < 3 * 3; i++) { + gl.addComponent(new Button("test")); + } + p.addComponent(gl); + p.addComponent(new Label("| next component")); + + Button b = new Button("next margin state"); + b.addListener(new Button.ClickListener() { + public void buttonClick(ClickEvent event) { + nextMarginState(); + } + + }); + + state = new Label(); + state.setCaption("Current margin state:"); + main.addComponent(state); + main.addComponent(b); + + Button b2 = new Button("next spacing state"); + b.addListener(new Button.ClickListener() { + public void buttonClick(ClickEvent event) { + nextSpacingState(); + } + + }); + + spacingstate = new Label(); + spacingstate.setCaption("Current Spacing State:"); + main.addComponent(spacingstate); + main.addComponent(b2); + + main.addComponent(p); + + nextMarginState(); + nextSpacingState(); + + } + + private int stateCounter = -1; + + private void nextMarginState() { + stateCounter++; + switch (stateCounter) { + case 0: + gl.setMargin(false); + state.setValue("Margin off"); + break; + case 1: + gl.setMargin(true); + state.setValue("Margin on"); + break; + case 2: + gl.setMargin(true, false, false, false); + state.setValue("Margin top"); + break; + case 3: + gl.setMargin(false, true, false, false); + state.setValue("Margin right"); + break; + case 4: + gl.setMargin(false, false, true, false); + state.setValue("Margin bottom"); + break; + case 5: + gl.setMargin(false, false, false, true); + state.setValue("Margin left"); + break; + default: + stateCounter = -1; + nextMarginState(); + break; + } + } + + private void nextSpacingState() { + spacingstate.setValue(" // TODO Auto-generated method stub"); + } + +}