01: /*
02: * RunningJobIndicator.java
03: *
04: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
05: *
06: * Copyright 2002-2008, Thomas Kellerer
07: * No part of this code maybe reused without the permission of the author
08: *
09: * To contact the author please send an email to: support@sql-workbench.net
10: *
11: */
12: package workbench.gui.components;
13:
14: import javax.swing.JFrame;
15:
16: /**
17: * @author support@sql-workbench.net
18: */
19: public class RunningJobIndicator {
20: private JFrame clientWindow;
21: private int runningJobs = 0;
22: public static final String TITLE_PREFIX = "\u00bb ";
23:
24: public RunningJobIndicator(JFrame client) {
25: this .clientWindow = client;
26: }
27:
28: public synchronized void baseTitleChanged() {
29: updateTitle();
30: }
31:
32: private synchronized void updateTitle() {
33: String title = this .clientWindow.getTitle();
34: if (runningJobs > 0) {
35: if (!title.startsWith(TITLE_PREFIX)) {
36: clientWindow.setTitle(TITLE_PREFIX + title);
37: }
38: } else {
39: if (title.startsWith(TITLE_PREFIX)) {
40: clientWindow.setTitle(title.substring(TITLE_PREFIX
41: .length()));
42: }
43: }
44: }
45:
46: public synchronized void jobStarted() {
47: runningJobs++;
48: updateTitle();
49: }
50:
51: public synchronized void jobEnded() {
52: if (runningJobs > 0)
53: runningJobs--;
54: updateTitle();
55: }
56:
57: }
|