📄 htablemodel.java
字号:
import java.awt.* ;import java.awt.event.* ;import java.io.* ;import java.text.* ;import java.util.* ;import javax.swing.* ;import javax.swing.event.* ;import javax.swing.table.* ;public class HTableModel extends AbstractTableModel { String fullPath ; File[] fList ; public HTableModel() { super() ; // fList=(new File(".")).listFiles(); // fullPath="."; // sortfList(); fList = ( new File( "\\" ) ).listFiles() ; fullPath = "\\" ; sortfList() ; } public HTableModel( String fString ) { super() ; fList = ( new File( fString ) ).listFiles() ; fullPath = fString ; sortfList() ; } public void setDir( String neuDir ) { fList = ( new File( neuDir ) ).listFiles() ; fullPath = neuDir ; sortfList() ; fireTableStructureChanged() ; } public int getColumnCount() { return 4 ; } public int getRowCount() { return fList.length ; } public Object getValueAt( int row , int col ) { if ( col == 0 ) { return fList[ row ].getName() ; } else if ( col == 1 ) { //return (new Boolean(fList[row].isFile())).toString(); String sAttr = "" ; // Attribut-String if ( fList[ row ].canRead() ) { sAttr += "r" ; } else { sAttr += "-" ; } if ( fList[ row ].canWrite() ) { sAttr += "w" ; } else { sAttr += "-" ; } if ( fList[ row ].isHidden() ) { sAttr += "h" ; } else { sAttr += "-" ; //if(fList[row].isDirectory()) sAttr+="D"; else sAttr+="F"; } if ( fList[ row ].isDirectory() ) { sAttr += "D" ; } else { sAttr += "-" ; } return sAttr ; } else if ( col == 2 ) { // return (new HLong(fList[row].length())).strzero(10); return ( new HLong( fList[ row ].length() ) ).strPoint() ; } else if ( col == 3 ) { // return (new Date(fList[row].lastModified())).toString(); Date dt = new Date( fList[ row ].lastModified() ) ; SimpleDateFormat df = new SimpleDateFormat( "dd.MM.yyyy-hh:mm:ss" ) ; return df.format( dt ) ; } return "" ; } public String getColumnName( int column ) { // Integer Column=new Integer(column); String[] HeaderArray = { "Dateiname" , "Attr" , "length" , "lastModified"} ; return HeaderArray[ column ] ; } public int getColumnWidth( int column ) { int[] widthArray = { 200 , 30 , 80 , 120} ; // System.out.println("getColumnWidth "+widthArray[column]); return widthArray[ column ] ; } public int getColumnAlignment( int column ) { int[] alignmentArray = { -1 , -1 , 1 , -1} ; // -1 links, 0 center, 1 rechts return alignmentArray[ column ] ; } void sortfList() { // Sortieren File-Liste if ( fList != null && fList.length > 0 ) { for ( int lauf = 0 ; lauf <= fList.length ; lauf++ ) { for ( int pos = 0 ; pos < fList.length - 1 ; pos++ ) { if ( fList[ pos ].compareTo( fList[ pos + 1 ] ) > 0 ) { File puffer = fList[ pos ] ; fList[ pos ] = fList[ pos + 1 ] ; fList[ pos + 1 ] = puffer ; } } } } } public boolean isDir( int i ) { return fList[ i ].isDirectory() ; } public String getName( int i ) { return fList[ i ].getName() ; } public String fullPath() { return fullPath ; } public String fullName( int i ) { // DateiName mit Pfad eines bestimmten Tabelleneintrages String t = fullPath ; if ( !t.substring( t.length() - 1 ).equals( "\\" ) ) { t += "\\" ; } return t + getName( i ) ; } public boolean isHidden( int i ) { // Hidden-Attribute einer Datei aus der Tabelle return fList[ i ].isHidden() ; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -