[brailleblaster] push by brandon....@xxxxxxxxx - reverted files that should not have been committed on 2014-07-24 21:06 GMT

  • From: brailleblaster@xxxxxxxxxxxxxx
  • To: brailleblaster@xxxxxxxxxxxxx
  • Date: Thu, 24 Jul 2014 21:06:33 +0000

Revision: 89af8a0a1dc7
Branch:   default
Author:   Brandon Roller <brandon.r.roller@xxxxxxxxx>
Date:     Thu Jul 24 21:02:30 2014 UTC
Log:      reverted files that should not have been committed
http://code.google.com/p/brailleblaster/source/detail?r=89af8a0a1dc7

Modified:
 /src/main/org/brailleblaster/archiver/Archiver.java
 /src/main/org/brailleblaster/archiver/EPub3Archiver.java
 /src/main/org/brailleblaster/perspectives/braille/views/wp/TextView.java
/src/main/org/brailleblaster/perspectives/imageDescriber/ImageDescriberController.java /src/main/org/brailleblaster/perspectives/imageDescriber/views/ImageDescriberView.java

=======================================
--- /src/main/org/brailleblaster/archiver/Archiver.java Thu Jul 24 19:01:54 2014 UTC +++ /src/main/org/brailleblaster/archiver/Archiver.java Thu Jul 24 21:02:30 2014 UTC
@@ -32,24 +32,12 @@

 import java.io.FileInputStream;
 import java.io.IOException;
-import java.util.ArrayList;
 import java.util.Properties;

-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-
-import nu.xom.converters.DOMConverter;
-
 import org.brailleblaster.BBIni;
 import org.brailleblaster.document.BBDocument;
 import org.brailleblaster.util.FileUtils;
 import org.brailleblaster.util.Notify;
-import org.brailleblaster.util.Zipper;
-import org.w3c.dom.DOMImplementation;
-import org.w3c.dom.Document;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.NodeList;

//////////////////////////////////////////////////////////////////////////////////
 // Archiver gives methods for opening/handling particular document types.
@@ -66,26 +54,6 @@
        protected String currentConfig;

        protected boolean documentEdited;
-
-       protected String opfFilePath = null;
-       protected Document opfDoc = null;
-       protected ArrayList<String> spineList = null;
-       NodeList manifestElements;
-       NodeList spineElements;
-
-       // Every file that makes our epub doc.
-       ArrayList<String> epubFileList = null;
-
-       // Number of images in each file that makes up our document.
- // For every spine element we have, we're going to count the number of images
-       // in that file. This helps with image traversal.
-       ArrayList<Integer> numImages = null;
-
-       // Index of current file we're looking at in the browser.
-       // Current file we're to load using the spine as a reference.
-       // Spine is in .opf file in epub.
-       int curSpineFileIdx = 0;
-
//////////////////////////////////////////////////////////////////////////////////
        // Constructor. Stores path to document to prepare.
        Archiver(String docToPrepare)
@@ -95,9 +63,6 @@
                workingDocPath = originalDocPath;
                zippedPath = "";
                documentEdited = false;
-               opfFilePath = null;
-               epubFileList = new ArrayList<String>();
-               numImages = new ArrayList<Integer>();
        }

        // Get-er for original document path.
