JAL-3032 adds Java 8 functionality (1/2)
[jalview.git] / src2 / net / miginfocom / layout / AnimSpec.java
1 package net.miginfocom.layout;
2
3 /*
4  * License (BSD):
5  * ==============
6  *
7  * Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (miglayout (at) miginfocom (dot) com)
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without modification,
11  * are permitted provided that the following conditions are met:
12  * Redistributions of source code must retain the above copyright notice, this list
13  * of conditions and the following disclaimer.
14  * Redistributions in binary form must reproduce the above copyright notice, this
15  * list of conditions and the following disclaimer in the documentation and/or other
16  * materials provided with the distribution.
17  * Neither the name of the MiG InfoCom AB nor the names of its contributors may be
18  * used to endorse or promote products derived from this software without specific
19  * prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24  * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
27  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
30  * OF SUCH DAMAGE.
31  *
32  * @version 1.0
33  */
34
35 import java.io.Serializable;
36
37 /**
38  * @author Mikael Grev, MiG InfoCom AB
39  *         Date: 14-09-24
40  *         Time: 17:05
41  */
42 public class AnimSpec implements Serializable
43 {
44 //      public static final AnimSpec OFF = new AnimSpec(-1, 0, 0);
45         public static final AnimSpec DEF = new AnimSpec(0, 0, 0.2f, 0.2f);
46
47         private final int prio;
48         private final int durMillis;
49         private final float easeIn, easeOut;
50
51         /**
52          * @param prio The animation priority. When added with the general animation priority of the layout the animation will
53          * be done if the resulting value is > 0.
54          * @param durMillis Duration in milliseconds. <=0 means default value should be used and > 0 is the number of millis
55          * @param easeIn 0 is linear (no ease). 1 is max ease. Always clamped between these values.
56          * @param easeOut 0 is linear (no ease). 1 is max ease. Always clamped between these values.
57          */
58         public AnimSpec(int prio, int durMillis, float easeIn, float easeOut)
59         {
60                 this.prio = prio;
61                 this.durMillis = durMillis;
62                 this.easeIn = LayoutUtil.clamp(easeIn, 0, 1);
63                 this.easeOut = LayoutUtil.clamp(easeOut, 0, 1);
64         }
65
66         /**
67          * @return The animation priority. When added with the general animation priority of the layout the animation will
68          * be done if the resulting value is > 0.
69          */
70         public int getPriority()
71         {
72                 return prio;
73         }
74
75         /**
76          * @param defMillis Default used if the millis in the spec is set to "default".
77          * @return Duration in milliseconds. <=0 means default value should be used and > 0 is the number of millis
78          */
79         public int getDurationMillis(int defMillis)
80         {
81                 return durMillis > 0 ? durMillis : defMillis;
82         }
83
84         /**
85          * @return Duration in milliseconds. <= 0 means default value should be used and > 0 is the number of millis
86          */
87         public int getDurationMillis()
88         {
89                 return durMillis;
90         }
91
92         /**
93          * @return A value between 0 and 1 where 0 is no ease in and 1 is maximum ease in.
94          */
95         public float getEaseIn()
96         {
97                 return easeIn;
98         }
99
100         /**
101          * @return A value between 0 and 1 where 0 is no ease out and 1 is maximum ease out.
102          */
103         public float getEaseOut()
104         {
105                 return easeOut;
106         }
107 }