java.awt.Desktop#isSupported ( )源码实例Demo

下面列出了java.awt.Desktop#isSupported ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: 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;
}
 
源代码2 项目: 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;
		}
	}
}
 
源代码3 项目: HBaseClient   文件: MenuSupportAction.java
@Override
public void onClick(ActionEvent arg0)
{
    try
    {
        URI     v_URI     = URI.create(AppMain.$SourceCode);
        Desktop v_Desktop = Desktop.getDesktop();
        
        // 判断系统桌面是否支持要执行的功能
        if ( v_Desktop.isSupported(Desktop.Action.BROWSE) )
        {
            // 获取系统默认浏览器打开链接
            v_Desktop.browse(v_URI);
        }
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
}
 
源代码4 项目: 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;
}
 
源代码5 项目: gcs   文件: ShowLibraryFolderCommand.java
@Override
public void actionPerformed(ActionEvent event) {
    try {
        File    dir     = mLibrary.getPath().toFile();
        Desktop desktop = Desktop.getDesktop();
        if (desktop.isSupported(Action.BROWSE_FILE_DIR)) {
            File[] contents = dir.listFiles();
            if (contents != null && contents.length > 0) {
                Arrays.sort(contents);
                dir = contents[0];
            }
            desktop.browseFileDirectory(dir.getCanonicalFile());
        } else {
            desktop.open(dir);
        }
    } catch (Exception exception) {
        WindowUtils.showError(null, exception.getMessage());
    }
}
 
源代码6 项目: 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;
				}
			}
}
 
源代码7 项目: runelite   文件: LinkBrowser.java
private static boolean attemptDesktopBrowse(String url)
{
	if (!Desktop.isDesktopSupported())
	{
		return false;
	}

	final Desktop desktop = Desktop.getDesktop();

	if (!desktop.isSupported(Desktop.Action.BROWSE))
	{
		return false;
	}

	try
	{
		desktop.browse(new URI(url));
		return true;
	}
	catch (IOException | URISyntaxException ex)
	{
		log.warn("Failed to open Desktop#browse {}", url, ex);
		return false;
	}
}
 
源代码8 项目: karamel   文件: KaramelServiceApplication.java
public synchronized static void openWebpage(URI uri) {
  Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
  if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
    try {
      desktop.browse(uri);
    } catch (Exception e) {
      e.printStackTrace();
    }
  } else {
    logger.error("Brower UI could not be launched using Java's Desktop library. "
      + "Are you running a window manager?");
    logger.error("If you are using Ubuntu, try: sudo apt-get install libgnome");
    logger.error("Retrying to launch the browser now using a different method.");
    BareBonesBrowserLaunch.openURL(uri.toASCIIString());
  }
}
 
源代码9 项目: datasync   文件: Utils.java
/**
 * Open given uri in local web browser
 * @param uri to open in browser
 */
public static void openWebpage(URI uri) {
    Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
    if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
        try {
            desktop.browse(uri);
        } catch (Exception e) {
            System.out.println("Error: cannot open web page");
        }
    }
}
 
源代码10 项目: CPE552-Java   文件: LinktoURL.java
public static void main(String[] args) throws Exception {
    URI uri = new URI("http://www.nytimes.com");
    Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
    if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
        desktop.browse(uri);
    }
}
 
