package com.sun.j2ee.blueprints.admin.client;
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;
public class About extends JDialog {
private AboutPanel panel;
public About(String title, String display, String[] names, Frame owner,
boolean modal) {
super(owner, title, modal);
panel = new AboutPanel(names);
panel.setLayout(new BorderLayout());
panel.add(new TranLabel(display), BorderLayout.NORTH);
setContentPane(panel);
setSize(320, 150);
setResizable(false);
}
public void setVisible(boolean b) {
if (b) {
panel.start();
} else {
panel.stop();
}
super.setVisible(b);
}
}
class AboutPanel extends JPanel implements ActionListener {
private static final ImageIcon[] icons = new ImageIcon[10];
static {
for (int i = 0; i < icons.length; i++) {
icons[i] = new ImageIcon(About.class.getResource("/resources/duke"
+ i + ".gif"));
}
}
private static final Color bgColorA = Color.white;
private static final Color bgColorB = new Color(120, 120, 255);
private static final Font nameFont = new Font("Dialog", Font.BOLD, 25);
private static final RenderingHints hints =
new RenderingHints(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
private int iconIndex = icons.length;
private String[] names;
private Timer timer = new Timer(80, this);
private boolean fading = false;
private int nameIndex = 0;
private int nameY = -10;
private float fade = 1.0f;
private int cachedWidth = 0;
private int cachedHeight = 0;
private GradientPaint bgPaint = null;
public AboutPanel(String[] names) {
this.names = names;
setOpaque(true);
setBorder(BorderFactory.createLoweredBevelBorder());
}
public void paintComponent(Graphics g) {
Graphics2D g2d = (Graphics2D)g.create();
int xloc;
int yloc;
int width = getWidth();
int height = getHeight();
if (cachedWidth != width || cachedHeight != height || bgPaint == null) {
cachedWidth = width;
cachedHeight = height;
bgPaint = new GradientPaint(0, 0, bgColorA, cachedWidth,
cachedHeight, bgColorB);
}
g2d.setRenderingHints(hints);
g2d.setPaint(bgPaint);
g2d.fillRect(0, 0, cachedWidth, cachedHeight);
ImageIcon icon = icons[iconIndex >= icons.length ? 0 : iconIndex];
xloc = getInsets().left;
yloc = cachedHeight - getInsets().bottom - 6 - icon.getIconHeight();
icon.paintIcon(this, g2d, xloc, yloc);
if (fading) {
g2d.setComposite(AlphaComposite.getInstance(
AlphaComposite.SRC_OVER, fade));
} else if (nameY >= cachedHeight - getInsets().bottom - 22) {
fading = true;
iconIndex = 0;
}
Rectangle rect = nameFont.getStringBounds(names[nameIndex],
g2d.getFontRenderContext()).getBounds();
g2d.setFont(nameFont);
xloc = xloc + icon.getIconWidth() + 5;
Paint paint = new GradientPaint(xloc, nameY, Color.red, xloc
+ rect.width, nameY, Color.blue);
g2d.setPaint(paint);
g2d.drawString(names[nameIndex], xloc, nameY);
g2d.dispose();
}
public void start() {
timer.start();
}
public void stop() {
timer.stop();
}
public void actionPerformed(ActionEvent ae) {
if (fading || iconIndex <= icons.length) {
iconIndex++;
}
if (fading) {
fade = fade - 0.05f;
if (fade <= 0.0f) {
nameIndex = (nameIndex + 1) % names.length;
nameY = -10;
fading = false;
fade = 1.0f;
}
} else {
nameY += 2;
}
repaint();
}
}
class TranLabel extends JLabel {
private static final RenderingHints hints =
new RenderingHints(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
private static final AlphaComposite composite =
AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.6f);
private static final Color bgColor = Color.white;
public TranLabel(String display) {
super();
setHorizontalAlignment(SwingConstants.CENTER);
setText("<html><font color=black face=\"Dialog\">" + display
+ "</font></html>");
}
public void paintComponent(Graphics g) {
Graphics2D g2d = (Graphics2D)g.create();
g2d.setRenderingHints(hints);
g2d.setComposite(composite);
g2d.setColor(bgColor);
g2d.fillRect(0, 0, getWidth(), getHeight());
super.paintComponent(g2d);
g2d.dispose();
}
}