Ejemplo n.º 1
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);
    }
  }
Ejemplo n.º 2
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);
    }
  }
Ejemplo n.º 3
0
 private static void openUpWebSite(String url) {
   Desktop d = Desktop.getDesktop();
   try {
     d.browse(new URI(url));
   } catch (Exception e) {
   }
 }
Ejemplo n.º 4
0
  public HyberLinkLabel(String text, String url) {
    this.text = text;
    this.url = url;
    try {
      this.isSupported =
          Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE);
    } catch (Exception e) {
      System.out.println("Browse is not supported");
      this.isSupported = false;
    }
    setActive(false);
    addMouseListener(
        new MouseAdapter() {
          public void mouseEntered(MouseEvent e) {
            setActive(isSupported);
            if (isSupported) setCursor(new Cursor(Cursor.HAND_CURSOR));
          }

          public void mouseExited(MouseEvent e) {
            setActive(false);
          }

          public void mouseClicked(MouseEvent e) {
            try {
              Desktop.getDesktop().browse(new java.net.URI(HyberLinkLabel.this.url));
            } catch (Exception ex) {
              System.out.println(ex.toString());
            }
          }
        });
  }
 private void openContentDirectory() {
   try {
     if (Desktop.isDesktopSupported()) {
       Desktop.getDesktop().open(new File(ForgeConstants.CACHE_DIR));
     }
   } catch (final Exception e) {
     System.out.println("Unable to open Directory: " + e.toString());
   }
 }
Ejemplo n.º 6
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.º 7
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;
  }
Ejemplo n.º 8
0
 @Override
 public void actionPerformed(ActionEvent e) {
   if (e.getSource().equals(this.browseButton)) {
     openFileChooser();
   } else if (e.getSource().equals(this.startExtractionButton)) {
     startExtraction();
   } else if (e.getSource().equals(this.openRootDirectoryButton)) {
     Desktop desktop = Desktop.getDesktop();
     try {
       desktop.open(EmojiTools.getRootDirectory());
     } catch (IOException e1) {
       EmojiTools.submitError(Thread.currentThread(), e1);
     }
   }
 }
Ejemplo n.º 9
0
 public void actionPerformed(ActionEvent event) {
   String link = "http://cran.r-project.org/web/views/Graphics.html";
   try {
     Desktop.getDesktop().browse(new URI(link));
   } catch (Exception ex) {
   }
 }
