com.mucommander.ui.main.table
Class FileTableModel

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by com.mucommander.ui.main.table.FileTableModel
All Implemented Interfaces:
java.io.Serializable, javax.swing.table.TableModel

public class FileTableModel
extends javax.swing.table.AbstractTableModel

This class maps table cells onto file attributes.

Author:
Maxence Bernard
See Also:
Serialized Form

Field Summary
static ConfigurationListener CONFIGURATION_ADAPTER
          Listens to configuration changes and updates static fields accordingly
static java.lang.String DIRECTORY_SIZE_STRING
          String used as size information for directories
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
FileTableModel()
          Creates a new FileTableModel, without any initial current folder.
 
Method Summary
 AbstractFile getCachedFileAtRow(int rowIndex)
          Returns a CachedFile instance of the file located at the given row index.
 AbstractFile[] getCachedFiles()
          Returns the current folder's children.
 int getColumnCount()
           
 java.lang.String getColumnName(int columnIndex)
           
 AbstractFile getCurrentFolder()
          Returns the current folder, i.e.
 long getCurrentFolderDateSnapshot()
          Returns the date of the current folder, when it was set using setCurrentFolder(com.mucommander.file.AbstractFile, com.mucommander.file.AbstractFile[]).
 AbstractFile getFileAt(int fileIndex)
          Returns the file located at the given index, not including the parent file.
 AbstractFile getFileAtRow(int rowIndex)
          Returns the file located at the given row index.
 int getFileCount()
          Returns the actual number of files the current folder contains, excluding the parent '..' file (if any).
 int getFileRow(AbstractFile file)
          Returns the index of the row where the given file is located, -1 if the file is not in the current folder.
 AbstractFile[] getFiles()
          Returns the current folder's children.
 FileSet getMarkedFiles()
          Returns a FileSet with all currently marked files.
 FileSet getMarkedFiles(boolean cloneFileSet)
          Same usage as getMarkedFiles() except that it can be specified whether the returned FileSet should be cloned or not.
 int getNbMarkedFiles()
          Returns the number of marked files.
 AbstractFile getParentFolder()
          Returns the current folder's parent if there is one, null otherwise.
 int getRowCount()
          Returns the total number of rows, including the special parent folder file '..', if there is one.
 long getTotalMarkedSize()
          Returns the combined size of marked files.
 java.lang.Object getValueAt(int rowIndex, int columnIndex)
           
 boolean hasParentFolder()
          Returns true if the current folder has a parent.
 boolean isCellEditable(int rowIndex, int columnIndex)
          Returns true if name column has temporarily be made editable by FileTable and given row doesn't correspond to parent file '..', false otherwise.
 boolean isRowMarked(int row)
          Returns true if the given row is marked (/!\ not selected).
 void setFileMarked(AbstractFile file, boolean marked)
          Marks/Unmarks the given file.
 void setFilesMarked(FileFilter filter, boolean marked)
          Marks/unmarks the files that match the given FileFilter.
 void setRangeMarked(int startRow, int endRow, boolean marked)
          Marks/unmarks the given row range, delimited by the provided start row index and end row index (inclusive).
 void setRowMarked(int row, boolean marked)
          Marks/Unmarks the given row.
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getColumnClass, getListeners, getTableModelListeners, removeTableModelListener, setValueAt
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DIRECTORY_SIZE_STRING

public static final java.lang.String DIRECTORY_SIZE_STRING
String used as size information for directories

See Also:
Constant Field Values

CONFIGURATION_ADAPTER

public static final ConfigurationListener CONFIGURATION_ADAPTER
Listens to configuration changes and updates static fields accordingly

Constructor Detail

FileTableModel

public FileTableModel()
Creates a new FileTableModel, without any initial current folder.

Method Detail

getCurrentFolder

public AbstractFile getCurrentFolder()
Returns the current folder, i.e. the last folder set using setCurrentFolder(com.mucommander.file.AbstractFile, com.mucommander.file.AbstractFile[]).

Returns:
the current folder

getCurrentFolderDateSnapshot

public long getCurrentFolderDateSnapshot()
Returns the date of the current folder, when it was set using setCurrentFolder(com.mucommander.file.AbstractFile, com.mucommander.file.AbstractFile[]). In other words, the returned date is a snapshot of the current folder's date which is never updated.

Returns:
Returns the date of the current folder, when it was set using #setCurrentFolder(Abstract, Abstract[])

hasParentFolder

public boolean hasParentFolder()
Returns true if the current folder has a parent.

Returns:
true if the current folder has a parent

getParentFolder

public AbstractFile getParentFolder()
Returns the current folder's parent if there is one, null otherwise.

Returns:
the current folder's parent if there is one, null otherwise

getCachedFileAtRow

public AbstractFile getCachedFileAtRow(int rowIndex)
Returns a CachedFile instance of the file located at the given row index. This method can return the parent folder file ('..') if a parent exists and rowIndex is 0.

Returns null if rowIndex is lower than 0 or is greater than or equals getRowCount().

Parameters:
rowIndex - a row index, comprised between 0 and #getRowCount()
Returns:
a CachedFile instance of the file located at the given row index

getCachedFiles

