Ejemplo n.º 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());
    }
  }
Ejemplo n.º 2
0
  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);
    }
  }
Ejemplo n.º 3
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);
      }
    }
  }
Ejemplo n.º 5
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();
        }
      }
    }
  }
Ejemplo n.º 6
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);
  }
Ejemplo n.º 7
0
  private JMenu createHelpMenu() {

    List<JComponent> menuItems = new ArrayList<JComponent>();

    MenuAction menuAction = null;

    menuAction =
        new MenuAction("User Guide ... ") {

          @Override
          public void actionPerformed(ActionEvent e) {
            try {
              BrowserLauncher.openURL(SERVER_BASE_URL + "igv/UserGuide");
            } catch (IOException ex) {
              log.error("Error opening browser", ex);
            }
          }
        };
    menuAction.setToolTipText(HELP_TOOLTIP);
    menuItems.add(MenuAndToolbarUtils.createMenuItem(menuAction));

    if (Desktop.isDesktopSupported()) {
      final Desktop desktop = Desktop.getDesktop();
      if (desktop.isSupported(Desktop.Action.MAIL)) {

        menuAction =
            new MenuAction("Help Forum...") {

              @Override
              public void actionPerformed(ActionEvent e) {
                try {
                  URI uri = new URI("http://groups.google.com/forum/#!forum/igv-help");
                  Desktop.getDesktop().browse(uri);
                } catch (Exception ex) {
                  log.error("Error opening igv-help uri", ex);
                }
              }
            };
        menuAction.setToolTipText("Email support");
        menuItems.add(MenuAndToolbarUtils.createMenuItem(menuAction));
      }
    }

    menuAction =
        new MenuAction("About IGV ") {

          @Override
          public void actionPerformed(ActionEvent e) {
            (new AboutDialog(IGV.getMainFrame(), true)).setVisible(true);
          }
        };
    menuAction.setToolTipText(ABOUT_TOOLTIP);
    menuItems.add(MenuAndToolbarUtils.createMenuItem(menuAction));

    MenuAction helpMenuAction = new MenuAction("Help");
    return MenuAndToolbarUtils.createMenu(menuItems, helpMenuAction);
  }
Ejemplo n.º 8
0
 public static void filmAbspielen(Frame parent, String datei) {
   boolean gut = false;
   File sFile;
   if (datei.isEmpty()) {
     return;
   }
   sFile = new File(datei);
   if (!sFile.exists()) {
     MVMessageDialog.showMessageDialog(
         parent, "Film existiert noch nicht!", "Fehler", JOptionPane.ERROR_MESSAGE);
     return;
   }
   try {
     if (!MVConfig.get(MVConfig.Configs.SYSTEM_PLAYER_ABSPIELEN).isEmpty()) {
       String programm = MVConfig.get(MVConfig.Configs.SYSTEM_PLAYER_ABSPIELEN);
       String[] cmd = {programm, sFile.getAbsolutePath()};
       Runtime.getRuntime().exec(cmd);
       gut = true;
     } else {
       if (Desktop.isDesktopSupported()) {
         Desktop d = Desktop.getDesktop();
         if (d.isSupported(Desktop.Action.OPEN)) {
           d.open(sFile);
           gut = true;
         }
       }
     }
   } catch (Exception ex) {
     try {
       gut = false;
       String programm = "";
       String text =
           "\n Ein Videoplayer zum Abspielen wird nicht gefunden.\n Videoplayer selbst auswählen.";
       DialogProgrammOrdnerOeffnen dialog =
           new DialogProgrammOrdnerOeffnen(parent, true, "", "Videoplayer suchen", text);
       dialog.setVisible(true);
       if (dialog.ok) {
         programm = dialog.ziel;
       }
       String[] cmd = {programm, sFile.getAbsolutePath()};
       Runtime.getRuntime().exec(cmd);
       MVConfig.add(MVConfig.Configs.SYSTEM_PLAYER_ABSPIELEN, programm);
       Listener.notify(Listener.EREIGNIS_PROGRAMM_OEFFNEN, GuiDownloads.class.getSimpleName());
       gut = true;
     } catch (Exception eex) {
       Log.errorLog(959632369, ex, "Ordner öffnen: " + datei);
     }
   } finally {
     if (!gut) {
       MVConfig.add(MVConfig.Configs.SYSTEM_PLAYER_ABSPIELEN, "");
       Listener.notify(Listener.EREIGNIS_PROGRAMM_OEFFNEN, GuiDownloads.class.getSimpleName());
       MVMessageDialog.showMessageDialog(
           parent, "Kann den Videoplayer nicht öffnen!", "Fehler", JOptionPane.ERROR_MESSAGE);
     }
   }
 }