Ejemplo n.º 10
0
 public void secureUse(File fi) {
   // System.out.println("Using " + fi.getAbsolutePath());
   try {
     Desktop.getDesktop().open(fi);
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
 private void onDownload() {
   try {
     Desktop.getDesktop().browse(new URI(downloadURL));
   } catch (IOException | URISyntaxException e) {
     e.printStackTrace();
   }
   dispose();
 }
Ejemplo n.º 12
0
  public void openLink(String link) {
    if (WWUtil.isEmpty(link)) return;

    try {
      try {
        // See if the link is a URL, and invoke the browser if it is
        URL url = new URL(link.replace(" ", "%20"));
        Desktop.getDesktop().browse(url.toURI());
        return;
      } catch (MalformedURLException ignored) { // just means that the link is not a URL
      }

      // It's not a URL, so see if it's a file and invoke the desktop to open it if it is.
      File file = new File(link);
      if (file.exists()) {
        Desktop.getDesktop().open(new File(link));
        return;
      }

      String message = "Cannot open resource. It's not a valid file or URL.";
      Util.getLogger().log(Level.SEVERE, message);
      this.showErrorDialog(null, "No Reconocido V\u00ednculo", message);
    } catch (UnsupportedOperationException e) {
      String message =
          "Unable to open resource.\n"
              + link
              + (e.getMessage() != null ? "\n" + e.getMessage() : "");
      Util.getLogger().log(Level.SEVERE, message, e);
      this.showErrorDialog(e, "Error Opening Resource", message);
    } catch (IOException e) {
      String message =
          "I/O error while opening resource.\n"
              + link
              + (e.getMessage() != null ? ".\n" + e.getMessage() : "");
      Util.getLogger().log(Level.SEVERE, message, e);
      this.showErrorDialog(e, "I/O Error", message);
    } catch (Exception e) {
      String message =
          "Error attempting to open resource.\n"
              + link
              + (e.getMessage() != null ? "\n" + e.getMessage() : "");
      Util.getLogger().log(Level.SEVERE, message);
      this.showMessageDialog(message, "Error Opening Resource", JOptionPane.ERROR_MESSAGE);
    }
  }
Ejemplo n.º 13
0
  /**
   * 访问服务器环境
   *
   * @param names 参数名字
   * @param values 参数值
   */
  public static void visitEnvServerByParameters(String[] names, String[] values) {
    int len = Math.min(ArrayUtils.getLength(names), ArrayUtils.getLength(values));
    String[] segs = new String[len];
    for (int i = 0; i < len; i++) {
      try {
        // 设计器里面据说为了改什么界面统一, 把分隔符统一用File.separator, 意味着在windows里面报表路径变成了\
        // 以前的超链, 以及预览url什么的都是/, 产品组的意思就是用到的地方替换下, 真恶心.
        String value = values[i].replaceAll("\\\\", "/");
        segs[i] =
            URLEncoder.encode(CodeUtils.cjkEncode(names[i]), EncodeConstants.ENCODING_UTF_8)
                + "="
                + URLEncoder.encode(CodeUtils.cjkEncode(value), "UTF-8");
      } catch (UnsupportedEncodingException e) {
        FRContext.getLogger().error(e.getMessage(), e);
      }
    }
    String postfixOfUri = (segs.length > 0 ? "?" + StableUtils.join(segs, "&") : StringUtils.EMPTY);

    if (FRContext.getCurrentEnv() instanceof RemoteEnv) {
      try {
        if (Utils.isEmbeddedParameter(postfixOfUri)) {
          String time = Calendar.getInstance().getTime().toString().replaceAll(" ", "");
          boolean isUserPrivilege =
              ((RemoteEnv) FRContext.getCurrentEnv()).writePrivilegeMap(time, postfixOfUri);
          postfixOfUri =
              isUserPrivilege
                  ? postfixOfUri
                      + "&fr_check_url="
                      + time
                      + "&id="
                      + FRContext.getCurrentEnv().getUserID()
                  : postfixOfUri;
        }

        String urlPath = getWebBrowserPath();
        Desktop.getDesktop().browse(new URI(urlPath + postfixOfUri));
      } catch (Exception e) {
        FRContext.getLogger().error("cannot open the url Successful", e);
      }
    } else {
      try {
        String web = GeneralContext.getCurrentAppNameOfEnv();
        String url =
            "http://localhost:"
                + DesignerEnvManager.getEnvManager().getJettyServerPort()
                + "/"
                + web
                + "/"
                + ConfigManager.getProviderInstance().getServletMapping()
                + postfixOfUri;
        StartServer.browerURLWithLocalEnv(url);
      } catch (Throwable e) {
        //
      }
    }
  }
Ejemplo n.º 14
0
 void browse(String urlStr) {
   try {
     Desktop.getDesktop().browse(new URI(urlStr));
   } catch (Exception ex) {
     showDialog();
     statusBar.setText(ex.getLocalizedMessage());
     if (JConsole.isDebug()) {
       ex.printStackTrace();
     }
   }
 }
Ejemplo n.º 15
0
  public void initialize() throws Exception {
    Security.setProperty("networkaddress.cache.ttl", AWS_RECOMMENDED_DNS_CACHE_TTL);
    AbstractNavigation.DEFAULT_AUTOCOMMIT_DELAY = 2000;

    String defaultEncoding = System.getProperty("file.encoding");
    if (!defaultEncoding.equals("UTF-8")) {
      logger.warn("default encoding " + defaultEncoding + " is not UTF-8");
    }

    initContainer();
    initPlugins();
    initGui();
    documentLauncher =
        url ->
            new Thread(
                    () -> {
                      try {
                        Desktop.getDesktop().browse(new URI(url));
                      } catch (IOException | URISyntaxException e) {
                        logger.error("failed to open uri", e);
                      }
                    })
                .start();
  }
Ejemplo n.º 16
0
  public EditorPaneHTMLHelp(String htmlFile) {
    if (GlobalValues.useSystemBrowserForHelp) {
      Desktop d = GlobalValues.desktop;
      try {
        // create a temp file
        GlobalValues.forHTMLHelptempFile = new File("tempHTMLHelpSynthetic.html");
        FileWriter fw = new FileWriter(GlobalValues.forHTMLHelptempFile);

        java.util.List<String> list = readTextFromJar(htmlFile);
        Iterator<String> it = list.iterator();
        while (it.hasNext()) {
          fw.write(it.next() + "\n");
        }

        String canonicalPathOfFile = GlobalValues.forHTMLHelptempFile.getCanonicalPath();
        URL urlFile = new URL("file://" + canonicalPathOfFile);
        URI uriOfFile = urlFile.toURI();

        fw.close();

        d.browse(uriOfFile);

      } catch (Exception e) {
        e.printStackTrace();
      }

    } else {
      URL initialURL = getClass().getResource(htmlFile);

      font = GlobalValues.htmlfont;

      String title = "HTML Help";
      setTitle(title);

      final Stack<String> urlStack = new Stack<String>();
      final JEditorPane editorPane;

      editorPane = new JEditorPane(new HTMLEditorKit().getContentType(), " ");

      editorPane.setOpaque(false);
      editorPane.setBorder(null);
      editorPane.setEditable(false);

      JPanel magPanel = new JPanel();

      magnificationFactor = GlobalValues.helpMagnificationFactor;
      magFactor = new JTextField(Double.toString(magnificationFactor));

      JButton magButton = new JButton("Set Magnification: ");
      magButton.addActionListener(
          new ActionListener() {

            public void actionPerformed(ActionEvent e) {
              magnificationFactor = Double.parseDouble(magFactor.getText());
              GlobalValues.helpMagnificationFactor = magnificationFactor;
            }
          });

      magPanel.setLayout(new GridLayout(1, 2));
      magPanel.add(magButton);
      magPanel.add(magFactor);

      final JTextField url = new JTextField(initialURL.toString());

      // set up hyperlink listener
      editorPane.setEditable(false);

      try {
        // remember URL for back button
        urlStack.push(initialURL.toString());
        // show URL in text field
        url.setText(initialURL.toString());

        // add a CSS rule to force body tags to use the default label font
        // instead of the value in javax.swing.text.html.default.csss

        String bodyRule =
            "body { font-family: "
                + font.getFamily()
                + "; "
                + "font-size: "
                + font.getSize() * GlobalValues.helpMagnificationFactor
                + "pt; }";
        ((HTMLDocument) editorPane.getDocument()).getStyleSheet().addRule(bodyRule);

        editorPane.setPage(initialURL);

        editorPane.firePropertyChange("dummyProp", true, false);

      } catch (IOException e) {
        editorPane.setText("Exception: " + e);
      }

      editorPane.addPropertyChangeListener(
          new PropertyChangeListener() {

            public void propertyChange(PropertyChangeEvent evt) {

              String bodyRule =
                  "body { font-family: "
                      + font.getFamily()
                      + "; "
                      + "font-size: "
                      + font.getSize() * GlobalValues.helpMagnificationFactor
                      + "pt; }";
              ((HTMLDocument) editorPane.getDocument()).getStyleSheet().addRule(bodyRule);
            }
          });

      editorPane.addHyperlinkListener(
          new HyperlinkListener() {
            public void hyperlinkUpdate(HyperlinkEvent event) {
              if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                try {
                  // remember URL for back button
                  urlStack.push(event.getURL().toString());
                  // show URL in text field
                  url.setText(event.getURL().toString());
                  editorPane.setPage(event.getURL());

                  editorPane.firePropertyChange("dummyProp", true, false);

                } catch (IOException e) {
                  editorPane.setText("Exception: " + e);
                }
              }
            }
          });

      // set up checkbox for toggling edit mode
      final JCheckBox editable = new JCheckBox();
      editable.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent event) {
              editorPane.setEditable(editable.isSelected());
            }
          });

      // set up load button for loading URL
      ActionListener listener =
          new ActionListener() {
            public void actionPerformed(ActionEvent event) {
              try {
                // remember URL for back button
                urlStack.push(url.getText());
                editorPane.setPage(url.getText());

                editorPane.firePropertyChange("dummyProp", true, false);

              } catch (IOException e) {
                editorPane.setText("Exception: " + e);
              }
            }
          };

      JButton loadButton = new JButton("Load/Magnify");
      loadButton.addActionListener(listener);
      url.addActionListener(listener);

      // set up back button and button action

      JButton backButton = new JButton("Back");
      backButton.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent event) {
              if (urlStack.size() <= 1) return;
              try {
                // get URL from back button
                urlStack.pop();
                // show URL in text field
                String urlString = urlStack.peek();
                url.setText(urlString);
                editorPane.setPage(urlString);

                editorPane.firePropertyChange("dummyProp", true, false);

              } catch (IOException e) {
                editorPane.setText("Exception: " + e);
              }
            }
          });

      JPanel allPanel = new JPanel(new BorderLayout());

      // put all control components in a panel

      JPanel ctrlPanel = new JPanel(new BorderLayout());
      JPanel urlPanel = new JPanel();
      urlPanel.add(new JLabel("URL"));
      urlPanel.add(url);
      JPanel buttonPanel = new JPanel();
      buttonPanel.add(loadButton);
      buttonPanel.add(backButton);
      buttonPanel.add(new JLabel("Editable"));
      buttonPanel.add(magPanel);
      buttonPanel.add(editable);
      ctrlPanel.add(buttonPanel, BorderLayout.NORTH);
      ctrlPanel.add(urlPanel, BorderLayout.CENTER);

      allPanel.add(ctrlPanel, BorderLayout.NORTH);
      allPanel.add(new JScrollPane(editorPane), BorderLayout.CENTER);

      add(allPanel);
    }
  }
