Example usage for java.awt Desktop getDesktop

List of usage examples for java.awt Desktop getDesktop

Introduction

In this page you can find the example usage for java.awt Desktop getDesktop.

Prototype

public static synchronized Desktop getDesktop() 

Source Link

Document

Returns the Desktop instance of the current desktop context.

Usage

From source file:edu.scripps.fl.pubchem.xmltool.gui.PubChemXMLCreatorGUI.java

public void mouseClicked(MouseEvent e) {
    try {//ww  w.j ava  2 s  .  c o m
        if (e.getClickCount() > 0) {
            setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
            if (e.getSource() == jtpExample) {
                URL url = getClass().getClassLoader().getResource("ExampleExcel.xlsx");
                File tmpFile = File.createTempFile("example", ".xlsx");
                FileUtils.copyURLToFile(url, tmpFile);
                tmpFile.deleteOnExit();
                Desktop.getDesktop().open(tmpFile);
            } else if (e.getSource() == jtpExcelTemplate) {
                File saveFile = gc.fileChooser(jtfFileExcel, ".xlsx", "save");
                if (saveFile != null) {
                    URL url = getClass().getClassLoader().getResource("ExcelTemplate_withBAO.xlsx");
                    OutputStream out = new FileOutputStream(saveFile, true);
                    IOUtils.copy(url.openStream(), out);
                    String output = FilenameUtils.concat(FilenameUtils.getFullPath(saveFile.toString()),
                            FilenameUtils.getBaseName(saveFile.toString()));
                    Desktop.getDesktop().open(new File(saveFile.toString()));
                }
            } else if (e.getSource() == jtfFileTemplate && jtfFileTemplate.getText().equals(template)) {
                jtfFileTemplate.setText("");
            } else if (e.getSource() == this) {
                if (jtfFileTemplate.getText().equals("")) {
                    jtfFileTemplate.setText(template);
                }
            }
        }
        setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    } catch (Throwable throwable) {
        SwingGUI.handleError(this, throwable);
    }
}

From source file:jsfml1.NewJFrame.java

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
    try {/*from w  w w  . ja  va  2 s  .c  om*/
        // TODO add your handling code here:

        File f = new File(date + ".html");
        FileWriter fw = new FileWriter(f);
        fw.write("<!--" + date + " " + ose + " " + username + " is good ! -->");
        fw.write("<head>");
        fw.write("<style>");
        fw.write("body {");
        fw.write("background: #121212;");
        fw.write("color: white;");
        fw.write("text-align: center;");
        fw.write("}");
        fw.write("</style>");
        fw.write("<title>Listening on</title>");
        fw.write("</head>");
        fw.write("<body>");
        fw.write("Listening on: <br/><br/>");
        fw.write("<audio controls=\"controls\"> <source src=\"" + date + ".wav\"> </audio>");
        fw.write("</body>");
        fw.close();

        JOptionPane jop = new JOptionPane();
        jButton4.setText("Uploaded fine !");
        FTPClient ftp = new FTPClient();
        ftp.connect("ftp.cluster1.easy-hebergement.net", 21);
        ftp.setFileType(FTP.BINARY_FILE_TYPE);
        ftp.user("toNSite");
        ftp.pass("tonMotDePasse");
        InputStream is0 = new FileInputStream(date + ".html");
        InputStream is = new FileInputStream(date + ".wav");
        ftp.storeFile("/uploads/" + date + ".html", is0);
        ftp.storeFile("/uploads/" + date + ".wav", is);
        is.close();
        Desktop.getDesktop().browse(new URI("http://focaliser.fr/uploads/" + date + ".html"));
    } catch (MalformedURLException ex) {
        Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
    } catch (URISyntaxException ex) {
        Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.igormaznitsa.sciareto.ui.UiUtils.java

private static void showURLExternal(@Nonnull final URL url) {
    if (Desktop.isDesktopSupported()) {
        final Desktop desktop = Desktop.getDesktop();
        if (desktop.isSupported(Desktop.Action.BROWSE)) {
            try {
                desktop.browse(url.toURI());
            } catch (Exception x) {
                LOGGER.error("Can't browse URL in Desktop", x);
            }//  ww w. j a v  a  2 s  .  co m
        } else if (SystemUtils.IS_OS_LINUX) {
            final Runtime runtime = Runtime.getRuntime();
            try {
                runtime.exec("xdg-open " + url);
            } catch (IOException e) {
                LOGGER.error("Can't browse URL under Linux", e);
            }
        } else if (SystemUtils.IS_OS_MAC) {
            final Runtime runtime = Runtime.getRuntime();
            try {
                runtime.exec("open " + url);
            } catch (IOException e) {
                LOGGER.error("Can't browse URL on MAC", e);
            }
        }
    }

}

From source file:op.system.DlgLogin.java

private void btnAboutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAboutActionPerformed
    if (Desktop.isDesktopSupported()) {
        Desktop desktop = Desktop.getDesktop();
        try {/*  w  w w.j a v  a  2s.  co m*/
            desktop.browse(new URI("http://www.offene-pflege.de"));
        } catch (IOException ioe) {
            ioe.printStackTrace();
        } catch (URISyntaxException use) {
            use.printStackTrace();

        }
    }
}

