001: /*
002:
003: Licensed to the Apache Software Foundation (ASF) under one or more
004: contributor license agreements. See the NOTICE file distributed with
005: this work for additional information regarding copyright ownership.
006: The ASF licenses this file to You under the Apache License, Version 2.0
007: (the "License"); you may not use this file except in compliance with
008: the License. You may obtain a copy of the License at
009:
010: http://www.apache.org/licenses/LICENSE-2.0
011:
012: Unless required by applicable law or agreed to in writing, software
013: distributed under the License is distributed on an "AS IS" BASIS,
014: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: See the License for the specific language governing permissions and
016: limitations under the License.
017:
018: */
019: package org.apache.batik.anim.values;
020:
021: import org.apache.batik.dom.anim.AnimationTarget;
022:
023: /**
024: * An integer in the animation engine.
025: *
026: * @author <a href="mailto:cam%40mcc%2eid%2eau">Cameron McCormack</a>
027: * @version $Id: AnimatableIntegerValue.java 475477 2006-11-15 22:44:28Z cam $
028: */
029: public class AnimatableIntegerValue extends AnimatableValue {
030:
031: /**
032: * The value.
033: */
034: protected int value;
035:
036: /**
037: * Creates a new, uninitialized AnimatableIntegerValue.
038: */
039: protected AnimatableIntegerValue(AnimationTarget target) {
040: super (target);
041: }
042:
043: /**
044: * Creates a new AnimatableIntegerValue.
045: */
046: public AnimatableIntegerValue(AnimationTarget target, int v) {
047: super (target);
048: value = v;
049: }
050:
051: /**
052: * Performs interpolation to the given value.
053: */
054: public AnimatableValue interpolate(AnimatableValue result,
055: AnimatableValue to, float interpolation,
056: AnimatableValue accumulation, int multiplier) {
057: AnimatableIntegerValue res;
058: if (result == null) {
059: res = new AnimatableIntegerValue(target);
060: } else {
061: res = (AnimatableIntegerValue) result;
062: }
063:
064: int v = value;
065: if (to != null) {
066: AnimatableIntegerValue toInteger = (AnimatableIntegerValue) to;
067: v += value + interpolation * (toInteger.getValue() - value);
068: }
069: if (accumulation != null) {
070: AnimatableIntegerValue accInteger = (AnimatableIntegerValue) accumulation;
071: v += multiplier * accInteger.getValue();
072: }
073:
074: if (res.value != v) {
075: res.value = v;
076: res.hasChanged = true;
077: }
078: return res;
079: }
080:
081: /**
082: * Returns the integer value.
083: */
084: public int getValue() {
085: return value;
086: }
087:
088: /**
089: * Returns whether two values of this type can have their distance
090: * computed, as needed by paced animation.
091: */
092: public boolean canPace() {
093: return true;
094: }
095:
096: /**
097: * Returns the absolute distance between this value and the specified other
098: * value.
099: */
100: public float distanceTo(AnimatableValue other) {
101: AnimatableIntegerValue o = (AnimatableIntegerValue) other;
102: return Math.abs(value - o.value);
103: }
104:
105: /**
106: * Returns a zero value of this AnimatableValue's type.
107: */
108: public AnimatableValue getZeroValue() {
109: return new AnimatableIntegerValue(target, 0);
110: }
111:
112: /**
113: * Returns the CSS text representation of the value.
114: */
115: public String getCssText() {
116: return Integer.toString(value);
117: }
118: }
|