Bubble.java
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13: package xeij;
14:
15: import java.awt.*;
16: import java.awt.font.*;
17: import java.awt.geom.*;
18:
19:
20:
21: public class Bubble {
22:
23: public static final boolean BBL_ON = true;
24: public static final int BBL_FONT_SIZE = 24;
25: public static final int BBL_Y = BBL_FONT_SIZE * 2;
26: public static final int BBL_PADDING_X = BBL_FONT_SIZE * 1;
27: public static final int BBL_PADDING_Y = BBL_FONT_SIZE / 2;
28: public static final Font BBL_FONT = new Font ("SansSerif", Font.PLAIN, BBL_FONT_SIZE);
29:
30: public static Color bblBackground;
31: public static Color bblForeground;
32: public static String bblText;
33: public static long bblEndTime;
34:
35: public static void bblInit () {
36: bblBackground = new Color (LnF.lnfRGB[14]);
37: bblForeground = new Color (LnF.lnfRGB[0]);
38: bblText = null;
39: bblEndTime = 0L;
40: }
41:
42:
43:
44: public static void bblStart (String text, long time) {
45: bblText = text;
46: bblEndTime = System.currentTimeMillis () + time;
47: }
48:
49:
50:
51: public static void bblDraw (Graphics2D g2) {
52: if (bblText != null) {
53: g2.setRenderingHint (RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
54: g2.setFont (BBL_FONT);
55: TextLayout tl = new TextLayout (bblText, BBL_FONT, g2.getFontRenderContext ());
56: Rectangle2D r = tl.getBounds ();
57: int x = (XEiJ.pnlWidth >> 1) - ((int) r.getWidth () >> 1);
58: int y = BBL_Y;
59: g2.setColor (bblBackground);
60: g2.fillRect ((int) r.getX () + x - BBL_PADDING_X,
61: (int) r.getY () + y - BBL_PADDING_Y,
62: (int) r.getWidth () + (BBL_PADDING_X << 1),
63: (int) r.getHeight () + (BBL_PADDING_Y << 1));
64: g2.setColor (bblForeground);
65: tl.draw (g2, x, y);
66: if (bblEndTime <= System.currentTimeMillis ()) {
67: bblEnd ();
68: }
69: }
70: }
71:
72:
73:
74: public static void bblEnd () {
75: bblText = null;
76: bblEndTime = 0L;
77: }
78:
79: }