java.awt.Desktop Java Examples

The following examples show how to use java.awt.Desktop. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ChatPanel.java    From xyTalk-pc with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 使用默认程序打开文件
 *
 * @param path
 */
private void openFileWithDefaultApplication(String path) {
	try {
		Desktop.getDesktop().open(new File(path));
	} catch (IOException e1) {
		JOptionPane.showMessageDialog(null, "文件打开失败,没有找到关联的应用程序", "打开失败", JOptionPane.ERROR_MESSAGE);
		try {
			java.awt.Desktop.getDesktop().open((new File(path)).getParentFile());
		} catch (IOException e) {

		}
		e1.printStackTrace();
	} catch (IllegalArgumentException e2) {
		JOptionPane.showMessageDialog(null, "文件不存在,可能已被删除", "打开失败", JOptionPane.ERROR_MESSAGE);
	}
}
 
Example #2
Source File: CycleView.java    From views-widgets-samples with Apache License 2.0 6 votes vote down vote up
public static void save(ActionEvent e, CycleView graph) {
  int w = graph.getWidth();
  int h = graph.getHeight();
  BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
  graph.paint(img.createGraphics());
  JFileChooser chooser = new JFileChooser(new File(System.getProperty("user.home")));
  int c = chooser.showSaveDialog(graph);
  if (c == JFileChooser.CANCEL_OPTION) {
    System.out.println("cancel");
    return;
  }
  try {
    File f = chooser.getSelectedFile();
    ImageIO.write(img, "png", f);
    System.out.println(f.getAbsolutePath());

    Desktop.getDesktop().open(f.getParentFile());
  } catch (IOException e1) {
    e1.printStackTrace();
  }
}
 
Example #3
Source File: FrmAbout.java    From MeteoInfo with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void jLabel_webMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel_webMouseClicked
    // TODO add your handling code here:
    try {
        URI uri = new URI("http://www.meteothink.org");
        Desktop desktop = null;
        if (Desktop.isDesktopSupported()) {
            desktop = Desktop.getDesktop();
        }
        if (desktop != null) {
            desktop.browse(uri);
        }
    } catch (URISyntaxException ex) {
        Logger.getLogger(FrmAbout.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ioe) {
    }
}
 
Example #4
Source File: KeycloakInstalled.java    From keycloak with Apache License 2.0 6 votes vote down vote up
private void logoutDesktop() throws IOException, URISyntaxException, InterruptedException {
    CallbackListener callback = new CallbackListener();
    callback.start();

    String redirectUri = "http://localhost:" + callback.getLocalPort();

    String logoutUrl = deployment.getLogoutUrl()
            .queryParam(OAuth2Constants.REDIRECT_URI, redirectUri)
            .build().toString();

    Desktop.getDesktop().browse(new URI(logoutUrl));

    try {
        callback.await();
    } catch (InterruptedException e) {
        callback.stop();
        throw e;
    }
}
 
