00001 package edu.stanford.hci.r3.util.graphics;
00002
00003 import java.awt.BasicStroke;
00004 import java.awt.Color;
00005 import java.awt.Graphics2D;
00006 import java.awt.SplashScreen;
00007 import java.awt.geom.Line2D;
00008 import java.awt.geom.Point2D;
00009 import java.util.ArrayList;
00010 import java.util.List;
00011
00012 import edu.stanford.hci.r3.util.MathUtils;
00013
00026 public class SplashScreenUtils {
00027
00034 public static void animateSplashScreen(final long maxNumMilliseconds, final Point2D center) {
00035
00036 final SplashScreen splashScreen = SplashScreen.getSplashScreen();
00037 if (splashScreen == null) {
00038 return;
00039 }
00040
00041
00042 final double radius = 26;
00043 final double numBars = 12;
00044
00045
00046 final long dTimeMillis = MathUtils.rint(700 / numBars);
00047
00048 final double dTheta = (2 * Math.PI / numBars);
00049 final double paddingX = 16;
00050 final double paddingY = 16;
00051 final float strokeThickness = 4.5f;
00052
00053
00054 final List<Color> colors = new ArrayList<Color>();
00055 final double dColor = .4f / numBars;
00056 float colorValue = .4f;
00057
00058 double theta = Math.PI;
00059 final List<Double> dX = new ArrayList<Double>();
00060 final List<Double> dY = new ArrayList<Double>();
00061
00062 for (int i = 0; i < numBars; i++) {
00063 colors.add(new Color(colorValue, colorValue, colorValue));
00064 colorValue -= dColor;
00065
00066 dX.add(Math.cos(theta));
00067 dY.add(Math.sin(theta));
00068 theta -= dTheta;
00069 }
00070
00071
00072 new Thread(new Runnable() {
00073 public void run() {
00074 try {
00075 final Graphics2D g = splashScreen.createGraphics();
00076 g.setRenderingHints(GraphicsUtils.getBestRenderingHints());
00077 g.setStroke(new BasicStroke(strokeThickness, BasicStroke.CAP_ROUND,
00078 BasicStroke.JOIN_ROUND));
00079
00080 int colorOffset = 0;
00081 long timeAnimating = 0;
00082 while (timeAnimating < maxNumMilliseconds) {
00083
00084 for (int i = 0; i < numBars; i++) {
00085
00086
00087
00088 g.setColor(colors.get((int) ((i + colorOffset) % numBars)));
00089 Double dYVal = dY.get(i);
00090 Double dXVal = dX.get(i);
00091 g.draw(new Line2D.Double(center.getX() + dXVal * paddingX, center
00092 .getY()
00093 + dYVal * paddingY, center.getX() + dXVal * radius, center
00094 .getY()
00095 + dYVal * radius));
00096 }
00097 splashScreen.update();
00098
00099 colorOffset++;
00100 if (colorOffset == numBars) {
00101 colorOffset = 0;
00102 }
00103
00104 Thread.sleep(dTimeMillis);
00105 timeAnimating += dTimeMillis;
00106 }
00107 splashScreen.close();
00108 } catch (IllegalStateException ise) {
00109
00110 return;
00111 } catch (InterruptedException e) {
00112 e.printStackTrace();
00113 }
00114 }
00115 }).start();
00116
00117 }
00118 }