KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > logger > Main


1 /*
2  * Main.java
3  *
4  * Created on April 7, 2005, 11:09 AM
5  */

6
7 package org.netbeans.modules.logger;
8
9 import org.netbeans.modules.logger.listeners.ListenerTools;
10 import org.netbeans.modules.logger.listeners.TCRPropertyListener;
11 import org.netbeans.modules.logger.listeners.WMPropertyListener;
12 import org.openide.modules.ModuleInstall;
13 import org.openide.windows.TopComponent;
14 import org.openide.windows.WindowManager;
15
16
17
18
19 /**
20  * Methods from this class are called when the IDE is installing / restoring /
21  * closing modules.
22  * @author loicsegapelli
23  */

24 public class Main extends ModuleInstall{
25     
26     TCRPropertyListener tcr;
27     WMPropertyListener wm;
28     /**
29      * makes the module wait until the user has entered a username and level.
30      */

31     public Waiter waiter;
32     
33     static String JavaDoc name;
34     static String JavaDoc level;
35    
36     /**
37      * called when the module is restored. Sets up listeners.
38      */

39     public void restored(){
40         
41         try{
42             // has the user already given his name + level?
43
if(!ListenerTools.findOutProperties()){
44                 new UserInput(this).setVisible(true);
45                 waiter = new Waiter();
46                 new Thread JavaDoc(waiter).start();
47                 waiter.makeMeWait();
48             }
49         }catch(Exception JavaDoc e){
50             ListenerTools.logError(e);
51         }catch(Error JavaDoc e){
52             ListenerTools.logError(e);
53         }
54         
55         // now we are attaching all our listeners to NB classes
56

57         // TopComponent.Registry listener
58
try{
59             tcr = new TCRPropertyListener();
60             TopComponent.Registry r=WindowManager.getDefault().getRegistry();
61             r.addPropertyChangeListener(tcr);
62         }catch(Exception JavaDoc e){
63             ListenerTools.logError(e);
64         }catch(Error JavaDoc e){
65             ListenerTools.logError(e);
66         }
67         
68         // WindowManager listener
69
try{
70             wm = new WMPropertyListener();
71             WindowManager.getDefault().addPropertyChangeListener(wm);
72         }catch(Exception JavaDoc e){
73             ListenerTools.logError(e);
74         }catch(Error JavaDoc e){
75             ListenerTools.logError(e);
76         }
77         
78         // zip the log files that have not been zipped during a previous
79
// session. This happens if NB crashed. It is important not to zip the
80
// current .log files, hence "zipUIExceptCurrent"
81
try{
82             new Zipper().zipUIExceptCurrent();
83         }catch(Exception JavaDoc e){
84             ListenerTools.logError(e);
85         }catch(Error JavaDoc e){
86             ListenerTools.logError(e);
87         }
88     }
89     
90     /**
91      * called when the module is closing
92      * @return <CODE>true</CODE> is everything is closed fine. Actually, always
93      * returns <CODE>true</CODE>
94      */

95     public boolean closing(){
96         try{
97             new Zipper().zipUI();
98         }catch(Exception JavaDoc e){
99             ListenerTools.logError(e);
100         }catch(Error JavaDoc e){
101             ListenerTools.logError(e);
102         }
103         return true;
104     }
105     
106     
107     /**
108      * this method is deprecated, but how to do it some other way?
109      */

110     public void installed() {
111         this.restored();
112     }
113     
114     /**
115      * stops the waiting loop inside <CODE>waiter</CODE>
116      */

117     public void wakeUp(){
118         waiter.wakeUp();
119     }
120     
121     
122 }
123
Popular Tags