📄 commontransitions.java
字号:
/* * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, * CA 95054 USA or visit www.sun.com if you need additional information or * have any questions. */package com.sun.lwuit.animations;import com.sun.lwuit.Component;import com.sun.lwuit.Dialog;import com.sun.lwuit.Graphics;import com.sun.lwuit.Image;import com.sun.lwuit.Painter;import com.sun.lwuit.RGBImage;/** * Contains common transition animations including the following: * <ol> * <li>Slide - the exiting form slides out of the screen while the new form slides in. * <li>Fade - components fade into/out of the screen * </ol> * <p>Instances of this class are created using factory methods. * * @author Shai Almog, Chen Fishbein */public final class CommonTransitions extends Transition { private Motion motion; private static final int TYPE_EMPTY = 0; private static final int TYPE_SLIDE = 1; private static final int TYPE_FADE = 2; /** * Slide the transtion horizontally * @see #createSlide */ public static final int SLIDE_HORIZONTAL = 0; /** * Slide the transtion vertically * @see #createSlide */ public static final int SLIDE_VERTICAL = 1; private int slideType; private int speed; private int position; private int transitionType; private Image buffer; /** * The transition is a special case where we "keep" an allocated buffer */ private RGBImage rgbBuffer; private boolean forward; private boolean drawDialogMenu; private boolean firstFinished; private CommonTransitions(int type) { transitionType = type; } /** * Creates an empty transition that does nothing. This has the same effect as * setting a transition to null. */ public static CommonTransitions createEmpty() { CommonTransitions t = new CommonTransitions(TYPE_EMPTY); return t; } /** * Creates a slide transition with the given duration and direction * * @param type type can be either vertically or horizontally, which means * the movement direction of the transition * @param forward forward is a boolean value, represent the directions of * switching forms, for example for a horizontally type, true means * horizontally movement to right. * @param duration represent the time the transition should take in millisecond * @return a transition object */ public static CommonTransitions createSlide(int type, boolean forward, int duration) { return createSlide(type, forward, duration, false); } /** * Creates a slide transition with the given duration and direction * * @param type type can be either vertically or horizontally, which means * the movement direction of the transition * @param forward forward is a boolean value, represent the directions of * switching forms, for example for a horizontally type, true means * horizontally movement to right. * @param duration represent the time the transition should take in millisecond * @param drawDialogMenu indicates that the menu of the dialog should be kept during * a slide transition. This is only relevant for dialog in/out transitions. * @return a transition object */ public static CommonTransitions createSlide(int type, boolean forward, int duration, boolean drawDialogMenu) { CommonTransitions t = new CommonTransitions(TYPE_SLIDE); t.slideType = type; t.forward = forward; t.speed = duration; t.position = 0; t.drawDialogMenu = drawDialogMenu; return t; } /** * Creates a transition for fading a form in while fading out the original form * * @param duration represent the time the transition should take in millisecond * @return a transition object */ public static CommonTransitions createFade(int duration) { CommonTransitions t = new CommonTransitions(TYPE_FADE); t.speed = duration; return t; } /** * @inheritDoc */ public void initTransition() { // for series 40 devices System.gc(); firstFinished = false; if(transitionType == TYPE_EMPTY) { return; } Component source = getSource(); Component destination = getDestination(); position = 0; int w = source.getWidth(); int h = source.getHeight(); if (buffer == null) { buffer = Image.createImage(w, h); } else { // this might happen when screen orientation changes or a MIDlet moves // to an external screen if(buffer.getWidth() != w || buffer.getHeight() != h) { buffer = Image.createImage(w, h); rgbBuffer = null; // slide motion might need resetting since screen size is different motion = null; } } if(transitionType == TYPE_FADE) { motion = Motion.createSplineMotion(0, 256, speed); motion.start(); Graphics g = buffer.getGraphics(); g.translate(-source.getAbsoluteX(), -source.getAbsoluteY()); if(getSource().getParent() != null){ getSource().getComponentForm().paintComponent(g); } //getSource().paintBackgrounds(g); paint(g, getDestination(), 0, 0); rgbBuffer = new RGBImage(buffer.getRGB(), buffer.getWidth(), buffer.getHeight()); paint(g, getSource(), 0, 0); g.translate(source.getAbsoluteX(), source.getAbsoluteY()); } else { if (transitionType == TYPE_SLIDE) { int dest; int startOffset = 0; if (slideType == SLIDE_HORIZONTAL) { dest = w; if(destination instanceof Dialog) { startOffset = w - ((Dialog)destination).getContentPane().getWidth(); if(forward) { startOffset -= ((Dialog)destination).getContentPane().getStyle().getMargin(Component.LEFT); } else { startOffset -= ((Dialog)destination).getContentPane().getStyle().getMargin(Component.RIGHT); } } else { if(source instanceof Dialog) { dest = ((Dialog)source).getContentPane().getWidth(); if(forward) { dest += ((Dialog)source).getContentPane().getStyle().getMargin(Component.LEFT); } else { dest += ((Dialog)source).getContentPane().getStyle().getMargin(Component.RIGHT); } } } } else { dest = h; if(destination instanceof Dialog) { startOffset = h - ((Dialog)destination).getContentPane().getHeight() - ((Dialog)destination).getTitleComponent().getHeight(); if(forward) { startOffset -= ((Dialog)destination).getContentPane().getStyle().getMargin(Component.BOTTOM); } else { startOffset -= ((Dialog)destination).getContentPane().getStyle().getMargin(Component.TOP); startOffset -= ((Dialog)destination).getTitleStyle().getMargin(Component.TOP); if(!drawDialogMenu && ((Dialog)destination).getCommandCount() > 0) { startOffset -= ((Dialog)destination).getSoftButton(0).getParent().getHeight(); } } } else { if(source instanceof Dialog) { dest = ((Dialog)source).getContentPane().getHeight() + ((Dialog)source).getTitleComponent().getHeight(); if(forward) { dest += ((Dialog)source).getContentPane().getStyle().getMargin(Component.BOTTOM); } else { dest += ((Dialog)source).getContentPane().getStyle().getMargin(Component.TOP); dest += ((Dialog)source).getTitleStyle().getMargin(Component.TOP); if(((Dialog)source).getCommandCount() > 0) { dest += ((Dialog)source).getSoftButton(0).getParent().getHeight(); } } } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -