1 19 20 package org.lucane.applications.sharedfolder.gui; 21 22 import org.lucane.applications.sharedfolder.model.SharedItem; 23 import org.lucane.applications.sharedfolder.model.FolderInfo; 24 import org.lucane.applications.sharedfolder.model.FileInfo; 25 import org.lucane.applications.sharedfolder.SharedFolderPlugin; 26 import org.lucane.applications.sharedfolder.SharedFolderUtils; 27 28 import javax.swing.table.AbstractTableModel ; 29 import javax.swing.*; 30 import java.util.List ; 31 import java.util.ArrayList ; 32 import java.text.DateFormat ; 33 34 public class FolderTableModel extends AbstractTableModel 35 { 36 private static final String [] columnsNames = {"", "col.name", "col.owner", "col.created", 37 "col.modified", "col.version", "col.size"}; 38 private static DateFormat format = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); 39 private SharedFolderPlugin plugin; 40 private FolderInfo currentFolder; 41 private List items; 42 43 44 public FolderTableModel(SharedFolderPlugin plugin) 45 { 46 this.plugin = plugin; 47 this.items = new ArrayList (); 48 } 49 50 public void setItems(FolderInfo currentFolder, List items) 51 { 52 this.currentFolder = currentFolder; 53 this.items = items; 54 this.fireTableDataChanged(); 55 } 56 57 public void removeItem(SharedItem item) 58 { 59 this.items.remove(item); 60 this.fireTableDataChanged(); 61 } 62 63 public String getColumnName(int col) 64 { 65 return plugin.tr(columnsNames[col]); 66 } 67 68 public Class getColumnClass(int c) 69 { 70 return c==0 ? ImageIcon.class : String .class; 71 } 72 73 public int getColumnCount() 74 { 75 return columnsNames.length; 76 } 77 78 public int getRowCount() 79 { 80 return items.size(); 81 } 82 83 public Object getValueAt(int rowIndex, int columnIndex) 84 { 85 SharedItem item = (SharedItem)items.get(rowIndex); 86 if(columnIndex == 0 && item.isFolder()) 87 return plugin.getImageIcon("folder.png"); 88 if(columnIndex == 0 && !item.isFolder()) 89 return getFileIcon((FileInfo)item); 90 if(columnIndex == 1) 91 return item.getName(); 92 if(columnIndex == 2) 93 return item.getOwner(); 94 if(columnIndex == 3 && item.getCreationDate() != null) 95 return format.format(item.getCreationDate()); 96 if(columnIndex == 4 && item.getLastModified() != null) 97 return format.format(item.getLastModified()); 98 if(columnIndex == 5 && !item.isFolder()) 99 return new Integer (((FileInfo)item).getVersion()); 100 if(columnIndex == 6 && !item.isFolder()) 101 return new Long (item.getSize()); 102 103 return ""; 104 } 105 106 public FolderInfo getCurrentFolder() 107 { 108 return currentFolder; 109 } 110 111 public SharedItem getItemAt(int row) 112 { 113 return (SharedItem)items.get(row); 114 } 115 116 private ImageIcon getFileIcon(FileInfo file) 117 { 118 ImageIcon icon = null; 119 icon = plugin.getImageIcon(SharedFolderUtils.getIconForFile(file)); 120 121 if(icon == null || icon.getIconHeight() < 0) 122 icon = plugin.getImageIcon("file.png"); 123 124 return icon; 125 } 126 } 127 | Popular Tags |