f@0: /*
f@0: CCmI Editor - A Collaborative Cross-Modal Diagram Editing Tool
f@0:
f@0: Copyright (C) 2011 Queen Mary University of London (http://ccmi.eecs.qmul.ac.uk/)
f@0:
f@0: This program is free software: you can redistribute it and/or modify
f@0: it under the terms of the GNU General Public License as published by
f@0: the Free Software Foundation, either version 3 of the License, or
f@0: (at your option) any later version.
f@0:
f@0: This program is distributed in the hope that it will be useful,
f@0: but WITHOUT ANY WARRANTY; without even the implied warranty of
f@0: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f@0: GNU General Public License for more details.
f@0:
f@0: You should have received a copy of the GNU General Public License
f@0: along with this program. If not, see .
f@0: */
f@0:
f@0: package uk.ac.qmul.eecs.ccmi.gui.filechooser;
f@0:
f@0: import java.awt.Component;
f@0: import java.awt.event.ActionEvent;
f@0: import java.awt.event.InputEvent;
f@0: import java.awt.event.KeyEvent;
f@0: import java.awt.event.MouseEvent;
f@0: import java.io.File;
f@0: import java.io.IOException;
f@0: import java.util.LinkedList;
f@0: import java.util.ResourceBundle;
f@0:
f@0: import javax.swing.AbstractAction;
f@0: import javax.swing.JTree;
f@0: import javax.swing.KeyStroke;
f@0: import javax.swing.event.TreeSelectionEvent;
f@0: import javax.swing.event.TreeSelectionListener;
f@0: import javax.swing.filechooser.FileFilter;
f@0: import javax.swing.tree.DefaultTreeModel;
f@0: import javax.swing.tree.TreeCellRenderer;
f@0: import javax.swing.tree.TreeNode;
f@0: import javax.swing.tree.TreePath;
f@0: import javax.swing.tree.TreeSelectionModel;
f@0:
f@0: import uk.ac.qmul.eecs.ccmi.sound.PlayerListener;
f@0: import uk.ac.qmul.eecs.ccmi.sound.SoundEvent;
f@0: import uk.ac.qmul.eecs.ccmi.sound.SoundFactory;
f@0: import uk.ac.qmul.eecs.ccmi.speech.NarratorFactory;
f@0:
f@0: /*
f@0: *
f@0: * A JTree displaying the content for the local file system.
f@0: *
f@0: *
f@0: */
f@0: @SuppressWarnings("serial")
f@0: class FileSystemTree extends JTree {
f@0: FileSystemTree(FileFilter filter){
f@0: super(new DefaultTreeModel(FileSystemTreeNode.getRootNode(filter)));
f@0: getAccessibleContext().setAccessibleName(ResourceBundle.getBundle(SpeechFileChooser.class.getName()).getString("tree.accessible_name"));
f@0: getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
f@0: setCellRenderer(new FileSystemTreeCellRendered(getCellRenderer()));
f@0:
f@0: setSelectionPath(new TreePath(getModel().getRoot()));
f@0: overwriteTreeKeystrokes();
f@0: this.addTreeSelectionListener(new TreeSelectionListener(){
f@0: @Override
f@0: public void valueChanged(TreeSelectionEvent evt) {
f@0: if(treeSelectionListenerGateOpen){
f@0: FileSystemTreeNode treeNode = (FileSystemTreeNode)evt.getPath().getLastPathComponent();
f@0: NarratorFactory.getInstance().speak(treeNode.spokenText());
f@0: }
f@0: }
f@0: });
f@0: }
f@0:
f@0: @Override
f@0: public void setSelectionPath(TreePath path){
f@0: super.setSelectionPath(path);
f@0: scrollPathToVisible(path);
f@0: getSelectionPath();
f@0: }
f@0:
f@0: public void setSelectionPath(File file){
f@0: if(file == null)
f@0: return;
f@0:
f@0: try {
f@0: file = file.getCanonicalFile();
f@0: } catch (IOException e) {
f@0: setSelectionPath(new TreePath(getModel().getRoot()));
f@0: return;
f@0: }
f@0: /* make a file path: a list of file's each one representing a directory of file's path */
f@0: LinkedList filePath = new LinkedList();
f@0: filePath.add(file);
f@0: File parent = file.getParentFile();
f@0: while(parent != null){
f@0: filePath.add(0, parent);
f@0: parent = parent.getParentFile();
f@0: }
f@0: /* make a TreePath out of the file path */
f@0: FileSystemTreeNode currentNode = (FileSystemTreeNode)getModel().getRoot();
f@0: TreePath treePath = new TreePath(currentNode);
f@0: for(File f : filePath){
f@0: boolean found = false;
f@0: for(int i=0;i