001: /*
002: This library is free software; you can redistribute it and/or
003: modify it under the terms of the GNU General Public
004: License as published by the Free Software Foundation; either
005: version 2 of the license, or (at your option) any later version.
006: */
007:
008: package org.gjt.jclasslib.browser;
009:
010: import org.gjt.jclasslib.browser.config.BrowserConfig;
011: import org.gjt.jclasslib.browser.config.classpath.*;
012: import org.gjt.jclasslib.browser.config.window.WindowState;
013: import org.gjt.jclasslib.mdi.*;
014: import org.gjt.jclasslib.structures.ClassFile;
015: import org.gjt.jclasslib.structures.InvalidByteCodeException;
016: import org.gjt.jclasslib.util.GUIHelper;
017:
018: import javax.swing.*;
019: import java.awt.*;
020: import java.awt.event.ActionEvent;
021: import java.awt.event.KeyEvent;
022: import java.beans.*;
023: import java.io.*;
024: import java.net.URL;
025: import java.util.prefs.Preferences;
026:
027: /**
028: * MDI Frame and entry point for the class file browser application.
029: *
030: * @author <a href="mailto:jclasslib@ej-technologies.com">Ingo Kegel</a>
031: * @version $Revision: 1.10 $ $Date: 2005/01/14 15:01:03 $
032: */
033: public class BrowserMDIFrame extends BasicMDIFrame {
034:
035: static final ImageIcon ICON_APPLICATION = loadIcon("jclasslib.gif");
036:
037: private static final String SETTINGS_WORKSPACE_CHOOSER_PATH = "workspaceChooserPath";
038: private static final String SETTINGS_CLASSES_CHOOSER_PATH = "classesChooserPath";
039:
040: private static final ImageIcon ICON_OPEN_CLASS_FILE = loadIcon("open_small.png");
041: private static final ImageIcon ICON_OPEN_CLASS_FILE_LARGE = loadIcon("open_large.png");
042: private static final ImageIcon ICON_OPEN_WORKSPACE = loadIcon("open_ws_small.png");
043: private static final ImageIcon ICON_OPEN_WORKSPACE_LARGE = loadIcon("open_ws_large.png");
044: private static final ImageIcon ICON_SAVE_WORKSPACE = loadIcon("save_ws_small.png");
045: private static final ImageIcon ICON_SAVE_WORKSPACE_LARGE = loadIcon("save_ws_large.png");
046: private static final ImageIcon ICON_BACKWARD = loadIcon("browser_backward_small.png");
047: private static final ImageIcon ICON_BACKWARD_LARGE = loadIcon("browser_backward_large.png");
048: private static final ImageIcon ICON_FORWARD = loadIcon("browser_forward_small.png");
049: private static final ImageIcon ICON_FORWARD_LARGE = loadIcon("browser_forward_large.png");
050: private static final ImageIcon ICON_RELOAD = loadIcon("reload_small.png");
051: private static final ImageIcon ICON_RELOAD_LARGE = loadIcon("reload_large.png");
052: private static final ImageIcon ICON_WEB = loadIcon("web_small.png");
053: private static final ImageIcon ICON_WEB_LARGE = loadIcon("web_large.png");
054: private static final ImageIcon ICON_BROWSE_CLASSPATH = loadIcon("tree_small.png");
055: private static final ImageIcon ICON_BROWSE_CLASSPATH_LARGE = loadIcon("tree_large.png");
056: private static final ImageIcon ICON_HELP = loadIcon("help.png");
057:
058: /**
059: * Load an icon from the <tt>images</tt> directory.
060: *
061: * @param fileName the file name for the icon
062: * @return the icon
063: */
064: public static ImageIcon loadIcon(String fileName) {
065:
066: URL imageURL = BrowserMDIFrame.class.getResource("images/"
067: + fileName);
068: return new ImageIcon(imageURL);
069: }
070:
071: private Action actionOpenClassFile;
072: private Action actionBrowseClasspath;
073: private Action actionSetupClasspath;
074: private Action actionNewWorkspace;
075: private Action actionOpenWorkspace;
076: private Action actionSaveWorkspace;
077: private Action actionSaveWorkspaceAs;
078: private Action actionQuit;
079: private Action actionShowHomepage;
080: private Action actionShowEJT;
081: private Action actionBackward;
082: private Action actionForward;
083: private Action actionReload;
084: private Action actionShowHelp;
085: private Action actionAbout;
086:
087: private File workspaceFile;
088: private String workspaceChooserPath = "";
089: private String classesChooserPath = "";
090: private BrowserConfig config;
091:
092: // Visual Components
093:
094: private JFileChooser workspaceFileChooser;
095: private JFileChooser classesFileChooser;
096:
097: private RecentMenu recentMenu;
098: private ClasspathSetupDialog classpathSetupDialog;
099: 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 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 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 ,
208: "An error occured while reading " + file.getPath(),
209: JOptionPane.ERROR_MESSAGE);
210: } finally {
211: setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
212: }
213: workspaceFile = file;
214: updateTitle();
215: actionSaveWorkspaceAs.setEnabled(true);
216: }
217:
218: /**
219: * Open an internal frame for a given file.
220: *
221: * @param file the file
222: * @return the created internal frame
223: */
224: public BrowserInternalFrame openClassFromFile(File file) {
225:
226: BrowserInternalFrame frame = new BrowserInternalFrame(
227: desktopManager, new WindowState(file.getPath()));
228: ClassFile classFile = frame.getClassFile();
229:
230: if (classFile != null) {
231: try {
232: String className = classFile.getThisClassName();
233: String[] pathComponents = className.split("/");
234: File currentDirectory = file.getParentFile();
235: boolean validClasspathEntry = true;
236: for (int i = pathComponents.length - 2; i >= 0; i--) {
237: String pathComponent = pathComponents[i];
238: if (!currentDirectory.getName().equals(
239: pathComponent)) {
240: validClasspathEntry = false;
241: break;
242: }
243: currentDirectory = currentDirectory.getParentFile();
244: }
245: if (validClasspathEntry) {
246: config.addClasspathDirectory(currentDirectory
247: .getPath());
248: }
249: } catch (InvalidByteCodeException e) {
250: }
251: }
252: return frame;
253: }
254:
255: protected void doQuit() {
256: saveSettings();
257: super .doQuit();
258: }
259:
260: protected BasicDesktopManager createDesktopManager() {
261: return new BrowserDesktopManager(this );
262: }
263:
264: protected Class[] getFrameConstructorArguments(Class frameClass) {
265: return BrowserInternalFrame.CONSTRUCTOR_ARGUMENTS;
266: }
267:
268: private void setupActions() {
269:
270: actionOpenClassFile = new DefaultAction("Open class file",
271: ICON_OPEN_CLASS_FILE);
272: actionOpenClassFile.putValue(Action.SHORT_DESCRIPTION,
273: "Open a class file");
274:
275: actionBrowseClasspath = new DefaultAction("Browse classpath",
276: ICON_BROWSE_CLASSPATH);
277: actionBrowseClasspath.putValue(Action.SHORT_DESCRIPTION,
278: "Browse the current classpath to open a class file");
279:
280: actionSetupClasspath = new DefaultAction("Setup classpath",
281: GUIHelper.ICON_EMPTY);
282: actionSetupClasspath.putValue(Action.SHORT_DESCRIPTION,
283: "Configure the classpath");
284:
285: actionNewWorkspace = new DefaultAction("New workspace",
286: GUIHelper.ICON_EMPTY);
287: actionNewWorkspace.putValue(Action.SHORT_DESCRIPTION,
288: "Close all frames and open a new workspace");
289:
290: actionOpenWorkspace = new DefaultAction("Open workspace",
291: ICON_OPEN_WORKSPACE);
292: actionOpenWorkspace.putValue(Action.SHORT_DESCRIPTION,
293: "Open workspace from disk");
294:
295: actionSaveWorkspace = new DefaultAction("Save workspace",
296: ICON_SAVE_WORKSPACE);
297: actionSaveWorkspace.putValue(Action.SHORT_DESCRIPTION,
298: "Save current workspace to disk");
299:
300: actionSaveWorkspaceAs = new DefaultAction("Save workspace as",
301: GUIHelper.ICON_EMPTY);
302: actionSaveWorkspaceAs.putValue(Action.SHORT_DESCRIPTION,
303: "Save current workspace to a different file");
304: actionSaveWorkspaceAs.setEnabled(false);
305:
306: actionQuit = new DefaultAction("Quit", GUIHelper.ICON_EMPTY);
307:
308: actionBackward = new DefaultAction("Backward", ICON_BACKWARD);
309: actionBackward.putValue(Action.SHORT_DESCRIPTION,
310: "Move backward in the navigation history");
311: actionBackward.setEnabled(false);
312:
313: actionForward = new DefaultAction("Forward", ICON_FORWARD);
314: actionForward.putValue(Action.SHORT_DESCRIPTION,
315: "Move forward in the navigation history");
316: actionForward.setEnabled(false);
317:
318: actionReload = new DefaultAction("Reload", ICON_RELOAD);
319: actionReload.putValue(Action.SHORT_DESCRIPTION,
320: "Reload class file");
321: actionReload.setEnabled(false);
322:
323: actionShowHomepage = new DefaultAction("jclasslib on the web",
324: ICON_WEB);
325: actionShowHomepage.putValue(Action.SHORT_DESCRIPTION,
326: "Visit jclasslib on the web");
327:
328: actionShowEJT = new DefaultAction("ej-technologies on the web",
329: ICON_WEB);
330: actionShowEJT.putValue(Action.SHORT_DESCRIPTION,
331: "Visit ej-technologies on the web");
332:
333: actionShowHelp = new DefaultAction("Show help", ICON_HELP);
334: actionShowHelp.putValue(Action.SHORT_DESCRIPTION,
335: "Show the jclasslib documentation");
336:
337: actionAbout = new DefaultAction(
338: "About the jclasslib bytecode viewer",
339: GUIHelper.ICON_EMPTY);
340: actionAbout.putValue(Action.SHORT_DESCRIPTION,
341: "Show the jclasslib documentation");
342: }
343:
344: private void setupMenu() {
345:
346: JMenuItem menuItem;
347: JMenuBar menuBar = new JMenuBar();
348:
349: JMenu menuFile = new JMenu("File");
350: menuFile.add(actionOpenClassFile);
351: menuFile.addSeparator();
352: menuFile.add(actionNewWorkspace);
353: menuFile.add(actionOpenWorkspace);
354: menuFile.add(recentMenu);
355: menuFile.addSeparator();
356: menuFile.add(actionSaveWorkspace);
357: menuFile.add(actionSaveWorkspaceAs);
358: menuFile.addSeparator();
359: menuFile.add(actionShowHomepage);
360: menuFile.add(actionShowEJT);
361: menuFile.addSeparator();
362: menuFile.add(actionQuit);
363:
364: JMenu menuClasspath = new JMenu("Classpath");
365: menuClasspath.add(actionBrowseClasspath);
366: menuClasspath.add(actionSetupClasspath);
367:
368: JMenu menuBrowse = new JMenu("Browse");
369: menuItem = menuBrowse.add(actionBackward);
370: menuItem.setAccelerator(KeyStroke.getKeyStroke(
371: KeyEvent.VK_LEFT, Event.ALT_MASK));
372: menuItem = menuBrowse.add(actionForward);
373: menuItem.setAccelerator(KeyStroke.getKeyStroke(
374: KeyEvent.VK_RIGHT, Event.ALT_MASK));
375:
376: menuBrowse.addSeparator();
377: menuItem = menuBrowse.add(actionReload);
378: menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R,
379: Event.CTRL_MASK));
380:
381: JMenu menuHelp = new JMenu("Help");
382: menuItem = menuHelp.add(actionShowHelp);
383: menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1,
384: 0));
385: menuHelp.add(actionAbout);
386:
387: menuBar.add(menuFile);
388: menuBar.add(menuClasspath);
389: menuBar.add(menuBrowse);
390: menuBar.add(menuWindow);
391: menuBar.add(menuHelp);
392: setJMenuBar(menuBar);
393:
394: }
395:
396: private void setupFrame() {
397:
398: Container contentPane = getContentPane();
399:
400: contentPane.add(buildToolbar(), BorderLayout.NORTH);
401: setIconImage(ICON_APPLICATION.getImage());
402: }
403:
404: private void updateTitle() {
405:
406: if (workspaceFile == null) {
407: setTitle(BrowserApplication.APPLICATION_TITLE);
408: if (actionSaveWorkspaceAs != null) {
409: actionSaveWorkspaceAs.setEnabled(false);
410: }
411: } else {
412: setTitle(BrowserApplication.APPLICATION_TITLE + " ["
413: + workspaceFile.getName() + "]");
414: }
415: }
416:
417: private JToolBar buildToolbar() {
418:
419: JToolBar toolBar = new JToolBar();
420: toolBar.add(actionOpenClassFile).setIcon(
421: ICON_OPEN_CLASS_FILE_LARGE);
422: toolBar.add(actionBrowseClasspath).setIcon(
423: ICON_BROWSE_CLASSPATH_LARGE);
424: toolBar.addSeparator();
425: toolBar.add(actionOpenWorkspace).setIcon(
426: ICON_OPEN_WORKSPACE_LARGE);
427: toolBar.add(actionSaveWorkspace).setIcon(
428: ICON_SAVE_WORKSPACE_LARGE);
429: toolBar.addSeparator();
430: toolBar.add(actionBackward).setIcon(ICON_BACKWARD_LARGE);
431: toolBar.add(actionForward).setIcon(ICON_FORWARD_LARGE);
432: toolBar.addSeparator();
433: toolBar.add(actionReload).setIcon(ICON_RELOAD_LARGE);
434: toolBar.addSeparator();
435: toolBar.add(actionShowHomepage).setIcon(ICON_WEB_LARGE);
436:
437: toolBar.setFloatable(false);
438:
439: return toolBar;
440: }
441:
442: private void repaintNow() {
443:
444: JComponent contentPane = (JComponent) getContentPane();
445: contentPane.paintImmediately(0, 0, contentPane.getWidth(),
446: contentPane.getHeight());
447: JMenuBar menuBar = getJMenuBar();
448: menuBar.paintImmediately(0, 0, menuBar.getWidth(), menuBar
449: .getHeight());
450: }
451:
452: private void loadSettings() {
453:
454: Preferences preferences = Preferences
455: .userNodeForPackage(getClass());
456:
457: workspaceChooserPath = preferences.get(
458: SETTINGS_WORKSPACE_CHOOSER_PATH, workspaceChooserPath);
459: classesChooserPath = preferences.get(
460: SETTINGS_CLASSES_CHOOSER_PATH, classesChooserPath);
461: recentMenu.read(preferences);
462: }
463:
464: private void saveSettings() {
465:
466: Preferences preferences = Preferences
467: .userNodeForPackage(getClass());
468: preferences.put(SETTINGS_WORKSPACE_CHOOSER_PATH,
469: workspaceChooserPath);
470: preferences.put(SETTINGS_CLASSES_CHOOSER_PATH,
471: classesChooserPath);
472: recentMenu.save(preferences);
473: }
474:
475: private void doSaveWorkspace(boolean saveAs) {
476:
477: config.setMDIConfig(createMDIConfig());
478: if (workspaceFile != null && !saveAs) {
479: saveWorkspaceToFile(workspaceFile);
480: return;
481: }
482:
483: JFileChooser fileChooser = getWorkspaceFileChooser();
484: int result = fileChooser.showSaveDialog(this );
485: if (result == JFileChooser.APPROVE_OPTION) {
486: File selectedFile = fileChooser.getSelectedFile();
487: if (!selectedFile.getName().toLowerCase().endsWith(
488: "." + BrowserApplication.WORKSPACE_FILE_SUFFIX)) {
489: selectedFile = new File(selectedFile.getPath() + "."
490: + BrowserApplication.WORKSPACE_FILE_SUFFIX);
491: }
492: if (selectedFile.exists()
493: && GUIHelper
494: .showOptionDialog(
495: this ,
496: "The file "
497: + selectedFile.getPath()
498: + "\nexists. Do you want to overwrite this file?",
499: GUIHelper.YES_NO_OPTIONS,
500: JOptionPane.QUESTION_MESSAGE) != 0) {
501: return;
502: }
503: saveWorkspaceToFile(selectedFile);
504: workspaceFile = selectedFile;
505: updateTitle();
506: workspaceChooserPath = fileChooser.getCurrentDirectory()
507: .getAbsolutePath();
508: }
509: }
510:
511: private void saveWorkspaceToFile(File file) {
512:
513: try {
514: FileOutputStream fos = new FileOutputStream(file);
515: XMLEncoder encoder = new XMLEncoder(fos);
516: encoder.writeObject(config);
517: encoder.close();
518: recentMenu.addRecentWorkspace(file);
519: } catch (FileNotFoundException e) {
520: GUIHelper
521: .showMessage(this ,
522: "An error occured while saving to "
523: + file.getPath(),
524: JOptionPane.ERROR_MESSAGE);
525: }
526: GUIHelper.showMessage(this , "Workspace saved to "
527: + file.getPath(), JOptionPane.INFORMATION_MESSAGE);
528: actionSaveWorkspaceAs.setEnabled(true);
529: }
530:
531: private void doNewWorkspace() {
532:
533: closeAllFrames();
534: workspaceFile = null;
535: config = new BrowserConfig();
536: config.addRuntimeLib();
537: if (classpathBrowser != null) {
538: classpathBrowser.setClasspathComponent(config);
539: }
540: updateTitle();
541: }
542:
543: private void doOpenWorkspace() {
544:
545: JFileChooser fileChooser = getWorkspaceFileChooser();
546: int result = fileChooser.showOpenDialog(this );
547: if (result == JFileChooser.APPROVE_OPTION) {
548: File selectedFile = fileChooser.getSelectedFile();
549: openWorkspace(selectedFile);
550: workspaceChooserPath = fileChooser.getCurrentDirectory()
551: .getAbsolutePath();
552: }
553: }
554:
555: private void doOpenClassFile() {
556:
557: JFileChooser fileChooser = getClassesFileChooser();
558: int result = fileChooser.showOpenDialog(this );
559: if (result == JFileChooser.APPROVE_OPTION) {
560: repaintNow();
561: setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
562: File file = fileChooser.getSelectedFile();
563: classesChooserPath = fileChooser.getCurrentDirectory()
564: .getAbsolutePath();
565:
566: BrowserInternalFrame frame;
567: if (file.getPath().toLowerCase().endsWith(".class")) {
568: frame = openClassFromFile(file);
569: } else {
570: frame = openClassFromJar(file);
571: }
572:
573: if (frame != null) {
574: try {
575: frame.setMaximum(true);
576: } catch (PropertyVetoException ex) {
577: }
578: }
579: setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
580: }
581: }
582:
583: private BrowserInternalFrame openClassFromJar(File file) {
584:
585: ClasspathArchiveEntry entry = new ClasspathArchiveEntry();
586: entry.setFileName(file.getPath());
587: if (jarBrowser == null) {
588: jarBrowser = new ClasspathBrowser(this , null,
589: "Classes in selected JAR file:", false);
590: }
591: jarBrowser.clear();
592: jarBrowser.setClasspathComponent(entry);
593: jarBrowser.setVisible(true);
594: String selectedClassName = jarBrowser.getSelectedClassName();
595: if (selectedClassName == null) {
596: return null;
597: }
598:
599: String fileName = file.getPath() + "!" + selectedClassName
600: + ".class";
601:
602: BrowserInternalFrame frame = new BrowserInternalFrame(
603: desktopManager, new WindowState(fileName));
604: ClassFile classFile = frame.getClassFile();
605: if (classFile != null) {
606: config.addClasspathArchive(file.getPath());
607: }
608:
609: return frame;
610: }
611:
612: private void doBrowseClasspath() {
613:
614: if (classpathBrowser == null) {
615: classpathBrowser = new ClasspathBrowser(this , config,
616: "Configured classpath:", true);
617: }
618: classpathBrowser.setVisible(true);
619: String selectedClassName = classpathBrowser
620: .getSelectedClassName();
621: if (selectedClassName == null) {
622: return;
623: }
624:
625: FindResult findResult = config.findClass(selectedClassName);
626: if (findResult == null) {
627: GUIHelper.showMessage(this , "Error loading "
628: + selectedClassName, JOptionPane.ERROR_MESSAGE);
629: return;
630: }
631:
632: repaintNow();
633: setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
634: BrowserInternalFrame frame = new BrowserInternalFrame(
635: desktopManager, new WindowState(findResult
636: .getFileName()));
637: try {
638: frame.setMaximum(true);
639: } catch (PropertyVetoException ex) {
640: }
641: setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
642:
643: }
644:
645: private void doSetupClasspath() {
646: if (classpathSetupDialog == null) {
647: classpathSetupDialog = new ClasspathSetupDialog(this );
648:
649: }
650: classpathSetupDialog.setVisible(true);
651: }
652:
653: private void doBackward() {
654: BrowserInternalFrame frame = (BrowserInternalFrame) desktopPane
655: .getSelectedFrame();
656: if (frame != null) {
657: frame.getBrowserComponent().getHistory().historyBackward();
658: }
659: }
660:
661: private void doForward() {
662: BrowserInternalFrame frame = (BrowserInternalFrame) desktopPane
663: .getSelectedFrame();
664: if (frame != null) {
665: frame.getBrowserComponent().getHistory().historyForward();
666: }
667: }
668:
669: private void doReload() {
670: BrowserInternalFrame frame = (BrowserInternalFrame) desktopPane
671: .getSelectedFrame();
672: if (frame != null) {
673: frame.reload();
674: }
675: }
676:
677: private JFileChooser getWorkspaceFileChooser() {
678:
679: if (workspaceFileChooser == null) {
680: workspaceFileChooser = new JFileChooser(
681: workspaceChooserPath);
682: workspaceFileChooser
683: .setDialogTitle("Choose workspace file");
684: workspaceFileChooser.setFileFilter(new BasicFileFilter(
685: BrowserApplication.WORKSPACE_FILE_SUFFIX,
686: "jclasslib workspace files"));
687: }
688:
689: return workspaceFileChooser;
690: }
691:
692: private JFileChooser getClassesFileChooser() {
693:
694: if (classesFileChooser == null) {
695: classesFileChooser = new JFileChooser(classesChooserPath);
696: classesFileChooser
697: .setDialogTitle("Choose class file or jar file");
698: classesFileChooser
699: .addChoosableFileFilter(new BasicFileFilter(
700: "class", "class files"));
701: classesFileChooser
702: .addChoosableFileFilter(new BasicFileFilter("jar",
703: "jar files"));
704: classesFileChooser.setFileFilter(new BasicFileFilter(
705: new String[] { "class", "jar" },
706: "class files and jar files"));
707: }
708:
709: return classesFileChooser;
710: }
711:
712: private void doShowURL(String urlSpec) {
713:
714: String commandLine;
715: if (System.getProperty("os.name").startsWith("Windows")) {
716: commandLine = "rundll32.exe url.dll,FileProtocolHandler "
717: + urlSpec;
718: } else {
719: commandLine = "netscape " + urlSpec;
720: }
721: try {
722: Runtime.getRuntime().exec(commandLine);
723: } catch (IOException ex) {
724: }
725: }
726:
727: private void doAbout() {
728: new BrowserAboutDialog(this ).setVisible(true);
729: }
730:
731: private class DefaultAction extends AbstractAction {
732:
733: private DefaultAction(String name, Icon icon) {
734: super (name, icon);
735: }
736:
737: public void actionPerformed(ActionEvent ev) {
738:
739: if (this == actionOpenClassFile) {
740: doOpenClassFile();
741: } else if (this == actionBrowseClasspath) {
742: doBrowseClasspath();
743: } else if (this == actionSetupClasspath) {
744: doSetupClasspath();
745: } else if (this == actionNewWorkspace) {
746: doNewWorkspace();
747: } else if (this == actionOpenWorkspace) {
748: doOpenWorkspace();
749: } else if (this == actionSaveWorkspace) {
750: doSaveWorkspace(false);
751: } else if (this == actionSaveWorkspaceAs) {
752: doSaveWorkspace(true);
753: } else if (this == actionQuit) {
754: doQuit();
755: } else if (this == actionBackward) {
756: doBackward();
757: } else if (this == actionForward) {
758: doForward();
759: } else if (this == actionReload) {
760: doReload();
761: } else if (this == actionShowHomepage) {
762: doShowURL("http://www.ej-technologies.com/products/jclasslib/overview.html");
763: } else if (this == actionShowEJT) {
764: doShowURL("http://www.ej-technologies.com");
765: } else if (this == actionShowHelp) {
766: try {
767: doShowURL(new File("doc/help.html")
768: .getCanonicalFile().toURL()
769: .toExternalForm());
770: } catch (IOException e) {
771: }
772: } else if (this == actionAbout) {
773: doAbout();
774: }
775: }
776:
777: }
778:
779: }
|