1 33 34 package edu.rice.cs.drjava.platform; 35 36 import edu.rice.cs.drjava.DrJava; 37 import edu.rice.cs.drjava.config.Configuration; 38 import edu.rice.cs.drjava.config.FileOption; 39 import edu.rice.cs.drjava.config.OptionConstants; 40 import edu.rice.cs.util.ArgumentTokenizer; 41 import edu.rice.cs.util.StringOps; 42 43 import javax.swing.*; 44 import java.io.File ; 45 import java.lang.reflect.Method ; 46 import java.net.URL ; 47 import java.util.List ; 48 49 53 class DefaultPlatform implements PlatformSupport { 54 55 public static DefaultPlatform ONLY = new DefaultPlatform(); 56 57 58 protected DefaultPlatform() { } 59 60 64 public boolean isUsingSystemLAF() { 65 String sysLAF = UIManager.getSystemLookAndFeelClassName(); 66 String curLAF = UIManager.getLookAndFeel().getClass().getName(); 67 return (sysLAF.equals(curLAF)); 68 } 69 70 73 public void beforeUISetup() { } 74 75 82 public void afterUISetup(Action about, Action prefs, Action quit) { } 83 84 85 public boolean isMacPlatform() { return false; } 86 87 88 public boolean isWindowsPlatform() { return false; } 89 90 91 public String getJavaSpecVersion() { 92 return System.getProperty("java.specification.version"); 93 } 94 95 96 public boolean has13ToolsJar() { 97 try { 99 Class <?> main = Class.forName("com.sun.tools.javadoc.Main"); 100 return !_javadocMainHasExecuteMethod(main); 101 } 102 catch (Throwable t) { return false; } 103 } 104 105 106 public boolean has14ToolsJar() { 107 try { 109 Class <?> main = Class.forName("com.sun.tools.javadoc.Main"); 110 return _javadocMainHasExecuteMethod(main); 111 } 112 catch (Throwable t) { return false; } 113 } 114 115 121 private boolean _javadocMainHasExecuteMethod(Class main) { 122 try { 123 @SuppressWarnings ("unchecked") Class <String []>[] arr = new Class []{String [].class}; 124 main.getMethod("execute", arr); 125 return true; 126 } 127 catch (Throwable t) { return false; } 128 } 129 130 139 public boolean openURL(URL address) { 140 Configuration config = DrJava.getConfig(); 142 File exe = config.getSetting(OptionConstants.BROWSER_FILE); 143 String command = config.getSetting(OptionConstants.BROWSER_STRING); 144 145 if ((exe == FileOption.NULL_FILE) && (command.equals(""))) { 147 return false; 149 } 150 else { 151 String addr = address.toString(); 152 if (command.equals("")) { 153 command = addr; 155 } 156 else { 157 String tag = "<URL>"; 159 if (command.indexOf(tag) != -1) { 160 command = StringOps.replace(command, tag, addr); 161 } 162 else { 163 command = command + " " + addr; 165 } 166 } 167 168 List <String > args = ArgumentTokenizer.tokenize(command); 170 171 if (exe != FileOption.NULL_FILE) args.add(0, exe.getAbsolutePath()); 173 174 try { 176 Runtime.getRuntime().exec(args.toArray(new String [args.size()])); 178 } 179 catch (Throwable t) { 180 return false; 182 } 183 } 184 185 return true; 187 } 188 } 189 | Popular Tags |