57
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
package javax.microedition.lcdui;
|
|
18 |
|
|
19 |
import java.util.NoSuchElementException;
|
|
20 |
import java.util.Vector;
|
|
21 |
import java.util.Enumeration;
|
|
22 |
import java.util.Timer;
|
|
23 |
import java.util.TimerTask;
|
|
24 |
|
|
25 |
import org.eclipse.swt.SWT;
|
|
26 |
import org.eclipse.swt.graphics.Point;
|
|
27 |
import org.eclipse.swt.widgets.Composite;
|
|
28 |
import org.eclipse.swt.widgets.Control;
|
|
29 |
|
|
30 |
/**
|
|
31 |
* FormLayouter implements form layout algorithm.
|
|
32 |
*/
|
|
33 |
class FormLayouter
|
|
34 |
{
|
|
35 |
|
|
36 |
/**
|
|
37 |
* Form instance (not owned).
|
|
38 |
*/
|
|
39 |
private Form form;
|
|
40 |
|
|
41 |
/**
|
|
42 |
* Form's scrolled composite (not owned).
|
|
43 |
*/
|
|
44 |
protected ScrolledComposite formComposite;
|
|
45 |
|
|
46 |
/**
|
|
47 |
* Controls vector.
|
|
48 |
*/
|
|
49 |
private Vector layoutObjects = new Vector();
|
|
50 |
|
|
51 |
/**
|
|
52 |
* Rows vector.
|
|
53 |
*/
|
|
54 |
private Vector rows = new Vector();
|
|
55 |
|
|
56 |
/**
|
|
57 |
* Form's current horizontal alignment
|
|
58 |
*/
|
|
59 |
private int currentHLayoutDirective;
|
|
60 |
|
|
61 |
private ImageItemLayouter imIL;
|
|
62 |
|
|
63 |
private StringItemLayouter sIL;
|
|
64 |
|
|
65 |
private GaugeLayouter gL;
|
|
66 |
|
|
67 |
private TextFieldLayouter tfL;
|
|
68 |
|
|
69 |
private DateFieldLayouter dfL;
|
|
70 |
|
|
71 |
private ChoiceGroupLayouter cgL;
|
|
72 |
|
|
73 |
private CustomItemLayouter ciL;
|
|
74 |
|
|
75 |
private SpacerLayouter sL;
|
|
76 |
|
|
77 |
private int vPosition;
|
|
78 |
|
|
79 |
private Item deferredScrollToItem;
|
|
80 |
|
|
81 |
private boolean isCurrent;
|
|
82 |
|
|
83 |
private Control itemMainControl;
|
|
84 |
|
|
85 |
private static final int NO_DIRECTION = -1;
|
|
86 |
|
|
87 |
private Item currentSelectedItem;
|
|
88 |
|
|
89 |
private int direction = NO_DIRECTION;
|
|
90 |
|
|
91 |
private boolean mousePressed;
|
|
92 |
|
|
93 |
private LayoutObject currentlyUnderMouse;
|
|
94 |
|
|
95 |
|
|
96 |
/**
|
|
97 |
* Constructor.
|
|
98 |
*
|
|
99 |
* @param form Form to perform layout on.
|
|
100 |
*/
|
|
101 |
FormLayouter(Form form)
|
|
102 |
{
|
|
103 |
this.form = form;
|
|
104 |
formComposite = form.getFormComposite();
|
|
105 |
imIL = new ImageItemLayouter(this);
|
|
106 |
sIL = new StringItemLayouter(this);
|
|
107 |
gL = new GaugeLayouter(this);
|
|
108 |
dfL = new DateFieldLayouter(this);
|
|
109 |
tfL = new TextFieldLayouter(this);
|
|
110 |
cgL = new ChoiceGroupLayouter(this);
|
|
111 |
ciL = new CustomItemLayouter(this);
|
|
112 |
sL = new SpacerLayouter(this);
|
|
113 |
}
|
|
114 |
|
|
115 |
/**
|
|
116 |
* Dispose and cleanup layouted items.
|
|
117 |
*/
|
|
118 |
void dispose()
|
|
119 |
{
|
|
120 |
ESWTUIThreadRunner.syncExec(new Runnable()
|
|
121 |
{
|
|
122 |
public void run()
|
|
123 |
{
|
|
124 |
eswtClearRows(0, null);
|
|
125 |
removeAllLayoutObjects();
|
|
126 |
rows = null;
|
|
127 |
layoutObjects = null;
|
|
128 |
}
|
|
129 |
});
|
|
130 |
}
|
|
131 |
|
|
132 |
/**
|
|
133 |
* Log out a control with all its children at the given indentation level.
|
|
134 |
*/
|
|
135 |
void logControl(int level, Control control)
|
|
136 |
{
|
|
137 |
if(control != null)
|
|
138 |
{
|
|
139 |
String s2 = control.toString();
|
|
140 |
s2 = s2.substring(0, s2.indexOf('}') - 1);
|
|
141 |
String s3 = control.getBounds().toString();
|
|
142 |
s3 = s3.substring(s3.indexOf('{'));
|
|
143 |
Logger.verbose(Logger.indent(s2 + s3, level * 2));
|
|
144 |
if(control instanceof Composite)
|
|
145 |
{
|
|
146 |
Control[] arr = ((Composite) control).getChildren();
|
|
147 |
for(int i = 0; i < arr.length; i++)
|
|
148 |
{
|
|
149 |
logControl(level + 1, arr[i]);
|
|
150 |
}
|
|
151 |
}
|
|
152 |
}
|
|
153 |
}
|
|
154 |
|
|
155 |
/**
|
|
156 |
* Log out all layoutobjects for each item.
|
|
157 |
*/
|
|
158 |
void logFormLayout()
|
|
159 |
{
|
|
160 |
Logger.verbose(form + " ---------------------------------------------");
|
|
161 |
LayoutObject lo = null;
|
|
162 |
Item item = null;
|
|
163 |
int line = -1;
|
|
164 |
while((lo = getNextLayoutObjectOfItem(lo, null)) != null)
|
|
165 |
{
|
|
166 |
if(lo.getOwningItem() != item)
|
|
167 |
{
|
|
168 |
item = lo.getOwningItem();
|
|
169 |
Logger.verbose(item.toString());
|
|
170 |
}
|
|
171 |
if(lo.getRowIdx() != line)
|
|
172 |
{
|
|
173 |
line = lo.getRowIdx();
|
|
174 |
}
|
|
175 |
Logger.verbose(Logger.indent("Row:" + lo.getRowIdx(), 2));
|
|
176 |
logControl(2, lo.getControl());
|
|
177 |
}
|
|
178 |
Logger.verbose(form + " ---------------------------------------------");
|
|
179 |
}
|
|
180 |
|
|
181 |
/**
|
|
182 |
* Called when Form is about to be shown.<br>
|
|
183 |
* NOTE: this is called from eSWT UI-thread
|
|
184 |
*/
|
|
185 |
void handleShowCurrentEvent()
|
|
186 |
{
|
|
187 |
Logger.method(this, "handleShowCurrentEvent");
|
|
188 |
isCurrent = true;
|
|
189 |
|
|
190 |
// restore our scrolling position (eSWT resets it to 0 by default)
|
|
191 |
eswtSetScrollingPosition(vPosition, true);
|
|
192 |
|
|
193 |
Item item = null;
|
|
194 |
LayoutObject lo = null;
|
|
195 |
while((lo = getNextLayoutObjectOfItem(lo, null)) != null)
|
|
196 |
{
|
|
197 |
if(lo.getOwningItem() != item)
|
|
198 |
{
|
|
199 |
// item border
|
|
200 |
item = lo.getOwningItem();
|
|
201 |
getItemLayouter(item).eswtAddListeners(item, lo);
|
|
202 |
}
|
|
203 |
}
|
|
204 |
|
|
205 |
eswtApplyCurrentFocus();
|
|
206 |
}
|
|
207 |
|
|
208 |
/**
|
|
209 |
* Called when Form is about to be hidden.<br>
|
|
210 |
* NOTE: this is called from eSWT UI-thread
|
|
211 |
*/
|
|
212 |
void handleHideCurrentEvent()
|
|
213 |
{
|
|
214 |
Logger.method(this, "handleHideCurrentEvent");
|
|
215 |
isCurrent = false;
|
|
216 |
|
|
217 |
Item item = null;
|
|
218 |
LayoutObject lo = null;
|
|
219 |
while((lo = getNextLayoutObjectOfItem(lo, null)) != null)
|
|
220 |
{
|
|
221 |
if(lo.getOwningItem() != item)
|
|
222 |
{
|
|
223 |
// item border
|
|
224 |
item = lo.getOwningItem();
|
|
225 |
getItemLayouter(item).eswtRemoveListeners(item, lo);
|
|
226 |
getItemLayouter(item).eswtHandleVisibilityChange(item, false);
|
|
227 |
}
|
|
228 |
}
|
|
229 |
|
|
230 |
direction = NO_DIRECTION;
|
|
231 |
}
|
|
232 |
|
|
233 |
/**
|
|
234 |
* Called when Form is beeing resized.<br>
|
|
235 |
* NOTE: this is called from eSWT UI-thread
|
|
236 |
*/
|
|
237 |
void handleResizeEvent(int width, int height)
|
|
238 |
{
|
|
239 |
// Logger.method(this, "handleResizeEvent");
|
|
240 |
int numitems = getItemCount();
|
|
241 |
for(int i = 0; i < numitems; i++)
|
|
242 |
{
|
|
243 |
getItem(i).invalidateCachedSizes();
|
|
244 |
}
|
|
245 |
ItemLayouter.eswtUpdateStaticShellSize(width, height);
|
|
246 |
}
|
|
247 |
|
|
248 |
/**
|
|
249 |
* Do form layout according to startIndex.
|
|
250 |
*
|
|
251 |
* @param startItem - index of item which need to be layouted.
|
|
252 |
*/
|
|
253 |
void layoutForm(final int startIndex)
|
|
254 |
{
|
|
255 |
ESWTUIThreadRunner.syncExec(new Runnable()
|
|
256 |
{
|
|
257 |
public void run()
|
|
258 |
{
|
|
259 |
eswtLayoutForm(startIndex);
|
|
260 |
}
|
|
261 |
});
|
|
262 |
}
|
|
263 |
|
|
264 |
/**
|
|
265 |
* eSWT callback for doLayout().
|
|
266 |
*/
|
|
267 |
void eswtLayoutForm(int startIndex)
|
|
268 |
{
|
|
269 |
int numItems = getItemCount();
|
|
270 |
Logger.method(this, "eswtLayoutForm", startIndex + " / " + numItems);
|
|
271 |
|
|
272 |
eswtUpdateFormComposite(false);
|
|
273 |
if(numItems > 0)
|
|
274 |
{
|
|
275 |
Item previousItem = null;
|
|
276 |
int startRowIndex = 0;
|
|
277 |
|
|
278 |
if(startIndex > 0)
|
|
279 |
{
|
|
280 |
// Find row with previous item.
|
|
281 |
previousItem = getItem(startIndex - 1);
|
|
282 |
Row prevItemRow = getLastRowOfItem(previousItem);
|
|
283 |
if(prevItemRow != null)
|
|
284 |
{
|
|
285 |
startRowIndex = rows.indexOf(prevItemRow);
|
|
286 |
}
|
|
287 |
}
|
|
288 |
|
|
289 |
// Clear rows starting from item - partial re-layouting
|
|
290 |
eswtClearRows(startRowIndex, previousItem);
|
|
291 |
// Layout items
|
|
292 |
for(int i = startIndex; i < numItems; i++)
|
|
293 |
{
|
|
294 |
eswtLayoutItem(getItem(i));
|
|
295 |
}
|
|
296 |
// Update last row
|
|
297 |
eswtUpdateRow(getLastRow());
|
|
298 |
}
|
|
299 |
else
|
|
300 |
{
|
|
301 |
eswtClearRows(0, null);
|
|
302 |
}
|
|
303 |
// check if we need to scroll to a particular item
|
|
304 |
if(deferredScrollToItem != null)
|
|
305 |
{
|
|
306 |
eswtSetCurrentItem(deferredScrollToItem);
|
|
307 |
deferredScrollToItem = null;
|
|
308 |
}
|
|
309 |
eswtUpdateFormComposite(true);
|
|
310 |
eswtHandleVisibilityChanges();
|
|
311 |
|
|
312 |
if(Logger.isLogVerbose())
|
|
313 |
{
|
|
314 |
logFormLayout();
|
|
315 |
}
|
|
316 |
|
|
317 |
// clear invalid selected item
|
|
318 |
eswtCheckCurrentSelectedItem();
|
|
319 |
|
|
320 |
if(currentSelectedItem != null
|
|
321 |
&& (currentSelectedItem.isFocusable()))
|
|
322 |
{
|
|
323 |
eswtApplyCurrentFocus();
|
|
324 |
}
|
|
325 |
else
|
|
326 |
{
|
|
327 |
// If there's no item currently selected try to find first
|
|
328 |
// focusable item and set it current (if found):
|
|
329 |
Item found = eswtGetNextFocusableItem(
|
|
330 |
getItem(startIndex - 1), SWT.ARROW_RIGHT);
|
|
331 |
if(found != null)
|
|
332 |
{
|
|
333 |
eswtSetCurrentSelectedItem(found, NO_DIRECTION);
|
|
334 |
}
|
|
335 |
else
|
|
336 |
{
|
|
337 |
eswtApplyCurrentFocus();
|
|
338 |
}
|
|
339 |
}
|
|
340 |
}
|
|
341 |
|
|
342 |
/**
|
|
343 |
* Returns if the parameter is a eSWT directional key code.
|
|
344 |
*
|
|
345 |
* @param keyCode key code
|
|
346 |
*/
|
|
347 |
private boolean isDirectionKey(int keyCode)
|
|
348 |
{
|
|
349 |
return (keyCode == SWT.ARROW_DOWN || keyCode == SWT.ARROW_UP
|
|
350 |
|| keyCode == SWT.ARROW_LEFT || keyCode == SWT.ARROW_RIGHT);
|
|
351 |
}
|
|
352 |
|
|
353 |
/**
|
|
354 |
* Handler for key events.<br>
|
|
355 |
* The implementation moves focus and/or scrolls the form when
|
|
356 |
* needed. The method is called by the Form.
|
|
357 |
*
|
|
358 |
* @param keyCode eSWT key code.
|
|
359 |
* @param keyType eSWT key type.
|
|
360 |
*/
|
|
361 |
final void handleKeyEvent(int keyCode, int keyType)
|
|
362 |
{
|
|
363 |
Logger.method(this, "handleKeyEvent", currentSelectedItem,
|
|
364 |
String.valueOf(keyCode), String.valueOf(keyType));
|
|
365 |
|
|
366 |
boolean isDirectionalKey = isDirectionKey(keyCode);
|
|
367 |
if(keyType == SWT.KeyDown && isDirectionalKey)
|
|
368 |
{
|
|
369 |
eswtCheckCurrentSelectedItem();
|
|
370 |
}
|
|
371 |
|
|
372 |
if(currentSelectedItem != null)
|
|
373 |
{
|
|
374 |
if(getItemLayouter(currentSelectedItem).eswtOfferKeyEvent(
|
|
375 |
currentSelectedItem, keyCode, keyType))
|
|
376 |
{
|
|
377 |
// if the key has been consumed
|
|
378 |
return;
|
|
379 |
}
|
|
380 |
}
|
|
381 |
|
|
382 |
// scrolling/focus traverse only happens on directional key's down event
|
|
383 |
if(keyType == SWT.KeyDown && isDirectionalKey)
|
|
384 |
{
|
|
385 |
// try to find next focusable item
|
|
386 |
Item next = eswtGetNextFocusableItem(currentSelectedItem, keyCode);
|
|
387 |
|
|
388 |
// if no visible & focusable item was found to transfer focus
|
|
389 |
if(next == currentSelectedItem)
|
|
390 |
{
|
|
391 |
// try to scroll a bit
|
|
392 |
eswtSetScrollingPosition(getNextScrollingPosition(keyCode),
|
|
393 |
true);
|
|
394 |
// find next focusable after scrolling
|
|
395 |
next = eswtGetNextFocusableItem(currentSelectedItem, keyCode);
|
|
396 |
}
|
|
397 |
|
|
398 |
if(next != currentSelectedItem)
|
|
399 |
{
|
|
400 |
//textfield always have to be fully visible when focused.
|
|
401 |
if(next instanceof TextField)
|
|
402 |
{
|
|
403 |
eswtScrollToItem(next);
|
|
404 |
}
|
|
405 |
eswtSetCurrentSelectedItem(next, keyCode);
|
|
406 |
}
|
|
407 |
}
|
|
408 |
}
|
|
409 |
|
|
410 |
/**
|
|
411 |
* Handler for pointer events.<br>
|
|
412 |
* The method is called by the Form.
|
|
413 |
*
|
|
414 |
* @param x coordinate relative to scrolledComposite
|
|
415 |
* @param y coordinate relative to scrolledComposite
|
|
416 |
* @param type event type: SWT.MouseDown, SWT.MouseMove, SWT.MouseUp
|
|
417 |
*/
|
|
418 |
final void handlePointerEvent(int x, int y, int type)
|
|
419 |
{
|
|
420 |
Logger.method(this, "handlePointerEvent", String.valueOf(x),
|
|
421 |
String.valueOf(y), String.valueOf(type));
|
|
422 |
|
|
423 |
// TODO: change when DirectUI style arrives.
|
|
424 |
/*
|
|
425 |
Item item;
|
|
426 |
if (type == SWT.MouseMove) {
|
|
427 |
if (currentlyUnderMouse == null
|
|
428 |
|| !currentlyUnderMouse.contains(x, y)) {
|
|
429 |
if (currentlyUnderMouse != null) {
|
|
430 |
//currentlyUnderMouse.getControl().setCapture(false);
|
|
431 |
}
|
|
432 |
item = eswtFindItemUnderMouse(x, y);
|
|
433 |
if (item != null && item != currentSelectedItem
|
|
434 |
&& item.isFocusable()) {
|
|
435 |
setCurrentItem(item);
|
|
436 |
item.internalSetFocused(true);
|
|
437 |
eswtSetCurrentSelectedItem(item);
|
|
438 |
//following method causes all mouse events delivered to it
|
|
439 |
|
|
440 |
currentlyUnderMouse.getControl().setCapture(true);
|
|
441 |
Logger.warning("seting capture to:" + item);
|
|
442 |
}
|
|
443 |
}
|
|
444 |
int currentVPosition = getVPosition();
|
|
445 |
boolean isMouseDirectionUp = false;
|
|
446 |
boolean doScrolling = false;
|
|
447 |
int localY = y;
|
|
448 |
|
|
449 |
if (y <= currentVPosition) {
|
|
450 |
localY = Math.max(0, y);
|
|
451 |
eswtSetScrollingPosition(localY, true);
|
|
452 |
isMouseDirectionUp = true;
|
|
453 |
doScrolling = true;
|
|
454 |
}
|
|
455 |
else if (y > (currentVPosition + getFormHeight())) {
|
|
456 |
//check for maxVPosition
|
|
457 |
if (y > (eswtGetMaxVPosition() + getFormHeight())) {
|
|
458 |
localY = eswtGetMaxVPosition() + getFormHeight();
|
|
459 |
}
|
|
460 |
else {
|
|
461 |
localY = y;
|
|
462 |
}
|
|
463 |
currentVPosition = localY - getFormHeight();
|
|
464 |
eswtSetScrollingPosition(currentVPosition, true);
|
|
465 |
|
|
466 |
isMouseDirectionUp = false;
|
|
467 |
doScrolling = true;
|
|
468 |
}
|
|
469 |
if (mousePressed && doScrolling) {
|
|
470 |
resetEventTimer(isMouseDirectionUp, localY);
|
|
471 |
}
|
|
472 |
}
|
|
473 |
else
|
|
474 |
if (type == SWT.MouseDown) {
|
|
475 |
mousePressed = true;
|
|
476 |
item = eswtFindItemUnderMouse(x, y);
|
|
477 |
if (item != null && item != currentSelectedItem
|
|
478 |
&& item.isFocusable() && getForm().getShell() ==
|
|
479 |
getForm().getShell().getDisplay().getActiveShell()) {
|
|
480 |
//eswtScrollToItem(item);
|
|
481 |
//following method causes all mouse events delivered to it
|
|
482 |
|
|
483 |
//currentlyUnderMouse.getControl().setCapture(true);
|
|
484 |
}
|
|
485 |
}
|
|
486 |
else if (type == SWT.MouseUp) {
|
|
487 |
mousePressed = false;
|
|
488 |
if (currentlyUnderMouse != null) {
|
|
489 |
//currentlyUnderMouse.getControl().setCapture(false);
|
|
490 |
}
|
|
491 |
}*/
|
|
492 |
}
|
|
493 |
|
|
494 |
/**
|
|
495 |
* Find item at the specified point.
|
|
496 |
*
|
|
497 |
* @param x coordinate.
|
|
498 |
* @param y coordinate.
|
|
499 |
* @return Item.
|
|
500 |
*/
|
|
501 |
Item eswtFindItemUnderMouse(int x, int y)
|
|
502 |
{
|
|
503 |
Row itemRow;
|
|
504 |
for(int i = 0; i < getRowCount(); i++)
|
|
505 |
{
|
|
506 |
itemRow = getRow(i);
|
|
507 |
if(itemRow.getYShift() <= y && y <= itemRow.getBottomPosition())
|
|
508 |
{
|
|
509 |
LayoutObject lo;
|
|
510 |
for(int j = 0; j < itemRow.size(); j++)
|
|
511 |
{
|
|
512 |
lo = itemRow.getLayoutObject(j);
|
|
513 |
if(lo.contains(x, y))
|
|
514 |
{
|
|
515 |
Logger.info("Item under mouse: "
|
|
516 |
+ lo.getOwningItem());
|
|
517 |
currentlyUnderMouse = lo;
|
|
518 |
return lo.getOwningItem();
|
|
519 |
}
|
|
520 |
}
|
|
521 |
break;
|
|
522 |
}
|
|
523 |
}
|
|
524 |
return null;
|
|
525 |
}
|
|
526 |
|
|
527 |
/**
|
|
528 |
* Gets next (or nearest) focusable item.
|
|
529 |
*
|
|
530 |
* @param fromItem Item where to start to search the next focusable item.
|
|
531 |
* @param dir Search direction, one of the arrow key constants defined
|
|
532 |
* in class SWT.
|
|
533 |
*
|
|
534 |
* @return Nearest focusable item or null if no item found.
|
|
535 |
*/
|
|
536 |
final Item eswtGetNextFocusableItem(Item fromItem, int dir)
|
|
537 |
{
|
|
538 |
Item nextItem = fromItem;
|
|
539 |
|
|
540 |
switch(dir)
|
|
541 |
{
|
|
542 |
case SWT.ARROW_RIGHT:
|
|
543 |
{
|
|
544 |
LayoutObject obj = getLastLayoutObjectOfItem(fromItem);
|
|
545 |
while((obj = getNextLayoutObjectOfItem(obj, null)) != null)
|
|
546 |
{
|
|
547 |
Item owner = obj.getOwningItem();
|
|
548 |
if(owner != null && owner != fromItem
|
|
549 |
&& owner.isFocusable()
|
|
550 |
&& isPartiallyVisible(obj, Config.DFI_VISIBILITY_PERCENT))
|
|
551 |
{
|
|
552 |
nextItem = owner;
|
|
553 |
break;
|
|
554 |
}
|
|
555 |
}
|
|
556 |
break;
|
|
557 |
}
|
|
558 |
|
|
559 |
case SWT.ARROW_LEFT:
|
|
560 |
{
|
|
561 |
LayoutObject obj = getFirstLayoutObjectOfItem(fromItem);
|
|
562 |
while((obj = getPrevLayoutObjectOfItem(obj, null)) != null)
|
|
563 |
{
|
|
564 |
Item owner = obj.getOwningItem();
|
|
565 |
if(owner != null && owner != fromItem
|
|
566 |
&& owner.isFocusable()
|
|
567 |
&& isPartiallyVisible(obj, Config.DFI_VISIBILITY_PERCENT))
|
|
568 |
{
|
|
569 |
nextItem = owner;
|
|
570 |
break;
|
|
571 |
}
|
|
572 |
}
|
|
573 |
break;
|
|
574 |
}
|
|
575 |
|
|
576 |
case SWT.ARROW_DOWN:
|
|
577 |
{
|
|
578 |
int minDist = Integer.MAX_VALUE;
|
|
579 |
LayoutObject start = getLastLayoutObjectOfItem(fromItem);
|
|
580 |
LayoutObject obj = start;
|
|
581 |
while((obj = getNextLayoutObjectOfItem(obj, null)) != null)
|
|
582 |
{
|
|
583 |
Item owner = obj.getOwningItem();
|
|
584 |
if(owner != null && owner != fromItem
|
|
585 |
&& owner.isFocusable() && obj.isBelow(start)
|
|
586 |
&& isPartiallyVisible(obj, Config.DFI_VISIBILITY_PERCENT))
|
|
587 |
{
|
|
588 |
int dist = obj.distanceTo(start);
|
|
589 |
if(dist < minDist)
|
|
590 |
{
|
|
591 |
minDist = dist;
|
|
592 |
nextItem = owner;
|
|
593 |
}
|
|
594 |
}
|
|
595 |
}
|
|
596 |
break;
|
|
597 |
}
|
|
598 |
|
|
599 |
case SWT.ARROW_UP:
|
|
600 |
{
|
|
601 |
int minDist = Integer.MAX_VALUE;
|
|
602 |
LayoutObject start = getFirstLayoutObjectOfItem(fromItem);
|
|
603 |
LayoutObject obj = start;
|
|
604 |
while((obj = getPrevLayoutObjectOfItem(obj, null)) != null)
|
|
605 |
{
|
|
606 |
Item owner = obj.getOwningItem();
|
|
607 |
if(owner != null && owner != fromItem
|
|
608 |
&& owner.isFocusable() && obj.isAbove(start)
|
|
609 |
&& isPartiallyVisible(obj, Config.DFI_VISIBILITY_PERCENT))
|
|
610 |
{
|
|
611 |
int dist = obj.distanceTo(start);
|
|
612 |
if(dist < minDist)
|
|
613 |
{
|
|
614 |
minDist = dist;
|
|
615 |
nextItem = owner;
|
|
616 |
}
|
|
617 |
}
|
|
618 |
}
|
|
619 |
break;
|
|
620 |
}
|
|
621 |
|
|
622 |
default:
|
|
623 |
}
|
|
624 |
|
|
625 |
return nextItem;
|
|
626 |
}
|
|
627 |
|
|
628 |
/**
|
|
629 |
* Check if the currentSelectedItem is valid and visible. If not then it
|
|
630 |
* sets it to null.
|
|
631 |
*/
|
|
632 |
final void eswtCheckCurrentSelectedItem()
|
|
633 |
{
|
|
634 |
if(currentSelectedItem != null)
|
|
635 |
{
|
|
636 |
if(currentSelectedItem.getParent() != getForm()
|
|
637 |
|| !currentSelectedItem.isVisible())
|
|
638 |
{
|
|
639 |
// we need to find another
|
|
640 |
Logger.method(this, "eswtCheckCurrentSelectedItem");
|
|
641 |
eswtSetCurrentSelectedItem(null, NO_DIRECTION);
|
|
642 |
}
|
|
643 |
}
|
|
644 |
}
|
|
645 |
|
|
646 |
/**
|
|
647 |
* Sets currentSelectedItem and sets focus to it.<br>
|
|
648 |
* If one of form's items is already selected when this method is called,
|
|
649 |
* removes focus from old item and then moves focus to new one.
|
|
650 |
*
|
|
651 |
* @param item Item to set as current selected. If null, nothing happens.
|
|
652 |
* @param dir Direction which is delivered to layouter.
|
|
653 |
*/
|
|
654 |
void eswtSetCurrentSelectedItem(Item item, int dir)
|
|
655 |
{
|
|
656 |
if(currentSelectedItem != item)
|
|
657 |
{
|
|
658 |
Logger.info(this + "::SelectedItem: "
|
|
659 |
+ currentSelectedItem + " --(" + dir + ")--> " + item);
|
|
660 |
|
|
661 |
// Save direction
|
|
662 |
direction = dir;
|
|
663 |
// Remove focus from currentSelectedItem and notify its Layouter.
|
|
664 |
if(currentSelectedItem != null)
|
|
665 |
{
|
|
666 |
getItemLayouter(currentSelectedItem).eswtFocusLost(
|
|
667 |
currentSelectedItem);
|
|
668 |
}
|
|
669 |
|
|
670 |
// Set new currentSelectedItem, must be focusable or null
|
|
671 |
currentSelectedItem = item;
|
|
672 |
|
|
673 |
// Set focus to currentSelectedItem and notify its Layouter.
|
|
674 |
if(currentSelectedItem != null)
|
|
675 |
{
|
|
676 |
getItemLayouter(currentSelectedItem).eswtFocusGained(
|
|
677 |
currentSelectedItem, dir);
|
|
678 |
}
|
|
679 |
|
|
680 |
// Apply eSWT focus to currentSelectedItem's control
|
|
681 |
eswtApplyCurrentFocus();
|
|
682 |
}
|
|
683 |
}
|
|
684 |
|
|
685 |
/**
|
|
686 |
* Sets currentSelectedItem and sets focus to it.<br>
|
|
687 |
* If one of form's items is already selected when this method is called,
|
|
688 |
* removes focus from old item and then moves focus to new one.
|
|
689 |
*
|
|
690 |
* @param item Item to set as current selected. If null, nothing happens.
|
|
691 |
* @param dir Direction which is delivered to layouter.
|
|
692 |
*/
|
|
693 |
void eswtSetCurrentSelectedItem(Item item)
|
|
694 |
{
|
|
695 |
if(currentSelectedItem != item)
|
|
696 |
{
|
|
697 |
Logger.info(this + "::SelectedItem: "
|
|
698 |
+ currentSelectedItem + " ---> " + item);
|
|
699 |
|
|
700 |
// Remove focus from currentSelectedItem and notify its Layouter.
|
|
701 |
if(currentSelectedItem != null)
|
|
702 |
{
|
|
703 |
getItemLayouter(currentSelectedItem).eswtFocusLost(
|
|
704 |
currentSelectedItem);
|
|
705 |
}
|
|
706 |
|
|
707 |
// Set new currentSelectedItem, must be focusable or null
|
|
708 |
currentSelectedItem = item;
|
|
709 |
|
|
710 |
// Set focus to currentSelectedItem and notify its Layouter.
|
|
711 |
if(currentSelectedItem != null)
|
|
712 |
{
|
|
713 |
getItemLayouter(currentSelectedItem).eswtFocusGained(
|
|
714 |
currentSelectedItem, NO_DIRECTION);
|
|
715 |
}
|
|
716 |
|
|
717 |
// Apply eSWT focus to currentSelectedItem's control
|
|
718 |
//eswtApplyCurrentFocus();
|
|
719 |
}
|
|
720 |
}
|
|
721 |
|
|
722 |
/**
|
|
723 |
* Sets focus to currentSelectedItem's control if its partially visible.
|
|
724 |
* Otherwise it sets dummy focus to form's composite.<br>
|
|
725 |
* <br>
|
|
726 |
* Note that this method applies focus only to eSWT control. Item focus
|
|
727 |
* update and layouter notifications are handled in method
|
|
728 |
* <code>eswtSetCurrentSelectedItem()</code>.<br>
|
|
729 |
* If currentSelectedItem is null or form is not shown, this method has no
|
|
730 |
* effect.
|
|
731 |
*/
|
|
732 |
void eswtApplyCurrentFocus()
|
|
733 |
{
|
|
734 |
if(isFormCurrent())
|
|
735 |
{
|
|
736 |
// if any of the Item's LayoutObjects is visible
|
|
737 |
if(isItemPartiallyVisible(currentSelectedItem))
|
|
738 |
{
|
|
739 |
Logger.method(this, "ApplyFocus", currentSelectedItem);
|
|
740 |
eswtSetFocusToFirstControl(currentSelectedItem);
|
|
741 |
}
|
|
742 |
else
|
|
743 |
{
|
|
744 |
Logger.method(this, "ApplyFocus", "dummy");
|
|
745 |
formComposite.forceFocus();
|
|
746 |
}
|
|
747 |
}
|
|
748 |
}
|
|
749 |
|
|
750 |
/**
|
|
751 |
* If the Item is valid and it is layouted, then sets the Item's first
|
|
752 |
* LayoutObject focused.
|
|
753 |
*
|
|
754 |
* @param item an item which first LayoutObject is set focused.
|
|
755 |
*/
|
|
756 |
void eswtSetFocusToFirstControl(Item item)
|
|
757 |
{
|
|
758 |
if(item != null && item.isFocusable())
|
|
759 |
{
|
|
760 |
LayoutObject lo = getFirstLayoutObjectOfItem(item);
|
|
761 |
if(lo != null)
|
|
762 |
{
|
|
763 |
lo.getControl().forceFocus();
|
|
764 |
}
|
|
765 |
}
|
|
766 |
}
|
|
767 |
|
|
768 |
/**
|
|
769 |
* Gets Current selected item.
|
|
770 |
*
|
|
771 |
* @return Current selected item. May also return null.
|
|
772 |
*/
|
|
773 |
Item getCurrentSelectedItem()
|
|
774 |
{
|
|
775 |
return currentSelectedItem;
|
|
776 |
}
|
|
777 |
|
|
778 |
/**
|
|
779 |
* Get the direction of scrolling.
|
|
780 |
*
|
|
781 |
* @return direction of scrolling.
|
|
782 |
*/
|
|
783 |
int getDirection()
|
|
784 |
{
|
|
785 |
return direction;
|
|
786 |
}
|
|
787 |
|
|
788 |
/**
|
|
789 |
* Set focus to an item if it is focusable and scroll form to make it
|
|
790 |
* visible if it is not.
|
|
791 |
*
|
|
792 |
* @param item Item to set as current item.
|
|
793 |
*/
|
|
794 |
void setCurrentItem(final Item item)
|
|
795 |
{
|
|
796 |
Logger.method(this, "setCurrentItem", item);
|
|
797 |
ESWTUIThreadRunner.syncExec(new Runnable()
|
|
798 |
{
|
|
799 |
public void run()
|
|
800 |
{
|
|
801 |
eswtSetCurrentItem(item);
|
|
802 |
}
|
|
803 |
});
|
|
804 |
}
|
|
805 |
|
|
806 |
/**
|
|
807 |
* eSWT callback for setCurrentItem.
|
|
808 |
*/
|
|
809 |
boolean eswtSetCurrentItem(Item item)
|
|
810 |
{
|
|
811 |
if(item != null)
|
|
812 |
{
|
|
813 |
if(isItemLayouted(item))
|
|
814 |
{
|
|
815 |
eswtScrollToItem(item);
|
|
816 |
deferredScrollToItem = null;
|
|
817 |
|
|
818 |
if(item.isFocusable())
|
|
819 |
{
|
|
820 |
eswtSetCurrentSelectedItem(item, NO_DIRECTION);
|
|
821 |
Logger.info("eswtSetCurrentItem" + item);
|
|
822 |
}
|
|
823 |
return true;
|
|
824 |
}
|
|
825 |
else
|
|
826 |
{
|
|
827 |
deferredScrollToItem = item;
|
|
828 |
}
|
|
829 |
}
|
|
830 |
return false;
|
|
831 |
}
|
|
832 |
|
|
833 |
void eswtScrollToItem(Item item)
|
|
834 |
{
|
|
835 |
if(item != null)
|
|
836 |
{
|
|
837 |
int pos = getItemBottomPosition(item) - getFormHeight();
|
|
838 |
if(!isItemPartiallyVisible(item))
|
|
839 |
{
|
|
840 |
eswtSetScrollingPosition(pos, true);
|
|
841 |
}
|
|
842 |
else if(item instanceof TextField && !isItemFullyVisible(item))
|
|
843 |
{
|
|
844 |
eswtSetScrollingPosition(pos, true);
|
|
845 |
}
|
|
846 |
}
|
|
847 |
}
|
|
848 |
|
|
849 |
void eswtScrolltoRegion(int yTop, int yBottom, int swtDir)
|
|
850 |
{
|
|
851 |
if(yTop < vPosition || yBottom > vPosition + getFormHeight())
|
|
852 |
{
|
|
853 |
// if the region is somewhat outside the screen
|
|
854 |
if(swtDir == SWT.ARROW_DOWN || swtDir == SWT.ARROW_RIGHT)
|
|
855 |
{
|
|
856 |
// align to top
|
|
857 |
eswtSetScrollingPosition(yTop, true);
|
|
858 |
}
|
|
859 |
else
|
|
860 |
{
|
|
861 |
// align to bottom
|
|
862 |
eswtSetScrollingPosition(yBottom - getFormHeight(), true);
|
|
863 |
}
|
|
864 |
}
|
|
865 |
}
|
|
866 |
|
|
867 |
void eswtScrollIfNeeded(final int top, final int bottom)
|
|
868 |
{
|
|
869 |
if(bottom > vPosition + getFormHeight())
|
|
870 |
{
|
|
871 |
eswtSetScrollingPosition(bottom - (getFormHeight() / 2), true);
|
|
872 |
}
|
|
873 |
else if(top < vPosition)
|
|
874 |
{
|
|
875 |
eswtSetScrollingPosition(bottom - (getFormHeight() / 2), true);
|
|
876 |
}
|
|
877 |
}
|
|
878 |
|
|
879 |
/**
|
|
880 |
* Get control's position relative to composite.
|
|
881 |
*/
|
|
882 |
void getControlPositionOnComposite(Control control, Point location)
|
|
883 |
{
|
|
884 |
if(control != formComposite)
|
|
885 |
{
|
|
886 |
Point rel = control.getLocation();
|
|
887 |
location.x += rel.x;
|
|
888 |
location.y += rel.y;
|
|
889 |
getControlPositionOnComposite(control.getParent(), location);
|
|
890 |
}
|
|
891 |
}
|
|
892 |
|
|
893 |
/**
|
|
894 |
* eSWT specific calls to do update ScrolledComposite.
|
|
895 |
*/
|
|
896 |
private void eswtUpdateFormComposite(boolean show)
|
|
897 |
{
|
|
898 |
if(getRowCount() > 0)
|
|
899 |
{
|
|
900 |
if(show)
|
|
901 |
{
|
|
902 |
formComposite.updateScrollbar(getLastRow().getBottomPosition());
|
|
903 |
formComposite.pack();
|
|
904 |
}
|
|
905 |
}
|
|
906 |
// Could happen if changing item from very tall to very short.
|
|
907 |
// so we have to update VPosition
|
|
908 |
if(getVPosition() > eswtGetMaxVPosition())
|
|
909 |
{
|
|
910 |
eswtSetScrollingPosition(eswtGetMaxVPosition(), false);
|
|
911 |
}
|
|
912 |
|
|
913 |
formComposite.setRedraw(show);
|
|
914 |
formComposite.setVisible(show);
|
|
915 |
}
|
|
916 |
|
|
917 |
/**
|
|
918 |
* Clean all form rows starting from startIndex.
|
|
919 |
*
|
|
920 |
* @param startIndex Start row from which to clean.
|
|
921 |
* @param keepItem - item in a startRow which shouldn't be recreated.
|
|
922 |
*/
|
|
923 |
private void eswtClearRows(int startIndex, Item keepItem)
|
|
924 |
{
|
|
925 |
Logger.method(this, "clearRows", String.valueOf(startIndex), keepItem);
|
|
926 |
Row row = null;
|
|
927 |
for(int i = (getRowCount() - 1); i >= startIndex; i--)
|
|
928 |
{
|
|
929 |
row = getRow(i);
|
|
930 |
if(row.cleanRow(keepItem))
|
|
931 |
{
|
|
932 |
break;
|
|
933 |
}
|
|
934 |
else
|
|
935 |
{
|
|
936 |
rows.removeElement(row);
|
|
937 |
}
|
|
938 |
}
|
|
939 |
|
|
940 |
// one row always should be available.
|
|
941 |
if((getRowCount() == 0))
|
|
942 |
{
|
|
943 |
// rows.addElement(tempRow);
|
|
944 |
currentHLayoutDirective = Item.LAYOUT_DEFAULT;
|
|
945 |
Row newRow = new Row(ItemLayouter.getMaximumItemWidth(null),
|
|
946 |
getCurrentHLayoutDirective());
|
|
947 |
rows.addElement(newRow);
|
|
948 |
}
|
|
949 |
}
|
|
950 |
|
|
951 |
/**
|
|
952 |
* Update Row's internal layout. Handles LAYOUT_2 related post-processing.
|
|
953 |
*
|
|
954 |
* @param row Row
|
|
955 |
*/
|
|
956 |
private void eswtUpdateRow(Row row)
|
|
957 |
{
|
|
958 |
if(row != null)
|
|
959 |
{
|
|
960 |
//Logger.verbose("updateRow start: " + row);
|
|
961 |
int numShrink = row.getNumLayoutObjects(Item.LAYOUT_SHRINK);
|
|
962 |
int numExpand = row.getNumLayoutObjects(Item.LAYOUT_EXPAND);
|
|
963 |
//Logger.verbose("shrink: " + numShrink + " expand: " + numExpand);
|
|
964 |
|
|
965 |
int vMask = Item.LAYOUT_VSHRINK | Item.LAYOUT_VEXPAND;
|
|
966 |
// Expand items vertically with VSHRINK or VEXPAND layout directive
|
|
967 |
LayoutObject lo = null;
|
|
968 |
int maxHeight = row.getRowHeight(vMask);
|
|
969 |
while((lo = row.getNextLayoutObject(lo, vMask)) != null)
|
|
970 |
{
|
|
971 |
if(lo.getOwningItem().hasLayout(Item.LAYOUT_VSHRINK))
|
|
972 |
{
|
|
973 |
int pref = lo.getOwningItem().getPreferredHeight();
|
|
974 |
getItemLayouter(lo.getOwningItem()).eswtResizeObject(lo,
|
|
975 |
lo.getWidth(), Math.min(pref, maxHeight));
|
|
976 |
}
|
|
977 |
else if(lo.getOwningItem().hasLayout(Item.LAYOUT_VEXPAND))
|
|
978 |
{
|
|
979 |
getItemLayouter(lo.getOwningItem()).eswtResizeObject(lo,
|
|
980 |
lo.getWidth(), maxHeight);
|
|
981 |
}
|
|
982 |
}
|
|
983 |
|
|
984 |
// Expand items with SHRINK layout directive
|
|
985 |
if(numShrink > 0)
|
|
986 |
{
|
|
987 |
// Get extra space before shrink and expand
|
|
988 |
int offset = row.getFreeSpace() / numShrink;
|
|
989 |
// Logger.verbose("shrinkOffset: " + offset);
|
|
990 |
if(offset >= 0)
|
|
991 |
{
|
|
992 |
while((lo = row.getNextLayoutObject(lo, Item.LAYOUT_SHRINK)) != null)
|
|
993 |
{
|
|
994 |
int pref = lo.getOwningItem().getPreferredWidth();
|
|
995 |
int min = lo.getOwningItem().getMinimumWidth();
|
|
996 |
int itemWidth = Math.min(pref, min + offset);
|
|
997 |
getItemLayouter(lo.getOwningItem()).eswtResizeObject(lo,
|
|
998 |
itemWidth, lo.getHeight());
|
|
999 |
}
|
|
1000 |
}
|
|
1001 |
}
|
|
1002 |
|
|
1003 |
// Expand items with EXPAND layout directive
|
|
1004 |
if(numExpand > 0)
|
|
1005 |
{
|
|
1006 |
// Get extra space after shrink but before expand
|
|
1007 |
int offset = row.getFreeSpace(Item.LAYOUT_EXPAND) / numExpand;
|
|
1008 |
if(offset >= 0)
|
|
1009 |
{
|
|
1010 |
// Logger.verbose("expandOffset: " + offset);
|
|
1011 |
while((lo = row.getNextLayoutObject(lo, Item.LAYOUT_EXPAND)) != null)
|
|
1012 |
{
|
|
1013 |
int pref = lo.getOwningItem().getPreferredWidth();
|
|
1014 |
getItemLayouter(lo.getOwningItem()).eswtResizeObject(lo,
|
|
1015 |
pref + offset, lo.getHeight());
|
|
1016 |
}
|
|
1017 |
}
|
|
1018 |
}
|
|
1019 |
|
|
1020 |
//if (numShrink > 0 || numExpand > 0) {
|
|
1021 |
row.updateRowInternals();
|
|
1022 |
//}
|
|
1023 |
|
|
1024 |
row.updateRowLayout(form.getLeftRightLanguage());
|
|
1025 |
// Logger.verbose("updateRow: " + row);
|
|
1026 |
}
|
|
1027 |
}
|
|
1028 |
|
|
1029 |
/**
|
|
1030 |
* Add a new Row.
|
|
1031 |
*/
|
|
1032 |
private Row eswtAddNewRow()
|
|
1033 |
{
|
|
1034 |
Row lastRow = getLastRow();
|
|
1035 |
eswtUpdateRow(lastRow);
|
|
1036 |
int yShift = (lastRow == null ? 0 : lastRow.getBottomPosition());
|
|
1037 |
// create new Row
|
|
1038 |
Row newRow = new Row(ItemLayouter.getMaximumItemWidth(null),
|
|
1039 |
getCurrentHLayoutDirective());
|
|
1040 |
newRow.setYShift(yShift);
|
|
1041 |
rows.addElement(newRow);
|
|
1042 |
return newRow;
|
|
1043 |
}
|
|
1044 |
|
|
1045 |
/**
|
|
1046 |
* Add a LayoutObject to the last Row.
|
|
1047 |
*
|
|
1048 |
* @param layoutObject the layout object
|
|
1049 |
*/
|
|
1050 |
void eswtAddNewLayoutObject(LayoutObject layoutObject)
|
|
1051 |
{
|
|
1052 |
if(!layoutObjects.contains(layoutObject))
|
|
1053 |
{
|
|
1054 |
layoutObjects.addElement(layoutObject);
|
|
1055 |
}
|
|
1056 |
Row lastRow = getLastRow();
|
|
1057 |
// check if the current Row is full
|
|
1058 |
if(!lastRow.isEmpty()
|
|
1059 |
&& lastRow.getFreeSpace() < layoutObject.getWidth())
|
|
1060 |
{
|
|
1061 |
lastRow = eswtAddNewRow();
|
|
1062 |
}
|
|
1063 |
lastRow.eswtAddLayoutObject(layoutObject);
|
|
1064 |
layoutObject.setRowIdx(getRowCount() - 1);
|
|
1065 |
}
|
|
1066 |
|
|
1067 |
/**
|
|
1068 |
* Optionally add a new Row and adds a LayoutObject.
|
|
1069 |
*
|
|
1070 |
* @param layoutObject the layout object
|
|
1071 |
* @param newRow adds a new row if true. If false, adds new row only if
|
|
1072 |
* there's no space for layoutObject in current row.
|
|
1073 |
*/
|
|
1074 |
void eswtAddNewLayoutObject(LayoutObject layoutObject, boolean newRow)
|
|
1075 |
{
|
|
1076 |
if(newRow)
|
|
1077 |
{
|
|
1078 |
eswtAddNewRow();
|
|
1079 |
}
|
|
1080 |
eswtAddNewLayoutObject(layoutObject);
|
|
1081 |
}
|
|
1082 |
|
|
1083 |
/**
|
|
1084 |
* Layout item in a row, if needed new row is added.
|
|
1085 |
*
|
|
1086 |
* @param row - where to startLayout.
|
|
1087 |
* @param item - Item to Layout
|
|
1088 |
*/
|
|
1089 |
private void eswtLayoutItem(Item item)
|
|
1090 |
{
|
|
1091 |
Row lastRow = getLastRow();
|
|
1092 |
boolean hlChange = setCurrentHLayoutDirective(item.internalGetLayout());
|
|
1093 |
if(hlChange || getItemNewLineBefore(item))
|
|
1094 |
{
|
|
1095 |
// newline directive or horizontal layout changed
|
|
1096 |
if(lastRow.isEmpty())
|
|
1097 |
{
|
|
1098 |
// if the current/last row is empty - use that
|
|
1099 |
lastRow.setRowHLayout(getCurrentHLayoutDirective());
|
|
1100 |
}
|
|
1101 |
else
|
|
1102 |
{
|
|
1103 |
eswtAddNewRow();
|
|
1104 |
}
|
|
1105 |
}
|
|
1106 |
|
|
1107 |
// Use the specific layouter to layout item in the last row
|
|
1108 |
getItemLayouter(item).eswtLayoutItem(getLastRow(), item);
|
|
1109 |
|
|
1110 |
if(form.eswtIsShown())
|
|
1111 |
{
|
|
1112 |
LayoutObject lo = getFirstLayoutObjectOfItem(item);
|
|
1113 |
if(lo != null)
|
|
1114 |
{
|
|
1115 |
getItemLayouter(item).eswtAddListeners(item, lo);
|
|
1116 |
}
|
|
1117 |
}
|
|
1118 |
|
|
1119 |
if(getItemNewLineAfter(item))
|
|
1120 |
{
|
|
1121 |
eswtAddNewRow();
|
|
1122 |
}
|
|
1123 |
}
|
|
1124 |
|
|
1125 |
/**
|
|
1126 |
* Set Form's Layout directive. if it differ from current set flag
|
|
1127 |
* startFromNewLine = true;
|
|
1128 |
*
|
|
1129 |
* @param newLayoutDirective
|
|
1130 |
* @return true if a layout change has occured
|
|
1131 |
*/
|
|
1132 |
private boolean setCurrentHLayoutDirective(int newLayoutDirective)
|
|
1133 |
{
|
|
1134 |
int newHLayoutDirective = Item.getHorizontalLayout(newLayoutDirective);
|
|
1135 |
if((newHLayoutDirective != currentHLayoutDirective)
|
|
1136 |
&& (newHLayoutDirective != Item.LAYOUT_DEFAULT))
|
|
1137 |
{
|
|
1138 |
currentHLayoutDirective = newHLayoutDirective;
|
|
1139 |
return true;
|
|
1140 |
}
|
|
1141 |
return false;
|
|
1142 |
}
|
|
1143 |
|
|
1144 |
/**
|
|
1145 |
* Get Form current Layout directive.
|
|
1146 |
*
|
|
1147 |
* @return current Layout directive for Form.
|
|
1148 |
*/
|
|
1149 |
private int getCurrentHLayoutDirective()
|
|
1150 |
{
|
|
1151 |
if(currentHLayoutDirective == Item.LAYOUT_DEFAULT)
|
|
1152 |
{
|
|
1153 |
return getLanguageSpecificLayoutDirective();
|
|
1154 |
}
|
|
1155 |
return currentHLayoutDirective;
|
|
1156 |
}
|
|
1157 |
|
|
1158 |
/**
|
|
1159 |
* Returns language specific layout directive.
|
|
1160 |
*
|
|
1161 |
* @return LAYOUT_LEFT or LAYOUT_RIGHT.
|
|
1162 |
*/
|
|
1163 |
int getLanguageSpecificLayoutDirective()
|
|
1164 |
{
|
|
1165 |
if(form.getLeftRightLanguage())
|
|
1166 |
{
|
|
1167 |
return Item.LAYOUT_LEFT;
|
|
1168 |
}
|
|
1169 |
else
|
|
1170 |
{
|
|
1171 |
return Item.LAYOUT_RIGHT;
|
|
1172 |
}
|
|
1173 |
}
|
|
1174 |
|
|
1175 |
private boolean getItemNewLineBefore(Item item)
|
|
1176 |
{
|
|
1177 |
return ((item.internalGetLayout() & Item.LAYOUT_NEWLINE_BEFORE) != 0);
|
|
1178 |
}
|
|
1179 |
|
|
1180 |
private boolean getItemNewLineAfter(Item item)
|
|
1181 |
{
|
|
1182 |
return ((item.internalGetLayout() & Item.LAYOUT_NEWLINE_AFTER) != 0);
|
|
1183 |
}
|
|
1184 |
|
|
1185 |
boolean isItemLayouted(Item item)
|
|
1186 |
{
|
|
1187 |
return (getFirstLayoutObjectOfItem(item) != null);
|
|
1188 |
}
|
|
1189 |
|
|
1190 |
/**
|
|
1191 |
* Returns if the form is shown.
|
|
1192 |
*/
|
|
1193 |
boolean isFormCurrent()
|
|
1194 |
{
|
|
1195 |
return isCurrent;
|
|
1196 |
}
|
|
1197 |
|
|
1198 |
/**
|
|
1199 |
* Returns if the region is partially visible.
|
|
1200 |
*
|
|
1201 |
* @param viewTop viewPort's top position
|
|
1202 |
* @param viewBottom viewPort's bottom position
|
|
1203 |
* @return true if visible
|
|
1204 |
*/
|
|
1205 |
boolean isPartiallyVisible(int yTop, int yBottom)
|
|
1206 |
{
|
|
1207 |
int vBottomPosition = vPosition + getFormHeight();
|
|
1208 |
if((vPosition <= yTop && vBottomPosition <= yTop)
|
|
1209 |
|| (vPosition >= yBottom && vBottomPosition >= yBottom))
|
|
1210 |
{
|
|
1211 |
return false;
|
|
1212 |
}
|
|
1213 |
return true;
|
|
1214 |
}
|
|
1215 |
|
|
1216 |
/**
|
|
1217 |
* Returns if at least the region's given percentage is visible.
|
|
1218 |
*/
|
|
1219 |
boolean isPartiallyVisible(int yTop, int yBottom, int minPercent)
|
|
1220 |
{
|
|
1221 |
int visPercent = getVisibilityPercent(yTop, yBottom);
|
|
1222 |
if(visPercent > minPercent)
|
|
1223 |
{
|
|
1224 |
return true;
|
|
1225 |
}
|
|
1226 |
return false;
|
|
1227 |
}
|
|
1228 |
|
|
1229 |
/**
|
|
1230 |
* Returns the region's visibility percentage.
|
|
1231 |
*/
|
|
1232 |
int getVisibilityPercent(int yTop, int yBottom)
|
|
1233 |
{
|
|
1234 |
if(yTop >= yBottom)
|
|
1235 |
{
|
|
1236 |
return 0;
|
|
1237 |
}
|
|
1238 |
int vBottomPosition = vPosition + getFormHeight();
|
|
1239 |
int r1 = Math.max(vPosition, Math.min(yTop, vBottomPosition));
|
|
1240 |
int r2 = Math.min(vBottomPosition, Math.max(yBottom, vPosition));
|
|
1241 |
return ((r2 - r1) * 100) / (yBottom - yTop);
|
|
1242 |
}
|
|
1243 |
|
|
1244 |
/**
|
|
1245 |
* Returns if the LayoutObject is partially visible.
|
|
1246 |
*/
|
|
1247 |
boolean isPartiallyVisible(LayoutObject lo)
|
|
1248 |
{
|
|
1249 |
if(lo != null)
|
|
1250 |
{
|
|
1251 |
return isPartiallyVisible(lo.getY(), lo.getY() + lo.getHeight());
|
|
1252 |
}
|
|
1253 |
return false;
|
|
1254 |
}
|
|
1255 |
|
|
1256 |
/**
|
|
1257 |
* Returns if at least the LayoutObject's given percentage is visible.
|
|
1258 |
*/
|
|
1259 |
boolean isPartiallyVisible(LayoutObject lo, int minPercent)
|
|
1260 |
{
|
|
1261 |
if(lo != null)
|
|
1262 |
{
|
|
1263 |
return isPartiallyVisible(lo.getY(), lo.getY() + lo.getHeight(),
|
|
1264 |
minPercent);
|
|
1265 |
}
|
|
1266 |
return false;
|
|
1267 |
}
|
|
1268 |
|
|
1269 |
/**
|
|
1270 |
* Returns if the Item is partially visible (if one of its LayoutObjects is
|
|
1271 |
* partially visible).
|
|
1272 |
*
|
|
1273 |
* @param item the Item
|
|
1274 |
* @return true if partially visible
|
|
1275 |
*/
|
|
1276 |
boolean isItemPartiallyVisible(Item item)
|
|
1277 |
{
|
|
1278 |
if(item != null)
|
|
1279 |
{
|
|
1280 |
LayoutObject lo = null;
|
|
1281 |
while((lo = getNextLayoutObjectOfItem(lo, item)) != null)
|
|
1282 |
{
|
|
1283 |
if(isPartiallyVisible(lo))
|
|
1284 |
{
|
|
1285 |
return true;
|
|
1286 |
}
|
|
1287 |
}
|
|
1288 |
}
|
|
1289 |
return false;
|
|
1290 |
}
|
|
1291 |
|
|
1292 |
|
|
1293 |
|
|
1294 |
/**
|
|
1295 |
* Returns true if item is fully visible.
|
|
1296 |
*
|
|
1297 |
* @param item the Item.
|
|
1298 |
* @return true if fully visible.
|
|
1299 |
*/
|
|
1300 |
boolean isItemFullyVisible(Item item)
|
|
1301 |
{
|
|
1302 |
if(item != null)
|
|
1303 |
{
|
|
1304 |
LayoutObject lo = null;
|
|
1305 |
while((lo = getNextLayoutObjectOfItem(lo, item)) != null)
|
|
1306 |
{
|
|
1307 |
if(!isLOFullyVisible(lo))
|
|
1308 |
{
|
|
1309 |
return false;
|
|
1310 |
}
|
|
1311 |
}
|
|
1312 |
}
|
|
1313 |
return true;
|
|
1314 |
}
|
|
1315 |
|
|
1316 |
/**
|
|
1317 |
* Returns if the LayoutObject is fully visible.
|
|
1318 |
*/
|
|
1319 |
boolean isLOFullyVisible(LayoutObject lo)
|
|
1320 |
{
|
|
1321 |
if(lo != null)
|
|
1322 |
{
|
|
1323 |
return isFullyVisible(lo.getY(), lo.getY() + lo.getHeight());
|
|
1324 |
}
|
|
1325 |
return false;
|
|
1326 |
}
|
|
1327 |
|
|
1328 |
/**
|
|
1329 |
* Returns if the region is fully visible.
|
|
1330 |
*
|
|
1331 |
* @param viewTop viewPort's top position
|
|
1332 |
* @param viewBottom viewPort's bottom position
|
|
1333 |
* @return true if visible
|
|
1334 |
*/
|
|
1335 |
boolean isFullyVisible(int yTop, int yBottom)
|
|
1336 |
{
|
|
1337 |
int vBottomPosition = vPosition + getFormHeight();
|
|
1338 |
if((vPosition <= yTop && vBottomPosition >= yBottom))
|
|
1339 |
{
|
|
1340 |
return true;
|
|
1341 |
}
|
|
1342 |
return false;
|
|
1343 |
}
|
|
1344 |
|
|
1345 |
int getItemTopPosition(Item item)
|
|
1346 |
{
|
|
1347 |
LayoutObject lo = getFirstLayoutObjectOfItem(item);
|
|
1348 |
if(lo != null)
|
|
1349 |
{
|
|
1350 |
return lo.getY();
|
|
1351 |
}
|
|
1352 |
return 0;
|
|
1353 |
}
|
|
1354 |
|
|
1355 |
int getItemBottomPosition(Item item)
|
|
1356 |
{
|
|
1357 |
LayoutObject lo = getLastLayoutObjectOfItem(item);
|
|
1358 |
if(lo != null)
|
|
1359 |
{
|
|
1360 |
return lo.getY() + lo.getHeight();
|
|
1361 |
}
|
|
1362 |
return 0;
|
|
1363 |
}
|
|
1364 |
|
|
1365 |
int getItemCount()
|
|
1366 |
{
|
|
1367 |
return form.size();
|
|
1368 |
}
|
|
1369 |
|
|
1370 |
Item getItem(int index)
|
|
1371 |
{
|
|
1372 |
try
|
|
1373 |
{
|
|
1374 |
return (Item) form.getItems().elementAt(index);
|
|
1375 |
}
|
|
1376 |
catch(ArrayIndexOutOfBoundsException e)
|
|
1377 |
{
|
|
1378 |
// Logger.exception(e);
|
|
1379 |
return null;
|
|
1380 |
}
|
|
1381 |
}
|
|
1382 |
|
|
1383 |
int getItemIndex(Item item)
|
|
1384 |
{
|
|
1385 |
return form.getItems().indexOf(item);
|
|
1386 |
}
|
|
1387 |
|
|
1388 |
int getRowCount()
|
|
1389 |
{
|
|
1390 |
return rows.size();
|
|
1391 |
}
|
|
1392 |
|
|
1393 |
/**
|
|
1394 |
* Return the Row with the given index.
|
|
1395 |
*
|
|
1396 |
* @param index Row's index
|
|
1397 |
* @return a Row
|
|
1398 |
*/
|
|
1399 |
Row getRow(int index)
|
|
1400 |
{
|
|
1401 |
try
|
|
1402 |
{
|
|
1403 |
return (Row) rows.elementAt(index);
|
|
1404 |
}
|
|
1405 |
catch(ArrayIndexOutOfBoundsException e)
|
|
1406 |
{
|
|
1407 |
Logger.exception("getRow", e);
|
|
1408 |
return null;
|
|
1409 |
}
|
|
1410 |
}
|
|
1411 |
|
|
1412 |
/**
|
|
1413 |
* Return the Row to which the given LayoutObject belongs.
|
|
1414 |
*
|
|
1415 |
* @param lo LayoutObject
|
|
1416 |
* @return the owning Row
|
|
1417 |
*/
|
|
1418 |
Row getRow(LayoutObject lo)
|
|
1419 |
{
|
|
1420 |
try
|
|
1421 |
{
|
|
1422 |
return getRow(lo.getRowIdx());
|
|
1423 |
}
|
|
1424 |
catch(NullPointerException e)
|
|
1425 |
{
|
|
1426 |
// Logger.exception("getRow", e);
|
|
1427 |
return null;
|
|
1428 |
}
|
|
1429 |
}
|
|
1430 |
|
|
1431 |
/**
|
|
1432 |
* Returns the last row of the form.
|
|
1433 |
*/
|
|
1434 |
Row getLastRow()
|
|
1435 |
{
|
|
1436 |
try
|
|
1437 |
{
|
|
1438 |
return (Row) rows.lastElement();
|
|
1439 |
}
|
|
1440 |
catch(NoSuchElementException nse)
|
|
1441 |
{
|
|
1442 |
// Logger.exception("getLastRow", nse);
|
|
1443 |
return null;
|
|
1444 |
}
|
|
1445 |
}
|
|
1446 |
|
|
1447 |
/**
|
|
1448 |
* Find last row which contains corresponding Item.
|
|
1449 |
*
|
|
1450 |
* @param item Item in a Row.
|
|
1451 |
* @return Last Row with that item.
|
|
1452 |
*/
|
|
1453 |
Row getLastRowOfItem(Item item)
|
|
1454 |
{
|
|
1455 |
return getRow(getLastLayoutObjectOfItem(item));
|
|
1456 |
}
|
|
1457 |
|
|
1458 |
/**
|
|
1459 |
* Get Form which requires layout.
|
|
1460 |
*
|
|
1461 |
* @return form.
|
|
1462 |
*/
|
|
1463 |
Form getForm()
|
|
1464 |
{
|
|
1465 |
return form;
|
|
1466 |
}
|
|
1467 |
|
|
1468 |
/**
|
|
1469 |
* Form's content height.
|
|
1470 |
*/
|
|
1471 |
int getFormHeight()
|
|
1472 |
{
|
|
1473 |
return form.getHeight();
|
|
1474 |
}
|
|
1475 |
|
|
1476 |
/**
|
|
1477 |
* Form's content width.
|
|
1478 |
*/
|
|
1479 |
int getFormWidth()
|
|
1480 |
{
|
|
1481 |
return form.getWidth();
|
|
1482 |
}
|
|
1483 |
|
|
1484 |
/**
|
|
1485 |
* Returns LayoutObject for the given Item.
|
|
1486 |
*
|
|
1487 |
* @param item Item to layout
|
|
1488 |
* @return LayoutObject
|
|
1489 |
*/
|
|
1490 |
LayoutObject getLayoutObject(Item item)
|
|
1491 |
{
|
|
1492 |
int num = layoutObjects.size();
|
|
1493 |
|
|
1494 |
for(int i = 0; i < num; i++)
|
|
1495 |
{
|
|
1496 |
if(((LayoutObject)layoutObjects.elementAt(i)).getOwningItem() == item)
|
|
1497 |
{
|
|
1498 |
LayoutObject lo = (LayoutObject)(layoutObjects.elementAt(i));
|
|
1499 |
lo.setRowIdx(-1);
|
|
1500 |
return lo;
|
|
1501 |
}
|
|
1502 |
}
|
|
1503 |
|
|
1504 |
return null;
|
|
1505 |
}
|
|
1506 |
|
|
1507 |
/**
|
|
1508 |
* Removes Layout Object for the given Item.
|
|
1509 |
*
|
|
1510 |
* @param item Item to remove LayoutObject
|
|
1511 |
*/
|
|
1512 |
void removeLayoutObject(Item item)
|
|
1513 |
{
|
|
1514 |
|
|
1515 |
int num = layoutObjects.size();
|
|
1516 |
|
|
1517 |
for(int i = 0; i < num; i++)
|
|
1518 |
{
|
|
1519 |
if(((LayoutObject)layoutObjects.elementAt(i)).getOwningItem() == item)
|
|
1520 |
{
|
|
1521 |
LayoutObject lo = (LayoutObject)(layoutObjects.elementAt(i));
|
|
1522 |
layoutObjects.removeElement(lo);
|
|
1523 |
lo.dispose();
|
|
1524 |
break;
|
|
1525 |
}
|
|
1526 |
}
|
|
1527 |
}
|
|
1528 |
|
|
1529 |
/**
|
|
1530 |
* Removes all Layout Objects from the FormLayouter.
|
|
1531 |
*/
|
|
1532 |
void removeAllLayoutObjects()
|
|
1533 |
{
|
|
1534 |
Enumeration e = layoutObjects.elements();
|
|
1535 |
|
|
1536 |
while(e.hasMoreElements())
|
|
1537 |
{
|
|
1538 |
LayoutObject lo = (LayoutObject)e.nextElement();
|
|
1539 |
layoutObjects.removeElement(lo);
|
|
1540 |
lo.dispose();
|
|
1541 |
}
|
|
1542 |
}
|
|
1543 |
|
|
1544 |
/**
|
|
1545 |
* Returns the next LayoutObject belonging to this Item.<br>
|
|
1546 |
*
|
|
1547 |
* @param lo starting LayoutObject; if null then it start from first.
|
|
1548 |
* @param item specifies the parent Item; null means any Item
|
|
1549 |
* @return the next LayoutObject in the layout.
|
|
1550 |
*/
|
|
1551 |
LayoutObject getNextLayoutObjectOfItem(LayoutObject lo, Item item)
|
|
1552 |
{
|
|
1553 |
int startRow = (lo == null ? 0 : lo.getRowIdx());
|
|
1554 |
LayoutObject temp = null;
|
|
1555 |
for(int i = startRow; i < getRowCount(); i++)
|
|
1556 |
{
|
|
1557 |
temp = getRow(i).getNextLayoutObject(lo, item);
|
|
1558 |
if(temp != null && temp != lo)
|
|
1559 |
{
|
|
1560 |
return temp;
|
|
1561 |
}
|
|
1562 |
}
|
|
1563 |
return null;
|
|
1564 |
}
|
|
1565 |
|
|
1566 |
/**
|
|
1567 |
* Returns the previous LayoutObject belonging to this Item.<br>
|
|
1568 |
*
|
|
1569 |
* @param lo starting LayoutObject; if null then it start from last.
|
|
1570 |
* @param item specifies the parent Item; null means any Item
|
|
1571 |
* @return the previous LayoutObject in the layout.
|
|
1572 |
*/
|
|
1573 |
LayoutObject getPrevLayoutObjectOfItem(LayoutObject lo, Item item)
|
|
1574 |
{
|
|
1575 |
int startRow = (lo == null ? rows.size() - 1 : lo.getRowIdx());
|
|
1576 |
LayoutObject temp = null;
|
|
1577 |
for(int i = startRow; i >= 0; i--)
|
|
1578 |
{
|
|
1579 |
temp = getRow(i).getPrevLayoutObject(lo, item);
|
|
1580 |
if(temp != null && temp != lo)
|
|
1581 |
{
|
|
1582 |
return temp;
|
|
1583 |
}
|
|
1584 |
}
|
|
1585 |
return null;
|
|
1586 |
}
|
|
1587 |
|
|
1588 |
/**
|
|
1589 |
* Returns the first LayoutObject of a layouted item.
|
|
1590 |
*
|
|
1591 |
* @param item
|
|
1592 |
* @return the LO, or NULL if the item is not layouted
|
|
1593 |
*/
|
|
1594 |
LayoutObject getFirstLayoutObjectOfItem(Item item)
|
|
1595 |
{
|
|
1596 |
if(item != null)
|
|
1597 |
{
|
|
1598 |
return getNextLayoutObjectOfItem(null, item);
|
|
1599 |
}
|
|
1600 |
return null;
|
|
1601 |
}
|
|
1602 |
|
|
1603 |
/**
|
|
1604 |
* Returns the last LayoutObject of a layouted item.
|
|
1605 |
*
|
|
1606 |
* @param item
|
|
1607 |
* @return the LO, or NULL if the item is not layouted
|
|
1608 |
*/
|
|
1609 |
LayoutObject getLastLayoutObjectOfItem(Item item)
|
|
1610 |
{
|
|
1611 |
if(item != null)
|
|
1612 |
{
|
|
1613 |
return getPrevLayoutObjectOfItem(null, item);
|
|
1614 |
}
|
|
1615 |
return null;
|
|
1616 |
}
|
|
1617 |
|
|
1618 |
/**
|
|
1619 |
* Update item state in form.
|
|
1620 |
*
|
|
1621 |
* @param item
|
|
1622 |
* @param updateReason
|
|
1623 |
* @param param additional parameter
|
|
1624 |
*/
|
|
1625 |
void updateItemState(Item item, int updateReason, Object param)
|
|
1626 |
{
|
|
1627 |
Logger.method(this, "updateItemState", item,
|
|
1628 |
String.valueOf(updateReason), param);
|
|
1629 |
|
|
1630 |
LayoutObject lo = getFirstLayoutObjectOfItem(item);
|
|
1631 |
|
|
1632 |
if(lo != null)
|
|
1633 |
{
|
|
1634 |
getItemLayouter(item).updateItem(item, lo.getControl(), updateReason,
|
|
1635 |
param);
|
|
1636 |
}
|
|
1637 |
|
|
1638 |
// Clean reason - without resizing flags
|
|
1639 |
int reason = updateReason & Item.UPDATE_SIZE_MASK;
|
|
1640 |
switch(reason)
|
|
1641 |
{
|
|
1642 |
case Item.UPDATE_ADDCOMMAND:
|
|
1643 |
{
|
|
1644 |
if(isFormCurrent() && param != null)
|
|
1645 |
{
|
|
1646 |
if(lo != null && param instanceof Command)
|
|
1647 |
{
|
|
1648 |
lo.addCommand((Command) param);
|
|
1649 |
}
|
|
1650 |
}
|
|
1651 |
break;
|
|
1652 |
}
|
|
1653 |
case Item.UPDATE_REMOVECOMMAND:
|
|
1654 |
{
|
|
1655 |
if(isFormCurrent() && param != null)
|
|
1656 |
{
|
|
1657 |
if(lo != null && param instanceof Command)
|
|
1658 |
{
|
|
1659 |
lo.removeCommand((Command) param);
|
|
1660 |
}
|
|
1661 |
}
|
|
1662 |
break;
|
|
1663 |
}
|
|
1664 |
}
|
|
1665 |
|
|
1666 |
// Check this always - because this is a flag
|
|
1667 |
if((updateReason & Item.UPDATE_HEIGHT_CHANGED)
|
|
1668 |
== Item.UPDATE_HEIGHT_CHANGED)
|
|
1669 |
{
|
|
1670 |
resizeItemAndShift(item);
|
|
1671 |
}
|
|
1672 |
}
|
|
1673 |
|
|
1674 |
int eswtGetMaxVPosition()
|
|
1675 |
{
|
|
1676 |
return formComposite.getSize().y - getFormHeight();
|
|
1677 |
}
|
|
1678 |
|
|
1679 |
/**
|
|
1680 |
* Called by key Form to compute new vertical coordinate to position form's
|
|
1681 |
* content.
|
|
1682 |
*
|
|
1683 |
* @param swtDir scrolling direction.
|
|
1684 |
* @return New vertical position of Form's content.
|
|
1685 |
*/
|
|
1686 |
protected int getNextScrollingPosition(int swtDir)
|
|
1687 |
{
|
|
1688 |
boolean scrollDown = (swtDir == SWT.ARROW_DOWN
|
|
1689 |
|| swtDir == SWT.ARROW_RIGHT);
|
|
1690 |
int formHeight = getFormHeight();
|
|
1691 |
int refPoint;
|
|
1692 |
int ret = vPosition;
|
|
1693 |
if(scrollDown)
|
|
1694 |
{
|
|
1695 |
ret += formHeight / 5;
|
|
1696 |
refPoint = (vPosition + 1) + formHeight;
|
|
1697 |
}
|
|
1698 |
else
|
|
1699 |
{
|
|
1700 |
ret -= formHeight / 5;
|
|
1701 |
refPoint = (vPosition - 1);
|
|
1702 |
}
|
|
1703 |
|
|
1704 |
Row row = null;
|
|
1705 |
for(int i = 0; i < getRowCount(); i++)
|
|
1706 |
{
|
|
1707 |
row = getRow(i);
|
|
1708 |
if(row.isInsideRow(refPoint)
|
|
1709 |
&& (row.getRowHeight() < formHeight))
|
|
1710 |
{
|
|
1711 |
if(scrollDown)
|
|
1712 |
{
|
|
1713 |
ret = row.getBottomPosition() - formHeight;
|
|
1714 |
}
|
|
1715 |
else
|
|
1716 |
{
|
|
1717 |
ret = row.getYShift();
|
|
1718 |
}
|
|
1719 |
break;
|
|
1720 |
}
|
|
1721 |
}
|
|
1722 |
|
|
1723 |
return ret;
|
|
1724 |
}
|
|
1725 |
|
|
1726 |
/**
|
|
1727 |
* Set the scrolling to the specified position.<br>
|
|
1728 |
* This method also updates the Form's scrollbars.
|
|
1729 |
*
|
|
1730 |
* @param position new position
|
|
1731 |
*/
|
|
1732 |
void eswtSetScrollingPosition(int position, boolean keyNav)
|
|
1733 |
{
|
|
1734 |
// check constraints
|
|
1735 |
int newVPosition = position;
|
|
1736 |
int maxVPos = eswtGetMaxVPosition();
|
|
1737 |
newVPosition = Math.min(newVPosition, maxVPos);
|
|
1738 |
newVPosition = Math.max(newVPosition, 0);
|
|
1739 |
|
|
1740 |
vPosition = newVPosition;
|
|
1741 |
formComposite.setRedraw(false);
|
|
1742 |
formComposite.setOrigin(0, vPosition, keyNav);
|
|
1743 |
formComposite.pack();
|
|
1744 |
formComposite.setRedraw(true);
|
|
1745 |
|
|
1746 |
eswtHandleVisibilityChanges();
|
|
1747 |
}
|
|
1748 |
|
|
1749 |
/**
|
|
1750 |
* Returns the scrolling position.
|
|
1751 |
*/
|
|
1752 |
protected int getScrollingPosition()
|
|
1753 |
{
|
|
1754 |
return vPosition;
|
|
1755 |
}
|
|
1756 |
|
|
1757 |
/**
|
|
1758 |
* Updates visibility status of all items.
|
|
1759 |
*/
|
|
1760 |
protected void eswtHandleVisibilityChanges()
|
|
1761 |
{
|
|
1762 |
// Logger.method(this, "eswtHandleVisibilityChanges");
|
|
1763 |
boolean shown = false;
|
|
1764 |
Item item = null;
|
|
1765 |
LayoutObject lo = null;
|
|
1766 |
// Go through all LayoutObjects and check/update visibilities
|
|
1767 |
while((lo = getNextLayoutObjectOfItem(lo, null)) != null)
|
|
1768 |
{
|
|
1769 |
// check if owning item is changing
|
|
1770 |
if(lo.getOwningItem() != item)
|
|
1771 |
{
|
|
1772 |
if(item != null)
|
|
1773 |
{
|
|
1774 |
// set current item's visibility
|
|
1775 |
getItemLayouter(item).eswtHandleVisibilityChange(item, shown);
|
|
1776 |
}
|
|
1777 |
// new item
|
|
1778 |
item = lo.getOwningItem();
|
|
1779 |
shown = false;
|
|
1780 |
}
|
|
1781 |
|
|
1782 |
// track current item's visibility
|
|
1783 |
if(!shown && isFormCurrent() && isPartiallyVisible(lo))
|
|
1784 |
{
|
|
1785 |
shown = true;
|
|
1786 |
}
|
|
1787 |
}
|
|
1788 |
|
|
1789 |
// call it for last item
|
|
1790 |
if(item != null)
|
|
1791 |
{
|
|
1792 |
getItemLayouter(item).eswtHandleVisibilityChange(item, shown);
|
|
1793 |
}
|
|
1794 |
|
|
1795 |
eswtCheckCurrentSelectedItem();
|
|
1796 |
}
|
|
1797 |
|
|
1798 |
/**
|
|
1799 |
* Changes item size and does shift of all Rows.
|
|
1800 |
*
|
|
1801 |
* @param item - item to changeSize.
|
|
1802 |
*/
|
|
1803 |
void resizeItemAndShift(final Item item)
|
|
1804 |
{
|
|
1805 |
ESWTUIThreadRunner.syncExec(new Runnable()
|
|
1806 |
{
|
|
1807 |
public void run()
|
|
1808 |
{
|
|
1809 |
int newVPosition = eswtResizeItemAndShift(item);
|
|
1810 |
if(newVPosition != vPosition)
|
|
1811 |
{
|
|
1812 |
eswtSetScrollingPosition(newVPosition, true);
|
|
1813 |
}
|
|
1814 |
else
|
|
1815 |
{
|
|
1816 |
eswtHandleVisibilityChanges();
|
|
1817 |
}
|
|
1818 |
}
|
|
1819 |
});
|
|
1820 |
}
|
|
1821 |
|
|
1822 |
/**
|
|
1823 |
* eSWT callback for resizeItemAndShift.
|
|
1824 |
*
|
|
1825 |
* @param item Item to be resized.
|
|
1826 |
* @return new scrolling vPosition
|
|
1827 |
*/
|
|
1828 |
int eswtResizeItemAndShift(Item item)
|
|
1829 |
{
|
|
1830 |
// save the state of the last row before resizing and Shifting.
|
|
1831 |
boolean itemWasVisible = isItemPartiallyVisible(item);
|
|
1832 |
Row row = getLastRowOfItem(item);
|
|
1833 |
int deltaYShift = row.getRowHeight();
|
|
1834 |
// if we un-comment this then when we set true,
|
|
1835 |
// focus will jump to first item.
|
|
1836 |
// eswtUpdateFormComposite(false);
|
|
1837 |
LayoutObject lo = getFirstLayoutObjectOfItem(item);
|
|
1838 |
if(lo != null)
|
|
1839 |
{
|
|
1840 |
getItemLayouter(item).eswtResizeObject(lo);
|
|
1841 |
}
|
|
1842 |
|
|
1843 |
eswtUpdateRow(row);
|
|
1844 |
|
|
1845 |
/*
|
|
1846 |
// to avoid double call of updateRowInternals
|
|
1847 |
if (row.getNumLayoutObjects(Item.LAYOUT_SHRINK) > 0
|
|
1848 |
|| row.getNumLayoutObjects(Item.LAYOUT_EXPAND) > 0) {
|
|
1849 |
eswtUpdateRow(row);
|
|
1850 |
}
|
|
1851 |
else {
|
|
1852 |
row.updateRowInternals();
|
|
1853 |
}
|
|
1854 |
*/
|
|
1855 |
deltaYShift = row.getRowHeight() - deltaYShift;
|
|
1856 |
// row's height change - all remaining rows are shifted with this.
|
|
1857 |
|
|
1858 |
Row lastRow = getLastRow();
|
|
1859 |
if(row != lastRow)
|
|
1860 |
{
|
|
1861 |
for(int i = rows.indexOf(row) + 1; i < getRowCount(); i++)
|
|
1862 |
{
|
|
1863 |
row = getRow(i);
|
|
1864 |
row.setYShift(row.getYShift() + deltaYShift);
|
|
1865 |
eswtUpdateRow(row);
|
|
1866 |
}
|
|
1867 |
}
|
|
1868 |
|
|
1869 |
// following code updates scrolling if needed.
|
|
1870 |
// need to check where in the form resize happeneed.
|
|
1871 |
|
|
1872 |
int itemRowYShift = getLastRowOfItem(item).getYShift();
|
|
1873 |
// vPosition should be changed in syncexec
|
|
1874 |
int newVPosition = vPosition;
|
|
1875 |
|
|
1876 |
// we need to scroll only if changes happened above the screen.
|
|
1877 |
if(newVPosition >= itemRowYShift)
|
|
1878 |
{
|
|
1879 |
newVPosition = Math.max(0, newVPosition + deltaYShift);
|
|
1880 |
}
|
|
1881 |
// check to avoid gap in the bottom of the form
|
|
1882 |
if(newVPosition + getFormHeight() > lastRow.getBottomPosition())
|
|
1883 |
{
|
|
1884 |
newVPosition = Math.max(0,
|
|
1885 |
lastRow.getBottomPosition() - getFormHeight());
|
|
1886 |
}
|
|
1887 |
|
|
1888 |
eswtUpdateFormComposite(true);
|
|
1889 |
|
|
1890 |
// formComposite.pack();
|
|
1891 |
// formComposite.updateScrollbarSize(lastRow.getBottomPosition());
|
|
1892 |
|
|
1893 |
if(item == currentSelectedItem)
|
|
1894 |
{
|
|
1895 |
if(itemWasVisible)
|
|
1896 |
{
|
|
1897 |
int itemTop = getItemTopPosition(item);
|
|
1898 |
int itemBottom = getItemBottomPosition(item);
|
|
1899 |
// currentSelectedItem has to be focused if it was focused
|
|
1900 |
// before resizing e.g TextField when it is resized by adding a
|
|
1901 |
// new row and it was in the bottom of the Screen.
|
|
1902 |
if(newVPosition <= itemTop
|
|
1903 |
&& (newVPosition + getFormHeight()) >= itemBottom)
|
|
1904 |
{
|
|
1905 |
// do not change vPosition;
|
|
1906 |
}
|
|
1907 |
else if(newVPosition > itemTop)
|
|
1908 |
{
|
|
1909 |
newVPosition = itemTop;
|
|
1910 |
}
|
|
1911 |
else if((newVPosition + getFormHeight()) < itemBottom)
|
|
1912 |
{
|
|
1913 |
newVPosition = itemBottom - getFormHeight();
|
|
1914 |
}
|
|
1915 |
}
|
|
1916 |
}
|
|
1917 |
return newVPosition;
|
|
1918 |
}
|
|
1919 |
|
|
1920 |
/**
|
|
1921 |
* Gets layouter that can layout the specified item.
|
|
1922 |
*
|
|
1923 |
* @param item Item to be layouted.
|
|
1924 |
* @return ItemLayouter or null if no Layouter found.
|
|
1925 |
*/
|
|
1926 |
protected final ItemLayouter getItemLayouter(Item item)
|
|
1927 |
{
|
|
1928 |
if(item instanceof StringItem)
|
|
1929 |
{
|
|
1930 |
return sIL;
|
|
1931 |
}
|
|
1932 |
else if(item instanceof ImageItem)
|
|
1933 |
{
|
|
1934 |
return imIL;
|
|
1935 |
}
|
|
1936 |
else if(item instanceof Gauge)
|
|
1937 |
{
|
|
1938 |
return gL;
|
|
1939 |
}
|
|
1940 |
else if(item instanceof TextField)
|
|
1941 |
{
|
|
1942 |
return tfL;
|
|
1943 |
}
|
|
1944 |
else if(item instanceof DateField)
|
|
1945 |
{
|
|
1946 |
return dfL;
|
|
1947 |
}
|
|
1948 |
else if(item instanceof ChoiceGroup)
|
|
1949 |
{
|
|
1950 |
return cgL;
|
|
1951 |
}
|
|
1952 |
else if(item instanceof CustomItem)
|
|
1953 |
{
|
|
1954 |
return ciL;
|
|
1955 |
}
|
|
1956 |
else if(item instanceof Spacer)
|
|
1957 |
{
|
|
1958 |
return sL;
|
|
1959 |
}
|
|
1960 |
return null;
|
|
1961 |
}
|
|
1962 |
|
|
1963 |
/**
|
|
1964 |
* Returns eSWT Control that represents the item specified.
|
|
1965 |
*/
|
|
1966 |
Control getItemControl(final Item item)
|
|
1967 |
{
|
|
1968 |
final LayoutObject lo = getFirstLayoutObjectOfItem(item);
|
|
1969 |
if(lo != null)
|
|
1970 |
{
|
|
1971 |
ESWTUIThreadRunner.syncExec(new Runnable()
|
|
1972 |
{
|
|
1973 |
public void run()
|
|
1974 |
{
|
|
1975 |
itemMainControl = getItemLayouter(item)
|
|
1976 |
.eswtFindSpecificControl(item, lo.getControl());
|
|
1977 |
}
|
|
1978 |
});
|
|
1979 |
return itemMainControl;
|
|
1980 |
}
|
|
1981 |
return null;
|
|
1982 |
}
|
|
1983 |
|
|
1984 |
void updateScrolling(final int value, final boolean keyNav)
|
|
1985 |
{
|
|
1986 |
Logger.method("updateScrolling", String.valueOf(value));
|
|
1987 |
ESWTUIThreadRunner.syncExec(new Runnable()
|
|
1988 |
{
|
|
1989 |
public void run()
|
|
1990 |
{
|
|
1991 |
|
|
1992 |
eswtSetScrollingPosition(value, keyNav);
|
|
1993 |
|
|
1994 |
}
|
|
1995 |
});
|
|
1996 |
}
|
|
1997 |
|
|
1998 |
/**
|
|
1999 |
* Get current scrolling value.
|
|
2000 |
*
|
|
2001 |
* @return vPosition.
|
|
2002 |
*/
|
|
2003 |
int getVPosition()
|
|
2004 |
{
|
|
2005 |
return vPosition;
|
|
2006 |
}
|
|
2007 |
|
|
2008 |
|
|
2009 |
private Timer eventTimer = new Timer();
|
|
2010 |
private EventGeneratorTask eventTask;
|
|
2011 |
|
|
2012 |
/**
|
|
2013 |
* Reset timer for do layout with a given start index.
|
|
2014 |
*/
|
|
2015 |
private void resetEventTimer(boolean directionUp, int y)
|
|
2016 |
{
|
|
2017 |
if(eventTimer != null)
|
|
2018 |
{
|
|
2019 |
if(eventTask != null)
|
|
2020 |
{
|
|
2021 |
eventTask.cancel();
|
|
2022 |
eventTask = null;
|
|
2023 |
}
|
|
2024 |
// schedule new timer
|
|
2025 |
eventTask = new EventGeneratorTask(directionUp, y);
|
|
2026 |
eventTimer.schedule(eventTask, Config.DFI_EVENT_TIMER_DELAY);
|
|
2027 |
}
|
|
2028 |
}
|
|
2029 |
|
|
2030 |
/**
|
|
2031 |
* Form Timer task. Triggers the formComposite to Layout.
|
|
2032 |
*/
|
|
2033 |
class EventGeneratorTask extends TimerTask
|
|
2034 |
{
|
|
2035 |
|
|
2036 |
private boolean isUpDirection;
|
|
2037 |
private int localY;
|
|
2038 |
|
|
2039 |
public EventGeneratorTask(boolean direction, int y)
|
|
2040 |
{
|
|
2041 |
isUpDirection = direction;
|
|
2042 |
localY = y;
|
|
2043 |
Logger.info("y is " + localY);
|
|
2044 |
}
|
|
2045 |
|
|
2046 |
public void run()
|
|
2047 |
{
|
|
2048 |
if(isUpDirection)
|
|
2049 |
{
|
|
2050 |
localY -= Config.DFI_EVENT_MOVE_DELTA;
|
|
2051 |
}
|
|
2052 |
else
|
|
2053 |
{
|
|
2054 |
localY += Config.DFI_EVENT_MOVE_DELTA;
|
|
2055 |
}
|
|
2056 |
handlePointerEvent(0, localY, SWT.MouseMove);
|
|
2057 |
}
|
|
2058 |
}
|
|
2059 |
|
|
2060 |
}
|