01: //The contents of this file are subject to the Mozilla Public License Version 1.1
02: //(the "License"); you may not use this file except in compliance with the
03: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
04: //
05: //Software distributed under the License is distributed on an "AS IS" basis,
06: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
07: //for the specific language governing rights and
08: //limitations under the License.
09: //
10: //The Original Code is "The Columba Project"
11: //
12: //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14: //
15: //All Rights Reserved.
16:
17: package org.columba.core.gui.util;
18:
19: import java.awt.BorderLayout;
20:
21: import javax.swing.JPanel;
22:
23: import org.columba.core.command.TaskManager;
24: import org.columba.core.command.TaskManagerEvent;
25: import org.columba.core.command.TaskManagerListener;
26: import org.columba.core.gui.base.AnimatedGIFComponent;
27: import org.columba.core.resourceloader.ImageLoader;
28:
29: /**
30: * Animated image showing background activity.
31: * <p>
32: * Can be found in the menubar in the right topmost corner of Columba.
33: * <p>
34: * ImageSequenceTimer actually only listens for {@link TaskManagerEvent} and
35: * starts/stops as appropriate.
36: *
37: * @author fdietz
38: */
39: public class ThrobberIcon extends JPanel implements TaskManagerListener {
40:
41: private TaskManager taskManager;
42:
43: private AnimatedGIFComponent comp;
44:
45: public ThrobberIcon() {
46: super ();
47:
48: setLayout(new BorderLayout());
49:
50: comp = new AnimatedGIFComponent(ImageLoader.getMiscIcon(
51: "Throbber.gif").getImage(), ImageLoader.getMiscIcon(
52: "Throbber.png").getImage());
53: add(comp, BorderLayout.CENTER);
54:
55: // register interested on changes in the running worker list
56: taskManager = TaskManager.getInstance();
57: taskManager.addTaskManagerListener(this );
58: }
59:
60: /**
61: * Its an element of the toolbar, and therefor can't have the focus.
62: */
63: public boolean isFocusTraversable() {
64: return isRequestFocusEnabled();
65: }
66:
67: public void start() {
68: comp.go();
69: }
70:
71: public void stop() {
72: comp.stop();
73:
74: }
75:
76: public void workerAdded(TaskManagerEvent e) {
77: update();
78: }
79:
80: public void workerRemoved(TaskManagerEvent e) {
81: update();
82: }
83:
84: protected void update() {
85: // just the animation, if there are more than zero
86: // workers running
87: if (taskManager.count() > 0) {
88: start();
89: } else {
90: stop();
91: }
92: }
93: }
|