示例#1
0
  /** @param helpAddress */
  public OpenHelpUrl(String helpAddress) {

    if (!java.awt.Desktop.isDesktopSupported()) {

      System.err.println("Desktop is not supported (fatal)");
      System.exit(1);
    }

    java.awt.Desktop desktop = java.awt.Desktop.getDesktop();

    if (!desktop.isSupported(java.awt.Desktop.Action.BROWSE)) {

      System.err.println("Desktop doesn't support the browse action (fatal)");
      System.exit(1);
    }

    try {

      java.net.URI uri = new java.net.URI(helpAddress);
      desktop.browse(uri);
    } catch (Exception e) {

      System.err.println(e.getMessage());
    }
  }
示例#2
0
  void lookUpTaxonID(String taxonID) {
    URI url;

    try {
      // We should look up the miITIS_TSN status, but since we don't
      // have any options there ...
      url =
          new URI(
              "http://www.itis.gov/servlet/SingleRpt/SingleRpt?search_topic=TSN&search_value="
                  + taxonID);
    } catch (URISyntaxException e) {
      throw new RuntimeException(e);
    }

    try {
      Desktop desktop = Desktop.getDesktop();
      desktop.browse(url);

    } catch (IOException e) {
      MessageBox.messageBox(
          mainFrame,
          "Could not open URL '" + url + "'",
          "The following error occurred while looking up URL '" + url + "': " + e.getMessage(),
          MessageBox.ERROR);
    }
  }
  // eventMenuPopup ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  private void eventMenuPopup() {

    try {

      URI uri = new URI(Data.WIKI_URL + underscoreName(getWikiTopic()));
      Desktop desktop = null;
      if (Desktop.isDesktopSupported()) {
        desktop = Desktop.getDesktop();
      } // if

      if (desktop != null) {
        desktop.browse(uri);
      } // if

    } // try
    catch (IOException error) {
      JOptionPane.showMessageDialog(
          Data.getView(),
          "^Wiki Error: " + error.getMessage(),
          "Wiki Error: " + Data.APP_TITLE,
          JOptionPane.ERROR_MESSAGE);
    } // catch
    catch (URISyntaxException error) {
      JOptionPane.showMessageDialog(
          Data.getView(),
          "@Wiki Error: " + error.getMessage(),
          "Wiki Error: " + Data.APP_TITLE,
          JOptionPane.ERROR_MESSAGE);
    } // catch
  } // eventMenuPopup ----------------------------------------------------------
示例#4
0
  private void facebookConnect() throws FacebookException {
    // auth.createToken returns a string
    // http://wiki.developers.facebook.com/index.php/Auth.createToken
    facebookAuthToken = facebookClient.executeQuery("auth.createToken", String.class);
    String url =
        "http://www.facebook.com/login.php"
            + "?api_key="
            + FACEBOOK_API_KEY
            + "&fbconnect=true"
            + "&v=1.0"
            + "&connect_display=page"
            + "&session_key_only=true"
            + "&req_perms=read_stream,publish_stream,offline_access"
            + "&auth_token="
            + facebookAuthToken;

    // Here we launch a browser with the above URL so the user can login to Facebook, grant our
    // requested permissions and send our token for pickup later
    if (Desktop.isDesktopSupported()) {
      Desktop desktop = Desktop.getDesktop();

      if (desktop.isSupported(Desktop.Action.BROWSE)) {
        try {
          desktop.browse(new URI(url));
        } catch (IOException ioe) {
          ioe.printStackTrace();
        } catch (URISyntaxException use) {
          use.printStackTrace();
        }
      }
    }
  }
