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;
}
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;
}
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());
}
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;
}
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);
}
}
}
Aggregations