⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mytablemodel.java

📁 Java实现的explorer程序
💻 JAVA
字号:
/*
 * myTableModel.java
 *
 * Created on 2007年8月4日, 上午11:00
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package explorer;

import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
import java.io.*;
import java.io.File.*;
import java.util.*;
import javax.swing.filechooser.*;

/**
 *
 * @author king
 */
public class myTableModel extends AbstractTableModel{
    String[] title;
    Object content[][];
    Class columnType[];
    String filePath;
    Vector<File> rootVector;
    /** Creates a new instance of myTableModel */
    public myTableModel(String path) {
        filePath = path;
        columnType = new Class[]{myFile.class,String.class,String.class,String.class};
        title = new String[]{"文件名","文件大小","文件类型","修改日期"};
        this.initialContent();
    }
    
    public myTableModel(Vector<File> mVector)
    {
        filePath = "useVector";
        rootVector = mVector;
        columnType = new Class[]{myFile.class,String.class,String.class,String.class};
        title = new String[]{"文件名","文件大小","文件类型","修改日期"};
        this.initialContent();
    }
    
    public int getColumnCount(){
        return this.title.length;
    }
    
    public int getRowCount(){
        return this.content.length;
    }
    
    public Object getValueAt(int row,int col){
        return content[row][col];
    }
    
    public String getColumnName(int col){
        return title[col];
    }
    
    public Class getColumnClass(int col){
        return columnType[col];
    }
    
    public void initialContent(){
        if (filePath != "useVector")
        {
            File tempEmptyFile = new File(filePath);
            File[] allFileName = tempEmptyFile.listFiles(new Filter());
            content = new Object[allFileName.length][title.length];
            for (int i=0;i<allFileName.length;i++)
            {
                File tempFile = new myFile(allFileName[i].getAbsolutePath());
                content[i][0] = tempFile;
                if (tempFile.isFile())
                {
                    content[i][1] = new String(tempFile.length()+"字节");
                }
                content[i][2] = FileSystemView.getFileSystemView().getSystemTypeDescription(tempFile);
                long lastRepair = tempFile.lastModified();
                Date mDate = new Date(lastRepair);
                content[i][3] = new String(mDate.toString());
            }
        }
        else
        {
            content = new Object[rootVector.size()][title.length];
            for (int i=0;i<rootVector.size();i++)
            {
                File file = new myFile(rootVector.get(i).getAbsolutePath());
                content[i][0] = file;
                content[i][2] = FileSystemView.getFileSystemView().getSystemTypeDescription(rootVector.get(i));
                long lastRepair = rootVector.get(i).lastModified();
                Date mDate = new Date(lastRepair);
                content[i][3] = new String(mDate.toString());
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -