KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > jclasslib > browser > BrowserMDIFrame


1 /*
2     This library is free software; you can redistribute it and/or
3     modify it under the terms of the GNU General Public
4     License as published by the Free Software Foundation; either
5     version 2 of the license, or (at your option) any later version.
6 */

7
8 package org.gjt.jclasslib.browser;
9
10 import org.gjt.jclasslib.browser.config.BrowserConfig;
11 import org.gjt.jclasslib.browser.config.classpath.*;
12 import org.gjt.jclasslib.browser.config.window.WindowState;
13 import org.gjt.jclasslib.mdi.*;
14 import org.gjt.jclasslib.structures.ClassFile;
15 import org.gjt.jclasslib.structures.InvalidByteCodeException;
16 import org.gjt.jclasslib.util.GUIHelper;
17
18 import javax.swing.*;
19 import java.awt.*;
20 import java.awt.event.ActionEvent JavaDoc;
21 import java.awt.event.KeyEvent JavaDoc;
22 import java.beans.*;
23 import java.io.*;
24 import java.net.URL JavaDoc;
25 import java.util.prefs.Preferences JavaDoc;
26
27
28 /**
29  * MDI Frame and entry point for the class file browser application.
30  *
31  * @author <a HREF="mailto:jclasslib@ej-technologies.com">Ingo Kegel</a>
32  * @version $Revision: 1.10 $ $Date: 2005/01/14 15:01:03 $
33  */

