1
|
/*******************************************************************************
|
2
|
* Copyright (c) 2000, 2010 IBM Corporation and others.
|
3
|
* All rights reserved. This program and the accompanying materials
|
4
|
* are made available under the terms of the Eclipse Public License v1.0
|
5
|
* which accompanies this distribution, and is available at
|
6
|
* http://www.eclipse.org/legal/epl-v10.html
|
7
|
*
|
8
|
* Contributors:
|
9
|
* IBM Corporation - initial API and implementation
|
10
|
*******************************************************************************/
|
11
|
package org.eclipse.draw2d.text;
|
12
|
|
13
|
/**
|
14
|
* A Geometric object for representing a region on a line of Text. This class
|
15
|
* adds the notion of a baseline to
|
16
|
* {@link org.eclipse.draw2d.geometry.Rectangle}. <i>Ascent</i> is the distance
|
17
|
* above the baseline. <i>Descent</i> is the distance below the baseline.
|
18
|
* <P>
|
19
|
* This class should not be treated as a <code>Rectangle</code> by clients. It
|
20
|
* is important to use getters when available for lazy calculation of values.
|
21
|
*
|
22
|
* @author hudsonr
|
23
|
* @since 2.1
|
24
|
*/
|
25
|
public abstract class FlowBox {
|
26
|
|
27
|
int width;
|
28
|
|
29
|
/**
|
30
|
* The x location
|
31
|
*/
|
32
|
private int x;
|
33
|
|
34
|
/**
|
35
|
* This method must be called on a block that is completely positioned and
|
36
|
* committed.
|
37
|
*
|
38
|
* @param x
|
39
|
* X
|
40
|
* @param y
|
41
|
* Y
|
42
|
* @return <code>true</code> if the FlowBox contains the point
|
43
|
*/
|
44
|
public abstract boolean containsPoint(int x, int y);
|
45
|
|
46
|
/**
|
47
|
* Returns the amount of line content in pixels which is above the baseline.
|
48
|
* Ascent and descent are used to space consecutive lines apart. Certain
|
49
|
* types of line content, such as borders, extend beyond the ascent and
|
50
|
* descent.
|
51
|
*
|
52
|
* @return the <i>descent</i> in pixels below the baseline
|
53
|
*/
|
54
|
public abstract int getAscent();
|
55
|
|
56
|
/**
|
57
|
* Returns y coordinate for the box's baseline.
|
58
|
*
|
59
|
* @return the baseline location
|
60
|
* @since 3.1
|
61
|
*/
|
62
|
public abstract int getBaseline();
|
63
|
|
64
|
/**
|
65
|
* Returns the amount of line content in pixels which is below the baseline.
|
66
|
*
|
67
|
* @return the <i>descent</i> in pixels
|
68
|
* @see #getAscent()
|
69
|
*/
|
70
|
public abstract int getDescent();
|
71
|
|
72
|
/**
|
73
|
* Returns the root LineBox in which this box is placed. The root line is
|
74
|
* interesting when painting selection or hit testing. All boxes in a line
|
75
|
* should render selection at the same top and bottom location.
|
76
|
*
|
77
|
* @return the line root.
|
78
|
* @since 3.1
|
79
|
*/
|
80
|
abstract LineRoot getLineRoot();
|
81
|
|
82
|
/**
|
83
|
* Returns the outer ascent of this box. The outer ascent is the ascent
|
84
|
* above the baseline including the border size and margin. This is used
|
85
|
* when adding content into a LineBox. The linebox's own border must be
|
86
|
* drawn around the children.
|
87
|
*/
|
88
|
int getOuterAscent() {
|
89
|
return getAscent();
|
90
|
}
|
91
|
|
92
|
/**
|
93
|
* Returns the outer descent of this box. The outer descent is the space
|
94
|
* below the baseline including the border size and margin. This is used
|
95
|
* when adding content into a LineBox. The linebox's own border must be
|
96
|
* drawn around the children.
|
97
|
*/
|
98
|
int getOuterDescent() {
|
99
|
return getDescent();
|
100
|
}
|
101
|
|
102
|
int getAscentWithBorder() {
|
103
|
throw new RuntimeException("Not valid on this box type"); //$NON-NLS-1$
|
104
|
}
|
105
|
|
106
|
int getDescentWithBorder() {
|
107
|
throw new RuntimeException("Not valid on this box type"); //$NON-NLS-1$
|
108
|
}
|
109
|
|
110
|
/**
|
111
|
* Returns the width of the box.
|
112
|
*
|
113
|
* @return the box's width
|
114
|
*/
|
115
|
public int getWidth() {
|
116
|
return width;
|
117
|
}
|
118
|
|
119
|
/**
|
120
|
* Returns the X coordinate of the box.
|
121
|
*
|
122
|
* @return the x coordinate
|
123
|
* @since 3.1
|
124
|
*/
|
125
|
public int getX() {
|
126
|
return x;
|
127
|
}
|
128
|
|
129
|
/**
|
130
|
* Returns <code>true</code> if any of the children are bi-directional.
|
131
|
* Default implementation returns false.
|
132
|
*
|
133
|
* @return <code>true</code> if the box is bi-directional
|
134
|
* @since 3.1
|
135
|
*/
|
136
|
public boolean requiresBidi() {
|
137
|
return false;
|
138
|
}
|
139
|
|
140
|
/**
|
141
|
* Sets the line root.
|
142
|
*
|
143
|
* @param root
|
144
|
* the line root
|
145
|
* @since 3.1
|
146
|
*/
|
147
|
void setLineRoot(LineRoot root) {
|
148
|
}
|
149
|
|
150
|
/**
|
151
|
* Sets the width of the box.
|
152
|
*
|
153
|
* @param width
|
154
|
* the new width
|
155
|
* @since 3.1
|
156
|
*/
|
157
|
public void setWidth(int width) {
|
158
|
this.width = width;
|
159
|
}
|
160
|
|
161
|
/**
|
162
|
* Sets the x coordinate for this box.
|
163
|
*
|
164
|
* @param x
|
165
|
* the x coordinate
|
166
|
* @since 3.1
|
167
|
*/
|
168
|
public void setX(int x) {
|
169
|
this.x = x;
|
170
|
}
|
171
|
|
172
|
}
|