1 16 17 package org.mc4j.console.swing.animate; 18 19 import com.jgoodies.animation.Animations; 20 import com.jgoodies.animation.Animation; 21 import com.jgoodies.animation.AbstractAnimation; 22 import com.jgoodies.animation.Animator; 23 import com.jgoodies.animation.animations.BasicTextAnimation; 24 import com.jgoodies.animation.animations.BasicTextAnimations; 25 import com.jgoodies.animation.animations.FanAnimation; 26 import com.jgoodies.animation.components.BasicTextLabel; 27 import com.jgoodies.animation.components.FanComponent; 28 29 import javax.swing.*; 30 import java.awt.*; 31 import java.awt.geom.AffineTransform ; 32 import java.net.URL ; 33 34 import org.openide.util.Utilities; 35 36 40 41 public final class IntroPage extends JPanel{ 42 43 private BasicTextLabel label1; 45 private BasicTextLabel label2; 46 private FanComponent fan; 47 private TransformablePanel logoPanel; 48 49 52 private Animation animation; 53 private static final Color MC4J_COLOR = Color.decode("0x87ADCB"); 54 55 public static void main(String [] args) { 56 JFrame frame = new JFrame(); 57 frame.setContentPane(new IntroPage()); 58 frame.setSize(350, 300); 59 frame.setTitle("MC4J intro"); 60 frame.setDefaultCloseOperation(3); 61 locateOnScreenCenter(frame); 62 frame.setVisible(true); 63 } 64 65 private static void locateOnScreenCenter(Component component) { 66 Dimension paneSize = component.getSize(); 67 Dimension screenSize = component.getToolkit().getScreenSize(); 68 component.setLocation( 69 (screenSize.width - paneSize.width) / 2, 70 (screenSize.height - paneSize.height) / 2); 71 } 72 73 public IntroPage() { 74 buildContent(); 75 Animator animator = new Animator(animation(), 30); 76 animator.start(); 77 } 78 79 80 85 public Animation animation() { 86 return animation; 87 } 88 89 90 93 private void initComponents() { 94 Font font = getAnimationFont(); 95 label1 = new BasicTextLabel(" "); 96 label1.setFont(font.deriveFont(Font.BOLD,18)); 97 label1.setOpaque(false); 98 99 label2 = new BasicTextLabel(" "); 100 label2.setFont(font.deriveFont(Font.BOLD,18)); 101 label2.setOpaque(false); 102 103 fan = new FanComponent(3,MC4J_COLOR); 104 105 logoPanel = new TransformablePanel(); 106 } 107 108 112 public void buildContent() { 113 initComponents(); 114 animation = createAnimation(); 115 116 setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); 117 setOpaque(false); 118 119 add(label1); 120 add(label2); 121 122 } 125 126 128 133 private Animation createAnimation() { 134 Animation one = 135 BasicTextAnimation.defaultFade( 136 label1, 137 2500, 138 "Welcome to MC4J", 139 MC4J_COLOR); 140 141 Animation twoA = 142 BasicTextAnimation.defaultFade( 143 label1, 144 2500, 145 "JMX application management", 146 Color.darkGray); 147 Animation twoB = 148 BasicTextAnimation.defaultFade( 149 label2, 150 4000, 151 "and monitoring", 152 Color.darkGray); 153 154 Animation two = Animations.parallel(twoA, twoB); 155 156 Animation three = 157 BasicTextAnimation.defaultScale( 158 label1, 2000, 159 "for all major servers", 160 Color.blue); 161 162 163 Animation fourA = 164 Animations.sequential( 165 new Animation[] { 166 BasicTextAnimation.defaultFade( 167 label1, 168 1000, 169 "WebLogic", 170 Color.decode("0xAD170F")), 171 Animations.pause(1000), 172 BasicTextAnimation.defaultFade( 173 label1, 174 1000, 175 "Oracle OC4J", 176 Color.decode("0xFF0000")), 177 Animations.pause(1000), 178 BasicTextAnimation.defaultFade( 179 label1, 180 1000, 181 "Pramati", 182 Color.decode("0xD6E0E0")), 183 Animations.pause(1000), 184 BasicTextAnimation.defaultFade( 185 label1, 186 1000, 187 "Geronimo", 188 Color.decode("0xCCCCCC")), 189 Animations.pause(1000) 190 }); 191 192 Animation fourB = 193 Animations.sequential( 194 new Animation[] { 195 Animations.pause(1000), 196 BasicTextAnimation.defaultFade( 197 label2, 198 1000, 199 "WebSphere", 200 Color.decode("0x006699")), 201 Animations.pause(1000), 202 BasicTextAnimation.defaultFade( 203 label2, 204 1000, 205 "JBoss", 206 Color.decode("0xF28423")), 207 Animations.pause(1000), 208 BasicTextAnimation.defaultFade( 209 label2, 210 1000, 211 "Tomcat", 212 Color.decode("0x525D76")), 213 Animations.pause(1000), 214 BasicTextAnimation.defaultFade( 215 label2, 216 1000, 217 "JS2E 1.5", 218 Color.decode("0x594FBF")), 219 Animations.pause(1000) 220 }); 221 222 Animation four = Animations.parallel(fourA,fourB); 223 224 225 Animation five = 226 BasicTextAnimations.defaultSpace( 227 label1,label2,2000,4000,"Customizable Dashboards",Color.darkGray); 228 229 Animation six = 230 BasicTextAnimations.defaultSpace( 231 label1,label2,2000,4000,"Live graphs",Color.darkGray); 232 233 234 Animation fanAnimation = 235 FanAnimation.defaultFan(fan,8000); 236 237 Animation all = 238 Animations.repeat(10f, 239 Animations.sequential( 240 new Animation[] { 241 Animations.pause(500), 242 one, 243 Animations.pause(500), 244 two, 245 three, 246 Animations.pause(500), 247 four, 248 Animations.pause(500), 249 five, 250 Animations.pause(500), 251 six, 252 Animations.pause(3000), 253 })); 254 255 Animation base = 256 Animations.parallel( 257 Animations.repeat(50f,fanAnimation), 258 all); 259 260 264 return base; 265 } 266 267 269 275 private Font getAnimationFont() { 276 return new Font("Tahoma", Font.BOLD, 18); 277 } 278 279 public static class TransformablePanel extends JPanel { 280 private AffineTransform currentTransform; 281 public void setTransform(AffineTransform transform) { 282 this.currentTransform = transform; 283 } 284 285 double angle; 286 public void setAngle(double angle) { 287 this.angle = angle; 288 } 289 290 private AlphaComposite slightAlpha = 291 AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f); 292 protected void paintChildren(Graphics g) { 293 ((Graphics2D)g).setComposite(slightAlpha); 296 super.paintChildren(g); 297 } 299 } 300 301 302 public static class LogoAnimation extends AbstractAnimation { 303 304 private TransformablePanel target; 305 private Image image; 306 307 public LogoAnimation(long l, TransformablePanel target) { 308 super(l); 309 this.target = target; 310 311 URL url = getClass().getClassLoader().getResource("images/FullLogo.gif"); 312 image = Toolkit.getDefaultToolkit().createImage(url); 313 target.add(new JLabel(new ImageIcon(image))); 314 } 315 316 protected void applyEffect(long l) { 317 AffineTransform transform = AffineTransform.getRotateInstance(l * 0.05); 318 319 target.setAngle(l * 0.05); 320 } 321 } 322 323 } | Popular Tags |