From 83c40fb1ac2f8e4bb166b3463dfa8559e3ec36c9 Mon Sep 17 00:00:00 2001 From: chrisleung Date: Thu, 6 Dec 2007 08:17:06 +0000 Subject: [PATCH] Amazingly enough, it all seems to work. (Level of focus!) --- src/powerreader/Player.java | 106 +++++++++++++++++------------ src/powerreader/PowerReaderUI.java | 22 ++++-- src/util/RawTextParser.java | 10 +++ 3 files changed, 91 insertions(+), 47 deletions(-) diff --git a/src/powerreader/Player.java b/src/powerreader/Player.java index 01f943d..29c2aa2 100644 --- a/src/powerreader/Player.java +++ b/src/powerreader/Player.java @@ -104,30 +104,43 @@ static public void setFocusLevel(int focusLevel) { } static public boolean setFocusOn(HierarchyObject hObj) { - int findOnLevel = hObj.getLevel(); - ArrayList objectsToSearch = m_instance.m_root.getAllChildrenOfLevel(findOnLevel); - Iterator it = objectsToSearch.iterator(); - int searchIndex = 0; - - while(it.hasNext()) { - Object objToTest = it.next(); - if(objToTest.equals(hObj)) { - - m_instance.m_focusLevel = findOnLevel; - m_instance.m_focusIndex = searchIndex; - - // Highlight the focused - hObj.color(true); - - // Set the objects to speach os the objects that were searched - m_instance.m_objectsToSpeak = objectsToSearch; - - // Set the index - m_instance.m_focusIndex = searchIndex; - - return true; + if(hObj.getLevel() == RawTextParser.LEVEL_DOCUMENT_ID) { + hObj.color(true); + m_instance.m_objectsToSpeak = new ArrayList(); + m_instance.m_objectsToSpeak.add(hObj); + m_instance.m_focusLevel = RawTextParser.LEVEL_DOCUMENT_ID; + m_instance.m_focusIndex = 0; + return true; + } + else { + int findOnLevel = hObj.getLevel(); + ArrayList objectsToSearch = m_instance.m_root.getAllChildrenOfLevel(findOnLevel); + Iterator it = objectsToSearch.iterator(); + int searchIndex = 0; + + while(it.hasNext()) { + Object objToTest = it.next(); + if(objToTest.equals(hObj)) { + + m_instance.m_focusLevel = findOnLevel; + m_instance.m_focusIndex = searchIndex; + + // Unhighlight everything just in case + m_instance.m_root.color(false); + + // Highlight the focused + hObj.color(true); + + // Set the objects to speach os the objects that were searched + m_instance.m_objectsToSpeak = objectsToSearch; + + // Set the index + m_instance.m_focusIndex = searchIndex; + + return true; + } + searchIndex++; } - searchIndex++; } return false; } @@ -233,7 +246,13 @@ static public void playOne() { currentObj.color(true); } - // TODO : Stop + + static public void restart(HierarchyObject root,int focusLevel) { + reset(); + m_instance.setHierarchyRoot(root); + m_instance.setFocusLevel(focusLevel); + } + static public void reset() { Speech.cancel(); if(m_instance.isAlive()) { @@ -248,6 +267,7 @@ static public Player getInstance() { static public void play() { if(m_instance.isAlive()) { + Speech.cancel(); m_instance.resume(); } else { m_instance.start(); @@ -261,24 +281,26 @@ static public void pause() { static public void disableRenderExcept(HierarchyObject object) { - // Enable depending on level of detail - if (ConfigurationManager.getDetailLevel() == RawTextParser.LEVEL_DOCUMENT_ID) { - enableRenderOfChildren(object.getParent(RawTextParser.LEVEL_DOCUMENT_ID)); - } else if(ConfigurationManager.getDetailLevel() == RawTextParser.LEVEL_PARAGRAPH_ID) { - enableRenderOfChildren(object.getParent(RawTextParser.LEVEL_PARAGRAPH_ID)); - } else if(ConfigurationManager.getDetailLevel() == RawTextParser.LEVEL_SENTENCE_ID) { - enableRenderOfChildren(object.getParent(RawTextParser.LEVEL_SENTENCE_ID)); - } - - // Disable Show depending on level of detail - if (ConfigurationManager.getDetailLevel() > RawTextParser.LEVEL_DOCUMENT_ID) { - disableRenderOfChildren(object.getParent(RawTextParser.LEVEL_DOCUMENT_ID),object.getParent(RawTextParser.LEVEL_PARAGRAPH_ID)); - } - if(ConfigurationManager.getDetailLevel() > RawTextParser.LEVEL_PARAGRAPH_ID ) { - disableRenderOfChildren(object.getParent(RawTextParser.LEVEL_PARAGRAPH_ID),object.getParent(RawTextParser.LEVEL_SENTENCE_ID)); - } - if(ConfigurationManager.getDetailLevel() > RawTextParser.LEVEL_SENTENCE_ID) { - disableRenderOfChildren(object.getParent(RawTextParser.LEVEL_SENTENCE_ID),object); + if(object.getLevel() != RawTextParser.LEVEL_DOCUMENT_ID) { + // Enable depending on level of detail + if (ConfigurationManager.getDetailLevel() == RawTextParser.LEVEL_DOCUMENT_ID) { + enableRenderOfChildren(object.getParent(RawTextParser.LEVEL_DOCUMENT_ID)); + } else if(ConfigurationManager.getDetailLevel() == RawTextParser.LEVEL_PARAGRAPH_ID) { + enableRenderOfChildren(object.getParent(RawTextParser.LEVEL_PARAGRAPH_ID)); + } else if(ConfigurationManager.getDetailLevel() == RawTextParser.LEVEL_SENTENCE_ID) { + enableRenderOfChildren(object.getParent(RawTextParser.LEVEL_SENTENCE_ID)); + } + + // Disable Show depending on level of detail + if (ConfigurationManager.getDetailLevel() > RawTextParser.LEVEL_DOCUMENT_ID) { + disableRenderOfChildren(object.getParent(RawTextParser.LEVEL_DOCUMENT_ID),object.getParent(RawTextParser.LEVEL_PARAGRAPH_ID)); + } + if(ConfigurationManager.getDetailLevel() > RawTextParser.LEVEL_PARAGRAPH_ID ) { + disableRenderOfChildren(object.getParent(RawTextParser.LEVEL_PARAGRAPH_ID),object.getParent(RawTextParser.LEVEL_SENTENCE_ID)); + } + if(ConfigurationManager.getDetailLevel() > RawTextParser.LEVEL_SENTENCE_ID) { + disableRenderOfChildren(object.getParent(RawTextParser.LEVEL_SENTENCE_ID),object); + } } } diff --git a/src/powerreader/PowerReaderUI.java b/src/powerreader/PowerReaderUI.java index d005327..64c1e1a 100644 --- a/src/powerreader/PowerReaderUI.java +++ b/src/powerreader/PowerReaderUI.java @@ -431,7 +431,22 @@ private void m_slider_lodStateChanged(javax.swing.event.ChangeEvent evt) {//GEN- }//GEN-LAST:event_m_slider_lodStateChanged private void m_slider_lofStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_m_slider_lofStateChanged - ConfigurationManager.setFocusLevel(m_slider_lof.getValue()); + int currentFocusLevel = m_slider_lof.getValue(); + ConfigurationManager.setFocusLevel(currentFocusLevel); + HierarchyObject currentObj = Player.getFocusOn(); + + Player.restart(m_hierarchyRoot,ConfigurationManager.getFocusLevel()); + + // Set the focus at the correct level now + if(currentFocusLevel < currentObj.getLevel()) { + Player.setFocusOn(currentObj.getParent(currentFocusLevel)); + } + else if (currentFocusLevel > currentObj.getLevel()) { + Player.setFocusOn((HierarchyObject)currentObj.getChildren().get(0)); + } + else { + Player.setFocusOn(currentObj); + } }//GEN-LAST:event_m_slider_lofStateChanged private void m_checkBox_showImagesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m_checkBox_showImagesActionPerformed @@ -519,10 +534,7 @@ private void startPowerReader(String file) { m_sceneRoot.addChild(m_hierarchyRoot.getBranchGroup()); - Player.reset(); - Player.setHierarchyRoot(m_hierarchyRoot); - Player.setFocusLevel(RawTextParser.LEVEL_WORD_ID); - + Player.restart(m_hierarchyRoot,ConfigurationManager.getFocusLevel()); } private void m_button_hlColorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m_button_hlColorActionPerformed diff --git a/src/util/RawTextParser.java b/src/util/RawTextParser.java index f28f3f1..ff9babb 100644 --- a/src/util/RawTextParser.java +++ b/src/util/RawTextParser.java @@ -70,6 +70,7 @@ public void parse() { String token = null; String sentenceText = new String(); String paragraphText = new String(); + String documentText = new String(); String senToken = null; HierarchyObject docuObj = new HierarchyObject(LEVEL_DOCUMENT_ID, LEVEL_DOCUMENT_STR); @@ -111,6 +112,9 @@ public void parse() { paraObj.setParents(currentParagraphParent); + // Add the paragraph to the document + documentText = documentText.concat(paragraphText); + // Clear the paragraph string paragraphText = new String(); @@ -186,16 +190,22 @@ public void parse() { // Add any more paragraphs to the document paraObj.setValue(paragraphText); + // Set the paragraph's parents paraObj.setParents(currentParagraphParent); // Add the paragraph object to list of paragraphs docuObj.addChild(paraObj); + // Complete the document text + documentText = documentText.concat(paragraphText); + docuObj.setValue(documentText); + // Set parser values m_hierarchyRoot = docuObj; m_rootNode = docuObj.getBranchGroup(); + } catch (FileNotFoundException ex) { ex.printStackTrace(); } catch (IOException ex){