Ejemplo n.º 17
0
 // open default mail client (use the mailto: protocol as the URI), eg.:
 // mailto:[email protected]?SUBJECT=Love me tender&BODY=love me sweet
 public static void mail(URI document) throws IOException {
   if (Desktop.isDesktopSupported()) Desktop.getDesktop().mail(document);
 }
Ejemplo n.º 18
0
 // print a file
 public static void print(File document) throws IOException {
   if (Desktop.isDesktopSupported()) Desktop.getDesktop().print(document);
 }
Ejemplo n.º 19
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));
      }
    }
  }
Ejemplo n.º 20
0
 static boolean isBrowseSupported() {
   return (Desktop.isDesktopSupported()
       && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE));
 }
Ejemplo n.º 21
0
 public void actionPerformed(ActionEvent evt) {
   String cmd = evt.getActionCommand();
   try {
     if (cmd != null) {
       if (cmd.equalsIgnoreCase("Exit")) {
         System.exit(0);
       }
       if (cmd.equalsIgnoreCase("View Images")) {
         if (Desktop.isDesktopSupported()) {
           // if(Desktop.getDesktop().isSupported(Action.OPEN)) {
           Desktop.getDesktop().open(new File("C:/.hack3rClient/Scre"));
           // }
         }
       }
       if (cmd.equalsIgnoreCase("Toggle 10x Damage")) {
         newDamage = true;
       }
       if (cmd.equalsIgnoreCase("Untoggle 10x Damage")) {
         newDamage = false;
       }
       if (cmd.equalsIgnoreCase("Website")) {
         openUpWebSite("http://vestigex.com");
       }
       if (cmd.equalsIgnoreCase("Forums")) {
         openUpWebSite("http://vestigex.com/forums/forum.php");
       }
       if (cmd.equalsIgnoreCase("Vote")) {
         openUpWebSite("http://vestigex.com/vote.php");
       }
       if (cmd.equalsIgnoreCase("Donate")) {
         openUpWebSite("http://vestigex.com/donate.html");
       }
       if (cmd.equalsIgnoreCase("Highscores")) {
         openUpWebSite("http://vestigex.com/highscores/");
       }
       if (cmd.equalsIgnoreCase("Guides")) {
         openUpWebSite("http://vestigex.com/forums/forum.php");
       }
       if (cmd.equalsIgnoreCase("Support")) {
         openUpWebSite("vestigex.com/forums/forum.php");
         JOptionPane.showMessageDialog(
             this,
             "A link to our support center on our forums has Popped up. Please create a new thread!",
             "Client Support",
             JOptionPane.INFORMATION_MESSAGE);
       }
       if (cmd.equalsIgnoreCase("Client Information")) {
         JOptionPane.showMessageDialog(
             this,
             "Vestige-x is Developed By Bill. We hope you enjoy the server!",
             "Client Updates",
             JOptionPane.INFORMATION_MESSAGE);
       }
       if (cmd.equalsIgnoreCase("World Map")) {
         launchURL("3. WorldMap.jar");
       }
       if (cmd.equalsIgnoreCase("Item Search")) {
         launchURL("1. ItemList.bat");
       }
       if (cmd.equalsIgnoreCase("Screenshot")) {
         takeScreenshot(true);
       }
     }
   } catch (Exception e) {
   }
 }