源代码11 项目: Game   文件: Utils.java
public static void openWebpage(final String url) {
	final Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
	if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
		try {
			desktop.browse(new URL(url).toURI());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
 
源代码12 项目: pcgen   文件: DesktopHandler.java
/**
 * Initialize the Mac-specific properties.
 * Create an ApplicationAdapter to listen for Help, Prefs, and Quit.
 */
public static void initialize()
{
	if (initialized)
	{
		return;
	}
	initialized = true;

	if (!Desktop.isDesktopSupported())
	{
		return;
	}

	Desktop theDesktop = Desktop.getDesktop();
	if (theDesktop.isSupported(Action.APP_ABOUT))
	{
		theDesktop.setAboutHandler(new AboutHandler());
	}
	if (theDesktop.isSupported(Action.APP_PREFERENCES))
	{
		theDesktop.setPreferencesHandler(new PreferencesHandler());
	}
	if (theDesktop.isSupported(Action.APP_QUIT_HANDLER))
	{
		theDesktop.setQuitHandler(new QuitHandler());
	}
}
 
源代码13 项目: jeddict   文件: SharingHelper.java
public static void openWebpage(String url) {
    Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
    if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
        try {
            desktop.browse(URI.create(url));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
 
源代码14 项目: amidst   文件: UpdatePrompt.java
@CalledOnlyBy(AmidstThread.EDT)
private void openURL(URI uri) throws IOException, UnsupportedOperationException {
	if (Desktop.isDesktopSupported()) {
		Desktop desktop = Desktop.getDesktop();
		if (desktop.isSupported(Desktop.Action.BROWSE)) {
			desktop.browse(uri);
		} else {
			throw new UnsupportedOperationException("Unable to open browser page.");
		}
	} else {
		throw new UnsupportedOperationException("Unable to open browser.");
	}
}
 
源代码15 项目: beast-mcmc   文件: Utils.java
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;

}
 
源代码16 项目: rest-client   文件: AppUpdateRunner.java
private void openUrl(String url) {
    Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
    if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
        try {
            desktop.browse(new URI(url));
        }
        catch(URISyntaxException | IOException ex) {
            LOG.log(Level.INFO, "Error when opening browser", ex);
        }
    }
}
 
源代码17 项目: jeveassets   文件: DesktopUtil.java
private static boolean isSupported(final Desktop.Action action) {
	if (Desktop.isDesktopSupported()) {
		Desktop desktop = Desktop.getDesktop();
		if (desktop.isSupported(action)) {
			return true;
		}
	}
	return false;
}
 
源代码18 项目: WorldGrower   文件: CreditsDialog.java
private static void openWebPage(URI uri) {
    Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
    if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
        try {
            desktop.browse(uri);
        } catch (IOException e) {
            throw new IllegalStateException("Problem opening " + uri.toString(), e);
        }
    }
}
 
源代码19 项目: mzmine3   文件: DesktopSetup.java
@Override
public void run() {

  logger.finest("Configuring desktop settings");

  // Set basic desktop handlers
  final Desktop awtDesktop = Desktop.getDesktop();
  if (awtDesktop != null) {

    // Setup About handler
    if (awtDesktop.isSupported(Desktop.Action.APP_ABOUT)) {
      awtDesktop.setAboutHandler(e -> {
        MZmineGUI.showAboutWindow();
      });
    }

    // Setup Quit handler
    if (awtDesktop.isSupported(Desktop.Action.APP_QUIT_HANDLER)) {
      awtDesktop.setQuitHandler((e, response) -> {
        ExitCode exitCode = MZmineCore.getDesktop().exitMZmine();
        if (exitCode == ExitCode.OK)
          response.performQuit();
        else
          response.cancelQuit();
      });
    }
  }

  if (Taskbar.isTaskbarSupported()) {

    final Taskbar taskBar = Taskbar.getTaskbar();

    // Set the main app icon
    if ((mzMineIcon != null) && taskBar.isSupported(Taskbar.Feature.ICON_IMAGE)) {
      final java.awt.Image mzMineIconAWT = SwingFXUtils.fromFXImage(mzMineIcon, null);
      taskBar.setIconImage(mzMineIconAWT);
    }

    // Add a task controller listener to show task progress
    MZmineCore.getTaskController().addTaskControlListener((numOfWaitingTasks, percentDone) -> {
      if (numOfWaitingTasks > 0) {
        if (taskBar.isSupported(Taskbar.Feature.ICON_BADGE_NUMBER)) {
          String badge = String.valueOf(numOfWaitingTasks);
          taskBar.setIconBadge(badge);
        }

        if (taskBar.isSupported(Taskbar.Feature.PROGRESS_VALUE))
          taskBar.setProgressValue(percentDone);

      } else {

        if (taskBar.isSupported(Taskbar.Feature.ICON_BADGE_NUMBER))
          taskBar.setIconBadge(null);
        /*
         * if (taskBar.isSupported( Taskbar.Feature.PROGRESS_STATE_WINDOW))
         * taskBar.setWindowProgressState( MZmineCore.getDesktop().getMainWindow(),
         * Taskbar.State.OFF);
         */
        if (taskBar.isSupported(Taskbar.Feature.PROGRESS_VALUE))
          taskBar.setProgressValue(-1);
        /*
         * if (taskBar.isSupported( Taskbar.Feature.PROGRESS_VALUE_WINDOW))
         * taskBar.setWindowProgressValue( MZmineCore.getDesktop().getMainWindow(), -1);
         */
      }
    });

  }

  // Let the OS decide the location of new windows. Otherwise, all windows
  // would appear at the top left corner by default.
  // TODO: investigate if this applies to JavaFX windows
  System.setProperty("java.awt.Window.locationByPlatform", "true");

}
 
源代码20 项目: socialauth   文件: GenerateToken.java
private void getAccessToken() throws Exception {
	SocialAuthConfig config = SocialAuthConfig.getDefault();
	config.load();
	SocialAuthManager manager = new SocialAuthManager();
	manager.setSocialAuthConfig(config);

	URL aURL = new URL(successURL);
	host = aURL.getHost();
	port = aURL.getPort();
	port = port == -1 ? 80 : port;
	callbackPath = aURL.getPath();

	if (tokenFilePath == null) {
		tokenFilePath = System.getProperty("user.home");
	}
	String url = manager.getAuthenticationUrl(providerId, successURL);
	startServer();

	if (Desktop.isDesktopSupported()) {
		Desktop desktop = Desktop.getDesktop();
		if (desktop.isSupported(Action.BROWSE)) {
			try {
				desktop.browse(URI.create(url));
				// return;
			} catch (IOException e) {
				// handled below
			}
		}
	}

	lock.lock();
	try {
		while (paramsMap == null && error == null) {
			gotAuthorizationResponse.awaitUninterruptibly();
		}
		if (error != null) {
			throw new IOException("User authorization failed (" + error
					+ ")");
		}
	} finally {
		lock.unlock();
	}
	stop();

	AccessGrant accessGrant = manager.createAccessGrant(providerId,
			paramsMap, successURL);

	Exporter.exportAccessGrant(accessGrant, tokenFilePath);

	LOG.info("Access Grant Object saved in a file  :: " + tokenFilePath
			+ File.separatorChar + accessGrant.getProviderId()
			+ "_accessGrant_file.txt");
}