@Override public boolean isSupported(Action action) { switch(action) { case OPEN: case EDIT: case PRINT: case MAIL: case BROWSE: case MOVE_TO_TRASH: case APP_SUDDEN_TERMINATION: case APP_EVENT_SYSTEM_SLEEP: return true; case APP_EVENT_USER_SESSION: return isEventUserSessionSupported; default: return false; } }
/** * Connects to the given server (IP and Port) using an empty (no) password. * Other than * {@link GTAController#connectToServer(String)} and * {@link GTAController#connectToServer(String, String)}, this method uses the * <code>samp://</code> protocol to connect to make the samp launcher connect to * the server. * * @param ipAndPort * the server to connect to * @return true if it was most likely successful */ private static boolean connectToServerUsingProtocol(final String ipAndPort) { if (!OSUtility.isWindows()) { return false; } try { Logging.info("Connecting using protocol."); final Desktop desktop = Desktop.getDesktop(); if (desktop.isSupported(Action.BROWSE)) { desktop.browse(new URI("samp://" + ipAndPort)); return true; } } catch (final IOException | URISyntaxException exception) { Logging.warn("Error connecting to server.", exception); } return false; }
/** * Display user guide section. * * @param section the section */ public void display(String section) { URL url = null; try { if (section == null) { url = new URL(USER_GUIDE_URL); } else { url = new URL(USER_GUIDE_URL + "#" + section); } } catch (MalformedURLException e1) { e1.printStackTrace(); } if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Action.BROWSE)) { Desktop desktop = Desktop.getDesktop(); try { desktop.browse(url.toURI()); } catch (IOException | URISyntaxException e) { e.printStackTrace(); } } }
/** * Display report issue section. */ public void display() { URL url = null; try { url = new URL(REPORT_ISSUE_URL); } catch (MalformedURLException e1) { ConsoleManager.getInstance().exception(this, e1); } if (url != null) { if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Action.BROWSE)) { Desktop desktop = Desktop.getDesktop(); try { desktop.browse(url.toURI()); } catch (IOException | URISyntaxException e) { ConsoleManager.getInstance().exception(this, e); } } } }
/** * Executes the given file. * @param file The file to be executed * @return True on success; false otherwise */ public static boolean executeFile(final File file) { final boolean desktopSupported = Desktop.isDesktopSupported(); if (desktopSupported && file.exists()) { final Desktop desktop = Desktop.getDesktop(); final boolean canOpen = desktop.isSupported(Action.OPEN); if (canOpen) { try { desktop.open(file); return true; } catch (final Exception ex) { ex.printStackTrace(); } } } return false; }
public static void browse(String url) throws BrowseException { if(Desktop.isDesktopSupported()) { Desktop desktop = Desktop.getDesktop(); if(desktop.isSupported(Action.BROWSE)) { try { desktop.browse(new URI(url)); } catch (Exception e) { throw new BrowseException(); } } else { throw new BrowseException(); } } else { throw new BrowseException(); } }
/** * Open the given URL in the system web browser. * * @param uri * the {@link URI} to be opened * * @return <code>true</code> if call to open was successfully made, * <code>false</code> otherwise. A value of <code>true</code> DOES * NOT guarantee that the {@link URI} was opened, but only that the * call was successfully made. */ public static boolean openURL(URI uri) { if(!Desktop.isDesktopSupported()) { return false; } Desktop d = Desktop.getDesktop(); if(!d.isSupported(Action.BROWSE)) { return false; } try { d.browse(uri); return true; } catch (IOException e) { return false; } }
/** * Utility method to create an action that opened a given file. * @param path path to the file * @return corresponding action */ public static SeerClickableLabelAction createOpenParentFolderAction(final String path) { return () -> { File file = new File(path); try { if (file.exists() && System.getProperty("os.name").startsWith("Windows")) Runtime.getRuntime().exec("Explorer /select," + file.getParentFile().getAbsolutePath() + "\\" + file.getName()); else { Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null; if (desktop != null && desktop.isSupported(Action.OPEN)) Desktop.getDesktop().open(file.getParentFile()); } } catch (IOException | RuntimeException e) { // ignored } }; }
/** * Launch the given URL in the system browser * @param url the URL to launch */ public static void openURL(String url) { Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null; if (desktop != null && desktop.isSupported(Action.BROWSE)) { try { desktop.browse(new URI(url)); } catch (Exception e) { JOptionPane.showMessageDialog(null, errMsg + ":\n" + e.getLocalizedMessage()); } } else { fallbackURL(url); } }
/** * Launches browser with homepage. */ public void gotoHomepage() { if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Action.BROWSE)) { try { Desktop.getDesktop().browse(new URI(HOMEPAGE)); } catch (Exception e) { System.err.println("Failed to launch browser with homepage!"); e.printStackTrace(); } } }
/** * Show download page. */ public void showDownloadPage() { if (client != null) { URL url = client.getDownloadURL(); if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Action.BROWSE)) { Desktop desktop = Desktop.getDesktop(); try { desktop.browse(url.toURI()); } catch (IOException | URISyntaxException e) { e.printStackTrace(); } } } }
public boolean isSupported(Action action) { String check = null; switch(action) { case BROWSE: check = _BROWSE; break; case MAIL: check = _MAIL; break; case EDIT: check = _EDIT; break; case PRINT: check = _PRINT; break; case OPEN: default: check = _OPEN; break; } return this.supportCommand(check); }
/** * * @param uri the target uri, maybe null. * @param desktopAction the type of desktop action this class should perform, must be * BROWSE or MAIL * @throws HeadlessException if {@link * GraphicsEnvironment#isHeadless()} returns {@code true} * @throws UnsupportedOperationException if the current platform doesn't support * Desktop * @throws IllegalArgumentException if unsupported action type */ public HyperlinkAction(URI uri, Action desktopAction) { super(); if (!Desktop.isDesktopSupported()) { throw new UnsupportedOperationException("Desktop API is not " + "supported on the current platform"); } if (desktopAction != Desktop.Action.BROWSE && desktopAction != Desktop.Action.MAIL) { throw new IllegalArgumentException("Illegal action type: " + desktopAction + ". Must be BROWSE or MAIL"); } this.desktopAction = desktopAction; getURIVisitor(); setTarget(uri); }
public static LaunchingStrategy detectFromOs() { if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Action.BROWSE)) { return DESKTOP_BROWSE; } else { String os = System.getProperty("os.name").toLowerCase(); if (os.contains("nix") || os.contains("nux") || os.contains("aix")) return XDG_OPEN_COMMAND; else if (os.contains("mac")) return OPEN_COMMAND; else return BROWSER_LAUNCHING_NOT_SUPPORTED; } }
private static void startBrowser(String url) throws IOException, URISyntaxException { if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Action.BROWSE)) { Desktop.getDesktop().browse(new URI(url)); } else { // We should try some commands, just in case they work LOGGER.debug("Browsing an URL is not directly supported by this JVM; trying some commands"); String os = System.getProperty("os.name"); if ("Linux".equals(os)) { // Partially sourced from org.eclipse.oomph.util.OS for (String browser : new String[] { "gnome-open", "kde-open", "xdg-open", "sensible-browser" }) { String[] command = { browser, url }; try { Process process = Runtime.getRuntime().exec(command); if (process != null) { // Don't check whether the process is still running; some commands just delegate to others // and terminate LOGGER.debug("It looks like {} is a valid browser", browser); return; } } catch (IOException ex) { LOGGER.debug("{} is not supported as a browser", browser); } } } LOGGER.info("Your OS ({}) does not support opening URLs directly, go manually to {}", os, url); JOptionPane.showMessageDialog(null, "Your OS (" + os + ") does not support opening URLs directly, go manually to " + url, "Error", JOptionPane.ERROR_MESSAGE); } }
private void doGoto(String url) { if (Desktop.isDesktopSupported()) { Desktop desktop = Desktop.getDesktop(); if (desktop.isSupported(Action.BROWSE)) try { desktop.browse(URI.create(url)); return; } catch (IOException e) { // handled below } } }
@Override public void openURI (String URI) { try { if (!GraphicsEnvironment.isHeadless() && Desktop.isDesktopSupported()) { if (Desktop.getDesktop().isSupported(Action.BROWSE)) { Desktop.getDesktop().browse(java.net.URI.create(URI)); return; } } } catch (Throwable t) { Gdx.app.error("HeadlessNet", "Failed to open URI. ", t); return; } Gdx.app.error("HeadlessNet", "Opening URIs on this environment is not supported. Ignoring."); }
public void openBrowser(String url) { Desktop desktop = Desktop.getDesktop(); if (Desktop.isDesktopSupported()) { if (desktop.isSupported(Action.BROWSE)) { try { desktop.browse(new URL(url).toURI()); } catch (IOException | URISyntaxException e) { e.printStackTrace(); } } } }
public void onPlayerInteractEvent(PlayerInteractEvent event) { org.bukkit.entity.Player player = (Player) event.getPlayer(); if(event.getAction() == org.bukkit.event.block.Action.LEFT_CLICK_BLOCK && event.getMaterial() == Material.WOOD_HOE && event.getClickedBlock().getType() == Material.CHEST) { player.sendMessage("That is a chest"); } }
public static boolean open(URI uri) { boolean opened = false; try { if(Desktop.isDesktopSupported()) { Desktop desktop = Desktop.getDesktop(); if(desktop.isSupported(Action.BROWSE)) { desktop.browse(uri); opened = true; } } } catch (Exception e) { e.printStackTrace(); } return opened; }
/** * Utility method to create an action that browse to a given internet address. * @param url internet address * @return corresponding action */ public static SeerClickableLabelAction createBrowseToUrlAction(final String url) { return () -> { Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null; if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) { try { desktop.browse(URI.create(url)); } catch (IOException | RuntimeException e) { // ignored } } }; }
/** * Utility method to create an action that opened a given file. * @param path path to the file * @return corresponding action */ public static SeerClickableLabelAction createOpenFileAction(final String path) { return () -> { File file = new File(path); try { Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null; if (desktop != null && desktop.isSupported(Action.OPEN)) Desktop.getDesktop().open(file); } catch (IOException | RuntimeException e) { // ignored } }; }
private void doGoto(String url) { if (Desktop.isDesktopSupported()) { Desktop desktop = Desktop.getDesktop(); if (desktop.isSupported(Action.BROWSE)) { try { desktop.browse(URI.create(url)); } catch (IOException e) { // handled below } } } }
private void doGoto(String url) { if (Desktop.isDesktopSupported()) { Desktop desktop = Desktop.getDesktop(); if (desktop.isSupported(Action.BROWSE)) { try { desktop.browse(URI.create(url)); return; } catch (IOException e) { // handled below } } } }
public boolean isSupported() { boolean supported = false; supported = Desktop.isDesktopSupported(); logger.debug("isDesktopSupported {}", supported); if (supported) { supported = Desktop.getDesktop().isSupported(Action.OPEN); logger.debug("isOpenSupported {}", supported); } return supported; }
public static void browse(String uri) { try { if (java.awt.Desktop.isDesktopSupported()) { java.awt.Desktop desktop = java.awt.Desktop.getDesktop(); if (desktop.isSupported(Action.BROWSE)) { desktop.browse(new URI(uri)); } } } catch (Exception e) { log.error("Browse URI failed", e); } }
public boolean isSupported(Action action) { // OPEN, EDIT, PRINT, MAIL, BROWSE all supported. // Though we don't really differentiate between OPEN / EDIT return true; }
@Override public boolean isSupported(Action action) { // OPEN, EDIT, PRINT, MAIL, BROWSE all supported on windows. return true; }
public boolean isSupported(Action type) { return supportedActions.contains(type); }