Revision: 784c362743ff Branch: default Author: Brandon Roller <brandon.r.roller@xxxxxxxxx> Date: Wed Jan 23 08:02:41 2013 Log: Redesigned DocumentManager and WPManager to use a tab format http://code.google.com/p/brailleblaster/source/detail?r=784c362743ff&repo=newdesign Added: /src/main/org/brailleblaster/wordprocessor/Encoder.java /src/main/org/brailleblaster/wordprocessor/Encodings.java /src/main/org/brailleblaster/wordprocessor/FontManager.java Modified: /build.xml /src/main/org/brailleblaster/BBIni.java /src/main/org/brailleblaster/Main.java /src/main/org/brailleblaster/Subcommands.java /src/main/org/brailleblaster/abstractClasses/AbstractPrinting.java /src/main/org/brailleblaster/abstractClasses/AbstractView.java /src/main/org/brailleblaster/importers/ImportersManager.java /src/main/org/brailleblaster/localization/LocaleHandler.java /src/main/org/brailleblaster/louisutdml/TranslateFile.java /src/main/org/brailleblaster/settings/SettingsDialog.java /src/main/org/brailleblaster/settings/Welcome.java /src/main/org/brailleblaster/util/CheckLiblouisutdmlLog.java /src/main/org/brailleblaster/util/Notify.java /src/main/org/brailleblaster/util/ShowBriefly.java /src/main/org/brailleblaster/util/YesNoChoice.java /src/main/org/brailleblaster/views/BrailleView.java /src/main/org/brailleblaster/views/TextView.java /src/main/org/brailleblaster/views/TreeView.java /src/main/org/brailleblaster/wordprocessor/BBMenu.java /src/main/org/brailleblaster/wordprocessor/BBToolBar.java /src/main/org/brailleblaster/wordprocessor/CallOutsideWP.java /src/main/org/brailleblaster/wordprocessor/DocumentManager.java /src/main/org/brailleblaster/wordprocessor/NewDocument.java /src/main/org/brailleblaster/wordprocessor/RecentDocuments.java /src/main/org/brailleblaster/wordprocessor/UTD.java /src/main/org/brailleblaster/wordprocessor/WPManager.java ======================================= --- /dev/null+++ /src/main/org/brailleblaster/wordprocessor/Encoder.java Wed Jan 23 08:02:41 2013
@@ -0,0 +1,158 @@ +package org.brailleblaster.wordprocessor; + +import org.brailleblaster.localization.LocaleHandler; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.layout.RowLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Monitor; +import org.eclipse.swt.widgets.Shell; + +public class Encoder { + static LocaleHandler lh = new LocaleHandler(); + static String encoding = null; + // encoding for Import + public static String getEncodingString(Display display) { + //String encoding = null; ++ // final Shell selShell = new Shell(display, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL | SWT.CENTER);
+ final Shell selShell = new Shell(display, SWT.DIALOG_TRIM | SWT.CENTER); + selShell.setText(lh.localValue("specifyEncoding")); + selShell.setMinimumSize(250, 100); + + FillLayout layout = new FillLayout(SWT.VERTICAL); + layout.marginWidth = 8; + selShell.setLayout(layout); + Composite radioGroup = new Composite(selShell, SWT.NONE); + radioGroup.setLayout(new RowLayout(SWT.VERTICAL)); + + Button b1 = new Button(radioGroup, SWT.RADIO); + b1.setText(lh.localValue("encodeUTF8")); + b1.setSelection(true); // default + b1.pack(); + + Button b2 = new Button(radioGroup, SWT.RADIO); + b2.setText(lh.localValue("encodeISO88591")); + b2.pack(); + + Button b3 = new Button(radioGroup, SWT.RADIO); + b3.setText(lh.localValue("encodeWINDOWS1252")); + b3.pack(); + + Button b4 = new Button(radioGroup, SWT.RADIO); + b4.setText(lh.localValue("encodeUSASCII")); + b4.pack(); + + // if (SWT.getPlatform().equals("win32") || + // SWT.getPlatform().equals("wpf")) { + // b1.setSelection(false); + // b3.setSelection(true); + // } + + radioGroup.pack(); + + Composite c = new Composite(selShell, SWT.NONE); + RowLayout clayout = new RowLayout(); + clayout.type = SWT.HORIZONTAL; + // clayout.spacing = 30; + // clayout.marginWidth = 8; + clayout.marginTop = 20; + clayout.center = true; + clayout.pack = true; + clayout.justify = true; + c.setLayout(clayout); + + Button bsel = new Button(c, SWT.PUSH); + bsel.setText(lh.localValue("encodeSelect")); + bsel.pack(); + + c.pack(); + + Control tabList[] = new Control[] { radioGroup, c, radioGroup }; + try { + selShell.setTabList(tabList); + } + catch (IllegalArgumentException e) { + System.err.println("setTabList exception " + e.getMessage()); + } + + selShell.setDefaultButton(bsel); + selShell.pack(); + + Monitor primary = display.getPrimaryMonitor(); + Rectangle bounds = primary.getBounds(); + Rectangle rect = selShell.getBounds(); + int x = bounds.x + (bounds.width - rect.width) / 2; + int y = bounds.y + (bounds.height - rect.height) / 2; + selShell.setLocation(x, y); + + b1.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + encoding = Encodings.UTF_8.encoding(); + } + }); + + b2.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + encoding = Encodings.ISO_8859_1.encoding(); + } + }); + + b3.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + encoding = Encodings.WINDOWS_1252.encoding(); + } + }); + + b4.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + encoding = Encodings.US_ASCII.encoding(); + } + }); + + /* Select */ + bsel.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + selShell.dispose(); + } + }); + + selShell.addListener(SWT.Close, new Listener() { + public void handleEvent(Event event) { + event.doit = false; // must pick a value + } + }); + + selShell.open(); + + while (!selShell.isDisposed()) { + if (!display.readAndDispatch()){ + display.sleep(); + } + // nothing clicked + if (encoding == null) { + if (b1.getSelection()) { + encoding = Encodings.UTF_8.encoding(); + } + else if (b2.getSelection()) { + encoding = Encodings.ISO_8859_1.encoding(); + } + else if (b3.getSelection()) { + encoding = Encodings.WINDOWS_1252.encoding(); + } + else if (b4.getSelection()) { + encoding = Encodings.US_ASCII.encoding(); + } + } + } + return encoding; + } +} ======================================= --- /dev/null+++ /src/main/org/brailleblaster/wordprocessor/Encodings.java Wed Jan 23 08:02:41 2013
@@ -0,0 +1,16 @@ +package org.brailleblaster.wordprocessor; + +public enum Encodings {+ ISO_8859_1("ISO-8859-1"), UTF_8("UTF-8"), WINDOWS_1252("WINDOWS-1252"), US_ASCII(
+ "US-ASCII"); + + private final String encoding; + + Encodings(String encoding) { + this.encoding = encoding; + } + + public String encoding() { + return encoding; + } +} ======================================= --- /dev/null+++ /src/main/org/brailleblaster/wordprocessor/FontManager.java Wed Jan 23 08:02:41 2013
@@ -0,0 +1,124 @@ +package org.brailleblaster.wordprocessor; + +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.brailleblaster.BBIni; +import org.brailleblaster.localization.LocaleHandler; +import org.brailleblaster.util.Notify; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.widgets.Shell; + +public class FontManager { + + private static Font simBrailleFont; + private static Font daisyFont; + static boolean SimBraille = false; + static boolean Courier = false; + static String altFont = "unibraille29"; + static String courierFont = "Courier New"; + static int daisyFontHeight = 10; + static int brailleFontHeight = 14; + static LocaleHandler lh = new LocaleHandler(); + static Logger logger = BBIni.getLogger(); + static boolean displayBrailleFont = false; + + public static void setShellFonts(Shell shell, DocumentManager dm){ + FontData[] fd = shell.getDisplay().getFontList(null, true); + String fn; + + for (int i = 0; i < fd.length; i++) { + fn = fd[i].getName(); + if (fn.contentEquals("SimBraille")) { + SimBraille = true; + break; + } + if (fn.contentEquals(courierFont)) { + Courier = true; + break; + } + } + + if (!SimBraille) {+ String fontPath = BBIni.getBrailleblasterPath() + "/programData/fonts/SimBraille.ttf";
+ String platform = SWT.getPlatform(); + if (platform.equals("win32") || platform.equals("wpf")) {+ fontPath = BBIni.getBrailleblasterPath() + "\\programData\\fonts\\SimBraille.ttf";
+ } + if (!shell.getDisplay().loadFont(fontPath)) { + new Notify(lh.localValue("fontNotLoadedBraille")); + } + } + + if (Courier) {+ daisyFont = new Font(shell.getDisplay(), courierFont, daisyFontHeight, SWT.NORMAL);
+ } + else {+ String fontPath = BBIni.getBrailleblasterPath() + "/programData/fonts/" + altFont + ".ttf";
+ String platform = SWT.getPlatform(); + if (platform.equals("win32") || platform.equals("wpf")) {+ fontPath = BBIni.getBrailleblasterPath() + "\\programData\\fonts\\" + altFont + ".ttf";
+ } + if (!shell.getDisplay().loadFont(fontPath)) { + new Notify(lh.localValue("fontNotLoadedText")); + }+ daisyFont = new Font(shell.getDisplay(), altFont, daisyFontHeight, SWT.NORMAL);
+ } + + dm.daisy.view.setFont(daisyFont); + dm.braille.view.setFont(daisyFont); + dm.braille.view.setEditable(false); + + String loc = lh.getLocale().toString(); + if (!loc.contentEquals(lh.localValue("localeResource"))) {+ logger.log(Level.WARNING, "Locale resource for " + loc + " not found. Using default."); + // System.err.println("Locale resource for '" + lh.getLocale().getDisplayName() + "' not found. Using default."); + // new Notify("Locale resource for '" + lh.getLocale().getDisplayName() + "' not found.");
+ } + } + + public static void increaseFont(WPManager wp, DocumentManager dm) { + if (daisyFontHeight + (daisyFontHeight / 4) <= 48) { + daisyFontHeight += daisyFontHeight / 4; + if (Courier) {+ daisyFont = new Font(wp.getDisplay(), courierFont, daisyFontHeight, SWT.NORMAL);
+ } else {+ daisyFont = new Font(wp.getDisplay(), altFont, daisyFontHeight, SWT.NORMAL);
+ } + dm.getDaisyView().setFont(daisyFont); + + brailleFontHeight += brailleFontHeight / 4; + if (displayBrailleFont) {+ simBrailleFont = new Font(wp.getDisplay(), "SimBraille", brailleFontHeight, SWT.NORMAL);
+ dm.getBrailleView().setFont(simBrailleFont); + } + else { + dm.getBrailleView().setFont(daisyFont); + } + } + } + + public static void decreaseFont(WPManager wp, DocumentManager dm) { + if (daisyFontHeight - (daisyFontHeight / 5) >= 8) { + daisyFontHeight -= daisyFontHeight / 5; + if (Courier) {+ daisyFont = new Font(wp.getDisplay(), courierFont, daisyFontHeight, SWT.NORMAL);
+ } + else {+ daisyFont = new Font(wp.getDisplay(), altFont, daisyFontHeight, SWT.NORMAL);
+ } + dm.getDaisyView().setFont(daisyFont); + + brailleFontHeight -= brailleFontHeight / 5; + if (displayBrailleFont) {+ simBrailleFont = new Font(wp.getDisplay(), "SimBraille", brailleFontHeight, SWT.NORMAL);
+ dm.getBrailleView().setFont(simBrailleFont); + } + else { + dm.getBrailleView().setFont(daisyFont); + } + } + } +} ======================================= --- /build.xml Mon Sep 24 03:06:59 2012 +++ /build.xml Wed Jan 23 08:02:41 2013 @@ -17,7 +17,7 @@ includeantruntime="false" source="1.6" target="1.6" > <classpath> <pathelement path="${classpath}"/> -<pathelement location="${classpath}/swt.jar"/> +<pathelement location="${classpath}/swt_win_64.jar"/> <pathelement location="${classpath}/commons-exec-1.1.jar"/> <pathelement location="${classpath}/jliblouisutdml.jar"/> <pathelement location="${classpath}/commons-cli-1.2.jar"/> ======================================= --- /src/main/org/brailleblaster/BBIni.java Tue Jan 15 12:08:29 2013 +++ /src/main/org/brailleblaster/BBIni.java Wed Jan 23 08:02:41 2013 @@ -69,7 +69,6 @@ private static boolean gotGui = true; private static boolean multipleSubcommands = false; private static Logger logger; - private static Display display = null; private static String BBVersion; private static String releaseDate; private static String brailleblasterPath; // FO @@ -113,15 +112,16 @@ if (platformName.equals("win32")) { BBHome = System.getenv("APPDATA") + fileSep + BBID; nativeLibrarySuffix = ".dll"; - } else if (platformName.equals("cocoa")) { + } + else if (platformName.equals("cocoa")) { BBHome = userHome + fileSep + "." + BBID; nativeLibrarySuffix = ".dylib"; - } else { + } + else { BBHome = userHome + fileSep + "." + BBID; nativeLibrarySuffix = ".so"; } - nativeLibraryPath = brailleblasterPath + fileSep + "native" + fileSep - + "lib";+ nativeLibraryPath = brailleblasterPath + fileSep + "native" + fileSep + "lib";
FileUtils fu = new FileUtils(); userProgramDataPath = BBHome + fileSep + "programData"; File userData = new File(userProgramDataPath); @@ -129,24 +129,22 @@ userData.mkdirs(); } makeUserProgramData(); - userSettings = userProgramDataPath + fileSep - + "user_settings.properties";+ userSettings = userProgramDataPath + fileSep + "user_settings.properties";
if (!fu.exists(userSettings)) { - fu.copyFile(programDataPath + fileSep + "settings" + fileSep - + "user_settings.properties", userSettings);+ fu.copyFile(programDataPath + fileSep + "settings" + fileSep + "user_settings.properties", userSettings);
} recentDocs = userProgramDataPath + fileSep + "recent_documents.txt"; fu.create(recentDocs); - // FO Aug 03 stylePath = userProgramDataPath + fileSep + "styles"; File styleDir = new File(stylePath); - if (!styleDir.exists()) + if (!styleDir.exists()){ styleDir.mkdirs(); - + } tempFilesPath = BBHome + fileSep + "temp" + fileSep + instanceId; File temps = new File(tempFilesPath); - if (!temps.exists()) + if (!temps.exists()){ temps.mkdirs(); + } logFilesPath = BBHome + fileSep + "log"; File logPath = new File(logFilesPath); if (!logPath.exists()) { @@ -155,7 +153,8 @@ logger = Logger.getLogger("org.brailleblaster"); try { logFile = new FileHandler(logFilesPath + fileSep + "log.xml"); - } catch (IOException e) { + } + catch (IOException e) { e.printStackTrace(); logger.log(Level.SEVERE, "cannot open logfile", e); e.printStackTrace(); @@ -165,7 +164,6 @@ } // disable output to console logger.setUseParentHandlers(false); - if (args.length > 0) { int i = 0; while (i < args.length) { @@ -187,54 +185,38 @@ hSubcommands = true; } } - if (gotGui) { - try { - display = new Display(); - } catch (SWTError e) { - logger.log(Level.SEVERE, "Can't find GUI", e); - } - } try { liblouisutdml.loadLibrary(nativeLibraryPath, nativeLibrarySuffix); - liblouisutdml.initialize(programDataPath, tempFilesPath, - "liblouisutdml.log");+ liblouisutdml.initialize(programDataPath, tempFilesPath, "liblouisutdml.log");
hLiblouisutdml = true; - } catch (UnsatisfiedLinkError e) { + } + catch (UnsatisfiedLinkError e) { logger.log(Level.SEVERE, "Problem with liblouisutdml library", e); - } catch (Exception e) { + } + catch (Exception e) { logger.log(Level.WARNING, "This shouldn't happen", e); } } private String getBrailleblasterPath(Object classToUse) { - - /* - * Option to use an environment variable (mostly for testing with - * Eclipse) - */ + //Option to use an environment variable (mostly for testing withEclipse) String url = System.getenv("BBLASTER_WORK"); if (url != null) { url = "file:/" + url; - } else { - url = classToUse - .getClass() - .getResource( - "/" - + classToUse.getClass().getName() - .replaceAll("\\.", "/") + ".class") - .toString(); - - url = url.substring(url.indexOf("file")).replaceFirst( - "/[^/]+\\.jar!.*$", "/"); + } + else {+ url = classToUse.getClass().getResource("/"+ classToUse.getClass().getName().replaceAll("\\.", "/") + ".class").toString(); + url = url.substring(url.indexOf("file")).replaceFirst("/[^/]+\\.jar!.*$", "/");
} try { File dir = new File(new URL(url).toURI()); url = dir.getAbsolutePath(); - - } catch (MalformedURLException mue) { + } + catch (MalformedURLException mue) { url = null; - } catch (URISyntaxException ue) { + } + catch (URISyntaxException ue) { url = null; } return url; @@ -261,14 +243,6 @@ public static boolean debugging() { return debug; } - - public static boolean haveGui() { - return gotGui; - } - - public static Display getDisplay() { - return display; - } public static boolean haveLiblouisutdml() { return hLiblouisutdml; ======================================= --- /src/main/org/brailleblaster/Main.java Tue Jan 15 05:17:47 2013 +++ /src/main/org/brailleblaster/Main.java Wed Jan 23 08:02:41 2013 @@ -47,14 +47,14 @@ BBIni.initialize(args); BBIni.setVersion("brailleblaster-1.4.0"); BBIni.setReleaseDate("July 17, 2012"); + if (BBIni.haveSubcommands()) { new Subcommands(args); - } else { + } + else { new WPManager(null); } - Display display = BBIni.getDisplay(); - if (display != null) - display.dispose(); + if (BBIni.haveLiblouisutdml()) { liblouisutdml louisutdml = liblouisutdml.getInstance(); louisutdml.free(); ======================================= --- /src/main/org/brailleblaster/Subcommands.java Wed Aug 22 09:23:22 2012 +++ /src/main/org/brailleblaster/Subcommands.java Wed Jan 23 08:02:41 2013 @@ -1,34 +1,33 @@ /* BrailleBlaster Braille Transcription Application - * - * Copyright (C) 2010, 2012 - * ViewPlus Technologies, Inc. www.viewplus.com - * and - * Abilitiessoft, Inc. www.abilitiessoft.com - * and - * American Printing House for the Blind, Inc. www.aph.org - * - * All rights reserved - * - * This file may contain code borrowed from files produced by various - * Java development teams. These are gratefully acknoledged. - * - * This file is free software; you can redistribute it and/or modify it - * under the terms of the Apache 2.0 License, as given at - * http://www.apache.org/licenses/ - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE - * See the Apache 2.0 License for more details. - * - * You should have received a copy of the Apache 2.0 License along with - * this program; see the file LICENSE. - * If not, see - * http://www.apache.org/licenses/ - * - * Maintained by John J. Boyer john.boyer@xxxxxxxxxxxxxxxxx -*/ - + * + * Copyright (C) 2010, 2012 + * ViewPlus Technologies, Inc. www.viewplus.com + * and + * Abilitiessoft, Inc. www.abilitiessoft.com + * and + * American Printing House for the Blind, Inc. www.aph.org + * + * All rights reserved + * + * This file may contain code borrowed from files produced by various + * Java development teams. These are gratefully acknoledged. + * + * This file is free software; you can redistribute it and/or modify it + * under the terms of the Apache 2.0 License, as given at + * http://www.apache.org/licenses/ + * + * This file is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE + * See the Apache 2.0 License for more details. + * + * You should have received a copy of the Apache 2.0 License along with + * this program; see the file LICENSE. + * If not, see + * http://www.apache.org/licenses/ + * + * Maintained by John J. Boyer john.boyer@xxxxxxxxxxxxxxxxx + */ package org.brailleblaster; @@ -49,158 +48,146 @@ import org.eclipse.swt.widgets.Display; /** - * Process subcommands. - * If the first argument is not a recognized subcommand,+ * Process subcommands. If the first argument is not a recognized subcommand,
* assume it is the name of a file to be opened in the wordprocessor. -*/ + */ class Subcommands { -private Logger logger = BBIni.getLogger(); -private LocaleHandler lh = new LocaleHandler (); -private liblouisutdml louisutdml; -private CheckLiblouisutdmlLog lbuLog = new CheckLiblouisutdmlLog(); -private String subcommand; -private String[] subArgs; + private Logger logger = BBIni.getLogger(); + private LocaleHandler lh = new LocaleHandler(); + private liblouisutdml louisutdml; + private CheckLiblouisutdmlLog lbuLog = new CheckLiblouisutdmlLog(); + private String subcommand; + private String[] subArgs; -Subcommands (String[] args) { -LocaleHandler lh = new LocaleHandler(); -logger = BBIni.getLogger(); -if (!BBIni.haveLiblouisutdml()) { -logger.log (Level.SEVERE, "The Braille translation facility is absent."); -} -// ParseCommandLine.getInstance().parseCommand (args); -louisutdml = liblouisutdml.getInstance(); -int i = 0; -while ( i < args.length) { -if (args[i].charAt(0) != '-') { -break; -} -i++; -} -if (i == args.length) { -return; -} -subcommand = args[i]; -subArgs = Arrays.copyOfRange (args, i + 1, args.length); -if (subcommand.equals ("translate")) { -doTranslate(); -} -else if (subcommand.equals ("emboss")) { -doEmboss(); -} -else if (subcommand.equals ("checktable")) { -doChecktable(); -} -else if (subcommand.equals ("help")) { -doHelp(); -} -else { -Display display = BBIni.getDisplay (); -if (display == null) { - System.out.println ("Incorrect options or subcommand"); - return; - } -new WPManager (subcommand); -} -if (BBIni.multCommands()) { -moreCommands(); -} -} + Subcommands(String[] args) { + LocaleHandler lh = new LocaleHandler(); + logger = BBIni.getLogger(); + if (!BBIni.haveLiblouisutdml()) { + logger.log(Level.SEVERE, + "The Braille translation facility is absent."); + } + // ParseCommandLine.getInstance().parseCommand (args); + louisutdml = liblouisutdml.getInstance(); + int i = 0; + while (i < args.length) { + if (args[i].charAt(0) != '-') { + break; + } + i++; + } + if (i == args.length) { + return; + } + subcommand = args[i]; + subArgs = Arrays.copyOfRange(args, i + 1, args.length); + if (subcommand.equals("translate")) { + doTranslate(); + } + else if (subcommand.equals("emboss")) { + doEmboss(); + } + else if (subcommand.equals("checktable")) { + doChecktable(); + } + else if (subcommand.equals("help")) { + doHelp(); + } + else { + new WPManager(subcommand); + } + if (BBIni.multCommands()) { + moreCommands(); + } + } -/** - * Ask for more commands and execute them. - */ -private void moreCommands () { -Console cons = System.console(); -if (cons == null) { -System.out.println ("The console is not available."); -return; -} -cons.printf ( -"Type another command at the prompt. Type exit when finished.\n"); -while (true) { -cons.printf ("Command: "); -String line = cons.readLine(); -String[] args = line.split (" ", 20); -subcommand = args[0]; -subArgs = Arrays.copyOfRange (args, 1, args.length); -if (subcommand.equals ("translate")) { -doTranslate(); -} -else if (subcommand.equals ("emboss")) { -doEmboss(); -} -else if (subcommand.equals ("checktable")) { -doChecktable(); -} -else if (subcommand.equals ("help")) { -doHelp(); -} -else if (subcommand.equals ("exit")) { -break; -} -else if (subcommand != null && !subcommand.equals("")) { -System.out.println ("Incorrect subcommand '" + subcommand + "'"); -} -} -} + /** + * Ask for more commands and execute them. + */ + private void moreCommands() { + Console cons = System.console(); + if (cons == null) { + System.out.println("The console is not available."); + return; + }+ cons.printf("Type another command at the prompt. Type exit when finished.\n");
+ while (true) { + cons.printf("Command: "); + String line = cons.readLine(); + String[] args = line.split(" ", 20); + subcommand = args[0]; + subArgs = Arrays.copyOfRange(args, 1, args.length); + if (subcommand.equals("translate")) { + doTranslate(); + } else if (subcommand.equals("emboss")) { + doEmboss(); + } else if (subcommand.equals("checktable")) { + doChecktable(); + } else if (subcommand.equals("help")) { + doHelp(); + } else if (subcommand.equals("exit")) { + break; + } else if (subcommand != null && !subcommand.equals("")) { + System.out.println("Incorrect subcommand '" + subcommand + "'"); + } + } + } -/** - * Translate the input file to the output file according to the options, - * if any. - */ -private void doTranslate() { -louisutdml.file2brl (subArgs); -lbuLog.showLog(); -} + /**+ * Translate the input file to the output file according to the options, if
+ * any. + */ + private void doTranslate() { + louisutdml.file2brl(subArgs); + lbuLog.showLog(); + } -/** - * This method takes the same arguments as translate, except that the - * output file must be specified and must be the name of a printer. Only - * the generic embosser is supported at the moment, but most embossers - * can run in this mode. - */ -private void doEmboss() { -int outIndex = subArgs.length - 1; -String transOut = "transout"; -String embosserName = subArgs[outIndex]; -subArgs[outIndex] = transOut; -if (embosserName.isEmpty() || (subArgs.length < 2)) { - System.out.println( "Embosser name not supplied. Exiting."); - return; -} -louisutdml.file2brl (subArgs); -File translatedFile = new File (transOut); -try { -PrinterDevice embosser = new PrinterDevice (embosserName, true); -embosser.transmit (translatedFile); -} catch (PrintException e) { -logger.log (Level.SEVERE, "Embosser is not working", e); -} -lbuLog.showLog(); -} + /**+ * This method takes the same arguments as translate, except that the output
+ * file must be specified and must be the name of a printer. Only the + * generic embosser is supported at the moment, but most embossers can run + * in this mode. + */ + private void doEmboss() { + int outIndex = subArgs.length - 1; + String transOut = "transout"; + String embosserName = subArgs[outIndex]; + subArgs[outIndex] = transOut; + if (embosserName.isEmpty() || (subArgs.length < 2)) { + System.out.println("Embosser name not supplied. Exiting."); + return; + } + louisutdml.file2brl(subArgs); + File translatedFile = new File(transOut); + try { + PrinterDevice embosser = new PrinterDevice(embosserName, true); + embosser.transmit(translatedFile); + } catch (PrintException e) { + logger.log(Level.SEVERE, "Embosser is not working", e); + } + lbuLog.showLog(); + } -private void doChecktable() { -String logFile = null; -if (subArgs.length == 0) { -System.out.println ("Usage: checktable tablename"); -return; -} -if (subArgs.length > 1) { -logFile = subArgs[1]; -} -louisutdml.checkTable (subArgs[0], logFile, 0); -lbuLog.showLog(); -} + private void doChecktable() { + String logFile = null; + if (subArgs.length == 0) { + System.out.println("Usage: checktable tablename"); + return; + } + if (subArgs.length > 1) { + logFile = subArgs[1]; + } + louisutdml.checkTable(subArgs[0], logFile, 0); + lbuLog.showLog(); + } -private void doHelp() { -final String[] help = new String[] { -"Usage: java -jar brailleblaster.jar {options} subcommand arguments", -"options: -nogui, the system does not have a GUI", -}; -for (int i = 0; i < help.length; i++) { -System.out.println (help[i]); -} -} + private void doHelp() { + final String[] help = new String[] { + "Usage: java -jar brailleblaster.jar {options} subcommand arguments", + "options: -nogui, the system does not have a GUI", }; + for (int i = 0; i < help.length; i++) { + System.out.println(help[i]); + } + } } =======================================--- /src/main/org/brailleblaster/abstractClasses/AbstractPrinting.java Tue Jan 15 07:30:48 2013 +++ /src/main/org/brailleblaster/abstractClasses/AbstractPrinting.java Wed Jan 23 08:02:41 2013
@@ -30,6 +30,7 @@ import org.eclipse.swt.printing.*; import org.brailleblaster.BBIni; +import org.brailleblaster.wordprocessor.WPManager; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.*; @@ -59,7 +60,7 @@ * This constructor takes care of printer setup. */ AbstractPrinting() { -Shell shell = new Shell (BBIni.getDisplay(), SWT.DIALOG_TRIM); +Shell shell = new Shell (WPManager.getDisplay(), SWT.DIALOG_TRIM); PrintDialog printer = new PrintDialog (shell); data = printer.open(); shell.dispose(); =======================================--- /src/main/org/brailleblaster/abstractClasses/AbstractView.java Tue Jan 15 07:30:48 2013 +++ /src/main/org/brailleblaster/abstractClasses/AbstractView.java Wed Jan 23 08:02:41 2013
@@ -30,6 +30,7 @@ import org.eclipse.swt.*; import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.layout.FormData; import org.eclipse.swt.layout.FormAttachment; @@ -45,9 +46,8 @@ public AbstractView() { }- public 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);+ public AbstractView(Group group, int left, int right, int top, int bottom) { + view = new StyledText(group, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.WRAP);
FormData location = new FormData(); location.left = new FormAttachment(left); @@ -76,4 +76,6 @@ hasChanged = true; event.doit = true; } + + public abstract void initializeView(); } =======================================--- /src/main/org/brailleblaster/importers/ImportersManager.java Fri Aug 31 14:46:26 2012 +++ /src/main/org/brailleblaster/importers/ImportersManager.java Wed Jan 23 08:02:41 2013
@@ -71,8 +71,7 @@ // Constructor- public ImportersManager (String fileName, String tempPath, String docID, String arcType)
- throws Exception {+ public ImportersManager (String fileName, String tempPath, String docID, String arcType) throws Exception {
this.fileName = fileName; this.tempPath = tempPath; this.docID = docID; @@ -81,21 +80,22 @@ if (arcType.contains("epub")) { isEpub = true; mediaType = "application/xhtml+xml"; - } else { + } + else { isNimas = true; mediaType = "application/x-dtbook+xml"; } if ((isNimas && isEpub) || (!isNimas && !isEpub)) {- System.err.println("extractZipFiles - Error - doc type - Nimas " + isNimas +
- " isEpub " + isNimas);+ System.err.println("extractZipFiles - Error - doc type - Nimas " + isNimas + " isEpub " + isNimas);
} } public String[] extractPubFiles () { if (isEpub || isNimas) { return extractZip(fileName, tempPath, docID); - } else { + } + else { return null; } } @@ -107,12 +107,13 @@ try { fis = new FileInputStream(new File(fileName)); - } catch (FileNotFoundException e) { + } + catch (FileNotFoundException e) { System.err.println(e.getMessage()); return null; } ZipInputStream zis = new - ZipInputStream(new BufferedInputStream(fis)); + ZipInputStream(new BufferedInputStream(fis)); ZipEntry entry; StringBuffer arcNames = new StringBuffer(); int count = 0; @@ -123,11 +124,11 @@ while((entry = zis.getNextEntry()) != null) { String fn = entry.getName(); String ext = getFileExt(fn);- if (ext.contentEquals("xml") || ext.contentEquals("opf") || ext.contentEquals("html")
- || ext.contentEquals("htm") || ext.contentEquals("xhtml")) {+ if (ext.contentEquals("xml") || ext.contentEquals("opf") || ext.contentEquals("html") || ext.contentEquals("htm") || ext.contentEquals("xhtml")) {
arcNames.append(fn + "|"); count++; - } else { + } + else { continue; } int c; @@ -140,16 +141,16 @@ of.getParentFile().mkdirs(); FileOutputStream fos = new FileOutputStream(destFile); BufferedOutputStream dest = new - BufferedOutputStream(fos, BUFFER); - while ((c = zis.read(data, 0, BUFFER)) != -1) { - + BufferedOutputStream(fos, BUFFER); + while ((c = zis.read(data, 0, BUFFER)) != -1) { dest.write(data, 0, c); } dest.flush(); dest.close(); } zis.close(); - } catch (IOException e) { + } + catch (IOException e) { System.err.println(e.getMessage()); return null; } @@ -174,13 +175,15 @@ File of = new File(opfFile); if (of.getParent() == null) { opfPath = BBIni.getFileSep(); - } else { + } + else { opfPath = of.getParent() + BBIni.getFileSep(); } orderedDocList = getOrderedFileList(a.length, tempPath+opfFile); encoding = getEncoding(tempPath+opfFile); - } else { + } + else { orderedDocList = a.clone(); encoding = "UTF-8"; } @@ -196,10 +199,12 @@ Document doc; try { doc = parser.build(opfFile); - } catch (ParsingException e) { + } + catch (ParsingException e) { new Notify(lh.localValue("malformedDocument") + "\n" + opfFile); return null; - } catch (IOException e) { + } + catch (IOException e) { new Notify(lh.localValue("couldNotOpen") + "\n" + opfFile); return null; } @@ -212,7 +217,6 @@ } void walkOpfTree (Node node ) { - Node newNode; for (int i = 0; i < node.getChildCount(); i++) { @@ -235,7 +239,6 @@ } private String getEncoding(String fileName) { - String line; try { @@ -246,21 +249,26 @@ //System.out.println(line); ois.close(); - } catch (FileNotFoundException e) { + } + catch (FileNotFoundException e) { System.err.println(e.getLocalizedMessage()); return null; - } catch (IOException e) { + } + catch (IOException e) { System.err.println(e.getLocalizedMessage()); return null; - } + } - if (line == null) return null; + if (line == null){ + return null; + } String e2; int i = line.indexOf("encoding="); if (i < 0) { e2 = "UTF-8"; - } else { + } + else { String e1 = line.substring(i); String e1a = e1.replace("'", "\""); e2 = e1a.substring(e1a.indexOf("\"")+1, e1a.lastIndexOf("\"") ); =======================================--- /src/main/org/brailleblaster/localization/LocaleHandler.java Mon Apr 23 08:40:54 2012 +++ /src/main/org/brailleblaster/localization/LocaleHandler.java Wed Jan 23 08:02:41 2013
@@ -1,65 +1,61 @@ /* BrailleBlaster Braille Transcription Application - * - * Copyright (C) 2010, 2012 - * ViewPlus Technologies, Inc. www.viewplus.com - * and - * Abilitiessoft, Inc. www.abilitiessoft.com - * All rights reserved - * - * This file may contain code borrowed from files produced by various - * Java development teams. These are gratefully acknoledged. - * - * This file is free software; you can redistribute it and/or modify it - * under the terms of the Apache 2.0 License, as given at - * http://www.apache.org/licenses/ - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE - * See the Apache 2.0 License for more details. - * - * You should have received a copy of the Apache 2.0 License along with - * this program; see the file LICENSE. - * If not, see - * http://www.apache.org/licenses/ - * - * Maintained by John J. Boyer john.boyer@xxxxxxxxxxxxxxxxx -*/ + * + * Copyright (C) 2010, 2012 + * ViewPlus Technologies, Inc. www.viewplus.com + * and + * Abilitiessoft, Inc. www.abilitiessoft.com + * All rights reserved + * + * This file may contain code borrowed from files produced by various + * Java development teams. These are gratefully acknoledged. + * + * This file is free software; you can redistribute it and/or modify it + * under the terms of the Apache 2.0 License, as given at + * http://www.apache.org/licenses/ + * + * This file is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE + * See the Apache 2.0 License for more details. + * + * You should have received a copy of the Apache 2.0 License along with + * this program; see the file LICENSE. + * If not, see + * http://www.apache.org/licenses/ + * + * Maintained by John J. Boyer john.boyer@xxxxxxxxxxxxxxxxx + */ package org.brailleblaster.localization; import java.util.Locale; -/** - * This class provides the methods used to deal with locales in other - * packages and classes. - */ -+//This class provides the methods used to deal with locales in other packages and classes.
public class LocaleHandler { - -public LocaleHandler () { -if (LocalizationBase.getLocale() == null) -LocalizationBase.setLocale(); -} + public LocaleHandler() { + if (LocalizationBase.getLocale() == null){ + LocalizationBase.setLocale(); + } + } -public LocaleHandler (String locale) { -LocalizationBase.setLocale (locale); -} + public LocaleHandler(String locale) { + LocalizationBase.setLocale(locale); + } -public Locale setLocale () { -return LocalizationBase.setLocale(); -} + public Locale setLocale() { + return LocalizationBase.setLocale(); + } -public Locale setLocale (String locale) { -return LocalizationBase.setLocale (locale); -} + public Locale setLocale(String locale) { + return LocalizationBase.setLocale(locale); + } -public String localValue (String key) { -return LocalizationBase.localValue (key); -} + public String localValue(String key) { + return LocalizationBase.localValue(key); + } -public Locale getLocale() { -return LocalizationBase.getLocale(); -} + public Locale getLocale() { + return LocalizationBase.getLocale(); + } } =======================================--- /src/main/org/brailleblaster/louisutdml/TranslateFile.java Sat Jan 29 00:19:30 2011 +++ /src/main/org/brailleblaster/louisutdml/TranslateFile.java Wed Jan 23 08:02:41 2013
@@ -2,21 +2,13 @@ import org.liblouis.liblouisutdml; -public class TranslateFile -{ +public class TranslateFile { - public TranslateFile (String configFileList, String - inputFileName, - String outputFileName, - String logFileName, - String settingsString, int mode) -throws LiblouisutdmlException -{ -boolean result; -result = liblouisutdml.getInstance().translateFile -(configFileList, inputFileName, - outputFileName, logFileName, - settingsString, mode); -}+ public TranslateFile(String configFileList, String inputFileName, String outputFileName, + String logFileName, String settingsString, int mode) throws LiblouisutdmlException {
+ boolean result; + result = liblouisutdml.getInstance().translateFile(configFileList, + inputFileName, outputFileName, logFileName, settingsString, mode); + } } =======================================--- /src/main/org/brailleblaster/settings/SettingsDialog.java Wed Dec 5 18:20:29 2012 +++ /src/main/org/brailleblaster/settings/SettingsDialog.java Wed Jan 23 08:02:41 2013
@@ -50,6 +50,7 @@ import org.brailleblaster.localization.LocaleHandler; import org.brailleblaster.util.Notify; import org.brailleblaster.wordprocessor.CallOutsideWP; +import org.brailleblaster.wordprocessor.WPManager; /** This class works closely with classes in the louisutdml package to chose the correct liblouisutdml configuration file and other user @@ -66,7 +67,7 @@ loadProperties(); } public void open() { - Display display = BBIni.getDisplay(); + Display display = WPManager.getDisplay(); shell = new Shell(display, SWT.DIALOG_TRIM); final Shell dialog = new Shell(shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL); =======================================--- /src/main/org/brailleblaster/settings/Welcome.java Sun Dec 30 10:54:38 2012 +++ /src/main/org/brailleblaster/settings/Welcome.java Wed Jan 23 08:02:41 2013
@@ -52,6 +52,7 @@ import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import org.brailleblaster.wordprocessor.CallOutsideWP; +import org.brailleblaster.wordprocessor.WPManager; /** * This class displays the welcome screen The first time BrailleBlaster @@ -70,7 +71,7 @@ return; } -Display display = BBIni.getDisplay(); +Display display = WPManager.getDisplay(); final Shell shell = new Shell(display, SWT.CLOSE|SWT.BORDER); FormLayout formLayout = new FormLayout(); =======================================--- /src/main/org/brailleblaster/util/CheckLiblouisutdmlLog.java Sat Jan 12 04:05:16 2013 +++ /src/main/org/brailleblaster/util/CheckLiblouisutdmlLog.java Wed Jan 23 08:02:41 2013
@@ -37,6 +37,8 @@ import org.eclipse.swt.widgets.MessageBox; import org.brailleblaster.BBIni; import org.brailleblaster.localization.LocaleHandler; +import org.brailleblaster.wordprocessor.WPManager; + import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -63,7 +65,7 @@ */ public void displayLog () { StringBuilder logMessages = new StringBuilder (4096); -Display display = BBIni.getDisplay(); +Display display = WPManager.getDisplay(); Shell shell = new Shell(display, SWT.DIALOG_TRIM); MessageBox mb = new MessageBox(shell, SWT.OK); String line; ======================================= --- /src/main/org/brailleblaster/util/Notify.java Mon Apr 30 12:42:35 2012 +++ /src/main/org/brailleblaster/util/Notify.java Wed Jan 23 08:02:41 2013 @@ -34,6 +34,7 @@ import org.eclipse.swt.widgets.MessageBox; import org.brailleblaster.BBIni; import org.brailleblaster.localization.LocaleHandler; +import org.brailleblaster.wordprocessor.WPManager; /** * Display a message. @@ -50,7 +51,7 @@ } else { realMessage = message; } -Display display = BBIni.getDisplay(); +Display display = WPManager.getDisplay(); if (display == null) { System.out.println (realMessage); return; =======================================--- /src/main/org/brailleblaster/util/ShowBriefly.java Sat Oct 15 06:14:59 2011 +++ /src/main/org/brailleblaster/util/ShowBriefly.java Wed Jan 23 08:02:41 2013
@@ -1,30 +1,30 @@ /* BrailleBlaster Braille Transcription Application - * - * Copyright (C) 2010, 2012 - * ViewPlus Technologies, Inc. www.viewplus.com - * and - * Abilitiessoft, Inc. www.abilitiessoft.com - * All rights reserved - * - * This file may contain code borrowed from files produced by various - * Java development teams. These are gratefully acknoledged. - * - * This file is free software; you can redistribute it and/or modify it - * under the terms of the Apache 2.0 License, as given at - * http://www.apache.org/licenses/ - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE - * See the Apache 2.0 License for more details. - * - * You should have received a copy of the Apache 2.0 License along with - * this program; see the file LICENSE. - * If not, see - * http://www.apache.org/licenses/ - * - * Maintained by John J. Boyer john.boyer@xxxxxxxxxxxxxxxxx -*/ + * + * Copyright (C) 2010, 2012 + * ViewPlus Technologies, Inc. www.viewplus.com + * and + * Abilitiessoft, Inc. www.abilitiessoft.com + * All rights reserved + * + * This file may contain code borrowed from files produced by various + * Java development teams. These are gratefully acknoledged. + * + * This file is free software; you can redistribute it and/or modify it + * under the terms of the Apache 2.0 License, as given at + * http://www.apache.org/licenses/ + * + * This file is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE + * See the Apache 2.0 License for more details. + * + * You should have received a copy of the Apache 2.0 License along with + * this program; see the file LICENSE. + * If not, see + * http://www.apache.org/licenses/ + * + * Maintained by John J. Boyer john.boyer@xxxxxxxxxxxxxxxxx + */ package org.brailleblaster.util; @@ -34,27 +34,29 @@ import org.eclipse.swt.widgets.MessageBox; import org.eclipse.swt.widgets.Label; import org.brailleblaster.BBIni; +import org.brailleblaster.wordprocessor.WPManager; /** -* Show the user a message for a brief time. -*/ + * Show the user a message for a brief time. + */ public class ShowBriefly { -private Shell shell; -public ShowBriefly (String message) { -Display display = BBIni.getDisplay(); -shell = new Shell(display, SWT.DIALOG_TRIM); -Label label = new Label (shell, SWT.HORIZONTAL); -label.setText (message); -shell.open (); -display.timerExec (60000, new Runnable () { -public void run () { -endShow(); -} -}); -} + private Shell shell; -private void endShow() { -shell.dispose(); -} + public ShowBriefly(String message) { + Display display = WPManager.getDisplay(); + shell = new Shell(display, SWT.DIALOG_TRIM); + Label label = new Label(shell, SWT.HORIZONTAL); + label.setText(message); + shell.open(); + display.timerExec(60000, new Runnable() { + public void run() { + endShow(); + } + }); + } + + private void endShow() { + shell.dispose(); + } } =======================================--- /src/main/org/brailleblaster/util/YesNoChoice.java Fri Aug 12 16:10:28 2011 +++ /src/main/org/brailleblaster/util/YesNoChoice.java Wed Jan 23 08:02:41 2013
@@ -1,30 +1,30 @@ /* BrailleBlaster Braille Transcription Application - * - * Copyright (C) 2010, 2012 - * ViewPlus Technologies, Inc. www.viewplus.com - * and - * Abilitiessoft, Inc. www.abilitiessoft.com - * All rights reserved - * - * This file may contain code borrowed from files produced by various - * Java development teams. These are gratefully acknoledged. - * - * This file is free software; you can redistribute it and/or modify it - * under the terms of the Apache 2.0 License, as given at - * http://www.apache.org/licenses/ - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE - * See the Apache 2.0 License for more details. - * - * You should have received a copy of the Apache 2.0 License along with - * this program; see the file LICENSE. - * If not, see - * http://www.apache.org/licenses/ - * - * Maintained by John J. Boyer john.boyer@xxxxxxxxxxxxxxxxx -*/ + * + * Copyright (C) 2010, 2012 + * ViewPlus Technologies, Inc. www.viewplus.com + * and + * Abilitiessoft, Inc. www.abilitiessoft.com + * All rights reserved + * + * This file may contain code borrowed from files produced by various + * Java development teams. These are gratefully acknoledged. + * + * This file is free software; you can redistribute it and/or modify it + * under the terms of the Apache 2.0 License, as given at + * http://www.apache.org/licenses/ + * + * This file is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE + * See the Apache 2.0 License for more details. + * + * You should have received a copy of the Apache 2.0 License along with + * this program; see the file LICENSE. + * If not, see + * http://www.apache.org/licenses/ + * + * Maintained by John J. Boyer john.boyer@xxxxxxxxxxxxxxxxx + */ package org.brailleblaster.util; @@ -33,21 +33,22 @@ import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.MessageBox; import org.brailleblaster.BBIni; +import org.brailleblaster.wordprocessor.WPManager; public class YesNoChoice { -/** -* Show the user a message and -* give her a yes/no choice. -*/ -public int result; -public YesNoChoice (String message) { -Display display = BBIni.getDisplay(); -Shell shell = new Shell(display, SWT.DIALOG_TRIM); -MessageBox mb = new MessageBox(shell, SWT.YES | SWT.NO); -mb.setMessage (message); -result = mb.open(); -shell.dispose(); -} + /** + * Show the user a message and give her a yes/no choice. + */ + public int result; + + public YesNoChoice(String message) { + Display display = WPManager.getDisplay(); + Shell shell = new Shell(display, SWT.DIALOG_TRIM); + MessageBox mb = new MessageBox(shell, SWT.YES | SWT.NO); + mb.setMessage(message); + result = mb.open(); + shell.dispose(); + } } =======================================--- /src/main/org/brailleblaster/views/BrailleView.java Tue Jan 15 07:30:48 2013 +++ /src/main/org/brailleblaster/views/BrailleView.java Wed Jan 23 08:02:41 2013
@@ -1,30 +1,30 @@ /* BrailleBlaster Braille Transcription Application - * - * Copyright (C) 2010, 2012 - * ViewPlus Technologies, Inc. www.viewplus.com - * and - * Abilitiessoft, Inc. www.abilitiessoft.com - * All rights reserved - * - * This file may contain code borrowed from files produced by various - * Java development teams. These are gratefully acknoledged. - * - * This file is free software; you can redistribute it and/or modify it - * under the terms of the Apache 2.0 License, as given at - * http://www.apache.org/licenses/ - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE - * See the Apache 2.0 License for more details. - * - * You should have received a copy of the Apache 2.0 License along with - * this program; see the file LICENSE. - * If not, see - * http://www.apache.org/licenses/ - * - * Maintained by John J. Boyer john.boyer@xxxxxxxxxxxxxxxxx -*/ + * + * Copyright (C) 2010, 2012 + * ViewPlus Technologies, Inc. www.viewplus.com + * and + * Abilitiessoft, Inc. www.abilitiessoft.com + * All rights reserved + * + * This file may contain code borrowed from files produced by various + * Java development teams. These are gratefully acknoledged. + * + * This file is free software; you can redistribute it and/or modify it + * under the terms of the Apache 2.0 License, as given at + * http://www.apache.org/licenses/ + * + * This file is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE + * See the Apache 2.0 License for more details. + * + * You should have received a copy of the Apache 2.0 License along with + * this program; see the file LICENSE. + * If not, see + * http://www.apache.org/licenses/ + * + * Maintained by John J. Boyer john.boyer@xxxxxxxxxxxxxxxxx + */ package org.brailleblaster.views; @@ -32,27 +32,28 @@ import org.brailleblaster.abstractClasses.AbstractView; import org.eclipse.swt.*; import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.layout.FormData; import org.eclipse.swt.layout.FormAttachment; import org.eclipse.swt.custom.VerifyKeyListener; import org.eclipse.swt.events.VerifyEvent; - public class BrailleView extends AbstractView { -public BrailleView (Shell documentWindow) { -// super (documentWindow, 56, 100, 12, 92); - super (documentWindow, 58, 100, 12, 92); + public BrailleView(Group documentWindow) { + // super (documentWindow, 56, 100, 12, 92); + super(documentWindow, 58, 100, 0, 100); -} + } + /*+ * This is a derivative work from org.eclipse.swt.custom.DefaultContent.java
+ */ + public void initializeView() { -/* This is a derivative work from - * org.eclipse.swt.custom.DefaultContent.java -*/ + } -class BrailleContent extends AbstractContent { -} + class BrailleContent extends AbstractContent { + } } - =======================================--- /src/main/org/brailleblaster/views/TextView.java Tue Jan 15 07:30:48 2013 +++ /src/main/org/brailleblaster/views/TextView.java Wed Jan 23 08:02:41 2013
@@ -32,6 +32,7 @@ import org.brailleblaster.abstractClasses.AbstractView; import org.eclipse.swt.*; import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.layout.FormData; import org.eclipse.swt.layout.FormAttachment; @@ -41,16 +42,19 @@ public class TextView extends AbstractView { -public TextView (Shell documentWindow) { +public TextView (Group documentWindow) { // super (documentWindow, 0, 55, 12, 92); -super (documentWindow, 16, 57, 12, 92); - +super (documentWindow, 16, 57, 0, 100); } /* This is a derivative work from * org.eclipse.swt.custom.DefaultContent.java */ +public void initializeView(){ + +} + private class TextContent extends AbstractContent { } =======================================--- /src/main/org/brailleblaster/views/TreeView.java Tue Jan 15 07:30:48 2013 +++ /src/main/org/brailleblaster/views/TreeView.java Wed Jan 23 08:02:41 2013
@@ -45,6 +45,7 @@ import org.brailleblaster.abstractClasses.AbstractView; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Tree; import org.eclipse.swt.widgets.TreeItem; @@ -54,8 +55,8 @@ Tree tree; - public TreeView(Shell documentWindow){ - super(documentWindow, 0, 15, 12, 92); + public TreeView(Group documentWindow){ + super(documentWindow, 0, 15, 0, 100); this.tree = new Tree(view, SWT.NONE); /* * Code below was used for testing purposes only. @@ -78,6 +79,10 @@ view.setLayout(new FillLayout()); tree.pack(); } + + public void initializeView(){ + + } public void populateTree(Document doc){ TreeItem root = new TreeItem(this.tree, 0); =======================================--- /src/main/org/brailleblaster/wordprocessor/BBMenu.java Tue Jan 15 05:17:47 2013 +++ /src/main/org/brailleblaster/wordprocessor/BBMenu.java Wed Jan 23 08:02:41 2013
@@ -36,17 +36,14 @@ import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.widgets.Menu; import org.eclipse.swt.widgets.MenuItem; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.TabFolder; class BBMenu { - - /** - * This class contains all the menus. - */ - + //This class contains all the menus. final Menu menuBar; - /*- * All the menu items are member fields so they can be accessed outside the + /* All the menu items are member fields so they can be accessed outside the
* constructor. This might be done for example with setEnabled(false) to * indicate that a menu item is unavailable. */ @@ -116,7 +113,7 @@ MenuItem checkUpdatesItem; MenuItem aboutItem; - BBMenu(final DocumentManager dm) { + BBMenu(final WPManager wp) { LocaleHandler lh = new LocaleHandler(); /* @@ -128,7 +125,7 @@ */ // Set up menu bar - menuBar = new Menu(dm.documentWindow, SWT.BAR); + menuBar = new Menu(wp.getShell(), SWT.BAR); MenuItem fileItem = new MenuItem(menuBar, SWT.CASCADE); fileItem.setText(lh.localValue("&File")); MenuItem editItem = new MenuItem(menuBar, SWT.CASCADE); @@ -148,15 +145,17 @@ helpItem.setText(lh.localValue("&Help")); // Set up file menu - Menu fileMenu = new Menu(dm.documentWindow, SWT.DROP_DOWN); + Menu fileMenu = new Menu(wp.getShell(), SWT.DROP_DOWN); newItem = new MenuItem(fileMenu, SWT.PUSH); - newItem.setText(lh.localValue("&New")); + newItem.setText(lh.localValue("&New") + "\tCtrl + N"); + newItem.setAccelerator(SWT.MOD1 + 'N'); newItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { if (BBIni.debugging()) { - dm.setReturn(WP.NewDocument); + //dm.setReturn(WP.NewDocument); } else { - dm.fileNew(); + System.out.println("New Document Tab created"); + wp.addDocumentManager(null); } } }); @@ -165,9 +164,12 @@ openItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { if (BBIni.debugging()) { - dm.setReturn(WP.OpenDocumentGetFile); - } else { - dm.fileOpen(); + //dm.setReturn(WP.OpenDocumentGetFile); + } + else { + //dm.fileOpen(); + int index= wp.getFolder().getSelectionIndex(); + wp.getList().get(index).fileOpenDialog(wp); } } }); @@ -176,28 +178,30 @@ recentItem.setText(lh.localValue("&Recent")); recentItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { - dm.recentDocuments(); + //dm.recentDocuments(); + int index = wp.getFolder().getSelectionIndex(); + wp.getList().get(index).rd.open(); } }); importItem = new MenuItem(fileMenu, SWT.PUSH); importItem.setText(lh.localValue("&Import")); importItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { - dm.importDocument(); + //dm.importDocument(); } }); saveItem = new MenuItem(fileMenu, SWT.PUSH); saveItem.setText(lh.localValue("&Save")); saveItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { - dm.fileSave(); + //dm.fileSave(); } }); saveAsItem = new MenuItem(fileMenu, SWT.PUSH); saveAsItem.setText(lh.localValue("Save&As")); saveAsItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { - dm.fileSaveAs(); + //dm.fileSaveAs(); } }); @@ -205,7 +209,7 @@ saveAsItem.setText(lh.localValue("Save&Braille")); saveAsItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { - dm.brailleSave(); + //dm.brailleSave(); } }); @@ -214,7 +218,7 @@ embosserSetupItem.setEnabled(false); /* FO */ embosserSetupItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { - dm.placeholder(); + //dm.placeholder(); } }); /** @@ -239,7 +243,7 @@ embossNowItem.setText(lh.localValue("Emboss&Now!")); embossNowItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { - dm.fileEmbossNow(); + //dm.fileEmbossNow(); } }); /** @@ -276,7 +280,7 @@ printItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { // dm.placeholder(); - dm.daisyPrint(); + //dm.daisyPrint(); } }); languageItem = new MenuItem(fileMenu, SWT.PUSH); @@ -284,7 +288,7 @@ languageItem.setEnabled(false); /* FO */ languageItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { - dm.placeholder(); + //dm.placeholder(); } }); @@ -292,33 +296,41 @@ closeItem.setText(lh.localValue("&Close")); closeItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { -// dm.setReturn(WP.DocumentClosed); //FO 29 - dm.fileClose(); + int index = wp.getFolder().getSelectionIndex(); + wp.getList().get(index).fileClose(); + wp.getList().remove(index); } }); if (!BBIni.getPlatformName().equals("cocoa")) { exitItem = new MenuItem(fileMenu, SWT.PUSH); - exitItem.setText(lh.localValue("e&xit")); + exitItem.setText(lh.localValue("e&xit") + "\tCtrl + Q"); + exitItem.setAccelerator(SWT.MOD1 + 'Q'); exitItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { -// dm.setReturn(WP.BBClosed); - dm.setReturn(WP.DocumentClosed); + for(int i = 0; i < wp.getList().size(); i++){ + DocumentManager temp = wp.getList().get(i); + if(temp.daisy.hasChanged || temp.braille.hasChanged){ + temp.fileClose(); + } + } + wp.getList().clear(); + wp.getShell().getDisplay().dispose(); } }); } fileItem.setMenu(fileMenu); // Set up edit menu - Menu editMenu = new Menu(dm.documentWindow, SWT.DROP_DOWN); + Menu editMenu = new Menu(wp.getShell(), SWT.DROP_DOWN); undoItem = new MenuItem(editMenu, SWT.PUSH); undoItem.setText(lh.localValue("&Undo")); undoItem.setEnabled(false); undoItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { if (BBIni.debugging()) { - dm.setReturn(WP.SwitchDocuments); + //dm.setReturn(WP.SwitchDocuments); } else { - dm.placeholder(); + //dm.placeholder(); } } }); @@ -327,7 +339,7 @@ redoItem.setEnabled(false); redoItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { - dm.placeholder(); + //dm.placeholder(); } }); cutItem = new MenuItem(editMenu, SWT.PUSH); @@ -335,7 +347,7 @@ cutItem.setEnabled(false); cutItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { - dm.placeholder(); + //dm.placeholder(); } }); copyItem = new MenuItem(editMenu, SWT.PUSH); @@ -343,7 +355,7 @@ copyItem.setEnabled(false); copyItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { - dm.placeholder(); + //dm.placeholder(); } }); pasteItem = new MenuItem(editMenu, SWT.PUSH); @@ -351,7 +363,7 @@ pasteItem.setEnabled(false); pasteItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { - dm.placeholder(); + //dm.placeholder(); } }); searchItem = new MenuItem(editMenu, SWT.PUSH); @@ -359,7 +371,7 @@ searchItem.setEnabled(false); searchItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { - dm.placeholder(); + //dm.placeholder(); } }); replaceItem = new MenuItem(editMenu, SWT.PUSH); @@ -367,7 +379,7 @@ replaceItem.setEnabled(false); replaceItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { - dm.placeholder(); + //dm.placeholder(); } }); spellCheckItem = new MenuItem(editMenu, SWT.PUSH); @@ -375,7 +387,7 @@ spellCheckItem.setEnabled(false); spellCheckItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { - dm.placeholder(); + //dm.placeholder(); } }); boldToggleItem = new MenuItem(editMenu, SWT.PUSH); @@ -383,7 +395,7 @@ boldToggleItem.setEnabled(false); boldToggleItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { - dm.placeholder(); + //dm.placeholder(); } }); italicToggleItem = new MenuItem(editMenu, SWT.PUSH); @@ -391,7 +403,7 @@ italicToggleItem.setEnabled(false); italicToggleItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { - dm.placeholder(); + //dm.placeholder(); } }); underlineToggleItem = new MenuItem(editMenu, SWT.PUSH); @@ -399,7 +411,7 @@ underlineToggleItem.setEnabled(false); underlineToggleItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { - dm.placeholder(); + //dm.placeholder(); } }); zoomImageItem = new MenuItem(editMenu, SWT.PUSH); @@ -407,7 +419,7 @@ zoomImageItem.setEnabled(false); zoomImageItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { - dm.placeholder(); + //dm.placeholder(); } }); selectAllItem = new MenuItem(editMenu, SWT.PUSH); @@ -415,7 +427,7 @@ selectAllItem.setEnabled(false); selectAllItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { - dm.placeholder(); + //dm.placeholder(); } }); stylePanelItem = new MenuItem(editMenu, SWT.PUSH); @@ -432,7 +444,7 @@ nextElementItem.setEnabled(false); nextElementItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { - dm.placeholder(); + //dm.placeholder(); } }); assocSelectionItem = new MenuItem(editMenu, SWT.PUSH); @@ -440,7 +452,7 @@ assocSelectionItem.setEnabled(false); assocSelectionItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { - dm.placeholder(); + //dm.placeholder(); } }); lockSelectionItem = new MenuItem(editMenu, SWT.PUSH); @@ -448,7 +460,7 @@ lockSelectionItem.setEnabled(false); lockSelectionItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { - dm.placeholder(); + //dm.placeholder(); } }); unlockSelectionItem = new MenuItem(editMenu, SWT.PUSH); @@ -456,7 +468,7 @@ unlockSelectionItem.setEnabled(false); unlockSelectionItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { - dm.placeholder(); + //dm.placeholder(); } }); editLockedItem = new MenuItem(editMenu, SWT.PUSH); @@ -464,7 +476,7 @@ editLockedItem.setEnabled(false); editLockedItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { - dm.placeholder(); + //dm.placeholder(); } }); keybdBrlToggleItem = new MenuItem(editMenu, SWT.PUSH); @@ -472,7 +484,7 @@ keybdBrlToggleItem.setEnabled(false); keybdBrlToggleItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { - dm.placeholder(); + //dm.placeholder(); } }); /** @@ -497,21 +509,23 @@ editItem.setEnabled(true); // Set up view menu - Menu viewMenu = new Menu(dm.documentWindow, SWT.DROP_DOWN); + Menu viewMenu = new Menu(wp.getShell(), SWT.DROP_DOWN); increaseFontSizeItem = new MenuItem(viewMenu, SWT.PUSH); - increaseFontSizeItem.setText(lh.localValue("&IncreaseFontSize"));+ increaseFontSizeItem.setText(lh.localValue("&IncreaseFontSize") + "\tCtrl + '+'");
+ increaseFontSizeItem.setAccelerator(SWT.MOD1 + '+'); increaseFontSizeItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { -// dm.placeholder(); - dm.increaseFont(); + int index = wp.getFolder().getSelectionIndex(); + FontManager.increaseFont(wp, wp.getList().get(index)); } }); decreaseFontSizeItem = new MenuItem(viewMenu, SWT.PUSH); - decreaseFontSizeItem.setText(lh.localValue("&DecreaseFintSize"));+ decreaseFontSizeItem.setText(lh.localValue("&DecreaseFontSize") + "\tCtrl + '-'");
+ decreaseFontSizeItem.setAccelerator(SWT.MOD1 + '-'); decreaseFontSizeItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { -// dm.placeholder(); - dm.decreaseFont(); + int index = wp.getFolder().getSelectionIndex(); + FontManager.decreaseFont(wp, wp.getList().get(index)); } }); increaseContrastItem = new MenuItem(viewMenu, SWT.PUSH); @@ -519,7 +533,7 @@ increaseContrastItem.setEnabled(false); increaseContrastItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { - dm.placeholder(); + //dm.placeholder(); } }); decreaseContrastItem = new MenuItem(viewMenu, SWT.PUSH); @@ -527,7 +541,7 @@ decreaseContrastItem.setEnabled(false); decreaseContrastItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { - dm.placeholder(); + //dm.placeholder(); } }); showOutlineItem = new MenuItem(viewMenu, SWT.PUSH); @@ -535,7 +549,7 @@ showOutlineItem.setEnabled(false); showOutlineItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { - dm.placeholder(); + //dm.placeholder(); } }); /** @@ -567,12 +581,12 @@ viewItem.setMenu(viewMenu); // Set up translate menu - Menu translateMenu = new Menu(dm.documentWindow, SWT.DROP_DOWN); + Menu translateMenu = new Menu(wp.getShell(), SWT.DROP_DOWN); xtranslateItem = new MenuItem(translateMenu, SWT.PUSH); xtranslateItem.setText(lh.localValue("&Translate")); xtranslateItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { - dm.translateView(true); + //dm.translateView(true); } }); backTranslateItem = new MenuItem(translateMenu, SWT.PUSH); @@ -580,7 +594,7 @@ backTranslateItem.setEnabled(false); backTranslateItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { - dm.placeholder(); + //dm.placeholder(); } }); translationTemplatesItem = new MenuItem(translateMenu, SWT.PUSH); @@ -588,58 +602,58 @@ .setText(lh.localValue("&TranslationTemplates")); translationTemplatesItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { - dm.placeholder(); + //dm.placeholder(); } }); translateItem.setMenu(translateMenu); // Set up insert menu - Menu insertMenu = new Menu(dm.documentWindow, SWT.DROP_DOWN); + Menu insertMenu = new Menu(wp.getShell(), SWT.DROP_DOWN); inLineMathItem = new MenuItem(insertMenu, SWT.PUSH); inLineMathItem.setText(lh.localValue("&InLineMath")); inLineMathItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { - dm.placeholder(); + //dm.placeholder(); } }); displayedMathItem = new MenuItem(insertMenu, SWT.PUSH); displayedMathItem.setText(lh.localValue("&DisplayedMath")); displayedMathItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { - dm.placeholder(); + //dm.placeholder(); } }); inLineGraphicItem = new MenuItem(insertMenu, SWT.PUSH); inLineGraphicItem.setText(lh.localValue("&InLineGraphic")); inLineGraphicItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { - dm.placeholder(); + //dm.placeholder(); } }); displayedGraphicItem = new MenuItem(insertMenu, SWT.PUSH); displayedGraphicItem.setText(lh.localValue("&DisplayedGraphic")); displayedGraphicItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { - dm.placeholder(); + //dm.placeholder(); } }); tableItem = new MenuItem(insertMenu, SWT.PUSH); tableItem.setText(lh.localValue("&Table")); tableItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { - dm.placeholder(); + //dm.placeholder(); } }); insertItem.setMenu(insertMenu); // Set up advanced menu - Menu advancedMenu = new Menu(dm.documentWindow, SWT.DROP_DOWN); + Menu advancedMenu = new Menu(wp.getShell(), SWT.DROP_DOWN); brlFormatItem = new MenuItem(advancedMenu, SWT.PUSH); brlFormatItem.setText(lh.localValue("&BrailleFormat")); brlFormatItem.setEnabled(false); brlFormatItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { - dm.placeholder(); + //dm.placeholder(); } }); brailleASCIIItem = new MenuItem(advancedMenu, SWT.PUSH); @@ -647,17 +661,16 @@ brailleASCIIItem.setEnabled(false); brailleASCIIItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { - dm.placeholder(); + //dm.placeholder(); } }); showTranslationTemplatesItem = new MenuItem(advancedMenu, SWT.PUSH); - showTranslationTemplatesItem.setText(lh - .localValue("&ShowTranslationTemplates"));+ showTranslationTemplatesItem.setText(lh.localValue("&ShowTranslationTemplates"));
showTranslationTemplatesItem.setEnabled(false); showTranslationTemplatesItem .addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { - dm.placeholder(); + //dm.placeholder(); } }); showFormatTemplatesItem = new MenuItem(advancedMenu, SWT.PUSH); @@ -665,7 +678,7 @@ showFormatTemplatesItem.setEnabled(false); showFormatTemplatesItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { - dm.placeholder(); + //dm.placeholder(); } }); changeSettingsItem = new MenuItem(advancedMenu, SWT.PUSH); @@ -678,7 +691,7 @@ advancedItem.setMenu(advancedMenu); // Set up help menu - Menu helpMenu = new Menu(dm.documentWindow, SWT.DROP_DOWN); + Menu helpMenu = new Menu(wp.getShell(), SWT.DROP_DOWN); aboutItem = new MenuItem(helpMenu, SWT.PUSH); aboutItem.setText(lh.localValue("&About")); aboutItem.addSelectionListener(new SelectionAdapter() { @@ -718,6 +731,6 @@ helpItem.setMenu(helpMenu); // Activate menus when documentWindow shell is opened - dm.documentWindow.setMenuBar(menuBar); + wp.getShell().setMenuBar(menuBar); } } =======================================--- /src/main/org/brailleblaster/wordprocessor/BBToolBar.java Fri Aug 31 04:10:32 2012 +++ /src/main/org/brailleblaster/wordprocessor/BBToolBar.java Wed Jan 23 08:02:41 2013
@@ -1,30 +1,30 @@ /* BrailleBlaster Braille Transcription Application - * - * Copyright (C) 2010, 2012 - * ViewPlus Technologies, Inc. www.viewplus.com - * and - * Abilitiessoft, Inc. www.abilitiessoft.com - * All rights reserved - * - * This file may contain code borrowed from files produced by various - * Java development teams. These are gratefully acknoledged. - * - * This file is free software; you can redistribute it and/or modify it - * under the terms of the Apache 2.0 License, as given at - * http://www.apache.org/licenses/ - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE - * See the Apache 2.0 License for more details. - * - * You should have received a copy of the Apache 2.0 License along with - * this program; see the file LICENSE. - * If not, see - * http://www.apache.org/licenses/ - * - * Maintained by John J. Boyer john.boyer@xxxxxxxxxxxxxxxxx -*/ + * + * Copyright (C) 2010, 2012 + * ViewPlus Technologies, Inc. www.viewplus.com + * and + * Abilitiessoft, Inc. www.abilitiessoft.com + * All rights reserved + * + * This file may contain code borrowed from files produced by various + * Java development teams. These are gratefully acknoledged. + * + * This file is free software; you can redistribute it and/or modify it + * under the terms of the Apache 2.0 License, as given at + * http://www.apache.org/licenses/ + * + * This file is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE + * See the Apache 2.0 License for more details. + * + * You should have received a copy of the Apache 2.0 License along with + * this program; see the file LICENSE. + * If not, see + * http://www.apache.org/licenses/ + * + * Maintained by John J. Boyer john.boyer@xxxxxxxxxxxxxxxxx + */ package org.brailleblaster.wordprocessor; @@ -36,104 +36,102 @@ import org.eclipse.swt.layout.FormAttachment; import org.eclipse.swt.layout.FormData; import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.ToolBar; import org.eclipse.swt.widgets.ToolItem; public class BBToolBar { -private ToolBar toolBar; + private ToolBar toolBar; -// FO -public BBToolBar (final DocumentManager dm) { -LocaleHandler lh = new LocaleHandler(); -toolBar = new ToolBar (dm.documentWindow, SWT.HORIZONTAL); -FormData location = new FormData(); -location.left = new FormAttachment(0); -location.right = new FormAttachment(50); -location.top = new FormAttachment (4); -toolBar.setLayoutData (location); -// FO -String tlabel; + // FO + public BBToolBar(Shell shell) { + LocaleHandler lh = new LocaleHandler(); + toolBar = new ToolBar(shell, SWT.HORIZONTAL); + FormData location = new FormData(); + location.left = new FormAttachment(0); + location.right = new FormAttachment(50); + location.top = new FormAttachment(4); + toolBar.setLayoutData(location); + // FO + String tlabel; -ToolItem openItem = new ToolItem (toolBar, SWT.PUSH); -tlabel = lh.localValue ("&Open"); -openItem.setText (tlabel.replace("&", "")); -openItem.addSelectionListener (new SelectionAdapter() { - public void widgetSelected (SelectionEvent e) { - if (BBIni.debugging()) { - dm.setReturn (WP.OpenDocumentGetFile); - } else { - dm.fileOpen(); - } - } -}); + ToolItem openItem = new ToolItem(toolBar, SWT.PUSH); + tlabel = lh.localValue("&Open"); + openItem.setText(tlabel.replace("&", "")); + openItem.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + if (BBIni.debugging()) { + // dm.setReturn (WP.OpenDocumentGetFile); + } + else { + // dm.fileOpen(); + } + } + }); -ToolItem saveItem = new ToolItem (toolBar, SWT.PUSH); -//FO -tlabel = lh.localValue ("&Save"); -saveItem.setText (tlabel.replace("&","")); -saveItem.addSelectionListener (new SelectionAdapter() { - public void widgetSelected (SelectionEvent e) { - dm.fileSave(); - } -}); + ToolItem saveItem = new ToolItem(toolBar, SWT.PUSH); + // FO + tlabel = lh.localValue("&Save"); + saveItem.setText(tlabel.replace("&", "")); + saveItem.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + // dm.fileSave(); + } + }); -ToolItem translateItem = new ToolItem (toolBar, SWT.PUSH); -// FO -tlabel = lh.localValue ("&Translate"); -translateItem.setText (tlabel.replace("&", "")); -// FO -translateItem.addSelectionListener (new SelectionAdapter() { - public void widgetSelected (SelectionEvent e) { - dm.translateView(true); - } -}); + ToolItem translateItem = new ToolItem(toolBar, SWT.PUSH); + // FO + tlabel = lh.localValue("&Translate"); + translateItem.setText(tlabel.replace("&", "")); + // FO + translateItem.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + // dm.translateView(true); + } + }); -ToolItem embossNow = new ToolItem (toolBar, SWT.PUSH); -// FO -tlabel = lh.localValue ("Emboss&Now!"); -embossNow.setText (tlabel.replace ("&", "")); -embossNow.addSelectionListener (new SelectionAdapter() { - public void widgetSelected (SelectionEvent e) { - dm.fileEmbossNow(); - } -}); + ToolItem embossNow = new ToolItem(toolBar, SWT.PUSH); + // FO + tlabel = lh.localValue("Emboss&Now!"); + embossNow.setText(tlabel.replace("&", "")); + embossNow.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + // dm.fileEmbossNow(); + } + }); -/** -ToolItem embossWithInk = new ToolItem (toolBar, SWT.PUSH); -tlabel = lh.localValue ("EmbossInkN&ow"); -embossWithInk.setText (tlabel.replace ("&", "")); -embossWithInk.setEnabled(false); -embossWithInk.addSelectionListener (new SelectionAdapter() { - public void widgetSelected (SelectionEvent e) { - dm.placeholder(); - } -}); -**/ + /** + * ToolItem embossWithInk = new ToolItem (toolBar, SWT.PUSH); tlabel = + * lh.localValue ("EmbossInkN&ow"); embossWithInk.setText + * (tlabel.replace ("&", "")); embossWithInk.setEnabled(false); + * embossWithInk.addSelectionListener (new SelectionAdapter() { public + * void widgetSelected (SelectionEvent e) { dm.placeholder(); } }); + **/ -ToolItem daisyPrint = new ToolItem (toolBar, SWT.PUSH); -tlabel = lh.localValue ("&Print"); -daisyPrint.setText (tlabel.replace ("&", "")); -daisyPrint.addSelectionListener (new SelectionAdapter() { - public void widgetSelected (SelectionEvent e) { - dm.daisyPrint(); - } -}); + ToolItem daisyPrint = new ToolItem(toolBar, SWT.PUSH); + tlabel = lh.localValue("&Print"); + daisyPrint.setText(tlabel.replace("&", "")); + daisyPrint.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + // dm.daisyPrint(); + } + }); -toolBar.pack(); + toolBar.pack(); -FormData bloc = new FormData(); -bloc.left = new FormAttachment(68); -bloc.right = new FormAttachment(78); -bloc.top = new FormAttachment (5); -Button checkBrailleItem = new Button (dm.documentWindow, SWT.CHECK); -checkBrailleItem.setLayoutData (bloc); -checkBrailleItem.setText (lh.localValue("viewBraille")); -checkBrailleItem.pack(); -checkBrailleItem.addSelectionListener (new SelectionAdapter() { - public void widgetSelected (SelectionEvent e) { - dm.toggleBrailleFont(); + FormData bloc = new FormData(); + bloc.left = new FormAttachment(68); + bloc.right = new FormAttachment(78); + bloc.top = new FormAttachment(5); + Button checkBrailleItem = new Button(shell, SWT.CHECK); + checkBrailleItem.setLayoutData(bloc); + checkBrailleItem.setText(lh.localValue("viewBraille")); + checkBrailleItem.pack(); + checkBrailleItem.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + // dm.toggleBrailleFont(); + } + }); } -}); -} } =======================================--- /src/main/org/brailleblaster/wordprocessor/CallOutsideWP.java Wed Nov 14 21:15:36 2012 +++ /src/main/org/brailleblaster/wordprocessor/CallOutsideWP.java Wed Jan 23 08:02:41 2013
@@ -35,14 +35,12 @@ * Make certain features available outside the word processor */ public class CallOutsideWP { - -public void showTutorial() { -new UserHelp (WP.ReadTutorial); -} - -public void showURL (String url) { -new UserHelp (url); -} + public void showTutorial() { + new UserHelp (WP.ReadTutorial); + } + public void showURL (String url) { + new UserHelp (url); + } } =======================================--- /src/main/org/brailleblaster/wordprocessor/DocumentManager.java Tue Jan 15 07:37:36 2013 +++ /src/main/org/brailleblaster/wordprocessor/DocumentManager.java Wed Jan 23 08:02:41 2013
@@ -31,118 +31,51 @@ package org.brailleblaster.wordprocessor; -import java.io.BufferedReader; + import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.FileReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; import java.util.logging.Level; import java.util.logging.Logger; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import javax.print.PrintException; -import javax.xml.parsers.ParserConfigurationException; - -import nu.xom.Builder; import nu.xom.Document; -import nu.xom.Element; -import nu.xom.Node; -import nu.xom.ParsingException; -import nu.xom.Serializer; -import nu.xom.Text; - -import org.apache.tika.Tika; -import org.apache.tika.exception.TikaException; -import org.apache.tika.io.TikaInputStream; -import org.apache.tika.metadata.Metadata; -import org.apache.tika.mime.MediaType; -import org.apache.tika.parser.AutoDetectParser; -import org.apache.tika.parser.ParseContext; -import org.apache.tika.parser.Parser; -import org.apache.tika.sax.ToXMLContentHandler; import org.brailleblaster.BBIni; import org.brailleblaster.abstractClasses.AbstractView; -import org.brailleblaster.importers.ImportersManager; -import org.brailleblaster.importers.XSLtransformer; +import org.brailleblaster.document.DocumentBase; import org.brailleblaster.localization.LocaleHandler; -import org.brailleblaster.printers.PrintersManager; -import org.brailleblaster.settings.Welcome; -import org.brailleblaster.util.FileUtils; -import org.brailleblaster.util.Notify; import org.brailleblaster.util.YesNoChoice; import org.brailleblaster.views.BrailleView; import org.brailleblaster.views.TextView; import org.brailleblaster.views.TreeView; -import org.daisy.printing.PrinterDevice; import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.StyledText; import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.graphics.FontData; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; import org.eclipse.swt.layout.FormLayout; -import org.eclipse.swt.layout.RowLayout; -import org.eclipse.swt.printing.PrintDialog; -import org.eclipse.swt.printing.PrinterData; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Listener; -import org.eclipse.swt.widgets.Menu; -import org.eclipse.swt.widgets.MenuItem; -import org.eclipse.swt.widgets.Monitor; import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.ToolBar; -import org.eclipse.swt.widgets.ToolItem; +import org.eclipse.swt.widgets.TabItem; import org.liblouis.liblouisutdml; -import org.xml.sax.SAXException; -enum Encodings {- ISO_8859_1("ISO-8859-1"), UTF_8("UTF-8"), WINDOWS_1252("WINDOWS-1252"), US_ASCII(
- "US-ASCII"); - - private final String encoding; - - Encodings(String encoding) { - this.encoding = encoding; - } - - public String encoding() { - return encoding; - } -} - -/** - * This class manages each document in an MDI environment. It controls the - * braille View and the daisy View. - */+//This class manages each document in an MDI environment. It controls the braille View and the daisy View.
public class DocumentManager { - final Display display; - final Shell documentWindow; - final int documentNumber; - final String docID; - int action; - int returnReason = 0; + //Shell shell; + WPManager wp; + TabItem item; + Group group; + BBStatusBar statusBar; + TreeView treeView; + TextView daisy; + BrailleView braille; FormLayout layout; + DocumentBase db; + static int docCount = 0; String documentName = null; boolean documentChanged = false; - BBToolBar toolBar; - BBMenu menu; RecentDocuments rd; UTD utd; - AbstractView activeView; - TextView daisy; - BrailleView braille; - TreeView treeView; - BBStatusBar statusBar; Document doc = null; NewDocument newDoc; String configFileList = null; @@ -156,1520 +89,89 @@ boolean textAndBraille = false; boolean saveUtdml = false; boolean metaContent = false; - liblouisutdml louisutdml; String logFile = "Translate.log"; String configSettings = null; - int mode = 0; - boolean finished = false; - private volatile boolean stopRequested = false; - static final boolean[] flags = new boolean[WPManager.getMaxNumDocs()]; - // static final String[] runningFiles = new - // String[WPManager.getMaxNumDocs()]; static String recentFileName = null; static int recentFileNameIndex = -1; - int numLines; - int numChars; - // FO - private Font simBrailleFont, daisyFont; - boolean displayBrailleFont = false; - int bvLineCount; - private boolean firstTime; - static int daisyFontHeight = 10; - static int brailleFontHeight = 14; - static boolean SimBraille = false; - static boolean Courier = false; - static String altFont = "unibraille29"; - static String courierFont = "Courier New"; LocaleHandler lh = new LocaleHandler(); - StringBuilder brailleLine = new StringBuilder(10000); - StringBuilder daisyLine = new StringBuilder(10000); - // character encoding for import - static String encoding = null; - static Logger logger; - - MediaType mediaType; - - final String[] compressed = { "application/zip", "application/epub+zip" }; - public boolean isNimas; - public boolean isEpub; - - /** - * Constructor that sets things up for a new document. - */ - DocumentManager(Display display, int documentNumber, int action, - String documentName) { - this.display = display; - this.documentNumber = documentNumber; - docID = new Integer(documentNumber).toString(); - this.action = action; - this.documentName = documentName; + + //Constructor that sets things up for a new document. + DocumentManager(WPManager wp, String docName) { + this.wp = wp; + this.db = new DocumentBase(); + //this.shell = wp.getShell(); + this.item = new TabItem(wp.getFolder(), 0); + this.group = new Group(wp.getFolder(),SWT.NONE); + this.group.setLayout(new FormLayout()); + + this.treeView = new TreeView(this.group); + this.daisy = new TextView(this.group); + this.braille = new BrailleView(this.group); + this.item.setControl(this.group); + this.doc = null; + tempPath = BBIni.getTempFilesPath() + BBIni.getFileSep(); louisutdml = liblouisutdml.getInstance(); - documentWindow = new Shell(display, SWT.SHELL_TRIM); - - // FO setup WP window - layout = new FormLayout(); - documentWindow.setLayout(layout); + + FontManager.setShellFonts(this.wp.getShell(), this); + rd = new RecentDocuments(this); utd = new UTD(this); - menu = new BBMenu(this); - toolBar = new BBToolBar(this); - /* text window is on the left */ - daisy = new TextView(documentWindow); - braille = new BrailleView(documentWindow); - treeView = new TreeView(documentWindow); logger = BBIni.getLogger(); - - // activeView = (ProtoView)daisy; - statusBar = new BBStatusBar(documentWindow); - documentWindow.setSize(1000, 700); - documentWindow.layout(true, true); - - documentWindow.addListener(SWT.Close, new Listener() { - public void handleEvent(Event event) { - setReturn(WP.DocumentClosed); - // this way clicking close box is equivalent to the 'close' item - // on the menu - } - }); - - documentWindow.addListener(SWT.Dispose, new Listener() { - public void handleEvent(Event event) { - handleShutdown(event); - } - }); - - Monitor primary = display.getPrimaryMonitor(); - Rectangle bounds = primary.getBounds(); - Rectangle rect = documentWindow.getBounds(); - int x = bounds.x + ((bounds.width - rect.width) / 2) - + (documentNumber * 30); - int y = bounds.y + ((bounds.height - rect.height) / 2) - + (documentNumber * 30); - documentWindow.setLocation(x, y); - documentWindow.open(); - setWindowTitle(" untitled"); - - // daisy.view.addModifyListener(daisyMod); - /** - * for later use braille.view.addModifyListener(brailleMod); - **/ - // + FO - /* Find out which scalable fonts are installed */ - FontData[] fd = documentWindow.getDisplay().getFontList(null, true); - String fn; - - for (int i = 0; i < fd.length; i++) { - fn = fd[i].getName(); - if (fn.contentEquals("SimBraille")) { - SimBraille = true; - break; - } - ; - if (fn.contentEquals(courierFont)) { - Courier = true; - break; - } - ; + docCount++; + + if(docName != null){ + openDocument(docName); } - - if (!SimBraille) { - String fontPath = BBIni.getBrailleblasterPath() - + "/programData/fonts/SimBraille.ttf"; - String platform = SWT.getPlatform(); - if (platform.equals("win32") || platform.equals("wpf")) { - fontPath = BBIni.getBrailleblasterPath() - + "\\programData\\fonts\\SimBraille.ttf"; - } - if (!documentWindow.getDisplay().loadFont(fontPath)) { - new Notify(lh.localValue("fontNotLoadedBraille")); - } + else{ + setTabTitle(docName); } - - if (Courier) { - daisyFont = new Font(documentWindow.getDisplay(), courierFont, - daisyFontHeight, SWT.NORMAL); - } else { - - String fontPath = BBIni.getBrailleblasterPath() - + "/programData/fonts/" + altFont + ".ttf"; - String platform = SWT.getPlatform(); - if (platform.equals("win32") || platform.equals("wpf")) { - fontPath = BBIni.getBrailleblasterPath() - + "\\programData\\fonts\\" + altFont + ".ttf"; - } - if (!documentWindow.getDisplay().loadFont(fontPath)) { - new Notify(lh.localValue("fontNotLoadedText")); - } - daisyFont = new Font(documentWindow.getDisplay(), altFont, - daisyFontHeight, SWT.NORMAL); - } - - daisy.view.setFont(daisyFont); - braille.view.setFont(daisyFont); - braille.view.setEditable(false); - - if (documentNumber == 0) { - new Welcome(); // This then calls the settings dialogs. - } - - String loc = lh.getLocale().toString(); - if (!loc.contentEquals(lh.localValue("localeResource"))) { - logger.log(Level.WARNING, "Locale resource for " + loc - + " not found. Using default."); - // System.err.println("Locale resource for '" + - // lh.getLocale().getDisplayName() + - // "' not found. Using default."); - // new Notify("Locale resource for '" + - // lh.getLocale().getDisplayName() + "' not found."); - } - - switch (action) { - case WP.OpenDocumentGetFile: - fileOpen(); - break; - case WP.DocumentFromCommandLine: - openDocument(documentName); - break; - case WP.OpenDocumentGetRecent: - // FO 04 - String ext = getFileExt(documentName); - String arcType = archiveType(documentName); - if (ext.contentEquals("utd") || ext.contentEquals("xml")) { - brailleFileName = getBrailleFileName(); - openDocument(documentName); - if (ext.contentEquals("utd")) { - // BBIni.setUtd(true); - utd.displayTranslatedFile(documentName, brailleFileName); - braille.hasChanged = false; - } - daisy.hasChanged = false; - } else if (arcType != null) { - importZip(arcType); - daisy.hasChanged = true; - - } else { - if (ext.contentEquals("brf")) { - openBrf(documentName); - setWindowTitle("untitled"); - } else { - parseImport(documentName, getEncodingString()); - setWindowTitle(documentName); - } - daisy.hasChanged = true; - } - daisy.view.setFocus(); - break; - - case WP.ImportDocument: - importDocument(); - break; - } - - boolean stop = false; - daisy.view.setFocus(); - - while (!documentWindow.isDisposed() && (!stop) && (returnReason == 0)) { - if (!display.readAndDispatch()) - display.sleep(); - for (boolean b : flags) { - stop |= b; - } - } - // get here if the window is disposed, or someone has a reason - if (flags[documentNumber]) { - WPManager.setCurDoc(documentNumber); - flags[documentNumber] = false; // all should be false now - } - // Then back to WPManager + } - /** - * Handle application shutdown signal from OS; - */ - void handleShutdown(Event event) { - if (daisy.hasChanged) { - YesNoChoice ync = new YesNoChoice(lh.localValue("hasChanged")); - if (ync.result == SWT.YES) { - fileSave(); - } else { - daisy.hasChanged = false; - braille.hasChanged = false; - } - } - event.doit = true; + public void fileSave(){ + System.out.println("File save occurs"); } + + public void fileOpenDialog(WPManager wp){ + String tempName; - /** - * Clean up before closing the document. - */ - void finish() { - documentWindow.dispose(); - finished = true; - } - - /** - * Checks if a return request is valid and does any necessary processing. - */ - boolean setReturn(int reason) { - switch (reason) { - case WP.SwitchDocuments: - if (WPManager.haveOtherDocuments()) { - // System.out.println("Switching to next"); - returnReason = reason; - flags[documentNumber] = true;// this fires the interrupt - return true; - } - new Notify(lh.localValue("oneDocument")); - return false; - case WP.NewDocument: - returnReason = reason; - break; - case WP.OpenDocumentGetFile: - returnReason = reason; - break; - case WP.DocumentClosed: - returnReason = reason; - break; - case WP.BBClosed: - returnReason = reason; - break; - default: - break; - } - WPManager.setCurDoc(documentNumber); // FO 27 - flags[documentNumber] = true;// this fires the interrupt - return true; - } - - /**- * This method is called to resume processing on this document after working
- * on another. - */ - void resume() { - if (documentWindow.isDisposed()) - return; - documentWindow.forceActive(); - boolean stop = false; - while (!documentWindow.isDisposed() && (!stop)) { - if (!documentWindow.getDisplay().readAndDispatch()) - documentWindow.getDisplay().sleep(); - for (boolean b : DocumentManager.getflags()) { - stop |= b; - } - } - } - - private void setWindowTitle(String pathName) { - int index = pathName.lastIndexOf(File.separatorChar); - if (index == -1) { - documentWindow.setText("BrailleBlaster " + pathName); - } else { - documentWindow.setText("BrailleBlaster " - + pathName.substring(index + 1)); - } - } - - void fileDocument() { - newDoc = new NewDocument(); - newDoc.fillOutBody(daisy.view); - doc = newDoc.getDocument(); - } - - void fileNew() { - // FO - if (!daisy.view.isVisible()) { - activateViews(true); - activateMenus(true); - daisy.hasChanged = false; - braille.hasChanged = false; - haveOpenedFile = false; - brailleFileName = null; - documentName = null; - daisy.hasChanged = false; - braille.hasChanged = false; - doc = null; - // BBIni.setUtd(false); - setWindowTitle(" untitled"); - daisy.view.setFocus(); - } else { - - // if (doc != null){ - returnReason = WP.NewDocument; - flags[documentNumber] = true; - // return; - // } - } - } - - void fileOpen() { - - if (!daisy.view.isVisible()) { - activateViews(true); - activateMenus(true); - daisy.hasChanged = false; - braille.hasChanged = false; - haveOpenedFile = false; - brailleFileName = null; - documentName = null; - daisy.hasChanged = false; - braille.hasChanged = false; - doc = null; - setWindowTitle(" untitled"); - daisy.view.setFocus(); - } - ; - - if ((doc != null) || daisy.hasChanged) { - returnReason = WP.OpenDocumentGetFile; - flags[documentNumber] = true; - return; - } - haveOpenedFile = false; - metaContent = false; - - Shell shell = new Shell(display, SWT.DIALOG_TRIM); - FileDialog dialog = new FileDialog(shell, SWT.OPEN); + FileDialog dialog = new FileDialog(this.wp.getShell(), SWT.OPEN); String filterPath = "/"; - String[] filterNames = new String[] { "XML", "TEXT", "BRF", - "UTDML working document", }; - String[] filterExtensions = new String[] { "*.xml", "*.txt", "*.brf", - "*.utd", };+ String[] filterNames = new String[] { "XML", "TEXT", "BRF", "UTDML working document", }; + String[] filterExtensions = new String[] { "*.xml", "*.txt", "*.brf", "*.utd", };
String platform = SWT.getPlatform(); if (platform.equals("win32") || platform.equals("wpf")) { filterPath = System.getProperty("user.home"); - if (filterPath == null) + if (filterPath == null){ filterPath = "c:\\"; - } - dialog.setFilterNames(filterNames); - dialog.setFilterExtensions(filterExtensions); - dialog.setFilterPath(filterPath); - - documentName = dialog.open(); - shell.dispose(); - - if (documentName != null) { - openDocument(documentName); - String ext = getFileExt(documentName); - if (ext.contentEquals("utd")) { - metaContent = true; - haveOpenedFile = true; - brailleFileName = getBrailleFileName(); - utd.displayTranslatedFile(documentName, brailleFileName); } - braille.view.setEditable(false); - daisy.hasChanged = false; - braille.hasChanged = false; - // daisy.view.addModifyListener(daisyMod); - setWindowTitle(documentName); - daisy.view.setFocus(); } - } - - void recentOpen(String path) { - - if (!daisy.view.isVisible()) { - activateViews(true); - activateMenus(true); - daisy.hasChanged = false; - braille.hasChanged = false; - haveOpenedFile = false; - brailleFileName = null; - documentName = null; - daisy.hasChanged = false; - braille.hasChanged = false; - doc = null; - // BBIni.setUtd(false); - } - - if (doc != null) { - // see if this recent document is already opened in current windows - // set - recentFileNameIndex = WPManager.isRunning(path); - if (recentFileNameIndex != -1) { - returnReason = WP.SwitchDocuments; - flags[documentNumber] = true; - return; - } - recentFileName = path; - returnReason = WP.OpenDocumentGetRecent; - flags[documentNumber] = true; - return; - } - documentName = path; - braille.view.setEditable(false); - - String ext = getFileExt(documentName); - String arcType = archiveType(documentName); - if (ext.contentEquals("utd") || ext.contentEquals("xml")) { - brailleFileName = getBrailleFileName(); - openDocument(documentName); - if (ext.contentEquals("utd")) { - // BBIni.setUtd(true); - utd.displayTranslatedFile(documentName, brailleFileName); - braille.hasChanged = false; - } - - daisy.hasChanged = false; - - } else if (arcType != null) { - importZip(arcType); - } else { - if (ext.contentEquals("brf")) { - openBrf(documentName); - setWindowTitle("untitled"); - } else { - parseImport(documentName, getEncodingString()); - setWindowTitle(documentName); - } - } - daisy.view.setFocus(); - } - - void openDocument(String fileName) { - - stopRequested = false; - - Builder parser = new Builder(); - try { - doc = parser.build(new File(fileName)); - } catch (ParsingException e) { - new Notify(lh.localValue("malformedDocument")); - return; - } catch (IOException e) { - new Notify(lh.localValue("couldNotOpen") + " " + fileName); - return; - } - // add this file to recentDocList - if (!((fileName.contains("-tempdoc.xml")) || (fileName - .contains(tempPath)))) { - rd.addDocument(fileName); - } - if ((getFileExt(fileName).contentEquals("brf")) - || (getFileExt(fileName).contentEquals("brl"))) { - setWindowTitle("untitled"); - } else { - setWindowTitle(fileName); - haveOpenedFile = true; - } - numLines = 0; - numChars = 0; - statusBar.setText(lh.localValue("loadingDocument") + " " + fileName); - daisyLine.delete(0, daisyLine.length()); - - final Element rootElement = doc.getRootElement();// this needs to be - // final, because it - // will be used by a - // different thread - - new Thread() { - public void run() { - while (!stopRequested) { - walkTree(rootElement); - } - } - }.start(); - } - - private void walkTree(Node node) { - Node newNode; - - for (int i = 0; i < node.getChildCount(); i++) { - newNode = node.getChild(i); - - if (newNode instanceof Element) { - walkTree(newNode); - } else if (newNode instanceof Text) { - String nname = ((Element) node).getLocalName(); - if (!(nname.matches("span") || nname.matches("brl") - || nname.matches("body") || nname.matches("title"))) { - final String value = newNode.getValue(); - numLines++; - numChars += value.length(); - - daisyLine.append(value + '\n'); - } - - // the main thread gets to execute the block inside syncExec() - if (daisyLine.length() > 8192 || i == node.getChildCount() - 1) { - display.syncExec(new Runnable() { - public void run() { - daisy.view.append(daisyLine.toString()); - statusBar.setText("Read " + numLines + " lines, " - + numChars + " characters."); - } - }); - daisyLine.delete(0, daisyLine.length()); - daisy.hasChanged = false; - } - } - } - stopRequested = true; - } - - void openTikaDocument(String fileName) { - stopRequested = false; - - Builder parser = new Builder(); - try { - doc = parser.build(new File(fileName)); - - } catch (ParsingException e) { - logger.log(Level.SEVERE, - lh.localValue("malformedDocument: " + fileName)); - logger.log(Level.INFO, e.getMessage()); - - new Notify(lh.localValue("malformedDocument") + "\n" + fileName); - // e.getStackTrace(); - return; - } catch (IOException e) { - new Notify(lh.localValue("couldNotOpen") + " " + fileName); - return; - } - - statusBar.setText(lh.localValue("loadingDocument") + " " + fileName); - final Element rootElement = doc.getRootElement();// this needs to be - // final - - // use thread only for single-file documents - if (!(isNimas || isEpub)) { - new Thread() { - public void run() { - while (!stopRequested) { - walkTikaTree(rootElement); - } - } - }.start(); - } else { - while (!stopRequested) { - walkTikaTree(rootElement); - } - } - } - - private void walkTikaTree(Node node) { - Node newNode; - - String tags[] = { "title", "p", "i", "b", "u", "strong", "span" }; - - for (int i = 0; i < node.getChildCount(); i++) { - newNode = node.getChild(i); - - if (newNode instanceof Element) { - walkTikaTree(newNode); // down one level - } else if (newNode instanceof Text) { - - String nname = ((Element) node).getLocalName(); - - Boolean match = false; - int j = 0; - while (!match && (j < tags.length)) { - if (nname.matches(tags[j++])) - match = true; - } - if (match) { - String value = newNode.getValue() + "\n"; - - // replace Unicode with matching codepoints - Matcher matcher = Pattern.compile( - "\\\\u((?i)[0-9a-fA-F]{4})").matcher(value); - StringBuffer sb = new StringBuffer(); - int codepoint; - while (matcher.find()) { - codepoint = Integer.valueOf(matcher.group(1), 16); - matcher.appendReplacement(sb, - String.valueOf((char) codepoint)); - } - matcher.appendTail(sb); - value = sb.toString(); - - numLines++; - numChars += value.length(); - - daisyLine.append(value); - } - ; - - if (daisyLine.length() > 4096 || i == node.getChildCount() - 1) { - display.syncExec(new Runnable() { - public void run() { - daisy.view.append(daisyLine.toString()); - statusBar.setText("Read " + numChars - + " characters."); - } - }); - - daisyLine.delete(0, daisyLine.length()); - } - } - } - stopRequested = true; - } - - void fileSave() { - if (!(daisy.hasChanged || braille.hasChanged)) { - new Notify(lh.localValue("noChange")); - return; - } - - String ext = ""; - if (documentName != null) - ext = getFileExt(documentName); - - /** no open file then do a Save As **/ - if ((!haveOpenedFile) || ext.contentEquals("xml")) { - fileSaveAs(); - } else { - saveDaisyWorkFile(); - String fileName = new File(documentName).getName(); - statusBar.setText(lh.localValue("savingFile") + " " + fileName); - - /* save utdml file */ - if (!metaContent) { - System.out.println(fileName + " " - + lh.localValue("saveTextOnly")); - new FileUtils().copyFile(daisyWorkFile, documentName); - statusBar.setText(lh.localValue("fileSaved")); - new Notify(lh.localValue("fileSaved")); - } else if (translatedFileName != null) { - YesNoChoice ync = new YesNoChoice( - lh.localValue("confirmTranslationSaved")); - if (ync.result == SWT.YES) { - // System.out.println(fileName + " " + - // lh.localValue("saveTextBraille")); - new FileUtils().copyFile(translatedFileName, documentName); - statusBar.setText(lh.localValue("fileSaved")); - new Notify(lh.localValue("fileSaved")); - daisy.hasChanged = false; - braille.hasChanged = false; - } else { - new Notify(lh.localValue("noChangeSaved")); - } - - } else { - fileSaveAs(); - } - } - } - - void fileSaveAs() { - // FO - if (daisyWorkFile == null) { - /* create the utd text file */ - saveDaisyWorkFile(); - } - - textAndBraille = false; - saveUtdml = false; - - /* dialog asking for the type of UTDML file to save */ - - if (braille.view.getCharCount() != 0) { - SaveOptionsDialog saveChoice = new SaveOptionsDialog(documentWindow); - saveChoice.setText(lh.localValue("optionSelect")); - SaveSelection result = saveChoice.open(); - if (result.equals(SaveSelection.TEXT_AND_BRAILLE)) { - textAndBraille = true; - } else if (result.equals(SaveSelection.CANCELLED)) { - return; - } - saveUtdml = true; - } - - Shell shell = new Shell(display); - FileDialog dialog = new FileDialog(shell, SWT.SAVE); - String filterPath = System.getProperty("user.home"); - // FO 04 - String[] filterNames = null; - String[] filterExtensions = null; - if (textAndBraille) { - filterNames = new String[] { "UTDML file" }; - filterExtensions = new String[] { "*.utd" }; - } else { - filterNames = new String[] { "XML file" }; - filterExtensions = new String[] { "*.xml" }; - } - - String platform = SWT.getPlatform(); - if (platform.equals("win32") || platform.equals("wpf")) { - if (filterPath == null) - filterPath = "c:\\"; - } - dialog.setFilterPath(filterPath); - dialog.setFilterNames(filterNames); - dialog.setFilterExtensions(filterExtensions); - - if (haveOpenedFile) { - int i = documentName.lastIndexOf("."); - String fn = documentName.substring(0, i); - if (getFileExt(documentName).contentEquals("xml")) { - if (textAndBraille) - documentName = fn + ".utd"; - else - documentName = fn + ".xml"; - } - dialog.setFileName(documentName); - } else { - if (documentName != null) { - if (getFileExt(documentName).contentEquals("brf")) { - saveDaisyWorkFile(); - int i = documentName.lastIndexOf("."); - String fn = documentName.substring(0, i); - newDaisyFile = fn + ".xml"; - } - } - dialog.setFileName(newDaisyFile); - } - - String saveTo = dialog.open(); - shell.dispose(); - if (saveTo == null) { - return; - } - - String fileName = new File(saveTo).getName(); - statusBar.setText(lh.localValue("savingFile") + " " + fileName); - - /* text and braille utd */ - if (textAndBraille) { - if (translatedFileName == null) { - new Notify(lh.localValue("noXlation")); - return; - } - - new FileUtils().copyFile(translatedFileName, saveTo); - - } else { - new FileUtils().copyFile(daisyWorkFile, saveTo); - } - - // add this file to recentDocList - rd.addDocument(saveTo); - statusBar.setText(lh.localValue("fileSaved") + " " + saveTo); - documentWindow.setText("BrailleBlaster " + fileName); - - if (!textAndBraille) { - translatedFileName = null; - braille.view.replaceTextRange(0, braille.view.getCharCount(), ""); - } - daisy.hasChanged = false; - braille.hasChanged = false; - } - - void fileClose() { - if (daisy.view == null) { - logger.log(Level.SEVERE, "fileCLose() - something wrong!!!"); - // System.err.println("fileCLose() - something wrong!!!"); - return; - } - activateMenus(false); - if (daisy.hasChanged || braille.hasChanged) { - YesNoChoice ync = new YesNoChoice(lh.localValue("hasChanged")); - if (ync.result == SWT.YES) { - fileSave(); - } - } - activateViews(false); - haveOpenedFile = false; - brailleFileName = null; - documentName = null; - doc = null; - // BBIni.setUtd(false); ***The diff for this file has been truncated for email.*** =======================================--- /src/main/org/brailleblaster/wordprocessor/NewDocument.java Mon Aug 27 15:58:46 2012 +++ /src/main/org/brailleblaster/wordprocessor/NewDocument.java Wed Jan 23 08:02:41 2013
@@ -1,30 +1,30 @@ /* BrailleBlaster Braille Transcription Application - * - * Copyright (C) 2010, 2012 - * ViewPlus Technologies, Inc. www.viewplus.com - * and - * Abilitiessoft, Inc. www.abilitiessoft.com - * All rights reserved - * - * This file may contain code borrowed from files produced by various - * Java development teams. These are gratefully acknoledged. - * - * This file is free software; you can redistribute it and/or modify it - * under the terms of the Apache 2.0 License, as given at - * http://www.apache.org/licenses/ - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE - * See the Apache 2.0 License for more details. - * - * You should have received a copy of the Apache 2.0 License along with - * this program; see the file LICENSE. - * If not, see - * http://www.apache.org/licenses/ - * - * Maintained by John J. Boyer john.boyer@xxxxxxxxxxxxxxxxx -*/ + * + * Copyright (C) 2010, 2012 + * ViewPlus Technologies, Inc. www.viewplus.com + * and + * Abilitiessoft, Inc. www.abilitiessoft.com + * All rights reserved + * + * This file may contain code borrowed from files produced by various + * Java development teams. These are gratefully acknoledged. + * + * This file is free software; you can redistribute it and/or modify it + * under the terms of the Apache 2.0 License, as given at + * http://www.apache.org/licenses/ + * + * This file is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE + * See the Apache 2.0 License for more details. + * + * You should have received a copy of the Apache 2.0 License along with + * this program; see the file LICENSE. + * If not, see + * http://www.apache.org/licenses/ + * + * Maintained by John J. Boyer john.boyer@xxxxxxxxxxxxxxxxx + */ package org.brailleblaster.wordprocessor; @@ -34,133 +34,129 @@ import org.eclipse.swt.custom.StyledText; class NewDocument { -Element headAdd; -Element sectionAdd; -Element frontAdd; -Element bodyAdd; -Element rearAdd; + Element headAdd; + Element sectionAdd; + Element frontAdd; + Element bodyAdd; + Element rearAdd; -private final String framework = -"<?xml version='1.0' encoding='utf-8'?>" -+ "<document " -+ "profile='http://www.daisy.org/z3986/2011/vocab/profiles/default/' " -+ "prefix='' xml:lang='' " -+ "xmlns='http://www.daisy.org/ns/z3986/authoring/' " -+ "xmlns:its='http://www.w3.org/2005/11/its' " -+ "xmlns:ssml='http://www.w3.org/2001/10/synthesis' " -+ "xmlns:xforms='http://www.w3.org/2002/xforms/' " -+ "xmlns:m='http://www.w3.org/1998/Math/MathML' " -+ "xmlns:sel='http://www.daisy.org/ns/z3986/authoring/features/select/' " -+ "xmlns:rend='http://www.daisy.org/ns/z3986/authoring/features/rend/'>" -+ "<head>" -+ "<meta rel='z3986:profile' " -+ "resource='http://www.daisy.org/z3986/2011/auth/profiles/genericdocument/0.7/'>" -+ "<meta rel='z3986:feature' " -+ "resource='http://www.daisy.org/z3986/2011/auth/features/its-ruby/0.6/'/>" -+ "<meta rel='z3986:feature' " -+ "resource='http://www.daisy.org/z3986/2011/auth/features/ssml/0.5/'/>" -+ "<meta rel='z3986:feature' " -+ "resource='http://www.daisy.org/z3986/2011/auth/features/forms/0.4/'/>" -+ "<meta rel='z3986:feature' " -+ "resource='http://www.daisy.org/z3986/2011/auth/features/mathml/0.4/'/>" -+ "<meta rel='z3986:feature' " -+ "resource='http://www.daisy.org/z3986/2011/auth/features/select/0.4/'/>" -+ "<meta rel='z3986:feature' " -+ "resource='http://www.daisy.org/z3986/2011/auth/features/rend/0.6/'/>" -+ "<meta rel='z3986:feature' " -+ "resource='http://www.daisy.org/z3986/2011/auth/features/svg-cdr/0.2/'/>" -+ "</meta>" -+ "<meta property='dcterms:identifier' content=''/>" -+ "<meta property='dcterms:publisher' content=''/>" -+ "<meta property='dcterms:modified' content=''/>" -+ "</head>" -+ "<body>" -+ "<section/>" -+ "</body>" -+ "</document>"; + private final String framework = "<?xml version='1.0' encoding='utf-8'?>" + + "<document " + + "profile='http://www.daisy.org/z3986/2011/vocab/profiles/default/' " + + "prefix='' xml:lang='' " + + "xmlns='http://www.daisy.org/ns/z3986/authoring/' " + + "xmlns:its='http://www.w3.org/2005/11/its' " + + "xmlns:ssml='http://www.w3.org/2001/10/synthesis' " + + "xmlns:xforms='http://www.w3.org/2002/xforms/' " + + "xmlns:m='http://www.w3.org/1998/Math/MathML' "+ + "xmlns:sel='http://www.daisy.org/ns/z3986/authoring/features/select/' "
+ + "xmlns:rend='http://www.daisy.org/ns/z3986/authoring/features/rend/'>" + + "<head>" + + "<meta rel='z3986:profile' "+ + "resource='http://www.daisy.org/z3986/2011/auth/profiles/genericdocument/0.7/'>"
+ + "<meta rel='z3986:feature' "+ + "resource='http://www.daisy.org/z3986/2011/auth/features/its-ruby/0.6/'/>"
+ + "<meta rel='z3986:feature' " + + "resource='http://www.daisy.org/z3986/2011/auth/features/ssml/0.5/'/>" + + "<meta rel='z3986:feature' "+ + "resource='http://www.daisy.org/z3986/2011/auth/features/forms/0.4/'/>"
+ + "<meta rel='z3986:feature' "+ + "resource='http://www.daisy.org/z3986/2011/auth/features/mathml/0.4/'/>"
+ + "<meta rel='z3986:feature' "+ + "resource='http://www.daisy.org/z3986/2011/auth/features/select/0.4/'/>"
+ + "<meta rel='z3986:feature' " + + "resource='http://www.daisy.org/z3986/2011/auth/features/rend/0.6/'/>" + + "<meta rel='z3986:feature' "+ + "resource='http://www.daisy.org/z3986/2011/auth/features/svg-cdr/0.2/'/>"
+ + "</meta>" + "<meta property='dcterms:identifier' content=''/>" + + "<meta property='dcterms:publisher' content=''/>" + + "<meta property='dcterms:modified' content=''/>" + "</head>" + + "<body>" + "<section/>" + "</body>" + "</document>"; -Document doc; + Document doc; -NewDocument () { -startDocument (); -} + NewDocument() { + startDocument(); + } -private void startDocument () { -Builder builder = new Builder(); -try { -doc = builder.build (framework, null); -} catch (ParsingException e) { -new Notify ("Framework is malformed"); -return; -} catch (IOException e) { -} -Element rootElement = doc.getRootElement(); -findAddChildPoints (rootElement); -} + private void startDocument() { + Builder builder = new Builder(); + try { + doc = builder.build(framework, null); + } + catch (ParsingException e) { + new Notify("Framework is malformed"); + return; + } + catch (IOException e) { + } + Element rootElement = doc.getRootElement(); + findAddChildPoints(rootElement); + } -private void findAddChildPoints (Node node) { -Node newNode = null; -Element elementNode = null; -String elementName; -String attributeName; -for (int i = 0; i < node.getChildCount(); i++) { -newNode = node.getChild(i); -if (newNode instanceof Element) { -elementNode = (Element)newNode; -elementName = elementNode.getLocalName(); -if (elementName.equals ("head")) { -headAdd = elementNode; -} else if (elementName.equals ("section")) { -sectionAdd = elementNode; -} -findAddChildPoints (elementNode); -} -} -} + private void findAddChildPoints(Node node) { + Node newNode = null; + Element elementNode = null; + String elementName; + String attributeName; + for (int i = 0; i < node.getChildCount(); i++) { + newNode = node.getChild(i); + if (newNode instanceof Element) { + elementNode = (Element) newNode; + elementName = elementNode.getLocalName(); + if (elementName.equals("head")) { + headAdd = elementNode; + } else if (elementName.equals("section")) { + sectionAdd = elementNode; + } + findAddChildPoints(elementNode); + } + } + } -void restartDocument () { -doc = null; -startDocument (); -} + void restartDocument() { + doc = null; + startDocument(); + } -void fillOutBody (StyledText view) { -String text = view.getText(); + void fillOutBody(StyledText view) { + String text = view.getText(); -int length = text.length(); -int beginParagraph = 0; -int endParagraph = 0; -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) { -// FO endParagraph = i - 1; -endParagraph = i; -if (c == 0x0a) { -i++; -} -else if (text.charAt(i + 1) == 0x0a) { -i += 1; -} else { -i++; -} -} else { -endParagraph = length; -} -if (beginParagraph >= 0 && endParagraph > beginParagraph) { -paragraph.appendChild (text.substring (beginParagraph, endParagraph)); -} -sectionAdd.appendChild (paragraph); -paragraph = null; -beginParagraph = i; -} -} + int length = text.length(); + int beginParagraph = 0; + int endParagraph = 0; + 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) { + // FO endParagraph = i - 1; + endParagraph = i; + if (c == 0x0a) { + i++; + } else if (text.charAt(i + 1) == 0x0a) { + i += 1; + } else { + i++; + } + } else { + endParagraph = length; + } + if (beginParagraph >= 0 && endParagraph > beginParagraph) { + paragraph.appendChild(text.substring(beginParagraph, + endParagraph)); + } + sectionAdd.appendChild(paragraph); + paragraph = null; + beginParagraph = i; + } + } -Document getDocument() { -return doc; -} + Document getDocument() { + return doc; + } } - =======================================--- /src/main/org/brailleblaster/wordprocessor/RecentDocuments.java Thu Jan 10 20:26:03 2013 +++ /src/main/org/brailleblaster/wordprocessor/RecentDocuments.java Wed Jan 23 08:02:41 2013
@@ -55,11 +55,7 @@ import org.eclipse.swt.widgets.Monitor; import org.eclipse.swt.widgets.Shell; -/** - * Pick a document from those recently opened and return its absolute - * path. - */ - +//Pick a document from those recently opened and return its absolute path. class RecentDocuments { Shell shell; Combo combo; @@ -84,7 +80,7 @@ void open() { readList(); processDocsList(); - Display display = BBIni.getDisplay(); + Display display = WPManager.getDisplay(); shell = new Shell (display, SWT.DIALOG_TRIM); shell.setText("Recent documents"); // FO @@ -106,7 +102,8 @@ combo = new Combo (shell, SWT.DROP_DOWN | SWT.READ_ONLY); if (recentDocsArr.length > 25) { combo.setVisibleItemCount(25); - } else { + } + else { combo.setVisibleItemCount(recentDocsArr.length); } combo.setItems(recentDocsArr); @@ -130,9 +127,10 @@ public void widgetSelected(SelectionEvent e) { int key = combo.getSelectionIndex(); if(key != -1){ - String path = recentDocsList.get(key); - shell.close(); - dm.recentOpen (path); + String path = recentDocsList.get(key); + shell.close(); + //dm.recentOpen (path); + dm.openDocument(path); } // shell.close(); } @@ -141,8 +139,9 @@ shell.pack(); shell.open(); while (!shell.isDisposed()) { - if (!display.readAndDispatch()) + if (!display.readAndDispatch()){ display.sleep(); + } } // tear down the SWT window shell.dispose(); @@ -155,7 +154,9 @@ for( int i=0; (i < recentDocsArr.length-1)&&(!dupArr[i]);i++) { String s1 = recentDocsArr[i]; int index = s1.lastIndexOf(fileSep); - if (index>=0) s1 = s1.substring(index); + if (index>=0) { + s1 = s1.substring(index); + } for(int j=i+1; (j< recentDocsArr.length)&&(!dupArr[j]); j++) { String s2 = recentDocsArr[j]; index = s2.lastIndexOf(fileSep); @@ -167,24 +168,29 @@ } } for(int i=0; i<recentDocsArr.length;i++) { - if(!dupArr[i]) + if(!dupArr[i]){recentDocsArr[i] = recentDocsArr[i].substring(recentDocsArr[i].lastIndexOf(fileSep)+1);
+ } } } void addDocument(String document) { if(document!=null) { - recentDocsList.remove(document); - recentDocsList.add(0, document);- if(recentDocsList.size()>MAX_NUM_FILES) recentDocsList.remove(MAX_NUM_FILES);
- storeList();} + recentDocsList.remove(document); + recentDocsList.add(0, document); + if(recentDocsList.size()>MAX_NUM_FILES){ + recentDocsList.remove(MAX_NUM_FILES); + } + storeList(); + } } private void storeList() { BufferedWriter writer = null; try { writer = new BufferedWriter(new FileWriter(file)); - } catch (IOException e) { + } + catch (IOException e) { new Notify(e.getMessage()); } try { @@ -192,12 +198,15 @@ writer.write(s); writer.newLine(); } - } catch (IOException e) { + } + catch (IOException e) { new Notify(e.getMessage()); - }finally{ + } + finally{ try { writer.close(); - } catch (IOException e) { + } + catch (IOException e) { new Notify(e.getMessage()); } } @@ -210,7 +219,8 @@ BufferedReader reader = null; try { reader = new BufferedReader(new FileReader(file)); - } catch (FileNotFoundException e) { + } + catch (FileNotFoundException e) { new Notify(e.getMessage()); } recentDocsList = new ArrayList<String>(); @@ -219,12 +229,15 @@ while ((line = reader.readLine()) != null) { recentDocsList.add(line); } - } catch (IOException e) { + } + catch (IOException e) { new Notify(e.getMessage()); - }finally{ + } + finally{ try { reader.close(); - } catch (IOException e) { + } + catch (IOException e) { new Notify(e.getMessage()); } } =======================================--- /src/main/org/brailleblaster/wordprocessor/UTD.java Thu Nov 29 06:25:08 2012 +++ /src/main/org/brailleblaster/wordprocessor/UTD.java Wed Jan 23 08:02:41 2013
@@ -212,7 +212,7 @@// if(brailleLine.length() > 4096 || printLine.length() > 4096 | | i == node.getChildCount()-1) { if(brailleLine.length() > 4096 || i == node.getChildCount()-1) {
- dm.display.syncExec(new Runnable() { + dm.getDisplay().syncExec(new Runnable() { public void run() { // FO if (firstTime) { @@ -230,7 +230,8 @@ } brailleLine.delete (0, brailleLine.length()); } - }); + }); + } /** p elements have their own structure **/ if (!(elementName == null)) { =======================================--- /src/main/org/brailleblaster/wordprocessor/WPManager.java Mon Jul 30 05:19:27 2012 +++ /src/main/org/brailleblaster/wordprocessor/WPManager.java Wed Jan 23 08:02:41 2013
@@ -29,235 +29,137 @@ package org.brailleblaster.wordprocessor; import org.eclipse.swt.*; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Monitor; import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.TabFolder; import org.brailleblaster.BBIni; +import org.brailleblaster.settings.Welcome; import org.brailleblaster.util.YesNoChoice; import org.brailleblaster.util.ShowBriefly; import org.brailleblaster.util.Notify; import java.util.ArrayList; +import java.util.LinkedList; public class WPManager { /*** This is the controller for the whole word processing operation. It is the * entry point for the word processor, and therefore the only public class.
*/ - - String fileName = null; - int action; - private Display display; + public static Display display; + private Shell shell; + private FormLayout layout; + private TabFolder folder; + private FormData location; + private BBMenu bbMenu; + private BBStatusBar statusBar; + private LinkedList<DocumentManager> managerList; +private static final int MAX_NUM_DOCS = 4;//the max limit of total number of docs can have at the same time - private static DocumentManager[] documents = new DocumentManager[MAX_NUM_DOCS];
- private static int documentIndex; - private static DocumentManager curDoc; - - private static boolean isDeactivated = false; - private static DocumentManager prevDoc; - private static int prevIndex= -1; - - /** - * This constructor is the entry point to the word processor. It gets - * things set up, handles multiple documents, etc. - */ - ++ //This constructor is the entry point to the word processor. It gets things set up, handles multiple documents, etc.
public WPManager(String fileName) { - this.fileName = fileName; - if (fileName != null) { - action = WP.DocumentFromCommandLine; - } else { - action = WP.NewDocument; - } - display = BBIni.getDisplay(); - if (display == null) {- System.out.println ("Could not find graphical interface environment");
- System.exit(1); - } - checkLiblouisutdml(); - documentIndex = 0; - curDoc = documents[0] = new DocumentManager(display, - documentIndex, action, fileName) ; - do { - findTrigger(); - switch (curDoc.returnReason) { - case WP.DocumentClosed://6 - documents[documentIndex].finish();- if (getNextAvailableDoc() == -1) return; //no more docs, exit
-//FO if (getNextAvailableDoc() == -1) { - // open new document -// documentIndex = 0; -// action = WP.NewDocument; -// curDoc = documents[0] = new DocumentManager(display, -// documentIndex, action, "") ; -// } else { - WPManager.resumeAll(documentIndex); -// } - break; - case WP.SwitchDocuments://4 - if(DocumentManager.recentFileNameIndex != -1){ - documentIndex = DocumentManager.recentFileNameIndex; - DocumentManager.recentFileNameIndex = -1; - } - else { - documentIndex = getNextAvailableDoc(); - } - curDoc = documents[documentIndex];- //System.out.println("Switching...from "+ documentIndex+ "to" +getNextAvailableDoc() );
- curDoc.resume(); - break; - case WP.NewDocument://1 - if (getNextAvailablePos() == -1){ - new Notify ("Too many documents"); - curDoc.resume(); - break; - } - documentIndex = getNextAvailablePos();- curDoc = documents[documentIndex] = new DocumentManager(display,
- documentIndex, WP.NewDocument, fileName); - break; - case WP.OpenDocumentGetFile://2 - if (getNextAvailablePos() == -1){ - new Notify ("Too many documents to open a new file"); - curDoc.resume(); - break; - } - documentIndex = getNextAvailablePos();- curDoc = documents[documentIndex] = new DocumentManager(display,
- documentIndex, WP.OpenDocumentGetFile, fileName); - break; -//FO 30 - case WP.ImportDocument://3 - if (getNextAvailablePos() == -1){ - new Notify ("Too many documents to open a new file"); - curDoc.resume(); - break; - } - documentIndex = getNextAvailablePos();- curDoc = documents[documentIndex] = new DocumentManager(display,
- documentIndex, WP.ImportDocument, fileName); - break; -- case WP.OpenDocumentGetRecent://8 open a recent doc in a new windows
- if (getNextAvailablePos() == -1){- new Notify ("Too many documents to open the recent document in a new window");
- curDoc.resume(); - break; - } - documentIndex = getNextAvailablePos(); - fileName = DocumentManager.getRecentFileName();- curDoc = documents[documentIndex] = new DocumentManager(display,
- documentIndex, WP.OpenDocumentGetRecent, fileName); - break; - case WP.BBClosed://7 - while(getNextAvailableDoc()!= -1){ - documents[getNextAvailableDoc()].finish(); - } - return; - default: - break; - } - } while (curDoc.returnReason != WP.BBClosed); + checkLiblouisutdml(); + + display = new Display(); + this.shell = new Shell(display, SWT.SHELL_TRIM); + this.shell.setText("BrailleBlaster"); + this.layout = new FormLayout(); + this.shell.setLayout(this.layout); + + this.folder = new TabFolder(this.shell, SWT.NONE); + this.location = new FormData(); + this.location.left = new FormAttachment(0); + this.location.right = new FormAttachment(100); + this.location.top = new FormAttachment (3); + this.location.bottom = new FormAttachment(98); + this.folder.setLayoutData (this.location); + + this.statusBar = new BBStatusBar(this.shell); + this.bbMenu = new BBMenu(this); + + this.managerList = new LinkedList<DocumentManager>(); + this.managerList.add(new DocumentManager(this, null)); + + this.shell.addListener(SWT.Close, new Listener() { + public void handleEvent(Event event) {+ System.out.println("Main Shell handling Close event, about to dipose the main Display");
+ display.dispose(); + } + }); + + setShellScreenLocation(display, this.shell); + + new Welcome(); + this.shell.open(); + + while (!display.isDisposed()) { + try { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + catch (Exception e) { + e.printStackTrace(); + } + } } - - private static void findTrigger(){ - int number = -1; - int i = 0; - for(boolean b:DocumentManager.getflags()){ - if(b) { - number=i; - break; - } - i++; - } - if(number != -1) - { - DocumentManager.setflags(number, false); - documentIndex = number; - curDoc = documents[documentIndex]; - } - } + + private void setShellScreenLocation(Display display, Shell shell){ + Monitor primary = display.getPrimaryMonitor(); + Rectangle bounds = primary.getBounds(); + Rectangle rect = shell.getBounds(); + int x = bounds.x + ((bounds.width - rect.width) / 2); + int y = bounds.y + ((bounds.height - rect.height) / 2); + shell.setLocation(x, y); + } + + public void addDocumentManager(String fileName){ + this.managerList.add(new DocumentManager(this, fileName)); + setSelection(); + } - //resume all the windows except the one with documentNumber - public static void resumeAll(int documentNumber){ - for(int i = 0 ; i< documents.length; i++){ - if(i != documentNumber) { - if(documents[i] != null) documents[i].resume(); - } - } - } - - static int getNextAvailableDoc(){ - //search in higher index first for the next available index - //index-> MAX - for(int i = documentIndex+1; i <MAX_NUM_DOCS; i++){ - if( documents[i] != null){ - if(documents[i].isFinished())documents[i] = null; - else return i; - } - } - //0->index - for(int i = 0; i <= documentIndex; i++){ - if( documents[i] != null){ - if(documents[i].isFinished())documents[i] = null; - else return i; - } - } - //if no available doc - return -1; - } -- //check if a document named fileName is running, return its index or -1;
- static int isRunning(String fileName){ - int start = documentIndex; - for(int i = 0; i <MAX_NUM_DOCS; i++){ - if( documents[i] != null){ - if(documents[i].isFinished()){ - documents[i] = null; - } - else{- //System.out.println("isRunning: NO"+i+"'s name is "+documents[i].documentName);
- if (documents[i].documentName.equals(fileName)) - return i; - } - } - } - return -1; - } - - int getNextAvailablePos(){- //see if there is available position for one more document, -1 if it is full
- for(int i = 0; i <MAX_NUM_DOCS; i++){ - if( documents[i] == null) return i;- else if (documents[i].isFinished()){documents[i] = null; return i;}
- } - return -1; - } - + public void setSelection(){ + int index = this.managerList.size() - 1; + this.folder.setSelection(index); + } + void checkLiblouisutdml() { if (BBIni.haveLiblouisutdml()) { return; } - if (new YesNoChoice - ("The Braille facility is not usable." + " See the log." - + " Do you wish to continue?") - .result == SWT.NO) {+ if (new YesNoChoice("The Braille facility is not usable." + " See the log." + " Do you wish to continue?").result == SWT.NO) {
System.exit(1); } } - - static void setCurDoc(int documentNumber){- //System.out.println("Something triggers current doc to change, now documentIndex = " + documentNumber );
- documentIndex = documentNumber; - curDoc = documents[documentIndex];; - } - - /** - * Check to see if there are other documents. - */ - static boolean haveOtherDocuments() { - return (getNextAvailableDoc()!= -1); - } static int getMaxNumDocs(){ return MAX_NUM_DOCS; } + + public static Display getDisplay() { + return display; + } + + public Shell getShell(){ + return shell; + } + + public TabFolder getFolder(){ + return this.folder; + } + + public LinkedList<DocumentManager> getList(){ + return this.managerList; + } + + public BBStatusBar getStatusBar(){ + return this.statusBar; + } }