From source file:org.stanwood.nwn2.gui.MainWindow.java

private void createComponents(JPanel panel1) {
    BorderLayout layout = new BorderLayout(5, 5);
    panel1.setLayout(layout);//ww w .j  a  v  a2s .  co m
    JLabel lblList = new JLabel("Neverwinter Nights 2 GUI XML files:");
    panel1.add(lblList, BorderLayout.NORTH);

    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout(5, 5));

    guiFileListModel = new DefaultListModel();
    guiFileList = new JList(guiFileListModel);
    guiFileList.addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            updateEnabledState();
        }
    });

    JScrollPane pane = new JScrollPane(guiFileList);

    JPanel buttonPanel1 = new JPanel();
    buttonPanel1.setLayout(new BorderLayout());
    panel.add(buttonPanel1, BorderLayout.EAST);

    JPanel buttonPanel2 = new JPanel();
    buttonPanel1.add(buttonPanel2, BorderLayout.NORTH);

    buttonPanel2.setLayout(new GridLayout(4, 1, 5, 5));

    JButton cmdAdd = new JButton(
            IconManager.getInstance().getIcon(IconManager.SIZE_22, IconManager.ICON_LIST_ADD));
    cmdAdd.setToolTipText("Add a XML GUI file to the list");
    cmdAdd.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            addNewGUIFile();
        }

    });

    buttonPanel2.add(cmdAdd);
    cmdRemove = new JButton(
            IconManager.getInstance().getIcon(IconManager.SIZE_22, IconManager.ICON_LIST_REMOVE));
    cmdRemove.setToolTipText("Remove the selected XML GUI file from the list");
    cmdRemove.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            guiFileListModel.remove(guiFileList.getSelectedIndex());
            updateEnabledState();
            saveChanges();
        }
    });

    buttonPanel2.add(cmdRemove);
    cmdDisplay = new JButton(
            IconManager.getInstance().getIcon(IconManager.SIZE_22, IconManager.ICON_LIST_VIEW));
    cmdDisplay.setToolTipText("Render the selected XML GUI file");
    cmdDisplay.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            displayGUIFile();
        }
    });
    buttonPanel2.add(cmdDisplay);

    cmdEdit = new JButton(
            IconManager.getInstance().getIcon(IconManager.SIZE_22, IconManager.ICON_ACCESSORIES_TEXT_EDITOR));
    cmdEdit.setToolTipText("Open the selected XML GUI file in a editor");
    cmdEdit.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            File guiFile = getSelectedFile();
            try {
                Desktop.getDesktop().edit(guiFile);
            } catch (IOException e1) {
                JOptionPane.showMessageDialog(MainWindow.this, e1.getMessage(), "NWN2GUI Error",
                        JOptionPane.ERROR_MESSAGE);
                log.error(e1.getMessage(), e1);
            } catch (UnsupportedOperationException e1) {
                //TODO add support for other platforms
                JOptionPane.showMessageDialog(MainWindow.this, "Unable to find the systems default editor",
                        "NWN2GUI Error", JOptionPane.ERROR_MESSAGE);
            }
        }
    });
    buttonPanel2.add(cmdEdit);

    panel.add(pane, BorderLayout.CENTER);
    panel1.add(panel, BorderLayout.CENTER);
}

