DirectoryTableModel.java


Dosyayı İndir
import javax.swing.table.*;
import java.io.*;
import java.util.*;
import java.text.*;
public class DirectoryTableModel extends AbstractTableModel{
  private String[] theColumnNames=new String[]{"Ad","Boyut","Değiştirilme"};
  private File theDirectory;
  private ArrayList theFileList;
  public DirectoryTableModel(File directory){
    setDirectory(directory);
  }
  public void setDirectory(File directory){
    theDirectory=directory;
    updateList();
    fireTableDataChanged();
  }
  public File getFile(int row){
    return (File)theFileList.get(row);
  }
  public int getRowCount(){
    return theFileList.size();
  }
  public int getColumnCount(){
    return 3;
  }
  public Object getValueAt(int row, int column){
    File file=(File)theFileList.get(row);
    if(column==0){
      return file;
    }else if(column==1&&!file.isDirectory()){
      long length=file.length();
      String size="";
      if(length>1024){
        size=length/1024+" kb";
      }else{
        size=length+" b";
      }
      return size;
    }else if(column==2&&!file.isDirectory()){
      return getFormattedDate(file.lastModified());
    }else{
      return "";
    }
  }
  public String getColumnName(int column){
    return theColumnNames[column];
  }
  private void updateList(){
    theFileList=new ArrayList();
    File[] theDirectoryList=theDirectory.listFiles(new FileFilter(){
      public boolean accept(File f){
        return f.isDirectory();
      }
    });
    File[] theNormalFileList=theDirectory.listFiles(new FileFilter(){
      public boolean accept(File f){
        return !f.isDirectory();
      }
    });
    for(int i=0;i<theDirectoryList.length;i++){
      theFileList.add(theDirectoryList[i]);
    }
    for(int i=0;i<theNormalFileList.length;i++){
      theFileList.add(theNormalFileList[i]);
    }
  }
  private static String getFormattedDate(long longDate){
    java.util.Date date=new Date(longDate);
    String dateOut;
    DateFormat dateFormatter;
    Locale currentLocale= new Locale("tr","TR");
    dateFormatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG,currentLocale);
    dateOut = dateFormatter.format(date);
    String dateStr= dateOut.substring(6, 10)+"-";
    dateStr= dateStr+dateOut.substring(3, 5)+"-";
    dateStr= dateStr+dateOut.substring(0, 2)+" ";
    dateStr= dateStr+dateOut.substring(11, 19);
    return dateStr;
  }
}
				
Dosyayı İndir

Bu Sayfayı Paylaş:




Bu Sayfayı Paylaş:

İletişim Bilgileri

Takip Et

Her Hakkı Saklıdır. Bu sitede yayınlanan tüm bilgi ve fikirlerin kullanımından fibiler.com sorumlu değildir. Bu sitede üretilmiş , derlenmiş içerikleri, fibiler.com'u kaynak göstermek koşuluyla kendi sitenizde kullanılabilirsiniz. Ancak telif hakkı olan içeriklerin hakları sahiplerine aittir