37 * Constructor. |
38 * Constructor. |
38 * |
39 * |
39 * @param rowWidth - total row width. |
40 * @param rowWidth - total row width. |
40 * @param hLayout horizontal layout |
41 * @param hLayout horizontal layout |
41 */ |
42 */ |
42 Row(int rowWidth, int hLayout) { |
43 Row(int rowWidth, int hLayout) |
|
44 { |
43 this.rowWidth = rowWidth; |
45 this.rowWidth = rowWidth; |
44 setRowHLayout(hLayout); |
46 setRowHLayout(hLayout); |
45 } |
47 } |
46 |
48 |
47 /** |
49 /** |
48 * Add new LayoutObject to the Row. |
50 * Add new LayoutObject to the Row. |
49 * |
51 * |
50 * @param layoutObj structure which represents Item or part Of Item. |
52 * @param layoutObj structure which represents Item or part Of Item. |
51 */ |
53 */ |
52 void addLayoutObject(final LayoutObject layoutObj) { |
54 void addLayoutObject(final LayoutObject layoutObj) |
53 ESWTUIThreadRunner.syncExec(new Runnable() { |
55 { |
54 public void run() { |
56 ESWTUIThreadRunner.syncExec(new Runnable() |
|
57 { |
|
58 public void run() |
|
59 { |
55 eswtAddLayoutObject(layoutObj); |
60 eswtAddLayoutObject(layoutObj); |
56 } |
61 } |
57 }); |
62 }); |
58 } |
63 } |
59 |
64 |
60 /** |
65 /** |
61 * eSWT specific calls to implement addLayoutObject. |
66 * eSWT specific calls to implement addLayoutObject. |
62 * |
67 * |
63 * @param lo structure which represents Item or part Of Item. |
68 * @param lo structure which represents Item or part Of Item. |
64 */ |
69 */ |
65 void eswtAddLayoutObject(LayoutObject lo) { |
70 void eswtAddLayoutObject(LayoutObject lo) |
|
71 { |
66 layoutObjects.addElement(lo); |
72 layoutObjects.addElement(lo); |
67 // update actual occupiedSpace |
73 // update actual occupiedSpace |
68 occupiedSpace += lo.getWidth(); |
74 occupiedSpace += lo.getWidth(); |
69 // update rowHeight |
75 // update rowHeight |
70 rowHeight = Math.max(rowHeight, lo.getHeight()); |
76 rowHeight = Math.max(rowHeight, lo.getHeight()); |
71 } |
77 } |
72 |
78 |
73 /** |
79 /** |
74 * Get the number of items with the given layout. |
80 * Get the number of items with the given layout. |
75 */ |
81 */ |
76 int getNumLayoutObjects(int layoutMask) { |
82 int getNumLayoutObjects(int layoutMask) |
|
83 { |
77 int ret = 0; |
84 int ret = 0; |
78 int num = layoutObjects.size(); |
85 int num = layoutObjects.size(); |
79 LayoutObject lo = null; |
86 LayoutObject lo = null; |
80 for (int i = 0; i < num; i++) { |
87 for(int i = 0; i < num; i++) |
|
88 { |
81 lo = (LayoutObject) layoutObjects.elementAt(i); |
89 lo = (LayoutObject) layoutObjects.elementAt(i); |
82 if (lo.getOwningItem().hasLayout(layoutMask)) { |
90 if(lo.getOwningItem().hasLayout(layoutMask)) |
|
91 { |
83 ret++; |
92 ret++; |
84 } |
93 } |
85 } |
94 } |
86 return ret; |
95 return ret; |
87 } |
96 } |
89 /** |
98 /** |
90 * Get available space in the Row for layout calculation. |
99 * Get available space in the Row for layout calculation. |
91 * |
100 * |
92 * @return space available for Items on that Row in pixels. |
101 * @return space available for Items on that Row in pixels. |
93 */ |
102 */ |
94 int getFreeSpace() { |
103 int getFreeSpace() |
|
104 { |
95 return getFreeSpace(Item.LAYOUT_SHRINK | Item.LAYOUT_EXPAND); |
105 return getFreeSpace(Item.LAYOUT_SHRINK | Item.LAYOUT_EXPAND); |
96 } |
106 } |
97 |
107 |
98 /** |
108 /** |
99 * Get free space based on LAYOUT mask. Item matching the layout mask will |
109 * Get free space based on LAYOUT mask. Item matching the layout mask will |
100 * be counted with their layouting size (not actual size). Used for LAYOUT_2 |
110 * be counted with their layouting size (not actual size). Used for LAYOUT_2 |
101 * row resizing. |
111 * row resizing. |
102 * |
112 * |
103 * @param layoutMask layout mask |
113 * @param layoutMask layout mask |
104 */ |
114 */ |
105 int getFreeSpace(int layoutMask) { |
115 int getFreeSpace(int layoutMask) |
|
116 { |
106 int ret = 0; |
117 int ret = 0; |
107 int num = layoutObjects.size(); |
118 int num = layoutObjects.size(); |
108 LayoutObject lo = null; |
119 LayoutObject lo = null; |
109 for (int i = 0; i < num; i++) { |
120 for(int i = 0; i < num; i++) |
|
121 { |
110 lo = (LayoutObject) layoutObjects.elementAt(i); |
122 lo = (LayoutObject) layoutObjects.elementAt(i); |
111 ret += getObjectWidth(lo, layoutMask); |
123 ret += getObjectWidth(lo, layoutMask); |
112 } |
124 } |
113 return rowWidth - ret; |
125 return rowWidth - ret; |
114 } |
126 } |
118 * be counted with their layouting size (not actual size). Used for LAYOUT_2 |
130 * be counted with their layouting size (not actual size). Used for LAYOUT_2 |
119 * row resizing. |
131 * row resizing. |
120 * |
132 * |
121 * @param layoutMask layout mask |
133 * @param layoutMask layout mask |
122 */ |
134 */ |
123 int getRowHeight(int layoutMask) { |
135 int getRowHeight(int layoutMask) |
|
136 { |
124 int ret = 0; |
137 int ret = 0; |
125 int num = layoutObjects.size(); |
138 int num = layoutObjects.size(); |
126 LayoutObject lo = null; |
139 LayoutObject lo = null; |
127 for (int i = 0; i < num; i++) { |
140 for(int i = 0; i < num; i++) |
|
141 { |
128 lo = (LayoutObject) layoutObjects.elementAt(i); |
142 lo = (LayoutObject) layoutObjects.elementAt(i); |
129 ret = Math.max(ret, getObjectHeight(lo, layoutMask)); |
143 ret = Math.max(ret, getObjectHeight(lo, layoutMask)); |
130 } |
144 } |
131 return ret; |
145 return ret; |
132 } |
146 } |
133 |
147 |
134 private int getObjectWidth(LayoutObject lo, int layoutMask) { |
148 private int getObjectWidth(LayoutObject lo, int layoutMask) |
135 if (lo.getOwningItem().hasLayout(layoutMask)) { |
149 { |
|
150 if(lo.getOwningItem().hasLayout(layoutMask)) |
|
151 { |
136 // this returns the min/pref width |
152 // this returns the min/pref width |
137 return lo.getOwningItem().getLayoutWidth(); |
153 return lo.getOwningItem().getLayoutWidth(); |
138 } |
154 } |
139 else { |
155 else |
|
156 { |
140 return lo.getWidth(); |
157 return lo.getWidth(); |
141 } |
158 } |
142 } |
159 } |
143 |
160 |
144 private int getObjectHeight(LayoutObject lo, int layoutMask) { |
161 private int getObjectHeight(LayoutObject lo, int layoutMask) |
145 if (lo.getOwningItem().hasLayout(layoutMask)) { |
162 { |
|
163 if(lo.getOwningItem().hasLayout(layoutMask)) |
|
164 { |
146 // this returns the min/pref width |
165 // this returns the min/pref width |
147 return lo.getOwningItem().getLayoutHeight(); |
166 return lo.getOwningItem().getLayoutHeight(); |
148 } |
167 } |
149 else { |
168 else |
|
169 { |
150 return lo.getHeight(); |
170 return lo.getHeight(); |
151 } |
171 } |
152 } |
172 } |
153 |
173 |
154 /** |
174 /** |
155 * Clean row, free resources. |
175 * Clean row, free resources. |
156 * |
176 * |
157 * @param keepItem Last Item to leave in a row. |
177 * @param keepItem Last Item to leave in a row. |
158 */ |
178 */ |
159 boolean cleanRow(Item keepItem) { |
179 boolean cleanRow(Item keepItem) |
160 LayoutObject lo = null; |
180 { |
161 for (int i = (layoutObjects.size() - 1); i >= 0; i--) { |
181 LayoutObject lo = null; |
|
182 for(int i = (layoutObjects.size() - 1); i >= 0; i--) |
|
183 { |
162 lo = (LayoutObject) layoutObjects.elementAt(i); |
184 lo = (LayoutObject) layoutObjects.elementAt(i); |
163 if (keepItem != null && keepItem == lo.getOwningItem()) { |
185 if(keepItem != null && keepItem == lo.getOwningItem()) |
|
186 { |
164 updateRowInternals(); |
187 updateRowInternals(); |
165 return true; |
188 return true; |
166 } |
189 } |
167 else { |
190 else |
|
191 { |
168 layoutObjects.removeElement(lo); |
192 layoutObjects.removeElement(lo); |
169 lo.dispose(); |
193 lo.dispose(); |
170 } |
194 } |
171 } |
195 } |
172 updateRowInternals(); |
196 updateRowInternals(); |
176 /** |
200 /** |
177 * Update item positions in a row.<br> |
201 * Update item positions in a row.<br> |
178 * This method called by Layouters or FormLayoutPolicy when row is full and |
202 * This method called by Layouters or FormLayoutPolicy when row is full and |
179 * ready for layout. |
203 * ready for layout. |
180 */ |
204 */ |
181 void updateRowLayout(boolean isLeftToRight) { |
205 void updateRowLayout(boolean isLeftToRight) |
|
206 { |
182 // update xShift |
207 // update xShift |
183 xShift = ItemLayouter.getXLocation(rowWidth, occupiedSpace, rowHLayout); |
208 xShift = ItemLayouter.getXLocation(rowWidth, occupiedSpace, rowHLayout); |
184 int xDelta = 0; |
209 int xDelta = 0; |
185 LayoutObject lo = null; |
210 LayoutObject lo = null; |
186 if (isLeftToRight) { |
211 if(isLeftToRight) |
187 for (int i = 0; i < layoutObjects.size(); i++) { |
212 { |
|
213 for(int i = 0; i < layoutObjects.size(); i++) |
|
214 { |
188 lo = (LayoutObject) layoutObjects.elementAt(i); |
215 lo = (LayoutObject) layoutObjects.elementAt(i); |
189 int yDelta = ItemLayouter.getYLocation(rowHeight, |
216 int yDelta = ItemLayouter.getYLocation(rowHeight, |
190 lo.getHeight(), lo.getVerticalLayout()); |
217 lo.getHeight(), lo.getVerticalLayout()); |
191 lo.eswtSetLocation(xShift + xDelta, yShift + yDelta); |
218 lo.eswtSetLocation(xShift + xDelta, yShift + yDelta); |
192 xDelta += lo.getWidth(); |
219 xDelta += lo.getWidth(); |
193 } |
220 } |
194 } |
221 } |
195 else { |
222 else |
196 for (int i = layoutObjects.size() - 1; i > 0; i--) { |
223 { |
|
224 for(int i = layoutObjects.size() - 1; i > 0; i--) |
|
225 { |
197 lo = (LayoutObject) layoutObjects.elementAt(i); |
226 lo = (LayoutObject) layoutObjects.elementAt(i); |
198 int yDelta = ItemLayouter.getYLocation(rowHeight, |
227 int yDelta = ItemLayouter.getYLocation(rowHeight, |
199 lo.getHeight(), lo.getVerticalLayout()); |
228 lo.getHeight(), lo.getVerticalLayout()); |
200 lo.eswtSetLocation(xShift + xDelta, yShift + yDelta); |
229 lo.eswtSetLocation(xShift + xDelta, yShift + yDelta); |
201 xDelta += lo.getWidth(); |
230 xDelta += lo.getWidth(); |
202 } |
231 } |
203 } |
232 } |
204 } |
233 } |
205 |
234 |
206 /** |
235 /** |
207 * Update width and height of a row if some layout objects were removed or |
236 * Update width and height of a row if some layout objects were removed or |
208 * changed. |
237 * changed. |
209 */ |
238 */ |
210 void updateRowInternals() { |
239 void updateRowInternals() |
|
240 { |
211 int newRowHeight = 0; |
241 int newRowHeight = 0; |
212 int newOccupiedSpace = 0; |
242 int newOccupiedSpace = 0; |
213 int num = layoutObjects.size(); |
243 int num = layoutObjects.size(); |
214 LayoutObject lo = null; |
244 LayoutObject lo = null; |
215 for (int i = 0; i < num; i++) { |
245 for(int i = 0; i < num; i++) |
|
246 { |
216 lo = (LayoutObject) layoutObjects.elementAt(i); |
247 lo = (LayoutObject) layoutObjects.elementAt(i); |
217 newRowHeight = Math.max(newRowHeight, lo.getHeight()); |
248 newRowHeight = Math.max(newRowHeight, lo.getHeight()); |
218 newOccupiedSpace += lo.getWidth(); |
249 newOccupiedSpace += lo.getWidth(); |
219 } |
250 } |
220 rowHeight = newRowHeight; |
251 rowHeight = newRowHeight; |
225 * Set the yShift to corresponding in ScrolledComposite which represents |
256 * Set the yShift to corresponding in ScrolledComposite which represents |
226 * Form. |
257 * Form. |
227 * |
258 * |
228 * @param aYShift yPosition of the row inside ScrolledComposite |
259 * @param aYShift yPosition of the row inside ScrolledComposite |
229 */ |
260 */ |
230 void setYShift(int aYShift) { |
261 void setYShift(int aYShift) |
|
262 { |
231 yShift = aYShift; |
263 yShift = aYShift; |
232 } |
264 } |
233 |
265 |
234 /** |
266 /** |
235 * Get the yPosition of a Row inside of ScrolledComposite. |
267 * Get the yPosition of a Row inside of ScrolledComposite. |
236 * |
268 * |
237 * @return yShift in pixels |
269 * @return yShift in pixels |
238 */ |
270 */ |
239 int getYShift() { |
271 int getYShift() |
|
272 { |
240 return yShift; |
273 return yShift; |
241 } |
274 } |
242 |
275 |
243 /** |
276 /** |
244 * Gets the width of the row in pixels. |
277 * Gets the width of the row in pixels. |
245 * |
278 * |
246 * @return - row's total width. |
279 * @return - row's total width. |
247 */ |
280 */ |
248 int getRowWidth() { |
281 int getRowWidth() |
|
282 { |
249 return rowWidth; |
283 return rowWidth; |
250 } |
284 } |
251 |
285 |
252 /** |
286 /** |
253 * Get the height of a row in pixels (height of tallest item). |
287 * Get the height of a row in pixels (height of tallest item). |
254 * |
288 * |
255 * @return height of a row; |
289 * @return height of a row; |
256 */ |
290 */ |
257 int getRowHeight() { |
291 int getRowHeight() |
|
292 { |
258 return rowHeight; |
293 return rowHeight; |
259 } |
294 } |
260 |
295 |
261 /** |
296 /** |
262 * Get the bottom (yPosition + rowHeight) of a Row . |
297 * Get the bottom (yPosition + rowHeight) of a Row . |
263 */ |
298 */ |
264 int getBottomPosition() { |
299 int getBottomPosition() |
|
300 { |
265 return yShift + rowHeight; |
301 return yShift + rowHeight; |
266 } |
302 } |
267 |
303 |
268 /** |
304 /** |
269 * Get the yPosition of a Row's height inside of ScrolledComposite. |
305 * Get the yPosition of a Row's height inside of ScrolledComposite. |
270 * |
306 * |
271 * @param yPosition the y position |
307 * @param yPosition the y position |
272 * @return yShift + rowHeight in pixels |
308 * @return yShift + rowHeight in pixels |
273 */ |
309 */ |
274 boolean isInsideRow(int yPosition) { |
310 boolean isInsideRow(int yPosition) |
|
311 { |
275 return (yShift <= yPosition && yPosition < yShift + rowHeight); |
312 return (yShift <= yPosition && yPosition < yShift + rowHeight); |
276 } |
313 } |
277 |
314 |
278 /** |
315 /** |
279 * set new horizontal Layout of a row. |
316 * set new horizontal Layout of a row. |
280 * |
317 * |
281 * @param aRowHLayout - set new horizontal of the row. |
318 * @param aRowHLayout - set new horizontal of the row. |
282 */ |
319 */ |
283 void setRowHLayout(int aRowHLayout) { |
320 void setRowHLayout(int aRowHLayout) |
|
321 { |
284 rowHLayout = aRowHLayout; |
322 rowHLayout = aRowHLayout; |
285 } |
323 } |
286 |
324 |
287 /** |
325 /** |
288 * Get horizontal Layout of row. |
326 * Get horizontal Layout of row. |
289 * |
327 * |
290 * @return horizontal Layout of a row; |
328 * @return horizontal Layout of a row; |
291 */ |
329 */ |
292 int getRowHLayout() { |
330 int getRowHLayout() |
|
331 { |
293 return rowHLayout; |
332 return rowHLayout; |
294 } |
333 } |
295 |
334 |
296 boolean isEmpty() { |
335 boolean isEmpty() |
|
336 { |
297 return ((occupiedSpace == 0) && (layoutObjects.size() == 0)); |
337 return ((occupiedSpace == 0) && (layoutObjects.size() == 0)); |
298 } |
338 } |
299 |
339 |
300 LayoutObject getNextLayoutObject(LayoutObject lo, Item item) { |
340 LayoutObject getNextLayoutObject(LayoutObject lo, Item item) |
|
341 { |
301 int startIdx = layoutObjects.indexOf(lo); |
342 int startIdx = layoutObjects.indexOf(lo); |
302 startIdx = (startIdx < 0 ? 0 : startIdx + 1); |
343 startIdx = (startIdx < 0 ? 0 : startIdx + 1); |
303 int num = layoutObjects.size(); |
344 int num = layoutObjects.size(); |
304 LayoutObject temp = null; |
345 LayoutObject temp = null; |
305 for (int i = startIdx; i < num; i++) { |
346 for(int i = startIdx; i < num; i++) |
|
347 { |
306 temp = getLayoutObject(i); |
348 temp = getLayoutObject(i); |
307 if (item == null || item == temp.getOwningItem()) { |
349 if(item == null || item == temp.getOwningItem()) |
|
350 { |
308 return temp; |
351 return temp; |
309 } |
352 } |
310 } |
353 } |
311 return null; |
354 return null; |
312 } |
355 } |
313 |
356 |
314 LayoutObject getPrevLayoutObject(LayoutObject lo, Item item) { |
357 LayoutObject getPrevLayoutObject(LayoutObject lo, Item item) |
|
358 { |
315 int startIdx = layoutObjects.indexOf(lo); |
359 int startIdx = layoutObjects.indexOf(lo); |
316 startIdx = (startIdx < 0 ? layoutObjects.size() - 1 : startIdx - 1); |
360 startIdx = (startIdx < 0 ? layoutObjects.size() - 1 : startIdx - 1); |
317 LayoutObject temp = null; |
361 LayoutObject temp = null; |
318 for (int i = startIdx; i >= 0; i--) { |
362 for(int i = startIdx; i >= 0; i--) |
|
363 { |
319 temp = getLayoutObject(i); |
364 temp = getLayoutObject(i); |
320 if (item == null || item == temp.getOwningItem()) { |
365 if(item == null || item == temp.getOwningItem()) |
|
366 { |
321 return temp; |
367 return temp; |
322 } |
368 } |
323 } |
369 } |
324 return null; |
370 return null; |
325 } |
371 } |
326 |
372 |
327 LayoutObject getNextLayoutObject(LayoutObject lo, int layoutMask) { |
373 LayoutObject getNextLayoutObject(LayoutObject lo, int layoutMask) |
|
374 { |
328 int startIdx = layoutObjects.indexOf(lo); |
375 int startIdx = layoutObjects.indexOf(lo); |
329 startIdx = (startIdx < 0 ? 0 : startIdx + 1); |
376 startIdx = (startIdx < 0 ? 0 : startIdx + 1); |
330 int num = layoutObjects.size(); |
377 int num = layoutObjects.size(); |
331 LayoutObject temp = null; |
378 LayoutObject temp = null; |
332 for (int i = startIdx; i < num; i++) { |
379 for(int i = startIdx; i < num; i++) |
|
380 { |
333 temp = getLayoutObject(i); |
381 temp = getLayoutObject(i); |
334 if (temp.getOwningItem().hasLayout(layoutMask)) { |
382 if(temp.getOwningItem().hasLayout(layoutMask)) |
|
383 { |
335 return temp; |
384 return temp; |
336 } |
385 } |
337 } |
386 } |
338 return null; |
387 return null; |
339 } |
388 } |
340 |
389 |
341 LayoutObject getLayoutObject(int index) { |
390 LayoutObject getLayoutObject(int index) |
|
391 { |
342 return (LayoutObject) layoutObjects.elementAt(index); |
392 return (LayoutObject) layoutObjects.elementAt(index); |
343 } |
393 } |
344 |
394 |
345 int size() { |
395 int size() |
|
396 { |
346 return layoutObjects.size(); |
397 return layoutObjects.size(); |
347 } |
398 } |
348 |
399 |
349 } |
400 } |