01: /*
02: * Copyright 2001-2006 C:1 Financial Services GmbH
03: *
04: * This software is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License Version 2.1, as published by the Free Software Foundation.
07: *
08: * This software is distributed in the hope that it will be useful,
09: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11: * Lesser General Public License for more details.
12: *
13: * You should have received a copy of the GNU Lesser General Public
14: * License along with this library; if not, write to the Free Software
15: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
16: */
17:
18: package de.finix.contelligent.client.util;
19:
20: import java.awt.Color;
21: import java.awt.Graphics;
22: import java.awt.Graphics2D;
23:
24: import javax.swing.JComponent;
25: import javax.swing.SwingUtilities;
26:
27: import de.finix.contelligent.client.base.ContelligentConstants;
28:
29: public class EventIndicatorPanel extends JComponent {
30:
31: private static int SPEED = 2;
32:
33: private static int PEAK = 4; // 0 = max
34:
35: private int level = 0;
36:
37: private boolean isRunning = false;
38:
39: public void paint(Graphics g) {
40: Graphics2D g2d = (Graphics2D) g;
41: g2d.setColor(Color.white);
42: g2d.fillRect(0, 0, getWidth(), getHeight());
43: g2d.setColor(ContelligentConstants.CI_COLOR);
44: g2d
45: .fillRect(getWidth() / 4, level, getWidth() / 2,
46: getHeight());
47: g2d.setColor(Color.darkGray);
48: g2d.drawRect(0, 0, getWidth(), getHeight());
49: g2d.drawRect(getWidth() / 6, level, getWidth() * 4 / 6,
50: getHeight());
51: }
52:
53: public void onEvent() {
54: level = PEAK;
55: EventIndicatorPanel.this .repaint();
56: if (!isRunning) {
57: isRunning = true;
58: java.util.Timer updateTimer = new java.util.Timer(true); // generate
59: // a
60: // timer
61: // using
62: // a
63: // daemon
64: // thread
65: updateTimer.scheduleAtFixedRate(new java.util.TimerTask() {
66: public void run() {
67: if (level <= getHeight()
68: && !SwingUtilities.isEventDispatchThread()) {
69: SwingUtilities.invokeLater(new Runnable() {
70: public void run() {
71: EventIndicatorPanel.this .repaint();
72: }
73: });
74: }
75: level = level + SPEED;
76: }
77: }, 100, 100);
78: }
79: }
80: }
|