public AbstractFile[] getCachedFiles()
Returns the current folder's children. The returned array contains CachedFile instances, where most attributes have already been fetched and cached.

Returns:
the current folder's children, as an array of CachedFile instances
See Also:
getFiles()

getFileAtRow

public AbstractFile getFileAtRow(int rowIndex)
Returns the file located at the given row index. This method can return the parent folder file ('..') if a parent exists and rowIndex is 0.

Returns null if rowIndex is lower than 0 or is greater than or equals getRowCount().

Parameters:
rowIndex - a row index, comprised between 0 and #getRowCount()
Returns:
the file located at the given row index

getFiles

public AbstractFile[] getFiles()
Returns the current folder's children. The returned array contains AbstractFile instances, and not CachedFile instances contrary to getCachedFiles().

Returns:
the current folder's children
See Also:
getCachedFiles()

getFileRow

public int getFileRow(AbstractFile file)
Returns the index of the row where the given file is located, -1 if the file is not in the current folder.

Parameters:
file - the file for which to find the row index
Returns:
the index of the row where the given file is located, -1 if the file is not in the current folder

getFileAt

public AbstractFile getFileAt(int fileIndex)
Returns the file located at the given index, not including the parent file. Returns null if fileIndex is lower than 0 or is greater than or equals getFileCount().

Parameters:
fileIndex - index of a file, comprised between 0 and #getFileCount()
Returns:
the file located at the given index, not including the parent file

getFileCount

public int getFileCount()
Returns the actual number of files the current folder contains, excluding the parent '..' file (if any).

Returns:
the actual number of files the current folder contains, excluding the parent '..' file (if any)

isRowMarked

public boolean isRowMarked(int row)
Returns true if the given row is marked (/!\ not selected). If the specified row corresponds to the special '..' parent file, false is always returned.

Parameters:
row - index of a row to test
Returns:
true if the given row is marked

setRowMarked

public void setRowMarked(int row,
                         boolean marked)
Marks/Unmarks the given row. If the specified row corresponds to the special '..' parent file, the row won't be marked.

Parameters:
row - the row to mark/unmark
marked - true to mark the row, false to unmark it

setRangeMarked

public void setRangeMarked(int startRow,
                           int endRow,
                           boolean marked)
Marks/unmarks the given row range, delimited by the provided start row index and end row index (inclusive). End row may be less, greater or equal to the start row.

Parameters:
startRow - index of the first row to mark/unmark
endRow - index of the last row to mark/ummark, startRow may be less or greater than startRow
marked - if true, all the rows within the range will be marked, unmarked otherwise

setFileMarked

public void setFileMarked(AbstractFile file,
                          boolean marked)
Marks/Unmarks the given file.

Parameters:
file - the file to mark/unmark
marked - true to mark the row, false to unmark it.

setFilesMarked

public void setFilesMarked(FileFilter filter,
                           boolean marked)
Marks/unmarks the files that match the given FileFilter.

Parameters:
filter - the FileFilter to match the files against
marked - if true, matching files will be marked, if false, they will be unmarked

getMarkedFiles

public FileSet getMarkedFiles()
Returns a FileSet with all currently marked files. The returned FileSet is a clone of the internal FileSet, so it can be safely modified.

However, it won't be kept current : the returned FileSet is just a snapshot which might not reflect the current marked files state after this method has returned and additional files have been marked/unmarked.

Returns:
the FileSet containing all the files that are currently marked

getMarkedFiles

public FileSet getMarkedFiles(boolean cloneFileSet)
Same usage as getMarkedFiles() except that it can be specified whether the returned FileSet should be cloned or not.

Not cloning the FileSet can be used for efficiency reasons when the FileSet is only accessed, but great precaution must be taken to ensure that the FileSet is never modified.

Parameters:
cloneFileSet - specifies whether the internal marked files FileSet should be cloned or not
Returns:
the FileSet containing all the files currently marked

getNbMarkedFiles

public int getNbMarkedFiles()
Returns the number of marked files. This number is pre-calculated so calling this method is much faster than retrieving the list of marked files and counting them.

Returns:
the number of marked files

getTotalMarkedSize

public long getTotalMarkedSize()
Returns the combined size of marked files. This number is pre-calculated so calling this method is much faster than retrieving the list of marked files and calculating their combined size.

Returns:
the combined size of marked files

getColumnCount

public int getColumnCount()

getColumnName

public java.lang.String getColumnName(int columnIndex)
Specified by:
getColumnName in interface javax.swing.table.TableModel
Overrides:
getColumnName in class javax.swing.table.AbstractTableModel

getRowCount

public int getRowCount()
Returns the total number of rows, including the special parent folder file '..', if there is one.


getValueAt

public java.lang.Object getValueAt(int rowIndex,
                                   int columnIndex)

isCellEditable

public boolean isCellEditable(int rowIndex,
                              int columnIndex)
Returns true if name column has temporarily be made editable by FileTable and given row doesn't correspond to parent file '..', false otherwise.

Specified by:
isCellEditable in interface javax.swing.table.TableModel
Overrides:
isCellEditable in class javax.swing.table.AbstractTableModel


This file is part of muCommander - Copyright (C) 2002-2008 Maxence Bernard