|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| package edu.rice.cs.drjava; |
|
38 |
| |
|
39 |
| import java.awt.EventQueue; |
|
40 |
| import java.awt.Window; |
|
41 |
| import java.awt.dnd.*; |
|
42 |
| import java.awt.event.WindowEvent; |
|
43 |
| import java.io.*; |
|
44 |
| import java.lang.reflect.InvocationTargetException; |
|
45 |
| |
|
46 |
| import javax.swing.UIManager; |
|
47 |
| import javax.swing.*; |
|
48 |
| |
|
49 |
| import edu.rice.cs.plt.lambda.Runnable1; |
|
50 |
| import edu.rice.cs.util.FileOpenSelector; |
|
51 |
| import edu.rice.cs.util.UnexpectedException; |
|
52 |
| import edu.rice.cs.util.OutputStreamRedirector; |
|
53 |
| import edu.rice.cs.util.swing.Utilities; |
|
54 |
| |
|
55 |
| import edu.rice.cs.drjava.ui.MainFrame; |
|
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.ui.SplashScreen; |
|
60 |
| import edu.rice.cs.drjava.model.*; |
|
61 |
| import edu.rice.cs.drjava.platform.PlatformFactory; |
|
62 |
| import edu.rice.cs.drjava.config.*; |
|
63 |
| |
|
64 |
| import com.jgoodies.looks.plastic.PlasticLookAndFeel; |
|
65 |
| import com.jgoodies.looks.plastic.PlasticTheme; |
|
66 |
| |
|
67 |
| import static edu.rice.cs.drjava.config.OptionConstants.*; |
|
68 |
| import static edu.rice.cs.plt.debug.DebugUtil.error; |
|
69 |
| import static edu.rice.cs.plt.debug.DebugUtil.debug; |
|
70 |
| |
|
71 |
| |
|
72 |
| |
|
73 |
| |
|
74 |
| public class DrJavaRoot { |
|
75 |
| |
|
76 |
| public static final String TEST_DEBUGGER_CLASS = "com.sun.jdi.Bootstrap"; |
|
77 |
| |
|
78 |
| public static final String PLASTIC_THEMES_PACKAGE = "com.jgoodies.looks.plastic.theme"; |
|
79 |
| |
|
80 |
| private static final PrintStream _consoleOut = System.out; |
|
81 |
| private static final PrintStream _consoleErr = System.err; |
|
82 |
| |
|
83 |
| |
|
84 |
| |
|
85 |
| private static SimpleInteractionsWindow _debugConsole = null; |
|
86 |
| |
|
87 |
| private static boolean anyLineNumbersSpecified = false; |
|
88 |
| |
|
89 |
| |
|
90 |
| private static MainFrame _mainFrame = null; |
|
91 |
| |
|
92 |
| |
|
93 |
| |
|
94 |
| |
|
95 |
| |
|
96 |
0
| public static void main(final String[] args) {
|
|
97 |
0
| debug.log("Starting up");
|
|
98 |
| |
|
99 |
0
| PlatformFactory.ONLY.beforeUISetup();
|
|
100 |
| |
|
101 |
| |
|
102 |
| |
|
103 |
0
| if (!DrJava.handleCommandLineArgs(args)) {
|
|
104 |
0
| System.exit(0);
|
|
105 |
| } |
|
106 |
| |
|
107 |
0
| DrJava.warnIfLinuxWithCompiz();
|
|
108 |
0
| new SplashScreen().flash();
|
|
109 |
| |
|
110 |
0
| final String[] filesToOpen = DrJava.getFilesToOpen();
|
|
111 |
0
| final int numFiles = filesToOpen.length;
|
|
112 |
| |
|
113 |
| |
|
114 |
| |
|
115 |
| |
|
116 |
| |
|
117 |
| |
|
118 |
| |
|
119 |
| |
|
120 |
| |
|
121 |
0
| try {
|
|
122 |
0
| String configLAFName = DrJava.getConfig().getSetting(LOOK_AND_FEEL);
|
|
123 |
0
| String currLAFName = UIManager.getLookAndFeel().getClass().getName();
|
|
124 |
0
| String failureMessage =
|
|
125 |
| "DrJava could not load the configured theme for the Plastic Look and Feel.\n" + |
|
126 |
| "If you've manually edited your configuration file, try \n" + |
|
127 |
| "removing the key \"plastic.theme\" and restarting DrJava.\n" + |
|
128 |
| "In the meantime, the system default Look and Feel will be used.\n"; |
|
129 |
0
| String failureTitle = "Theme not found";
|
|
130 |
0
| if(Utilities.isPlasticLaf(configLAFName)) {
|
|
131 |
0
| String themeName = PLASTIC_THEMES_PACKAGE + "." + DrJava.getConfig().getSetting(PLASTIC_THEMES);
|
|
132 |
0
| try {
|
|
133 |
0
| PlasticTheme theme = (PlasticTheme) Class.forName(themeName).getConstructor(new Class<?>[]{ }).newInstance();
|
|
134 |
0
| PlasticLookAndFeel.setPlasticTheme(theme);
|
|
135 |
0
| PlasticLookAndFeel.setTabStyle(PlasticLookAndFeel.TAB_STYLE_METAL_VALUE);
|
|
136 |
0
| com.jgoodies.looks.Options.setPopupDropShadowEnabled(true);
|
|
137 |
0
| if(! configLAFName.equals(currLAFName)) UIManager.setLookAndFeel(configLAFName);
|
|
138 |
| } catch(NoSuchMethodException nsmex) { |
|
139 |
0
| JOptionPane.showMessageDialog(null, failureMessage, failureTitle, JOptionPane.ERROR_MESSAGE);
|
|
140 |
| } catch(SecurityException sex) { |
|
141 |
0
| JOptionPane.showMessageDialog(null, failureMessage, failureTitle, JOptionPane.ERROR_MESSAGE);
|
|
142 |
| } catch(InstantiationException iex) { |
|
143 |
0
| JOptionPane.showMessageDialog(null, failureMessage, failureTitle, JOptionPane.ERROR_MESSAGE);
|
|
144 |
| } catch(IllegalAccessException iaex) { |
|
145 |
0
| JOptionPane.showMessageDialog(null, failureMessage, failureTitle, JOptionPane.ERROR_MESSAGE);
|
|
146 |
| } catch(IllegalArgumentException iaex) { |
|
147 |
0
| JOptionPane.showMessageDialog(null, failureMessage, failureTitle, JOptionPane.ERROR_MESSAGE);
|
|
148 |
| } catch(InvocationTargetException itex) { |
|
149 |
0
| JOptionPane.showMessageDialog(null, failureMessage, failureTitle, JOptionPane.ERROR_MESSAGE);
|
|
150 |
| } |
|
151 |
0
| } else if (! configLAFName.equals(currLAFName)) {
|
|
152 |
0
| UIManager.setLookAndFeel(configLAFName);
|
|
153 |
| } |
|
154 |
| |
|
155 |
| |
|
156 |
| |
|
157 |
| |
|
158 |
| |
|
159 |
0
| _mainFrame = new MainFrame();
|
|
160 |
| |
|
161 |
| |
|
162 |
| |
|
163 |
0
| DrJavaErrorWindow.setFrame(_mainFrame);
|
|
164 |
0
| Thread.setDefaultUncaughtExceptionHandler(DrJavaErrorHandler.INSTANCE);
|
|
165 |
| |
|
166 |
| |
|
167 |
| |
|
168 |
| |
|
169 |
| |
|
170 |
0
| EventQueue.invokeLater(new Runnable(){
|
|
171 |
0
| public void run(){
|
|
172 |
0
| _mainFrame.start();
|
|
173 |
| |
|
174 |
| |
|
175 |
| |
|
176 |
| |
|
177 |
0
| _openCommandLineFiles(_mainFrame, filesToOpen, numFiles, true);
|
|
178 |
| } |
|
179 |
| }); |
|
180 |
| |
|
181 |
| |
|
182 |
0
| System.setOut(new PrintStream(new OutputStreamRedirector() {
|
|
183 |
0
| public void print(String s) { _mainFrame.getModel().systemOutPrint(s); }
|
|
184 |
| })); |
|
185 |
| |
|
186 |
| |
|
187 |
0
| System.setErr(new PrintStream(new OutputStreamRedirector() {
|
|
188 |
0
| public void print(String s) { _mainFrame.getModel().systemErrPrint(s); }
|
|
189 |
| })); |
|
190 |
| |
|
191 |
| |
|
192 |
| |
|
193 |
0
| if (DrJava.getShowDebugConsole()) showDrJavaDebugConsole(_mainFrame);
|
|
194 |
| } |
|
195 |
| catch(Throwable t) { |
|
196 |
0
| error.log(t);
|
|
197 |
| |
|
198 |
0
| _consoleErr.println(t.getClass().getName() + ": " + t.getMessage());
|
|
199 |
0
| t.printStackTrace(_consoleErr);
|
|
200 |
0
| System.out.println("error thrown");
|
|
201 |
0
| DrJavaErrorHandler.record(t);
|
|
202 |
| } |
|
203 |
| } |
|
204 |
| |
|
205 |
| |
|
206 |
| |
|
207 |
| |
|
208 |
| |
|
209 |
10
| static void openCommandLineFiles(final MainFrame mf, final String[] filesToOpen, boolean jump) {
|
|
210 |
10
| openCommandLineFiles(mf, filesToOpen, filesToOpen.length, jump);
|
|
211 |
| } |
|
212 |
| |
|
213 |
| |
|
214 |
| |
|
215 |
| |
|
216 |
| |
|
217 |
| |
|
218 |
10
| static void openCommandLineFiles(final MainFrame mf, final String[] filesToOpen, final int len, final boolean jump) {
|
|
219 |
10
| Utilities.invokeAndWait(new Runnable() { public void run() { _openCommandLineFiles(mf, filesToOpen, len, jump); }});
|
|
220 |
| } |
|
221 |
| |
|
222 |
10
| private static void _openCommandLineFiles(final MainFrame mf, String[] filesToOpen, int len, boolean jump) {
|
|
223 |
| |
|
224 |
| |
|
225 |
| |
|
226 |
10
| anyLineNumbersSpecified = false;
|
|
227 |
10
| for (int i = 0; i < len; i++) {
|
|
228 |
21
| String currFileName = filesToOpen[i];
|
|
229 |
| |
|
230 |
| |
|
231 |
| |
|
232 |
| |
|
233 |
21
| int lineNo = -1;
|
|
234 |
21
| int pathSepIndex = currFileName.indexOf(File.pathSeparatorChar);
|
|
235 |
21
| if (pathSepIndex >= 0) {
|
|
236 |
0
| try {
|
|
237 |
0
| lineNo = Integer.valueOf(currFileName.substring(pathSepIndex+1));
|
|
238 |
0
| anyLineNumbersSpecified = true;
|
|
239 |
| } |
|
240 |
0
| catch(NumberFormatException nfe) { lineNo = -1; }
|
|
241 |
0
| currFileName = currFileName.substring(0,pathSepIndex);
|
|
242 |
| } |
|
243 |
| |
|
244 |
21
| boolean isProjectFile =
|
|
245 |
| currFileName.endsWith(OptionConstants.PROJECT_FILE_EXTENSION) || |
|
246 |
| currFileName.endsWith(OptionConstants.PROJECT_FILE_EXTENSION2) || |
|
247 |
| currFileName.endsWith(OptionConstants.OLD_PROJECT_FILE_EXTENSION); |
|
248 |
21
| final File file = new File(currFileName).getAbsoluteFile();
|
|
249 |
21
| FileOpenSelector command = new FileOpenSelector() {
|
|
250 |
21
| public File[] getFiles() { return new File[] {file}; }
|
|
251 |
| }; |
|
252 |
21
| try {
|
|
253 |
0
| if (isProjectFile) mf.openProject(command);
|
|
254 |
0
| else if (currFileName.endsWith(OptionConstants.EXTPROCESS_FILE_EXTENSION)) MainFrame.openExtProcessFile(file);
|
|
255 |
| else { |
|
256 |
21
| if (jump && (lineNo >= 0)) {
|
|
257 |
| |
|
258 |
| |
|
259 |
0
| mf.open(command);
|
|
260 |
0
| mf._jumpToLine(lineNo);
|
|
261 |
| } |
|
262 |
| else { |
|
263 |
| |
|
264 |
21
| mf.getModel().openFile(command);
|
|
265 |
| } |
|
266 |
| } |
|
267 |
| } |
|
268 |
| |
|
269 |
| catch (FileNotFoundException ex) { |
|
270 |
| |
|
271 |
| } |
|
272 |
| catch (SecurityException se) { |
|
273 |
| |
|
274 |
| } |
|
275 |
| catch (AlreadyOpenException aoe) { |
|
276 |
| |
|
277 |
| } |
|
278 |
| catch (FileMovedException aoe) { |
|
279 |
| |
|
280 |
| } |
|
281 |
| catch (IOException ex) { |
|
282 |
| |
|
283 |
| } |
|
284 |
0
| catch (Exception ex) { throw new UnexpectedException(ex); }
|
|
285 |
| } |
|
286 |
| } |
|
287 |
| |
|
288 |
| |
|
289 |
| |
|
290 |
| |
|
291 |
| |
|
292 |
0
| public static void showDrJavaDebugConsole(MainFrame mf) {
|
|
293 |
0
| if (_debugConsole == null) {
|
|
294 |
0
| _debugConsole = new SimpleInteractionsWindow("DrJava Debug Console") {
|
|
295 |
0
| protected void close() {
|
|
296 |
0
| dispose();
|
|
297 |
0
| _debugConsole = null;
|
|
298 |
| } |
|
299 |
| }; |
|
300 |
| |
|
301 |
| |
|
302 |
| |
|
303 |
| |
|
304 |
0
| _debugConsole.setVisible(true);
|
|
305 |
| } |
|
306 |
0
| else _debugConsole.toFront();
|
|
307 |
| } |
|
308 |
| |
|
309 |
| |
|
310 |
| |
|
311 |
| |
|
312 |
0
| public static PrintStream consoleErr() { return _consoleErr; }
|
|
313 |
| |
|
314 |
| |
|
315 |
| |
|
316 |
| |
|
317 |
0
| public static PrintStream consoleOut() { return _consoleOut; }
|
|
318 |
| |
|
319 |
| |
|
320 |
0
| public static void dragEnter(DropTargetDragEvent dropTargetDragEvent) {
|
|
321 |
0
| _mainFrame.dragEnter(dropTargetDragEvent);
|
|
322 |
| } |
|
323 |
| |
|
324 |
| |
|
325 |
0
| public static void drop(DropTargetDropEvent dropTargetDropEvent) {
|
|
326 |
0
| _mainFrame.drop(dropTargetDropEvent);
|
|
327 |
| } |
|
328 |
| |
|
329 |
| |
|
330 |
| |
|
331 |
| |
|
332 |
| |
|
333 |
| |
|
334 |
0
| public static void installModalWindowAdapter(final Window w,
|
|
335 |
| final Runnable1<? super WindowEvent> toFrontAction, |
|
336 |
| final Runnable1<? super WindowEvent> closeAction) { |
|
337 |
0
| _mainFrame.installModalWindowAdapter(w, toFrontAction, closeAction);
|
|
338 |
| } |
|
339 |
| |
|
340 |
| |
|
341 |
| |
|
342 |
0
| public static void removeModalWindowAdapter(Window w) {
|
|
343 |
0
| _mainFrame.removeModalWindowAdapter(w);
|
|
344 |
| } |
|
345 |
| |
|
346 |
| |
|
347 |
| |
|
348 |
| |
|
349 |
0
| public static void handleRemoteOpenFile(File f, int lineNo) {
|
|
350 |
0
| DrJava._log.log("DrJavaRoot.handleRemoteOpenFile, f=" + f);
|
|
351 |
0
| if (_mainFrame != null) {
|
|
352 |
0
| DrJava._log.log("\tcalling _mainFrame");
|
|
353 |
0
| _mainFrame.handleRemoteOpenFile(f, lineNo);
|
|
354 |
| } |
|
355 |
| else { |
|
356 |
0
| DrJava._log.log("\tadded to _filesToOpen");
|
|
357 |
0
| DrJava.addFileToOpen(f.getAbsolutePath());
|
|
358 |
| } |
|
359 |
| } |
|
360 |
| } |
|
361 |
| |