KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > blueprints > ui > overview > OverviewPageTopComponent


1 /*
2  * OverviewPageTopComponent.java
3  *
4  * Created on June 14, 2006, 2:38 AM
5  *
6  */

7 package org.netbeans.modules.j2ee.blueprints.ui.overview;
8
9 import java.awt.Cursor JavaDoc;
10 import java.io.File JavaDoc;
11 import java.io.IOException JavaDoc;
12 import java.io.Serializable JavaDoc;
13 import java.net.URL JavaDoc;
14 import javax.swing.event.HyperlinkEvent JavaDoc;
15 import javax.swing.event.HyperlinkListener JavaDoc;
16 import javax.swing.text.html.HTMLEditorKit JavaDoc;
17 import org.openide.ErrorManager;
18 import org.openide.awt.HtmlBrowser;
19 import org.openide.util.NbBundle;
20 import org.openide.windows.TopComponent;
21 import org.openide.windows.WindowManager;
22
23 /**
24  * Top component which displays Blueprint project Information.
25  */

26 /**
27  *
28  * @author Nitya Doraisamy
29  */

30 public class OverviewPageTopComponent extends TopComponent implements HyperlinkListener JavaDoc {
31     
32     private static final long serialVersionUID = 6051472310161712674L;
33     
34     private static OverviewPageTopComponent instance;
35     /** path to the icon used by the component and its open action */
36     //static final String ICON_PATH = "SET/PATH/TO/ICON/HERE";
37

38     private static final String JavaDoc PREFERRED_ID = "BluePrintsSolution";
39     
40     private String JavaDoc overviewFile;
41     
42     private HtmlBrowser.URLDisplayer browser = HtmlBrowser.URLDisplayer.getDefault();
43     
44     private static boolean firstTime = true;
45     
46     private String JavaDoc optionalTabName = java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/blueprints/ui/overview/Bundle").
47             getString("SOLUTION_EXTRA_PAGE_TAB");
48     
49     private OverviewPageTopComponent() {
50         initComponents();
51         setName(NbBundle.getMessage(OverviewPageTopComponent.class, "CTL_OverviewPageTopComponent"));
52         setToolTipText(NbBundle.getMessage(OverviewPageTopComponent.class, "HINT_OverviewPageTopComponent"));
53         //setIcon(Utilities.loadImage(ICON_PATH, true));
54

55         jTabbedPane1.remove(optionalScrollPane);
56     }
57     
58     /** This method is called from within the constructor to
59      * initialize the form.
60      * WARNING: Do NOT modify this code. The content of this method is
61      * always regenerated by the Form Editor.
62      */

63     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
64
private void initComponents() {
65         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
66
67         jTabbedPane1 = new javax.swing.JTabbedPane JavaDoc();
68         mainScrollPane = new javax.swing.JScrollPane JavaDoc();
69         mainEditorPane = new javax.swing.JEditorPane JavaDoc();
70         optionalScrollPane = new javax.swing.JScrollPane JavaDoc();
71         optionalEditorPane = new javax.swing.JEditorPane JavaDoc();
72
73         setLayout(new java.awt.BorderLayout JavaDoc());
74
75         mainScrollPane.setViewportView(mainEditorPane);
76
77         jTabbedPane1.addTab(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/blueprints/ui/overview/Bundle").getString("SOLUTION_PAGE_TAB"), mainScrollPane);
78
79         optionalScrollPane.setViewportView(optionalEditorPane);
80
81         jTabbedPane1.addTab("tab2", optionalScrollPane);
82
83         add(jTabbedPane1, java.awt.BorderLayout.CENTER);
84
85     }// </editor-fold>//GEN-END:initComponents
86

87     
88     // Variables declaration - do not modify//GEN-BEGIN:variables
89
private javax.swing.JTabbedPane JavaDoc jTabbedPane1;
90     private javax.swing.JEditorPane JavaDoc mainEditorPane;
91     private javax.swing.JScrollPane JavaDoc mainScrollPane;
92     private javax.swing.JEditorPane JavaDoc optionalEditorPane;
93     private javax.swing.JScrollPane JavaDoc optionalScrollPane;
94     // End of variables declaration//GEN-END:variables
95

96     /**
97      * Gets default instance. Do not use directly: reserved for *.settings files only,
98      * i.e. deserialization routines; otherwise you could get a non-deserialized instance.
99      * To obtain the singleton instance, use {@link findInstance}.
100      */

101     public static synchronized OverviewPageTopComponent getDefault() {
102         if (instance == null) {
103             instance = new OverviewPageTopComponent();
104         }
105         return instance;
106     }
107     
108     /**
109      * Obtain the OverviewPageTopComponent instance. Never call {@link #getDefault} directly!
110      */

111     public static synchronized OverviewPageTopComponent findInstance() {
112         TopComponent win = WindowManager.getDefault().findTopComponent(PREFERRED_ID);
113         if (win == null) {
114             ErrorManager.getDefault().log(ErrorManager.WARNING, "Cannot find OverviewPage component. It will not be located properly in the window system.");
115             return getDefault();
116         }
117         if (win instanceof OverviewPageTopComponent) {
118             return (OverviewPageTopComponent)win;
119         }
120         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.");
121         return getDefault();
122     }
123     
124     public int getPersistenceType() {
125         return TopComponent.PERSISTENCE_NEVER;
126     }
127     
128     public void componentOpened() {
129         mainEditorPane.setEditorKit(new HTMLEditorKit JavaDoc());
130         mainEditorPane.setEditorKitForContentType("text/html", new HTMLEditorKit JavaDoc()); //NOI18N
131
mainEditorPane.setEditable(false);
132         mainEditorPane.addHyperlinkListener(this);
133         try {
134             URL JavaDoc demoDetailsURL = new URL JavaDoc("nbresloc:" + this.overviewFile);
135             mainEditorPane.setPage(demoDetailsURL);
136         } catch (IOException JavaDoc ex) {
137             //ex.printStackTrace();
138
}
139     }
140     
141     public void hyperlinkUpdate(HyperlinkEvent JavaDoc e) {
142         HyperlinkEvent.EventType JavaDoc type = e.getEventType();
143         if (type == HyperlinkEvent.EventType.ACTIVATED) {
144             updatePageWithURL(e.getURL());
145         }
146     }
147     
148     protected void updatePageWithURL(URL JavaDoc u) {
149         if (u != null) {
150             String JavaDoc protocol = u.getProtocol();
151             // Launch browser for these types of links
152
if (protocol != null && (protocol.equals("http") || protocol.equals("https"))) {
153                 browser.showURL(u);
154             } else {
155                 Cursor JavaDoc currentC = mainEditorPane.getCursor();
156                 Cursor JavaDoc busyC = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
157                 try {
158                    //if(firstTime){
159
optionalEditorPane.setEditorKit(new HTMLEditorKit JavaDoc());
160                         mainEditorPane.setEditorKitForContentType("text/html", new HTMLEditorKit JavaDoc()); //NOI18N
161
optionalEditorPane.setEditable(false);
162                         optionalEditorPane.addHyperlinkListener(this);
163                         optionalEditorPane.setPage(u);
164                         firstTime = false;
165                     //}
166
optionalEditorPane.setPage(u);
167                     String JavaDoc fileName = optionalTabName;
168                     File JavaDoc f = new File JavaDoc(u.getFile());
169                     if(f != null)
170                         fileName = f.getName();
171                     jTabbedPane1.addTab(fileName, optionalScrollPane);
172                     jTabbedPane1.setSelectedComponent(optionalScrollPane);
173                     optionalEditorPane.setCursor(busyC);
174                 } catch (IOException JavaDoc e) {
175                      mainEditorPane.setCursor(currentC);
176                 } finally {
177                      mainEditorPane.setCursor(currentC);
178                 }
179             }
180         }
181     }
182     
183     public void componentClosed() {
184         // TODO add custom code on component closing
185
}
186     
187     /** replaces this in object stream */
188     public Object JavaDoc writeReplace() {
189         return new ResolvableHelper();
190     }
191     
192     protected String JavaDoc preferredID() {
193         return PREFERRED_ID;
194     }
195     
196     public void setOverviewFile(String JavaDoc overviewFile){
197         this.overviewFile = overviewFile;
198         jTabbedPane1.removeAll();
199         jTabbedPane1.addTab(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/blueprints/ui/overview/Bundle").getString("SOLUTION_PAGE_TAB"), mainScrollPane);
200     }
201         
202     final static class ResolvableHelper implements Serializable JavaDoc {
203         private static final long serialVersionUID = 1L;
204         public Object JavaDoc readResolve() {
205             return OverviewPageTopComponent.getDefault();
206         }
207     }
208     
209 }
210
Popular Tags