use of com.mucommander.ui.main.table.FileTableModel in project mucommander by mucommander.
the class OpenInBothPanelsAction method performAction.
// - Action code ---------------------------------------------------------------------
// -----------------------------------------------------------------------------------
/**
* Opens the current selection and its inactive equivalent.
*/
@Override
public void performAction() {
Thread openThread;
AbstractFile selectedFile;
AbstractFile otherFile = null;
// Retrieves the current selection, aborts if none (should not normally happen).
if ((selectedFile = mainFrame.getActiveTable().getSelectedFile(true, true)) == null || !selectedFile.isBrowsable())
return;
try {
FileTableModel otherTableModel = mainFrame.getInactiveTable().getFileTableModel();
if (mainFrame.getActiveTable().isParentFolderSelected()) {
otherFile = otherTableModel.getParentFolder();
} else {
// Look for a file in the other table with the same name as the selected one (case insensitive)
int fileCount = otherTableModel.getFileCount();
String targetFilename = selectedFile.getName();
for (int i = otherTableModel.getFirstMarkableRow(); i < fileCount; i++) {
otherFile = otherTableModel.getCachedFileAtRow(i);
if (otherFile.getName().equalsIgnoreCase(targetFilename))
break;
if (i == fileCount - 1)
otherFile = null;
}
}
} catch (Exception e) {
otherFile = null;
}
// Opens 'file' in the active panel.
openThread = mainFrame.getActivePanel().tryChangeCurrentFolder(selectedFile);
// Opens 'otherFile' (if any) in the inactive panel.
if (otherFile != null) {
// Waits for the previous folder change to be finished.
if (openThread != null) {
while (openThread.isAlive()) {
try {
openThread.join();
} catch (InterruptedException e) {
}
}
}
mainFrame.getInactivePanel().tryChangeCurrentFolder(otherFile);
}
}
use of com.mucommander.ui.main.table.FileTableModel in project mucommander by mucommander.
the class CompareFoldersAction method performAction.
@Override
public void performAction() {
FileTable leftTable = mainFrame.getLeftPanel().getFileTable();
FileTable rightTable = mainFrame.getRightPanel().getFileTable();
FileTableModel leftTableModel = leftTable.getFileTableModel();
FileTableModel rightTableModel = rightTable.getFileTableModel();
int nbFilesLeft = leftTableModel.getFileCount();
int nbFilesRight = rightTableModel.getFileCount();
int fileIndex;
String tempFileName;
AbstractFile tempFile;
for (int i = 0; i < nbFilesLeft; i++) {
tempFile = leftTableModel.getFileAt(i);
if (tempFile.isDirectory())
continue;
tempFileName = tempFile.getName();
fileIndex = -1;
for (int j = 0; j < nbFilesRight; j++) if (rightTableModel.getFileAt(j).getName().equals(tempFileName)) {
fileIndex = j;
break;
}
if (fileIndex == -1 || rightTableModel.getFileAt(fileIndex).getDate() < tempFile.getDate()) {
leftTableModel.setFileMarked(tempFile, true);
leftTable.repaint();
}
}
for (int i = 0; i < nbFilesRight; i++) {
tempFile = rightTableModel.getFileAt(i);
if (tempFile.isDirectory())
continue;
tempFileName = tempFile.getName();
fileIndex = -1;
for (int j = 0; j < nbFilesLeft; j++) if (leftTableModel.getFileAt(j).getName().equals(tempFileName)) {
fileIndex = j;
break;
}
if (fileIndex == -1 || leftTableModel.getFileAt(fileIndex).getDate() < tempFile.getDate()) {
rightTableModel.setFileMarked(tempFile, true);
rightTable.repaint();
}
}
// Notify registered listeners that currently marked files have changed on the file tables
leftTable.fireMarkedFilesChangedEvent();
rightTable.fireMarkedFilesChangedEvent();
}
use of com.mucommander.ui.main.table.FileTableModel in project mucommander by mucommander.
the class ShowFilePopupMenuAction method performAction.
@Override
public void performAction() {
try {
AbstractFile selectedFile = mainFrame.getActiveTable().getSelectedFile();
FileTable fileTable = mainFrame.getActiveTable();
FileTableModel tableModel = (FileTableModel) fileTable.getModel();
int selectedRow = fileTable.getSelectedRow();
Rectangle rect = fileTable.getCellRect(selectedRow, fileTable.convertColumnIndexToView(Column.NAME.ordinal()), true);
boolean parentFolderSelected = selectedRow == 0 && tableModel.hasParentFolder();
new TablePopupMenu(mainFrame, fileTable.getFolderPanel().getCurrentFolder(), parentFolderSelected ? null : selectedFile, parentFolderSelected, tableModel.getMarkedFiles()).show(fileTable, rect.x + rect.width, rect.y);
} catch (Exception e) {
InformationDialog.showErrorDialog(mainFrame);
}
}
use of com.mucommander.ui.main.table.FileTableModel in project mucommander by mucommander.
the class FileDragSourceListener method dragGestureRecognized.
// /**
// * Creates a custom DragGestureEvent instance re-using the information contained in the given DragGestureEvent, but
// * overridding the actions with the specified actions bitwise mask.
// * When used with <code>DragSource.startDrag</code>, this allows to start a drag operation with a different source
// * action set from the one specified in the <code>DragGestureRecognizer</code>, based on the current state and
// * contents of the FolderPanel.
// */
// private DragGestureEvent createCustomDragGestureEvent(DragGestureEvent originalDGE, int actions) {
// Vector eventList = new Vector();
// Iterator eventIterator = originalDGE.iterator();
//
// while(eventIterator.hasNext())
// eventList.add(eventIterator.next());
//
// DragGestureRecognizer dragGestureRecognizer = originalDGE.getSourceAsDragGestureRecognizer();
// dragGestureRecognizer.setSourceActions(actions);
//
// return new DragGestureEvent(dragGestureRecognizer,
// actions,
// originalDGE.getDragOrigin(),
// eventList);
// }
// ///////////////////////////////
// DragGestureListener methods //
// ///////////////////////////////
public void dragGestureRecognized(DragGestureEvent event) {
if (folderPanel.getMainFrame().getNoEventsMode())
return;
FileTable fileTable = folderPanel.getFileTable();
FileTableModel tableModel = fileTable.getFileTableModel();
// Return (do not initiate drag) if mouse button2 or button3 was used
if ((event.getTriggerEvent().getModifiers() & (InputEvent.BUTTON2_MASK | InputEvent.BUTTON3_MASK)) != 0)
return;
// Do not use that to retrieve the current selected file as it is inaccurate: the selection could have changed since the
// the mouse was clicked.
// AbstractFile selectedFile = fileTable.getSelectedFile(false);
// // Return if selected file is null (could happen if '..' is selected)
// if(selectedFile==null)
// return;
// Find out which row was clicked
int clickedRow = fileTable.rowAtPoint(event.getDragOrigin());
// Return (do not initiate drag) if the selected file is the parent folder '..'
if (clickedRow == -1 || fileTable.isParentFolder(clickedRow))
return;
// Retrieve the file corresponding to the clicked row
AbstractFile selectedFile = tableModel.getFileAtRow(clickedRow);
// Find out which files are to be dragged, based on the selected file and currenlty marked files.
// If there are some files marked, drag marked files only if the selected file is one of the marked files.
// In any other case, only drag the selected file.
FileSet markedFiles;
FileSet draggedFiles;
if (tableModel.getNbMarkedFiles() > 0 && (markedFiles = fileTable.getSelectedFiles()).contains(selectedFile)) {
draggedFiles = markedFiles;
} else {
draggedFiles = new FileSet(folderPanel.getCurrentFolder(), selectedFile);
}
// Set initial DnDContext information
DnDContext.setDragInitiatedByMucommander(true);
DnDContext.setDragInitiator(folderPanel);
DnDContext.setDragGestureModifiersEx(event.getTriggerEvent().getModifiersEx());
// Start dragging
DragSource.getDefaultDragSource().startDrag(event, null, new TransferableFileSet(draggedFiles), this);
// DragSource.getDefaultDragSource().startDrag(createCustomDragGestureEvent(event, DnDConstants.ACTION_MOVE), null, new TransferableFileSet(draggedFiles), this);
}
use of com.mucommander.ui.main.table.FileTableModel in project mucommander by mucommander.
the class StatusBar method updateSelectedFilesInfo.
/**
* Updates info about currently selected files ((nb of selected files, combined size), displayed on the left-side of this status bar.
*/
// Making this method synchronized creates a deadlock with FileTable
// public synchronized void updateSelectedFilesInfo() {
public void updateSelectedFilesInfo() {
// No need to waste precious cycles if status bar is not visible
if (!isVisible())
return;
FileTable currentFileTable = mainFrame.getActiveTable();
// Currently select file, can be null
AbstractFile selectedFile = currentFileTable.getSelectedFile(false, true);
FileTableModel tableModel = currentFileTable.getFileTableModel();
// Number of marked files, can be 0
int nbMarkedFiles = tableModel.getNbMarkedFiles();
// Combined size of marked files, 0 if no file has been marked
long markedTotalSize = tableModel.getTotalMarkedSize();
// number of files in folder
int fileCount = tableModel.getFileCount();
// Update files info based on marked files if there are some, or currently selected file otherwise
int nbSelectedFiles;
if (nbMarkedFiles == 0 && selectedFile != null)
nbSelectedFiles = 1;
else
nbSelectedFiles = nbMarkedFiles;
String filesInfo;
if (fileCount == 0) {
// Set status bar to a space character, not an empty string
// otherwise it will disappear
filesInfo = " ";
} else {
filesInfo = Translator.get("status_bar.selected_files", "" + nbSelectedFiles, "" + fileCount);
if (nbMarkedFiles > 0)
filesInfo += " - " + SizeFormat.format(markedTotalSize, selectedFileSizeFormat);
if (selectedFile != null)
filesInfo += " - " + selectedFile.getName();
}
// Update label
setStatusInfo(filesInfo);
}
Aggregations