package edu.princeton.toy; import java.awt.*; import javax.swing.*; import edu.princeton.swing.*; /** * TSplashWindow is the splash window which pops up at startup. Due to the image-specific qualities * of the TSplashWindow, this class cannot be generalized for other uses. * * @author btsang * @version 7.1 */ public class TSplashWindow extends JWindow { private static final Toolkit TOOLKIT = Toolkit.getDefaultToolkit(); private static final Rectangle TEXT_RECTANGLE = new Rectangle(210, 40, 85, 180); private static final String TEXT_STRINGS[] = { "Author", " B. Tsang", null, "Advisors", "(to be scrambled)", "(to be scrambled)", "(to be scrambled)", null, "Version", " " + TMain.getVersion(), null, "Build Date", " " + TMain.getBuildDate() }; private static final Font HEADING_LABEL_FONT = new Font("Dialog", Font.BOLD, 12); private static final Font TEXT_LABEL_FONT = new Font("Dialog", Font.PLAIN, 11); private static final int SEPARATOR_HEIGHT = 5; private static final Color FONT_COLOR = new Color(102, 102, 153); /** * Scramble the advisors section (for fun). */ static { switch ((int)(Math.random() * 6)) { case 0: TEXT_STRINGS[4] = " D. Clark"; TEXT_STRINGS[5] = " R. Sedgewick"; TEXT_STRINGS[6] = " K. Wayne"; break; case 1: TEXT_STRINGS[4] = " D. Clark"; TEXT_STRINGS[5] = " K. Wayne"; TEXT_STRINGS[6] = " R. Sedgewick"; break; case 2: TEXT_STRINGS[4] = " R. Sedgewick"; TEXT_STRINGS[5] = " K. Wayne"; TEXT_STRINGS[6] = " D. Clark"; break; case 3: TEXT_STRINGS[4] = " R. Sedgewick"; TEXT_STRINGS[5] = " D. Clark"; TEXT_STRINGS[6] = " K. Wayne"; break; case 4: TEXT_STRINGS[4] = " K. Wayne"; TEXT_STRINGS[5] = " R. Sedgewick"; TEXT_STRINGS[6] = " D. Clark"; break; default: TEXT_STRINGS[4] = " K. Wayne"; TEXT_STRINGS[5] = " D. Clark"; TEXT_STRINGS[6] = " R. Sedgewick"; } } /** * Constructs a TSplashWindow, centered in the screen. */ public TSplashWindow() { super(); Icon icon = TImageManager.getIcon( TImageManager.STARTUP_UNSCALED_IMAGE_GROUP, TImageManager.STARTUP_UNSCALED_SPLASH_BACKGROUND ); int width = icon.getIconWidth(); int height = icon.getIconHeight(); PTransparentPanel labelPanel = new PTransparentPanel(new GridBagLayout()); for (int ctr = 0; ctr < TEXT_STRINGS.length; ctr++) { JComponent label; if (TEXT_STRINGS[ctr] != null) { label = new JLabel(TEXT_STRINGS[ctr]); if (!TEXT_STRINGS[ctr].startsWith(" ")) label.setFont(HEADING_LABEL_FONT); else label.setFont(TEXT_LABEL_FONT); label.setForeground(FONT_COLOR); } else { label = new PSpacer(TEXT_RECTANGLE.width, SEPARATOR_HEIGHT); } labelPanel.add( label, new GridBagConstraints( 0, ctr, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0 ) ); } labelPanel.add( new PSpacer(1, 1), new GridBagConstraints( 0, TEXT_STRINGS.length, 1, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0 ) ); PImagePanel imagePanel = new PImagePanel( icon, new BorderLayout() ); imagePanel.add( new PSpacer(width, TEXT_RECTANGLE.y), BorderLayout.NORTH ); imagePanel.add( new PSpacer(TEXT_RECTANGLE.x, TEXT_RECTANGLE.height), BorderLayout.WEST ); imagePanel.add( new PSpacer(width, height - TEXT_RECTANGLE.y - TEXT_RECTANGLE.height), BorderLayout.SOUTH ); imagePanel.add( new PSpacer(width - TEXT_RECTANGLE.x - TEXT_RECTANGLE.width, TEXT_RECTANGLE.height), BorderLayout.EAST ); imagePanel.add( labelPanel, BorderLayout.CENTER ); getContentPane().add(imagePanel); Dimension screenSize = TOOLKIT.getScreenSize(); setBounds( screenSize.width / 2 - width / 2, screenSize.height / 2 - height / 2, width, height ); } }