[brailleblaster] push by john.bo...@xxxxxxxxxxxxxxxxx - Tidying up classes on 2012-05-04 16:35 GMT

Revision: 5d3ba8677eb2
Author:   John Boyer <john.boyer@xxxxxxxxxxxxxxxxx>
Date:     Fri May  4 09:34:43 2012
Log:      Tidying up classes
http://code.google.com/p/brailleblaster/source/detail?r=5d3ba8677eb2

Modified:
 /src/main/org/brailleblaster/wordprocessor/DocumentManager.java
 /src/main/org/brailleblaster/wordprocessor/RecentDocuments.java

=======================================
--- /src/main/org/brailleblaster/wordprocessor/DocumentManager.java Fri May 4 01:52:02 2012 +++ /src/main/org/brailleblaster/wordprocessor/DocumentManager.java Fri May 4 09:34:43 2012
@@ -54,13 +54,14 @@
 import org.eclipse.swt.widgets.Listener;
 import org.brailleblaster.settings.Welcome;
 import org.eclipse.swt.widgets.MessageBox;
+import org.brailleblaster.util.FileUtils;
+
+/**
+ * This class manages each document in an MDI environment. It controls
+ * the braille View and the daisy View.
+  */
 class DocumentManager {

-    /**
-     * This class manages each document in an MDI environment. It controls
-     * the braille View and the daisy View.
-     */
-
     final Display display;
     final Shell documentWindow;
     final int documentNumber;
@@ -116,7 +117,7 @@
         });
         layout = new FormLayout();
         documentWindow.setLayout (layout);
-        rd= new RecentDocuments();
+        rd = new RecentDocuments(this);
         utd = new UTD(this);
         menu = new BBMenu (this);
         toolBar = new BBToolBar (this);
@@ -140,7 +141,7 @@
         if (action == WP.OpenDocumentGetFile) {
             fileOpen();
         } else if (action == WP.DocumentFromCommandLine) {
-            openFirstDocument();
+            openDocument(documentName);
         }
         boolean stop = false;
while (!documentWindow.isDisposed() && (!stop)&&(returnReason == 0)) {
@@ -226,24 +227,6 @@
             }
         }
     }
-
-    void openFirstDocument() {
-        Builder parser = new Builder();
-        try {
-            doc = parser.build (documentName);
-        } catch (ParsingException e) {
-            new Notify ("Malformed document");
-            return;
-        }
-        catch (IOException e) {
-            new Notify ("Could not open " + documentName);
-            return;
-        }
-        setWindowTitle (documentName);
-        haveOpenedFile = true;
-        Element rootElement = doc.getRootElement();
-        walkTree (rootElement);
-    }

     private void setWindowTitle (String pathName) {
         int index = pathName.lastIndexOf (File.separatorChar);
@@ -286,7 +269,10 @@
             new Notify ("File not found");
             return;
         }
-        String fileName = documentName;
+        openDocument (documentName);
+    }
+
+    void openDocument (String fileName) {
         Builder parser = new Builder();
         try {
             doc = parser.build (fileName);
@@ -363,46 +349,9 @@
             new Notify ("There is no translated file to be saved.");
             return;
         }
-        FileInputStream inFile = null;
-        FileOutputStream outFile = null;
-        try {
-            inFile = new FileInputStream (translatedFileName);
-        } catch (FileNotFoundException e) {
-            new Notify ("Could not open " + translatedFileName);
-            return;
-        }
-        try {
-            outFile = new FileOutputStream (saveTo);
-        } catch (FileNotFoundException e) {
-            new Notify ("Could not open " + saveTo);
-            return;
-        }
-        byte[] buffer = new byte[1024];
-        int length = 0;
-        while (length != -1) {
-            try {
-                length = inFile.read (buffer, 0, buffer.length);
-            } catch (IOException e) {
-                new Notify ("Problem reading " + translatedFileName);
-                break;
-            }
-            if (length == -1) {
-                break;
-            }
-            try {
-                outFile.write (buffer, 0, length);
-            } catch (IOException e) {
-                new Notify ("Problem writing to " + saveTo);
-                break;
-            }
-        }
-        try {
-            outFile.close();
+        new FileUtils().copyFile (translatedFileName, saveTo);
             //add this file to recentDocList
             rd.addDocument(translatedFileName);
-        } catch (IOException e) {
-            new Notify (saveTo + " could not be completed");
-        }
     }

     void showBraille() {
=======================================
--- /src/main/org/brailleblaster/wordprocessor/RecentDocuments.java Fri May 4 01:12:16 2012 +++ /src/main/org/brailleblaster/wordprocessor/RecentDocuments.java Fri May 4 09:34:43 2012
@@ -26,6 +26,8 @@
  * Maintained by John J. Boyer john.boyer@xxxxxxxxxxxxxxxxx
  */

+/* Author: Hanxiao Fu */
+
 package org.brailleblaster.wordprocessor;

 import java.io.BufferedReader;
@@ -51,6 +53,7 @@
  * Pick a document from those recently opened and return its absolute
  * path.
  */
+
 class RecentDocuments {
     Shell shell;
     Combo combo;
@@ -60,8 +63,10 @@
     private String recentFiles;
     private static final int MAX_NUM_FILES=50;
     private String fileSep;
-
-    RecentDocuments() {
+    private DocumentManager dm;
+
+    RecentDocuments(final DocumentManager dm) {
+        this.dm = dm;
         recentFiles = BBIni.getRecentDocs();
         fileSep = BBIni.getFileSep();
         file = new File(recentFiles);
@@ -90,8 +95,7 @@
                 String path = recentDocsList.get(key);
                 //This is for debug
                 new Notify("Value="+value+", path="+path);
-                //then open the file
-                //openFile(path);
+                dm.openDocument (path);
                 shell.close();
             }
         });

Other related posts:

  • » [brailleblaster] push by john.bo...@xxxxxxxxxxxxxxxxx - Tidying up classes on 2012-05-04 16:35 GMT - brailleblaster