[Jreepad-CVS] jreepad/src/jreepad OSXAdapter.java, 1.5, 1.6 JreepadViewer.java, 1.57, 1.58
Brought to you by:
danstowell
From: PeWu <pe...@us...> - 2007-03-26 13:41:55
|
Update of /cvsroot/jreepad/jreepad/src/jreepad In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv23286/src/jreepad Modified Files: OSXAdapter.java JreepadViewer.java Log Message: refactoring: minor refactoring of open and save functions Index: OSXAdapter.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/OSXAdapter.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** OSXAdapter.java 12 Mar 2006 12:05:48 -0000 1.5 --- OSXAdapter.java 26 Mar 2007 13:28:16 -0000 1.6 *************** *** 3,13 **** File: OSXAdapter.java ! Abstract: A single class with clear, static entry points for ! hooking existing preferences, about, quit functionality from an existing Java app into handlers for the Mac OS X ! application menu. Useful for developers looking to support ! multiple platforms with a single codebase, and support Mac OS X features with minimal impact. ! Version: 1.1 --- 3,13 ---- File: OSXAdapter.java ! Abstract: A single class with clear, static entry points for ! hooking existing preferences, about, quit functionality from an existing Java app into handlers for the Mac OS X ! application menu. Useful for developers looking to support ! multiple platforms with a single codebase, and support Mac OS X features with minimal impact. ! Version: 1.1 *************** *** 26,30 **** provided that if you redistribute the Apple Software in its entirety and without modifications, you must retain this notice and the following ! text and disclaimers in all such redistributions of the Apple Software. Neither the name, trademarks, service marks or logos of Apple Computer, Inc. may be used to endorse or promote products derived from the Apple --- 26,30 ---- provided that if you redistribute the Apple Software in its entirety and without modifications, you must retain this notice and the following ! text and disclaimers in all such redistributions of the Apple Software. Neither the name, trademarks, service marks or logos of Apple Computer, Inc. may be used to endorse or promote products derived from the Apple *************** *** 50,56 **** POSSIBILITY OF SUCH DAMAGE. ! Copyright © 2004 Apple Computer, Inc., All Rights Reserved ! */ package jreepad; --- 50,56 ---- POSSIBILITY OF SUCH DAMAGE. ! Copyright � 2004 Apple Computer, Inc., All Rights Reserved ! */ package jreepad; *************** *** 67,76 **** // reference to the app where the existing quit, about, prefs code is private JreepadViewer mainApp; ! private OSXAdapter (JreepadViewer inApp) { mainApp = inApp; } ! ! // implemented handler methods. These are basically hooks into existing // functionality from the main app, as if it came over from another platform. public void handleAbout(ApplicationEvent ae) { --- 67,76 ---- // reference to the app where the existing quit, about, prefs code is private JreepadViewer mainApp; ! private OSXAdapter (JreepadViewer inApp) { mainApp = inApp; } ! ! // implemented handler methods. These are basically hooks into existing // functionality from the main app, as if it came over from another platform. public void handleAbout(ApplicationEvent ae) { *************** *** 82,86 **** } } ! public void handlePreferences(ApplicationEvent ae) { if (mainApp != null) { --- 82,86 ---- } } ! public void handlePreferences(ApplicationEvent ae) { if (mainApp != null) { *************** *** 91,105 **** } } ! // Added by Dan public void handleOpenFile(ApplicationEvent ae) { //System.err.println("Jreepad.handleOpenFile() - ApplicationEvent is " + ae); ! mainApp.openHjtFile(new java.io.File(ae.getFilename())); } ! public void handleQuit(ApplicationEvent ae) { if (mainApp != null) { ! /* / You MUST setHandled(false) if you want to delay or cancel the quit. / This is important for cross-platform development -- have a universal quit --- 91,105 ---- } } ! // Added by Dan public void handleOpenFile(ApplicationEvent ae) { //System.err.println("Jreepad.handleOpenFile() - ApplicationEvent is " + ae); ! mainApp.openFile(new java.io.File(ae.getFilename())); } ! public void handleQuit(ApplicationEvent ae) { if (mainApp != null) { ! /* / You MUST setHandled(false) if you want to delay or cancel the quit. / This is important for cross-platform development -- have a universal quit *************** *** 114,127 **** } } ! ! // The main entry-point for this functionality. This is the only method // that needs to be called at runtime, and it can easily be done using ! // reflection (see JreepadViewer.java) public static void registerMacOSXApplication(JreepadViewer inApp) { if (theApplication == null) { theApplication = new com.apple.eawt.Application(); ! } ! if (theAdapter == null) { theAdapter = new OSXAdapter(inApp); --- 114,127 ---- } } ! ! // The main entry-point for this functionality. This is the only method // that needs to be called at runtime, and it can easily be done using ! // reflection (see JreepadViewer.java) public static void registerMacOSXApplication(JreepadViewer inApp) { if (theApplication == null) { theApplication = new com.apple.eawt.Application(); ! } ! if (theAdapter == null) { theAdapter = new OSXAdapter(inApp); *************** *** 129,135 **** theApplication.addApplicationListener(theAdapter); } ! ! // Another static entry point for EAWT functionality. Enables the ! // "Preferences..." menu item in the application menu. public static void enablePrefs(boolean enabled) { if (theApplication == null) { --- 129,135 ---- theApplication.addApplicationListener(theAdapter); } ! ! // Another static entry point for EAWT functionality. Enables the ! // "Preferences..." menu item in the application menu. public static void enablePrefs(boolean enabled) { if (theApplication == null) { Index: JreepadViewer.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/JreepadViewer.java,v retrieving revision 1.57 retrieving revision 1.58 diff -C2 -d -r1.57 -r1.58 *** JreepadViewer.java 26 Mar 2007 11:49:24 -0000 1.57 --- JreepadViewer.java 26 Mar 2007 13:28:16 -0000 1.58 *************** *** 75,79 **** import javax.swing.SpinnerNumberModel; import javax.swing.UIManager; - import javax.swing.filechooser.FileFilter; import javax.swing.undo.CannotRedoException; import javax.swing.undo.CannotUndoException; --- 75,78 ---- *************** *** 86,90 **** import jreepad.io.TreepadWriter; import jreepad.io.XmlWriter; - import jreepad.ui.ExtensionFileFilter; import jreepad.ui.SaveFileChooser; import edu.stanford.ejalbert.BrowserLauncher; --- 85,88 ---- *************** *** 178,191 **** public static final int appleAppCode = 0x4A524545; - /** - * File filter for Jreepad XML .jree files. - */ - private static final FileFilter JREEPAD_FILE_FILTER = new ExtensionFileFilter("Jreepad XML file (*.jree)", "jree"); - - /** - * File filter for Treepad .hjt files. - */ - private static final FileFilter TREEPAD_FILE_FILTER = new ExtensionFileFilter("Treepad file (*.hjt)", "hjt"); - public JreepadViewer() { --- 176,179 ---- *************** *** 298,330 **** if(firstTimeFile != null && firstTimeFile.isFile()) ! { ! try ! { ! getPrefs().openLocation = firstTimeFile; // Remember the open directory ! content.remove(theJreepad); ! ! InputStream in = new FileInputStream(firstTimeFile); ! JreepadReader reader = new AutoDetectReader(getPrefs().getEncoding(), getPrefs().autoDetectHtmlArticles); ! document = reader.read(in); ! document.setSaveLocation(firstTimeFile); ! theJreepad = new JreepadView(document); ! ! getPrefs().exportLocation = getPrefs().importLocation = firstTimeFile; ! content.add(theJreepad); ! searchDialog.setJreepad(theJreepad); ! ! setTitleBasedOnFilename(firstTimeFile.getName()); ! } ! catch(IOException err) ! { ! JOptionPane.showMessageDialog(this, err, lang.getString("MSG_LOAD_FILE_FAILED") , JOptionPane.ERROR_MESSAGE); ! content.remove(theJreepad); ! document = new JreepadTreeModel(); ! theJreepad = new JreepadView(document); ! content.add(theJreepad); ! searchDialog.setJreepad(theJreepad); ! setTitleBasedOnFilename(""); ! } ! } // Set close operation --- 286,290 ---- if(firstTimeFile != null && firstTimeFile.isFile()) ! openFile(firstTimeFile); // Set close operation *************** *** 1314,1354 **** fileChooser.setCurrentDirectory(getPrefs().openLocation); ! if(fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) ! { ! openHjtFile(fileChooser.getSelectedFile()); ! } ! } // End of: openAction() ! protected void openHjtFile(File f) ! { ! try ! { ! setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); ! getPrefs().openLocation = f; ! content.remove(theJreepad); ! ! InputStream in = new FileInputStream(f); ! JreepadReader reader = new AutoDetectReader(getPrefs().getEncoding(), getPrefs().autoDetectHtmlArticles); ! document = reader.read(in); ! document.setSaveLocation(f); ! theJreepad = new JreepadView(document); ! content.add(theJreepad); ! searchDialog.setJreepad(theJreepad); ! addToOpenRecentMenu(f); ! setTitleBasedOnFilename(f.getName()); ! validate(); ! repaint(); ! //DEL theJreepad.clearUndoCache(); ! setCursor(Cursor.getDefaultCursor()); ! } ! catch(IOException err) ! { ! setCursor(Cursor.getDefaultCursor()); ! JOptionPane.showMessageDialog(this, err, lang.getString("TITLE_FILE_ERROR") , JOptionPane.ERROR_MESSAGE); ! } ! updateUndoRedoMenuState(); ! } // End of: openHjtFile() private class SaveAction extends AbstractAction --- 1274,1312 ---- fileChooser.setCurrentDirectory(getPrefs().openLocation); ! if(fileChooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) ! return; ! setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); ! openFile(fileChooser.getSelectedFile()); ! setCursor(Cursor.getDefaultCursor()); ! updateUndoRedoMenuState(); ! validate(); ! repaint(); ! } // End of: openAction() ! public boolean openFile(File file) ! { ! getPrefs().openLocation = file; // Remember the open directory ! try ! { ! InputStream in = new FileInputStream(file); ! JreepadReader reader = new AutoDetectReader(getPrefs().getEncoding(), getPrefs().autoDetectHtmlArticles); ! document = reader.read(in); ! document.setSaveLocation(file); ! } ! catch(IOException e) ! { ! JOptionPane.showMessageDialog(this, e, lang.getString("MSG_LOAD_FILE_FAILED") , JOptionPane.ERROR_MESSAGE); ! return false; ! } ! content.remove(theJreepad); ! theJreepad = new JreepadView(document); ! content.add(theJreepad); ! searchDialog.setJreepad(theJreepad); + getPrefs().exportLocation = getPrefs().importLocation = file; + setTitleBasedOnFilename(file.getName()); + return true; + } private class SaveAction extends AbstractAction *************** *** 1389,1400 **** { // Ask for filename ! JFileChooser fileChooser = new SaveFileChooser(); fileChooser.setCurrentDirectory(getPrefs().openLocation); - fileChooser.addChoosableFileFilter(JREEPAD_FILE_FILTER); - fileChooser.addChoosableFileFilter(TREEPAD_FILE_FILTER); - if (getPrefs().mainFileType == JreepadPrefs.FILETYPE_XML) - fileChooser.setFileFilter(JREEPAD_FILE_FILTER); - else - fileChooser.setFileFilter(TREEPAD_FILE_FILTER); fileChooser.setSelectedFile(new File(document.getRootNode().getTitle() + --- 1347,1352 ---- { // Ask for filename ! JFileChooser fileChooser = new SaveFileChooser(getPrefs().mainFileType); fileChooser.setCurrentDirectory(getPrefs().openLocation); fileChooser.setSelectedFile(new File(document.getRootNode().getTitle() + *************** *** 1406,1412 **** } saveLocation = fileChooser.getSelectedFile(); ! if (fileChooser.getFileFilter() == JREEPAD_FILE_FILTER) fileType = JreepadPrefs.FILETYPE_XML; ! else if (fileChooser.getFileFilter() == TREEPAD_FILE_FILTER) fileType = JreepadPrefs.FILETYPE_HJT; } --- 1358,1364 ---- } saveLocation = fileChooser.getSelectedFile(); ! if (fileChooser.getFileFilter() == SaveFileChooser.JREEPAD_FILE_FILTER) fileType = JreepadPrefs.FILETYPE_XML; ! else if (fileChooser.getFileFilter() == SaveFileChooser.TREEPAD_FILE_FILTER) fileType = JreepadPrefs.FILETYPE_HJT; } *************** *** 2017,2021 **** File f; FileOpeningActionListener(File f) {this.f = f;} ! public void actionPerformed(ActionEvent e) {openHjtFile(f);} } // End of: private class FileOpeningActionListener extends ActionListener --- 1969,1973 ---- File f; FileOpeningActionListener(File f) {this.f = f;} ! public void actionPerformed(ActionEvent e) {openFile(f);} } // End of: private class FileOpeningActionListener extends ActionListener |