package amena;


import java.awt.Color;

/**
 * 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 AbstractTreeTableModel 
                             implements TreeTableModel {

    // Names of the columns.
    static protected String[]  cNames = {"Name", "Size", "Type", "Modified"};

    // Types of the columns.
    static protected Class[]  cTypes = {TreeTableModel.class, Color.class, Color.class, Color.class};
    //static protected Color[]  cRows = {Color.white,Color.white,Color.white,Color.white};
    // The the returned file length for directories. 
    public static final Integer ZERO = new Integer(0); 

    public FileSystemModel() { 
	super(new ItemNode("Items")); 
        
    }

    //
    // Some convenience methods. 
    //

    protected String createItem(Object node) {
	ItemNode itemNode = ((ItemNode)node); 
	return itemNode.getName();       
    }

    protected Object[] getChildren(Object node) {
	ItemNode fileNode = ((ItemNode)node); 
	return fileNode.getChildren(); 
    }

    //
    // The TreeModel interface
    //

    public int getChildCount(Object node) { 
	Object[] children = getChildren(node); 
	return (children == null) ? 0 : children.length;
    }

    public Object getChild(Object node, int i) { 
	return getChildren(node)[i]; 
    }

    // The superclass's implementation would work, but this is more efficient. 
 //   public boolean isLeaf(Object node) { return getFile(node).isFile(); }

    //
    //  The TreeTableNode interface. 
    //

    public int getColumnCount() {
	return cNames.length;
    }

    public String getColumnName(int column) {
	return cNames[column];
    }

    public Class getColumnClass(int column) {
	return cTypes[column];
    }
 
    Color[][] Big2dArray={{Color.white,Color.white,Color.white,Color.white,Color.white,Color.white},
    {Color.white,Color.white,Color.white,Color.white,Color.white,Color.white},
    {Color.white,Color.white,Color.white,Color.white,Color.white,Color.white},
    {Color.white,Color.white,Color.white,Color.white,Color.white,Color.white}};

    public Object getValueAt(Object node, int column) {
	ItemNode item = new ItemNode(node); 
        int row;
        try {
            //JOptionPane
            row=0;
            return Big2dArray[row][column];
		//return Big2dArray[Integer.parseInt(mentababy.toString())][column];
	}
	catch  (SecurityException se) { }
   
	return null; 
    }

}

/* A FileNode is a derivative of the File class - though we delegate to 
 * the File object rather than subclassing it. It is used to maintain a 
 * cache of a directory's children and therefore avoid repeated access 
 * to the underlying file system during rendering. 
 */
class ItemNode { 
    String     Name; 
    ItemNode[] children; 

    public ItemNode(Object node) { 
	this.Name=node.toString();
        
    }
    
//    public ItemNode(String Name) { 
//	this.Name=Name;
//        
//    }

    // Used to sort the file names.
    static private MergeSort  fileMS = new MergeSort() {
	public int compareElementsAt(int a, int b) {
	    return ((String)toSort[a]).compareTo((String)toSort[b]);
	}
    };

    /**
     * Returns the the string to be used to display this leaf in the JTree.
     */
    public String toString() { 
	return getName();
    }

    public String getName() {
	return this.Name; 
    }
    
    public String getItem(Object node) {
        ItemNode itemNode = ((ItemNode)node); 
        return itemNode.Name; 
    }
    
//    public File getFile() {
//	return file; 
//    }
    
    static String[] get3eyaloMnDB(String Type) {            //return the children of this type in the DB
        int count=0;
        for(int i=0;i<Variable.X.length;i++)
            {
            //    JOptionPane.showMessageDialog(null,"Variable.X.length   "+Variable.X.length);
               if(Variable.X[i][0]==Type)
               { 
                 count++;
               }
            }
        int count2=0;
        String[] tempArr = new String[count];
       for(int i=0;i<Variable.X.length;i++)
            {
            //    JOptionPane.showMessageDialog(null,"Variable.X.length   "+Variable.X.length);
               if(Variable.X[i][0]==Type)
               {                    
                 tempArr[count2]=Variable.X[i][1];
          //       JOptionPane.showMessageDialog(null,"Variable.X[i][0] "+Variable.X[i][1]+" i= "+i+"    ");
                 count2++;
               }
            }
        return tempArr; 
    }
 /**
     * Loads the children, caching the results in the children ivar.
//     */
//public static String[][] X={{"Items","A1"},{"Items","A2"},
//        {"I1","I1-3"},{"I1","I1-4"},{"I1","I1-5"}
//       ,{"I2","I2-4"},{"I2","I2-5"}}; 
      protected Object[] getChildren() {
          String Type="Items";
	if (children != null) {
	    return children; 
	}
	try {
	    String[] itemsArr = ItemNode.get3eyaloMnDB(Type);            //items under that type
	    if(itemsArr != null) {
		fileMS.sort(itemsArr); 
		children = new ItemNode[itemsArr.length]; //array of ItemNodes
		//String path = file.getPath();
		for(int i = 0; i < itemsArr.length; i++) {
		    ItemNode childFile = new ItemNode(itemsArr[i]);
		    children[i] = new ItemNode(childFile);
		}
	    }
	} catch (SecurityException se) {}
	return children; 
    }
    

    private ItemNode(String aya) {
        Name=aya;
    }
}

Edited 5 Years Ago by Ezzaral: Added code tags. Please use them to format any code that you post.

Good luck getting help with that. Describe your problem, post the code related to it and use the code tags.

This article has been dead for over six months. Start a new discussion instead.