Ejemplo n.º 9
0
 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();
     }
   }
 }
  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);
      }
    }
  }
 @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();
   }
 }
Ejemplo n.º 12
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");
   }
 }
Ejemplo n.º 13
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);
    }
  }
Ejemplo n.º 14
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);
      }
    }
  }
Ejemplo n.º 15
0
  public boolean isMailSupported() {
    if (isSupported()) {
      return desktop.isSupported(Desktop.Action.MAIL);
      /*System.out.println("Desktop.Action.BROWSE :"+desktop.isSupported(Desktop.Action.BROWSE));
      System.out.println("Desktop.Action.EDIT :"+desktop.isSupported(Desktop.Action.EDIT));
      System.out.println("Desktop.Action.OPEN :"+desktop.isSupported(Desktop.Action.OPEN));
      System.out.println("Desktop.Action.PRINT :"+desktop.isSupported(Desktop.Action.PRINT));*/

    }
    // System.out.println("Desktop not supported");
    return false;
  }
 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();
     }
   }
 }
Ejemplo n.º 17
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();
     }
   }
 }
Ejemplo n.º 18
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);
    }
  }
Ejemplo n.º 19
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);
     }
   }
 }
Ejemplo n.º 20
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
Ejemplo n.º 21
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);
    }
  }
Ejemplo n.º 22
0
 private static void createNativesFolder(File folder) {
   if (folder.exists() && !folder.isDirectory()) {
     Desktop desktop = Desktop.getDesktop();
     JButton browseFolder;
     JButton ok = new JButton(UIManager.getString("OptionPane.okButtonText"));
     Object[] options;
     if (desktop.isSupported(Action.BROWSE)) {
       browseFolder = new JButton("Browse Folder");
       options = new Object[] {browseFolder, ok};
     } else {
       browseFolder = null;
       options = new Object[] {ok};
     }
     JOptionPane msg =
         new JOptionPane(
             "We must create this folder \""
                 + folder
                 + "\" and there is a file called natives in its place.\n"
                 + "Rename or move at this time or it will be deleted. Resistance is futile.",
             JOptionPane.INFORMATION_MESSAGE,
             JOptionPane.DEFAULT_OPTION,
             null,
             options);
     if (browseFolder != null) {
       browseFolder.addActionListener(
           action -> {
             try {
               Desktop.getDesktop().browse(folder.getParentFile().toURI());
             } catch (Exception e) {
               UIUtils.displayException("Unable to browse folder", e);
             }
           });
     }
     ok.addActionListener(action -> msg.setValue(0));
     JDialog dialog = msg.createDialog("Slyther");
     try (InputStream icon = ClientMain.class.getResourceAsStream("/textures/icon_32.png")) {
       dialog.setIconImage(ImageIO.read(icon));
     } catch (IOException e) {
     }
     dialog.setVisible(true);
     dialog.dispose();
     folder.delete();
   }
   folder.mkdirs();
 }
Ejemplo n.º 23
0
 /**
  * Use the functionality within {@link java.awt.Desktop} to try opening the user's preferred web
  * browser.
  *
  * @param url URL to visit.
  * @return Either {@code true} if things look ok, {@code false} if there were problems.
  */
 private static boolean openNewStyle(final String url) {
   boolean retVal = false;
   if (Desktop.isDesktopSupported()) {
     Desktop desktop = Desktop.getDesktop();
     if (desktop.isSupported(Desktop.Action.BROWSE)) {
       try {
         desktop.browse(new URI(url));
         // well... the assumption is that there was not a problem
         retVal = true;
       } catch (URISyntaxException e) {
         LogUtil.logException("Bad syntax in URI: " + url, e);
       } catch (IOException e) {
         LogUtil.logException("Problem accessing URI: " + url, e);
       }
     }
   }
   return retVal;
 }