@@ -129,7 +94,6 @@
        //
        // Appropriate strings to pass so far are: epub, nimas,
        public String getAutoCfg(String settingStr) {
-
                // Init and load properties.
                Properties props = new Properties();
                try {
@@ -147,10 +111,8 @@

                // If we made it here, there was no setting by that name.
                return null;
-
        } // getAutoCfg()

-       // lic void copySemanticsFile(String
        public void copySemanticsFile(String tempSemFile, String savedFilePath) 
{
                FileUtils fu = new FileUtils();

@@ -178,306 +140,4 @@

        public abstract Archiver saveAs(BBDocument doc, String path, String 
ext);

- ////////////////////////////////////////////////////////////////////////////////// - // Returns path to opf file if we found one with a prior call to findOPF().
-       public String getOPFPath() {
-               return opfFilePath;
-       } // getOPF()
-
- //////////////////////////////////////////////////////////////////////////////////
-       // Traverses the list of upzipped files and attempts to find an opf
-       // file.
-       //
-       // Notes: zipper must have already been used to unzip an archive.
-       // String is the path to the opf file. We also store it.
-       // Get it with getOPF().
-       public String findOPF(Zipper zipper)
-       {
-               // Get paths to all unzipped files.
-               ArrayList<String> unzippedPaths = zipper.getUnzippedFilePaths();
-
-               // Find the .opf file.
-               for(int curFile = 0; curFile < unzippedPaths.size(); curFile++)
-               {
-                       // Does this file have an .opf extension?
-                       
if(unzippedPaths.get(curFile).toLowerCase().endsWith(".opf") == true)
-                       {
-                               // Found it!
-                               return unzippedPaths.get(curFile).toLowerCase();
-
-                       } // If ends with opf
-
-               } // for(int curFile...
-
-               // Couldn't find it.
-               return null;
-
-       } // findOPF()
-
- //////////////////////////////////////////////////////////////////////////////////
-       // Uses opf file to build a list of files used by the book/document.
-       public ArrayList<String> parseOPFFile(String _opfPath)
-       {
-               // Build factory, and parse the opf.
-               DocumentBuilderFactory factory = 
DocumentBuilderFactory.newInstance();
-        DocumentBuilder builder;
-        try {
- factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd";, false); - factory.setNamespaceAware(true); // Needed, just in case manifest/spine are in a namespace.
-                       builder = factory.newDocumentBuilder();
-                       opfDoc = builder.parse(opfFilePath);
-        } catch (Exception e) { e.printStackTrace(); }
-
-               // Grab the spine elements and manifest elements.
-        manifestElements = opfDoc.getElementsByTagNameNS("*", "item");
-               spineElements = opfDoc.getElementsByTagNameNS("*", "itemref");
-
-               // Filepath to current document.
-               String curDocFilePath = null;
-
- // Loop through the spine and find the items in the manifest that we need.
-               for(int curSP = 0; curSP < spineElements.getLength(); curSP++)
-               {
-                       // Get the attributes for this spine element.
-                       NamedNodeMap spineAtts = 
spineElements.item(curSP).getAttributes();
-
-                       // Get the ID of the item we need from the manifest.
-                       String fileID = 
spineAtts.getNamedItem("idref").getNodeValue();
-
-                       // Get the file path from the manifest.
- curDocFilePath = opfFilePath.substring( 0, opfFilePath.lastIndexOf(BBIni.getFileSep()) ) + BBIni.getFileSep();
-                       curDocFilePath += findHrefById(fileID).replace("/", 
BBIni.getFileSep());
-
-                       // Add this path to the list of document paths.
-                       epubFileList.add(curDocFilePath);
-               }
-
-               // Return list.
-               return epubFileList;
-
-       } // buildOPF()
-
-       
/////////////////////////////////////////////////////////////////////////
-       // Finds the manifest element using the given id,
-       // and returns the href attribute value.
-       String findHrefById(String id)
-       {
-               // Loop through the manifest items and find the file with this 
ID.
-               for(int curMan = 0; curMan < manifestElements.getLength(); 
curMan++)
-               {
-                       // Get the attributes for this manifest item.
-                       NamedNodeMap manAtts = 
manifestElements.item(curMan).getAttributes();
-
- // If this manifest item has the id we're looking for, time to open a file.
-                       if( 
manAtts.getNamedItem("id").getNodeValue().compareTo(id) == 0 )
-                       {
- // Get value of href; this is our local file path to the file. Return it.
-                               return 
manAtts.getNamedItem("href").getNodeValue();
-
-                       } // if manifestItem ID == fileID...
-
-               } // for(int curMan...
-
-               // Couldn't find it.
-               return null;
-
-       } // findHrefById()
-
- ///////////////////////////////////////////////////////////////////////////////////////////
-       // Takes in a document(W3C) and adds its image count to the list.
-       public void addToNumImgsList(Document addMe)
-       {
- // Create space big enough to hold our image integers if we haven't done so already.
-               if(numImages == null)
-                       numImages = new ArrayList<Integer>();
-
-               // Grab all <img> elements.
-               NodeList imgElements = addMe.getElementsByTagName("img");
-
-               // Add this value to the list.
-               numImages.add(imgElements.getLength());
-       }
-
- ///////////////////////////////////////////////////////////////////////////////////////////
-       // Takes in a document(XOM) and adds its image count to the list.
-       public void addToNumImgsList(nu.xom.Document addMe)
-       {
-               // Convert to DOM.
-               Document w3cDoc = null;
-               try {
-                       DocumentBuilderFactory factory = 
DocumentBuilderFactory.newInstance();
-                       DocumentBuilder builder = factory.newDocumentBuilder();
-                       DOMImplementation impl = builder.getDOMImplementation();
-                       w3cDoc = DOMConverter.convert(addMe, impl);
-               }
-               catch(Exception e) { e.printStackTrace(); }
-
- // Create space big enough to hold our image integers if we haven't done so already.
-               if(numImages == null)
-                       numImages = new ArrayList<Integer>();
-
-               // Grab all <img> elements.
-               NodeList imgElements = w3cDoc.getElementsByTagName("img");
-
-               // Add this value to the list.
-               numImages.add(imgElements.getLength());
-       }
-
- ///////////////////////////////////////////////////////////////////////////////////////////
-       // Returns the list of documents that make up this book.
-       public ArrayList<String> getSpine() {
-               return epubFileList;
-       }
- ///////////////////////////////////////////////////////////////////////////////////////////
-       // Returns a path from a particular spine element.
-       public String getSpineFilePath(int idx) {
-               if(epubFileList != null)
-                       if(epubFileList.size() > 0)
-                               return epubFileList.get(idx);
-               return null;
-       }
-
-       //////////////////////////////////////////////////////////////////////
-       // Returns list of image counts for files in spine.
-       public ArrayList<Integer> getImgCountList() {
-               return numImages;
-       }
-
-       //////////////////////////////////////////////////////////////////////
-       // Return number of spine elements.
-       public int getNumSpineElements()
-       {
-               // Returns size of spine list.
-               return getSpine().size();
-
-       } // getNumSpineElements()
-
-       //////////////////////////////////////////////////////////////////////
-       // If working with an epub document, returns current spine file.
-       public String getCurSpineFilePath()
-       {
-               // Get current spine file path.
-               return getSpineFilePath(curSpineFileIdx);
-
-       } // getCurSpineFile()
-
-       //////////////////////////////////////////////////////////////////////
-       // Returns the current spine index.
-       public int getCurSpineIdx() {
-               return curSpineFileIdx;
-       } // getCurSpineIdx()
-
-       //////////////////////////////////////////////////////////////////////
-       // Converts image index to a local index, in reference to
-       // a page.
-       //
-       // For example: We could be on the 56th image, but it could be the
-       // second image in this particular spine element/page.
-       //
-       // Returns -1 if we can't find it, or if there isn't a supported
-       // archiver.
-       public int getImageIndexInSpinePage(int imageIndex)
-       {
-               // Get image counts for spine.
-               ArrayList<Integer> imgCntList = getImgCountList();
-
-               // Current image index in the spine we're testing against.
-               int curImgIdx = 0;
-
-               // Add up the spine/image counts
-               for(int curS = 0; curS < curSpineFileIdx; curS++)
-                       curImgIdx += imgCntList.get(curS);
-
-               // Is this image index within range of this particular spine 
element?
- if( imageIndex >= curImgIdx && imageIndex < curImgIdx + imgCntList.get(curSpineFileIdx) )
-               {
-                       // Move to the spine element that we've found.
-                       return imageIndex - curImgIdx;
-
-               } // if( within range )
-
-               // If we're here, we couldn't find the spine or image. Return 
failure.
-               return -1;
-       }
-
-       //////////////////////////////////////////////////////////////////////
-       // Takes an image index, and finds the spine file
-       // that contains this image.
-       public String setSpineFileWithImgIndex(int imgIndex)
-       {
-
-               // Get image counts for spine.
-               ArrayList<Integer> imgCntList = getImgCountList();
-
-               // Current image index in the spine we're testing against.
-               int curImgIdx = 0;
-
- // Loop through the spine/image counts, until we find one that contains this image.
-               for(int curS = 0; curS < imgCntList.size(); curS++)
-               {
-                       // Is this image index within range of this particular 
spine element?
- if( imgIndex >= curImgIdx && imgIndex < curImgIdx + imgCntList.get(curS) )
-                       {
-                               // Move to the spine element that we've found.
-                               return gotoSpineFilePath(curS);
-
-                       } // if( within range )
-
-                       // Move forward with the index.
-                       curImgIdx += imgCntList.get(curS);
-
-               } // for(curS)
-
- // If we make it here, we couldn't find that particular spine file/element.
-               return null;
-
-       } // setSpineFileWithImgIndex()
-
-       //////////////////////////////////////////////////////////////////////
-       // Moves to a specific spine file using an index into the list.
-       public String gotoSpineFilePath(int idx)
-       {
-               // Go to next file path.
-               curSpineFileIdx = idx;
-               // If we've gone too far, wrap around.
-               if(curSpineFileIdx >= getSpine().size())
-                       curSpineFileIdx = 0;
-               if(curSpineFileIdx < 0 )
-                       curSpineFileIdx = getSpine().size() - 1;
-
-               // Return the current spine file path.
-               return getSpineFilePath(curSpineFileIdx);
-
-       } // gotoSpineFilePath()
-
-       //////////////////////////////////////////////////////////////////////
-       // Moves index to current file to the next one we see in the spine.
-       public String nextSpineFilePath()
-       {
-               // Go to next file path.
-               curSpineFileIdx++;
-               // If we've gone too far, wrap around.
-               if(curSpineFileIdx >= getSpine().size())
-                       curSpineFileIdx = 0;
-
-               // Return the current spine file path.
-               return getSpineFilePath(curSpineFileIdx);
-
-       } // nextSpineFile()
-
-       //////////////////////////////////////////////////////////////////////
-       // Moves index to current file to the previous one we see in the spine.
-       public String prevSpineFilePath()
-       {
-               // Go to previous file path.
-               curSpineFileIdx--;
-               // If we've gone too far, wrap around.
-               if(curSpineFileIdx < 0 )
-                       curSpineFileIdx = getSpine().size() - 1;
-
-               // Return the current spine file path.
-               return getSpineFilePath(curSpineFileIdx);
-
-       } // prevSpineFile()
-
 } // class Archiver
=======================================
--- /src/main/org/brailleblaster/archiver/EPub3Archiver.java Thu Jul 24 19:01:54 2014 UTC +++ /src/main/org/brailleblaster/archiver/EPub3Archiver.java Thu Jul 24 21:02:30 2014 UTC
@@ -72,6 +72,9 @@

        // Path to .opf file.
        String opfPath;
+       // Manifest and spine elements.
+       NodeList manifestElements;
+       NodeList spineElements;

        // The main document we'll be appending to.
        Document mainDoc = null;
@@ -82,84 +85,74 @@
        // Opf document.
        Document opfDoc = null;

+       // Every file that makes our epub doc.
+       ArrayList<String> epubFileList = null;
+
        // The last bookmark we were at.
        String bkMarkStr = null;

-       public EPub3Archiver(String docToPrepare) {
+       // Number of images in each file that makes up our document.
+ // For every spine element we have, we're going to count the number of images
+       // in that file. This helps with image traversal.
+       ArrayList<Integer> numImages = null;
+
+       EPub3Archiver(String docToPrepare) {
                super(docToPrepare);
-               open(null);
+               open();
                currentConfig = getAutoCfg("epub");
                filterNames = new String[] {"EPUB", "BRF", "UTDML"};
                filterExtensions = new String[] {"*.epub","*.brf", "*.utd"};
        }
-
-       // Also takes path to opf file. Assumes document is already unzipped.
-//     public EPub3Archiver(String docToPrepare, String _opfPath) {
-//             super(docToPrepare);
-//             open(_opfPath);
-//             currentConfig = getAutoCfg("epub");
-//             filterNames = new String[] {"EPUB", "BRF", "UTDML"};
-//             filterExtensions = new String[] {"*.epub","*.brf", "*.utd"};
-//     }

//////////////////////////////////////////////////////////////////////////////////
        //
-       private String open(String _opath) {
+       private String open() {

                // Init variables.
                mainDoc = null;
                mainBodyElement = null;
                mainHtmlElement = null;
                opfDoc = null;
+               epubFileList = new ArrayList<String>();

                // First things first, we have to unzip the EPub doc.

                /////////
                // Unzip.

-                       // Get ready to unzip.
-                       Zipper zpr = null;
+                       // Create unzipper.
+                       Zipper zpr = new Zipper();
+
+                       // Unzip.
+                       String sep = BBIni.getFileSep();
+ String nameStr = originalDocPath.substring(originalDocPath.lastIndexOf(sep) + 1, originalDocPath.length()); + String outPath = BBIni.getTempFilesPath() + sep + nameStr.substring( 0, nameStr.lastIndexOf(".") ) + sep;
+                       zpr.Unzip( originalDocPath, outPath );

-                       // If zipped.
-                       if( _opath == null ) {
-                               // Create unzipper.
-                               zpr = new Zipper();
-
-                               // Unzip.
-                               String sep = BBIni.getFileSep();
- String nameStr = originalDocPath.substring(originalDocPath.lastIndexOf(sep) + 1, originalDocPath.length()); - String outPath = BBIni.getTempFilesPath() + sep + nameStr.substring( 0, nameStr.lastIndexOf(".") ) + sep;
-                               zpr.Unzip( originalDocPath, outPath );
-                       }
                // Unzip.
                /////////

                // Get ready to look for the opf file.
-               opfPath = _opath;
+               opfPath = null;

+               // Get paths to all unzipped files.
+               ArrayList<String> unzippedPaths = zpr.getUnzippedFilePaths();

-               // If zipped.
-               if( opfPath == null ) {
-                       // Get paths to all unzipped files.
-                       ArrayList<String> unzippedPaths = 
zpr.getUnzippedFilePaths();
-
-                       // Find the .opf file.
-                       for(int curFile = 0; curFile < unzippedPaths.size(); 
curFile++)
+               // Find the .opf file.
+               for(int curFile = 0; curFile < unzippedPaths.size(); curFile++)
+               {
+                       // Does this file have an .opf extension?
+                       
if(unzippedPaths.get(curFile).toLowerCase().endsWith(".opf") == true)
                        {
-                               // Does this file have an .opf extension?
-                               
if(unzippedPaths.get(curFile).toLowerCase().endsWith(".opf") == true)
-                               {
-                                       // Found it!
-                                       opfPath = 
unzippedPaths.get(curFile).toLowerCase();
-
-                                       // Found it, take a break.
-                                       break;
-
-                               } // If ends with opf
+                               // Found it!
+                               opfPath = 
unzippedPaths.get(curFile).toLowerCase();

-                       } // for(int curFile...
+                               // Found it, take a break.
+                               break;
+
+                       } // If ends with opf

-               } // if( opfPath == null )
+               } // for(int curFile...

                // If we couldn't find the opf file, no point in continuing.
                if(opfPath == null)
@@ -333,6 +326,32 @@
                return null;

        } // open()
+
+       
/////////////////////////////////////////////////////////////////////////
+       // Finds the manifest element using the given id,
+       // and returns the href attribute value.
+       String findHrefById(String id)
+       {
+               // Loop through the manifest items and find the file with this 
ID.
+               for(int curMan = 0; curMan < manifestElements.getLength(); 
curMan++)
+               {
+                       // Get the attributes for this manifest item.
+                       NamedNodeMap manAtts = 
manifestElements.item(curMan).getAttributes();
+
+ // If this manifest item has the id we're looking for, time to open a file.
+                       if( 
manAtts.getNamedItem("id").getNodeValue().compareTo(id) == 0 )
+                       {
+ // Get value of href; this is our local file path to the file. Return it.
+                               return 
manAtts.getNamedItem("href").getNodeValue();
+
+                       } // if manifestItem ID == fileID...
+
+               } // for(int curMan...
+
+               // Couldn't find it.
+               return null;
+
+       } // findHrefById()

        @Override
        public void save(BBDocument doc, String path)
@@ -428,7 +447,37 @@

        } // save()

+ ///////////////////////////////////////////////////////////////////////////////////////////
+       // Takes in a document and adds its image count to the list.
+       public void addToNumImgsList(Document addMe)
+       {
+ // Create space big enough to hold our image integers if we haven't done so already.
+               if(numImages == null)
+                       numImages = new ArrayList<Integer>();
+
+               // Grab all <img> elements.
+               NodeList imgElements = addMe.getElementsByTagName("img");
+
+               // Add this value to the lsit.
+               numImages.add(imgElements.getLength());
+       }

+ ///////////////////////////////////////////////////////////////////////////////////////////
+       // Returns list of image counts for documents in the spine.
+       public ArrayList<Integer> getImgCounts() {
+               return numImages;
+       }
+
+ ///////////////////////////////////////////////////////////////////////////////////////////
+       // Returns the list of documents that make up this book.
+       public ArrayList<String> getSpine() {
+               return epubFileList;
+       }
+ ///////////////////////////////////////////////////////////////////////////////////////////
+       // Returns a path from a particular spine element.
+       public String getSpineFilePath(int idx) {
+               return epubFileList.get(idx);
+       }

///////////////////////////////////////////////////////////////////////////////////////////
        // Simple message box for alerts and messages to user.
=======================================
--- /src/main/org/brailleblaster/perspectives/braille/views/wp/TextView.java Thu Jul 24 19:01:54 2014 UTC +++ /src/main/org/brailleblaster/perspectives/braille/views/wp/TextView.java Thu Jul 24 21:02:30 2014 UTC
@@ -103,8 +103,6 @@
        private PaintObjectListener paintObjListener;
        private int originalStart, originalEnd;
        private TextMapElement currentElement;
-       int startSelection;
-       int endSelection;

public TextView (Manager manager, Group documentWindow, BBSemanticsTable table) { super (manager, documentWindow, LEFT_MARGIN, RIGHT_MARGIN, TOP_MARGIN, BOTTOM_MARGIN, table);
@@ -119,16 +117,7 @@
                view.addSelectionListener(selectionListener = new 
SelectionAdapter(){
                        @Override
                        public void widgetSelected(SelectionEvent e) {
-
                                selectionArray = view.getSelectionRanges();
-                               //Added this part for start and end of text 
selection
-                               for (int i = 0; i < selectionArray.length-1; 
i++) {
-                                       startSelection=selectionArray[i];
-                                       
endSelection=selectionArray[i]+selectionArray[i+1];
-
-
-                            }
-                                System.out.println(startSelection+"   
"+endSelection);
                                if(selectionArray[1] > 0){
                                        setSelection(selectionArray[0], 
selectionArray[1]);
                                        currentChar = ' ';
=======================================
--- /src/main/org/brailleblaster/perspectives/imageDescriber/ImageDescriberController.java Thu Jul 24 19:01:54 2014 UTC +++ /src/main/org/brailleblaster/perspectives/imageDescriber/ImageDescriberController.java Thu Jul 24 21:02:30 2014 UTC
@@ -69,6 +69,11 @@
        // Helps with managing and manipulating images.
        ImageHelper imgHelper;

+       // Index of current file we're looking at in the browser.
+       // Current file we're to load using the spine as a reference.
+       // Spine is in .opf file in epub.
+       int curSpineFileIdx = 0;
+
///////////////////////////////////////////////////////////////////////////////////////////
        // Constructor.
public ImageDescriberController(WPManager wordProcesserManager, String fileName) {
@@ -131,7 +136,7 @@

                // If we have a Nimas file, convert to epub then push along to 
BB.
 //             if(arch instanceof NimasArchiver) {
-// arch = new EPub3Archiver(fileName, ((NimasArchiver)(arch)).convertToEPUB() );
+//                     ((NimasArchiver)(arch)).convertToEPUB();
 //             } // if(arch instanceof NimasArchiver)

                ////////////////
@@ -400,6 +405,201 @@
        public Archiver getArchiver() {
                return arch;
        }
+
+       //////////////////////////////////////////////////////////////////////
+       // Returns list of image counts for files in spine.
+       // Returns null if there is no list. Don't call
+       // unless working with EPUB3 for now.
+       public ArrayList<Integer> getImgCountList() {
+               if(arch != null)
+                       if(arch instanceof EPub3Archiver)
+                               return ((EPub3Archiver)arch).getImgCounts();
+
+               return null;
+       }
+
+       //////////////////////////////////////////////////////////////////////
+       // Return number of spine elements.
+       public int getNumSpineElements()
+       {
+               // If there is an archiver, and this archiver
+               // represents a multi-file document, return number of spine 
elements.
+               if(arch != null)
+                       if(arch instanceof EPub3Archiver)
+                               return ((EPub3Archiver)arch).getSpine().size();
+
+               // This isn't a multi-file document. Return 0.
+               return 0;
+
+       } // getNumSpineElements()
+
+       //////////////////////////////////////////////////////////////////////
+       // If working with an epub document, returns current spine file.
+       public String getCurSpineFilePath()
+       {
+               // Get current spine file path.
+               if(arch != null)
+                       if(arch instanceof EPub3Archiver)
+                               return 
((EPub3Archiver)arch).getSpineFilePath(curSpineFileIdx);
+
+               // If we get here, there is no spine path to return.
+               return null;
+
+       } // getCurSpineFile()
+
+       //////////////////////////////////////////////////////////////////////
+       // Returns the current spine index.
+       public int getCurSpineIdx() {
+               return curSpineFileIdx;
+       } // getCurSpineIdx()
+
+       //////////////////////////////////////////////////////////////////////
+       // Converts image index to a local index, in reference to
+       // a page.
+       //
+       // For example: We could be on the 56th image, but it could be the
+       // second image in this particular spine element/page.
+       //
+       // Returns -1 if we can't find it, or if there isn't a supported
+       // archiver.
+       public int getImageIndexInSpinePage(int imageIndex)
+       {
+               // Make sure there is an archiver.
+               if(arch == null)
+                       return -1;
+               if(arch instanceof EPub3Archiver == false)
+                       return -1;
+
+               // Save some typing.
+               EPub3Archiver ep3Arch = ((EPub3Archiver)arch);
+
+               // Get image counts for spine.
+               ArrayList<Integer> imgCntList = ep3Arch.getImgCounts();
+
+               // Current image index in the spine we're testing against.
+               int curImgIdx = 0;
+
+               // Add up the spine/image counts
+               for(int curS = 0; curS < curSpineFileIdx; curS++)
+                       curImgIdx += imgCntList.get(curS);
+
+               // Is this image index within range of this particular spine 
element?
+ if( imageIndex >= curImgIdx && imageIndex < curImgIdx + imgCntList.get(curSpineFileIdx) )
+               {
+                       // Move to the spine element that we've found.
+                       return imageIndex - curImgIdx;
+
+               } // if( within range )
+
+               // If we're here, we couldn't find the spine or image. Return 
failure.
+               return -1;
+       }
+
+       //////////////////////////////////////////////////////////////////////
+       // Takes an image index, and finds the spine file
+       // that contains this image.
+       public String setSpineFileWithImgIndex(int imgIndex)
+       {
+               // Make sure there is an archiver.
+               if(arch == null)
+                       return null;
+               if(arch instanceof EPub3Archiver == false)
+                       return null;
+
+               // Save some typing.
+               EPub3Archiver ep3Arch = ((EPub3Archiver)arch);
+
+               // Get image counts for spine.
+               ArrayList<Integer> imgCntList = ep3Arch.getImgCounts();
+
+               // Current image index in the spine we're testing against.
+               int curImgIdx = 0;
+
+ // Loop through the spine/image counts, until we find one that contains this image.
+               for(int curS = 0; curS < imgCntList.size(); curS++)
+               {
+                       // Is this image index within range of this particular 
spine element?
+ if( imgIndex >= curImgIdx && imgIndex < curImgIdx + imgCntList.get(curS) )
+                       {
+                               // Move to the spine element that we've found.
+                               return gotoSpineFilePath(curS);
+
+                       } // if( within range )
+
+                       // Move forward with the index.
+                       curImgIdx += imgCntList.get(curS);
+
+               } // for(curS)
+
+ // If we make it here, we couldn't find that particular spine file/element.
+               return null;
+
+       } // setSpineFileWithImgIndex()
+
+       //////////////////////////////////////////////////////////////////////
+       // Moves to a specific spine file using an index into the list.
+       public String gotoSpineFilePath(int idx)
+       {
+               // Make sure there is an archiver.
+               if(arch == null)
+                       return null;
+               if(arch instanceof EPub3Archiver == false)
+                       return null;
+
+               // Go to next file path.
+               curSpineFileIdx = idx;
+               // If we've gone too far, wrap around.
+               if(curSpineFileIdx >= ((EPub3Archiver)arch).getSpine().size())
+                       curSpineFileIdx = 0;
+               if(curSpineFileIdx < 0 )
+                       curSpineFileIdx = 
((EPub3Archiver)arch).getSpine().size() - 1;
+
+               // Return the current spine file path.
+               return ((EPub3Archiver)arch).getSpineFilePath(curSpineFileIdx);
+
+       } // gotoSpineFilePath()
+
+       //////////////////////////////////////////////////////////////////////
+       // Moves index to current file to the next one we see in the spine.
+       public String nextSpineFilePath()
+       {
+               // Make sure there is an archiver.
+               if(arch == null)
+                       return null;
+               if(arch instanceof EPub3Archiver == false)
+                       return null;
+
+               // Go to next file path.
+               curSpineFileIdx++;
+               // If we've gone too far, wrap around.
+               if(curSpineFileIdx >= ((EPub3Archiver)arch).getSpine().size())
+                       curSpineFileIdx = 0;
+
+               // Return the current spine file path.
+               return ((EPub3Archiver)arch).getSpineFilePath(curSpineFileIdx);
+
+       } // nextSpineFile()
+
+       //////////////////////////////////////////////////////////////////////
+       // Moves index to current file to the previous one we see in the spine.
+       public String prevSpineFilePath()
+       {
+               // Make sure there is an archiver.
+               if(arch == null)
+                       return null;
+               if(arch instanceof EPub3Archiver == false)
+                       return null;
+
+               // Go to previous file path.
+               curSpineFileIdx--;
+               // If we've gone too far, wrap around.
+               if(curSpineFileIdx < 0 )
+                       curSpineFileIdx = 
((EPub3Archiver)arch).getSpine().size() - 1;
+
+               // Return the current spine file path.
+               return ((EPub3Archiver)arch).getSpineFilePath(curSpineFileIdx);
+
+       } // prevSpineFile()

        /////////////////////////////////////////////////////////////////
        // Returns the image desciber "document"
@@ -445,14 +645,14 @@
                idv.setTextBox(imgDesc.getCurDescription());
                idv.setAltBox(imgDesc.getCurElmAttribute("alt"));

-//             if(arch != null){
-//                     if( arch instanceof EPub3Archiver )
-//                             idv.enableBrowserNavButtons();
-//                     else
-//                             idv.disableBrowserNavButtons();
-//             }
-//             else
-//                     idv.disableBrowserNavButtons();
+               if(arch != null){
+                       if( arch instanceof EPub3Archiver )
+                               idv.enableBrowserNavButtons();
+                       else
+                               idv.disableBrowserNavButtons();
+               }
+               else
+                       idv.disableBrowserNavButtons();
 //             if(file.endsWith(".zip")){
 //                     openZipFile(file);
 //             }
=======================================
--- /src/main/org/brailleblaster/perspectives/imageDescriber/views/ImageDescriberView.java Thu Jul 24 19:01:54 2014 UTC +++ /src/main/org/brailleblaster/perspectives/imageDescriber/views/ImageDescriberView.java Thu Jul 24 21:02:30 2014 UTC
@@ -111,7 +111,7 @@
                        int imgIndex = 
idd.getImageDescriber().getCurrentElementIndex();

                        // Is it time to move to another page/chapter?
-                       String newPath = 
idd.getArchiver().setSpineFileWithImgIndex(imgIndex);
+                       String newPath = idd.setSpineFileWithImgIndex(imgIndex);

                        // If the page needs to move/change, update.
                        // Otherwise, don't move the page yet.
@@ -144,7 +144,7 @@
                                int imgIndex = 
idd.getImageDescriber().getCurrentElementIndex();

                                // Is it time to move to another page/chapter?
-                               String newPath = 
idd.getArchiver().setSpineFileWithImgIndex(imgIndex);
+                               String newPath = 
idd.setSpineFileWithImgIndex(imgIndex);

                                // If the page needs to move/change, update.
                                // Otherwise, don't move the page yet.
@@ -248,15 +248,15 @@
                        public void widgetSelected(SelectionEvent e) {

                                // Previous page.
-                               curBrowserFilePath = 
idd.getArchiver().prevSpineFilePath();
+                               curBrowserFilePath = idd.prevSpineFilePath();

                                // Grab image count list.
-                               ArrayList<Integer> imgCntList = 
idd.getArchiver().getImgCountList();
+                               ArrayList<Integer> imgCntList = 
idd.getImgCountList();

                                // Count images in each page until we get to 
the first one
                                // on the current page/chapter.
                                int curImgIdx = 0;
-                               for(int curP = 0; curP < 
idd.getArchiver().getCurSpineIdx(); curP++)
+                               for(int curP = 0; curP < idd.getCurSpineIdx(); 
curP++)
                                        curImgIdx += imgCntList.get(curP);

                                // Set current image.
@@ -279,15 +279,15 @@
                        public void widgetSelected(SelectionEvent e) {

                                // Move to next page.
-                               curBrowserFilePath = 
idd.getArchiver().nextSpineFilePath();
+                               curBrowserFilePath = idd.nextSpineFilePath();

                                // Grab image count list.
-                               ArrayList<Integer> imgCntList = 
idd.getArchiver().getImgCountList();
+                               ArrayList<Integer> imgCntList = 
idd.getImgCountList();

                                // Count images in each page until we get to 
the first one
                                // on the current page/chapter.
                                int curImgIdx = 0;
-                               for(int curP = 0; curP < 
idd.getArchiver().getCurSpineIdx(); curP++)
+                               for(int curP = 0; curP < idd.getCurSpineIdx(); 
curP++)
                                        curImgIdx += imgCntList.get(curP);

                                // Set current image.
@@ -610,8 +610,8 @@

                // If we're dealing with a multi-file document,
                // get the index on the PAGE!!!!
-               if(idd.getArchiver().getNumSpineElements() > 0)
-                       imgIdx = 
idd.getArchiver().getImageIndexInSpinePage(imgIdx);
+               if(idd.getNumSpineElements() > 0)
+                       imgIdx = idd.getImageIndexInSpinePage(imgIdx);

                // Get the index of the current element.
                String indexStr = Integer.toString( imgIdx );
@@ -724,8 +724,8 @@
        {
         // If there are spine paths, that means there are multiple
         // files to load, and we don't need to create an html file(EPUB).
-       if(idd.getArchiver().getCurSpineFilePath() != null) {
-               curBrowserFilePath = idd.getArchiver().getCurSpineFilePath();
+       if(idd.getCurSpineFilePath() != null) {
+               curBrowserFilePath = idd.getCurSpineFilePath();
                return;
        }

@@ -759,8 +759,8 @@
        {
// If there are spine paths, then this is more than likely an EPUB document.
                // Nothing to delete.
-       if(idd.getArchiver().getCurSpineFilePath() != null) {
-               curBrowserFilePath = idd.getArchiver().getCurSpineFilePath();
+       if(idd.getCurSpineFilePath() != null) {
+               curBrowserFilePath = idd.getCurSpineFilePath();
                return;
        }


Other related posts:

  • » [brailleblaster] push by brandon....@xxxxxxxxx - reverted files that should not have been committed on 2014-07-24 21:06 GMT - brailleblaster