Lines 12-18
Link Here
|
12 |
|
12 |
|
13 |
import java.util.List; |
13 |
import java.util.List; |
14 |
|
14 |
|
|
|
15 |
import org.eclipse.draw2d.Graphics; |
15 |
import org.eclipse.draw2d.geometry.Dimension; |
16 |
import org.eclipse.draw2d.geometry.Dimension; |
|
|
17 |
import org.eclipse.draw2d.geometry.Point; |
18 |
import org.eclipse.draw2d.geometry.PointList; |
16 |
import org.eclipse.draw2d.geometry.Rectangle; |
19 |
import org.eclipse.draw2d.geometry.Rectangle; |
17 |
|
20 |
|
18 |
/** |
21 |
/** |
Lines 29-39
Link Here
|
29 |
extends BlockFlow |
32 |
extends BlockFlow |
30 |
{ |
33 |
{ |
31 |
|
34 |
|
|
|
35 |
/** temporarily stores the preferred size of this figure after a layout has occurred */ |
32 |
private Dimension pageSize = new Dimension(); |
36 |
private Dimension pageSize = new Dimension(); |
33 |
private int recommendedWidth; |
37 |
|
|
|
38 |
/** the recommended size for this figure to be used during layout */ |
39 |
private Dimension recommendedSize = new Dimension(); |
40 |
|
34 |
private int pageSizeCacheKeys[] = new int[3]; |
41 |
private int pageSizeCacheKeys[] = new int[3]; |
35 |
private Dimension pageSizeCacheValues[] = new Dimension[3]; |
42 |
private Dimension pageSizeCacheValues[] = new Dimension[3]; |
36 |
|
43 |
|
|
|
44 |
/** true if the text should be truncated vertically if necessary */ |
45 |
private boolean truncateVertically = false; |
46 |
|
47 |
/** |
48 |
* Returns true if the text should be truncated vertically if it is too big |
49 |
* vertically to fit in the preferred size given. |
50 |
* |
51 |
* @return true if the text should be truncated vertically if necessary |
52 |
*/ |
53 |
public boolean shouldTruncateVertically() { |
54 |
return truncateVertically; |
55 |
} |
56 |
|
57 |
/** |
58 |
* If set to true and the text is too big vertically to fit in the preferred |
59 |
* size given, a truncation decoration (by default an arrow) will be drawn |
60 |
* at the bottom of this figure. |
61 |
* |
62 |
* @param truncateVertically |
63 |
* true if the text should be truncated vertically if necessary; |
64 |
* false otherwise |
65 |
*/ |
66 |
public void setTruncateVertically(boolean truncateVertically) { |
67 |
this.truncateVertically = truncateVertically; |
68 |
} |
69 |
|
37 |
/** |
70 |
/** |
38 |
* @see org.eclipse.draw2d.Figure#addNotify() |
71 |
* @see org.eclipse.draw2d.Figure#addNotify() |
39 |
*/ |
72 |
*/ |
Lines 53-58
Link Here
|
53 |
* @see org.eclipse.draw2d.Figure#getMinimumSize(int, int) |
86 |
* @see org.eclipse.draw2d.Figure#getMinimumSize(int, int) |
54 |
*/ |
87 |
*/ |
55 |
public Dimension getMinimumSize(int w, int h) { |
88 |
public Dimension getMinimumSize(int w, int h) { |
|
|
89 |
if (shouldTruncateVertically()) { |
90 |
return getTruncatedDecorationSize(); |
91 |
} |
56 |
return getPreferredSize(w, h); |
92 |
return getPreferredSize(w, h); |
57 |
} |
93 |
} |
58 |
|
94 |
|
Lines 67-77
Link Here
|
67 |
/** |
103 |
/** |
68 |
* @see org.eclipse.draw2d.Figure#getPreferredSize(int, int) |
104 |
* @see org.eclipse.draw2d.Figure#getPreferredSize(int, int) |
69 |
*/ |
105 |
*/ |
70 |
public Dimension getPreferredSize(int width, int h) { |
106 |
public Dimension getPreferredSize(int width, int height) { |
71 |
for (int i = 0; i < 3; i++) { |
107 |
for (int i = 0; i < 3; i++) { |
72 |
if (pageSizeCacheKeys[i] == width && pageSizeCacheValues[i] != null) |
108 |
if (pageSizeCacheKeys[i] == width && pageSizeCacheValues[i] != null) |
73 |
return pageSizeCacheValues[i]; |
109 |
return pageSizeCacheValues[i]; |
74 |
} |
110 |
} |
|
|
111 |
|
112 |
Dimension sizeHint = new Dimension(width, height); |
113 |
if (!shouldTruncateVertically()) { |
114 |
// avoid triggering a layout in the children blockflows if only the |
115 |
// height has changed in this case |
116 |
sizeHint.height = -1; |
117 |
} |
75 |
|
118 |
|
76 |
pageSizeCacheKeys[2] = pageSizeCacheKeys[1]; |
119 |
pageSizeCacheKeys[2] = pageSizeCacheKeys[1]; |
77 |
pageSizeCacheKeys[1] = pageSizeCacheKeys[0]; |
120 |
pageSizeCacheKeys[1] = pageSizeCacheKeys[0]; |
Lines 81-100
Link Here
|
81 |
pageSizeCacheValues[1] = pageSizeCacheValues[0]; |
124 |
pageSizeCacheValues[1] = pageSizeCacheValues[0]; |
82 |
|
125 |
|
83 |
//Flowpage must temporarily layout to determine its preferred size |
126 |
//Flowpage must temporarily layout to determine its preferred size |
84 |
int oldWidth = getPageWidth(); |
127 |
Dimension oldSize = getPageSize(); |
85 |
setPageWidth(width); |
128 |
setPageSize(sizeHint); |
|
|
129 |
|
86 |
validate(); |
130 |
validate(); |
87 |
pageSizeCacheValues[0] = pageSize.getCopy(); |
131 |
pageSizeCacheValues[0] = pageSize.getCopy(); |
88 |
|
132 |
|
89 |
if (width != oldWidth) { |
133 |
if (sizeHint.equals(oldSize)) { |
90 |
setPageWidth(oldWidth); |
134 |
setPageSize(oldSize); |
91 |
getUpdateManager().addInvalidFigure(this); |
135 |
getUpdateManager().addInvalidFigure(this); |
92 |
} |
136 |
} |
93 |
return pageSizeCacheValues[0]; |
137 |
return pageSizeCacheValues[0]; |
94 |
} |
138 |
} |
95 |
|
139 |
|
96 |
int getPageWidth() { |
140 |
Dimension getPageSize() { |
97 |
return recommendedWidth; |
141 |
return recommendedSize; |
98 |
} |
142 |
} |
99 |
|
143 |
|
100 |
/** |
144 |
/** |
Lines 104-109
Link Here
|
104 |
Rectangle r = getBlockBox().toRectangle(); |
148 |
Rectangle r = getBlockBox().toRectangle(); |
105 |
pageSize.width = r.width; |
149 |
pageSize.width = r.width; |
106 |
pageSize.height = r.height; |
150 |
pageSize.height = r.height; |
|
|
151 |
|
152 |
if (shouldTruncateVertically() && r.height > getPageSize().height) { |
153 |
setTruncationPoint(new Point(0, getPageSize().height |
154 |
- getTruncatedDecorationSize().height)); |
155 |
} |
156 |
|
107 |
List v = getChildren(); |
157 |
List v = getChildren(); |
108 |
for (int i = 0; i < v.size(); i++) |
158 |
for (int i = 0; i < v.size(); i++) |
109 |
((FlowFigure)v.get(i)).postValidate(); |
159 |
((FlowFigure)v.get(i)).postValidate(); |
Lines 126-142
Link Here
|
126 |
return; |
176 |
return; |
127 |
boolean invalidate = getBounds().width != r.width || getBounds().height != r.height; |
177 |
boolean invalidate = getBounds().width != r.width || getBounds().height != r.height; |
128 |
super.setBounds(r); |
178 |
super.setBounds(r); |
129 |
int newWidth = r.width; |
179 |
Dimension newSize = new Dimension(r.width, r.height); |
130 |
if (invalidate || getPageWidth() != newWidth) { |
180 |
if (!shouldTruncateVertically()) { |
131 |
setPageWidth(newWidth); |
181 |
// avoid triggering a layout if only the height has changed in this case |
|
|
182 |
newSize.height = -1; |
183 |
} |
184 |
if (invalidate || !newSize.equals(getPageSize())) { |
185 |
setPageSize(newSize); |
132 |
getUpdateManager().addInvalidFigure(this); |
186 |
getUpdateManager().addInvalidFigure(this); |
133 |
} |
187 |
} |
134 |
} |
188 |
} |
135 |
|
189 |
|
136 |
private void setPageWidth(int width) { |
190 |
private void setPageSize(Dimension size) { |
137 |
if (recommendedWidth == width) |
191 |
if (size.equals(recommendedSize)) |
138 |
return; |
192 |
return; |
139 |
recommendedWidth = width; |
193 |
recommendedSize = size; |
140 |
super.invalidate(); |
194 |
super.invalidate(); |
141 |
} |
195 |
} |
142 |
|
196 |
|
Lines 150-153
Link Here
|
150 |
postValidate(); |
204 |
postValidate(); |
151 |
} |
205 |
} |
152 |
|
206 |
|
|
|
207 |
protected void layout() { |
208 |
setTruncationPoint(null); |
209 |
super.layout(); |
210 |
} |
211 |
|
212 |
protected Point getTruncationPoint() { |
213 |
if (shouldTruncateVertically()) { |
214 |
return super.getTruncationPoint(); |
215 |
} else { |
216 |
return null; |
217 |
} |
218 |
} |
219 |
|
220 |
public void paintBorder(Graphics graphics) { |
221 |
super.paintBorder(graphics); |
222 |
if (getTruncationPoint() != null) { |
223 |
paintTruncationDecoration(graphics); |
224 |
} |
225 |
} |
226 |
|
227 |
/** |
228 |
* Paints the truncation decoration. |
229 |
* |
230 |
* @param graphics |
231 |
*/ |
232 |
protected void paintTruncationDecoration(Graphics graphics) { |
233 |
Point bottomPoint = getBounds().getBottom().translate(-1, -1); |
234 |
PointList points = new PointList(3); |
235 |
points.addPoint(bottomPoint); |
236 |
points.addPoint(bottomPoint.getTranslated(-4, -4)); |
237 |
points.addPoint(bottomPoint.getTranslated(4, -4)); |
238 |
graphics.drawPolygon(points); |
239 |
} |
240 |
|
241 |
/** |
242 |
* Gets the size of the truncation decoration that will be drawn and any |
243 |
* whitespace around it. |
244 |
* |
245 |
* @return the size required for the truncation decoration |
246 |
*/ |
247 |
protected Dimension getTruncatedDecorationSize() { |
248 |
return new Dimension(10, 6); |
249 |
} |
153 |
} |
250 |
} |