KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > applications > sharedfolder > gui > FolderTableModel


1 /*
2  * Lucane - a collaborative platform
3  * Copyright (C) 2005 Vincent Fiack <vfiack@mail15.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

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 JavaDoc;
29 import javax.swing.*;
30 import java.util.List JavaDoc;
31 import java.util.ArrayList JavaDoc;
32 import java.text.DateFormat JavaDoc;
33
34 public class FolderTableModel extends AbstractTableModel JavaDoc
35 {
36     private static final String JavaDoc[] columnsNames = {"", "col.name", "col.owner", "col.created",
37                                                   "col.modified", "col.version", "col.size"};
38     private static DateFormat JavaDoc format = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
39     private SharedFolderPlugin plugin;
40     private FolderInfo currentFolder;
41     private List JavaDoc items;
42
43
44     public FolderTableModel(SharedFolderPlugin plugin)
45     {
46         this.plugin = plugin;
47         this.items = new ArrayList JavaDoc();
48     }
49
50     public void setItems(FolderInfo currentFolder, List JavaDoc 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 JavaDoc getColumnName(int col)
64     {
65         return plugin.tr(columnsNames[col]);
66     }
67
68     public Class JavaDoc getColumnClass(int c)
69     {
70         return c==0 ? ImageIcon.class : String JavaDoc.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 JavaDoc 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 JavaDoc(((FileInfo)item).getVersion());
100         if(columnIndex == 6 && !item.isFolder())
101             return new Long JavaDoc(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