[brailleblaster] push by john.bo...@xxxxxxxxxxxxxxxxx - implementing creation of new documents on 2011-11-21 19:13 GMT

  • From: brailleblaster@xxxxxxxxxxxxxx
  • To: brailleblaster@xxxxxxxxxxxxx
  • Date: Mon, 21 Nov 2011 19:14:11 +0000

Revision: 99055d9c03c2
Author:   John Boyer <john.boyer@xxxxxxxxxxxxxxxxx>
Date:     Mon Nov 21 11:12:43 2011
Log:      implementing creation of new documents
http://code.google.com/p/brailleblaster/source/detail?r=99055d9c03c2

Added:
 /dist/programData/liblouisutdml/lbu_files/document.sem
Modified:
 /src/main/org/brailleblaster/wordprocessor/AbstractView.java
 /src/main/org/brailleblaster/wordprocessor/BrailleView.java
 /src/main/org/brailleblaster/wordprocessor/DaisyView.java
 /src/main/org/brailleblaster/wordprocessor/DocumentManager.java
 /src/main/org/brailleblaster/wordprocessor/NewDocument.java

=======================================
--- /dev/null
+++ /dist/programData/liblouisutdml/lbu_files/document.sem Mon Nov 21 11:12:43 2011
@@ -0,0 +1,6 @@
+document document
+skip head
+no body
+no section
+para p
+
=======================================
--- /src/main/org/brailleblaster/wordprocessor/AbstractView.java Fri Oct 21 09:20:33 2011 +++ /src/main/org/brailleblaster/wordprocessor/AbstractView.java Mon Nov 21 11:12:43 2011
@@ -39,8 +39,30 @@
 abstract class AbstractView {
 StyledText view;
 boolean hasFocus = false;
-
-AbstractView() {
+boolean hasChanged = false;
+
+AbstractView() {}
+
+AbstractView (Shell documentWindow, int left, int right, int top,
+int bottom) {
+view = new StyledText (documentWindow, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.WRAP);
+FormData location = new FormData();
+location.left = new FormAttachment(left);
+location.right = new FormAttachment(right);
+location.top = new FormAttachment (top);
+location.bottom = new FormAttachment(bottom);
+view.setLayoutData (location);
+view.addVerifyKeyListener (new VerifyKeyListener() {
+public void verifyKey (VerifyEvent event) {
+handleKeystrokes (event);
+}
+});
+}
+
+void handleKeystrokes (VerifyEvent event) {
+hasChanged = true;
+event.doit = true;
+return;
 }

 }
=======================================
--- /src/main/org/brailleblaster/wordprocessor/BrailleView.java Fri Oct 21 09:20:33 2011 +++ /src/main/org/brailleblaster/wordprocessor/BrailleView.java Mon Nov 21 11:12:43 2011
@@ -36,29 +36,10 @@
 import org.eclipse.swt.custom.VerifyKeyListener;
 import org.eclipse.swt.events.VerifyEvent;

-
-
 class BrailleView extends AbstractView {

-// (in AbstractView) StyledText view;
-
 BrailleView (Shell documentWindow) {
-view = new StyledText (documentWindow, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.WRAP);
-FormData location = new FormData();
-location.left = new FormAttachment(56);
-location.right = new FormAttachment(100);
-location.top = new FormAttachment (12);
-location.bottom = new FormAttachment(92);
-view.setLayoutData (location);
-view.addVerifyKeyListener (new VerifyKeyListener() {
-public void verifyKey (VerifyEvent event) {
-handleKeystrokes (event);
-}
-});
-}
-
-private void handleKeystrokes (VerifyEvent event) {
-return;
+super (documentWindow, 56, 100, 12, 92);
 }

 }
=======================================
--- /src/main/org/brailleblaster/wordprocessor/DaisyView.java Mon Oct 24 07:48:38 2011 +++ /src/main/org/brailleblaster/wordprocessor/DaisyView.java Mon Nov 21 11:12:43 2011
@@ -37,25 +37,9 @@
 import org.eclipse.swt.custom.VerifyKeyListener;

 class DaisyView extends AbstractView {
-// (in AbstractView) StyledText view;

 DaisyView (Shell documentWindow) {
-view = new StyledText (documentWindow, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.WRAP);
-FormData location = new FormData();
-location.left = new FormAttachment(0);
-location.right = new FormAttachment(55);
-location.top = new FormAttachment (12);
-location.bottom = new FormAttachment(92);
-view.setLayoutData (location);
-view.addVerifyKeyListener (new VerifyKeyListener() {
-public void verifyKey (VerifyEvent event) {
-handleKeystrokes (event);
-}
-});
-}
-
-private void handleKeystrokes (VerifyEvent event) {
-return;
+super (documentWindow, 0, 55, 12, 92);
 }

 }
=======================================
--- /src/main/org/brailleblaster/wordprocessor/DocumentManager.java Fri Nov 18 11:53:17 2011 +++ /src/main/org/brailleblaster/wordprocessor/DocumentManager.java Mon Nov 21 11:12:43 2011
@@ -50,6 +50,7 @@
 import java.io.File;
 import org.daisy.printing.*;
 import javax.print.PrintException;
+import org.eclipse.swt.widgets.Listener;

 class DocumentManager {

@@ -66,6 +67,7 @@
 int returnReason = 0;
 FormLayout layout;
 String documentName = null;
+boolean documentChanged = false;
 BBToolBar toolBar;
 BBMenu menu;
 AbstractView activeView;
@@ -107,6 +109,11 @@
 statusBar = new BBStatusBar (documentWindow);
 documentWindow.setSize (1000, 700);
 documentWindow.layout(true, true);
+documentWindow.addListener (SWT.Close, new Listener () {
+public void handleEvent (Event event) {
+handleShutdown(event);
+}
+});
 documentWindow.open();
 if (action == WP.OpenDocumentGetFile) {
 fileOpen();
@@ -136,6 +143,13 @@
 }

 /**
+ * Handle application shutdown signal from OS;
+ */
+void handleShutdown (Event event) {
+event.doit = true;
+}
+
+ /**
 * Clean up before closing the document.
 */
 void finish() {
@@ -209,9 +223,15 @@
 1));
 }
 }
