diff options
author | Artur Signell <artur@vaadin.com> | 2012-08-20 19:29:04 +0300 |
---|---|---|
committer | Artur Signell <artur@vaadin.com> | 2012-08-22 13:58:50 +0300 |
commit | 667ef9c144bf3522100e5c8eac4d76a3c4faf65b (patch) | |
tree | 186994e13b55cda64fc5df96b5464d0905a8006b | |
parent | 514bffe7a6aa2c599ab9f4ba239295d63f229125 (diff) | |
download | vaadin-framework-667ef9c144bf3522100e5c8eac4d76a3c4faf65b.tar.gz vaadin-framework-667ef9c144bf3522100e5c8eac4d76a3c4faf65b.zip |
Refactored margin handlers (#8292)
Only layouts actually supporting margins now implement MarginHandler
CssLayout should be simplified before 7.0.0 so margin support was removed. GridLayout, VerticalLayout and HorizontalLayout were the only other layouts which actually supported margin.
MarginInfo is now passed directly in the state.
32 files changed, 165 insertions, 202 deletions
diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/csslayout/CssLayoutConnector.java b/client/src/com/vaadin/terminal/gwt/client/ui/csslayout/CssLayoutConnector.java index 47c2049a67..2e51d717a4 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ui/csslayout/CssLayoutConnector.java +++ b/client/src/com/vaadin/terminal/gwt/client/ui/csslayout/CssLayoutConnector.java @@ -23,7 +23,6 @@ import com.google.gwt.user.client.Element; import com.google.gwt.user.client.ui.Widget; import com.vaadin.shared.ui.Connect; import com.vaadin.shared.ui.LayoutClickRpc; -import com.vaadin.shared.ui.VMarginInfo; import com.vaadin.shared.ui.csslayout.CssLayoutServerRpc; import com.vaadin.shared.ui.csslayout.CssLayoutState; import com.vaadin.terminal.gwt.client.BrowserInfo; @@ -75,9 +74,6 @@ public class CssLayoutConnector extends AbstractLayoutConnector { public void onStateChanged(StateChangeEvent stateChangeEvent) { super.onStateChanged(stateChangeEvent); - getWidget().setMarginStyles( - new VMarginInfo(getState().getMarginsBitmask())); - for (ComponentConnector child : getChildComponents()) { if (!getState().getChildCss().containsKey(child)) { continue; diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/csslayout/VCssLayout.java b/client/src/com/vaadin/terminal/gwt/client/ui/csslayout/VCssLayout.java index 813e95e3ed..e66b1c4208 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ui/csslayout/VCssLayout.java +++ b/client/src/com/vaadin/terminal/gwt/client/ui/csslayout/VCssLayout.java @@ -21,8 +21,6 @@ import com.google.gwt.user.client.Element; import com.google.gwt.user.client.ui.FlowPanel; import com.google.gwt.user.client.ui.SimplePanel; import com.google.gwt.user.client.ui.Widget; -import com.vaadin.shared.ui.VMarginInfo; -import com.vaadin.terminal.gwt.client.StyleConstants; public class VCssLayout extends SimplePanel { public static final String TAGNAME = "csslayout"; @@ -64,21 +62,4 @@ public class VCssLayout extends SimplePanel { } - /** - * Sets CSS classes for margin based on the given parameters. - * - * @param margins - * A {@link VMarginInfo} object that provides info on - * top/left/bottom/right margins - */ - protected void setMarginStyles(VMarginInfo margins) { - setStyleName(margin, VCssLayout.CLASSNAME + "-" - + StyleConstants.MARGIN_TOP, margins.hasTop()); - setStyleName(margin, VCssLayout.CLASSNAME + "-" - + StyleConstants.MARGIN_RIGHT, margins.hasRight()); - setStyleName(margin, VCssLayout.CLASSNAME + "-" - + StyleConstants.MARGIN_BOTTOM, margins.hasBottom()); - setStyleName(margin, VCssLayout.CLASSNAME + "-" - + StyleConstants.MARGIN_LEFT, margins.hasLeft()); - } } diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/formlayout/FormLayoutConnector.java b/client/src/com/vaadin/terminal/gwt/client/ui/formlayout/FormLayoutConnector.java index 7d5edfadf5..cbe06244af 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ui/formlayout/FormLayoutConnector.java +++ b/client/src/com/vaadin/terminal/gwt/client/ui/formlayout/FormLayoutConnector.java @@ -18,7 +18,7 @@ package com.vaadin.terminal.gwt.client.ui.formlayout; import com.google.gwt.dom.client.Element; import com.google.gwt.user.client.ui.Widget; import com.vaadin.shared.ui.Connect; -import com.vaadin.shared.ui.VMarginInfo; +import com.vaadin.shared.ui.MarginInfo; import com.vaadin.shared.ui.orderedlayout.AbstractOrderedLayoutState; import com.vaadin.terminal.gwt.client.ComponentConnector; import com.vaadin.terminal.gwt.client.ConnectorHierarchyChangeEvent; @@ -46,7 +46,7 @@ public class FormLayoutConnector extends AbstractLayoutConnector { VFormLayoutTable formLayoutTable = getWidget().table; - formLayoutTable.setMargins(new VMarginInfo(getState() + formLayoutTable.setMargins(new MarginInfo(getState() .getMarginsBitmask())); formLayoutTable.setSpacing(getState().isSpacing()); diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/formlayout/VFormLayout.java b/client/src/com/vaadin/terminal/gwt/client/ui/formlayout/VFormLayout.java index d3ce6f3d3f..7f211aaf9c 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ui/formlayout/VFormLayout.java +++ b/client/src/com/vaadin/terminal/gwt/client/ui/formlayout/VFormLayout.java @@ -29,7 +29,7 @@ import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.SimplePanel; import com.google.gwt.user.client.ui.Widget; import com.vaadin.shared.ComponentState; -import com.vaadin.shared.ui.VMarginInfo; +import com.vaadin.shared.ui.MarginInfo; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.BrowserInfo; import com.vaadin.terminal.gwt.client.ComponentConnector; @@ -112,7 +112,7 @@ public class VFormLayout extends SimplePanel { } } - public void setMargins(VMarginInfo margins) { + public void setMargins(MarginInfo margins) { Element margin = getElement(); setStyleName(margin, CLASSNAME + "-" + StyleConstants.MARGIN_TOP, margins.hasTop()); diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/gridlayout/GridLayoutConnector.java b/client/src/com/vaadin/terminal/gwt/client/ui/gridlayout/GridLayoutConnector.java index 520afb778d..9a2732e408 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ui/gridlayout/GridLayoutConnector.java +++ b/client/src/com/vaadin/terminal/gwt/client/ui/gridlayout/GridLayoutConnector.java @@ -22,7 +22,7 @@ import com.google.gwt.user.client.ui.Widget; import com.vaadin.shared.ui.AlignmentInfo; import com.vaadin.shared.ui.Connect; import com.vaadin.shared.ui.LayoutClickRpc; -import com.vaadin.shared.ui.VMarginInfo; +import com.vaadin.shared.ui.MarginInfo; import com.vaadin.shared.ui.gridlayout.GridLayoutServerRpc; import com.vaadin.shared.ui.gridlayout.GridLayoutState; import com.vaadin.terminal.gwt.client.ApplicationConnection; @@ -163,7 +163,7 @@ public class GridLayoutConnector extends AbstractComponentContainerConnector layout.colExpandRatioArray = uidl.getIntArrayAttribute("colExpand"); layout.rowExpandRatioArray = uidl.getIntArrayAttribute("rowExpand"); - layout.updateMarginStyleNames(new VMarginInfo(getState() + layout.updateMarginStyleNames(new MarginInfo(getState() .getMarginsBitmask())); layout.updateSpacingStyleName(getState().isSpacing()); diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/gridlayout/VGridLayout.java b/client/src/com/vaadin/terminal/gwt/client/ui/gridlayout/VGridLayout.java index 25d7de6ee6..ef44964da7 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ui/gridlayout/VGridLayout.java +++ b/client/src/com/vaadin/terminal/gwt/client/ui/gridlayout/VGridLayout.java @@ -29,7 +29,7 @@ import com.google.gwt.user.client.Element; import com.google.gwt.user.client.ui.ComplexPanel; import com.google.gwt.user.client.ui.Widget; import com.vaadin.shared.ui.AlignmentInfo; -import com.vaadin.shared.ui.VMarginInfo; +import com.vaadin.shared.ui.MarginInfo; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.ComponentConnector; import com.vaadin.terminal.gwt.client.ConnectorMap; @@ -677,7 +677,7 @@ public class VGridLayout extends ComplexPanel { } } - void updateMarginStyleNames(VMarginInfo marginInfo) { + void updateMarginStyleNames(MarginInfo marginInfo) { togglePrefixedStyleName("margin-top", marginInfo.hasTop()); togglePrefixedStyleName("margin-right", marginInfo.hasRight()); togglePrefixedStyleName("margin-bottom", marginInfo.hasBottom()); diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java b/client/src/com/vaadin/terminal/gwt/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java index 5da01bf127..122547ddb4 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java +++ b/client/src/com/vaadin/terminal/gwt/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java @@ -23,7 +23,7 @@ import com.google.gwt.user.client.Element; import com.google.gwt.user.client.ui.Widget; import com.vaadin.shared.ui.AlignmentInfo; import com.vaadin.shared.ui.LayoutClickRpc; -import com.vaadin.shared.ui.VMarginInfo; +import com.vaadin.shared.ui.MarginInfo; import com.vaadin.shared.ui.orderedlayout.AbstractOrderedLayoutServerRpc; import com.vaadin.shared.ui.orderedlayout.AbstractOrderedLayoutState; import com.vaadin.terminal.gwt.client.ComponentConnector; @@ -133,9 +133,8 @@ public abstract class AbstractOrderedLayoutConnector extends slot.setExpandRatio(expandRatio); } - layout.updateMarginStyleNames(new VMarginInfo(getState() + layout.updateMarginStyleNames(new MarginInfo(getState() .getMarginsBitmask())); - layout.updateSpacingStyleName(getState().isSpacing()); getLayoutManager().setNeedsLayout(this); diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/orderedlayout/VMeasuringOrderedLayout.java b/client/src/com/vaadin/terminal/gwt/client/ui/orderedlayout/VMeasuringOrderedLayout.java index ec2c4afa97..ee55bc07ba 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ui/orderedlayout/VMeasuringOrderedLayout.java +++ b/client/src/com/vaadin/terminal/gwt/client/ui/orderedlayout/VMeasuringOrderedLayout.java @@ -27,7 +27,7 @@ import com.google.gwt.user.client.Element; import com.google.gwt.user.client.ui.ComplexPanel; import com.google.gwt.user.client.ui.Widget; import com.google.gwt.user.client.ui.WidgetCollection; -import com.vaadin.shared.ui.VMarginInfo; +import com.vaadin.shared.ui.MarginInfo; import com.vaadin.terminal.gwt.client.VCaption; import com.vaadin.terminal.gwt.client.ui.layout.VLayoutSlot; @@ -75,7 +75,7 @@ public class VMeasuringOrderedLayout extends ComplexPanel { } } - void updateMarginStyleNames(VMarginInfo marginInfo) { + void updateMarginStyleNames(MarginInfo marginInfo) { togglePrefixedStyleName("margin-top", marginInfo.hasTop()); togglePrefixedStyleName("margin-right", marginInfo.hasRight()); togglePrefixedStyleName("margin-bottom", marginInfo.hasBottom()); diff --git a/server/src/com/vaadin/ui/AbstractLayout.java b/server/src/com/vaadin/ui/AbstractLayout.java index c26812f3fc..dd1d5eab12 100644 --- a/server/src/com/vaadin/ui/AbstractLayout.java +++ b/server/src/com/vaadin/ui/AbstractLayout.java @@ -17,7 +17,6 @@ package com.vaadin.ui; import com.vaadin.shared.ui.AbstractLayoutState; -import com.vaadin.ui.Layout.MarginHandler; /** * An abstract class that defines default implementation for the {@link Layout} @@ -26,62 +25,12 @@ import com.vaadin.ui.Layout.MarginHandler; * @author Vaadin Ltd. * @since 5.0 */ -@SuppressWarnings("serial") public abstract class AbstractLayout extends AbstractComponentContainer - implements Layout, MarginHandler { - - protected MarginInfo margins = new MarginInfo(false); + implements Layout { @Override public AbstractLayoutState getState() { return (AbstractLayoutState) super.getState(); } - /* - * (non-Javadoc) - * - * @see com.vaadin.ui.Layout#setMargin(boolean) - */ - @Override - public void setMargin(boolean enabled) { - margins.setMargins(enabled); - getState().setMarginsBitmask(margins.getBitMask()); - requestRepaint(); - } - - /* - * (non-Javadoc) - * - * @see com.vaadin.ui.Layout.MarginHandler#getMargin() - */ - @Override - public MarginInfo getMargin() { - return margins; - } - - /* - * (non-Javadoc) - * - * @see com.vaadin.ui.Layout.MarginHandler#setMargin(MarginInfo) - */ - @Override - public void setMargin(MarginInfo marginInfo) { - margins.setMargins(marginInfo); - getState().setMarginsBitmask(margins.getBitMask()); - requestRepaint(); - } - - /* - * (non-Javadoc) - * - * @see com.vaadin.ui.Layout#setMargin(boolean, boolean, boolean, boolean) - */ - @Override - public void setMargin(boolean topEnabled, boolean rightEnabled, - boolean bottomEnabled, boolean leftEnabled) { - margins.setMargins(topEnabled, rightEnabled, bottomEnabled, leftEnabled); - getState().setMarginsBitmask(margins.getBitMask()); - requestRepaint(); - } - } diff --git a/server/src/com/vaadin/ui/AbstractOrderedLayout.java b/server/src/com/vaadin/ui/AbstractOrderedLayout.java index a7cc780414..3ac4e76bdb 100644 --- a/server/src/com/vaadin/ui/AbstractOrderedLayout.java +++ b/server/src/com/vaadin/ui/AbstractOrderedLayout.java @@ -25,6 +25,7 @@ import com.vaadin.event.LayoutEvents.LayoutClickNotifier; import com.vaadin.shared.Connector; import com.vaadin.shared.EventId; import com.vaadin.shared.MouseEventDetails; +import com.vaadin.shared.ui.MarginInfo; import com.vaadin.shared.ui.orderedlayout.AbstractOrderedLayoutServerRpc; import com.vaadin.shared.ui.orderedlayout.AbstractOrderedLayoutState; import com.vaadin.shared.ui.orderedlayout.AbstractOrderedLayoutState.ChildComponentData; @@ -32,7 +33,8 @@ import com.vaadin.terminal.Sizeable; @SuppressWarnings("serial") public abstract class AbstractOrderedLayout extends AbstractLayout implements - Layout.AlignmentHandler, Layout.SpacingHandler, LayoutClickNotifier { + Layout.AlignmentHandler, Layout.SpacingHandler, LayoutClickNotifier, + Layout.MarginHandler { private AbstractOrderedLayoutServerRpc rpc = new AbstractOrderedLayoutServerRpc() { @@ -392,4 +394,26 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements return components.get(index); } + public void setMargin(boolean enabled) { + setMargin(new MarginInfo(enabled)); + } + + /* + * (non-Javadoc) + * + * @see com.vaadin.ui.Layout.MarginHandler#getMargin() + */ + public MarginInfo getMargin() { + return new MarginInfo(getState().getMarginsBitmask()); + } + + /* + * (non-Javadoc) + * + * @see com.vaadin.ui.Layout.MarginHandler#setMargin(MarginInfo) + */ + public void setMargin(MarginInfo marginInfo) { + getState().setMarginsBitmask(marginInfo.getBitMask()); + requestRepaint(); + } } diff --git a/server/src/com/vaadin/ui/CustomLayout.java b/server/src/com/vaadin/ui/CustomLayout.java index 2da443bfa5..d47b2f92b3 100644 --- a/server/src/com/vaadin/ui/CustomLayout.java +++ b/server/src/com/vaadin/ui/CustomLayout.java @@ -291,33 +291,6 @@ public class CustomLayout extends AbstractLayout implements Vaadin6Component { requestRepaint(); } - /** - * Although most layouts support margins, CustomLayout does not. The - * behaviour of this layout is determined almost completely by the actual - * template. - * - * @throws UnsupportedOperationException - */ - @Override - public void setMargin(boolean enabled) { - throw new UnsupportedOperationException( - "CustomLayout does not support margins."); - } - - /** - * Although most layouts support margins, CustomLayout does not. The - * behaviour of this layout is determined almost completely by the actual - * template. - * - * @throws UnsupportedOperationException - */ - @Override - public void setMargin(boolean topEnabled, boolean rightEnabled, - boolean bottomEnabled, boolean leftEnabled) { - throw new UnsupportedOperationException( - "CustomLayout does not support margins."); - } - @Override public void changeVariables(Object source, Map<String, Object> variables) { // Nothing to see here diff --git a/server/src/com/vaadin/ui/FormLayout.java b/server/src/com/vaadin/ui/FormLayout.java index c4ba4665ea..15ea478597 100644 --- a/server/src/com/vaadin/ui/FormLayout.java +++ b/server/src/com/vaadin/ui/FormLayout.java @@ -16,6 +16,8 @@ package com.vaadin.ui; +import com.vaadin.shared.ui.MarginInfo; + /** * FormLayout is used by {@link Form} to layout fields. It may also be used * separately without {@link Form}. @@ -36,7 +38,7 @@ public class FormLayout extends AbstractOrderedLayout { public FormLayout() { super(); setSpacing(true); - setMargin(true, false, true, false); + setMargin(new MarginInfo(true, false, true, false)); setWidth(100, UNITS_PERCENTAGE); } diff --git a/server/src/com/vaadin/ui/GridLayout.java b/server/src/com/vaadin/ui/GridLayout.java index 5a748c04f6..b31ab82741 100644 --- a/server/src/com/vaadin/ui/GridLayout.java +++ b/server/src/com/vaadin/ui/GridLayout.java @@ -30,6 +30,7 @@ import com.vaadin.event.LayoutEvents.LayoutClickNotifier; import com.vaadin.shared.Connector; import com.vaadin.shared.EventId; import com.vaadin.shared.MouseEventDetails; +import com.vaadin.shared.ui.MarginInfo; import com.vaadin.shared.ui.gridlayout.GridLayoutServerRpc; import com.vaadin.shared.ui.gridlayout.GridLayoutState; import com.vaadin.terminal.LegacyPaint; @@ -63,8 +64,8 @@ import com.vaadin.terminal.Vaadin6Component; */ @SuppressWarnings("serial") public class GridLayout extends AbstractLayout implements - Layout.AlignmentHandler, Layout.SpacingHandler, LayoutClickNotifier, - Vaadin6Component { + Layout.AlignmentHandler, Layout.SpacingHandler, Layout.MarginHandler, + LayoutClickNotifier, Vaadin6Component { private GridLayoutServerRpc rpc = new GridLayoutServerRpc() { @@ -1416,4 +1417,37 @@ public class GridLayout extends AbstractLayout implements LayoutClickEvent.class, listener); } + /* + * (non-Javadoc) + * + * @see com.vaadin.ui.Layout.MarginHandler#setMargin(boolean) + */ + @Override + public void setMargin(boolean enabled) { + setMargin(new MarginInfo(enabled)); + } + + /* + * (non-Javadoc) + * + * @see + * com.vaadin.ui.Layout.MarginHandler#setMargin(com.vaadin.shared.ui.MarginInfo + * ) + */ + @Override + public void setMargin(MarginInfo marginInfo) { + getState().setMarginsBitmask(marginInfo.getBitMask()); + requestRepaint(); + } + + /* + * (non-Javadoc) + * + * @see com.vaadin.ui.Layout.MarginHandler#getMargin() + */ + @Override + public MarginInfo getMargin() { + return new MarginInfo(getState().getMarginsBitmask()); + } + } diff --git a/server/src/com/vaadin/ui/Layout.java b/server/src/com/vaadin/ui/Layout.java index 6a95d23f8c..9c7cd2b477 100644 --- a/server/src/com/vaadin/ui/Layout.java +++ b/server/src/com/vaadin/ui/Layout.java @@ -18,8 +18,8 @@ package com.vaadin.ui; import java.io.Serializable; -import com.vaadin.shared.ui.VMarginInfo; import com.vaadin.shared.ui.AlignmentInfo.Bits; +import com.vaadin.shared.ui.MarginInfo; /** * Extension to the {@link ComponentContainer} interface which adds the @@ -33,30 +33,6 @@ import com.vaadin.shared.ui.AlignmentInfo.Bits; public interface Layout extends ComponentContainer, Serializable { /** - * Enable layout margins. Affects all four sides of the layout. This will - * tell the client-side implementation to leave extra space around the - * layout. The client-side implementation decides the actual amount, and it - * can vary between themes. - * - * @param enabled - */ - public void setMargin(boolean enabled); - - /** - * Enable specific layout margins. This will tell the client-side - * implementation to leave extra space around the layout in specified edges, - * clockwise from top (top, right, bottom, left). The client-side - * implementation decides the actual amount, and it can vary between themes. - * - * @param top - * @param right - * @param bottom - * @param left - */ - public void setMargin(boolean top, boolean right, boolean bottom, - boolean left); - - /** * AlignmentHandler is most commonly an advanced {@link Layout} that can * align its components. */ @@ -197,6 +173,19 @@ public interface Layout extends ComponentContainer, Serializable { * its components). */ public interface MarginHandler extends Serializable { + + /** + * Enable layout margins. Affects all four sides of the layout. This + * will tell the client-side implementation to leave extra space around + * the layout. The client-side implementation decides the actual amount, + * and it can vary between themes. + * + * @param enabled + * true if margins should be enabled on all sides, false to + * disable all margins + */ + public void setMargin(boolean enabled); + /** * Enable margins for this layout. * @@ -224,16 +213,4 @@ public interface Layout extends ComponentContainer, Serializable { public MarginInfo getMargin(); } - @SuppressWarnings("serial") - public static class MarginInfo extends VMarginInfo implements Serializable { - - public MarginInfo(boolean enabled) { - super(enabled, enabled, enabled, enabled); - } - - public MarginInfo(boolean top, boolean right, boolean bottom, - boolean left) { - super(top, right, bottom, left); - } - } } diff --git a/shared/src/com/vaadin/shared/ui/AbstractLayoutState.java b/shared/src/com/vaadin/shared/ui/AbstractLayoutState.java index 675d11d0b7..4fc865626c 100644 --- a/shared/src/com/vaadin/shared/ui/AbstractLayoutState.java +++ b/shared/src/com/vaadin/shared/ui/AbstractLayoutState.java @@ -18,14 +18,5 @@ package com.vaadin.shared.ui; import com.vaadin.shared.ComponentState; public class AbstractLayoutState extends ComponentState { - private int marginsBitmask; - - public int getMarginsBitmask() { - return marginsBitmask; - } - - public void setMarginsBitmask(int marginsBitmask) { - this.marginsBitmask = marginsBitmask; - } }
\ No newline at end of file diff --git a/shared/src/com/vaadin/shared/ui/VMarginInfo.java b/shared/src/com/vaadin/shared/ui/MarginInfo.java index 9e9e0a4bb4..21e52f258a 100644 --- a/shared/src/com/vaadin/shared/ui/VMarginInfo.java +++ b/shared/src/com/vaadin/shared/ui/MarginInfo.java @@ -18,8 +18,7 @@ package com.vaadin.shared.ui; import java.io.Serializable; -@SuppressWarnings("serial") -public class VMarginInfo implements Serializable { +public class MarginInfo implements Serializable { private static final int TOP = 1; private static final int RIGHT = 2; @@ -28,11 +27,15 @@ public class VMarginInfo implements Serializable { private int bitMask; - public VMarginInfo(int bitMask) { + public MarginInfo(boolean enabled) { + this(enabled, enabled, enabled, enabled); + } + + public MarginInfo(int bitMask) { this.bitMask = bitMask; } - public VMarginInfo(boolean top, boolean right, boolean bottom, boolean left) { + public MarginInfo(boolean top, boolean right, boolean bottom, boolean left) { setMargins(top, right, bottom, left); } @@ -44,7 +47,7 @@ public class VMarginInfo implements Serializable { bitMask += left ? LEFT : 0; } - public void setMargins(VMarginInfo marginInfo) { + public void setMargins(MarginInfo marginInfo) { bitMask = marginInfo.bitMask; } @@ -78,11 +81,11 @@ public class VMarginInfo implements Serializable { @Override public boolean equals(Object obj) { - if (!(obj instanceof VMarginInfo)) { + if (!(obj instanceof MarginInfo)) { return false; } - return ((VMarginInfo) obj).bitMask == bitMask; + return ((MarginInfo) obj).bitMask == bitMask; } @Override diff --git a/shared/src/com/vaadin/shared/ui/gridlayout/GridLayoutState.java b/shared/src/com/vaadin/shared/ui/gridlayout/GridLayoutState.java index d2e685d8cb..381a6a7f85 100644 --- a/shared/src/com/vaadin/shared/ui/gridlayout/GridLayoutState.java +++ b/shared/src/com/vaadin/shared/ui/gridlayout/GridLayoutState.java @@ -21,6 +21,7 @@ public class GridLayoutState extends AbstractLayoutState { private boolean spacing = false; private int rows = 0; private int columns = 0; + private int marginsBitmask = 0; public boolean isSpacing() { return spacing; @@ -30,6 +31,14 @@ public class GridLayoutState extends AbstractLayoutState { this.spacing = spacing; } + public int getMarginsBitmask() { + return marginsBitmask; + } + + public void setMarginsBitmask(int marginsBitmask) { + this.marginsBitmask = marginsBitmask; + } + public int getRows() { return rows; } diff --git a/shared/src/com/vaadin/shared/ui/orderedlayout/AbstractOrderedLayoutState.java b/shared/src/com/vaadin/shared/ui/orderedlayout/AbstractOrderedLayoutState.java index 235c9eab13..3fa2ad771c 100644 --- a/shared/src/com/vaadin/shared/ui/orderedlayout/AbstractOrderedLayoutState.java +++ b/shared/src/com/vaadin/shared/ui/orderedlayout/AbstractOrderedLayoutState.java @@ -27,6 +27,8 @@ public class AbstractOrderedLayoutState extends AbstractLayoutState { public HashMap<Connector, ChildComponentData> childData = new HashMap<Connector, ChildComponentData>(); + private int marginsBitmask = 0; + public static class ChildComponentData implements Serializable { private int alignmentBitmask = AlignmentInfo.TOP_LEFT.getBitMask(); private float expandRatio = 0.0f; @@ -65,4 +67,12 @@ public class AbstractOrderedLayoutState extends AbstractLayoutState { this.spacing = spacing; } + public int getMarginsBitmask() { + return marginsBitmask; + } + + public void setMarginsBitmask(int marginsBitmask) { + this.marginsBitmask = marginsBitmask; + } + }
\ No newline at end of file diff --git a/tests/testbench/com/vaadin/tests/Parameters.java b/tests/testbench/com/vaadin/tests/Parameters.java index 4fb224eb19..e9824d9c40 100644 --- a/tests/testbench/com/vaadin/tests/Parameters.java +++ b/tests/testbench/com/vaadin/tests/Parameters.java @@ -27,7 +27,7 @@ import com.vaadin.terminal.RequestHandler; import com.vaadin.terminal.WrappedRequest; import com.vaadin.terminal.WrappedResponse; import com.vaadin.ui.Label; -import com.vaadin.ui.Layout; +import com.vaadin.ui.Layout.MarginHandler; import com.vaadin.ui.Link; import com.vaadin.ui.Panel; import com.vaadin.ui.Root.LegacyWindow; @@ -90,7 +90,7 @@ public class Parameters extends com.vaadin.Application.LegacyApplication final Panel panel2 = new Panel("Parameter Handler"); params.setSizeFull(); panel2.setContent(new VerticalLayout()); - ((Layout) panel2.getContent()).setMargin(true); + ((MarginHandler) panel2.getContent()).setMargin(true); params.setColumnHeaderMode(Table.COLUMN_HEADER_MODE_ID); panel2.addComponent(params); diff --git a/tests/testbench/com/vaadin/tests/components/AbstractLayoutTest.java b/tests/testbench/com/vaadin/tests/components/AbstractLayoutTest.java index af62e5e4a4..c04be3d724 100644 --- a/tests/testbench/com/vaadin/tests/components/AbstractLayoutTest.java +++ b/tests/testbench/com/vaadin/tests/components/AbstractLayoutTest.java @@ -2,11 +2,12 @@ package com.vaadin.tests.components; import java.util.LinkedHashMap; +import com.vaadin.shared.ui.MarginInfo; import com.vaadin.ui.AbstractLayout; import com.vaadin.ui.Alignment; import com.vaadin.ui.Component; import com.vaadin.ui.Layout.AlignmentHandler; -import com.vaadin.ui.Layout.MarginInfo; +import com.vaadin.ui.Layout.MarginHandler; import com.vaadin.ui.Layout.SpacingHandler; public abstract class AbstractLayoutTest<T extends AbstractLayout> extends @@ -17,7 +18,7 @@ public abstract class AbstractLayoutTest<T extends AbstractLayout> extends @Override public void execute(T c, MarginInfo value, Object data) { - c.setMargin(value); + ((MarginHandler) c).setMargin(value); } }; @@ -42,7 +43,9 @@ public abstract class AbstractLayoutTest<T extends AbstractLayout> extends @Override protected void createActions() { super.createActions(); - createMarginsSelect(CATEGORY_LAYOUT_FEATURES); + if (MarginHandler.class.isAssignableFrom(getTestClass())) { + createMarginsSelect(CATEGORY_LAYOUT_FEATURES); + } if (SpacingHandler.class.isAssignableFrom(getTestClass())) { createSpacingSelect(CATEGORY_LAYOUT_FEATURES); } diff --git a/tests/testbench/com/vaadin/tests/components/customfield/NestedPersonForm.java b/tests/testbench/com/vaadin/tests/components/customfield/NestedPersonForm.java index 0bc4f45545..0655c09102 100644 --- a/tests/testbench/com/vaadin/tests/components/customfield/NestedPersonForm.java +++ b/tests/testbench/com/vaadin/tests/components/customfield/NestedPersonForm.java @@ -4,6 +4,7 @@ import java.util.Arrays; import com.vaadin.data.Item; import com.vaadin.data.util.BeanItem; +import com.vaadin.shared.ui.MarginInfo; import com.vaadin.tests.util.Person; import com.vaadin.ui.Alignment; import com.vaadin.ui.Button; @@ -13,6 +14,7 @@ import com.vaadin.ui.DefaultFieldFactory; import com.vaadin.ui.Field; import com.vaadin.ui.Form; import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.Layout.MarginHandler; /** * Example of nested forms @@ -37,7 +39,8 @@ public class NestedPersonForm extends Form { setItemDataSource(beanItem, Arrays.asList("firstName", "lastName", "address", "email", "phoneNumber")); getFooter().addComponent(getButtonsLayout()); - getFooter().setMargin(false, false, true, true); + ((MarginHandler) getFooter()).setMargin(new MarginInfo(false, false, + true, true)); } /** diff --git a/tests/testbench/com/vaadin/tests/integration/LiferayThemeDemo.java b/tests/testbench/com/vaadin/tests/integration/LiferayThemeDemo.java index 1ea800821b..a35b78c219 100644 --- a/tests/testbench/com/vaadin/tests/integration/LiferayThemeDemo.java +++ b/tests/testbench/com/vaadin/tests/integration/LiferayThemeDemo.java @@ -8,6 +8,7 @@ import com.vaadin.Application; import com.vaadin.data.Property; import com.vaadin.data.Property.ValueChangeEvent; import com.vaadin.event.Action; +import com.vaadin.shared.ui.MarginInfo; import com.vaadin.shared.ui.label.ContentMode; import com.vaadin.terminal.ExternalResource; import com.vaadin.terminal.Page; @@ -103,7 +104,6 @@ public class LiferayThemeDemo extends Application.LegacyApplication { mainLayout.addComponent(getTopMenu()); CssLayout margin = new CssLayout(); - margin.setMargin(false, true, true, true); margin.setSizeFull(); tabs = new TabSheet(); tabs.setSizeFull(); @@ -239,7 +239,7 @@ public class LiferayThemeDemo extends Application.LegacyApplication { HorizontalLayout hl = new HorizontalLayout(); hl.setSpacing(true); - hl.setMargin(true, false, false, false); + hl.setMargin(new MarginInfo(true, false, false, false)); l.addComponent(hl); AbstractSelect cb = new ComboBox(); @@ -270,7 +270,7 @@ public class LiferayThemeDemo extends Application.LegacyApplication { HorizontalLayout hl = new HorizontalLayout(); hl.setSpacing(true); - hl.setMargin(true, false, false, false); + hl.setMargin(new MarginInfo(true, false, false, false)); l.addComponent(hl); DateField df = new DateField(); diff --git a/tests/testbench/com/vaadin/tests/layouts/CssLayoutCustomCss.java b/tests/testbench/com/vaadin/tests/layouts/CssLayoutCustomCss.java index 792bcb1aab..ed35d39ef7 100644 --- a/tests/testbench/com/vaadin/tests/layouts/CssLayoutCustomCss.java +++ b/tests/testbench/com/vaadin/tests/layouts/CssLayoutCustomCss.java @@ -12,6 +12,7 @@ import com.vaadin.ui.Button.ClickListener; import com.vaadin.ui.CheckBox; import com.vaadin.ui.Component; import com.vaadin.ui.CssLayout; +import com.vaadin.ui.Layout.MarginHandler; import com.vaadin.ui.NativeButton; public class CssLayoutCustomCss extends TestBase implements ClickListener { @@ -48,7 +49,7 @@ public class CssLayoutCustomCss extends TestBase implements ClickListener { @Override public void valueChange(ValueChangeEvent event) { - layout.setMargin(cb.getValue()); + ((MarginHandler) layout).setMargin(cb.getValue()); } }); diff --git a/tests/testbench/com/vaadin/tests/layouts/GridLayoutInsidePanel.java b/tests/testbench/com/vaadin/tests/layouts/GridLayoutInsidePanel.java index 1c864fdb47..e200c40744 100644 --- a/tests/testbench/com/vaadin/tests/layouts/GridLayoutInsidePanel.java +++ b/tests/testbench/com/vaadin/tests/layouts/GridLayoutInsidePanel.java @@ -3,7 +3,7 @@ package com.vaadin.tests.layouts; import com.vaadin.tests.components.TestBase; import com.vaadin.ui.GridLayout; import com.vaadin.ui.Label; -import com.vaadin.ui.Layout; +import com.vaadin.ui.Layout.MarginHandler; import com.vaadin.ui.Panel; public class GridLayoutInsidePanel extends TestBase { @@ -27,7 +27,7 @@ public class GridLayoutInsidePanel extends TestBase { "A label which defines the size of the GL")); Panel p = new Panel("Panel 1"); - ((Layout) p.getContent()).setMargin(false); + ((MarginHandler) p.getContent()).setMargin(false); p.setSizeUndefined(); p.getContent().setSizeUndefined(); @@ -41,7 +41,7 @@ public class GridLayoutInsidePanel extends TestBase { "A label which defines the size of the GL")); Panel p = new Panel("Panel 2", gl); - ((Layout) p.getContent()).setMargin(false); + ((MarginHandler) p.getContent()).setMargin(false); p.setSizeUndefined(); p.getContent().setSizeUndefined(); diff --git a/tests/testbench/com/vaadin/tests/tickets/Ticket1435.java b/tests/testbench/com/vaadin/tests/tickets/Ticket1435.java index 438f7e2d5f..d6d3b132c3 100644 --- a/tests/testbench/com/vaadin/tests/tickets/Ticket1435.java +++ b/tests/testbench/com/vaadin/tests/tickets/Ticket1435.java @@ -10,6 +10,7 @@ import com.vaadin.ui.CustomComponent; import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.Label; import com.vaadin.ui.Layout; +import com.vaadin.ui.Layout.MarginHandler; import com.vaadin.ui.Panel; import com.vaadin.ui.Root.LegacyWindow; import com.vaadin.ui.Table; @@ -159,7 +160,7 @@ public class Ticket1435 extends Application.LegacyApplication { private void initContainer() { container.setStyleName("custompanel"); container.setSizeFull(); - ((Layout) container.getContent()).setMargin(false); + ((MarginHandler) container.getContent()).setMargin(false); container.getContent().setSizeFull(); root.addComponent(container); root.setExpandRatio(container, 1); diff --git a/tests/testbench/com/vaadin/tests/tickets/Ticket1572.java b/tests/testbench/com/vaadin/tests/tickets/Ticket1572.java index b9fd2debd5..87ea7e86a8 100644 --- a/tests/testbench/com/vaadin/tests/tickets/Ticket1572.java +++ b/tests/testbench/com/vaadin/tests/tickets/Ticket1572.java @@ -1,5 +1,6 @@ package com.vaadin.tests.tickets; +import com.vaadin.shared.ui.MarginInfo; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.GridLayout; @@ -82,19 +83,19 @@ public class Ticket1572 extends com.vaadin.Application.LegacyApplication { state.setValue("Margin on"); break; case 2: - gl.setMargin(true, false, false, false); + gl.setMargin(new MarginInfo(true, false, false, false)); state.setValue("Margin top"); break; case 3: - gl.setMargin(false, true, false, false); + gl.setMargin(new MarginInfo(false, true, false, false)); state.setValue("Margin right"); break; case 4: - gl.setMargin(false, false, true, false); + gl.setMargin(new MarginInfo(false, false, true, false)); state.setValue("Margin bottom"); break; case 5: - gl.setMargin(false, false, false, true); + gl.setMargin(new MarginInfo(false, false, false, true)); state.setValue("Margin left"); break; default: diff --git a/tests/testbench/com/vaadin/tests/tickets/Ticket1710.java b/tests/testbench/com/vaadin/tests/tickets/Ticket1710.java index 01792aeb89..1f2c9624c3 100644 --- a/tests/testbench/com/vaadin/tests/tickets/Ticket1710.java +++ b/tests/testbench/com/vaadin/tests/tickets/Ticket1710.java @@ -5,6 +5,7 @@ import java.util.Iterator; import com.vaadin.data.Property; import com.vaadin.data.Property.ValueChangeEvent; import com.vaadin.data.util.MethodProperty; +import com.vaadin.shared.ui.MarginInfo; import com.vaadin.terminal.SystemError; import com.vaadin.terminal.ThemeResource; import com.vaadin.ui.AbstractComponent; @@ -393,10 +394,13 @@ public class Ticket1710 extends com.vaadin.Application.LegacyApplication { } private void updateMarginsAndSpacing() { - testedLayout.setMargin(marginTop.getValue().booleanValue(), - marginRight.getValue().booleanValue(), marginBottom - .getValue().booleanValue(), marginLeft.getValue() - .booleanValue()); + if (testedLayout instanceof Layout.MarginHandler) { + ((Layout.MarginHandler) testedLayout).setMargin(new MarginInfo( + marginTop.getValue().booleanValue(), marginRight + .getValue().booleanValue(), marginBottom + .getValue().booleanValue(), marginLeft + .getValue().booleanValue())); + } if (testedLayout instanceof Layout.SpacingHandler) { ((Layout.SpacingHandler) testedLayout).setSpacing(spacing .getValue().booleanValue()); diff --git a/tests/testbench/com/vaadin/tests/tickets/Ticket1805.java b/tests/testbench/com/vaadin/tests/tickets/Ticket1805.java index a40f5b25b9..e5fcf59db8 100644 --- a/tests/testbench/com/vaadin/tests/tickets/Ticket1805.java +++ b/tests/testbench/com/vaadin/tests/tickets/Ticket1805.java @@ -6,7 +6,7 @@ import com.vaadin.ui.Alignment; import com.vaadin.ui.Button; import com.vaadin.ui.GridLayout; import com.vaadin.ui.Label; -import com.vaadin.ui.Layout; +import com.vaadin.ui.Layout.MarginHandler; import com.vaadin.ui.Root.LegacyWindow; import com.vaadin.ui.TextField; @@ -17,7 +17,7 @@ public class Ticket1805 extends com.vaadin.Application.LegacyApplication { final LegacyWindow main = new LegacyWindow(getClass().getName() .substring(getClass().getName().lastIndexOf(".") + 1)); setMainWindow(main); - ((Layout) main.getContent()).setMargin(false); + ((MarginHandler) main.getContent()).setMargin(false); Label description = new Label( "GridLayout with 100% (no height), is wanted to " diff --git a/tests/testbench/com/vaadin/tests/tickets/Ticket2021.java b/tests/testbench/com/vaadin/tests/tickets/Ticket2021.java index c36bb5c25e..f6d8ce5e01 100644 --- a/tests/testbench/com/vaadin/tests/tickets/Ticket2021.java +++ b/tests/testbench/com/vaadin/tests/tickets/Ticket2021.java @@ -9,6 +9,7 @@ import com.vaadin.ui.Button.ClickListener; import com.vaadin.ui.GridLayout; import com.vaadin.ui.Label; import com.vaadin.ui.Layout; +import com.vaadin.ui.Layout.MarginHandler; import com.vaadin.ui.Panel; import com.vaadin.ui.Root.LegacyWindow; import com.vaadin.ui.TextArea; @@ -78,7 +79,7 @@ public class Ticket2021 extends Application.LegacyApplication { p3.setHeight("500px"); // p3.setContent(new GridLayout()); p3.getContent().setSizeFull(); - ((Layout) p3.getContent()).setMargin(false); + ((MarginHandler) p3.getContent()).setMargin(false); GridLayout gl = new GridLayout(); gl.setSizeFull(); diff --git a/tests/testbench/com/vaadin/tests/tickets/Ticket2040.java b/tests/testbench/com/vaadin/tests/tickets/Ticket2040.java index ac8928d110..d98656b9ca 100644 --- a/tests/testbench/com/vaadin/tests/tickets/Ticket2040.java +++ b/tests/testbench/com/vaadin/tests/tickets/Ticket2040.java @@ -2,7 +2,7 @@ package com.vaadin.tests.tickets; import com.vaadin.ui.Accordion; import com.vaadin.ui.Label; -import com.vaadin.ui.Layout; +import com.vaadin.ui.Layout.MarginHandler; import com.vaadin.ui.Root.LegacyWindow; import com.vaadin.ui.TextArea; import com.vaadin.ui.TextField; @@ -17,7 +17,7 @@ public class Ticket2040 extends com.vaadin.Application.LegacyApplication { setMainWindow(main); main.getContent().setSizeFull(); - ((Layout) main.getContent()).setMargin(true); + ((MarginHandler) main.getContent()).setMargin(true); setTheme("tests-tickets"); diff --git a/tests/testbench/com/vaadin/tests/tickets/Ticket2405.java b/tests/testbench/com/vaadin/tests/tickets/Ticket2405.java index 16a552e37a..c5ef9ec0b0 100644 --- a/tests/testbench/com/vaadin/tests/tickets/Ticket2405.java +++ b/tests/testbench/com/vaadin/tests/tickets/Ticket2405.java @@ -8,7 +8,7 @@ import com.vaadin.ui.Embedded; import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.HorizontalSplitPanel; import com.vaadin.ui.Label; -import com.vaadin.ui.Layout; +import com.vaadin.ui.Layout.MarginHandler; import com.vaadin.ui.Root.LegacyWindow; import com.vaadin.ui.TextField; import com.vaadin.ui.VerticalLayout; @@ -31,7 +31,7 @@ public class Ticket2405 extends Application.LegacyApplication { setMainWindow(root); root.getContent().setSizeFull(); - ((Layout) root.getContent()).setMargin(false); + ((MarginHandler) root.getContent()).setMargin(false); // Top area, containing playback and volume controls, play status, view // modes and search diff --git a/tests/testbench/com/vaadin/tests/tickets/Ticket2998.java b/tests/testbench/com/vaadin/tests/tickets/Ticket2998.java index ee60c0ce7e..2d2970d36e 100644 --- a/tests/testbench/com/vaadin/tests/tickets/Ticket2998.java +++ b/tests/testbench/com/vaadin/tests/tickets/Ticket2998.java @@ -19,6 +19,7 @@ import com.vaadin.ui.DefaultFieldFactory; import com.vaadin.ui.Field; import com.vaadin.ui.FormLayout; import com.vaadin.ui.Layout; +import com.vaadin.ui.Layout.MarginHandler; import com.vaadin.ui.ListSelect; import com.vaadin.ui.Notification; import com.vaadin.ui.Panel; @@ -252,7 +253,7 @@ public class Ticket2998 extends Application.LegacyApplication { // set theme and some layout stuff setMainWindow(w); w.getContent().setSizeFull(); - ((Layout) w.getContent()).setMargin(false); + ((MarginHandler) w.getContent()).setMargin(false); Panel p = new Panel("Workout Log"); p.setStyleName(Reindeer.PANEL_LIGHT); |