[brailleblaster] [brailleblaster.newdesign] push by brandon....@xxxxxxxxx - Added ability to open single epub xhtml files for preliminary testing ... on 2013-09-13 17:45 GMT

  • From: brailleblaster@xxxxxxxxxxxxxx
  • To: brailleblaster@xxxxxxxxxxxxx
  • Date: Fri, 13 Sep 2013 17:46:15 +0000

Revision: 26a8a7959cd9
Branch:   default
Author:   Brandon Roller <brandon.r.roller@xxxxxxxxx>
Date:     Fri Sep 13 17:44:22 2013 UTC
Log: Added ability to open single epub xhtml files for preliminary testing only
http://code.google.com/p/brailleblaster/source/detail?r=26a8a7959cd9&repo=newdesign

Modified:
 /src/main/org/brailleblaster/document/BBDocument.java
 /src/main/org/brailleblaster/document/BBSemanticsTable.java
 /src/main/org/brailleblaster/document/SemanticFileHandler.java
 /src/main/org/brailleblaster/mapping/MapList.java
 /src/main/org/brailleblaster/settings/ConfigFileDialog.java
 /src/main/org/brailleblaster/stylePanel/StyleManager.java
 /src/main/org/brailleblaster/stylePanel/StyleTable.java
 /src/main/org/brailleblaster/views/BrailleView.java
 /src/main/org/brailleblaster/views/PropertyView.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/DocumentManager.java

=======================================
--- /src/main/org/brailleblaster/document/BBDocument.java Wed Sep 11 17:46:32 2013 UTC +++ /src/main/org/brailleblaster/document/BBDocument.java Fri Sep 13 17:44:22 2013 UTC
@@ -128,16 +128,24 @@
configFileWithPath = fu.findInProgramData ("liblouisutdml" + BBIni.getFileSep() + "lbu_files" + BBIni.getFileSep() + configFile);

                if (configSettings == null) {
- configWithUTD = "formatFor utd\n mode notUC\n printPages no\n" + semHandler.getSemanticsConfigSetting(completePath);
+                       configWithUTD = "formatFor utd\n mode notUC\n printPages 
no\n";
                }
                else {
- configWithUTD = configSettings + "formatFor utd\n mode notUC\n printPages no\n" + semHandler.getSemanticsConfigSetting(completePath); + configWithUTD = configSettings + "formatFor utd\n mode notUC\n printPages no\n";
+               }
+
+               if(dm.getWorkingPath() != null){
+                       configWithUTD += 
semHandler.getSemanticsConfigSetting(completePath);
+               }
+               else {
+ configFileWithPath = fu.findInProgramData ("liblouisutdml" + BBIni.getFileSep() + "lbu_files" + BBIni.getFileSep() + "nimas.cfg");
                }
+
                String outFile = BBIni.getTempFilesPath() + fileSep + 
"outFile.utd";
                String logFile = BBIni.getLogFilesPath() + fileSep + 
"liblouisutdml.log";
                int extPos = completePath.lastIndexOf (".") + 1;
                String ext = completePath.substring (extPos);