示例#5
0
 private static void openUpWebSite(String url) {
   Desktop d = Desktop.getDesktop();
   try {
     d.browse(new URI(url));
   } catch (Exception e) {
   }
 }
  private static void openBrowser(OAuthV1 oAuth) {

    String authorizationUrl = OAuthV1Client.generateAuthorizationURL(oAuth);

    System.out.println("Get verification code......");
    if (!java.awt.Desktop.isDesktopSupported()) {

      System.err.println("Desktop is not supported (fatal)");
      System.exit(1);
    }
    java.awt.Desktop desktop = java.awt.Desktop.getDesktop();
    if (desktop == null || !desktop.isSupported(java.awt.Desktop.Action.BROWSE)) {

      System.err.println("Desktop doesn't support the browse action (fatal)");
      System.exit(1);
    }
    try {
      desktop.browse(new URI(authorizationUrl));
    } catch (IOException e) {
      e.printStackTrace();
      System.exit(1);
    } catch (URISyntaxException e) {
      e.printStackTrace();
      System.exit(1);
    }
  }
示例#7
0
  public static void openURL(String url) {

    try {
      // Since Java6 this is a much easier method to open the browser
      if (Desktop.isDesktopSupported()) {
        Desktop desktop = Desktop.getDesktop();
        desktop.browse(new URI(url));
      }

      // Only if desktop is not supported we try the old main specific code
      else {
        if (SystemInfo.OS == Os.MAC) {
          Class<?> fileMgr = Class.forName("com.apple.eio.FileManager");
          Method openURL = fileMgr.getDeclaredMethod("openURL", new Class[] {String.class});
          openURL.invoke(null, new Object[] {url});
        } else if (SystemInfo.OS == Os.WINDOWS)
          Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
        else { // assume Unix or Linux
          String[] browsers = {"firefox", "opera", "konqueror", "epiphany", "mozilla", "netscape"};
          String browser = null;
          for (int count = 0; (count < browsers.length) && (browser == null); count++)
            if (Runtime.getRuntime().exec(new String[] {"which", browsers[count]}).waitFor() == 0)
              browser = browsers[count];
          if (browser == null) throw new Exception("Could not find web browser");
          else Runtime.getRuntime().exec(new String[] {browser, url});
        }
      }
    } catch (Exception e) {
      log.error("Error at opening the URL.", e);
    }
  }
示例#8
0
  public static void main(String[] args) {

    if (!java.awt.Desktop.isDesktopSupported()) {

      System.err.println("Desktop is not supported (fatal)");
      System.exit(1);
    }

    java.awt.Desktop desktop = java.awt.Desktop.getDesktop();

    if (!desktop.isSupported(java.awt.Desktop.Action.BROWSE)) {

      System.err.println("Desktop doesn't support the browse action (fatal)");
      System.exit(1);
    }

    try {

      java.net.URI uri = new java.net.URI("http://www.d3js.org");
      desktop.browse(uri);
    } catch (Exception e) {

      System.err.println(e.getMessage());
    }
  }
  /**
   * @param he hiperlik Event.
   * @see
   *     javax.help.plaf.basic.BasicContentViewerUI#hyperlinkUpdate(javax.swing.event.HyperlinkEvent)
   */
  @Override
  public void hyperlinkUpdate(final HyperlinkEvent he) {

    if (he.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
      URL u = he.getURL();
      if ("mailto".equalsIgnoreCase(u.getProtocol())
          || "http".equalsIgnoreCase(u.getProtocol())
          || "ftp".equalsIgnoreCase(u.getProtocol())) {
        Desktop desktop = null;
        if (Desktop.isDesktopSupported()) {
          desktop = Desktop.getDesktop();
          if (desktop.isSupported(Desktop.Action.BROWSE)) {
            try {
              desktop.browse(u.toURI());
            } catch (MalformedURLException e1) {
              DialogUtils.showGeneralErrorDialog(
                  new Frame(), "MalformedURLException", "Invalid URL.");
            } catch (IOException e1) {
              DialogUtils.showGeneralErrorDialog(new Frame(), "IOException", "Resource not found.");
            } catch (URISyntaxException uriSyntaxEx) {
              DialogUtils.showGeneralErrorDialog(new Frame(), "URISyntaxException", "Invalid URI.");
            }
          }
        }
      } else {
        super.hyperlinkUpdate(he);
      }
    }
  }
