Spec-Zone .ru
спецификации, руководства, описания, API
001/*
002 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation.  Oracle designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Oracle in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
022 * or visit www.oracle.com if you need additional information or have any
023 * questions.
024 */
025
026package javafx.animation;
027
028import javafx.beans.property.ObjectProperty;
029import javafx.beans.property.ObjectPropertyBase;
030import javafx.util.Duration;
031
032/**
033 * This {@code Transition} executes an {@link Animation#onFinished} at the end of its
034 * {@link #duration}.
035 * 
036 * <p>
037 * Code Segment Example:
038 * </p>
039 * 
040 * <pre>
041 * <code>
042 * import javafx.scene.shape.*;
043 * import javafx.animation.transition.*;
044 * 
045 * ...
046 * 
047 *     Rectangle rect = new Rectangle (100, 40, 100, 100);
048 *     rect.setArcHeight(50);
049 *     rect.setArcWidth(50);
050 *     rect.setFill(Color.VIOLET);
051 * 
052 *     RotateTransition rt = new RotateTransition(Duration.millis(3000), rect);
053 *     rt.setByAngle(180);
054 *     rt.setCycleCount(4f);
055 *     rt.setAutoReverse(true);
056 *     SequentialTransition seqTransition = new SequentialTransition (
057 *         new PauseTransition(Duration.millis(1000)), // wait a second
058 *         rt
059 *     );
060 *     seqTransition.play();
061 * 
062 * ...
063 * 
064 * </code>
065 * </pre>
066 * 
067 * @see Transition
068 * @see Animation
069 * 
070 */
071public final class PauseTransition extends Transition {
072
073    /**
074     * The duration of this {@code Transition}. 
075     * <p>
076     * It is not possible to change the {@code duration} of a running
077     * {@code PauseTransition}. If the value of {@code duration} is changed for a
078     * running {@code PauseTransition}, the animation has to be stopped and started again to
079     * pick up the new value.
080     * <p>
081     * Note: While the unit of {@code duration} is a millisecond, the
082     * granularity depends on the underlying operating system and will in
083     * general be larger. For example animations on desktop systems usually run
084     * with a maximum of 60fps which gives a granularity of ~17 ms.
085     *
086     * Setting duration to value lower than {@link Duration#ZERO} will result
087     * in {@link IllegalArgumentException}.
088     * 
089     * @defaultValue 400ms
090     */
091    private ObjectProperty<Duration> duration;
092    private static final Duration DEFAULT_DURATION = Duration.millis(400);
093
094    public final void setDuration(Duration value) {
095        if ((duration != null) || (!DEFAULT_DURATION.equals(value))) {
096            durationProperty().set(value);
097        }
098    }
099
100    public final Duration getDuration() {
101        return (duration == null)? DEFAULT_DURATION : duration.get();
102    }
103
104    public final ObjectProperty<Duration> durationProperty() {
105        if (duration == null) {
106            duration = new ObjectPropertyBase<Duration>(DEFAULT_DURATION) {
107
108                @Override
109                public void invalidated() {
110                    try {
111                        setCycleDuration(getDuration());
112                    } catch (IllegalArgumentException e) {
113                        if (isBound()) {
114                            unbind();
115                        }
116                        set(getCycleDuration());
117                        throw e;
118                    }
119                }
120
121                @Override
122                public Object getBean() {
123                    return PauseTransition.this;
124                }
125
126                @Override
127                public String getName() {
128                    return "duration";
129                }
130            };
131        }
132        return duration;
133    }
134
135    /**
136     * The constructor of {@code PauseTransition}.
137     * 
138     * @param duration
139     *            The duration of the {@code PauseTransition}
140     */
141    public PauseTransition(Duration duration) {
142        setDuration(duration);
143        setCycleDuration(duration);
144    }
145
146    /**
147     * The constructor of {@code PauseTransition}
148     */
149    public PauseTransition() {
150        this(DEFAULT_DURATION);
151    }
152
153    /**
154     * {@inheritDoc}
155     */
156    @Override
157    public void interpolate(double frac) {
158        // no-op
159    }
160}