001: /*
002: * Lucane - a collaborative platform
003: * Copyright (C) 2005 Vincent Fiack <vfiack@mail15.com>
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: */
019:
020: package org.lucane.applications.sharedfolder.gui;
021:
022: import org.lucane.applications.sharedfolder.model.SharedItem;
023: import org.lucane.applications.sharedfolder.model.FolderInfo;
024: import org.lucane.applications.sharedfolder.model.FileInfo;
025: import org.lucane.applications.sharedfolder.SharedFolderPlugin;
026: import org.lucane.applications.sharedfolder.SharedFolderUtils;
027:
028: import javax.swing.table.AbstractTableModel;
029: import javax.swing.*;
030: import java.util.List;
031: import java.util.ArrayList;
032: import java.text.DateFormat;
033:
034: public class FolderTableModel extends AbstractTableModel {
035: private static final String[] columnsNames = { "", "col.name",
036: "col.owner", "col.created", "col.modified", "col.version",
037: "col.size" };
038: private static DateFormat format = DateFormat.getDateTimeInstance(
039: DateFormat.SHORT, DateFormat.SHORT);
040: private SharedFolderPlugin plugin;
041: private FolderInfo currentFolder;
042: private List items;
043:
044: public FolderTableModel(SharedFolderPlugin plugin) {
045: this .plugin = plugin;
046: this .items = new ArrayList();
047: }
048:
049: public void setItems(FolderInfo currentFolder, List items) {
050: this .currentFolder = currentFolder;
051: this .items = items;
052: this .fireTableDataChanged();
053: }
054:
055: public void removeItem(SharedItem item) {
056: this .items.remove(item);
057: this .fireTableDataChanged();
058: }
059:
060: public String getColumnName(int col) {
061: return plugin.tr(columnsNames[col]);
062: }
063:
064: public Class getColumnClass(int c) {
065: return c == 0 ? ImageIcon.class : String.class;
066: }
067:
068: public int getColumnCount() {
069: return columnsNames.length;
070: }
071:
072: public int getRowCount() {
073: return items.size();
074: }
075:
076: public Object getValueAt(int rowIndex, int columnIndex) {
077: SharedItem item = (SharedItem) items.get(rowIndex);
078: if (columnIndex == 0 && item.isFolder())
079: return plugin.getImageIcon("folder.png");
080: if (columnIndex == 0 && !item.isFolder())
081: return getFileIcon((FileInfo) item);
082: if (columnIndex == 1)
083: return item.getName();
084: if (columnIndex == 2)
085: return item.getOwner();
086: if (columnIndex == 3 && item.getCreationDate() != null)
087: return format.format(item.getCreationDate());
088: if (columnIndex == 4 && item.getLastModified() != null)
089: return format.format(item.getLastModified());
090: if (columnIndex == 5 && !item.isFolder())
091: return new Integer(((FileInfo) item).getVersion());
092: if (columnIndex == 6 && !item.isFolder())
093: return new Long(item.getSize());
094:
095: return "";
096: }
097:
098: public FolderInfo getCurrentFolder() {
099: return currentFolder;
100: }
101:
102: public SharedItem getItemAt(int row) {
103: return (SharedItem) items.get(row);
104: }
105:
106: private ImageIcon getFileIcon(FileInfo file) {
107: ImageIcon icon = null;
108: icon = plugin.getImageIcon(SharedFolderUtils
109: .getIconForFile(file));
110:
111: if (icon == null || icon.getIconHeight() < 0)
112: icon = plugin.getImageIcon("file.png");
113:
114: return icon;
115: }
116: }
|