-               if (ext.equalsIgnoreCase ("xml")) {
+               if (ext.equalsIgnoreCase ("xml") || ext.equals("xhtml")) {
String tempPath = BBIni.getTempFilesPath() + completePath.substring(completePath.lastIndexOf(BBIni.getFileSep()), completePath.lastIndexOf(".")) + "_temp.xml"; if(normalizeFile(completePath, tempPath) && lutdml.translateFile (configFileWithPath, tempPath, outFile, logFile, configWithUTD, 0)){
                                deleteFile(tempPath);
@@ -268,13 +276,11 @@

list.add(index, new TextMapElement(textOffset, textOffset, p.getChild(0)));

-       //      if(index < list.size() - 1){
                Element brl = new Element("brl");
                brl.appendChild(new Text(""));
                p.appendChild(brl);
                addNamespace(brl);
list.get(index).brailleList.add(new BrailleMapElement(brailleOffset, brailleOffset, brl.getChild(0)));
-//             }
        }

        private void changeTextNode(Node n, String text){
@@ -518,7 +524,7 @@

        private int translateString(String text, byte[] outbuffer) {
String logFile = BBIni.getLogFilesPath() + BBIni.getFileSep() + BBIni.getInstanceID() + BBIni.getFileSep() + "liblouisutdml.log"; - String preferenceFile = fu.findInProgramData ("liblouisutdml" + BBIni.getFileSep() + "lbu_files" + BBIni.getFileSep() + BBIni.getDefaultConfigFile()); + String preferenceFile = fu.findInProgramData ("liblouisutdml" + BBIni.getFileSep() + "lbu_files" + BBIni.getFileSep() + dm.getCurrentConfig());

                byte[] inbuffer;
                try {
@@ -561,7 +567,7 @@
                Elements els = e.getChildElements();

                if(e instanceof Element && e.getLocalName().equals("meta")){
-                       if(e.getAttributeValue("name").equals("utd"))
+ if(checkAttribute(e, "name") && e.getAttributeValue("name").equals("utd"))
                                e.getParent().removeChild(e);
                        else {
                                Attribute attr = e.getAttribute("semantics");
@@ -593,9 +599,8 @@
                else {
                        Element parent = t.parentElement();
                        
while(!parent.getAttributeValue("semantics").contains("style")){
-                               
if(((Element)parent.getParent()).getChildElements().size() <= 1){
+                               
if(((Element)parent.getParent()).getChildElements().size() <= 1)
                                        parent = (Element)parent.getParent();
-                               }
                                else
                                        break;
                        }
@@ -643,7 +648,7 @@
                Elements e = this.doc.getRootElement().getChildElements();

                for(int i = 0; i < e.size(); i++){
-                       
if(e.get(i).getAttributeValue("semantics").equals("style,document")){
+ if(checkAttribute(e.get(i), "semantics") && e.get(i).getAttributeValue("semantics").equals("style,document")){
                                Elements els = e.get(i).getChildElements();
                                for(int j = 0; j < els.size(); j++){
                                        
if(els.get(j).getLocalName().equals("brl")){
=======================================
--- /src/main/org/brailleblaster/document/BBSemanticsTable.java Fri Sep 6 18:16:34 2013 UTC +++ /src/main/org/brailleblaster/document/BBSemanticsTable.java Fri Sep 13 17:44:22 2013 UTC
@@ -1,6 +1,7 @@
 package org.brailleblaster.document;

 import java.io.BufferedReader;
+import java.io.FileNotFoundException;
 import java.io.FileReader;
 import java.io.IOException;
 import java.util.HashMap;
@@ -78,10 +79,10 @@
        FileUtils fu = new FileUtils();
        static Logger logger = BBIni.getLogger();

-       public BBSemanticsTable(){
+       public BBSemanticsTable(String config){
                try {
                        this.table = new HashMap<String, Styles>();
- String filePath = fu.findInProgramData ("liblouisutdml" + BBIni.getFileSep() + "lbu_files" + BBIni.getFileSep() + BBIni.getDefaultConfigFile()); + String filePath = fu.findInProgramData ("liblouisutdml" + BBIni.getFileSep() + "lbu_files" + BBIni.getFileSep() + config);
                        FileReader file = new FileReader(filePath);
                        BufferedReader reader = new BufferedReader(file);
                        makeHashTable(reader);
@@ -180,7 +181,7 @@
                if(temp != null){
                        Element e = (Element)n.getParent();
                        String nextKey = getKeyFromAttribute(e);
-                       while(!nextKey.equals("document")){
+                       while(!nextKey.equals("document") && 
!nextKey.equals("markhead")){
                                if(this.table.containsKey(nextKey)){
                                        makeComposite(nextKey,temp);
                                }
@@ -226,4 +227,26 @@
                else
                        return false;
        }
+
+       public void resetStyleTable(String configFile){
+               table.clear();
+ String filePath = fu.findInProgramData ("liblouisutdml" + BBIni.getFileSep() + "lbu_files" + BBIni.getFileSep() + configFile);
+
+               try {
+                       FileReader file = new FileReader(filePath);
+                       BufferedReader reader = new BufferedReader(file);
+                       makeHashTable(reader);
+                       reader.close();
+                       makeStylesObject("italicx");
+                       insertValue("italicx","\tFont " + SWT.ITALIC);
+                       makeStylesObject("boldx");
+                       insertValue("boldx","\tFont " + SWT.BOLD);
+               }
+               catch (FileNotFoundException e) {
+                       e.printStackTrace();
+               }
+               catch (IOException e) {
+                       e.printStackTrace();
+               }
+       }
 }
=======================================
--- /src/main/org/brailleblaster/document/SemanticFileHandler.java Tue Sep 10 19:49:10 2013 UTC +++ /src/main/org/brailleblaster/document/SemanticFileHandler.java Fri Sep 13 17:44:22 2013 UTC
@@ -66,9 +66,9 @@
                        String currentLine;

                        File f = new File(defaultSemFile);
-                       FileReader fr;
+
                        try {
-                               fr = new FileReader(f);
+                               FileReader fr = new FileReader(f);
                                BufferedReader br = new BufferedReader(fr);

                                while ((currentLine = br.readLine()) != null) {
@@ -79,7 +79,8 @@
                                }

                                br.close();
-                       } catch (FileNotFoundException e) {
+                       }
+                       catch (FileNotFoundException e) {
                                e.printStackTrace();
                        }
                        catch(IOException e){
=======================================
--- /src/main/org/brailleblaster/mapping/MapList.java Wed Sep 11 14:00:18 2013 UTC +++ /src/main/org/brailleblaster/mapping/MapList.java Fri Sep 13 17:44:22 2013 UTC
@@ -540,4 +540,10 @@

                return list;
        }
+
+       public void clearList(){
+               this.clear();
+               this.current = null;
+               currentIndex = -1;
+       }
 }
=======================================
--- /src/main/org/brailleblaster/settings/ConfigFileDialog.java Fri Jul 5 16:39:08 2013 UTC +++ /src/main/org/brailleblaster/settings/ConfigFileDialog.java Fri Sep 13 17:44:22 2013 UTC
@@ -1009,8 +1009,10 @@
        void refreshViews()
        {
                int index = dm.getFolder().getSelectionIndex();
-               if(index  > -1)
+               if(index  > -1) {
+                       
dm.getList().get(index).setCurrentConfig(defaultCfgFileName);
                        dm.getList().get(index).refresh();
+               }

        } // void refreshViews()

=======================================
--- /src/main/org/brailleblaster/stylePanel/StyleManager.java Fri Aug 2 12:45:05 2013 UTC +++ /src/main/org/brailleblaster/stylePanel/StyleManager.java Fri Sep 13 17:44:22 2013 UTC
@@ -46,14 +46,16 @@
     private StylePanel sp;
     private StyleTable table;
     //private PropertyView propView;
+    private String configFile;
     DocumentManager dm;

     private BBSemanticsTable semanticsTable;

     public StyleManager(DocumentManager dm) {
        this.dm = dm;
+       this.configFile = dm.getCurrentConfig();
        this.table = new StyleTable(this, dm.getGroup());
-       this.semanticsTable = new BBSemanticsTable();
+       this.semanticsTable = dm.getStyleTable();
        }

        void createStyle(String styleName){
@@ -99,6 +101,10 @@
     public BBSemanticsTable getSemanticsTable(){
        return this.semanticsTable;
     }
+
+    public StyleTable getStyleTable(){
+       return table;
+    }

     public Table getTable(){
        return table.getTable();
@@ -111,4 +117,8 @@
     public void hideTable(){
        table.hideTable();
     }
+
+    public String getConfigFile(){
+       return configFile;
+    }
 }
=======================================
--- /src/main/org/brailleblaster/stylePanel/StyleTable.java Mon Aug 19 14:52:27 2013 UTC +++ /src/main/org/brailleblaster/stylePanel/StyleTable.java Fri Sep 13 17:44:22 2013 UTC
@@ -99,7 +99,7 @@
                        }
                });

-               populateTable();
+               populateTable(sm.getConfigFile());
                initializeListeners();
        }

@@ -167,9 +167,8 @@
                t.setSelection(searchTree(text));
        }

-    private void populateTable(){
-       String defaultName = BBIni.getDefaultConfigFile();
- String fullPath = fu.findInProgramData ("liblouisutdml" + BBIni.getFileSep() + "lbu_files" + BBIni.getFileSep() + defaultName);
+    private void populateTable(String config){
+ String fullPath = fu.findInProgramData ("liblouisutdml" + BBIni.getFileSep() + "lbu_files" + BBIni.getFileSep() + config);
        String currentLine;

        try {
@@ -196,6 +195,11 @@
                logger.log(Level.SEVERE, "File Not Found Exception", e);
        }
     }
+
+    public void resetTable(String configFile){
+       t.removeAll();
+       populateTable(configFile);
+    }

     private void addTableItem(String item){
        TableItem tItem = new TableItem(t, SWT.CENTER);
=======================================
--- /src/main/org/brailleblaster/views/BrailleView.java Wed Sep 11 19:17:39 2013 UTC +++ /src/main/org/brailleblaster/views/BrailleView.java Fri Sep 13 17:44:22 2013 UTC
@@ -688,9 +688,8 @@
                                else {
                                        if((Integer)message.getValue("lastPosition") < 0 
&& currentStart > 0)
                                                pos = currentStart + 
(Integer)message.getValue("lastPosition");
-                                       else 
if((Integer)message.getValue("lastPosition") == 99999){
+                                       else 
if((Integer)message.getValue("lastPosition") == 99999)
                                                pos = currentEnd + offset;
-                                       }
                                        else {
pos = currentStart + findCurrentPosition(arr, (Integer)message.getValue("lastPosition")) + offset;
                                                pos += checkPageRange(pos);
=======================================
--- /src/main/org/brailleblaster/views/PropertyView.java Thu Aug 1 15:10:48 2013 UTC +++ /src/main/org/brailleblaster/views/PropertyView.java Fri Sep 13 17:44:22 2013 UTC
@@ -41,7 +41,7 @@

        public PropertyView(DocumentManager dm, Group documentWindow) {
                this.group = new Group(documentWindow, SWT.BORDER | 
SWT.V_SCROLL);
-               this.stylesTable = new BBSemanticsTable();
+               this.stylesTable = dm.getStyleTable();
                group.setText("Element Attributes");
setLayoutData(group, LEFT_MARGIN, RIGHT_MARGIN, TOP_MARGIN, BOTTOM_MARGIN);
                group.setLayout(new FormLayout());
=======================================
--- /src/main/org/brailleblaster/views/TextView.java Wed Sep 11 17:46:32 2013 UTC +++ /src/main/org/brailleblaster/views/TextView.java Fri Sep 13 17:44:22 2013 UTC
@@ -986,6 +986,7 @@

        private void setCursorPosition(Message message){
                int offset = (Integer)message.getValue("offset");
+
                if(message.contains("element")){
                        Element e = 
getBrlNode((Node)message.getValue("element"));
                        int pos;
=======================================
--- /src/main/org/brailleblaster/views/TreeView.java Fri Sep 6 18:16:34 2013 UTC +++ /src/main/org/brailleblaster/views/TreeView.java Fri Sep 13 17:44:22 2013 UTC
@@ -182,7 +182,7 @@

                this.tree.addFocusListener(treeFocusListener = new 
FocusListener(){
                        @Override
-                       public void focusGained(FocusEvent arg0) {
+                       public void focusGained(FocusEvent e) {
                                // TODO Auto-generated method stub
                        }

@@ -261,7 +261,7 @@
private void populateItemChildren(TreeItem item, Element e, DocumentManager dm){
                ArrayList<Text>textList = new ArrayList<Text>();
                Elements els = e.getChildElements();
-
+
                for(int i = 0; i < els.size(); i++){
if(!els.get(i).getLocalName().equals("pagenum") && !els.get(i).getLocalName().equals("brl") && !els.get(i).getAttributeValue("semantics").contains("skip")){
                                TreeItem temp = new TreeItem(item, 0);
=======================================
--- /src/main/org/brailleblaster/wordprocessor/BBMenu.java Fri Sep 6 18:16:34 2013 UTC +++ /src/main/org/brailleblaster/wordprocessor/BBMenu.java Fri Sep 13 17:44:22 2013 UTC
@@ -949,6 +949,7 @@
                                        {
                                                
wordProc.getList().get(index).closeUntitledTab();
                                                
wordProc.getList().get(index).openDocument(curStr2);
+                                               
wordProc.getList().get(index).checkTreeFocus();
                                        }
                                }

=======================================
--- /src/main/org/brailleblaster/wordprocessor/DocumentManager.java Wed Sep 11 14:00:18 2013 UTC +++ /src/main/org/brailleblaster/wordprocessor/DocumentManager.java Fri Sep 13 17:44:22 2013 UTC
@@ -102,11 +102,17 @@
        String zippedPath;
        String workingFilePath;
        FileUtils fu;
+       String currentConfig;

        //Constructor that sets things up for a new document.
        public DocumentManager(WPManager wp, String docName) {
+               if(docName != null)
+                       currentConfig = BBIni.getDefaultConfigFile();
+               else
+                       currentConfig = "nimas.cfg";
+
                this.fu = new FileUtils();
-               this.styles = new BBSemanticsTable();
+               this.styles = new BBSemanticsTable(currentConfig);
                this.documentName = docName;
                this.list = new MapList(this);
                this.wp = wp;
@@ -126,9 +132,8 @@

                docCount++;

-               if(docName != null){
+               if(docName != null)
                        openDocument(docName);
-               }
                else {
initializeAllViews(docName, BBIni.getProgramDataPath() + BBIni.getFileSep() + "xmlTemplates" + BBIni.getFileSep() + "dtbook.xml", null);
                        Nodes n = this.document.query("/*/*[2]/*[2]/*[1]/*[1]");
@@ -209,8 +214,8 @@
        public void fileOpenDialog() {
                String tempName;

- String[] filterNames = new String[] { "XML", "XML ZIP", "TEXT", "BRF", "UTDML working document", }; - String[] filterExtensions = new String[] { "*.xml", "*.zip", "*.txt", "*.brf", "*.utd", }; + String[] filterNames = new String[] { "XML", "XML ZIP", "XHTML", "TEXT", "BRF", "UTDML working document", }; + String[] filterExtensions = new String[] { "*.xml", "*.zip", "*.xhtml","*.txt", "*.brf", "*.utd", }; BBFileDialog dialog = new BBFileDialog(this.wp.getShell(), SWT.OPEN, filterNames, filterExtensions);

                tempName = dialog.open();
@@ -225,6 +230,7 @@
                        else {
                                closeUntitledTab();
                                openDocument(tempName);
+                               checkTreeFocus();
                        }

                } // if(tempName != null)
@@ -233,6 +239,12 @@
        public void openDocument(String fileName){
                // Update file we're about to work on.
                workingFilePath = fileName;
+
+               if(!currentConfig.equals(BBIni.getDefaultConfigFile())){
+                       currentConfig = BBIni.getDefaultConfigFile();
+                       styles.resetStyleTable(currentConfig);
+                       sm.getStyleTable().resetTable(currentConfig);
+               }
                ////////////////////////
                // Zip and Recent Files.

@@ -288,7 +300,7 @@

private void initializeAllViews(String fileName, String filePath, String configSettings){
                try{
- if(document.startDocument(filePath, BBIni.getDefaultConfigFile(), configSettings)){
+                       if(document.startDocument(filePath, currentConfig, 
configSettings)){
                                group.setRedraw(false);
                                text.view.setWordWrap(false);
                                braille.view.setWordWrap(false);
@@ -958,7 +970,7 @@
                                }
                                else
                                        text.view.setCaretOffset(0);
-
+
                                setCurrentOnRefresh("text",currentOffset, 
false);
                                text.setPositionFromStart();
                                text.view.setFocus();
@@ -987,7 +999,6 @@
                        else {
                                currentOffset = text.view.getCaretOffset();
                                resetViews();
-
                                setCurrentOnRefresh(null,currentOffset, false);
                                text.view.setCaretOffset(currentOffset);
                                text.setPositionFromStart();
@@ -1004,7 +1015,7 @@
                        File f = new File(path);
                        f.createNewFile();
                        fu.createXMLFile(document.getNewXML(), path);
-                       list.clear();
+                       list.clearList();
                        text.removeListeners();
                        text.resetView(group);
                        braille.removeListeners();
@@ -1028,9 +1039,15 @@
                                initializeAllViews(documentName, path, null);

                        f.delete();
-
+
                        text.hasChanged = textChanged;
                        braille.hasChanged = brailleChanged;
+
+                       if(workingFilePath == null && list.size() == 0){
+                               Nodes n = 
document.query("/*/*[2]/*[2]/*[1]/*[1]");
+                               ((Element)n.get(0)).appendChild(new Text(""));
+                               list.add(new TextMapElement(0, 0, 
n.get(0).getChild(0)));
+                       }
                }
                catch (IOException e) {
new Notify("An error occurred while refreshing the document. Please save your work and try again.");
@@ -1080,9 +1097,20 @@
                treeView.clearTree();
                text.removeListeners();
                braille.removeListeners();
-               list.clear();
+               list.clearList();
+       }
+
+ //if tree has focus when opening a document and closing an untitled document, the trees selection must be reset
+       public void checkTreeFocus(){
+ if(treeView.tree.isFocusControl() && treeView.tree.getSelectionCount() == 0){
+                       treeView.tree.setSelection(treeView.getRoot());
+               }
        }

+       public void setCurrentConfig(String config){
+               if(workingFilePath != null)
+                       currentConfig = config;
+       }

        public void checkForUpdatedViews(){
                if(text.hasChanged)
@@ -1124,4 +1152,12 @@
        public BBDocument getDocument(){
                return document;
        }
+
+       public String getCurrentConfig(){
+               return currentConfig;
+       }
+
+       public BBSemanticsTable getStyleTable(){
+               return styles;
+       }
 }

Other related posts:

  • » [brailleblaster] [brailleblaster.newdesign] push by brandon....@xxxxxxxxx - Added ability to open single epub xhtml files for preliminary testing ... on 2013-09-13 17:45 GMT - brailleblaster