Skip to content

Commit

Permalink
Amazingly enough, it all seems to work. (Level of focus!)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisleung committed Dec 6, 2007
1 parent c1ef5f5 commit 83c40fb
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 47 deletions.
106 changes: 64 additions & 42 deletions src/powerreader/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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()) {
Expand All @@ -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();
Expand All @@ -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);
}
}
}

Expand Down
22 changes: 17 additions & 5 deletions src/powerreader/PowerReaderUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions src/util/RawTextParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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){
Expand Down

0 comments on commit 83c40fb

Please sign in to comment.