use of com.mucommander.commons.file.AbstractFile in project mucommander by mucommander.
the class FileTable method sortTable.
/**
* Sorts this FileTable and repaints it. Marked files and selected file will remain the same, only
* their position will have changed in the newly sorted table.
*/
private void sortTable() {
// Save currently selected file
AbstractFile selectedFile = tableModel.getFileAtRow(currentRow);
// Sort table, doesn't affect marked files
tableModel.sortRows();
// Restore selected file
selectFile(selectedFile);
// Repaint table
repaint();
}
use of com.mucommander.commons.file.AbstractFile in project mucommander by mucommander.
the class FileTableCellRenderer method getTableCellRendererComponent.
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int rowIndex, int columnIndex) {
// ask for a row index greater than the length if the old folder contained more files
if (rowIndex < 0 || rowIndex >= tableModel.getRowCount())
return null;
// Sanity check.
AbstractFile file = tableModel.getCachedFileAtRow(rowIndex);
if (file == null) {
LOGGER.debug("tableModel.getCachedFileAtRow(" + rowIndex + ") RETURNED NULL !");
return null;
}
QuickSearch search = this.table.getQuickSearch();
boolean matches;
if (!table.hasFocus())
matches = true;
else {
if (search.isActive())
matches = search.matches(this.table.getFileNameAtRow(rowIndex));
else
matches = true;
}
// Retrieves the various indexes of the colors to apply.
// Selection only applies when the table is the active one
int selectedIndex = (isSelected && ((FileTable) table).isActiveTable()) ? ThemeCache.SELECTED : ThemeCache.NORMAL;
int focusedIndex = table.hasFocus() ? ThemeCache.ACTIVE : ThemeCache.INACTIVE;
int colorIndex = getColorIndex(rowIndex, file, tableModel);
Column column = Column.valueOf(table.convertColumnIndexToModel(columnIndex));
CellLabel label = cellLabels[column.ordinal()];
// Extension/icon column: return ImageIcon instance
if (column == Column.EXTENSION) {
// Set file icon (parent folder icon if '..' file)
label.setIcon(rowIndex == 0 && tableModel.hasParentFolder() ? IconManager.getIcon(IconManager.FILE_ICON_SET, CustomFileIconProvider.PARENT_FOLDER_ICON_NAME, FileIcons.getScaleFactor()) : FileIcons.getFileIcon(file));
} else // Any other column (name, date or size)
{
String text = (String) value;
if (matches || isSelected)
label.setForeground(ThemeCache.foregroundColors[focusedIndex][selectedIndex][colorIndex]);
else
label.setForeground(ThemeCache.unmatchedForeground);
// Set the label's text, before calculating it width
label.setText(text);
// - set a tooltip text that will display the whole text when mouse is over the label
if (table.getColumnModel().getColumn(columnIndex).getWidth() < label.getPreferredSize().getWidth()) {
String leftText = text.substring(0, text.length() / 2);
String rightText = text.substring(text.length() / 2, text.length());
while (table.getColumnModel().getColumn(columnIndex).getWidth() < label.getPreferredSize().getWidth() && leftText.length() > 0 && rightText.length() > 0) {
if (leftText.length() > rightText.length())
leftText = leftText.substring(0, leftText.length() - 1);
else
rightText = rightText.substring(1, rightText.length());
label.setText(leftText + "..." + rightText);
}
// Set the toop
label.setToolTipText(text);
} else
// Have to set it to null otherwise the defaultRender sets the tooltip text to the last one
// specified
label.setToolTipText(null);
}
// Set background color depending on whether the row is selected or not, and whether the table has focus or not
if (selectedIndex == ThemeCache.SELECTED)
label.setBackground(ThemeCache.backgroundColors[focusedIndex][ThemeCache.SELECTED], ThemeCache.backgroundColors[focusedIndex][ThemeCache.SECONDARY]);
else if (matches) {
if (table.hasFocus() && search.isActive())
label.setBackground(ThemeCache.backgroundColors[focusedIndex][ThemeCache.NORMAL]);
else
label.setBackground(ThemeCache.backgroundColors[focusedIndex][(rowIndex % 2 == 0) ? ThemeCache.NORMAL : ThemeCache.ALTERNATE]);
} else
label.setBackground(ThemeCache.unmatchedBackground);
if (selectedIndex == ThemeCache.SELECTED)
label.setOutline(table.hasFocus() ? ThemeCache.activeOutlineColor : ThemeCache.inactiveOutlineColor);
else
label.setOutline(null);
return label;
}
use of com.mucommander.commons.file.AbstractFile in project mucommander by mucommander.
the class FileTableModel method setCurrentFolder.
/**
* Sets the current folder and its children.
*
* @param folder the current folder
* @param children the current folder's children
*/
synchronized void setCurrentFolder(AbstractFile folder, AbstractFile[] children) {
int nbFiles = children.length;
this.currentFolder = (folder instanceof CachedFile) ? folder : new CachedFile(folder, true);
// Note: the returned parent is a CachedFile instance
this.parent = currentFolder.getParent();
if (parent != null) {
// Pre-fetch the attributes that are used by the table renderer and some actions.
prefetchCachedFileAttributes(parent);
}
stopSizeCalculation();
// Initialize file indexes and create CachedFile instances to speed up table display and navigation
this.cachedFiles = children;
this.fileArrayIndex = new int[nbFiles];
AbstractFile file;
for (int i = 0; i < nbFiles; i++) {
file = new CachedFile(children[i], true);
// Pre-fetch the attributes that are used by the table renderer and some actions.
prefetchCachedFileAttributes(file);
cachedFiles[i] = file;
fileArrayIndex[i] = i;
}
// Reset marked files
int nbRows = getRowCount();
this.rowMarked = new boolean[nbRows];
this.markedTotalSize = 0;
this.nbRowsMarked = 0;
// Init and fill cell cache to speed up table even more
this.cellValuesCache = new Object[nbRows][Column.values().length - 1];
fillCellCache();
}
use of com.mucommander.commons.file.AbstractFile in project mucommander by mucommander.
the class FileTableModel method processNextQueuedFile.
/**
* Takes a first ask for queue and starts calculation worker
* @param table
*/
private void processNextQueuedFile(FileTable table) {
AbstractFile nextFile;
synchronized (calculateSizeQueue) {
if (calculateSizeQueue.size() > 0) {
nextFile = calculateSizeQueue.remove(0);
} else {
nextFile = null;
}
}
if (nextFile == null) {
calculateDirectorySizeWorker = null;
table.getParent().setCursor(Cursor.getDefaultCursor());
} else {
calculateDirectorySizeWorker = new CalculateDirectorySizeWorker(this, table, nextFile);
table.getParent().setCursor(WAIT_CURSOR);
calculateDirectorySizeWorker.execute();
}
}
use of com.mucommander.commons.file.AbstractFile in project mucommander by mucommander.
the class FileTableModel method sort.
/**
* Quick sort implementation, based on James Gosling's implementation.
*/
private void sort(FileComparator fc, int lo0, int hi0) {
int lo = lo0;
int hi = hi0;
int temp;
if (lo >= hi) {
return;
} else if (lo == hi - 1) {
// sort a two element list by swapping if necessary
if (fc.compare(cachedFiles[fileArrayIndex[lo]], cachedFiles[fileArrayIndex[hi]]) > 0) {
temp = fileArrayIndex[lo];
fileArrayIndex[lo] = fileArrayIndex[hi];
fileArrayIndex[hi] = temp;
}
return;
}
// Pick a pivot and move it out of the way
int pivotIndex = fileArrayIndex[(lo + hi) / 2];
fileArrayIndex[(lo + hi) / 2] = fileArrayIndex[hi];
fileArrayIndex[hi] = pivotIndex;
AbstractFile pivot = cachedFiles[pivotIndex];
while (lo < hi) {
// is greater than the pivot or lo >= hi
while (fc.compare(cachedFiles[fileArrayIndex[lo]], pivot) <= 0 && lo < hi) {
lo++;
}
// is less than the pivot, or lo >= hi
while (fc.compare(pivot, cachedFiles[fileArrayIndex[hi]]) <= 0 && lo < hi) {
hi--;
}
// Swap elements files[lo] and files[hi]
if (lo < hi) {
temp = fileArrayIndex[lo];
fileArrayIndex[lo] = fileArrayIndex[hi];
fileArrayIndex[hi] = temp;
}
}
// Put the median in the "center" of the list
fileArrayIndex[hi0] = fileArrayIndex[hi];
fileArrayIndex[hi] = pivotIndex;
// Recursive calls, elements files[lo0] to files[lo-1] are less than or
// equal to pivot, elements files[hi+1] to files[hi0] are greater than
// pivot.
sort(fc, lo0, lo - 1);
sort(fc, hi + 1, hi0);
}
Aggregations