001: package tide.greeting;
002:
003: import java.util.TimerTask;
004: import java.awt.font.*;
005: import java.awt.*;
006: import java.awt.Graphics;
007: import javax.swing.*;
008: import javax.swing.event.*;
009: import java.awt.event.*;
010:
011: public final class GreetingAnim extends JPanel {
012: java.util.Timer timer;
013:
014: public GreetingAnim() {
015: //setBackground(Color.WHITE);
016: timer = new java.util.Timer();
017: timer.scheduleAtFixedRate(new TimerTask() {
018: public void run() {
019: if (!isVisible())
020: return;
021: repaint();
022: }
023: }, 1000, 30);
024: }
025:
026: public void terminate() {
027: timer.cancel();
028: }
029:
030: int repaints = 0;
031: GlyphVector gv = null;
032:
033: int shiftX = 20, shiftY = 110;
034:
035: @Override
036: public void paintComponent(Graphics g) {
037: repaints++;
038: if (repaints > 2500)
039: timer.cancel();
040:
041: super .paintComponent(g);
042:
043: Font f = new Font("Lucida", Font.PLAIN, 64);
044: Graphics2D g2 = (Graphics2D) g;
045:
046: g2.setComposite(AlphaComposite.Src);
047: g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
048: RenderingHints.VALUE_ANTIALIAS_ON);
049: g2.setRenderingHint(RenderingHints.KEY_RENDERING,
050: RenderingHints.VALUE_RENDER_QUALITY);
051: if (gv == null) {
052: gv = f.createGlyphVector(g2.getFontRenderContext(), "tIDE");
053: }
054: Shape out = gv.getOutline(shiftX, shiftY);
055:
056: int width = getWidth();
057: int height = getHeight();
058:
059: int xgr = (int) (Math.sin(repaints / 40.0) * width);
060:
061: g2.setPaint(new GradientPaint(xgr, 0, Color.BLUE.brighter(),
062: xgr + 150, height, Color.white));
063: //g2.fillRect(0, 0, width, height);
064:
065: /*g2.setStroke(new BasicStroke(3, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
066: g2.setPaint(new GradientPaint(xgr, 0, Color.orange.brighter(), xgr+150, height, Color.white));
067: */
068: for (int i = 0; i < gv.getNumGlyphs(); i++) {
069: int dx = (int) (Math.sin(i * Math.PI / 2.0 + repaints
070: / 25.0) * 15.0);
071: dx = (int) (Math.exp(-repaints / 720.0) * dx);
072: drawGlyph(g2, gv.getGlyphOutline(i, shiftX, shiftY + dx),
073: false);
074: }
075: /*
076: g2.setPaint(new GradientPaint(0, 0, Color.darkGray, 0, height, Color.YELLOW));
077: g2.fill(out);
078:
079:
080: g2.setPaint(new GradientPaint(0, 0, Color.ORANGE, 0, height, Color.YELLOW));
081: g2.translate(2,2);
082: g2.fill(out);
083: g2.translate(-2,-2);
084:
085: int gn = repaints/10 % 4;
086: gn = gv.getNumGlyphs()-4+gn;
087:
088: g2.setColor(Color.ORANGE.darker());
089: g2.fill( gv.getGlyphOutline(gn,shiftX,shiftY));*/
090: }
091:
092: private void drawGlyph(Graphics2D g2, Shape out, boolean emph) {
093: int width = getWidth();
094: int height = getHeight();
095:
096: /* int xgr=100;
097: g2.setStroke(new BasicStroke(3, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
098: g2.setPaint(new GradientPaint(xgr, 0, Color.orange.brighter(), xgr+150, height, Color.white));
099: //g2.draw(out);*/
100:
101: g2.setPaint(new GradientPaint(0, 0, Color.darkGray, 0, height,
102: Color.YELLOW));
103: g2.fill(out);
104:
105: g2.setPaint(new GradientPaint(0, 0, Color.ORANGE, 0, height,
106: Color.YELLOW));
107: g2.translate(2, 2);
108: g2.fill(out);
109: g2.translate(-2, -2);
110:
111: if (emph) {
112: g2.setColor(Color.ORANGE.darker());
113: g2.fill(out);
114: }
115: }
116: /*
117: public static void main(String[] args)
118: {
119: JFrame f = new JFrame();
120: f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
121: GreetingAnim g = new GreetingAnim();
122: f.setContentPane(g);
123: f.setSize(160,350);
124: f.setLocationRelativeTo(null);
125: f.setVisible(true);
126:
127: }*/
128:
129: }
|