Mercurial > hg > ccmieditor
diff java/src/uk/ac/qmul/eecs/ccmi/gui/DiagramTree.java @ 2:4b2f975e35fa
Minor Bug fixes
author | Fiore Martin <fiore@eecs.qmul.ac.uk> |
---|---|
date | Mon, 06 Feb 2012 12:54:06 +0000 |
parents | 9418ab7b7f3f |
children | 9e67171477bc |
line wrap: on
line diff
--- a/java/src/uk/ac/qmul/eecs/ccmi/gui/DiagramTree.java Tue Jan 10 11:39:43 2012 +0000 +++ b/java/src/uk/ac/qmul/eecs/ccmi/gui/DiagramTree.java Mon Feb 06 12:54:06 2012 +0000 @@ -34,8 +34,6 @@ import javax.swing.KeyStroke; import javax.swing.event.TreeModelEvent; import javax.swing.event.TreeModelListener; -import javax.swing.event.TreeSelectionEvent; -import javax.swing.event.TreeSelectionListener; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.TreeNode; import javax.swing.tree.TreePath; @@ -70,24 +68,6 @@ setEditable(false); getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); overwriteTreeKeystrokes(); - this.addTreeSelectionListener(new TreeSelectionListener(){ - @Override - public void valueChanged(TreeSelectionEvent evt) { - if(treeSelectionListenerGateOpen){ - final DiagramModelTreeNode treeNode = (DiagramModelTreeNode)evt.getPath().getLastPathComponent(); - if(treeNode instanceof DiagramElement){ - SoundFactory.getInstance().play(((DiagramElement)treeNode).getSound(), new PlayerListener(){ - @Override - public void playEnded() { - NarratorFactory.getInstance().speak(treeNode.spokenText()); - } - }); - }else{ - NarratorFactory.getInstance().speak(treeNode.spokenText()); - } - } - } - }); /* don't use the swing focus system as we provide one on our own */ setFocusTraversalKeysEnabled(false); getAccessibleContext().setAccessibleName(""); @@ -168,7 +148,6 @@ public void jump(JumpTo jumpTo){ final Narrator narrator = NarratorFactory.getInstance(); TreePath oldPath; - treeSelectionListenerGateOpen = false; switch(jumpTo){ case REFERENCE : oldPath = getSelectionPath(); @@ -250,7 +229,6 @@ /* it speaks anyway as we set up the playerListener in the EditorFrame class. No need to use narrator then */ SoundFactory.getInstance().play(SoundEvent.CANCEL); InteractionLog.log(INTERACTIONLOG_SOURCE,"cancel select type to jump dialog",""); - treeSelectionListenerGateOpen = true; return; } /* we search in the root which type tree node has getName() equal to the selected one */ @@ -279,11 +257,10 @@ SoundFactory.getInstance().play(SoundEvent.ERROR ,new PlayerListener(){ @Override public void playEnded() { - narrator.speak("speech.no_bookmarks"); + narrator.speak(resources.getString("speech.no_bookmarks")); } }); InteractionLog.log(INTERACTIONLOG_SOURCE,"no bookmarks available",""); - treeSelectionListenerGateOpen = true; return; } @@ -315,7 +292,6 @@ /* it speaks anyway, as we set up the speech in the EditorFrame class. no need to use the narrator then */ SoundFactory.getInstance().play(SoundEvent.CANCEL); InteractionLog.log(INTERACTIONLOG_SOURCE,"cancel select bookmark dialog",""); - treeSelectionListenerGateOpen = true; return; } break; @@ -323,21 +299,18 @@ } InteractionLog.log(INTERACTIONLOG_SOURCE,"jumped to "+jumpTo.toString(),((DiagramModelTreeNode)getSelectionPath().getLastPathComponent()).getName()); SoundFactory.getInstance().play(SoundEvent.JUMP); - treeSelectionListenerGateOpen = true; } public void jumpTo(final DiagramElement de){ TreePath oldPath = getSelectionPath(); collapseAll((DiagramModelTreeNode)oldPath.getLastPathComponent(),de); setSelectionPath(new TreePath(de.getPath())); - treeSelectionListenerGateOpen = false; SoundFactory.getInstance().play( SoundEvent.JUMP, new PlayerListener(){ @Override public void playEnded() { NarratorFactory.getInstance().speak(MessageFormat.format(resources.getString("speech.jump"),de.spokenText())); } }); - treeSelectionListenerGateOpen = true; } /* collapse all the nodes in the path from "from" to "to" upwards(with the same direction as going from a leaf to the root)*/ @@ -354,6 +327,18 @@ //do nothing as the tree does not have to be editable with mouse } + @Override + protected void processKeyEvent(KeyEvent e){ + /* allow only cursor keys, tab key, delete, and actions (CTRL+something) */ + if(e.getKeyChar() == KeyEvent.CHAR_UNDEFINED + || e.getKeyCode() == KeyEvent.VK_TAB + || e.getKeyCode() == KeyEvent.VK_SPACE + || e.getKeyCode() == KeyEvent.VK_DELETE + || e.isControlDown() + || e.isAltDown()) + super.processKeyEvent(e); + } + private void overwriteTreeKeystrokes() { /* overwrite the keys. up and down arrow are overwritten so that it loops when the top and the */ /* bottom are reached rather than getting stuck */ @@ -375,7 +360,6 @@ nextTreeNode = (DiagramModelTreeNode)parent.getFirstChild(); loop = SoundEvent.LIST_BOTTOM_REACHED; } - treeSelectionListenerGateOpen = false; setSelectionPath(new TreePath(nextTreeNode.getPath())); final InputStream finalSound = getTreeNodeSound(nextTreeNode); final String currentPathSpeech = currentPathSpeech(); @@ -385,7 +369,6 @@ NarratorFactory.getInstance().speak(currentPathSpeech); } }); - treeSelectionListenerGateOpen = true; InteractionLog.log(INTERACTIONLOG_SOURCE,"move down",nextTreeNode.toString()); }}); @@ -404,7 +387,6 @@ previousTreeNode = (DiagramModelTreeNode)parent.getLastChild(); loop = SoundEvent.LIST_TOP_REACHED; } - treeSelectionListenerGateOpen = false; setSelectionPath(new TreePath(previousTreeNode.getPath())); final InputStream finalSound = getTreeNodeSound(previousTreeNode); final String currentPathSpeech = currentPathSpeech(); @@ -414,7 +396,6 @@ NarratorFactory.getInstance().speak(currentPathSpeech); } }); - treeSelectionListenerGateOpen = true; InteractionLog.log(INTERACTIONLOG_SOURCE,"move up",previousTreeNode.toString()); }}); @@ -429,7 +410,6 @@ InteractionLog.log(INTERACTIONLOG_SOURCE,"move right","border reached"); } else{ - treeSelectionListenerGateOpen = false; expandPath(path); setSelectionPath(new TreePath(((DiagramModelTreeNode)treeNode.getFirstChild()).getPath())); final String currentPathSpeech = currentPathSpeech(); @@ -439,7 +419,6 @@ NarratorFactory.getInstance().speak(currentPathSpeech); } }); - treeSelectionListenerGateOpen = true; InteractionLog.log(INTERACTIONLOG_SOURCE,"move right",((DiagramModelTreeNode)treeNode.getFirstChild()).toString()); } } @@ -457,7 +436,6 @@ InteractionLog.log(INTERACTIONLOG_SOURCE,"move left","border reached"); } else{ - treeSelectionListenerGateOpen = false; TreePath newPath = new TreePath(((DiagramModelTreeNode)parent).getPath()); setSelectionPath(newPath); collapsePath(newPath); @@ -469,7 +447,6 @@ } }); InteractionLog.log(INTERACTIONLOG_SOURCE,"move left",((DiagramModelTreeNode)parent).toString()); - treeSelectionListenerGateOpen = true; } } }); @@ -602,7 +579,6 @@ private List<Node> selectedNodes; private Diagram diagram; private ResourceBundle resources; - private boolean treeSelectionListenerGateOpen; private static final char SELECTED_NODE_MARK_BEGIN = '<'; private static final char SELECTED_NODE_MARK_END = '>'; private static final String INTERACTIONLOG_SOURCE = "TREE";