1 33 34 package edu.rice.cs.drjava; 35 36 import java.io.*; 37 import java.net.URL ; 38 import java.net.URLClassLoader ; 39 import java.net.MalformedURLException ; 40 import java.util.Arrays ; 41 import java.util.StringTokenizer ; 42 import java.util.jar.JarFile ; 43 import javax.swing.UIManager ; 44 import javax.swing.*; 45 46 import edu.rice.cs.util.FileOpenSelector; 47 import edu.rice.cs.util.UnexpectedException; 48 import edu.rice.cs.util.OutputStreamRedirector; 49 import edu.rice.cs.util.newjvm.ExecJVM; 50 import edu.rice.cs.util.classloader.ToolsJarClassLoader; 51 import edu.rice.cs.util.swing.Utilities; 52 53 import edu.rice.cs.drjava.ui.MainFrame; 54 import edu.rice.cs.drjava.ui.SplashScreen; 55 import edu.rice.cs.drjava.ui.ClassPathFilter; 56 import edu.rice.cs.drjava.ui.DrJavaErrorWindow; 57 import edu.rice.cs.drjava.ui.DrJavaErrorHandler; 58 import edu.rice.cs.drjava.ui.SimpleInteractionsWindow; 59 import edu.rice.cs.drjava.model.*; 60 import edu.rice.cs.drjava.model.compiler.*; 61 import edu.rice.cs.drjava.platform.PlatformFactory; 62 import edu.rice.cs.drjava.config.FileConfiguration; 63 import edu.rice.cs.drjava.config.*; 64 65 import static edu.rice.cs.drjava.config.OptionConstants.*; 66 67 70 public class DrJavaRoot { 71 72 73 public static final int FULL_JAVA = 0; 74 public static final int ELEMENTARY_LEVEL = 1; 75 public static final int INTERMEDIATE_LEVEL = 2; 76 public static final int ADVANCED_LEVEL = 3; 77 public static final String [] LANGUAGE_LEVEL_EXTENSIONS = new String [] {"java", "dj0", "dj1", "dj2"}; 78 79 80 public static final String TEST_DEBUGGER_CLASS = "com.sun.jdi.Bootstrap"; 81 82 private static final PrintStream _consoleOut = System.out; 83 private static final PrintStream _consoleErr = System.err; 84 85 88 private static boolean _attemptingAugmentedClassPath = false; 89 private static SimpleInteractionsWindow _debugConsole = null; 90 91 94 95 public static void main(final String [] args) { 96 PlatformFactory.ONLY.beforeUISetup(); 98 99 if (!DrJava.handleCommandLineArgs(args)) { 102 System.exit(0); 103 } 104 105 String [] filesToOpen = DrJava.getFilesToOpen(); 106 final int numFiles = filesToOpen.length; 107 108 109 110 114 try { 117 String configLAFName = DrJava.getConfig().getSetting(LOOK_AND_FEEL); 118 String currLAFName = UIManager.getLookAndFeel().getClass().getName(); 119 if (! configLAFName.equals(currLAFName)) UIManager.setLookAndFeel(configLAFName); 120 121 124 126 final MainFrame mf = new MainFrame(); 127 128 130 DrJavaErrorWindow.setFrame(mf); 132 System.setProperty("sun.awt.exception.handler", "edu.rice.cs.drjava.ui.DrJavaErrorHandler"); 133 134 _openCommandLineFiles(mf, filesToOpen, numFiles); 135 136 141 SwingUtilities.invokeLater(new Runnable (){ public void run(){ mf.setVisible(true); } }); 142 143 System.setOut(new PrintStream(new OutputStreamRedirector() { 145 public void print(String s) { mf.getModel().systemOutPrint(s); } 146 })); 147 148 System.setErr(new PrintStream(new OutputStreamRedirector() { 150 public void print(String s) { mf.getModel().systemErrPrint(s); } 151 })); 152 153 if (DrJava.getShowDebugConsole()) showDrJavaDebugConsole(mf); 156 } 157 catch (Throwable t) { 158 _consoleErr.println(t.getClass().getName() + ": " + t.getMessage()); 160 t.printStackTrace(_consoleErr); 161 System.out.println("error thrown"); 162 new DrJavaErrorHandler().handle(t); 163 } 164 } 167 168 172 static void openCommandLineFiles(final MainFrame mf, final String [] filesToOpen) { 173 openCommandLineFiles(mf, filesToOpen, filesToOpen.length); 174 } 175 176 181 static void openCommandLineFiles(final MainFrame mf, final String [] filesToOpen, final int len) { 182 Utilities.invokeAndWait(new Runnable () { public void run() { _openCommandLineFiles(mf, filesToOpen, len); }}); 183 } 184 185 private static void _openCommandLineFiles(MainFrame mf, String [] filesToOpen, int len) { 186 for (int i = 0; i < len; i++) { 188 String currFileName = filesToOpen[i]; 189 boolean isProjectFile = currFileName.endsWith(".pjt"); 190 final File file = new File (currFileName).getAbsoluteFile(); 191 FileOpenSelector command = new FileOpenSelector() { 192 public File [] getFiles() { return new File [] {file}; } 193 }; 194 try { 195 if (isProjectFile) mf.openProject(command); 196 else mf.getModel().openFile(command); 197 } 198 199 catch (FileNotFoundException ex) { 200 } 202 catch (SecurityException se) { 203 } 205 catch (AlreadyOpenException aoe) { 206 } 208 catch (FileMovedException aoe) { 209 } 211 catch (IOException ex) { 212 } 214 catch (Exception ex) { throw new UnexpectedException(ex); } 215 } 216 } 217 218 222 public static void showDrJavaDebugConsole(MainFrame mf) { 223 if (_debugConsole == null) { 224 _debugConsole = new SimpleInteractionsWindow("DrJava Debug Console") { 225 protected void close() { 226 dispose(); 227 _debugConsole = null; 228 } 229 }; 230 _debugConsole.defineConstant("mainFrame", mf); 231 _debugConsole.defineConstant("model", mf.getModel()); 232 _debugConsole.defineConstant("config", DrJava.getConfig()); 233 _debugConsole.setInterpreterPrivateAccessible(true); 234 _debugConsole.setVisible(true); 235 } 236 else _debugConsole.toFront(); 237 } 238 239 242 public static PrintStream consoleErr() { return _consoleErr; } 243 244 247 public static PrintStream consoleOut() { return _consoleOut; } 248 249 } 250 251 | Popular Tags |