Ejemplo n.º 24
0
 public static void navigate(String url) {
   Desktop desktop;
   if (Desktop.isDesktopSupported()) {
     desktop = Desktop.getDesktop();
     // Now enable buttons for actions that are supported.
     if (desktop.isSupported(Desktop.Action.BROWSE)) {
       URI uri = null;
       try {
         // String dir = System.getProperty("user.dir");
         uri = new URI(url);
         desktop.browse(uri);
       } catch (IOException ioe) {
         ioe.printStackTrace();
       } catch (URISyntaxException use) {
         use.printStackTrace();
       }
     }
   }
 }
  /**
   * Open the aware-p webpage in the browser.
   *
   * @param url
   */
  private void browse(String url) {
    if (!java.awt.Desktop.isDesktopSupported()) {
      System.err.println("Desktop is not supported");
      return;
    }

    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");
      System.exit(1);
    }

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

      System.err.println(e.getMessage());
    }
  }
Ejemplo n.º 26
0
 public static void main(String[] args) {
   try {
     // String url = "http://www.baidu.com";
     String url = "http://nana.dgut.edu.cn";
     java.net.URI uri = java.net.URI.create(url);
     // 获取当前系统桌面扩展
     java.awt.Desktop dp = java.awt.Desktop.getDesktop();
     // 判断系统桌面是否支持要执行的功能
     if (dp.isSupported(java.awt.Desktop.Action.BROWSE)) {
       // File file = new File("D:\\aa.txt");
       // dp.edit(file);//  编辑文件
       dp.browse(uri); // 获取系统默认浏览器打开链接
       // dp.open(file);// 用默认方式打开文件
       // dp.print(file);// 用打印机打印文件
     }
   } catch (java.lang.NullPointerException e) {
     // 此为uri为空时抛出异常
     e.printStackTrace();
   } catch (java.io.IOException e) {
     // 此为无法获取系统默认浏览器
     e.printStackTrace();
   }
 }
  public void openLink() {
    if (java.awt.Desktop.isDesktopSupported()) {
      Desktop desktop = Desktop.getDesktop();

      if (desktop.isSupported(Desktop.Action.BROWSE)) {
        URL url;
        try {
          url = new URL(phpURLAddress);
          URI uri = url.toURI();
          desktop.browse(uri);
        } catch (MalformedURLException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (URISyntaxException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }
    }
  }
  private static void openBrowser(OAuthV2 oAuth) {

    String authorizationUrl = OAuthV2Client.generateAuthorizationURL(oAuth);

    // 调用外部浏览器
    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 (Exception e) {
      e.printStackTrace();
      System.exit(1);
    }

    System.out.println(
        "Input the authorization information (eg: code=CODE&openid=OPENID&openkey=OPENKEY) :");
    Scanner in = new Scanner(System.in);
    String responseData = in.nextLine();
    in.close();

    if (OAuthV2Client.parseAuthorization(responseData, oAuth)) {
      System.out.println("Parse Authorization Information Successfully");
    } else {
      System.out.println("Fail to Parse Authorization Information");
      return;
    }
  }
Ejemplo n.º 29
0
  protected final void showMsg(final String msg, final boolean quit) {
    final JPanel p = new JPanel();
    p.setLayout(new GridBagLayout());
    final GridBagConstraints c = new GridBagConstraints();
    c.insets = new Insets(10, 10, 10, 10);
    c.gridx = 0;
    c.gridy = 0;
    c.fill = GridBagConstraints.BOTH;
    final JImage im = new JImage(new ImageIcon(this.getClass().getResource("error.png")));
    final JLabel l = new JLabel("Une erreur est survenue");
    l.setFont(l.getFont().deriveFont(Font.BOLD));
    final JLabel lError = new JLabel(msg);

    final JTextArea textArea = new JTextArea();
    textArea.setFont(textArea.getFont().deriveFont(11f));

    c.gridheight = 3;
    p.add(im, c);
    c.insets = new Insets(2, 4, 2, 4);
    c.gridheight = 1;
    c.gridx++;
    c.weightx = 1;
    c.gridwidth = 2;
    p.add(l, c);
    c.gridy++;
    p.add(lError, c);

    c.gridy++;
    p.add(
        new JLabel(
            "Il s'agit probablement d'une mauvaise configuration ou installation du logiciel."),
        c);

    c.gridx = 0;
    c.gridwidth = 3;
    c.gridy++;
    c.weighty = 0;
    c.gridwidth = 1;
    c.gridx = 1;
    c.gridy++;

    c.fill = GridBagConstraints.NONE;
    c.anchor = GridBagConstraints.EAST;
    final Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
    final boolean browseSupported = desktop != null && desktop.isSupported(Action.BROWSE);
    if (ForumURL != null) {
      final javax.swing.Action communityAction;
      if (browseSupported) {
        communityAction =
            new AbstractAction("Consulter le forum") {
              @Override
              public void actionPerformed(ActionEvent e) {
                try {
                  desktop.browse(new URI(ForumURL));
                } catch (Exception e1) {
                  e1.printStackTrace();
                }
              }
            };
      } else {
        communityAction =
            new AbstractAction("Copier l'adresse du forum") {
              @Override
              public void actionPerformed(ActionEvent e) {
                copyToClipboard(ForumURL);
              }
            };
      }
      p.add(new JButton(communityAction), c);
    }
    c.weightx = 0;
    c.gridx++;

    final javax.swing.Action supportAction;
    if (browseSupported)
      supportAction =
          new AbstractAction("Contacter l'assistance") {
            @Override
            public void actionPerformed(ActionEvent e) {
              try {
                desktop.browse(URI.create(ILM_CONTACT));
              } catch (Exception e1) {
                e1.printStackTrace();
              }
            }
          };
    else
      supportAction =
          new AbstractAction("Copier l'adresse de l'assistance") {
            @Override
            public void actionPerformed(ActionEvent e) {
              copyToClipboard(ILM_CONTACT);
            }
          };

    p.add(new JButton(supportAction), c);
    c.gridy++;
    c.gridx = 0;
    c.gridwidth = 3;
    c.fill = GridBagConstraints.BOTH;
    c.insets = new Insets(0, 0, 0, 0);
    p.add(new JSeparator(), c);

    c.gridx = 0;
    c.gridwidth = 3;
    c.gridy++;
    c.insets = new Insets(2, 4, 2, 4);
    p.add(new JLabel("Détails de l'erreur:"), c);
    c.insets = new Insets(0, 0, 0, 0);
    c.gridy++;
    String message = this.getCause() == null ? null : this.getCause().getMessage();
    if (message == null) {
      message = msg;
    } else {
      message = msg + "\n\n" + message;
    }
    message += "\n";
    message += getTrace();
    textArea.setText(message);
    textArea.setEditable(false);
    // Scroll
    JScrollPane scroll = new JScrollPane(textArea);
    scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
    scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    scroll.getViewport().setMinimumSize(new Dimension(200, 300));
    c.weighty = 1;
    c.gridwidth = 3;
    c.gridx = 0;
    c.gridy++;
    p.add(scroll, c);

    c.gridy++;
    c.fill = GridBagConstraints.NONE;
    c.weighty = 0;
    c.insets = new Insets(2, 4, 2, 4);
    final JButton buttonClose = new JButton("Fermer");
    p.add(buttonClose, c);

    final Window window = this.comp == null ? null : SwingUtilities.getWindowAncestor(this.comp);
    final JDialog f;
    if (window instanceof Frame) {
      f = new JDialog((Frame) window, "Erreur", true);
    } else {
      f = new JDialog((Dialog) window, "Erreur", true);
    }
    f.setContentPane(p);
    f.pack();
    f.setSize(580, 680);
    f.setMinimumSize(new Dimension(380, 380));
    f.setLocationRelativeTo(this.comp);
    final ActionListener al =
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            if (quit) {
              System.exit(1);
            } else {
              f.dispose();
            }
          }
        };
    buttonClose.addActionListener(al);
    // cannot set EXIT_ON_CLOSE on JDialog
    f.addWindowListener(
        new WindowAdapter() {
          @Override
          public void windowClosing(WindowEvent e) {
            al.actionPerformed(null);
          }
        });
    f.setVisible(true);
  }