Ejemplo n.º 22
0
  public DesktopAppFrame() {
    setLayout(new GridBagLayout());
    final JFileChooser chooser = new JFileChooser();
    JButton fileChooserButton = new JButton("...");
    final JTextField fileField = new JTextField(20);
    fileField.setEditable(false);
    JButton openButton = new JButton("Open");
    JButton editButton = new JButton("Edit");
    JButton printButton = new JButton("Print");
    final JTextField browseField = new JTextField();
    JButton browseButton = new JButton("Browse");
    final JTextField toField = new JTextField();
    final JTextField subjectField = new JTextField();
    JButton mailButton = new JButton("Mail");

    openButton.setEnabled(false);
    editButton.setEnabled(false);
    printButton.setEnabled(false);
    browseButton.setEnabled(false);
    mailButton.setEnabled(false);

    if (Desktop.isDesktopSupported()) {
      Desktop desktop = Desktop.getDesktop();
      if (desktop.isSupported(Desktop.Action.OPEN)) openButton.setEnabled(true);
      if (desktop.isSupported(Desktop.Action.EDIT)) editButton.setEnabled(true);
      if (desktop.isSupported(Desktop.Action.PRINT)) printButton.setEnabled(true);
      if (desktop.isSupported(Desktop.Action.BROWSE)) browseButton.setEnabled(true);
      if (desktop.isSupported(Desktop.Action.MAIL)) mailButton.setEnabled(true);
    }

    fileChooserButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (chooser.showOpenDialog(DesktopAppFrame.this) == JFileChooser.APPROVE_OPTION)
              fileField.setText(chooser.getSelectedFile().getAbsolutePath());
          }
        });

    openButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            try {
              Desktop.getDesktop().open(chooser.getSelectedFile());
            } catch (IOException ex) {
              ex.printStackTrace();
            }
          }
        });

    editButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            try {
              Desktop.getDesktop().edit(chooser.getSelectedFile());
            } catch (IOException ex) {
              ex.printStackTrace();
            }
          }
        });

    printButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            try {
              Desktop.getDesktop().print(chooser.getSelectedFile());
            } catch (IOException ex) {
              ex.printStackTrace();
            }
          }
        });

    browseButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            try {
              Desktop.getDesktop().browse(new URI(browseField.getText()));
            } catch (URISyntaxException ex) {
              ex.printStackTrace();
            } catch (IOException ex) {
              ex.printStackTrace();
            }
          }
        });

    mailButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            try {
              String subject = percentEncode(subjectField.getText());
              URI uri = new URI("mailto:" + toField.getText() + "?subject=" + subject);

              System.out.println(uri);
              Desktop.getDesktop().mail(uri);
            } catch (URISyntaxException ex) {
              ex.printStackTrace();
            } catch (IOException ex) {
              ex.printStackTrace();
            }
          }
        });

    JPanel buttonPanel = new JPanel();
    ((FlowLayout) buttonPanel.getLayout()).setHgap(2);
    buttonPanel.add(openButton);
    buttonPanel.add(editButton);
    buttonPanel.add(printButton);

    add(fileChooserButton, new GBC(0, 0).setAnchor(GBC.EAST).setInsets(2));
    add(fileField, new GBC(1, 0).setFill(GBC.HORIZONTAL));
    add(buttonPanel, new GBC(2, 0).setAnchor(GBC.WEST).setInsets(0));
    add(browseField, new GBC(1, 1).setFill(GBC.HORIZONTAL));
    add(browseButton, new GBC(2, 1).setAnchor(GBC.WEST).setInsets(2));
    add(new JLabel("To:"), new GBC(0, 2).setAnchor(GBC.EAST).setInsets(5, 2, 5, 2));
    add(toField, new GBC(1, 2).setFill(GBC.HORIZONTAL));
    add(mailButton, new GBC(2, 2).setAnchor(GBC.WEST).setInsets(2));
    add(new JLabel("Subject:"), new GBC(0, 3).setAnchor(GBC.EAST).setInsets(5, 2, 5, 2));
    add(subjectField, new GBC(1, 3).setFill(GBC.HORIZONTAL));

    pack();
  }
