Java 类java.awt.Desktop.Action 实例源码

项目:openjdk-jdk10    文件:WDesktopPeer.java   
@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;
    }
}
项目:ServerBrowser    文件:GTAController.java   
/**
 * 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;
}
项目:openjdk9    文件:WDesktopPeer.java   
@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;
    }
}
项目:sldeditor    文件:Help.java   
/**
 * 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();
        }
    }
}
项目:sldeditor    文件:ReportIssue.java   
/**
 * 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);
            }
        }
    }
}
项目:spjgl    文件:FileUtils.java   
/**
 * 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;
}
项目:CryptMeme    文件:I2PDesktop.java   
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();
    }
}
项目:jerry-core    文件:DesktopUtils.java   
/**
 * 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;
    }
}
项目:naaccr-xml    文件:SeerClickableLabel.java   
/**
 * 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
        }
    };
}
项目:jmt    文件:BrowserLauncher.java   
/**
 * 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);
    }
}
项目:screencast4j    文件:ScreencastPanel.java   
/**
  * 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();
     }
   }
 }
项目:sldeditor    文件:CheckUpdate.java   
/**
 * 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();
            }
        }
    }
}
项目:javify    文件:ClasspathDesktopPeer.java   
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);
}
项目:screencast4j    文件:ScreencastPanel.java   
/**
  * 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();
     }
   }
 }
项目:jvm-stm    文件:ClasspathDesktopPeer.java   
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);
}
项目:swingx    文件:HyperlinkAction.java   
/**
 * 
 * @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);
}
项目:bauhinia    文件:BrowserLauncher.java   
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;
    }
}
项目:demyo    文件:DesktopUtils.java   
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);
    }
}
项目:SMEditClassic    文件:DlgAbout.java   
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
            }
    }
}
项目:SMEditClassic    文件:BegPanel.java   
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
            }
    }
}
项目:SMEditClassic    文件:DlgError.java   
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
            }
    }
}
项目:libgdxcn    文件:HeadlessNet.java   
@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.");
}
项目:twitch-raffle    文件:IOHandler.java   
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();
            }
        }
    }
}
项目:JamVM-PH    文件:ClasspathDesktopPeer.java   
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);
}
项目:usefullStuff    文件:PlayerCottage.java   
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");
    }
}
项目:olca-converter    文件:Browser.java   
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;
}
项目:naaccr-xml    文件:SeerClickableLabel.java   
/**
 * 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
            }
        }
    };
}
项目:naaccr-xml    文件:SeerClickableLabel.java   
/**
 * 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
        }
    };
}
项目:SMEdit    文件:DlgAbout.java   
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
            }
        }
    }
}
项目:SMEdit    文件:BegPanel.java   
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
            }
        }
    }
}
项目:SMEdit    文件:DlgError.java   
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
            }
        }
    }
}
项目:classpath    文件:ClasspathDesktopPeer.java   
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);
}
项目:mkRemote    文件:QuickLaunchServiceImpl.java   
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;
}
项目:olca-app    文件:Desktop.java   
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);
    }
}
项目:OpenJSharp    文件:CDesktopPeer.java   
public boolean isSupported(Action action) {
    // OPEN, EDIT, PRINT, MAIL, BROWSE all supported.
    // Though we don't really differentiate between OPEN / EDIT
    return true;
}
项目:OpenJSharp    文件:WDesktopPeer.java   
@Override
public boolean isSupported(Action action) {
    // OPEN, EDIT, PRINT, MAIL, BROWSE all supported on windows.
    return true;
}
项目:OpenJSharp    文件:XDesktopPeer.java   
public boolean isSupported(Action type) {
    return supportedActions.contains(type);
}
项目:jdk8u-jdk    文件:CDesktopPeer.java   
public boolean isSupported(Action action) {
    // OPEN, EDIT, PRINT, MAIL, BROWSE all supported.
    // Though we don't really differentiate between OPEN / EDIT
    return true;
}
项目:jdk8u-jdk    文件:WDesktopPeer.java   
@Override
public boolean isSupported(Action action) {
    // OPEN, EDIT, PRINT, MAIL, BROWSE all supported on windows.
    return true;
}
项目:jdk8u-jdk    文件:XDesktopPeer.java   
public boolean isSupported(Action type) {
    return supportedActions.contains(type);
}