summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2012-04-03 18:54:21 +0300
committerArtur Signell <artur@vaadin.com>2012-04-05 00:09:16 +0300
commit69ea130cd3cf57ed1373adf7899fb1f4c9184a32 (patch)
tree5a6a4e5601281f47d4e8e2502392fa9e64d87b8f
parent6ac1b1580596b1fcac28cb6b16f1c431300fe32e (diff)
downloadvaadin-framework-69ea130cd3cf57ed1373adf7899fb1f4c9184a32.tar.gz
vaadin-framework-69ea130cd3cf57ed1373adf7899fb1f4c9184a32.zip
Moved margins to AbstractLayoutState
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/AbsoluteLayoutConnector.java4
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/AbstractLayoutConnector.java25
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/AbstractOrderedLayoutConnector.java7
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/CssLayoutConnector.java24
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/GridLayoutConnector.java8
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VCssLayout.java10
-rw-r--r--src/com/vaadin/ui/AbstractLayout.java25
-rw-r--r--src/com/vaadin/ui/AbstractSplitPanel.java2
-rw-r--r--tests/testbench/com/vaadin/tests/components/splitpanel/AbstractSplitPanelTest.java5
-rw-r--r--tests/testbench/com/vaadin/tests/layouts/CssLayoutCustomCss.java18
-rw-r--r--tests/testbench/com/vaadin/tests/tickets/Ticket1983.java1
11 files changed, 72 insertions, 57 deletions
diff --git a/src/com/vaadin/terminal/gwt/client/ui/AbsoluteLayoutConnector.java b/src/com/vaadin/terminal/gwt/client/ui/AbsoluteLayoutConnector.java
index 51596adead..d29f3dadb3 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/AbsoluteLayoutConnector.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/AbsoluteLayoutConnector.java
@@ -12,7 +12,6 @@ import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.terminal.gwt.client.ComponentConnector;
-import com.vaadin.terminal.gwt.client.ComponentState;
import com.vaadin.terminal.gwt.client.Connector;
import com.vaadin.terminal.gwt.client.ConnectorHierarchyChangeEvent;
import com.vaadin.terminal.gwt.client.DirectionalManagedLayout;
@@ -20,6 +19,7 @@ import com.vaadin.terminal.gwt.client.VCaption;
import com.vaadin.terminal.gwt.client.communication.RpcProxy;
import com.vaadin.terminal.gwt.client.communication.ServerRpc;
import com.vaadin.terminal.gwt.client.communication.StateChangeEvent;
+import com.vaadin.terminal.gwt.client.ui.AbstractLayoutConnector.AbstractLayoutState;
import com.vaadin.terminal.gwt.client.ui.VAbsoluteLayout.AbsoluteWrapper;
import com.vaadin.ui.AbsoluteLayout;
@@ -27,7 +27,7 @@ import com.vaadin.ui.AbsoluteLayout;
public class AbsoluteLayoutConnector extends
AbstractComponentContainerConnector implements DirectionalManagedLayout {
- public static class AbsoluteLayoutState extends ComponentState {
+ public static class AbsoluteLayoutState extends AbstractLayoutState {
// Maps each component to a position
private Map<String, String> connectorToCssPosition = new HashMap<String, String>();
diff --git a/src/com/vaadin/terminal/gwt/client/ui/AbstractLayoutConnector.java b/src/com/vaadin/terminal/gwt/client/ui/AbstractLayoutConnector.java
new file mode 100644
index 0000000000..1814f9cde9
--- /dev/null
+++ b/src/com/vaadin/terminal/gwt/client/ui/AbstractLayoutConnector.java
@@ -0,0 +1,25 @@
+package com.vaadin.terminal.gwt.client.ui;
+
+import com.vaadin.terminal.gwt.client.ComponentState;
+
+public abstract class AbstractLayoutConnector extends
+ AbstractComponentContainerConnector {
+
+ public static class AbstractLayoutState extends ComponentState {
+ private int marginsBitmask;
+
+ public int getMarginsBitmask() {
+ return marginsBitmask;
+ }
+
+ public void setMarginsBitmask(int marginsBitmask) {
+ this.marginsBitmask = marginsBitmask;
+ }
+
+ }
+
+ @Override
+ public AbstractLayoutState getState() {
+ return (AbstractLayoutState) super.getState();
+ }
+}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/AbstractOrderedLayoutConnector.java b/src/com/vaadin/terminal/gwt/client/ui/AbstractOrderedLayoutConnector.java
index fd2c92dec7..c4c017920c 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/AbstractOrderedLayoutConnector.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/AbstractOrderedLayoutConnector.java
@@ -23,8 +23,7 @@ import com.vaadin.terminal.gwt.client.ui.layout.ComponentConnectorLayoutSlot;
import com.vaadin.terminal.gwt.client.ui.layout.VLayoutSlot;
public abstract class AbstractOrderedLayoutConnector extends
- AbstractComponentContainerConnector implements Paintable,
- DirectionalManagedLayout {
+ AbstractLayoutConnector implements Paintable, DirectionalManagedLayout {
public interface AbstractOrderedLayoutServerRPC extends LayoutClickRPC,
ServerRpc {
@@ -113,8 +112,8 @@ public abstract class AbstractOrderedLayoutConnector extends
slot.setExpandRatio(expandRatio);
}
- int bitMask = uidl.getIntAttribute("margins");
- layout.updateMarginStyleNames(new VMarginInfo(bitMask));
+ layout.updateMarginStyleNames(new VMarginInfo(getState()
+ .getMarginsBitmask()));
layout.updateSpacingStyleName(uidl.getBooleanAttribute("spacing"));
diff --git a/src/com/vaadin/terminal/gwt/client/ui/CssLayoutConnector.java b/src/com/vaadin/terminal/gwt/client/ui/CssLayoutConnector.java
index ac091f0484..7d375501db 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/CssLayoutConnector.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/CssLayoutConnector.java
@@ -10,13 +10,9 @@ import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.Widget;
-import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.BrowserInfo;
import com.vaadin.terminal.gwt.client.ComponentConnector;
-import com.vaadin.terminal.gwt.client.ComponentState;
import com.vaadin.terminal.gwt.client.ConnectorHierarchyChangeEvent;
-import com.vaadin.terminal.gwt.client.Paintable;
-import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.Util;
import com.vaadin.terminal.gwt.client.VCaption;
import com.vaadin.terminal.gwt.client.communication.RpcProxy;
@@ -26,10 +22,9 @@ import com.vaadin.terminal.gwt.client.ui.VCssLayout.FlowPane;
import com.vaadin.ui.CssLayout;
@Component(CssLayout.class)
-public class CssLayoutConnector extends AbstractComponentContainerConnector
- implements Paintable {
+public class CssLayoutConnector extends AbstractLayoutConnector {
- public static class CssLayoutState extends ComponentState {
+ public static class CssLayoutState extends AbstractLayoutState {
private Map<String, String> childCss = new HashMap<String, String>();
public Map<String, String> getChildCss() {
@@ -80,6 +75,9 @@ public class CssLayoutConnector extends AbstractComponentContainerConnector
public void onStateChanged(StateChangeEvent stateChangeEvent) {
super.onStateChanged(stateChangeEvent);
+ getWidget().setMarginStyles(
+ new VMarginInfo(getState().getMarginsBitmask()));
+
for (ComponentConnector child : getChildren()) {
if (!getState().getChildCss().containsKey(child.getConnectorId())) {
continue;
@@ -130,18 +128,6 @@ public class CssLayoutConnector extends AbstractComponentContainerConnector
}
}
- public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
-
- if (!isRealUpdate(uidl)) {
- return;
- }
-
- getWidget().setMarginAndSpacingStyles(
- new VMarginInfo(uidl.getIntAttribute("margins")),
- uidl.hasAttribute("spacing"));
-
- }
-
private static final String makeCamelCase(String cssProperty) {
// TODO this might be cleaner to implement with regexp
while (cssProperty.contains("-")) {
diff --git a/src/com/vaadin/terminal/gwt/client/ui/GridLayoutConnector.java b/src/com/vaadin/terminal/gwt/client/ui/GridLayoutConnector.java
index 5e87bd83a8..be7defc2f6 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/GridLayoutConnector.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/GridLayoutConnector.java
@@ -11,7 +11,6 @@ import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.ComponentConnector;
-import com.vaadin.terminal.gwt.client.ComponentState;
import com.vaadin.terminal.gwt.client.ConnectorMap;
import com.vaadin.terminal.gwt.client.DirectionalManagedLayout;
import com.vaadin.terminal.gwt.client.Paintable;
@@ -20,6 +19,7 @@ import com.vaadin.terminal.gwt.client.VCaption;
import com.vaadin.terminal.gwt.client.communication.RpcProxy;
import com.vaadin.terminal.gwt.client.communication.ServerRpc;
import com.vaadin.terminal.gwt.client.communication.StateChangeEvent;
+import com.vaadin.terminal.gwt.client.ui.AbstractLayoutConnector.AbstractLayoutState;
import com.vaadin.terminal.gwt.client.ui.VGridLayout.Cell;
import com.vaadin.terminal.gwt.client.ui.layout.VLayoutSlot;
import com.vaadin.ui.GridLayout;
@@ -28,7 +28,7 @@ import com.vaadin.ui.GridLayout;
public class GridLayoutConnector extends AbstractComponentContainerConnector
implements Paintable, DirectionalManagedLayout {
- public static class GridLayoutState extends ComponentState {
+ public static class GridLayoutState extends AbstractLayoutState {
private boolean spacing = false;
private int rows = 0;
private int columns = 0;
@@ -169,8 +169,8 @@ public class GridLayoutConnector extends AbstractComponentContainerConnector
cell.slot = null;
}
- int bitMask = uidl.getIntAttribute("margins");
- layout.updateMarginStyleNames(new VMarginInfo(bitMask));
+ layout.updateMarginStyleNames(new VMarginInfo(getState()
+ .getMarginsBitmask()));
layout.updateSpacingStyleName(getState().isSpacing());
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VCssLayout.java b/src/com/vaadin/terminal/gwt/client/ui/VCssLayout.java
index 64f7ba3240..69c3659d3f 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VCssLayout.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VCssLayout.java
@@ -52,16 +52,13 @@ public class VCssLayout extends SimplePanel {
}
/**
- * Sets CSS classes for margin and spacing based on the given parameters.
+ * 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
- * @param spacing
- * true to enable spacing, false otherwise
*/
- protected void setMarginAndSpacingStyles(VMarginInfo margins,
- boolean spacing) {
+ protected void setMarginStyles(VMarginInfo margins) {
setStyleName(margin, VCssLayout.CLASSNAME + "-"
+ StyleConstants.MARGIN_TOP, margins.hasTop());
setStyleName(margin, VCssLayout.CLASSNAME + "-"
@@ -70,8 +67,5 @@ public class VCssLayout extends SimplePanel {
+ StyleConstants.MARGIN_BOTTOM, margins.hasBottom());
setStyleName(margin, VCssLayout.CLASSNAME + "-"
+ StyleConstants.MARGIN_LEFT, margins.hasLeft());
-
- setStyleName(margin, VCssLayout.CLASSNAME + "-" + "spacing", spacing);
-
}
}
diff --git a/src/com/vaadin/ui/AbstractLayout.java b/src/com/vaadin/ui/AbstractLayout.java
index 9f9a929a29..7d982964e2 100644
--- a/src/com/vaadin/ui/AbstractLayout.java
+++ b/src/com/vaadin/ui/AbstractLayout.java
@@ -4,8 +4,7 @@
package com.vaadin.ui;
-import com.vaadin.terminal.PaintException;
-import com.vaadin.terminal.PaintTarget;
+import com.vaadin.terminal.gwt.client.ui.AbstractLayoutConnector.AbstractLayoutState;
import com.vaadin.ui.Layout.MarginHandler;
/**
@@ -23,6 +22,11 @@ public abstract class AbstractLayout extends AbstractComponentContainer
protected MarginInfo margins = new MarginInfo(false);
+ @Override
+ public AbstractLayoutState getState() {
+ return (AbstractLayoutState) super.getState();
+ }
+
/*
* (non-Javadoc)
*
@@ -30,6 +34,7 @@ public abstract class AbstractLayout extends AbstractComponentContainer
*/
public void setMargin(boolean enabled) {
margins.setMargins(enabled);
+ getState().setMarginsBitmask(margins.getBitMask());
requestRepaint();
}
@@ -49,6 +54,7 @@ public abstract class AbstractLayout extends AbstractComponentContainer
*/
public void setMargin(MarginInfo marginInfo) {
margins.setMargins(marginInfo);
+ getState().setMarginsBitmask(margins.getBitMask());
requestRepaint();
}
@@ -60,21 +66,8 @@ public abstract class AbstractLayout extends AbstractComponentContainer
public void setMargin(boolean topEnabled, boolean rightEnabled,
boolean bottomEnabled, boolean leftEnabled) {
margins.setMargins(topEnabled, rightEnabled, bottomEnabled, leftEnabled);
+ getState().setMarginsBitmask(margins.getBitMask());
requestRepaint();
}
- /*
- * (non-Javadoc)
- *
- * @see com.vaadin.ui.AbstractComponent#paintContent(com.vaadin
- * .terminal.PaintTarget)
- */
- @Override
- public void paintContent(PaintTarget target) throws PaintException {
-
- // Add margin info. Defaults to false.
- target.addAttribute("margins", margins.getBitMask());
-
- }
-
}
diff --git a/src/com/vaadin/ui/AbstractSplitPanel.java b/src/com/vaadin/ui/AbstractSplitPanel.java
index b576008344..3ab80444c2 100644
--- a/src/com/vaadin/ui/AbstractSplitPanel.java
+++ b/src/com/vaadin/ui/AbstractSplitPanel.java
@@ -29,7 +29,7 @@ import com.vaadin.tools.ReflectTools;
* @VERSION@
* @since 6.5
*/
-public abstract class AbstractSplitPanel extends AbstractLayout {
+public abstract class AbstractSplitPanel extends AbstractComponentContainer {
private Unit posUnit;
diff --git a/tests/testbench/com/vaadin/tests/components/splitpanel/AbstractSplitPanelTest.java b/tests/testbench/com/vaadin/tests/components/splitpanel/AbstractSplitPanelTest.java
index 861bdc1aab..1f7b6b7cbe 100644
--- a/tests/testbench/com/vaadin/tests/components/splitpanel/AbstractSplitPanelTest.java
+++ b/tests/testbench/com/vaadin/tests/components/splitpanel/AbstractSplitPanelTest.java
@@ -2,13 +2,14 @@ package com.vaadin.tests.components.splitpanel;
import com.vaadin.terminal.Sizeable;
import com.vaadin.terminal.Sizeable.Unit;
-import com.vaadin.tests.components.AbstractLayoutTest;
+import com.vaadin.tests.components.AbstractComponentContainerTest;
import com.vaadin.ui.AbstractSplitPanel;
import com.vaadin.ui.AbstractSplitPanel.SplitterClickEvent;
import com.vaadin.ui.AbstractSplitPanel.SplitterClickListener;
public abstract class AbstractSplitPanelTest<T extends AbstractSplitPanel>
- extends AbstractLayoutTest<T> implements SplitterClickListener {
+ extends AbstractComponentContainerTest<T> implements
+ SplitterClickListener {
private Command<T, Boolean> splitterClickListenerCommand = new Command<T, Boolean>() {
diff --git a/tests/testbench/com/vaadin/tests/layouts/CssLayoutCustomCss.java b/tests/testbench/com/vaadin/tests/layouts/CssLayoutCustomCss.java
index b2712fc54c..5ddf196bcc 100644
--- a/tests/testbench/com/vaadin/tests/layouts/CssLayoutCustomCss.java
+++ b/tests/testbench/com/vaadin/tests/layouts/CssLayoutCustomCss.java
@@ -3,10 +3,13 @@ package com.vaadin.tests.layouts;
import java.util.HashMap;
import java.util.Map;
+import com.vaadin.data.Property.ValueChangeEvent;
+import com.vaadin.data.Property.ValueChangeListener;
import com.vaadin.tests.components.TestBase;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
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.NativeButton;
@@ -31,6 +34,21 @@ public class CssLayoutCustomCss extends TestBase implements ClickListener {
layout.addComponent(createButton("color:red"));
layout.addComponent(createButton("color: blue"));
layout.addComponent(createButton("color: green"));
+
+ layout.addComponent(createMarginsToggle());
+ }
+
+ private Component createMarginsToggle() {
+ final CheckBox cb = new CheckBox("Margins");
+ cb.setImmediate(true);
+ cb.addListener(new ValueChangeListener() {
+
+ public void valueChange(ValueChangeEvent event) {
+ layout.setMargin(cb.getValue());
+ }
+ });
+
+ return cb;
}
private Component createButton(String string) {
diff --git a/tests/testbench/com/vaadin/tests/tickets/Ticket1983.java b/tests/testbench/com/vaadin/tests/tickets/Ticket1983.java
index c68ccf08f9..5bd0cd2ae6 100644
--- a/tests/testbench/com/vaadin/tests/tickets/Ticket1983.java
+++ b/tests/testbench/com/vaadin/tests/tickets/Ticket1983.java
@@ -34,7 +34,6 @@ public class Ticket1983 extends Application.LegacyApplication {
public TestLayout() {
setSplitPosition(200, Sizeable.UNITS_PIXELS);
- setMargin(false);
setLocked(true);
final HorizontalSplitPanel leftSide = initLeftSide();