示例#10
0
  void searchName(String nameToMatch) {
    URI url;

    try {
      // We should look up the miITIS_TSN status, but since we don't
      // have any options there ...
      url = new URI("http", "www.google.com", "/search", "q=" + nameToMatch);
      // I think the URI handles the URL encoding?

    } catch (URISyntaxException e) {
      throw new RuntimeException(e);
    }

    try {
      Desktop desktop = Desktop.getDesktop();
      desktop.browse(url);

    } catch (IOException e) {
      MessageBox.messageBox(
          mainFrame,
          "Could not open URL '" + url + "'",
          "The following error occurred while looking up URL '" + url + "': " + e.getMessage(),
          MessageBox.ERROR);
    }
  }
示例#11
0
  @Override
  protected final void doExecute(Application app) {
    if (Desktop.isDesktopSupported()) {
      Desktop desktop = Desktop.getDesktop();
      if (desktop.isSupported(getType())) {
        try {
          switch (getType()) {
            case BROWSE:
              desktop.browse(getURI(app));
              return;
            case MAIL:
              desktop.mail(getURI(app));
              return;
          }
        } catch (Exception e) {
          getLog().error("Invalid URI", e);
        }
      }
    }

    JOptionPane.showMessageDialog(
        app.getAppFrame(),
        String.format("Action %s is not supported", getType()),
        "",
        JOptionPane.WARNING_MESSAGE);
  }
示例#12
0
  private static void sendMail() throws URISyntaxException, IOException {

    Desktop desktop = Desktop.getDesktop();
    try {
      desktop.browse(new URI("mailto:[email protected]"));
    } catch (IOException e) {
      JOptionPane.showMessageDialog(null, "Can't access.");
    }
  }
  public static void openwebsite(String url) {
    try {
      Desktop dt = Desktop.getDesktop();
      URI uri = new URI(url);
      dt.browse(uri.resolve(uri));

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  public static void openUrl(final String url) throws IOException, URISyntaxException {
    if (java.awt.Desktop.isDesktopSupported()) {
      final java.awt.Desktop desktop = java.awt.Desktop.getDesktop();

      if (desktop.isSupported(java.awt.Desktop.Action.BROWSE)) {
        final java.net.URI uri = new java.net.URI(url);
        desktop.browse(uri);
      }
    }
  }
示例#15
0
文件: Util.java 项目: ENGYS/HELYX-OS
 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 (Exception e) {
       e.printStackTrace();
     }
   }
 }
 @Override
 public void actionPerformed(ActionEvent ae) {
   if (ae.getSource().equals(openItem)) {
     File f = null;
     if (null == (f = SpeedyGrader.getInstance().getFilesLoc())) {
       f = new File(System.getProperty("user.home"));
     }
     JFileChooser chooser = new JFileChooser(f);
     chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
     int ret = chooser.showOpenDialog(this);
     if (ret == JFileChooser.APPROVE_OPTION) {
       newFolderSelected(chooser.getSelectedFile());
     }
   } else if (ae.getSource().equals(inputItem)) {
     new InputDialog();
   } else if (ae.getSource().equals(saveItem)) {
     for (EditorPanel ep : editorPanels) {
       ep.save();
     }
     SpeedyGrader.getInstance().startComplieAndRun();
   } else if (ae.getSource().equals(refreshItem)) {
     newFolderSelected(null);
   } else if (ae.getSource().equals(githubItem)) {
     String url = "https://github.com/MitchellSlavik/SpeedyGrader";
     Desktop d = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
     if (d != null && d.isSupported(Action.BROWSE)) {
       try {
         d.browse(URI.create(url));
       } catch (IOException e) {
         e.printStackTrace();
       }
     } else {
       JOptionPane.showMessageDialog(
           this,
           "We were unable to open a web browser. The url has been copied to your clipboard.",
           "Unable to preform operation",
           JOptionPane.ERROR_MESSAGE);
       StringSelection selection = new StringSelection(url);
       Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
       clipboard.setContents(selection, selection);
     }
   } else if (ae.getSource().equals(aboutItem)) {
     new AboutDialog();
   } else if (ae.getSource().equals(installItem)) {
     new InstallDialog();
   } else if (ae.getSource().equals(upgradeItem)) {
     new AutoUpdater();
   } else if (ae.getSource().equals(editorSplitToggle)) {
     splitEditorPane.setOrientation(
         editorSplitToggle.isSelected() ? JSplitPane.VERTICAL_SPLIT : JSplitPane.HORIZONTAL_SPLIT);
     this.validate();
     this.repaint();
   }
 }
