/**
* Initialize the location of the widget that will slide into view.
*/
private void doBeforeLayout() {
Layer oldLayer = (lastVisibleWidget == null) ? null
: (Layer) lastVisibleWidget.getLayoutData();
Layer newLayer = (visibleWidget == null) ? null
: (Layer) visibleWidget.getLayoutData();
// Calculate the direction that the new widget will enter.
int oldIndex = getWidgetIndex(lastVisibleWidget);
int newIndex = getWidgetIndex(visibleWidget);
double direction = (oldIndex < newIndex) ? 100.0 : -100.0;
double vDirection = isAnimationVertical ? direction : 0.0;
double hDirection = isAnimationVertical ? 0.0
: LocaleInfo.getCurrentLocale().isRTL() ? -direction : direction;
/*
* Position the old widget in the center of the panel, and the new widget
* off to one side. If the old widget is the same as the new widget, then
* skip this step.
*/
hidingWidget = null;
if (visibleWidget != lastVisibleWidget) {
// Position the layers in their start positions.
if (oldLayer != null) {
// The old layer starts centered in the panel.
oldLayer.setTopHeight(0.0, Unit.PCT, 100.0, Unit.PCT);
oldLayer.setLeftWidth(0.0, Unit.PCT, 100.0, Unit.PCT);
setWidgetVisible(lastVisibleWidget, oldLayer, true);
}
if (newLayer != null) {
// The new layer starts off to one side.
newLayer.setTopHeight(vDirection, Unit.PCT, 100.0, Unit.PCT);
newLayer.setLeftWidth(hDirection, Unit.PCT, 100.0, Unit.PCT);
setWidgetVisible(visibleWidget, newLayer, true);
}
layout.layout();
hidingWidget = lastVisibleWidget;
}
// Set the end positions of the layers.
if (oldLayer != null) {
// The old layer ends off to one side.
oldLayer.setTopHeight(-vDirection, Unit.PCT, 100.0, Unit.PCT);
oldLayer.setLeftWidth(-hDirection, Unit.PCT, 100.0, Unit.PCT);
setWidgetVisible(lastVisibleWidget, oldLayer, true);
}
if (newLayer != null) {
// The new layer ends centered in the panel.
newLayer.setTopHeight(0.0, Unit.PCT, 100.0, Unit.PCT);
newLayer.setLeftWidth(0.0, Unit.PCT, 100.0, Unit.PCT);
/*
* The call to layout() above could have canceled an existing layout
* animation, which could cause this widget to be hidden if the user
* toggles between two visible widgets. We set it visible again to ensure
* that it ends up visible.