Ejemplo n.º 30
0
  /**
   * Try to determine whether this application is running under Windows or some other platform by
   * examining the "os.name" property.
   */
  static {
    String os = System.getProperty("os.name");
    // String version = System.getProperty("os.version"); // for Win7, reports "6.0" on JDK7, should
    // be "6.1"; for Win8, reports "6.2" as of JDK7u17

    if (SystemUtils.startsWithIgnoreCase(os, "windows 7"))
      isWin7 = true; // reports "Windows Vista" on JDK7
    else if (SystemUtils.startsWithIgnoreCase(os, "windows 8"))
      isWin7 = true; // reports "Windows 8" as of JDK7u17
    else if (SystemUtils.startsWithIgnoreCase(os, "windows vista")) isVista = true;
    else if (SystemUtils.startsWithIgnoreCase(os, "windows xp")) isWinXP = true;
    else if (SystemUtils.startsWithIgnoreCase(os, "windows 2000")) isWin2k = true;
    else if (SystemUtils.startsWithIgnoreCase(os, "windows nt")) isWinNT = true;
    else if (SystemUtils.startsWithIgnoreCase(os, "windows"))
      isWin9X = true; // win95 or win98 (what about WinME?)
    else if (SystemUtils.startsWithIgnoreCase(os, "mac")) isMac = true;
    else if (SystemUtils.startsWithIgnoreCase(os, "so")) isSolaris = true; // sunos or solaris
    else if (os.equalsIgnoreCase("linux")) isLinux = true;
    else isUnix = true; // assume UNIX, e.g. AIX, HP-UX, IRIX

    String osarch = System.getProperty("os.arch");
    String arch = (osarch != null && osarch.contains("64")) ? "_x64" /* eg. 'amd64' */ : "_x32";
    String syslib = SYSLIB + arch;

    try { // loading a native lib in a static initializer ensures that it is available before any
          // method in this class is called:
      System.loadLibrary(syslib);
      System.out.println(
          "Done loading '" + System.mapLibraryName(syslib) + "', PID=" + getProcessID());
    } catch (Error e) {
      System.err.println(
          "Native library '"
              + System.mapLibraryName(syslib)
              + "' not found in 'java.library.path': "
              + System.getProperty("java.library.path"));
      throw e; // re-throw
    }

    if (isWinPlatform()) {
      System.setProperty(
          "line.separator", "\n"); // so we won't have to mess with DOS line endings ever again
      comSpec =
          getEnv(
              "comSpec"); // use native method here since getEnvironmentVariable() needs to know
                          // comSpec
      comSpec = (comSpec != null) ? comSpec + " /c " : "";

      try (BufferedReader br =
          new BufferedReader(
              new InputStreamReader(
                  RUNTIME.exec(comSpec + "ver").getInputStream()))) { // fix for Win7,8
        for (String line = null; (line = br.readLine()) != null; ) {
          if (isVista && (line.contains("6.1" /*Win7*/) || line.contains("6.2" /*Win8*/))) {
            isVista = false;
            isWin7 = true;
          }
        }
      } catch (IOException e) {
        e.printStackTrace();
      }

      String cygdir = getEnv("cygdir"); // this is set during CygWin install to "?:/cygwin/bin"
      isCygWin = (cygdir != null && !cygdir.equals("%cygdir%"));
      cygstartPath = cygdir + "/cygstart.exe"; // path to CygWin's cygutils' "cygstart" binary

      if (getDebug() && Desktop.isDesktopSupported()) {
        Desktop desktop = Desktop.getDesktop();
        for (Desktop.Action action : Desktop.Action.values())
          System.out.println(
              "Desktop action " + action + " supported?  " + desktop.isSupported(action));
      }
    }
  }