use of com.mucommander.viewer.FileViewerService in project mucommander by mucommander.
the class ViewerRegistrar method registerFileViewers.
/**
* Registers all available viewer services for the given file type.
*
* @param file the file that will be displayed by the returned FileViewer
* @param presenter file viewer presenter to register to
* @return number of viewer services registered
* @throws UserCancelledException if the user has been asked to confirm the
* operation and canceled
*/
public static int registerFileViewers(AbstractFile file, FileViewerPresenter presenter, ViewerFrame viewerFrame) throws UserCancelledException {
int counter = 0;
boolean viewerCanceled = false;
List<FileViewerService> viewerServices = FileViewerServiceTracker.getViewerServices();
for (FileViewerService service : viewerServices) {
try {
if (service.canViewFile(file)) {
presenter.addViewerService(service);
counter++;
}
} catch (WarnUserException e) {
// TODO: question the user how does he want to open the file (as image, text..)
// Todo: display a proper warning dialog with the appropriate icon
QuestionDialog dialog = new QuestionDialog((Frame) null, Translator.get("warning"), Translator.get(e.getMessage()), viewerFrame.getMainFrame(), Arrays.asList(ViewerRegistrarAction.OPEN_ANYWAY, ViewerRegistrarAction.CANCEL), 0);
DialogAction ret = dialog.getActionValue();
if (ret == ViewerRegistrarAction.CANCEL || ret == DIALOG_DISPOSED_ACTION) {
// User canceled the operation
viewerCanceled = true;
} else {
// User confirmed the operation
presenter.addViewerService(service);
counter++;
}
}
}
if (counter == 0 && viewerCanceled) {
throw new UserCancelledException();
}
return counter;
}
use of com.mucommander.viewer.FileViewerService in project mucommander by mucommander.
the class FileViewerServiceTracker method addingService.
@Override
public FileViewerService addingService(ServiceReference<FileViewerService> reference) {
FileViewerService service = super.addingService(reference);
FileViewerServiceTracker.addViewerService(service);
LOGGER.info("FileViewerService is registered: " + service);
return service;
}
use of com.mucommander.viewer.FileViewerService in project mucommander by mucommander.
the class FileViewerPresenter method switchFileViewer.
private void switchFileViewer(int index) throws IOException {
if (fileViewer != null) {
clearComponentToPresent();
fileViewer.close();
resetTitle();
}
menuBar.removeAll();
menuBar.add(viewerMenu);
FileViewerService service = services.get(index);
fileViewer = service.createFileViewer();
fileViewer.setPresenter(this);
JComponent viewerComponent = fileViewer.getUI();
fileViewer.open(getCurrentFile());
fileViewer.extendMenu(menuBar);
menuBar.revalidate();
setComponentToPresent(viewerComponent);
}
Aggregations