1 30 31 package com.jgoodies.animation.animations; 32 33 import java.awt.Color ; 34 import java.util.LinkedList ; 35 import java.util.List ; 36 37 import com.jgoodies.animation.Animation; 38 import com.jgoodies.animation.AnimationUtils; 39 import com.jgoodies.animation.Animations; 40 import com.jgoodies.animation.components.BasicTextLabel; 41 42 43 52 public final class BasicTextAnimations { 53 54 private static final int FADE_TYPE = 0; 55 private static final int SCALE_TYPE = 1; 56 private static final int SPACE_TYPE = 2; 57 58 59 private BasicTextAnimations() { 60 } 62 63 64 76 public static Animation defaultFade( 77 BasicTextLabel label1, 78 BasicTextLabel label2, 79 long singleDuration, 80 long beginOffset, 81 String separatedTexts, 82 Color baseColor) { 83 84 return createTextSequence(label1, label2, 85 singleDuration, beginOffset, 86 separatedTexts, baseColor, 87 FADE_TYPE); 88 } 89 90 91 103 public static Animation defaultScale( 104 BasicTextLabel label1, 105 BasicTextLabel label2, 106 long singleDuration, 107 long beginOffset, 108 String separatedTexts, 109 Color baseColor) { 110 111 return createTextSequence(label1, label2, 112 singleDuration, beginOffset, 113 separatedTexts, baseColor, 114 SCALE_TYPE); 115 } 116 117 118 130 public static Animation defaultSpace( 131 BasicTextLabel label1, 132 BasicTextLabel label2, 133 long singleDuration, 134 long beginOffset, 135 String separatedTexts, 136 Color baseColor) { 137 138 return createTextSequence(label1, label2, 139 singleDuration, beginOffset, 140 separatedTexts, baseColor, 141 SPACE_TYPE); 142 } 143 144 145 147 159 private static Animation createTextSequence( 160 BasicTextLabel label1, 161 BasicTextLabel label2, 162 long singleDuration, 163 long beginOffset, 164 String separatedTexts, 165 Color baseColor, 166 int type) { 167 168 Animation animation; 169 String [] texts = AnimationUtils.splitTexts(separatedTexts); 170 List animations = new LinkedList (); 171 long beginTime = 0; 172 173 BasicTextLabel label = label1; 174 for (int i = 0; i < texts.length; i++) { 175 label = i % 2 == 0 ? label1 : label2; 176 animation = animation(label, singleDuration, texts[i], baseColor, type); 177 animations.add(Animations.offset(beginTime, animation)); 178 beginTime += singleDuration + beginOffset; 179 } 180 181 return Animations.parallel(animations); 182 } 183 184 185 private static Animation animation(BasicTextLabel label, 186 long duration, 187 String text, 188 Color baseColor, 189 int type) { 190 switch (type) { 191 case FADE_TYPE : 192 return BasicTextAnimation.defaultFade(label, duration, text, baseColor); 193 194 case SCALE_TYPE : 195 return BasicTextAnimation.defaultScale(label, duration, text, baseColor); 196 197 case SPACE_TYPE : 198 return BasicTextAnimation.defaultSpace(label, duration, text, baseColor); 199 200 default : 201 return null; 202 } 203 } 204 205 206 } | Popular Tags |