/* $Id: TextTree.java 125 2011-03-09 09:49:51Z ohura $ */
package smart_gs.logical;

import java.io.File;

import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;

@SuppressWarnings("serial")
public class TextTree extends JTree{
	
	private static TextTree singleton = new TextTree();
	
	private static final String DOCUMENT_FOLDER_PATH = "./text_documents/";
	
	private DefaultMutableTreeNode root;
	
	public static TextTree getInstance(){
		return singleton;
	}
	private TextTree(){
		super(new DefaultMutableTreeNode("root"));
		
		this.root = (DefaultMutableTreeNode) ((DefaultTreeModel)this.getModel()).getRoot();
		File rootFolder = new File(DOCUMENT_FOLDER_PATH);
		this.load(root,rootFolder);
	}
	public DefaultMutableTreeNode getSelectedNode(){
		TreePath path = this.getSelectionModel().getSelectionPath();
		if(path == null){
			return this.root;
		}
		return (DefaultMutableTreeNode)path.getLastPathComponent();
	}
	private void load(DefaultMutableTreeNode parent,File file){
//		if(file.isDirectory()){
//			DefaultMutableTreeNode node = new DefaultMutableTreeNode(file.getName());
//			parent.add(node);
//			File[] files = file.listFiles();
//			for(int i=0;i<files.length;i++){
//				this.load(node, files[i]);
//			}
//		}else{
//			StandardTextDocument document = new StandardTextDocument(file);
//			DefaultMutableTreeNode node = new DefaultMutableTreeNode(document);
//			parent.add(node);
//		}
	}
}
