Search in sources :

Example 1 with Desktop

use of java.awt.Desktop in project screenbird by adamhub.

the class MediaUtil method playVideo.

public static boolean playVideo(String pathToVideo) {
    boolean result = true;
    if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.OPEN)) {
        try {
            Desktop d = Desktop.getDesktop();
            d.open(new File(pathToVideo));
        } catch (IOException ex) {
            if (MediaUtil.osIsWindows()) {
                try {
                    // Runtime.getRuntime().exec(System.getenv("ProgramFiles")+"\\Windows Media Player\\wmplayer.exe "+this.outputMovieFilename);
                    Runtime.getRuntime().exec("cmd /c \"start " + pathToVideo);
                } catch (Exception ex1) {
                    result = false;
                }
            } else {
                result = false;
            }
        }
    } else {
        result = false;
    }
    return result;
}
Also used : Desktop(java.awt.Desktop) IOException(java.io.IOException) File(java.io.File) IOException(java.io.IOException)

Example 2 with Desktop

use of java.awt.Desktop in project adempiere by adempiere.

the class Attachment method openAttachment.

//	saveAttachmentToFile
/**
	 *	Open the temporary file with the application associated with the extension in the file name
	 *	@return true if file was opened with third party application
	 */
private boolean openAttachment() {
    int index = cbContent.getSelectedIndex();
    byte[] data = m_attachment.getEntryData(index);
    if (data == null)
        return false;
    try {
        String fileName = System.getProperty("java.io.tmpdir") + System.getProperty("file.separator") + m_attachment.getEntryName(index);
        File tempFile = new File(fileName);
        m_attachment.getEntryFile(index, tempFile);
        if (Env.isWindows()) {
            //	Runtime.getRuntime().exec ("rundll32 url.dll,FileProtocolHandler " + url);
            Process p = Runtime.getRuntime().exec("rundll32 SHELL32.DLL,ShellExec_RunDLL \"" + tempFile + "\"");
            //	p.waitFor();
            return true;
        } else if (Env.isMac()) {
            String[] cmdArray = new String[] { "open", tempFile.getAbsolutePath() };
            Process p = Runtime.getRuntime().exec(cmdArray);
            //	p.waitFor();
            return true;
        } else //	other OS. originally nothing here. add the following codes
        {
            try {
                Desktop desktop = null;
                if (Desktop.isDesktopSupported()) {
                    desktop = Desktop.getDesktop();
                    File file = new File(tempFile.getAbsolutePath());
                    desktop.open(file);
                    return true;
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    } catch (Exception e) {
        log.log(Level.SEVERE, "", e);
    }
    return false;
}
Also used : Desktop(java.awt.Desktop) IOException(java.io.IOException) File(java.io.File) IOException(java.io.IOException)

Example 3 with Desktop

use of java.awt.Desktop in project jabref by JabRef.

the class SendAsEMailAction method run.

@Override
public void run() {
    if (!Desktop.isDesktopSupported()) {
        message = Localization.lang("Error creating email");
        return;
    }
    BasePanel panel = frame.getCurrentBasePanel();
    if (panel == null) {
        return;
    }
    if (panel.getSelectedEntries().isEmpty()) {
        message = Localization.lang("This operation requires one or more entries to be selected.");
        return;
    }
    StringWriter sw = new StringWriter();
    List<BibEntry> bes = panel.getSelectedEntries();
    // write the entries using sw, which is used later to form the email content
    BibEntryWriter bibtexEntryWriter = new BibEntryWriter(new LatexFieldFormatter(Globals.prefs.getLatexFieldFormatterPreferences()), true);
    for (BibEntry entry : bes) {
        try {
            bibtexEntryWriter.write(entry, sw, panel.getBibDatabaseContext().getMode());
        } catch (IOException e) {
            LOGGER.warn("Problem creating BibTeX file for mailing.", e);
        }
    }
    List<String> attachments = new ArrayList<>();
    // open folders is needed to indirectly support email programs, which cannot handle
    //   the unofficial "mailto:attachment" property
    boolean openFolders = JabRefPreferences.getInstance().getBoolean(JabRefPreferences.OPEN_FOLDERS_OF_ATTACHED_FILES);
    List<Path> fileList = FileUtil.getListOfLinkedFiles(bes, frame.getCurrentBasePanel().getBibDatabaseContext().getFileDirectoriesAsPaths(Globals.prefs.getFileDirectoryPreferences()));
    for (Path f : fileList) {
        attachments.add(f.toAbsolutePath().toString());
        if (openFolders) {
            try {
                JabRefDesktop.openFolderAndSelectFile(f.toAbsolutePath());
            } catch (IOException e) {
                LOGGER.debug("Cannot open file", e);
            }
        }
    }
    String mailTo = "?Body=".concat(sw.getBuffer().toString());
    mailTo = mailTo.concat("&Subject=");
    mailTo = mailTo.concat(JabRefPreferences.getInstance().get(JabRefPreferences.EMAIL_SUBJECT));
    for (String path : attachments) {
        mailTo = mailTo.concat("&Attachment=\"").concat(path);
        mailTo = mailTo.concat("\"");
    }
    URI uriMailTo;
    try {
        uriMailTo = new URI("mailto", mailTo, null);
    } catch (URISyntaxException e1) {
        message = Localization.lang("Error creating email");
        LOGGER.warn(message, e1);
        return;
    }
    Desktop desktop = Desktop.getDesktop();
    try {
        desktop.mail(uriMailTo);
    } catch (IOException e) {
        message = Localization.lang("Error creating email");
        LOGGER.warn(message, e);
        return;
    }
    message = String.format("%s: %d", Localization.lang("Entries added to an email"), bes.size());
}
Also used : Path(java.nio.file.Path) BibEntry(org.jabref.model.entry.BibEntry) BasePanel(org.jabref.gui.BasePanel) ArrayList(java.util.ArrayList) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) BibEntryWriter(org.jabref.logic.bibtex.BibEntryWriter) URI(java.net.URI) LatexFieldFormatter(org.jabref.logic.bibtex.LatexFieldFormatter) StringWriter(java.io.StringWriter) Desktop(java.awt.Desktop) JabRefDesktop(org.jabref.gui.desktop.JabRefDesktop)

Example 4 with Desktop

use of java.awt.Desktop in project beast-mcmc by beast-dev.

the class Utils method isBrowsingSupported.

// END: CreateImageIcon
public static boolean isBrowsingSupported() {
    if (!Desktop.isDesktopSupported()) {
        return false;
    }
    boolean result = false;
    Desktop desktop = java.awt.Desktop.getDesktop();
    if (desktop.isSupported(Desktop.Action.BROWSE)) {
        result = true;
    }
    return result;
}
Also used : Desktop(java.awt.Desktop)

Example 5 with Desktop

use of java.awt.Desktop in project languagetool by languagetool-org.

the class ResultAreaHelper method handleHttpClick.

private void handleHttpClick(URL url) {
    if (Desktop.isDesktopSupported()) {
        try {
            Desktop desktop = Desktop.getDesktop();
            desktop.browse(url.toURI());
        } catch (Exception ex) {
            throw new RuntimeException("Could not open URL: " + url, ex);
        }
    }
}
Also used : Desktop(java.awt.Desktop) IOException(java.io.IOException) BadLocationException(javax.swing.text.BadLocationException)

Aggregations

Desktop (java.awt.Desktop)13 IOException (java.io.IOException)10 URI (java.net.URI)6 File (java.io.File)3 URISyntaxException (java.net.URISyntaxException)3 ROMFormatUnsupportedException (org.javatari.atari.cartridge.ROMFormatUnsupportedException)2 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)1 FileNotFoundException (java.io.FileNotFoundException)1 StringWriter (java.io.StringWriter)1 SocketException (java.net.SocketException)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 BadLocationException (javax.swing.text.BadLocationException)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Button (org.eclipse.swt.widgets.Button)1