类java.awt.Desktop源码实例Demo

下面列出了怎么用java.awt.Desktop的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: views-widgets-samples   文件: CycleView.java
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();
  }
}
 
源代码2 项目: constellation   文件: BrowseContextMenu.java
@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();
        }
    }
 
源代码3 项目: jpexs-decompiler   文件: View.java
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;
}
 
源代码4 项目: snap-desktop   文件: HelpAction.java
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;
}
 
源代码5 项目: MeteoInfo   文件: FrmAbout.java
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) {
    }
}
 
源代码6 项目: keycloak   文件: KeycloakInstalled.java
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;
    }
}
 
源代码7 项目: MeteoInfo   文件: FrmAbout.java
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) {
    }
}
 
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);
}
 
源代码9 项目: torrenttunes-client   文件: DesktopApi.java
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;
		}
	}
 
源代码10 项目: aurous-app   文件: Utils.java
/**
 * 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;
		}
	}
}
 
源代码11 项目: ghidra   文件: PluginToolMacQuitHandler.java
/**
 * 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();
	});
}
 
源代码12 项目: marathonv5   文件: AddPropertiesView.java
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);
}
 
源代码13 项目: mzmine2   文件: ResultsTextPane.java
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();
          }
        }
      }
    }
  });
}
 
源代码14 项目: pcgen   文件: DesktopBrowserLauncher.java
/**
 * 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);
	}
}
 
源代码15 项目: bisq   文件: DesktopUtil.java
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;
        }
    }
 
源代码16 项目: bisq   文件: DesktopUtil.java
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;
        }
    }
 
源代码17 项目: nanoleaf-desktop   文件: SpotifyAuthenticator.java
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();
}
 
源代码18 项目: DeconvolutionLab2   文件: WebBrowser.java
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;
}
 
源代码19 项目: bladecoder-adventure-engine   文件: AssetsList.java
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);
		}
	}
}
 
源代码20 项目: bisq   文件: DesktopUtil.java
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;
        }
    }
 
源代码21 项目: proxyee-down   文件: DownApplication.java
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);
      }
    });
  }
}
 
源代码22 项目: FoxTelem   文件: DesktopApi.java
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;
        }
    }
 
源代码23 项目: xyTalk-pc   文件: ChatPanel.java
/**
 * 使用默认程序打开文件
 *
 * @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);
	}
}
 
源代码24 项目: netbeans   文件: NbURLDisplayer.java
private HtmlBrowserComponent createExternalBrowser() {
    Factory browser = IDESettings.getExternalWWWBrowser();
    if (browser == null) {
        Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
        if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
            browser = new DesktopBrowser(desktop);
        } else {
            //external browser is not available, fallback to swingbrowser
            browser = new SwingBrowser();
        }
    }
    return new HtmlBrowserComponent(browser, true, true);
}
 
源代码25 项目: pgptool   文件: CheckForUpdatesView.java
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);
}
 
源代码26 项目: drmips   文件: FrmSimulator.java
/**
 * Opens the documentation directory.
 */
public void openDocDir() {
	File docDir = new File(DrMIPS.path + File.separator + DrMIPS.DOC_DIR);
	File docDir2 = new File(DrMIPS.DOC_DIR2);
	File dir;

	if(docDir.isDirectory())
		dir = docDir;
	else if(docDir2.isDirectory())
		dir = docDir2;
	else {
		JOptionPane.showMessageDialog(this, Lang.t("doc_dir_not_found"), AppInfo.NAME, JOptionPane.ERROR_MESSAGE);
		return;
	}

	if(!Desktop.isDesktopSupported()) {
		LOG.log(Level.WARNING, "Desktop class is not supported in this system");
		JOptionPane.showMessageDialog(this, Lang.t("failed_to_open_doc_folder", dir.getAbsolutePath()), AppInfo.NAME, JOptionPane.ERROR_MESSAGE);
		return;
	}

	if(!openDocIndex(dir)) { // try to open index.html
		// if failed, try to open the directory
		try {
			Desktop.getDesktop().open(dir);
		}
		catch(Exception ex) {
			LOG.log(Level.WARNING, "error opening doc folder", ex);
			JOptionPane.showMessageDialog(this, Lang.t("failed_to_open_doc_folder", dir.getAbsolutePath()), AppInfo.NAME, JOptionPane.ERROR_MESSAGE);
		}
	}
}
 
源代码27 项目: SubTitleSearcher   文件: UpgradeCommon.java
/**
	 * 开始更新
	 */
	public static void upgrade() {
		//Runtime rt = Runtime.getRuntime();
		//StringBuffer result = new StringBuffer();
		try {
			String upgradeCmd = download();
			if(upgradeCmd == null) {
				logger.error("更新失败");
				return;
			}
			logger.info("更新命令: "+upgradeCmd);
			Desktop.getDesktop().open(new File(upgradeCmd));
			System.exit(0);
			//Process p = rt.exec(upgradeCmd);
			//p.waitFor();

//			InputStream fis = p.getInputStream();
//			InputStreamReader isr = new InputStreamReader(fis,"GBK");
//			BufferedReader br = new BufferedReader(isr);
//			String line = null;
//			while ((line = br.readLine()) != null) {
//				result.append(line);
//				result.append("\r\n");
//			}
//			logger.info(result.toString());
			
		}catch(Exception e) {
			e.printStackTrace();
		}
	}
 
源代码28 项目: WhiteRabbit   文件: RabbitInAHatMain.java
private void doOpenDocumentation() {
	try {
		Desktop desktop = Desktop.getDesktop();
		desktop.browse(new URI(DOCUMENTATION_URL));
	} catch (URISyntaxException | IOException ex) {

	}
}
 
源代码29 项目: Wurst7   文件: ForceOpDialog.java
private void openHowToUseLink()
{
	try
	{
		String howToLink =
			"https://www.wurstclient.net/Mods/Force_OP_(AuthMeCracker)/";
		
		Desktop.getDesktop().browse(URI.create(howToLink));
		
	}catch(IOException e2)
	{
		throw new RuntimeException(e2);
	}
}
 
源代码30 项目: Spark   文件: ReceiveFileTransfer.java
/**
 * Launches a file browser or opens a file with java Desktop.open() if is
 * supported
 * 
 * @param filePath
 */
private void launchFile(String filePath) {
    if (filePath == null || filePath.trim().length() == 0)
        return;
    if (!Desktop.isDesktopSupported())
        return;
    Desktop dt = Desktop.getDesktop();
    try {
 dt.browse(getFileURI(filePath));
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
 
 类所在包
 同包方法