34 public class BrowserMDIFrame extends BasicMDIFrame {
35
36     static final ImageIcon ICON_APPLICATION = loadIcon("jclasslib.gif");
37
38     private static final String JavaDoc SETTINGS_WORKSPACE_CHOOSER_PATH = "workspaceChooserPath";
39     private static final String JavaDoc SETTINGS_CLASSES_CHOOSER_PATH = "classesChooserPath";
40
41     private static final ImageIcon ICON_OPEN_CLASS_FILE = loadIcon("open_small.png");
42     private static final ImageIcon ICON_OPEN_CLASS_FILE_LARGE = loadIcon("open_large.png");
43     private static final ImageIcon ICON_OPEN_WORKSPACE = loadIcon("open_ws_small.png");
44     private static final ImageIcon ICON_OPEN_WORKSPACE_LARGE = loadIcon("open_ws_large.png");
45     private static final ImageIcon ICON_SAVE_WORKSPACE = loadIcon("save_ws_small.png");
46     private static final ImageIcon ICON_SAVE_WORKSPACE_LARGE = loadIcon("save_ws_large.png");
47     private static final ImageIcon ICON_BACKWARD = loadIcon("browser_backward_small.png");
48     private static final ImageIcon ICON_BACKWARD_LARGE = loadIcon("browser_backward_large.png");
49     private static final ImageIcon ICON_FORWARD = loadIcon("browser_forward_small.png");
50     private static final ImageIcon ICON_FORWARD_LARGE = loadIcon("browser_forward_large.png");
51     private static final ImageIcon ICON_RELOAD = loadIcon("reload_small.png");
52     private static final ImageIcon ICON_RELOAD_LARGE = loadIcon("reload_large.png");
53     private static final ImageIcon ICON_WEB = loadIcon("web_small.png");
54     private static final ImageIcon ICON_WEB_LARGE = loadIcon("web_large.png");
55     private static final ImageIcon ICON_BROWSE_CLASSPATH = loadIcon("tree_small.png");
56     private static final ImageIcon ICON_BROWSE_CLASSPATH_LARGE = loadIcon("tree_large.png");
57     private static final ImageIcon ICON_HELP = loadIcon("help.png");
58
59     /**
60      * Load an icon from the <tt>images</tt> directory.
61      *
62      * @param fileName the file name for the icon
63      * @return the icon
64      */

65     public static ImageIcon loadIcon(String JavaDoc fileName) {
66
67         URL JavaDoc imageURL = BrowserMDIFrame.class.getResource("images/" + fileName);
68         return new ImageIcon(imageURL);
69     }
70
71     private Action actionOpenClassFile;
72     private Action actionBrowseClasspath;
73     private Action actionSetupClasspath;
74     private Action actionNewWorkspace;
75     private Action actionOpenWorkspace;
76     private Action actionSaveWorkspace;
77     private Action actionSaveWorkspaceAs;
78     private Action actionQuit;
79     private Action actionShowHomepage;
80     private Action actionShowEJT;
81     private Action actionBackward;
82     private Action actionForward;
83     private Action actionReload;
84     private Action actionShowHelp;
85     private Action actionAbout;
86
87     private File workspaceFile;
88     private String JavaDoc workspaceChooserPath = "";
89     private String JavaDoc classesChooserPath = "";
90     private BrowserConfig config;
91
92     // Visual Components
93

94     private JFileChooser workspaceFileChooser;
95     private JFileChooser classesFileChooser;
96
97     private RecentMenu recentMenu;
98     private ClasspathSetupDialog classpathSetupDialog;
99     private ClasspathBrowser classpathBrowser;
100     private ClasspathBrowser jarBrowser;
101
102     /**
103      * Constructor.
104      */

105     public BrowserMDIFrame() {
106
107         doNewWorkspace();
108
109         recentMenu = new RecentMenu(this);
110         loadSettings();
111         setupActions();
112         setupMenu();
113         setupFrame();
114     }
115
116     /**
117      * Get the current browser config.
118      *
119      * @return the browser config
120      */

121     public BrowserConfig getConfig() {
122         return config;
123     }
124
125     public void setVisible(boolean visible) {
126         super.setVisible(visible);
127         if (visible) {
128             desktopManager.showAll();
129         }
130     }
131
132     /**
133      * Get the action for displaying the classpath setup dialog.
134      *
135      * @return the action
136      */

137     public Action getActionSetupClasspath() {
138         return actionSetupClasspath;
139     }
140
141     /**
142      * Get the action for going backward in the navigation history.
143      *
144      * @return the action
145      */

146     public Action getActionBackward() {
147         return actionBackward;
148     }
149
150     /**
151      * Get the action for going forward in the navigation history.
152      *
153      * @return the action
154      */

155     public Action getActionForward() {
156         return actionForward;
157     }
158
159     /**
160      * Get the action for reloading the current frame.
161      *
162      * @return the action
163      */

164     public Action getActionReload() {
165         return actionReload;
166     }
167
168     /**
169      * Get the last path for the classes file chooser.
170      *
171      * @return the path
172      */

173     public String JavaDoc getClassesChooserPath() {
174         return classesChooserPath;
175     }
176
177     /**
178      * Set the last path for the classes file chooser.
179      *
180      * @param classesChooserPath the path
181      */

182     public void setClassesChooserPath(String JavaDoc classesChooserPath) {
183         this.classesChooserPath = classesChooserPath;
184     }
185
186     /**
187      * Open a workspace file.
188      *
189      * @param file the file.
190      */

191     public void openWorkspace(File file) {
192
193         repaintNow();
194         setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
195         closeAllFrames();
196         try {
197             FileInputStream fos = new FileInputStream(file);
198             XMLDecoder decoder = new XMLDecoder(fos);
199             config = (BrowserConfig)decoder.readObject();
200             readMDIConfig(config.getMDIConfig());
201             decoder.close();
202             recentMenu.addRecentWorkspace(file);
203             if (classpathBrowser != null) {
204                 classpathBrowser.setClasspathComponent(config);
205             }
206         } catch (FileNotFoundException e) {
207             GUIHelper.showMessage(this, "An error occured while reading " + file.getPath(), JOptionPane.ERROR_MESSAGE);
208         } finally {
209             setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
210         }
211         workspaceFile = file;
212         updateTitle();
213         actionSaveWorkspaceAs.setEnabled(true);
214     }
215
216     /**
217      * Open an internal frame for a given file.
218      *
219      * @param file the file
220      * @return the created internal frame
221      */

222     public BrowserInternalFrame openClassFromFile(File file) {
223
224         BrowserInternalFrame frame = new BrowserInternalFrame(desktopManager, new WindowState(file.getPath()));
225         ClassFile classFile = frame.getClassFile();
226
227         if (classFile != null) {
228             try {
229                 String JavaDoc className = classFile.getThisClassName();
230                 String JavaDoc[] pathComponents = className.split("/");
231                 File currentDirectory = file.getParentFile();
232                 boolean validClasspathEntry = true;
233                 for (int i = pathComponents.length - 2; i >= 0; i--) {
234                     String JavaDoc pathComponent = pathComponents[i];
235                     if (!currentDirectory.getName().equals(pathComponent)) {
236                         validClasspathEntry = false;
237                         break;
238                     }
239                     currentDirectory = currentDirectory.getParentFile();
240                 }
241                 if (validClasspathEntry) {
242                     config.addClasspathDirectory(currentDirectory.getPath());
243                 }
244             } catch (InvalidByteCodeException e) {
245             }
246         }
247         return frame;
248     }
249
250     protected void doQuit() {
251         saveSettings();
252         super.doQuit();
253     }
254
255     protected BasicDesktopManager createDesktopManager() {
256         return new BrowserDesktopManager(this);
257     }
258
259     protected Class JavaDoc[] getFrameConstructorArguments(Class JavaDoc frameClass) {
260         return BrowserInternalFrame.CONSTRUCTOR_ARGUMENTS;
261     }
262
263     private void setupActions() {
264
265         actionOpenClassFile = new DefaultAction("Open class file", ICON_OPEN_CLASS_FILE);
266         actionOpenClassFile.putValue(Action.SHORT_DESCRIPTION, "Open a class file");
267
268         actionBrowseClasspath = new DefaultAction("Browse classpath", ICON_BROWSE_CLASSPATH);
269         actionBrowseClasspath.putValue(Action.SHORT_DESCRIPTION, "Browse the current classpath to open a class file");
270
271         actionSetupClasspath = new DefaultAction("Setup classpath", GUIHelper.ICON_EMPTY);
272         actionSetupClasspath.putValue(Action.SHORT_DESCRIPTION, "Configure the classpath");
273
274         actionNewWorkspace = new DefaultAction("New workspace", GUIHelper.ICON_EMPTY);
275         actionNewWorkspace.putValue(Action.SHORT_DESCRIPTION, "Close all frames and open a new workspace");
276
277         actionOpenWorkspace = new DefaultAction("Open workspace", ICON_OPEN_WORKSPACE);
278         actionOpenWorkspace.putValue(Action.SHORT_DESCRIPTION, "Open workspace from disk");
279
280         actionSaveWorkspace = new DefaultAction("Save workspace", ICON_SAVE_WORKSPACE);
281         actionSaveWorkspace.putValue(Action.SHORT_DESCRIPTION, "Save current workspace to disk");
282
283         actionSaveWorkspaceAs = new DefaultAction("Save workspace as", GUIHelper.ICON_EMPTY);
284         actionSaveWorkspaceAs.putValue(Action.SHORT_DESCRIPTION, "Save current workspace to a different file");
285         actionSaveWorkspaceAs.setEnabled(false);
286
287         actionQuit = new DefaultAction("Quit", GUIHelper.ICON_EMPTY);
288
289         actionBackward = new DefaultAction("Backward", ICON_BACKWARD);
290         actionBackward.putValue(Action.SHORT_DESCRIPTION, "Move backward in the navigation history");
291         actionBackward.setEnabled(false);
292
293         actionForward = new DefaultAction("Forward", ICON_FORWARD);
294         actionForward.putValue(Action.SHORT_DESCRIPTION, "Move forward in the navigation history");
295         actionForward.setEnabled(false);
296
297         actionReload = new DefaultAction("Reload", ICON_RELOAD);
298         actionReload.putValue(Action.SHORT_DESCRIPTION, "Reload class file");
299         actionReload.setEnabled(false);
300
301         actionShowHomepage = new DefaultAction("jclasslib on the web", ICON_WEB);
302         actionShowHomepage.putValue(Action.SHORT_DESCRIPTION, "Visit jclasslib on the web");
303
304         actionShowEJT = new DefaultAction("ej-technologies on the web", ICON_WEB);
305         actionShowEJT.putValue(Action.SHORT_DESCRIPTION, "Visit ej-technologies on the web");
306
307         actionShowHelp = new DefaultAction("Show help", ICON_HELP);
308         actionShowHelp.putValue(Action.SHORT_DESCRIPTION, "Show the jclasslib documentation");
309
310         actionAbout = new DefaultAction("About the jclasslib bytecode viewer", GUIHelper.ICON_EMPTY);
311         actionAbout.putValue(Action.SHORT_DESCRIPTION, "Show the jclasslib documentation");
312     }
313
314     private void setupMenu() {
315
316         JMenuItem menuItem;
317         JMenuBar menuBar = new JMenuBar();
318
319         JMenu menuFile = new JMenu("File");
320         menuFile.add(actionOpenClassFile);
321         menuFile.addSeparator();
322         menuFile.add(actionNewWorkspace);
323         menuFile.add(actionOpenWorkspace);
324         menuFile.add(recentMenu);
325         menuFile.addSeparator();
326         menuFile.add(actionSaveWorkspace);
327         menuFile.add(actionSaveWorkspaceAs);
328         menuFile.addSeparator();
329         menuFile.add(actionShowHomepage);
330         menuFile.add(actionShowEJT);
331         menuFile.addSeparator();
332         menuFile.add(actionQuit);
333
334         JMenu menuClasspath = new JMenu("Classpath");
335         menuClasspath.add(actionBrowseClasspath);
336         menuClasspath.add(actionSetupClasspath);
337
338         JMenu menuBrowse = new JMenu("Browse");
339         menuItem = menuBrowse.add(actionBackward);
340         menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, Event.ALT_MASK));
341         menuItem = menuBrowse.add(actionForward);
342         menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, Event.ALT_MASK));
343
344         menuBrowse.addSeparator();
345         menuItem = menuBrowse.add(actionReload);
346         menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, Event.CTRL_MASK));
347
348         JMenu menuHelp = new JMenu("Help");
349         menuItem = menuHelp.add(actionShowHelp);
350         menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0));
351         menuHelp.add(actionAbout);
352
353
354         menuBar.add(menuFile);
355         menuBar.add(menuClasspath);
356         menuBar.add(menuBrowse);
357         menuBar.add(menuWindow);
358         menuBar.add(menuHelp);
359         setJMenuBar(menuBar);
360
361     }
362
363     private void setupFrame() {
364
365         Container contentPane = getContentPane();
366
367         contentPane.add(buildToolbar(), BorderLayout.NORTH);
368         setIconImage(ICON_APPLICATION.getImage());
369     }
370
371     private void updateTitle() {
372
373         if (workspaceFile == null) {
374             setTitle(BrowserApplication.APPLICATION_TITLE);
375             if (actionSaveWorkspaceAs != null) {
376                 actionSaveWorkspaceAs.setEnabled(false);
377             }
378         } else {
379             setTitle(BrowserApplication.APPLICATION_TITLE + " [" + workspaceFile.getName() + "]");
380         }
381     }
382
383     private JToolBar buildToolbar() {
384
385         JToolBar toolBar = new JToolBar();
386         toolBar.add(actionOpenClassFile).setIcon(ICON_OPEN_CLASS_FILE_LARGE);
387         toolBar.add(actionBrowseClasspath).setIcon(ICON_BROWSE_CLASSPATH_LARGE);
388         toolBar.addSeparator();
389         toolBar.add(actionOpenWorkspace).setIcon(ICON_OPEN_WORKSPACE_LARGE);
390         toolBar.add(actionSaveWorkspace).setIcon(ICON_SAVE_WORKSPACE_LARGE);
391         toolBar.addSeparator();
392         toolBar.add(actionBackward).setIcon(ICON_BACKWARD_LARGE);
393         toolBar.add(actionForward).setIcon(ICON_FORWARD_LARGE);
394         toolBar.addSeparator();
395         toolBar.add(actionReload).setIcon(ICON_RELOAD_LARGE);
396         toolBar.addSeparator();
397         toolBar.add(actionShowHomepage).setIcon(ICON_WEB_LARGE);
398
399         toolBar.setFloatable(false);
400
401         return toolBar;
402     }
403
404     private void repaintNow() {
405
406         JComponent contentPane = (JComponent)getContentPane();
407         contentPane.paintImmediately(0, 0, contentPane.getWidth(), contentPane.getHeight());
408         JMenuBar menuBar = getJMenuBar();
409         menuBar.paintImmediately(0, 0, menuBar.getWidth(), menuBar.getHeight());
410     }
411
412     private void loadSettings() {
413
414         Preferences JavaDoc preferences = Preferences.userNodeForPackage(getClass());
415
416         workspaceChooserPath = preferences.get(SETTINGS_WORKSPACE_CHOOSER_PATH, workspaceChooserPath);
417         classesChooserPath = preferences.get(SETTINGS_CLASSES_CHOOSER_PATH, classesChooserPath);
418         recentMenu.read(preferences);
419     }
420
421     private void saveSettings() {
422
423         Preferences JavaDoc preferences = Preferences.userNodeForPackage(getClass());
424         preferences.put(SETTINGS_WORKSPACE_CHOOSER_PATH, workspaceChooserPath);
425         preferences.put(SETTINGS_CLASSES_CHOOSER_PATH, classesChooserPath);
426         recentMenu.save(preferences);
427     }
428
429     private void doSaveWorkspace(boolean saveAs) {
430
431         config.setMDIConfig(createMDIConfig());
432         if (workspaceFile != null && !saveAs) {
433             saveWorkspaceToFile(workspaceFile);
434             return;
435         }
436
437         JFileChooser fileChooser = getWorkspaceFileChooser();
438         int result = fileChooser.showSaveDialog(this);
439         if (result == JFileChooser.APPROVE_OPTION) {
440             File selectedFile = fileChooser.getSelectedFile();
441             if (!selectedFile.getName().toLowerCase().endsWith("." + BrowserApplication.WORKSPACE_FILE_SUFFIX)) {
442                 selectedFile = new File(selectedFile.getPath() + "." + BrowserApplication.WORKSPACE_FILE_SUFFIX);
443             }
444             if (selectedFile.exists() &&
445                     GUIHelper.showOptionDialog(this,
446                             "The file " + selectedFile.getPath() + "\nexists. Do you want to overwrite this file?",
447                             GUIHelper.YES_NO_OPTIONS,
448                             JOptionPane.QUESTION_MESSAGE) != 0) {
449                 return;
450             }
451             saveWorkspaceToFile(selectedFile);
452             workspaceFile = selectedFile;
453             updateTitle();
454             workspaceChooserPath = fileChooser.getCurrentDirectory().getAbsolutePath();
455         }
456     }
457
458     private void saveWorkspaceToFile(File file) {
459
460         try {
461             FileOutputStream fos = new FileOutputStream(file);
462             XMLEncoder encoder = new XMLEncoder(fos);
463             encoder.writeObject(config);
464             encoder.close();
465             recentMenu.addRecentWorkspace(file);
466         } catch (FileNotFoundException e) {
467             GUIHelper.showMessage(this, "An error occured while saving to " + file.getPath(), JOptionPane.ERROR_MESSAGE);
468         }
469         GUIHelper.showMessage(this, "Workspace saved to " + file.getPath(), JOptionPane.INFORMATION_MESSAGE);
470         actionSaveWorkspaceAs.setEnabled(true);
471     }
472
473     private void doNewWorkspace() {
474
475         closeAllFrames();
476         workspaceFile = null;
477         config = new BrowserConfig();
478         config.addRuntimeLib();
479         if (classpathBrowser != null) {
480             classpathBrowser.setClasspathComponent(config);
481         }
482         updateTitle();
483     }
484
485     private void doOpenWorkspace() {
486
487         JFileChooser fileChooser = getWorkspaceFileChooser();
488         int result = fileChooser.showOpenDialog(this);
489         if (result == JFileChooser.APPROVE_OPTION) {
490             File selectedFile = fileChooser.getSelectedFile();
491             openWorkspace(selectedFile);
492             workspaceChooserPath = fileChooser.getCurrentDirectory().getAbsolutePath();
493         }
494     }
495
496     private void doOpenClassFile() {
497
498         JFileChooser fileChooser = getClassesFileChooser();
499         int result = fileChooser.showOpenDialog(this);
500         if (result == JFileChooser.APPROVE_OPTION) {
501             repaintNow();
502             setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
503             File file = fileChooser.getSelectedFile();
504             classesChooserPath = fileChooser.getCurrentDirectory().getAbsolutePath();
505
506             BrowserInternalFrame frame;
507             if (file.getPath().toLowerCase().endsWith(".class")) {
508                 frame = openClassFromFile(file);
509             } else {
510                 frame = openClassFromJar(file);
511             }
512
513             if (frame != null) {
514                 try {
515                     frame.setMaximum(true);
516                 } catch (PropertyVetoException ex) {
517                 }
518             }
519             setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
520         }
521     }
522
523     private BrowserInternalFrame openClassFromJar(File file) {
524
525         ClasspathArchiveEntry entry = new ClasspathArchiveEntry();
526         entry.setFileName(file.getPath());
527         if (jarBrowser == null) {
528             jarBrowser = new ClasspathBrowser(this, null, "Classes in selected JAR file:", false);
529         }
530         jarBrowser.clear();
531         jarBrowser.setClasspathComponent(entry);
532         jarBrowser.setVisible(true);
533         String JavaDoc selectedClassName = jarBrowser.getSelectedClassName();
534         if (selectedClassName == null) {
535             return null;
536         }
537
538         String JavaDoc fileName = file.getPath() + "!" + selectedClassName + ".class";
539
540         BrowserInternalFrame frame = new BrowserInternalFrame(desktopManager, new WindowState(fileName));
541         ClassFile classFile = frame.getClassFile();
542         if (classFile != null) {
543             config.addClasspathArchive(file.getPath());
544         }
545
546         return frame;
547     }
548
549     private void doBrowseClasspath() {
550
551         if (classpathBrowser == null) {
552             classpathBrowser = new ClasspathBrowser(this, config, "Configured classpath:", true);
553         }
554         classpathBrowser.setVisible(true);
555         String JavaDoc selectedClassName = classpathBrowser.getSelectedClassName();
556         if (selectedClassName == null) {
557             return;
558         }
559
560         FindResult findResult = config.findClass(selectedClassName);
561         if (findResult == null) {
562             GUIHelper.showMessage(this, "Error loading " + selectedClassName, JOptionPane.ERROR_MESSAGE);
563             return;
564         }
565
566         repaintNow();
567         setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
568         BrowserInternalFrame frame = new BrowserInternalFrame(desktopManager, new WindowState(findResult.getFileName()));
569         try {
570             frame.setMaximum(true);
571         } catch (PropertyVetoException ex) {
572         }
573         setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
574
575     }
576
577     private void doSetupClasspath() {
578         if (classpathSetupDialog == null) {
579             classpathSetupDialog = new ClasspathSetupDialog(this);
580
581         }
582         classpathSetupDialog.setVisible(true);
583     }
584
585     private void doBackward() {
586         BrowserInternalFrame frame = (BrowserInternalFrame)desktopPane.getSelectedFrame();
587         if (frame != null) {
588             frame.getBrowserComponent().getHistory().historyBackward();
589         }
590     }
591
592     private void doForward() {
593         BrowserInternalFrame frame = (BrowserInternalFrame)desktopPane.getSelectedFrame();
594         if (frame != null) {
595             frame.getBrowserComponent().getHistory().historyForward();
596         }
597     }
598
599     private void doReload() {
600         BrowserInternalFrame frame = (BrowserInternalFrame)desktopPane.getSelectedFrame();
601         if (frame != null) {
602             frame.reload();
603         }
604     }
605
606     private JFileChooser getWorkspaceFileChooser() {
607
608         if (workspaceFileChooser == null) {
609             workspaceFileChooser = new JFileChooser(workspaceChooserPath);
610             workspaceFileChooser.setDialogTitle("Choose workspace file");
611             workspaceFileChooser.setFileFilter(new BasicFileFilter(BrowserApplication.WORKSPACE_FILE_SUFFIX, "jclasslib workspace files"));
612         }
613
614         return workspaceFileChooser;
615     }
616
617     private JFileChooser getClassesFileChooser() {
618
619         if (classesFileChooser == null) {
620             classesFileChooser = new JFileChooser(classesChooserPath);
621             classesFileChooser.setDialogTitle("Choose class file or jar file");
622             classesFileChooser.addChoosableFileFilter(new BasicFileFilter("class", "class files"));
623             classesFileChooser.addChoosableFileFilter(new BasicFileFilter("jar", "jar files"));
624             classesFileChooser.setFileFilter(new BasicFileFilter(new String JavaDoc[]{"class", "jar"}, "class files and jar files"));
625         }
626
627         return classesFileChooser;
628     }
629
630     private void doShowURL(String JavaDoc urlSpec) {
631
632         String JavaDoc commandLine;
633         if (System.getProperty("os.name").startsWith("Windows")) {
634             commandLine = "rundll32.exe url.dll,FileProtocolHandler " + urlSpec;
635         } else {
636             commandLine = "netscape " + urlSpec;
637         }
638         try {
639             Runtime.getRuntime().exec(commandLine);
640         } catch (IOException ex) {
641         }
642     }
643
644     private void doAbout() {
645         new BrowserAboutDialog(this).setVisible(true);
646     }
647
648     private class DefaultAction extends AbstractAction {
649
650         private DefaultAction(String JavaDoc name, Icon icon) {
651             super(name, icon);
652         }
653
654         public void actionPerformed(ActionEvent JavaDoc ev) {
655
656             if (this == actionOpenClassFile) {
657                 doOpenClassFile();
658             } else if (this == actionBrowseClasspath) {
659                 doBrowseClasspath();
660             } else if (this == actionSetupClasspath) {
661                 doSetupClasspath();
662             } else if (this == actionNewWorkspace) {
663                 doNewWorkspace();
664             } else if (this == actionOpenWorkspace) {
665                 doOpenWorkspace();
666             } else if (this == actionSaveWorkspace) {
667                 doSaveWorkspace(false);
668             } else if (this == actionSaveWorkspaceAs) {
669                 doSaveWorkspace(true);
670             } else if (this == actionQuit) {
671                 doQuit();
672             } else if (this == actionBackward) {
673                 doBackward();
674             } else if (this == actionForward) {
675                 doForward();
676             } else if (this == actionReload) {
677                 doReload();
678             } else if (this == actionShowHomepage) {
679                 doShowURL("http://www.ej-technologies.com/products/jclasslib/overview.html");
680             } else if (this == actionShowEJT) {
681                 doShowURL("http://www.ej-technologies.com");
682             } else if (this == actionShowHelp) {
683                 try {
684                     doShowURL(new File("doc/help.html").getCanonicalFile().toURL().toExternalForm());
685                 } catch (IOException e) {
686                 }
687             } else if (this == actionAbout) {
688                 doAbout();
689             }
690         }
691
692     }
693
694 }
695
Popular Tags