Example #5
Source File: View.java    From jpexs-decompiler with GNU General Public License v3.0 6 votes vote down vote up
public static boolean navigateUrl(String url) {
    if (Desktop.isDesktopSupported()) {
        Desktop desktop = Desktop.getDesktop();
        if (desktop.isSupported(Desktop.Action.BROWSE)) {
            try {
                URI uri = new URI(url);
                desktop.browse(uri);
                return true;
            } catch (URISyntaxException | IOException ex) {
                Logger.getLogger(View.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

    return false;
}
 
Example #6
Source File: HelpAction.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
private JPopupMenu createHelpMenu() {
    final JPopupMenu jsMenu = new JPopupMenu();
    final String[][] entries = new String[][]{
            {"BEAM JavaScript (BEAM Wiki)", "http://www.brockmann-consult.de/beam-wiki/display/BEAM/BEAM+JavaScript+Examples"},
            {"JavaScript Introduction (Mozilla)", "http://developer.mozilla.org/en/docs/JavaScript"},
            {"JavaScript Syntax (Wikipedia)", "http://en.wikipedia.org/wiki/JavaScript_syntax"},
    };


    for (final String[] entry : entries) {
        final String text = entry[0];
        final String target = entry[1];
        final JMenuItem menuItem = new JMenuItem(text);
        menuItem.addActionListener(e -> {
            try {
                Desktop.getDesktop().browse(new URI(target));
            } catch (IOException | URISyntaxException e1) {
                getScriptConsoleTopComponent().showErrorMessage(e1.getMessage());
            }
        });
        jsMenu.add(menuItem);
    }
    return jsMenu;
}
 
Example #7
Source File: FrmAbout.java    From MeteoInfo with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void jLabel_webMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel_webMouseClicked
    // TODO add your handling code here:
    try {
        URI uri = new URI("http://www.meteothink.org");
        Desktop desktop = null;
        if (Desktop.isDesktopSupported()) {
            desktop = Desktop.getDesktop();
        }
        if (desktop != null) {
            desktop.browse(uri);
        }
    } catch (URISyntaxException ex) {
        Logger.getLogger(FrmAbout.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ioe) {
    }
}
 
Example #8
Source File: UpdateFoundDialog.java    From universal-pokemon-randomizer with GNU General Public License v3.0 6 votes vote down vote up
private void attemptOpenBrowser() {
    String targetURL = SysConstants.WEBSITE_URL;
    Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop()
            : null;

    if (desktop == null || !desktop.isSupported(Desktop.Action.BROWSE)) {
        JOptionPane
                .showMessageDialog(
                        this,
                        "The downloads page could not be opened automatically.\n"
                                + "Open a browser and navigate to the below link to download the update:\n"
                                + targetURL);
    } else {
        try {
            desktop.browse(new URI(targetURL));
        } catch (Exception e) {
            JOptionPane
                    .showMessageDialog(
                            this,
                            "The downloads page could not be opened automatically.\n"
                                    + "Open a browser and navigate to the below link to download the update:\n"
                                    + targetURL);
        }
    }
    this.setVisible(false);
}
 
Example #9
Source File: DesktopApi.java    From torrenttunes-client with GNU General Public License v3.0 6 votes vote down vote up
private static boolean editDESKTOP(File file) {

		logOut("Trying to use Desktop.getDesktop().edit() with " + file);
		try {
			if (!Desktop.isDesktopSupported()) {
				logErr("Platform is not supported.");
				return false;
			}

			if (!Desktop.getDesktop().isSupported(Desktop.Action.EDIT)) {
				logErr("EDIT is not supported.");
				return false;
			}

			Desktop.getDesktop().edit(file);

			return true;
		} catch (Throwable t) {
			logErr("Error using desktop edit.", t);
			return false;
		}
	}
 
Example #10
Source File: Utils.java    From aurous-app with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Open a file using {@link Desktop} if supported, or a manual
 * platform-specific method if not.
 *
 * @param file
 *            The file to open.
 * @throws Exception
 *             if the file could not be opened.
 */
public static void openFile(final File file) throws Exception {
	final Desktop desktop = Desktop.isDesktopSupported() ? Desktop
			.getDesktop() : null;
	if ((desktop != null) && desktop.isSupported(Desktop.Action.OPEN)) {
		desktop.open(file);
	} else {
		final OperatingSystem system = Utils.getPlatform();
		switch (system) {
		case MAC:
		case WINDOWS:
			Utils.openURL(file.toURI().toURL());
			break;
		default:
			final String fileManager = Utils.findSupportedProgram(
					"file manager", Utils.FILE_MANAGERS);
			Runtime.getRuntime().exec(
					new String[] { fileManager, file.getAbsolutePath() });
			break;
		}
	}
}
 
Example #11
Source File: PluginToolMacQuitHandler.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * Applies a quit handler which will close the given tool.
 * 
 * @param tool The tool to close, which should result in the desired quit behavior.
 */
public static synchronized void install(PluginTool tool) {

	if (installed) {
		return;
	}
	installed = true;

	if (Platform.CURRENT_PLATFORM.getOperatingSystem() != OperatingSystem.MAC_OS_X) {
		return;
	}

	Desktop.getDesktop().setQuitHandler((evt, response) -> {
		response.cancelQuit(); // allow our tool to quit the application instead of the OS
		tool.close();
	});
}
 
Example #12
Source File: AddPropertiesView.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public AddPropertiesView(TestPropertiesInfo issueInfo) {
    this.issueInfo = issueInfo;
    initComponents();
 // @formatter:off
    Label severityLabel = new Label("Severity: ");
    severityLabel.setMinWidth(Region.USE_PREF_SIZE);
    tmsLink.setOnAction((e) -> {
        try {
            Desktop.getDesktop().browse(new URI(tmsLink.getText()));
        } catch (Exception e1) {
            FXUIUtils._showMessageDialog(null, "Unable to open link: " + tmsLink.getText(), "Unable to open link",
                    AlertType.ERROR);
            e1.printStackTrace();
        }
    });
    formPane.addFormField("Name: ", nameField)
            .addFormField("Description: ", descriptionField)
            .addFormField("ID: ", idField, severityLabel, severities);
    String tmsPattern = System.getProperty(Constants.PROP_TMS_PATTERN);
    if (tmsPattern != null && tmsPattern.length() > 0) {
        tmsLink.textProperty().bind(Bindings.format(tmsPattern, idField.textProperty()));
        formPane.addFormField("", tmsLink);
    }
    // @formatter:on
    setCenter(content);
}
 
Example #13
Source File: DesktopBrowserLauncher.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * View a URI in a browser.
 *
 * @param uri URI to display in browser.
 * @throws IOException if browser can not be launched
 */
private static void viewInBrowser(URI uri) throws IOException
{
	if (Desktop.isDesktopSupported() && DESKTOP.isSupported(Action.BROWSE))
	{
		DESKTOP.browse(uri);
	}
	else
	{
		Dialog<ButtonType> alert = GuiUtility.runOnJavaFXThreadNow(() ->  new Alert(Alert.AlertType.WARNING));
		Logging.debugPrint("unable to browse to " + uri);
		alert.setTitle(LanguageBundle.getString("in_err_browser_err"));
		alert.setContentText(LanguageBundle.getFormattedString("in_err_browser_uri", uri));
		GuiUtility.runOnJavaFXThreadNow(alert::showAndWait);
	}
}
 
Example #14
Source File: BrowseContextMenu.java    From constellation with Apache License 2.0 6 votes vote down vote up
@Override
    public void selectItem(String item, Graph graph, GraphElementType elementType, int elementId, Vector3f unprojected) {
        final ReadableGraph rg = graph.getReadableGraph();
        try {
            final int attribute = rg.getAttribute(elementType, item);
            if (attribute != Graph.NOT_FOUND) {
                final URI uri = (URI) rg.getObjectValue(attribute, elementId);
                if (uri != null) {
                    Desktop.getDesktop().browse(uri);
                    // unable to use the plugin due to a circular dependency
//                    PluginExecution.withPlugin(VisualGraphPluginRegistry.OPEN_IN_BROWSER)
//                            .withParameter(OpenInBrowserPlugin.APPLICATION_PARAMETER_ID, "Browse To")
//                            .withParameter(OpenInBrowserPlugin.URL_PARAMETER_ID, uri)
//                            .executeLater(null);
                }
            }
        } catch (IOException ex) {

        } finally {
            rg.release();
        }
    }
 
Example #15
Source File: DesktopApi.java    From FoxTelem with GNU General Public License v3.0 6 votes vote down vote up
private static boolean browseDESKTOP(URI uri) {

        logOut("Trying to use Desktop.getDesktop().browse() with " + uri.toString());
        try {
            if (!Desktop.isDesktopSupported()) {
                logErr("Platform is not supported.");
                return false;
            }

            if (!Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
                logErr("BROWSE is not supported.");
                return false;
            }

            Desktop.getDesktop().browse(uri);

            return true;
        } catch (Throwable t) {
            Log.errorDialog("Error using desktop browse.", t.getMessage() + "\nTrying: " + uri.toString());
            return false;
        }
    }
 
Example #16
Source File: DownApplication.java    From proxyee-down with Apache License 2.0 6 votes vote down vote up
public void loadUri(String uri, boolean isTray, boolean isStartup) {
  String url = "http://127.0.0.1:" + FRONT_PORT + (uri == null ? "" : uri);
  boolean autoOpen = PDownConfigContent.getInstance().get().isAutoOpen();
  if (OsUtil.isWindowsXP() || PDownConfigContent.getInstance().get().getUiMode() == 0) {
    if (!isStartup || autoOpen) {
      try {
        Desktop.getDesktop().browse(URI.create(url));
      } catch (IOException e) {
        LOGGER.error("Open browse error", e);
      }
    }

  } else {
    Platform.runLater(() -> {
      if (uri != null || !browser.isLoad()) {
        browser.load(url);
      }
      if (!isStartup || autoOpen) {
        show(isTray);
      }
    });
  }
}
 
Example #17
Source File: DesktopUtil.java    From bisq with GNU Affero General Public License v3.0 6 votes vote down vote up
private static boolean editDESKTOP(File file) {

        logOut("Trying to use Desktop.getDesktop().edit() with " + file);
        try {
            if (!Desktop.isDesktopSupported()) {
                logErr("Platform is not supported.");
                return false;
            }

            if (!Desktop.getDesktop().isSupported(Desktop.Action.EDIT)) {
                logErr("EDIT is not supported.");
                return false;
            }

            Desktop.getDesktop().edit(file);

            return true;
        } catch (Throwable t) {
            logErr("Error using desktop edit.", t);
            return false;
        }
    }
 
Example #18
Source File: AssetsList.java    From bladecoder-adventure-engine with Apache License 2.0 6 votes vote down vote up
private void edit() {
	if (Desktop.isDesktopSupported()) {
		String type = assetTypes.getSelected();
		String dir = getAssetDir(type);

		if (type.equals("images") || type.equals("atlases"))
			dir += "/1";

		try {
			Desktop.getDesktop().open(new File(dir));
		} catch (IOException e1) {
			String msg = "Something went wrong while opening assets folder.\n\n" + e1.getClass().getSimpleName()
					+ " - " + e1.getMessage();
			Message.showMsgDialog(getStage(), "Error", msg);
		}
	}
}
 
Example #19
Source File: WebBrowser.java    From DeconvolutionLab2 with GNU General Public License v3.0 6 votes vote down vote up
public static boolean open(String url) {
	Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
	if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
		try {
			desktop.browse(new URL(url).toURI());
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
		}
	}
	JFrame frame = new JFrame("Help");
	JLabel lbl = new JLabel(url);
	frame.add(lbl);
	frame.pack();
	frame.setVisible(true);	
	return false;
}
 
Example #20
Source File: SpotifyAuthenticator.java    From nanoleaf-desktop with MIT License 6 votes vote down vote up
private String getAuthCode()
		throws IOException, InterruptedException
{
	URI uri = authCodeUriRequest.execute();
	
	if (Desktop.isDesktopSupported() &&
			Desktop.getDesktop().isSupported(Desktop.Action.BROWSE))
	{
		Desktop.getDesktop().browse(uri);
	}
	
	AuthCallbackServer server = new AuthCallbackServer();
	
	while (server.getAccessToken() == null)
	{
		Thread.sleep(1000);
	}
	
	if (!server.getAccessToken().equals("error"))
	{
		startRefreshTokenTimer();
	}
	stopServer(server);
	
	return server.getAccessToken();
}
 
Example #21
Source File: DesktopUtil.java    From bisq with GNU Affero General Public License v3.0 6 votes vote down vote up
private static boolean browseDESKTOP(URI uri) {

        logOut("Trying to use Desktop.getDesktop().browse() with " + uri.toString());
        try {
            if (!Desktop.isDesktopSupported()) {
                logErr("Platform is not supported.");
                return false;
            }

            if (!Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
                logErr("BROWSE is not supported.");
                return false;
            }

            Desktop.getDesktop().browse(uri);

            return true;
        } catch (Throwable t) {
            logErr("Error using desktop browse.", t);
            return false;
        }
    }
 
Example #22
Source File: DesktopUtil.java    From bisq with GNU Affero General Public License v3.0 6 votes vote down vote up
private static boolean openDESKTOP(File file) {

        logOut("Trying to use Desktop.getDesktop().open() with " + file.toString());
        try {
            if (!Desktop.isDesktopSupported()) {
                logErr("Platform is not supported.");
                return false;
            }

            if (!Desktop.getDesktop().isSupported(Desktop.Action.OPEN)) {
                logErr("OPEN is not supported.");
                return false;
            }

            Desktop.getDesktop().open(file);

            return true;
        } catch (Throwable t) {
            logErr("Error using desktop open.", t);
            return false;
        }
    }
 
Example #23
Source File: ResultsTextPane.java    From mzmine2 with GNU General Public License v2.0 6 votes vote down vote up
public ResultsTextPane(StyledDocument doc) {
  super(doc);
  createStyles();
  setEditorKit(JTextPane.createEditorKitForContentType("text/html"));
  setEditable(false);
  addHyperlinkListener(new HyperlinkListener() {
    @Override
    public void hyperlinkUpdate(HyperlinkEvent e) {
      if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
        if (Desktop.isDesktopSupported()) {
          try {
            Desktop.getDesktop().browse(e.getURL().toURI());
          } catch (IOException | URISyntaxException e1) {
            e1.printStackTrace();
          }
        }
      }
    }
  });
}
 
Example #24
Source File: StatusPanel.java    From subsonic with GNU General Public License v3.0 5 votes vote down vote up
private void openBrowser() {
    String url = urlButton.getText();
    if (url == null) {
        return;
    }
    try {
        Desktop.getDesktop().browse(new URI(url));
    } catch (Throwable x) {
        x.printStackTrace();
    }
}
 
Example #25
Source File: ReceiveFileTransfer.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
 * Launches a file browser or opens a file with java Desktop.open() if is
 * supported
 * 
 * @param file
 */
private void launchFile(File file) {
    if (!Desktop.isDesktopSupported())
        return;
    Desktop dt = Desktop.getDesktop();
    try {
        dt.open(file);
    } catch (IOException ex) {
        launchFile(file.getPath());
    }
}
 
Example #26
Source File: GuiMain.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static JMenu makeHelpMenu() {
    if (!Desktop.isDesktopSupported()) return null;
    final Desktop desktop = Desktop.getDesktop();
    if (!desktop.isSupported(Desktop.Action.BROWSE)) return null;

    JMenu help = new JMenu("Help");
    help.setMnemonic(KeyEvent.VK_H);
    JMenuItem onlineHelp = new JMenuItem(new OnlineHelpAction());
    help.add(onlineHelp);

    return help;
}
 
Example #27
Source File: SessionInformationsPanel.java    From javamelody with Apache License 2.0 5 votes vote down vote up
final void actionPdf() throws IOException {
	final File tempFile = createTempFileForPdf();
	final PdfOtherReport pdfOtherReport = createPdfOtherReport(tempFile);
	try {
		pdfOtherReport.writeSessionInformations(sessionsInformations);
	} finally {
		pdfOtherReport.close();
	}
	Desktop.getDesktop().open(tempFile);
}
 
Example #28
Source File: CheckForUpdatesView.java    From pgptool with GNU General Public License v3.0 5 votes vote down vote up
private void initSiteLink(JLabel label, MouseListener mouseListener) {
	if (!Desktop.isDesktopSupported() || !Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
		return;
	}

	label.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
	label.setForeground(Color.blue);
	label.addMouseListener(mouseListener);
}
 
Example #29
Source File: App.java    From SikuliX1 with MIT License 5 votes vote down vote up
public static boolean openLink(String url) {
  if (!Desktop.isDesktopSupported()) {
    return false;
  }
  try {
    Desktop.getDesktop().browse(new URL(url).toURI());
  } catch (Exception ex) {
    return false;
  }
  return true;
}
 
Example #30
Source File: AboutPm.java    From pgptool with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e) {
	super.actionPerformed(e);
	try {
		Desktop.getDesktop().browse(new URI(urlToSite));
	} catch (Throwable t) {
		EntryPoint.reportExceptionToUser(e, "exception.unexpected", t);
	}
	host.handleClose();
}