1 2 23 package org.enhydra.tool.common; 24 25 import org.enhydra.tool.ToolBoxInfo; 27 28 import java.awt.Component ; 30 import java.io.File ; 31 import java.util.ResourceBundle ; 32 import java.util.Properties ; 33 public class Browser { 34 static ResourceBundle res = 35 ResourceBundle.getBundle("org.enhydra.tool.common.Res"); private final String MSIE = "IEXPLORE.EXE"; private final String NETSCAPE = "netscape"; private Component owner = null; 39 40 public void open(String target) { 41 StringBuffer buf = new StringBuffer (); 42 String browser = getBrowser(); 43 File file = null; 44 45 if (browser == null) { 46 47 } else { 49 file = new File (browser); 50 } 51 if ((file == null) || (!file.isFile())) { 52 System.err.println("Help browser not found."); 53 } else { 54 buf.append(file.getAbsolutePath()); 55 buf.append(' '); 56 buf.append(target); 57 try { 58 Runtime.getRuntime().exec(buf.toString()); 59 } catch (java.io.IOException e) { 60 e.printStackTrace(System.err); 61 } 62 } 63 } 64 65 public void setOwner(Component o) { 66 owner = o; 67 } 68 69 public Component getOwner() { 70 return owner; 71 } 72 73 public String getBrowser() { 74 PathHandle path = null; 75 Properties props = null; 76 77 if (File.pathSeparatorChar == '\\') { 78 path = PathHandle.createPathHandle(MSIE); 79 } else { 80 path = PathHandle.createPathHandle(NETSCAPE); 81 } 82 try { 83 props = ToolBoxInfo.loadProperties(); 84 path = PathHandle.createPathHandle(props.getProperty("browser")); 85 } catch (ToolException e) { 86 e.printStackTrace(System.err); 87 } 88 if (!path.isFile()) { 89 path = selectBrowser(); 90 if (path.isFile()) { 91 setBrowser(path.getPath()); 92 } 93 } 94 return path.getPath(); 95 } 96 97 public void setBrowser(String browser) { 98 Properties props = null; 99 100 try { 101 props = ToolBoxInfo.loadProperties(); 102 props.setProperty("browser", browser); 103 ToolBoxInfo.storeProperties(props); 104 } catch (ToolException e) { 105 e.printStackTrace(System.err); 106 } 107 } 108 109 private PathHandle selectBrowser() { 110 PathHandle path = null; 111 File choice = null; 112 ExtensionFilter filter = null; 113 114 filter = new ExtensionFilter(); 115 filter.setDescriptionTitle(res.getString("Browser")); 116 if (File.separatorChar == '\\') { 117 filter.addExtension("exe"); path = PathHandle.createPathHandle(MSIE); 119 } else { 120 path = PathHandle.createPathHandle(NETSCAPE); 121 } 122 choice = SwingUtil.getFileChoice(getOwner(), path.getPath(), filter, 123 res.getString("Select_browser")); 124 path = PathHandle.createPathHandle(choice); 125 return path; 126 } 127 128 } 129 | Popular Tags |