1 7 package org.netbeans.modules.j2ee.blueprints.ui.overview; 8 9 import java.awt.Cursor ; 10 import java.io.File ; 11 import java.io.IOException ; 12 import java.io.Serializable ; 13 import java.net.URL ; 14 import javax.swing.event.HyperlinkEvent ; 15 import javax.swing.event.HyperlinkListener ; 16 import javax.swing.text.html.HTMLEditorKit ; 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 26 30 public class OverviewPageTopComponent extends TopComponent implements HyperlinkListener { 31 32 private static final long serialVersionUID = 6051472310161712674L; 33 34 private static OverviewPageTopComponent instance; 35 36 38 private static final String PREFERRED_ID = "BluePrintsSolution"; 39 40 private String overviewFile; 41 42 private HtmlBrowser.URLDisplayer browser = HtmlBrowser.URLDisplayer.getDefault(); 43 44 private static boolean firstTime = true; 45 46 private String 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 55 jTabbedPane1.remove(optionalScrollPane); 56 } 57 58 63 private void initComponents() { 65 java.awt.GridBagConstraints gridBagConstraints; 66 67 jTabbedPane1 = new javax.swing.JTabbedPane (); 68 mainScrollPane = new javax.swing.JScrollPane (); 69 mainEditorPane = new javax.swing.JEditorPane (); 70 optionalScrollPane = new javax.swing.JScrollPane (); 71 optionalEditorPane = new javax.swing.JEditorPane (); 72 73 setLayout(new java.awt.BorderLayout ()); 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 } 87 88 private javax.swing.JTabbedPane jTabbedPane1; 90 private javax.swing.JEditorPane mainEditorPane; 91 private javax.swing.JScrollPane mainScrollPane; 92 private javax.swing.JEditorPane optionalEditorPane; 93 private javax.swing.JScrollPane optionalScrollPane; 94 96 101 public static synchronized OverviewPageTopComponent getDefault() { 102 if (instance == null) { 103 instance = new OverviewPageTopComponent(); 104 } 105 return instance; 106 } 107 108 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 ()); 130 mainEditorPane.setEditorKitForContentType("text/html", new HTMLEditorKit ()); mainEditorPane.setEditable(false); 132 mainEditorPane.addHyperlinkListener(this); 133 try { 134 URL demoDetailsURL = new URL ("nbresloc:" + this.overviewFile); 135 mainEditorPane.setPage(demoDetailsURL); 136 } catch (IOException ex) { 137 } 139 } 140 141 public void hyperlinkUpdate(HyperlinkEvent e) { 142 HyperlinkEvent.EventType type = e.getEventType(); 143 if (type == HyperlinkEvent.EventType.ACTIVATED) { 144 updatePageWithURL(e.getURL()); 145 } 146 } 147 148 protected void updatePageWithURL(URL u) { 149 if (u != null) { 150 String protocol = u.getProtocol(); 151 if (protocol != null && (protocol.equals("http") || protocol.equals("https"))) { 153 browser.showURL(u); 154 } else { 155 Cursor currentC = mainEditorPane.getCursor(); 156 Cursor busyC = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR); 157 try { 158 optionalEditorPane.setEditorKit(new HTMLEditorKit ()); 160 mainEditorPane.setEditorKitForContentType("text/html", new HTMLEditorKit ()); optionalEditorPane.setEditable(false); 162 optionalEditorPane.addHyperlinkListener(this); 163 optionalEditorPane.setPage(u); 164 firstTime = false; 165 optionalEditorPane.setPage(u); 167 String fileName = optionalTabName; 168 File f = new File (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 e) { 175 mainEditorPane.setCursor(currentC); 176 } finally { 177 mainEditorPane.setCursor(currentC); 178 } 179 } 180 } 181 } 182 183 public void componentClosed() { 184 } 186 187 188 public Object writeReplace() { 189 return new ResolvableHelper(); 190 } 191 192 protected String preferredID() { 193 return PREFERRED_ID; 194 } 195 196 public void setOverviewFile(String 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 { 203 private static final long serialVersionUID = 1L; 204 public Object readResolve() { 205 return OverviewPageTopComponent.getDefault(); 206 } 207 } 208 209 } 210 | Popular Tags |