/* * * * This file is part of Artemis * * Copyright(C) 2006 Genome Research Limited * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or(at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ package uk.ac.sanger.artemis.components.filetree; import java.io.File; import java.io.FileFilter; import java.util.Date; import java.text.SimpleDateFormat; import java.awt.Cursor; import javax.swing.JFrame; import javax.swing.tree.TreeNode; import javax.swing.tree.DefaultTreeModel; import uk.ac.sanger.artemis.components.filetree.FileNode; import uk.ac.sanger.artemis.components.filetree.RemoteFileNode; /** * * FileSystemModel is a TreeTableModel representing a hierarchical file * system. Nodes in the FileSystemModel are FileNodes which, when they * are directory nodes, cache their children to avoid repeatedly querying * the real file system. * */ public class FileSystemModel extends DefaultTreeModel { // Names of the columns. static protected String[] cNames = {"Name", "Size", "Modified"}; // Types of the columns. static protected Class[] cTypes = {TreeTableModel.class, Integer.class, String.class}; /** busy cursor */ private Cursor cbusy = new Cursor(Cursor.WAIT_CURSOR); /** done cursor */ private Cursor cdone = new Cursor(Cursor.DEFAULT_CURSOR); private FileFilter filter; private JFrame frame; SimpleDateFormat formatter = new SimpleDateFormat("MMM dd HH:mm yyyy"); public FileSystemModel(final JFrame frame) { super(new FileNode(new File(""))); this.frame = frame; filter = new FileFilter() { public boolean accept(File pathname) { if(pathname.isDirectory() || !pathname.getName().startsWith(".")) return true; return false; } }; FileNode rootNode = (FileNode)getRoot(); rootNode.setDirectory(true); rootNode.add( new FileNode(new File( System.getProperty("user.dir") )) ); rootNode.add( new FileNode(new File( System.getProperty("user.home") )) ); } public FileSystemModel(File rt[], FileFilter filter, JFrame frame) { super(new FileNode(new File(""))); this.frame = frame; this.filter = filter; FileNode rootNode = (FileNode)getRoot(); rootNode.setDirectory(true); File homeDir = new File(System.getProperty("user.home")); rootNode.add(new FileNode(homeDir)); for(int i=0; i