1 /*------------------------------------------------------------------------------
2 Name: MonitoringAppl.java
3 Project: xmlBlaster.org
4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
5 ------------------------------------------------------------------------------*/
6
7 package javaclients.graphical;
8
9 import java.io.File;
10 import java.util.HashMap;
11
12 import javax.swing.JFileChooser;
13
14 import CH.ifa.draw.framework.DrawingView;
15 import CH.ifa.draw.samples.javadraw.JavaDrawApp;
16
17 import java.util.logging.Logger;
18 import java.util.logging.Level;
19 import org.xmlBlaster.util.Global;
20
21 /**
22 * @author <a href="mailto:michele@laghi.eu">Michele Laghi</a>
23 */
24 public class MonitoringAppl extends JavaDrawApp {
25
26 private Global global;
27 private static Logger log = Logger.getLogger(MonitoringAppl.class.getName());
28 private String ME = "MonitoringAppl";
29 private HashMap subscribers;
30 private int count;
31 private JFileChooser chooser;
32
33
34 public MonitoringAppl(Global global) {
35 super("MonitoringAppl");
36 this.global = global;
37
38 this.subscribers = new HashMap();
39 this.count = 1;
40 }
41
42
43 public void fireViewDestroyingEvent(DrawingView view) {
44 if (log.isLoggable(Level.FINER)) this.log.finer("fireViewDestroyingEvent(view)");
45 MonitorSubscriber subscriber = (MonitorSubscriber)this.subscribers.remove(view);
46 if (subscriber != null) subscriber.stop();
47 super.fireViewDestroyingEvent(view);
48 }
49
50 public JFileChooser createOpenFileChooser() {
51 if (log.isLoggable(Level.FINER)) this.log.finer("createOpenFileChooser");
52 if (this.chooser == null) {
53 this.chooser = super.createOpenFileChooser();
54 this.chooser.setCurrentDirectory(new File("."));
55 }
56 return this.chooser;
57 }
58
59 public void fireViewCreatedEvent(DrawingView view) {
60 super.fireViewCreatedEvent(view);
61 MonitorSubscriber subscriber = new MonitorSubscriber(this.global, view);
62 String name = "drawing" + this.count++;
63 if (subscriber.start(name))
64 this.subscribers.put(view, subscriber);
65 }
66
67
68 public void exit() {
69 if (log.isLoggable(Level.FINER)) this.log.finer("exit");
70 if (this.subscribers.size() > 0) {
71 try {
72 MonitorSubscriber[] subs = (MonitorSubscriber[])this.subscribers.values().toArray(new MonitorSubscriber[this.subscribers.size()]);
73 for (int i=0; i < subs.length; i++) subs[i].stop();
74 }
75 catch (Throwable ex) {
76 ex.printStackTrace();
77 }
78 }
79 this.subscribers.clear();
80 super.exit();
81 }
82
83 //-- main -----------------------------------------------------------
84
85 public static void main(String[] args) {
86
87 Global glob = new Global();
88 if (glob.init(args) != 0) { // Get help with -help
89 System.out.println(glob.usage());
90 System.err.println("Example: java javaclients.graphical.MonitoringAppl -chatMaster true\n");
91 System.exit(1);
92 }
93
94 MonitoringAppl window = new MonitoringAppl(glob);
95 window.open();
96 }
97
98 }
syntax highlighted by Code2HTML, v. 0.9.1