Ejemplo n.º 23
0
  // Listener für die Menüelemente und Buttons
  @Override
  public void actionPerformed(ActionEvent e) {
    if (e.getSource() == btnAusw) {
      LOG.info("DB Verbindung wird hergestellt.");
      dbgetter = new DBConnection(SERVERNAME, PORT, DB, USER, PWD);

      dwAusw = new DWAuswertung(dbgetter);

      lblErgebnis.setText(
          dwAusw.getQuartal(
              (String) cBoxJahr.getSelectedItem(), (String) cBoxQuartal.getSelectedItem()));
    }

    if (e.getSource() == btnAusw2) {
      LOG.info("DB Verbindung wird hergestellt.");
      dbgetter = new DBConnection(SERVERNAME, PORT, DB, USER, PWD);

      dwAusw = new DWAuswertung(dbgetter);
      String[] array =
          dwAusw.getAuswertung(
              (String) cBoxJahr2.getSelectedItem(),
              (String) cBoxQuartal2.getSelectedItem(),
              (String) cBoxEinArt.getSelectedItem(),
              (String) cBoxMitglied.getSelectedItem());

      lblErgebnis_2.setText(array[0]);
      lblMengeErg.setText(array[1]);
    }

    if (e.getSource() == mnItmQExp) {
      pfad = null;
      chooser = new JFileChooser(pfad);
      chooser.setDialogType(JFileChooser.SAVE_DIALOG);
      plainFilter = new FileNameExtensionFilter("*.csv", "csv");
      chooser.removeChoosableFileFilter(chooser.getAcceptAllFileFilter());
      chooser.setFileFilter(plainFilter);
      chooser.setDialogTitle("Speichern unter...");
      chooser.setVisible(true);

      file = null;

      int result = chooser.showSaveDialog(frmAuswertung);
      if (result == JFileChooser.APPROVE_OPTION) {
        file = chooser.getSelectedFile();
      }

      if (plainFilter.accept(file)) {
        LOG.info(file.getAbsolutePath() + " bereit zum speichern.");
        entries = new String[3];
        entries[0] = lblErgebnis.getText().substring(0, lblErgebnis.getText().length() - 4);
        entries[1] = (String) cBoxJahr.getSelectedItem();
        entries[2] = (String) cBoxQuartal.getSelectedItem();

        if (new CSVParser().saveAs(file, entries)) {
          LOG.info("Datei erfolgreich gespeichert.");
          JOptionPane.showMessageDialog(
              new JFrame(),
              "Daten erfolgreich exportiert nach:\n" + file.getAbsolutePath(),
              "Datenexport",
              JOptionPane.INFORMATION_MESSAGE);
        } else {
          LOG.log(Level.WARNING, "Datei nicht gespeichert.");
          JOptionPane.showMessageDialog(
              new JFrame(), "Daten nicht exportiert!", "Datenexport", JOptionPane.ERROR_MESSAGE);
        }
      } else {
        LOG.info(file.getAbsolutePath() + " ist der falsche Dateityp.");
        JOptionPane.showMessageDialog(
            new JFrame(),
            "Bitte folgendes Format nutzen:\n" + "{DATEINAME}.csv",
            "Datenexport",
            JOptionPane.ERROR_MESSAGE);
      }
      chooser.setVisible(false);
    }

    if (e.getSource() == mnItmAExp) {
      pfad = null;
      chooser = new JFileChooser(pfad);
      chooser.setDialogType(JFileChooser.SAVE_DIALOG);
      plainFilter = new FileNameExtensionFilter("*.csv", "csv");
      chooser.removeChoosableFileFilter(chooser.getAcceptAllFileFilter());
      chooser.setFileFilter(plainFilter);
      chooser.setDialogTitle("Speichern unter...");
      chooser.setVisible(true);

      file = null;

      int result = chooser.showSaveDialog(frmAuswertung);
      if (result == JFileChooser.APPROVE_OPTION) {
        file = chooser.getSelectedFile();
      }

      if (plainFilter.accept(file)) {
        LOG.info(file.getAbsolutePath() + " bereit zum speichern.");
        entries = new String[6];
        entries[0] = lblErgebnis.getText().substring(0, lblErgebnis.getText().length() - 4);
        entries[1] = lblMengeErg.getText().substring(0, lblMengeErg.getText().length() - 4);
        entries[2] = (String) cBoxEinArt.getSelectedItem();
        entries[3] = (String) cBoxMitglied.getSelectedItem();
        entries[4] = (String) cBoxJahr.getSelectedItem();
        entries[5] = (String) cBoxQuartal.getSelectedItem();

        if (new CSVParser().saveAs(file, entries)) {
          LOG.info("Datei erfolgreich gespeichert.");
          JOptionPane.showMessageDialog(
              new JFrame(),
              "Daten erfolgreich exportiert nach:\n" + file.getAbsolutePath(),
              "Datenexport",
              JOptionPane.INFORMATION_MESSAGE);
        } else {
          LOG.log(Level.WARNING, "Datei nicht gespeichert.");
          JOptionPane.showMessageDialog(
              new JFrame(), "Daten nicht exportiert!", "Datenexport", JOptionPane.ERROR_MESSAGE);
        }
      } else {
        LOG.info(file.getAbsolutePath() + " ist der falsche Dateityp.");
        JOptionPane.showMessageDialog(
            new JFrame(),
            "Bitte folgendes Format nutzen:\n" + "{DATEINAME}.csv",
            "Datenexport",
            JOptionPane.ERROR_MESSAGE);
      }
      chooser.setVisible(false);
    }

    if (e.getSource() == mnItmLog) {
      try {
        Desktop.getDesktop()
            .browse(
                new URI(
                    "file://"
                        + System.getProperty("user.home")
                        + System.getProperty("file.separator")
                        + "dw-log.html"));
      } catch (URISyntaxException | IOException e1) {
        LOG.log(Level.WARNING, "Protokoll kann nicht geöffnet werden.", e1);
        JOptionPane.showMessageDialog(
            new JFrame(),
            "Protokoll konnte nicht geöffnet werden.",
            "Protokoll öffnen...",
            JOptionPane.ERROR_MESSAGE);
      }
    }

    if (e.getSource() == mnItmQuit) {
      frmAuswertung.dispose();
    }

    if (e.getSource() == mnItmAbout) {
      About frame = new About();
      frame.setVisible(true);
    }
  }