All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.webswing.toolkit.WebDesktopPeer Maven / Gradle / Ivy

There is a newer version: 20.2.4
Show newest version
package org.webswing.toolkit;

import java.awt.Desktop;
import java.awt.Desktop.Action;
import java.awt.peer.DesktopPeer;
import java.io.File;
import java.io.IOException;
import java.net.URI;

import org.webswing.Constants;
import org.webswing.model.internal.OpenFileResultMsgInternal;
import org.webswing.toolkit.util.Logger;
import org.webswing.toolkit.util.Util;

public class WebDesktopPeer implements DesktopPeer {


    public WebDesktopPeer(Desktop d) {
    }

    @Override
    public boolean isSupported(Action action) {
        switch (action) {
            case BROWSE:
            case MAIL:
            case EDIT:
            case OPEN:
            case PRINT:
                return true;
            default:
                return false;
        }

    }

    @Override
    public void open(File file) throws IOException {
        Logger.info("WebDesktopPeer:open", file);
        sendFile(file, false);
    }

    @Override
    public void edit(File file) throws IOException {
        Logger.info("WebDesktopPeer:edit", file);
        sendFile(file,false);
    }

    @Override
    public void print(File file) throws IOException {
        Logger.info("WebDesktopPeer:print", file);
        sendFile(file,true);
    }

    private void sendFile(File file, boolean preview) {
        Util.getWebToolkit().getPaintDispatcher().notifyFileRequested(file,preview);
    }

    @Override
    public void mail(URI mailtoURL) throws IOException {
        Util.getWebToolkit().getPaintDispatcher().notifyOpenLinkAction(mailtoURL);
    }

    @Override
    public void browse(URI url) throws IOException {
        Util.getWebToolkit().getPaintDispatcher().notifyOpenLinkAction(url);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy