Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 52b376589f7a927fde48669a2a19877c958b4d1b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
/*******************************************************************************
 * Copyright (c) 2006 Sybase, Inc. and others.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Sybase, Inc. - initial API and implementation
 *******************************************************************************/
package org.eclipse.jst.pagedesigner.css2.layout;

import org.eclipse.draw2d.geometry.Insets;
import org.eclipse.draw2d.geometry.Rectangle;

/**
 * This class represents the CSS box model. See chapter 8 of CSS2 spec.
 * 
 * see http://www.w3.org/TR/REC-CSS2/box.html
 * 
 */
public class FlowBox {
	private Object _verticalAlignData = null;

	/**
	 * The x location
	 */
	protected int _x;

	/**
	 * The y location
	 */
	protected int _y;

	int _width;

	int _height;

	private Insets _marginInsets = new Insets();

	private Insets _borderInsets = new Insets();

	private Insets _paddingInsets = new Insets();

	/**
	 * This method must be called on a block that is completely positioned and
	 * committed.
	 * 
	 * @param x
	 *            X
	 * @param y
	 *            Y
	 * @return <code>true</code> if the FlowBox contains the point
	 */
	public boolean containsPoint(int x, int y) {
		return x >= this._x && y >= this._y && x < this._x + this._width
				&& y < this._y + this._height;
	}

	/**
	 * By default, a FlowBox is all ascent, and no descent, so the height is
	 * returned.
	 * 
	 * @return the <i>ascent </i> in pixels above the baseline
	 */
	public int getAscent() {
		return getHeight();
	}


	/**
	 * By default, a simple FlowBox is all ascent, and no descent. Zero is
	 * returned.
	 * 
	 * @return the <i>descent </i> in pixels below the baseline
	 */
	public final int getDescent() {
		return getHeight() - getAscent();
	}

	/**
	 * Returns the height
	 * 
	 * @return height
	 */
	public int getHeight() {
		return _height;
	}

	/**
	 * Returns the width
	 * 
	 * @return width
	 */
	public int getWidth() {
		return _width;
	}

	/**
	 * @param w
	 */
	public void setWidth(int w) {
		_width = w;
	}

	/**
	 * @param h
	 */
	public void setHeight(int h) {
		_height = h;
	}

	/**
	 * Used to set the baseline of this FlowBox to the specified value.
	 * 
	 * @param value
	 *            the new baseline
	 */
	public void makeBaseline(int value) {
		_y = (value - getAscent());
	}

	/**
	 * @return the border padding width
	 */
	public int getBorderPaddingWidth() {
		return _borderInsets.getWidth() + _paddingInsets.getWidth();
	}

	/**
	 * @return the border padding height
	 */
	public int getBorderPaddingHeight() {
		return _borderInsets.getHeight() + _paddingInsets.getHeight();
	}

	/**
	 * @return the border padding insets
	 */
	public Insets getBorderPaddingInsets() {
		Insets temp = new Insets(_borderInsets);
		return temp.add(_paddingInsets);
	}

	/**
	 * @param rect
	 */
	public void setXYWidthHeight(Rectangle rect) {
		this._x = rect.x;
		this._y = rect.y;
		this.setWidth(rect.width);
		this.setHeight(rect.height);
	}

	/**
	 * @return Returns the _verticalAlignData.
	 */
	public Object getVerticalAlignData() {
		return _verticalAlignData;
	}

	/**
	 * @param alignData
	 *            The _verticalAlignData to set.
	 */
	public void setVerticalAlignData(Object alignData) {
		_verticalAlignData = alignData;
	}

	/**
	 * @return a copy of the rectangle
	 * TODO: use getCopy() ?
	 */
	public Rectangle getRectangle() {
		return new Rectangle(this._x, this._y, this.getWidth(), this
				.getHeight());
	}

    /**
     * @return the x coordinate
     */
    public final int getX() {
        return _x;
    }

    /**
     * @return the y coordinate
     */
    public final int getY() {
        return _y;
    }

    /**
     * @param y
     */
    protected void setY(int y)
    {
        _y = y;
    }
    
    /**
     * @return the margin insets
     */
    public final Insets getMarginInsets() {
        return _marginInsets;
    }

    final void setMarginInsets(Insets marginInsets) {
        _marginInsets = marginInsets;
    }

    final Insets getBorderInsets() {
        return _borderInsets;
    }

    final void setBorderInsets(Insets borderInsets)
    {
        _borderInsets = borderInsets;
    }
    
    final Insets getPaddingInsets() {
        return _paddingInsets;
    }
	
	final void setPaddingInsets(Insets paddingInsets)
	{
	    _paddingInsets = paddingInsets;
	}
}

Back to the top