示例#17
0
 public void openInBrowser(URI uri) {
   Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
   if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
     try {
       desktop.browse(uri);
     } catch (IOException e) {
       System.err.println(e.getMessage());
     }
   } else {
     System.err.println("Desktop not supported, cannout open browser");
   }
 }
示例#18
0
  @Override
  public void mouseClicked(MouseEvent e) {
    Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;

    if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
      try {
        desktop.browse(url.toURI());
      } catch (IOException | URISyntaxException exc) {
        Logger.getLogger(AbreNavegador.class.getName()).log(Level.SEVERE, null, exc);
      }
    }
  }
示例#19
0
  public void openURI(String uri) {
    if (!Desktop.isDesktopSupported()) return;

    Desktop desktop = Desktop.getDesktop();
    if (!desktop.isSupported(Desktop.Action.BROWSE)) return;

    try {
      desktop.browse(new URI(uri));
    } catch (Exception ex) {
      throw new GdxRuntimeException(ex);
    }
  }
示例#20
0
  public static boolean browse(URI uri) throws IOException {
    // Try using the Desktop api first
    try {
      Desktop desktop = Desktop.getDesktop();
      desktop.browse(uri);

      return true;
    } catch (SecurityException e) {
    }

    return false;
  }
 @Override
 public void mouseClicked(MouseEvent arg0) {
   Desktop desktop = Desktop.getDesktop();
   try {
     URI uri = new URI(Param.URL_Logo);
     desktop.browse(uri);
   } catch (URISyntaxException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
示例#22
0
 /* (non-Javadoc)
  * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
  */
 @Override
 public void actionPerformed(ActionEvent arg0) {
   Desktop desktop = Desktop.getDesktop();
   if (Desktop.isDesktopSupported() && desktop.isSupported(Desktop.Action.BROWSE)) {
     try {
       desktop.browse(new URI("http://blog.sina.com.cn/kkliuyao"));
     } catch (IOException e) {
       e.printStackTrace();
     } catch (URISyntaxException e) {
       e.printStackTrace();
     }
   }
 }
 private void openErrorMessage(final String url) {
   Desktop desktop = Desktop.getDesktop();
   if ((Desktop.isDesktopSupported()) && (desktop.isSupported(Desktop.Action.BROWSE))) {
     try {
       URI uri = new URI(url);
       desktop.browse(uri);
     } catch (URISyntaxException e) {
       e.printStackTrace();
     } catch (IOException e) {
       e.printStackTrace();
     }
   }
 }
示例#24
0
  @Override
  public void openURI(String URI) {
    if (!Desktop.isDesktopSupported()) return;

    Desktop desktop = Desktop.getDesktop();

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

    try {
      desktop.browse(new java.net.URI(URI));
    } catch (Exception e) {
      throw new GdxRuntimeException(e);
    }
  }
示例#25
0
  public static Token login() throws Exception {
    JinxLogger.setLogger(new StdoutLogger());
    if (properties == null) {
      properties = new Properties();
      properties.load(new FileReader(new File("./test/flickr.properties")));
      JinxLogger.getLogger().log(properties.toString());
    }

    Token token = null;
    Jinx jinx = Jinx.getInstance();
    File tokenFile = new File((String) properties.get("flickt.tokenfile"));
    if (tokenFile.exists()) {
      token = new Token();
      // load token and initialize Jinx
      token.load(tokenFile);
      Jinx.getInstance()
          .init(
              (String) properties.get("flickr.api_key"),
              (String) properties.get("flickr.secret"),
              token);
    } else {
      jinx.init(
          (String) properties.get("flickr.api_key"), (String) properties.get("flickr.secret"));
      Frob frob = AuthApi.getInstance().getFrob(JinxConstants.PERMS_READ);

      JinxLogger.getLogger().log("Go to this URL to authorize the application:");
      JinxLogger.getLogger().log(frob.getLoginUrl());

      Desktop desktop = Desktop.getDesktop();
      desktop.browse(URI.create(frob.getLoginUrl()));

      System.out.print("When you have authorized the app, press Enter to continue...");
      System.in.read();
      token = AuthApi.getInstance().getToken(frob);
      if (token.getNsid() != ("")) {
        JinxLogger.getLogger().log("Authorization successful.");

        File file = new File((String) properties.get("flickt.tokenfile"));
        JinxLogger.getLogger().log(file.getAbsolutePath());

        token.store(file); // put the token in the Jinx class instance jinx.setToken(token);
        // // now you can do all the cool stuff....
      } else {
        JinxLogger.getLogger().log("Authorization failed.");
        // JinxLogger.getLogger().log("Error code: " + token.getErrorCode() + " - " +
        // token.getErrorMessage()); System.exit(1);
      }
    }
    return token;
  }
示例#26
0
 /**
  * Launches the user's browser to the specified URL.
  *
  * @param url the url to open to
  */
 public static void browse(String url) {
   url = sanitizeURL(url);
   java.net.URI uri = null;
   java.awt.Desktop desktop = java.awt.Desktop.getDesktop();
   try {
     uri = new java.net.URI(url);
     desktop.browse(uri);
   } catch (java.io.IOException io) {
     // io error
     System.err.println("Error launching browser! Details: " + io);
   } catch (java.net.URISyntaxException ex) {
     // error with syntax of URI
     System.err.println("Bad URI!: " + uri + ", details: " + ex);
   }
 }
示例#27
0
 /** This method is responsible for open the web browser and displaying the website */
 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 (Exception e) {
       e.printStackTrace();
       JOptionPane.showMessageDialog(
           null,
           "Wystąpił problem z otworzeniem strony internetowej w przeglądarce",
           "Błąd",
           JOptionPane.ERROR_MESSAGE);
     }
   }
 }
  public void generateHtml()
      throws IllegalArgumentException, IllegalAccessException, IOException,
          SIMPLTranslationException, URISyntaxException {
    appendHeader(print);
    Desktop desktop = Desktop.getDesktop();
    URI uri = new URI("MmtoHtml.html");
    for (DocumentClosure documentClosure : documentCollection) {
      Document document = documentClosure.getDocument();

      TranslationContext translationContext = new TranslationContext();
      document.serializeToHtml(print, translationContext);
    }
    appendFooter(print);
    print.close();
    desktop.browse(uri);
  }
示例#29
0
 private void jMenuItem3ActionPerformed(
     java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jMenuItem3ActionPerformed
   try {
     URI uri = new URI("http://www.rcnet.com");
     Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
     if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
       try {
         desktop.browse(uri);
       } catch (Exception e) {
         e.printStackTrace();
       }
     }
   } catch (URISyntaxException ex) {
     Logger.getLogger(mainInterface.class.getName()).log(Level.SEVERE, null, ex);
   }
 } // GEN-LAST:event_jMenuItem3ActionPerformed
示例#30
0
  public static void launchUrl(String url) {
    if (!java.awt.Desktop.isDesktopSupported()) {
      throw new RuntimeException("Desktop is not supported (fatal)");
    }

    java.awt.Desktop desktop = java.awt.Desktop.getDesktop();
    if (!desktop.isSupported(java.awt.Desktop.Action.BROWSE)) {
      throw new RuntimeException("Desktop doesn't support the browse action (fatal)");
    }

    try {
      java.net.URI uri = new java.net.URI(url);
      desktop.browse(uri);
    } catch (Exception exception) {
      throw new RuntimeException(exception);
    }
  }