Transition.java
上传用户:haobig99
上传日期:2022-06-15
资源大小:369k
文件大小:4k
源码类别:

J2ME

开发平台:

Java

  1. /*
  2.  * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
  3.  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4.  *
  5.  * This code is free software; you can redistribute it and/or modify it
  6.  * under the terms of the GNU General Public License version 2 only, as
  7.  * published by the Free Software Foundation.  Sun designates this
  8.  * particular file as subject to the "Classpath" exception as provided
  9.  * by Sun in the LICENSE file that accompanied this code.
  10.  *
  11.  * This code is distributed in the hope that it will be useful, but WITHOUT
  12.  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13.  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14.  * version 2 for more details (a copy is included in the LICENSE file that
  15.  * accompanied this code).
  16.  *
  17.  * You should have received a copy of the GNU General Public License version
  18.  * 2 along with this work; if not, write to the Free Software Foundation,
  19.  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20.  *
  21.  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  22.  * CA 95054 USA or visit www.sun.com if you need additional information or
  23.  * have any questions.
  24.  */
  25. package com.sun.lwuit.animations;
  26. import com.sun.lwuit.Component;
  27. import com.sun.lwuit.Container;
  28. import com.sun.lwuit.Form;
  29. import com.sun.lwuit.Graphics;
  30. /**
  31.  * Represents a transition animation between two forms this class is used internally
  32.  * by Display to play an animation when moving from one form to the next. A transition
  33.  * can be installed on a  {@link com.sun.lwuit.Form}  object using the in/out transitions, for ease of use
  34.  * {@link com.sun.lwuit.plaf.LookAndFeel} has support for default transitions. 
  35.  *
  36.  * @author Shai Almog
  37.  */
  38. public abstract class Transition implements Animation {
  39.     private Component source;
  40.     
  41.     private Component destination;
  42.     
  43.     /**
  44.      * Invoked by {@link com.sun.lwuit.Display} to set the source and destination forms.
  45.      * This method should not be invoked by developers.
  46.      * 
  47.      * @param source the source form from which the transition originates
  48.      * @param destination the destination form to which the transition will lead
  49.      */
  50.     public final void init(Component source, Component destination){
  51.         this.source = source;
  52.         this.destination = destination;
  53.         if (source != null && source instanceof Container) {
  54.             ((Container)source).layoutContainer();
  55.         }
  56.         if (destination != null && destination instanceof Container) {
  57.             ((Container)destination).layoutContainer();
  58.         }
  59.     }
  60.     
  61.     /**
  62.      * Callback thats invoked before a transition begins, the source form may be null
  63.      * for the first form in the application.
  64.      */
  65.     public void initTransition(){
  66.     }
  67.     
  68.     /**
  69.      * Returns the destination form that should be set once animation is completed
  70.      * 
  71.      * @return the destination component
  72.      */
  73.     public final Component getDestination(){
  74.         return destination;
  75.     }
  76.     
  77.     /**
  78.      * Returns the source form which is the form from which the animation is starting.
  79.      * This may be null for the first form in the application
  80.      * 
  81.      * @return the source component
  82.      */
  83.     public final Component getSource(){
  84.         return source;
  85.     }
  86.     /**
  87.      * Optional operation to cleanup the garbage left over by a running transition
  88.      */
  89.     public void cleanup() {
  90.         source = null;
  91.         destination = null;
  92.     }
  93.     
  94.     /**
  95.      * Create a copy of the transition, usually the transition used is a copy.
  96.      * 
  97.      * @return new transition instance
  98.      * @deprecated use the version that accepts boolean instead
  99.      */
  100.     public Transition copy() {
  101.         return copy(false);
  102.     }
  103.     /**
  104.      * Create a copy of the transition, usually the transition used is a copy.
  105.      *
  106.      * @param reverse creates a new transition instance with "reverse" behavior useful
  107.      * for signifying "back" operations
  108.      * @return new transition instance
  109.      */
  110.     public Transition copy(boolean reverse) {
  111.         // for compatibility with older transitions
  112.         return copy();
  113.     }
  114.     
  115.     /**
  116.      * Allows setting the source form to null to save memory if the transition doesn't need
  117.      * it in memory.
  118.      */
  119.     protected final void cleanSource() {
  120.         source = null;
  121.     }
  122.     
  123.     /**
  124.      * @inheritDoc
  125.      */
  126.     public abstract boolean animate();
  127.     
  128.     /**
  129.      * @inheritDoc
  130.      */
  131.     public abstract void paint(Graphics g);
  132. }