KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > extbrowser > SimpleExtBrowser


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.extbrowser;
21
22 import java.beans.*;
23 import java.util.HashMap JavaDoc;
24
25 import org.openide.awt.HtmlBrowser;
26 import org.openide.execution.NbProcessDescriptor;
27 import org.openide.util.NbBundle;
28
29 import org.openide.util.Utilities;
30
31 /** Simple external browser that uses new process for each URL request.
32  * Typically it runs command like <CODE>netscape [url]</CODE>.
33  *
34  * @author Radim Kubacki, Martin Grebac
35  */

36 public class SimpleExtBrowser extends ExtWebBrowser {
37
38     private static final long serialVersionUID = -8494345762328555637L;
39     
40     /** Determines whether the browser should be visible or not
41      * @return false when OS is Windows or Unix.
42      * true in all other cases.
43      */

44     public static Boolean JavaDoc isHidden () {
45         return Boolean.valueOf(Utilities.isWindows() || (Utilities.isUnix() && !Utilities.isMac()));
46     }
47     
48     /** Creates new SimpleExtBrowser */
49     public SimpleExtBrowser() {
50         super();
51         if (Utilities.getOperatingSystem () == Utilities.OS_OS2) {
52             browserExecutable = new NbProcessDescriptor(
53                 "Netscape.exe", // NOI18N
54
// {URL}
55
" {" + BrowserFormat.TAG_URL + "}", // NOI18N
56
NbBundle.getBundle(SimpleExtBrowser.class).getString("MSG_BrowserExecutorHint")
57             );
58         } else if (Utilities.isMac()) {
59             browserExecutable = new NbProcessDescriptor(
60                 "/usr/bin/open", // NOI18N
61
// {URL}
62
" {" + BrowserFormat.TAG_URL + "}", // NOI18N
63
NbBundle.getBundle(SimpleExtBrowser.class).getString("MSG_BrowserExecutorHint")
64             );
65         } else {
66             browserExecutable = new NbProcessDescriptor(
67                 // empty string for process
68
"", // NOI18N
69
// {URL}
70
" {" + BrowserFormat.TAG_URL + "}", // NOI18N
71
NbBundle.getBundle(SimpleExtBrowser.class).getString("MSG_BrowserExecutorHint")
72             );
73         }
74     }
75     
76     /** Getter for browser name
77      * @return name of browser
78      */

79     public String JavaDoc getName() {
80         if (name == null) {
81             this.name = NbBundle.getMessage(SimpleExtBrowser.class, "CTL_SimpleExtBrowser");
82         }
83         return name;
84     }
85             
86     /** Builds new implementation of specified browser.
87      * If embeddable property is true, then it is expected
88      * that returned implementation will implement org.openide.awt.HtmlBrowser.Impl
89      */

90     public HtmlBrowser.Impl createHtmlBrowserImpl() {
91         return new SimpleExtBrowserImpl(this);
92     }
93         
94     /** Default format that can format tags related to execution. Currently this is only the URL.
95      */

96     public static class BrowserFormat extends org.openide.util.MapFormat {
97         
98         private static final long serialVersionUID = 5990981835151848381L;
99         /** Tag replaced with the URL */
100         public static final String JavaDoc TAG_URL = "URL"; // NOI18N
101

102         
103         /** @param info exec info about class to execute
104          * @param classPath to substitute instead of CLASSPATH
105          * @param bootClassPath boot class path
106          * @param repository repository path
107          * @param library library path
108          */

109         public BrowserFormat (String JavaDoc url) {
110             super(new HashMap JavaDoc());
111             java.util.Map JavaDoc map = getMap ();
112             
113             map.put (TAG_URL, url);
114         }
115         
116     }
117 }
118
Popular Tags