01: /*
02: * GWT-Ext Widget Library
03: * Copyright(c) 2007-2008, GWT-Ext.
04: * licensing@gwt-ext.com
05: *
06: * http://www.gwt-ext.com/license
07: */
08: package com.gwtext.client.core;
09:
10: import com.google.gwt.core.client.JavaScriptObject;
11: import com.gwtext.client.util.JavaScriptObjectHelper;
12:
13: /**
14: * Class that represents the margins of an element.
15: */
16: public class Margins extends JsObject {
17:
18: private int top;
19: private int left;
20: private int right;
21: private int bottom;
22:
23: /**
24: * Create a new Margins instance.
25: *
26: * @param left the left margin
27: * @param top the top margin
28: * @param right the right margin
29: * @param bottom the bottom margin
30: */
31: public Margins(int top, int left, int right, int bottom) {
32: this .top = top;
33: this .left = left;
34: this .right = right;
35: this .bottom = bottom;
36: jsObj = JavaScriptObject.createObject();
37: JavaScriptObjectHelper.setAttribute(jsObj, "top", top);
38: JavaScriptObjectHelper.setAttribute(jsObj, "left", left);
39: JavaScriptObjectHelper.setAttribute(jsObj, "right", right);
40: JavaScriptObjectHelper.setAttribute(jsObj, "bottom", bottom);
41: }
42:
43: private static Margins instance(JavaScriptObject jsObj) {
44: return new Margins(JavaScriptObjectHelper.getAttributeAsInt(
45: jsObj, "left"), JavaScriptObjectHelper
46: .getAttributeAsInt(jsObj, "top"),
47: JavaScriptObjectHelper
48: .getAttributeAsInt(jsObj, "right"),
49: JavaScriptObjectHelper.getAttributeAsInt(jsObj,
50: "bottom"));
51: }
52:
53: /**
54: * @return the top margin
55: */
56: public int getTop() {
57: return top;
58: }
59:
60: /**
61: * @return the left margin
62: */
63: public int getLeft() {
64: return left;
65: }
66:
67: /**
68: * @return the right margin
69: */
70: public int getRight() {
71: return right;
72: }
73:
74: /**
75: * @return the bottom margin
76: */
77: public int getBottom() {
78: return bottom;
79: }
80:
81: /**
82: * Return the margins as a CSS style string.
83: *
84: * @return margin as style String
85: */
86: public String getStyleString() {
87: return "margin:" + top + "px " + right + "px " + bottom + "px "
88: + left + "px;";
89: }
90: }
|