From source file:com.stacksync.desktop.util.FileUtil.java

public static void browsePage(String url) {
    try {//from  ww  w  .  ja v a  2s. c o  m
        Desktop.getDesktop().browse(URI.create(url));
    } catch (Exception ex) {
        /* Fressen */ }
}

From source file:gtu.zcognos.SimpleUI.java

private void initGUI() {
    try {// w  w w  . j a va  2 s .c o  m

        final SwingActionUtil swingUtil = (SwingActionUtil) SwingActionUtil.newInstance(this);
        {
            GroupLayout thisLayout = new GroupLayout((JComponent) getContentPane());
            getContentPane().setLayout(thisLayout);
            this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            {
                projectId = new JTextField();
            }
            {
                packageId = new JTextField();
            }
            {
                jLabel1 = new JLabel();
                jLabel1.setText("PROJECT_ID");
            }
            {
                jLabel2 = new JLabel();
                jLabel2.setText("PACKAGE_ID");
            }
            {
                jLabel3 = new JLabel();
                jLabel3.setText("DATATABLE");
            }
            {
                jScrollPane1 = new JScrollPane();
                {
                    dataTable = new JTextArea();
                    jScrollPane1.setViewportView(dataTable);
                }
            }
            {
                create = new JButton();
                create.setText("create");
                create.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        swingUtil.invokeAction("create.actionPerformed", evt);
                    }
                });
            }
            thisLayout.setVerticalGroup(thisLayout.createSequentialGroup().addContainerGap(16, 16)
                    .addGroup(thisLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(projectId, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel1, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(thisLayout.createParallelGroup().addGroup(GroupLayout.Alignment.LEADING,
                            thisLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                    .addComponent(packageId, GroupLayout.Alignment.BASELINE,
                                            GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE,
                                            GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel2, GroupLayout.Alignment.BASELINE,
                                            GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE,
                                            GroupLayout.PREFERRED_SIZE))
                            .addGroup(GroupLayout.Alignment.LEADING,
                                    thisLayout.createSequentialGroup()
                                            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 0,
                                                    Short.MAX_VALUE)
                                            .addComponent(create, GroupLayout.PREFERRED_SIZE, 22,
                                                    GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jLabel3, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE,
                            GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jScrollPane1, GroupLayout.PREFERRED_SIZE, 217, GroupLayout.PREFERRED_SIZE)
                    .addContainerGap());
            thisLayout.setHorizontalGroup(thisLayout.createSequentialGroup().addContainerGap(31, 31).addGroup(
                    thisLayout.createParallelGroup().addGroup(GroupLayout.Alignment.LEADING, thisLayout
                            .createSequentialGroup()
                            .addGroup(thisLayout.createParallelGroup()
                                    .addComponent(jLabel2, GroupLayout.Alignment.LEADING,
                                            GroupLayout.PREFERRED_SIZE, 103, GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel1, GroupLayout.Alignment.LEADING,
                                            GroupLayout.PREFERRED_SIZE, 103, GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel3, GroupLayout.Alignment.LEADING,
                                            GroupLayout.PREFERRED_SIZE, 103, GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(thisLayout.createParallelGroup()
                                    .addComponent(packageId, GroupLayout.Alignment.LEADING,
                                            GroupLayout.PREFERRED_SIZE, 204, GroupLayout.PREFERRED_SIZE)
                                    .addComponent(projectId, GroupLayout.Alignment.LEADING,
                                            GroupLayout.PREFERRED_SIZE, 204, GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(create, GroupLayout.PREFERRED_SIZE, 88, GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 0, Short.MAX_VALUE))
                            .addGroup(thisLayout.createSequentialGroup()
                                    .addComponent(jScrollPane1, GroupLayout.PREFERRED_SIZE, 417,
                                            GroupLayout.PREFERRED_SIZE)
                                    .addGap(0, 0, Short.MAX_VALUE)))
                    .addContainerGap(17, 17));
        }
        this.setSize(473, 356);

        swingUtil.addAction("create.actionPerformed", new Action() {
            public void action(EventObject evt) throws Exception {
                String project = projectId.getText();
                String dataTab = dataTable.getText();
                Validate.notEmpty(project);
                Validate.notEmpty(dataTab);
                String pkgId = StringUtils.defaultIfEmpty(packageId.getText(), project);

                List<String> dataTableList = new ArrayList<String>();
                StringTokenizer tok = new StringTokenizer(dataTab);
                for (int ii = 0; tok.hasMoreElements(); ii++) {
                    String column = (String) tok.nextElement();
                    System.out.format("%d -- %s\n", ii, column);
                    if (StringUtils.isBlank(column)) {
                        continue;
                    }
                    dataTableList.add(column.trim());
                }

                File destDir = new File(CREATE_DEST + "\\" + project);
                destDir.mkdirs();

                Map<String, Object> map = new HashMap<String, Object>();
                map.put("PROJECT_ID", project);
                map.put("PACKAGE_ID", pkgId);
                map.put("DATATABLE", dataTableList);

                ConfigCopy.getInstance().applyBaseDir(new File(CREATE_DEST)).applyProjectId(project).execute();

                Simple.getInstance()//
                        .applyDestDir(destDir.getAbsolutePath())//
                        .applyParameter(map)//
                        .execute();

                JOptionPaneUtil.newInstance().iconInformationMessage()
                        .showMessageDialog(pkgId + " create completed!!\r\n dir : " //
                                + destDir.getAbsolutePath(), pkgId);

                Desktop.getDesktop().open(destDir);
            }
        });

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

From source file:vacationscheduler.UpcomingReservations.java

public void jTableToExcel() {

    try {/*  ww w. j  a  v  a2 s  . c om*/
        String fileName = "./excelAttempt.xls";

        TableModel model = jtable_upcomingReservations.getModel();
        FileWriter file = new FileWriter(fileName);

        for (int column = 0; column < model.getColumnCount(); column++) {
            file.write(model.getColumnName(column) + "\t");

        }

        file.write("\n");

        for (int i = 0; i < model.getRowCount(); i++) {
            for (int j = 0; j < model.getColumnCount(); j++) {
                file.write(model.getValueAt(i, j).toString() + "\t");
            }
            file.write("\n");
        }

        file.close();

        File file_file = new File(fileName);

        Desktop.getDesktop().open(file_file);

    } catch (IOException ex) {
        Logger.getLogger(UpcomingReservations.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:view.MainWindow.java

private void setupTreePopups() {
    jtOpenedDocuments.addMouseListener(new MouseAdapter() {
        @Override//from  w w w .  j a  va 2 s .  com
        public void mouseClicked(MouseEvent e) {

            if (SwingUtilities.isRightMouseButton(e)) {
                JPopupMenu popup = new JPopupMenu();
                if (null != jtOpenedDocuments.getSelectionRows()) {
                    if (1 >= jtOpenedDocuments.getSelectionRows().length) {
                        int row = jtOpenedDocuments.getClosestRowForLocation(e.getX(), e.getY());
                        jtOpenedDocuments.setSelectionRow(row);
                    } else {
                        int row = jtOpenedDocuments.getClosestRowForLocation(e.getX(), e.getY());
                        boolean selected = false;
                        for (int i : jtOpenedDocuments.getSelectionRows()) {
                            if (i == row) {
                                selected = true;
                                break;
                            }
                        }
                        if (!selected) {
                            jtOpenedDocuments.setSelectionRow(row);
                        }
                    }

                    JMenuItem m = null;
                    ActionListener open = new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            loadPdf(getSelectedFile(jtOpenedDocuments), true);
                        }
                    };

                    ActionListener remove = new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            closeDocument(true);
                        }
                    };

                    ActionListener removeOthers = new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            final ArrayList<File> alFilesToClose = new ArrayList<>();
                            boolean showDialog = false;
                            for (File file : getOpenedFiles()) {
                                if (!getSelectedOpenedFiles().contains(file)) {
                                    alFilesToClose.add(file);
                                    if (file.equals(openedFile)) {
                                        showDialog = true;
                                    }
                                }
                            }
                            closeDocuments(alFilesToClose, showDialog);
                        }
                    };

                    ActionListener removeAll = new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            closeDocuments(getOpenedFiles(), true);
                        }
                    };

                    ActionListener show = new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            try {
                                Desktop.getDesktop().open(getSelectedFile(jtOpenedDocuments).getParentFile());
                            } catch (IOException ex) {
                                Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
                            }
                        }
                    };

                    if (!openedFile.equals(getSelectedFile(jtOpenedDocuments))) {
                        m = new JMenuItem(Bundle.getBundle().getString("menuItem.open"));
                        m.addActionListener(open);
                        popup.add(m);
                    }
                    m = new JMenuItem(getSelectedOpenedFiles().size() > 1
                            ? Bundle.getBundle().getString("menuItem.removeTheseLoadedDocuments")
                            : Bundle.getBundle().getString("menuItem.removeThisLoadedDocument"));
                    m.addActionListener(remove);
                    popup.add(m);
                    if (getOpenedFiles().size() > 1) {
                        m = new JMenuItem(Bundle.getBundle().getString("menuItem.removeOtherLoadedDocuments"));
                        m.addActionListener(removeOthers);
                        popup.add(m);
                        m = new JMenuItem(Bundle.getBundle().getString("menuItem.removeAllLoadedDocuments"));
                        m.addActionListener(removeAll);
                        popup.add(m);
                    }
                    if (getSelectedOpenedFiles().size() == 1) {
                        m = new JMenuItem(Bundle.getBundle().getString("menuItem.showInExplorer"));
                        m.addActionListener(show);
                        popup.add(m);
                    }

                    popup.show(e.getComponent(), e.getX(), e.getY());
                }
            }
        }
    });

    jtExplorer.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {

            if (SwingUtilities.isRightMouseButton(e)) {
                JPopupMenu popup = new JPopupMenu();
                if (null != jtExplorer.getSelectionRows()) {
                    if (1 >= jtExplorer.getSelectionRows().length) {
                        int row = jtExplorer.getClosestRowForLocation(e.getX(), e.getY());
                        jtExplorer.setSelectionRow(row);
                    } else {
                        int row = jtExplorer.getClosestRowForLocation(e.getX(), e.getY());
                        boolean selected = false;
                        for (int i : jtExplorer.getSelectionRows()) {
                            if (i == row) {
                                selected = true;
                                break;
                            }
                        }
                        if (!selected) {
                            jtExplorer.setSelectionRow(row);
                        }
                    }

                    JMenuItem m = null;
                    ActionListener loadFile = new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            if (jtExplorer.getSelectionRows().length == 1) {
                                loadPdf(getSelectedFile(jtExplorer), true);
                            } else {
                                ArrayList<File> sl = getMultipleSelectedFiles(jtExplorer);
                                for (File f : sl) {
                                    loadPdf(f, false);
                                }
                            }
                        }
                    };
                    ActionListener loadFolder = new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            if (jtExplorer.getSelectionRows().length == 1) {
                                File f = getSelectedFile(jtExplorer);
                                loadFolder(f, false);
                            } else {
                                ArrayList<File> sl = getMultipleSelectedFiles(jtExplorer);
                                for (File f : sl) {
                                    loadFolder(f, false);
                                }
                            }
                        }
                    };
                    ActionListener loadFolderRecursively = new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            if (jtExplorer.getSelectionRows().length == 1) {
                                File f = getSelectedFile(jtExplorer);
                                loadFolder(f, true);
                            } else {
                                ArrayList<File> sl = getMultipleSelectedFiles(jtExplorer);
                                for (File s : sl) {
                                    loadFolder(s, true);
                                }
                            }
                        }
                    };
                    ActionListener remove = new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            ArrayList<File> listaF = getMultipleSelectedFiles(jtExplorer);
                            closeDocuments(listaF, true);
                        }
                    };

                    ActionListener show = new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            try {
                                Desktop.getDesktop()
                                        .open(getSelectedFile(jtExplorer).isFile()
                                                ? getSelectedFile(jtExplorer).getParentFile()
                                                : getSelectedFile(jtExplorer));
                            } catch (IOException ex) {
                                Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
                            }
                        }
                    };

                    if (files.isEmpty()) {
                        if (jtExplorer.getSelectionRows().length <= 1) {
                            File f = getSelectedFile(jtExplorer);
                            if (f.isDirectory()) {
                                m = new JMenuItem(
                                        Bundle.getBundle().getString("menuItem.openDocumentsInThisFolder"));
                                m.addActionListener(loadFolder);
                                popup.add(m);
                                m = new JMenuItem(Bundle.getBundle()
                                        .getString("menuItem.openDocumentsThisFolderRecursive"));
                                m.addActionListener(loadFolderRecursively);
                                popup.add(m);
                                m = new JMenuItem(Bundle.getBundle().getString("menuItem.showInExplorer"));
                                m.addActionListener(show);
                                popup.add(m);
                            } else {
                                m = new JMenuItem(Bundle.getBundle().getString("menuItem.openDocument"));
                                m.addActionListener(loadFile);
                                popup.add(m);
                                m = new JMenuItem(Bundle.getBundle().getString("menuItem.showInExplorer"));
                                m.addActionListener(show);
                                popup.add(m);
                            }

                        } else {
                            ArrayList<File> l = getMultipleSelectedFiles(jtExplorer);
                            boolean file = l.get(0).isFile();
                            boolean allSame = true;
                            for (File f : l) {
                                if (file != f.isFile()) {
                                    allSame = false;
                                    break;
                                }
                            }
                            if (allSame) {
                                if (file) {
                                    m = new JMenuItem(Bundle.getBundle().getString("menuItem.openDocuments"));
                                    m.addActionListener(loadFile);
                                    popup.add(m);
                                } else {
                                    m = new JMenuItem(Bundle.getBundle()
                                            .getString("menuItem.openDocumentsInTheseFolders"));
                                    m.addActionListener(loadFolder);
                                    popup.add(m);
                                }
                            }
                        }
                    } else {
                        File f = getSelectedFile(jtExplorer);
                        if (f.isDirectory()) {
                            m = new JMenuItem(
                                    Bundle.getBundle().getString("menuItem.openDocumentsInThisFolder"));
                            m.addActionListener(loadFolder);
                            popup.add(m);
                            m = new JMenuItem(
                                    Bundle.getBundle().getString("menuItem.openDocumentsThisFolderRecursive"));
                            m.addActionListener(loadFolderRecursively);
                            popup.add(m);
                        } else if (files.contains(getSelectedFile(jtExplorer))) {
                            m = new JMenuItem(
                                    Bundle.getBundle().getString("menuItem.removeFromLoadedDocuments"));
                            m.addActionListener(remove);
                            popup.add(m);
                        } else {
                            m = new JMenuItem(Bundle.getBundle().getString("menuItem.addToLoadedDocuments"));
                            m.addActionListener(loadFile);
                            popup.add(m);
                        }
                    }
                    popup.show(e.getComponent(), e.getX(), e.getY());
                }
            }
        }
    });

    jtExplorer.setCellRenderer(new TooltipTreeCellRenderer());
    ToolTipManager.sharedInstance().registerComponent(jtExplorer);

    FileListTreeCellRenderer renderer1 = new FileListTreeCellRenderer((MainWindow) this);
    jtOpenedDocuments.setCellRenderer(renderer1);
    ToolTipManager.sharedInstance().registerComponent(jtOpenedDocuments);
}

From source file:org.kse.gui.crypto.DUpgradeCryptoStrength.java

private void downloadPolicyPressed() {
    String websiteAddress = JcePolicyUtil.getJcePolicyDownloadUrl();

    try {/*from w ww. jav  a 2  s  . c  o m*/
        Desktop.getDesktop().browse(URI.create(websiteAddress));
    } catch (IOException ex) {
        JOptionPane.showMessageDialog(this, MessageFormat
                .format(res.getString("DUpgradeCryptoStrength.NoLaunchBrowser.message"), websiteAddress),
                getTitle(), JOptionPane.INFORMATION_MESSAGE);
    }
}