+
+void createDocument () {
+newDoc = new NewDocument();
+newDoc.fillOutBody (daisy.view);
+doc = newDoc.getDocument();
+}

 void fileNew() {
-newDoc = new NewDocument (doc);
+placeholder();
 }

 void fileOpen () {
@@ -351,6 +371,7 @@
 }

 void translate() {
+createDocument();
 if (doc == null) {
 new Notify ("There is no open file.");
 return;
=======================================
--- /src/main/org/brailleblaster/wordprocessor/NewDocument.java Fri Nov 18 11:53:17 2011 +++ /src/main/org/brailleblaster/wordprocessor/NewDocument.java Mon Nov 21 11:12:43 2011
@@ -31,6 +31,7 @@
 import nu.xom.*;
 import org.brailleblaster.util.Notify;
 import java.io.IOException;
+import org.eclipse.swt.custom.StyledText;

 class NewDocument {
 Element headAdd;
@@ -39,7 +40,7 @@
 Element bodyAdd;
 Element rearAdd;

-private String framework =
+private final String framework =
 "<?xml version='1.0' encoding='utf-8'?>"
 + "<document "
 + "profile='http://www.daisy.org/z3986/2011/vocab/profiles/default/' "
@@ -76,10 +77,15 @@
 + "<body>"
 + "<section/>"
 + "</body>"
-+ "</document>"
-;
-
-NewDocument (Document doc) {
++ "</document>";
+
+Document doc;
+
+NewDocument () {
+startDocument ();
+}
+
+private void startDocument () {
 Builder builder = new Builder();
 try {
 doc = builder.build (framework, null);
@@ -111,6 +117,46 @@
 }
 findAddChildPoints (newNode);
 }
+
+void restartDocument () {
+doc = null;
+startDocument ();
+}
+
+void fillOutBody (StyledText view) {
+String text = view.getText();
+int length = text.length();
+int beginParagraph = 0;
+int endParagraph;
+while (beginParagraph < length) {
+Element paragraph = new Element ("p");
+char c = 0;
+int i;
+for (i = beginParagraph; (i < length && (c = text.charAt(i)) != 0x0a
+&& c != 0x0d); i++);
+if (i  < length) {
+endParagraph = i - 1;
+if (c == 0x0a) {
+i++;
+}
+else if (text.charAt(i + 1) == 0x0a) {
+i += 2;
+} else {
+i++;
+}
+} else {
+endParagraph = length;
+}
+paragraph.appendChild (text.substring (beginParagraph, endParagraph));
+sectionAdd.appendChild (paragraph);
+paragraph = null;
+beginParagraph = i;
+}
+}
+
+Document getDocument() {
+return doc;
+}

 }


Other related posts:

  • » [brailleblaster] push by john.bo...@xxxxxxxxxxxxxxxxx - implementing creation of new documents on 2011-11-21 19:13 GMT - brailleblaster