KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > bluej > welcome > BluejWelcomeTopComponent


1 package org.netbeans.bluej.welcome;
2
3 import java.awt.Graphics JavaDoc;
4 import java.awt.Graphics2D JavaDoc;
5 import java.awt.Image JavaDoc;
6 import java.awt.LayoutManager JavaDoc;
7 import java.io.Serializable JavaDoc;
8 import javax.swing.JPanel JavaDoc;
9 import org.openide.ErrorManager;
10 import org.openide.util.NbBundle;
11 import org.openide.util.Utilities;
12 import org.openide.windows.TopComponent;
13 import org.openide.windows.WindowManager;
14
15 /**
16  * Top component which displays something.
17  */

18 final class BluejWelcomeTopComponent extends TopComponent {
19     
20     private static final long serialVersionUID = 1L;
21     
22     private static BluejWelcomeTopComponent instance;
23     /** path to the icon used by the component and its open action */
24     static final String JavaDoc ICON_PATH = "org/netbeans/bluej/welcome/frame.gif"; // NOI18N
25

26     private static final String JavaDoc PREFERRED_ID = "BluejWelcomeTopComponent"; // NOI18N
27
private JPanel JavaDoc panel;
28     private BluejWelcomeTopComponent() {
29         initComponents();
30         panel = new TitlePanel50();
31         add(panel);
32         setName(NbBundle.getMessage(BluejWelcomeTopComponent.class, "CTL_BluejWelcomeTopComponent")); // NOI18N
33
setToolTipText(NbBundle.getMessage(BluejWelcomeTopComponent.class, "HINT_BluejWelcomeTopComponent")); // NOI18N
34
setIcon(Utilities.loadImage(ICON_PATH, true));
35     }
36     
37     /** This method is called from within the constructor to
38      * initialize the form.
39      * WARNING: Do NOT modify this code. The content of this method is
40      * always regenerated by the Form Editor.
41      */

42     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
43
private void initComponents() {
44
45         setLayout(new java.awt.BorderLayout JavaDoc());
46
47     }// </editor-fold>//GEN-END:initComponents
48

49     
50     // Variables declaration - do not modify//GEN-BEGIN:variables
51
// End of variables declaration//GEN-END:variables
52

53     public void addNotify() {
54         super.addNotify();
55         
56     }
57     
58     /**
59      * Gets default instance. Do not use directly: reserved for *.settings files only,
60      * i.e. deserialization routines; otherwise you could get a non-deserialized instance.
61      * To obtain the singleton instance, use {@link findInstance}.
62      */

63     public static synchronized BluejWelcomeTopComponent getDefault() {
64         if (instance == null) {
65             instance = new BluejWelcomeTopComponent();
66         }
67         return instance;
68     }
69     
70     /**
71      * Obtain the BluejWelcomeTopComponent instance. Never call {@link #getDefault} directly!
72      */

73     public static synchronized BluejWelcomeTopComponent findInstance() {
74         TopComponent win = WindowManager.getDefault().findTopComponent(PREFERRED_ID);
75         if (win == null) {
76             ErrorManager.getDefault().log(ErrorManager.WARNING, "Cannot find BluejWelcome component. It will not be located properly in the window system."); // NOI18N
77
return getDefault();
78         }
79         if (win instanceof BluejWelcomeTopComponent) {
80             return (BluejWelcomeTopComponent)win;
81         }
82         ErrorManager.getDefault().log(ErrorManager.WARNING, "There seem to be multiple components with the '" + PREFERRED_ID + "' ID. That is a potential source of errors and unexpected behavior."); // NOI18N
83
return getDefault();
84     }
85     
86     public int getPersistenceType() {
87         return TopComponent.PERSISTENCE_ALWAYS;
88     }
89     
90     public void componentOpened() {
91         // TODO add custom code on component opening
92
}
93     
94     public void componentClosed() {
95         // TODO add custom code on component closing
96
}
97     
98     /** replaces this in object stream */
99     public Object JavaDoc writeReplace() {
100         return new ResolvableHelper();
101     }
102     
103     protected String JavaDoc preferredID() {
104         return PREFERRED_ID;
105     }
106     
107     final static class ResolvableHelper implements Serializable JavaDoc {
108         private static final long serialVersionUID = 1L;
109         public Object JavaDoc readResolve() {
110             return BluejWelcomeTopComponent.getDefault();
111         }
112     }
113     
114     
115 }
116
Popular Tags