Search in sources :

Example 1 with FileViewerService

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;
}
Also used : Frame(java.awt.Frame) MainFrame(com.mucommander.ui.main.MainFrame) QuestionDialog(com.mucommander.ui.dialog.QuestionDialog) DialogAction(com.mucommander.ui.dialog.DialogAction) FileViewerService(com.mucommander.viewer.FileViewerService) WarnUserException(com.mucommander.viewer.WarnUserException)

Example 2 with FileViewerService

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;
}
Also used : FileViewerService(com.mucommander.viewer.FileViewerService)

Example 3 with FileViewerService

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);
}
Also used : JComponent(javax.swing.JComponent) FileViewerService(com.mucommander.viewer.FileViewerService)

Aggregations

FileViewerService (com.mucommander.viewer.FileViewerService)3 DialogAction (com.mucommander.ui.dialog.DialogAction)1 QuestionDialog (com.mucommander.ui.dialog.QuestionDialog)1 MainFrame (com.mucommander.ui.main.MainFrame)1 WarnUserException (com.mucommander.viewer.WarnUserException)1 Frame (java.awt.Frame)1 JComponent (javax.swing.JComponent)1