use of com.codename1.ui.animations.Transition in project CodenameOne by codenameone.
the class XYSeriesTransition method initTransition.
/**
* Initializes the transition. This can be overridden by subclasses to
* provide their own functionality to be executed just before the transition
* occurs.
*/
@Override
public void initTransition() {
super.initTransition();
// Now make sure that there are the same number of values in source and
// target
startVals = new XYSeries("Start");
copyValues(series, startVals);
endVals = new XYSeries("End");
copyValues(cachedSeries, endVals);
}
use of com.codename1.ui.animations.Transition in project CodenameOne by codenameone.
the class XYValueSeriesTransition method initTransition.
/**
* Initializes the transition. This can be overridden by subclasses to
* provide their own functionality to be executed just before the transition
* occurs.
*/
@Override
public void initTransition() {
super.initTransition();
// Now make sure that there are the same number of values in source and
// target
startVals = new XYValueSeries("Start");
copyValues(series, startVals);
endVals = new XYValueSeries("End");
copyValues(cachedSeries, endVals);
}
use of com.codename1.ui.animations.Transition in project CodenameOne by codenameone.
the class Dialog method show.
/**
* Shows a modal dialog with the given component as its "body" placed in the
* center.
*
* @param title title for the dialog
* @param body component placed in the center of the dialog
* @param defaultCommand command to be assigned as the default command or null
* @param cmds commands that are added to the form any click on any command
* will dispose the form
* @param type the type of the alert one of TYPE_WARNING, TYPE_INFO,
* TYPE_ERROR, TYPE_CONFIRMATION or TYPE_ALARM
* @param icon the icon for the dialog, can be null
* @param timeout a timeout after which null would be returned if timeout is 0 inifinite time is used
* @param transition the transition installed when the dialog enters/leaves
* @return the command pressed by the user
*/
public static Command show(String title, Component body, Command defaultCommand, Command[] cmds, int type, Image icon, long timeout, Transition transition) {
Dialog dialog = new Dialog(title);
dialog.dialogType = type;
dialog.setTransitionInAnimator(transition);
dialog.setTransitionOutAnimator(transition);
dialog.lastCommandPressed = null;
dialog.setLayout(new BorderLayout());
if (cmds != null) {
if (commandsAsButtons) {
dialog.placeButtonCommands(cmds);
} else {
for (int iter = 0; iter < cmds.length; iter++) {
dialog.addCommand(cmds[iter]);
}
}
// maps the first command to back
if (cmds.length == 1 || cmds.length == 2) {
dialog.setBackCommand(cmds[0]);
}
}
if (defaultCommand != null) {
dialog.setDefaultCommand(defaultCommand);
}
dialog.addComponent(BorderLayout.CENTER, body);
if (icon != null) {
dialog.addComponent(BorderLayout.EAST, new Label(icon));
}
if (timeout != 0) {
dialog.setTimeout(timeout);
}
if (body.isScrollable() || disableStaticDialogScrolling) {
dialog.setScrollable(false);
}
dialog.show();
return dialog.lastCommandPressed;
}
use of com.codename1.ui.animations.Transition in project CodenameOne by codenameone.
the class Display method setCurrent.
/**
* Displays the given Form on the screen.
*
* @param newForm the Form to Display
*/
void setCurrent(final Form newForm, boolean reverse) {
if (edt == null) {
throw new IllegalStateException("Initialize must be invoked before setCurrent!");
}
Form current = impl.getCurrentForm();
if (autoFoldVKBOnFormSwitch && !(newForm instanceof Dialog)) {
setShowVirtualKeyboard(false);
}
if (current == newForm) {
current.revalidate();
current.repaint();
current.onShowCompletedImpl();
return;
}
if (impl.isEditingText()) {
switch(showDuringEdit) {
case SHOW_DURING_EDIT_ALLOW_DISCARD:
break;
case SHOW_DURING_EDIT_ALLOW_SAVE:
impl.saveTextEditingState();
break;
case SHOW_DURING_EDIT_EXCEPTION:
throw new IllegalStateException("Show during edit");
case SHOW_DURING_EDIT_IGNORE:
return;
case SHOW_DURING_EDIT_SET_AS_NEXT:
impl.setCurrentForm(newForm);
return;
}
}
if (!isEdt()) {
callSerially(new RunnableWrapper(newForm, null, reverse));
return;
}
if (current != null) {
if (current.isInitialized()) {
current.deinitializeImpl();
} else {
Form fg = getCurrentUpcoming();
if (fg != current) {
if (fg.isInitialized()) {
fg.deinitializeImpl();
}
}
}
}
if (!newForm.isInitialized()) {
newForm.initComponentImpl();
}
if (newForm.getWidth() != getDisplayWidth() || newForm.getHeight() != getDisplayHeight()) {
newForm.setSize(new Dimension(getDisplayWidth(), getDisplayHeight()));
newForm.setShouldCalcPreferredSize(true);
newForm.layoutContainer();
} else {
// if shouldLayout is true
newForm.layoutContainer();
}
boolean transitionExists = false;
if (animationQueue != null && animationQueue.size() > 0) {
Object o = animationQueue.get(animationQueue.size() - 1);
if (o instanceof Transition) {
current = (Form) ((Transition) o).getDestination();
impl.setCurrentForm(current);
}
}
if (current != null) {
// to the correct parent!
if (current instanceof Dialog && ((Dialog) current).isMenu()) {
Transition t = current.getTransitionOutAnimator();
if (t != null) {
// go back to the parent form first
if (((Dialog) current).getPreviousForm() != null) {
initTransition(t.copy(false), current, ((Dialog) current).getPreviousForm());
}
}
current = ((Dialog) current).getPreviousForm();
impl.setCurrentForm(current);
}
// prevent the transition from occurring from a form into itself
if (newForm != current) {
if ((current != null && current.getTransitionOutAnimator() != null) || newForm.getTransitionInAnimator() != null) {
if (animationQueue == null) {
animationQueue = new ArrayList<Animation>();
}
// transitions which are a bit sensitive
if (current != null && (!(newForm instanceof Dialog))) {
Transition t = current.getTransitionOutAnimator();
if (current != null && t != null) {
transitionExists = initTransition(t.copy(reverse), current, newForm);
}
}
if (current != null && !(current instanceof Dialog)) {
Transition t = newForm.getTransitionInAnimator();
if (t != null) {
transitionExists = initTransition(t.copy(reverse), current, newForm);
}
}
}
}
}
synchronized (lock) {
lock.notify();
}
if (!transitionExists) {
if (animationQueue == null || animationQueue.size() == 0) {
setCurrentForm(newForm);
} else {
// we need to add an empty transition to "serialize" this
// screen change...
Transition t = CommonTransitions.createEmpty();
initTransition(t, current, newForm);
}
}
}
use of com.codename1.ui.animations.Transition in project CodenameOne by codenameone.
the class CommonTransitions method paint.
/**
* {@inheritDoc}
*/
public void paint(Graphics g) {
try {
switch(transitionType) {
case TYPE_FAST_SLIDE:
case TYPE_SLIDE:
// if this is an up or down slide
if (slideType == SLIDE_HORIZONTAL) {
paintSlideAtPosition(g, position, 0);
} else {
paintSlideAtPosition(g, 0, position);
}
return;
case TYPE_UNCOVER:
int p = motion.getDestinationValue() - position;
if (slideType == SLIDE_HORIZONTAL) {
paintCoverAtPosition(g, p, 0);
} else {
paintCoverAtPosition(g, 0, p);
}
return;
case TYPE_COVER:
if (slideType == SLIDE_HORIZONTAL) {
paintCoverAtPosition(g, position, 0);
} else {
paintCoverAtPosition(g, 0, position);
}
return;
case TYPE_FADE:
paintAlpha(g);
return;
case TYPE_TIMELINE:
Object mask = timeline.createMask();
paint(g, getSource(), 0, 0);
g.drawImage(buffer.applyMask(mask), 0, 0);
return;
case TYPE_SLIDE_AND_FADE:
{
Form sourceForm = (Form) getSource();
Form destForm = (Form) getDestination();
int alpha = position;
int slidePos = motion2.getValue();
int clipX = g.getClipX();
int clipY = g.getClipY();
int clipW = g.getClipWidth();
int clipH = g.getClipHeight();
if (clipW <= 0 || clipH <= 0) {
return;
}
g.translate(0, sourceForm.getTitleArea().getHeight());
Container sourcePane = ((Form) getSource()).getContentPane();
Container destPane = ((Form) getDestination()).getContentPane();
boolean dir = forward;
if (sourceForm != null && sourceForm.getUIManager().getLookAndFeel().isRTL()) {
dir = !dir;
}
if (dir) {
g.translate(slidePos, 0);
paint(g, sourcePane, -sourcePane.getAbsoluteX() - sourcePane.getScrollX(), -sourcePane.getAbsoluteY() - sourcePane.getScrollY(), true);
g.translate(-destPane.getWidth(), 0);
paint(g, destPane, -destPane.getAbsoluteX() - destPane.getScrollX(), -destPane.getAbsoluteY() - destPane.getScrollY(), true);
g.translate(destPane.getWidth() - slidePos, 0);
} else {
g.translate(-slidePos, 0);
paint(g, sourcePane, -sourcePane.getAbsoluteX() - sourcePane.getScrollX(), -sourcePane.getAbsoluteY() - sourcePane.getScrollY(), true);
g.translate(destPane.getWidth(), 0);
paint(g, destPane, -destPane.getAbsoluteX() - destPane.getScrollX(), -destPane.getAbsoluteY() - destPane.getScrollY(), true);
g.translate(slidePos - destPane.getWidth(), 0);
}
g.translate(0, -sourceForm.getTitleArea().getHeight());
g.setClip(clipX, clipY, clipW, clipH);
sourceForm.getTitleArea().paintComponentBackground(g);
paintShiftFadeHierarchy(sourceForm.getTitleArea(), 255 - alpha, g, false);
paintShiftFadeHierarchy(destForm.getTitleArea(), alpha, g, true);
return;
}
case TYPE_PULSATE_DIALOG:
paint(g, getSource(), 0, 0);
int alpha = g.getAlpha();
if (motion2 != null) {
g.setAlpha(motion2.getValue());
}
Component c = getDialogParent(getDestination());
float ratio = ((float) position) / 1000.0f;
if (g.isAffineSupported()) {
g.scale(ratio, ratio);
int w = (int) (originalWidth * ratio);
int h = (int) (originalHeight * ratio);
c.setX(originalX + ((originalWidth - w) / 2));
c.setY(originalY + ((originalHeight - h) / 2));
int currentDlgX = getDialogParent(getDestination()).getX();
int currentDlgY = getDialogParent(getDestination()).getY();
g.drawImage(buffer, currentDlgX, currentDlgY);
// paint(g, c, 0, 0);
g.resetAffine();
} else {
c.setWidth((int) (originalWidth * ratio));
c.setHeight((int) (originalHeight * ratio));
c.setX(originalX + ((originalWidth - c.getWidth()) / 2));
c.setY(originalY + ((originalHeight - c.getHeight()) / 2));
paint(g, c, 0, 0);
}
g.setAlpha(alpha);
return;
}
} catch (Throwable t) {
Log.p("An exception occurred during transition paint this might be valid in case of a resize in the middle of a transition");
Log.e(t);
}
}
Aggregations