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:gtu._work.ui.JarFinderUI.java

private void initGUI() {
    try {/*  w ww .j ava  2  s  .c  o m*/

        BorderLayout thisLayout = new BorderLayout();
        getContentPane().setLayout(thisLayout);
        this.setTitle("Jar finder");
        {
            jTabbedPane1 = new JTabbedPane();
            getContentPane().add(jTabbedPane1, BorderLayout.CENTER);
            {
                jPanel1 = new JPanel();
                BorderLayout jPanel1Layout = new BorderLayout();
                jPanel1.setLayout(jPanel1Layout);
                jTabbedPane1.addTab("src dir", null, jPanel1, null);
                {
                    openDir = new JButton();
                    jPanel1.add(openDir, BorderLayout.NORTH);
                    openDir.setText("open dir");
                    openDir.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            jButton1ActionPerformed(evt);
                        }
                    });
                }
                {
                    jScrollPane1 = new JScrollPane();
                    jPanel1.add(jScrollPane1, BorderLayout.CENTER);
                    jScrollPane1.setPreferredSize(new java.awt.Dimension(406, 255));
                    {
                        DefaultListModel jList1Model = new DefaultListModel();
                        try {
                            prop.load(new FileInputStream(CONFIG_FILE));
                            for (Enumeration<?> enu = prop.keys(); enu.hasMoreElements();) {
                                File val = new File((String) enu.nextElement());
                                jList1Model.addElement(val);
                            }
                        } catch (Exception ex) {
                            JCommonUtil.handleException("??:" + CONFIG_FILE, ex);
                        }
                        jarFileDirs = new JList();
                        jScrollPane1.setViewportView(jarFileDirs);
                        jarFileDirs.setModel(jList1Model);
                        jarFileDirs.setPreferredSize(new java.awt.Dimension(406, 221));
                        jarFileDirs.addMouseListener(new MouseAdapter() {
                            public void mouseClicked(MouseEvent evt) {
                                if (!JListUtil.newInstance(jarFileDirs).isCorrectMouseClick(evt)) {
                                    return;
                                }
                                File file = (File) JListUtil.getLeadSelectionObject(jarFileDirs);
                                try {
                                    Desktop.getDesktop().open(file);
                                } catch (IOException e) {
                                    JCommonUtil.handleException(e);
                                }
                            }
                        });
                        jarFileDirs.addKeyListener(new KeyAdapter() {
                            public void keyPressed(KeyEvent evt) {
                                JListUtil.newInstance(jarFileDirs).defaultJListKeyPressed(evt);
                            }
                        });
                    }
                }
            }
            {
                jPanel2 = new JPanel();
                BorderLayout jPanel2Layout = new BorderLayout();
                jPanel2.setLayout(jPanel2Layout);
                jTabbedPane1.addTab("result", null, jPanel2, null);
                {
                    jPanel3 = new JPanel();
                    BorderLayout jPanel3Layout = new BorderLayout();
                    jPanel3.setLayout(jPanel3Layout);
                    jPanel2.add(jPanel3, BorderLayout.NORTH);
                    jPanel3.setPreferredSize(new java.awt.Dimension(406, 26));
                    {
                        searchText = new JTextField();
                        jPanel3.add(searchText, BorderLayout.WEST);
                        searchText.setPreferredSize(new java.awt.Dimension(326, 26));
                    }
                    {
                        search = new JButton();
                        jPanel3.add(search, BorderLayout.CENTER);
                        search.setText("search");
                        search.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent evt) {
                                jButton2ActionPerformed(evt);
                            }
                        });
                    }
                }
                {
                    jScrollPane2 = new JScrollPane();
                    jPanel2.add(jScrollPane2, BorderLayout.CENTER);
                    jScrollPane2.setPreferredSize(new java.awt.Dimension(406, 231));
                    {
                        ListModel searchResultModel = new DefaultListModel();
                        searchResult = new JList();
                        jScrollPane2.setViewportView(searchResult);
                        searchResult.setModel(searchResultModel);
                        searchResult.addMouseListener(new MouseAdapter() {
                            public void mouseClicked(MouseEvent evt) {
                                jList1MouseClicked(evt);
                            }
                        });
                        searchResult.addKeyListener(new KeyAdapter() {
                            public void keyPressed(KeyEvent evt) {
                                JListUtil.newInstance(searchResult).defaultJListKeyPressed(evt);
                            }
                        });
                    }
                }
                {
                    resetFinder = new JButton();
                    jPanel2.add(resetFinder, BorderLayout.SOUTH);
                    resetFinder.setText("reset finder");
                    resetFinder.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            jarfinder.clear();
                        }
                    });
                }
            }
            {
                jPanel4 = new JPanel();
                BorderLayout jPanel4Layout = new BorderLayout();
                jPanel4.setLayout(jPanel4Layout);
                jTabbedPane1.addTab("copy to", null, jPanel4, null);
                {
                    copyToBtn = new JButton();
                    jPanel4.add(copyToBtn, BorderLayout.NORTH);
                    copyToBtn.setText("copy to");
                    copyToBtn.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            File file = JFileChooserUtil.newInstance().selectDirectoryOnly().showOpenDialog()
                                    .getApproveSelectedFile();
                            if (file == null) {
                                JOptionPaneUtil.newInstance().iconErrorMessage()
                                        .showMessageDialog("copy to dir undefined!", getTitle());
                                return;
                            } else {
                                copyToFile = file;
                            }
                        }
                    });
                }
                {
                    jScrollPane3 = new JScrollPane();
                    jPanel4.add(jScrollPane3, BorderLayout.CENTER);
                    {
                        DefaultListModel copyToListModel = new DefaultListModel();
                        copyToList = new JList();
                        jScrollPane3.setViewportView(copyToList);
                        copyToList.setModel(copyToListModel);
                        {
                            panel = new JPanel();
                            jTabbedPane1.addTab("config", null, panel, null);
                            panel.setLayout(new FormLayout(
                                    new ColumnSpec[] { FormFactory.RELATED_GAP_COLSPEC,
                                            FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC,
                                            ColumnSpec.decode("default:grow"), },
                                    new RowSpec[] { FormFactory.RELATED_GAP_ROWSPEC,
                                            FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
                                            FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
                                            FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
                                            FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
                                            FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
                                            FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
                                            FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
                                            FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
                                            FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
                                            FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
                                            FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
                                            FormFactory.DEFAULT_ROWSPEC, }));
                            {
                                lblNewLabel = new JLabel("JD Gui");
                                panel.add(lblNewLabel, "2, 2, right, default");
                            }
                            {
                                jdGuiText = new JTextField();
                                JCommonUtil.jTextFieldSetFilePathMouseEvent(jdGuiText, false);
                                panel.add(jdGuiText, "4, 2, fill, default");
                                jdGuiText.setColumns(10);
                            }
                            {
                                saveConfigBtn = new JButton("");
                                saveConfigBtn.addActionListener(new ActionListener() {
                                    public void actionPerformed(ActionEvent e) {
                                        try {
                                            configBean.reflectSetConfig(JarFinderUI.this);
                                            configBean.store();
                                            JCommonUtil._jOptionPane_showMessageDialog_info("?!");
                                        } catch (Exception ex) {
                                            JCommonUtil.handleException(ex);
                                        }
                                    }
                                });
                                panel.add(saveConfigBtn, "2, 24");
                            }
                        }
                        copyToList.addMouseListener(new MouseAdapter() {
                            public void mouseClicked(MouseEvent evt) {
                                // copyToFile
                                if (evt.getClickCount() != 2) {
                                    return;
                                }
                                if (copyToList.getLeadSelectionIndex() == -1) {
                                    return;
                                }
                                if (copyToFile == null) {
                                    JOptionPaneUtil.newInstance().iconErrorMessage()
                                            .showMessageDialog("copy to dir undefined!", getTitle());
                                    return;
                                }
                                DefaultListModel model = (DefaultListModel) copyToList.getModel();
                                Object val = model.getElementAt(copyToList.getLeadSelectionIndex());
                                StringBuilder sb = new StringBuilder();
                                sb.append("?\n");
                                sb.append("file : " + val + "\n");
                                sb.append("copy to dir : " + copyToFile + "\n");
                                ComfirmDialogResult result = JOptionPaneUtil.newInstance().confirmButtonYesNo()
                                        .showConfirmDialog(sb, getTitle());
                                File srcFile = new File((String) val);
                                if (!srcFile.exists()) {
                                    JOptionPaneUtil.newInstance().iconErrorMessage()
                                            .showMessageDialog(srcFile + "  not found!", getTitle());
                                    return;
                                }
                                File copyDestFile = new File(copyToFile, srcFile.getName());
                                switch (result) {
                                case YES_OK_OPTION:
                                    System.out.println("yes..");
                                    try {
                                        FileUtil.copyFile(srcFile, copyDestFile);
                                    } catch (IOException e) {
                                        JCommonUtil.handleException(e.toString(), e);
                                    }
                                    if (srcFile != null && //
                                    copyDestFile != null && //
                                    srcFile.length() == copyDestFile.length()) {
                                        JOptionPaneUtil.newInstance().iconInformationMessage()
                                                .showMessageDialog("success!\n" + copyDestFile, getTitle());
                                    } else {
                                        JOptionPaneUtil.newInstance().iconErrorMessage()
                                                .showMessageDialog("failed!\n" + copyDestFile, getTitle());
                                    }
                                    break;
                                case NO_OPTION:
                                    System.out.println("no..");
                                    break;
                                }
                            }
                        });
                    }
                }
            }

            jTabbedPane1.addChangeListener(new ChangeListener() {
                public void stateChanged(ChangeEvent evt) {
                    copyToList.setModel(searchResult.getModel());
                }
            });
        }
        this.setSize(562, 407);

        JCommonUtil.frameCloseDo(this, new WindowAdapter() {
            public void windowClosing(WindowEvent paramWindowEvent) {
                if (CONFIG_FILE.exists()) {
                    DefaultListModel model = (DefaultListModel) jarFileDirs.getModel();
                    for (Enumeration<?> enu = model.elements(); enu.hasMoreElements();) {
                        Object obj = enu.nextElement();
                        prop.setProperty(((File) obj).getAbsolutePath(), "");
                    }
                    try {
                        prop.store(new FileOutputStream(CONFIG_FILE), "testtesttesttest");
                    } catch (Exception e) {
                        JCommonUtil.handleException("", e);
                    }
                }
                setVisible(false);
                dispose();
            }
        });

        {
            configBean.reflectInit(this);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:ui.HelpUI.java

    private void loadPDF()  {
        Desktop ccc=Desktop.getDesktop();
//        SwingController controller = new SwingController(); 
//        SwingViewBuilder factory = new SwingViewBuilder(controller); 
//        jPanel1 = factory.buildViewerPanel(); 
           InputStream is=this.getClass().getResourceAsStream("/report/generateInvoice_1001.pdf");
//        controller.openDocument(is,"Help Document",null);
        //www.  j av a2  s .c  om
        try {
            File file=stream2file(is);
            ccc.open(file);//(new File("/report/generateInvoice_1001.pdf"));
            //add(jPanel1);
        } catch (IOException ex) {
            Logger.getLogger(HelpUI.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

From source file:org.pgptool.gui.ui.feedbackForm.FeedbackFormPm.java

private void redirectUserToBrowser() {
    try {/*from www .  j  a  v  a2  s  .  co  m*/
        Desktop.getDesktop().browse(new URI(formUrlForBrowser));
    } catch (Throwable t) {
        EntryPoint.reportExceptionToUser("exception.unexpected", t);
    }
}

From source file:display.containers.FileManager.java

public Container getPane() {
    //if (gui==null) {

    fileSystemView = FileSystemView.getFileSystemView();
    desktop = Desktop.getDesktop();

    JPanel detailView = new JPanel(new BorderLayout(3, 3));
    //fileTableModel = new FileTableModel();

    table = new JTable();
    table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    table.setAutoCreateRowSorter(true);/*from   ww w .  ja  va 2 s .  c o  m*/
    table.setShowVerticalLines(false);
    table.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            if (e.getClickCount() >= 2) {
                Point p = e.getPoint();
                int row = table.convertRowIndexToModel(table.rowAtPoint(p));
                int column = table.convertColumnIndexToModel(table.columnAtPoint(p));
                if (row >= 0 && column >= 0) {
                    mouseDblClicked(row, column);
                }
            }
        }
    });
    table.addKeyListener(new KeyListener() {

        @Override
        public void keyTyped(KeyEvent arg0) {

        }

        @Override
        public void keyReleased(KeyEvent arg0) {
            if (KeyEvent.VK_DELETE == arg0.getKeyCode()) {
                if (mode != 2) {
                    parentFrame.setLock(true);
                    parentFrame.getProgressBarPanel().setVisible(true);
                    Thread t = new Thread(new Runnable() {

                        @Override
                        public void run() {
                            try {
                                deleteSelectedFiles();
                            } catch (IOException e) {
                                JOptionPane.showMessageDialog(parentFrame, "Error during the deletion.",
                                        "Deletion error", JOptionPane.ERROR_MESSAGE);
                                WindowManager.mwLogger.log(Level.SEVERE, "Error during the deletion.", e);
                            } finally {
                                parentFrame.setLock(false);
                                refresh();
                                parentFrame.getProgressBarPanel().setVisible(false);
                            }
                        }
                    });
                    t.start();

                } else {
                    if (UserProfile.CURRENT_USER.getLevel() == 3) {
                        parentFrame.setLock(true);
                        parentFrame.getProgressBarPanel().setVisible(true);
                        Thread delThread = new Thread(new Runnable() {

                            @Override
                            public void run() {
                                int[] rows = table.getSelectedRows();
                                int[] columns = table.getSelectedColumns();
                                for (int i = 0; i < rows.length; i++) {
                                    if (!continueAction) {
                                        continueAction = true;
                                        return;
                                    }
                                    int row = table.convertRowIndexToModel(rows[i]);
                                    try {
                                        deleteServerFile(row);
                                    } catch (Exception e) {
                                        WindowManager.mwLogger.log(Level.SEVERE, "Error during the deletion.",
                                                e);
                                    }
                                }
                                refresh();
                                parentFrame.setLock(false);
                                parentFrame.getProgressBarPanel().setVisible(false);
                            }
                        });
                        delThread.start();

                    }
                }
            }
        }

        @Override
        public void keyPressed(KeyEvent arg0) {
            // TODO Auto-generated method stub

        }
    });
    table.getSelectionModel().addListSelectionListener(listSelectionListener);
    JScrollPane tableScroll = new JScrollPane(table);
    Dimension d = tableScroll.getPreferredSize();
    tableScroll.setPreferredSize(new Dimension((int) d.getWidth(), (int) d.getHeight() / 2));
    detailView.add(tableScroll, BorderLayout.CENTER);

    // the File tree
    DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    treeModel = new DefaultTreeModel(root);
    table.getRowSorter().addRowSorterListener(new RowSorterListener() {

        @Override
        public void sorterChanged(RowSorterEvent e) {
            ((FileTableModel) table.getModel()).fireTableDataChanged();
        }
    });

    // show the file system roots.
    File[] roots = fileSystemView.getRoots();
    for (File fileSystemRoot : roots) {
        DefaultMutableTreeNode node = new DefaultMutableTreeNode(fileSystemRoot);
        root.add(node);
        //showChildren(node);
        //
        File[] files = fileSystemView.getFiles(fileSystemRoot, true);
        for (File file : files) {
            if (file.isDirectory()) {
                node.add(new DefaultMutableTreeNode(file));
            }
        }
        //
    }
    JScrollPane treeScroll = new JScrollPane();

    Dimension preferredSize = treeScroll.getPreferredSize();
    Dimension widePreferred = new Dimension(200, (int) preferredSize.getHeight());
    treeScroll.setPreferredSize(widePreferred);

    JPanel fileView = new JPanel(new BorderLayout(3, 3));

    detailView.add(fileView, BorderLayout.SOUTH);

    JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, treeScroll, detailView);

    JPanel simpleOutput = new JPanel(new BorderLayout(3, 3));
    progressBar = new JProgressBar();
    simpleOutput.add(progressBar, BorderLayout.EAST);
    progressBar.setVisible(false);
    showChildren(getCurrentDir().toPath());
    //table.setDragEnabled(true);
    table.setColumnSelectionAllowed(false);

    // Menu popup
    Pmenu = new JPopupMenu();
    changeProjectitem = new JMenuItem("Reassign");
    renameProjectitem = new JMenuItem("Rename");
    twitem = new JMenuItem("To workspace");
    tlitem = new JMenuItem("To local");
    processitem = new JMenuItem("Select for process");
    switch (mode) {
    case 0:
        Pmenu.add(twitem);
        twitem.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                parentFrame.getBtnlocalTowork().doClick();
            }
        });
        break;
    case 1:
        Pmenu.add(tlitem);
        Pmenu.add(processitem);
        tlitem.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                parentFrame.getBtnWorkTolocal().doClick();
            }
        });
        processitem.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent arg0) {
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        // Recupere les lignes selectionnees
                        int[] indices = table.getSelectedRows();
                        // On recupere les fichiers correspondants
                        ArrayList<File> files = new ArrayList<File>();
                        for (int i = 0; i < indices.length; i++) {
                            int row = table.convertRowIndexToModel(indices[i]);
                            File fi = ((FileTableModel) table.getModel()).getFile(row);
                            if (fi.isDirectory())
                                files.add(fi);
                        }
                        ImageProcessingFrame imf = new ImageProcessingFrame(files);
                    }
                });

            }
        });
        break;
    case 2:
        if (UserProfile.CURRENT_USER.getLevel() == 3) {
            Pmenu.add(changeProjectitem);
            Pmenu.add(renameProjectitem);
        }
        Pmenu.add(twitem);
        twitem.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                parentFrame.getBtndistToWorkspace().doClick();
            }
        });
        Pmenu.add(tlitem);
        tlitem.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                parentFrame.getBtndistToLocal().doClick();
            }
        });
        break;
    }
    changeProjectitem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            table.setEnabled(false);
            File from = ((FileTableModel) table.getModel())
                    .getFile(table.convertRowIndexToModel(table.getSelectedRows()[0]));

            ReassignProjectPanel reas = new ReassignProjectPanel(from.toPath()); // mode creation de liens
            Popup popup = PopupFactory.getSharedInstance().getPopup(WindowManager.MAINWINDOW, reas,
                    (int) WindowManager.MAINWINDOW.getX() + 200, (int) WindowManager.MAINWINDOW.getY() + 150);
            reas.setPopupWindow(popup);
            popup.show();
            table.setEnabled(true);
        }
    });
    renameProjectitem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            table.setEnabled(false);
            final File from = ((FileTableModel) table.getModel())
                    .getFile(table.convertRowIndexToModel(table.getSelectedRows()[0]));
            JDialog.setDefaultLookAndFeelDecorated(true);
            String s = (String) JOptionPane.showInputDialog(WindowManager.MAINWINDOW, "New project name ?",
                    "Rename project", JOptionPane.PLAIN_MESSAGE, null, null, from.getName());

            //If a string was returned, say so.
            if ((s != null) && (s.length() > 0)) {
                ProjectDAO pdao = new MySQLProjectDAO();
                if (new File(from.getParent() + File.separator + s).exists()) {
                    SwingUtilities.invokeLater(new Runnable() {

                        @Override
                        public void run() {
                            JDialog.setDefaultLookAndFeelDecorated(true);
                            JOptionPane.showMessageDialog(WindowManager.MAINWINDOW,
                                    "Couldn't rename " + from.getName()
                                            + " (A file with this filename already exists)",
                                    "Renaming error", JOptionPane.ERROR_MESSAGE);
                        }
                    });
                    WindowManager.mwLogger.log(Level.SEVERE,
                            "Error during file project renaming (" + from.getName() + "). [Duplication error]");
                } else {
                    try {
                        boolean succeed = pdao.renameProject(from.getName(), s);
                        if (!succeed) {
                            SwingUtilities.invokeLater(new Runnable() {

                                @Override
                                public void run() {
                                    JDialog.setDefaultLookAndFeelDecorated(true);
                                    JOptionPane.showMessageDialog(WindowManager.MAINWINDOW,
                                            "Couldn't rename " + from.getName()
                                                    + " (no project with this name)",
                                            "Renaming error", JOptionPane.ERROR_MESSAGE);
                                }
                            });
                        } else {
                            from.renameTo(new File(from.getParent() + File.separator + s));
                            // on renomme le repertoire nifti ou dicom correspondant si il existe
                            switch (from.getParentFile().getName()) {
                            case ServerInfo.NRI_ANALYSE_NAME:
                                if (new File(from.getAbsolutePath().replaceAll(ServerInfo.NRI_ANALYSE_NAME,
                                        ServerInfo.NRI_DICOM_NAME)).exists())
                                    try {
                                        Files.move(Paths.get(from.getAbsolutePath().replaceAll(
                                                ServerInfo.NRI_ANALYSE_NAME, ServerInfo.NRI_DICOM_NAME)),
                                                Paths.get(from.getParent().replaceAll(
                                                        ServerInfo.NRI_ANALYSE_NAME, ServerInfo.NRI_DICOM_NAME)
                                                        + File.separator + s));
                                    } catch (IOException e) {
                                        e.printStackTrace();
                                        SwingUtilities.invokeLater(new Runnable() {

                                            @Override
                                            public void run() {
                                                JDialog.setDefaultLookAndFeelDecorated(true);
                                                JOptionPane.showMessageDialog(WindowManager.MAINWINDOW,
                                                        "Couldn't rename " + from.getName()
                                                                + " (error with file system)",
                                                        "Renaming error", JOptionPane.ERROR_MESSAGE);
                                            }
                                        });
                                        WindowManager.mwLogger.log(Level.SEVERE,
                                                "Error during file project renaming (" + from.getName() + ")",
                                                e);
                                    } //from.renameTo(new File(from.getParent().replaceAll(ServerInfo.NRI_ANALYSE_NAME, ServerInfo.NRI_DICOM_NAME)+File.separator+s));
                                break;
                            case ServerInfo.NRI_DICOM_NAME:
                                if (new File(from.getAbsolutePath().replaceAll(ServerInfo.NRI_DICOM_NAME,
                                        ServerInfo.NRI_ANALYSE_NAME)).exists())
                                    try {
                                        Files.move(Paths.get(from.getAbsolutePath().replaceAll(
                                                ServerInfo.NRI_DICOM_NAME, ServerInfo.NRI_ANALYSE_NAME)),
                                                Paths.get(from.getParent().replaceAll(ServerInfo.NRI_DICOM_NAME,
                                                        ServerInfo.NRI_ANALYSE_NAME) + File.separator + s));
                                    } catch (IOException e) {
                                        SwingUtilities.invokeLater(new Runnable() {

                                            @Override
                                            public void run() {
                                                JDialog.setDefaultLookAndFeelDecorated(true);
                                                JOptionPane.showMessageDialog(WindowManager.MAINWINDOW,
                                                        "Couldn't rename " + from.getName()
                                                                + " (error with file system)",
                                                        "Renaming error", JOptionPane.ERROR_MESSAGE);
                                            }
                                        });
                                        e.printStackTrace();
                                        WindowManager.mwLogger.log(Level.SEVERE,
                                                "Error during file project renaming (" + from.getName() + ")",
                                                e);
                                    } //from.renameTo(new File(from.getParent().replaceAll(ServerInfo.NRI_DICOM_NAME, ServerInfo.NRI_ANALYSE_NAME)+File.separator+s));
                                break;
                            }
                            refresh();
                        }
                    } catch (final SQLException e) {
                        WindowManager.mwLogger.log(Level.SEVERE, "Error during SQL project renaming", e);
                        SwingUtilities.invokeLater(new Runnable() {

                            @Override
                            public void run() {
                                JDialog.setDefaultLookAndFeelDecorated(true);
                                JOptionPane.showMessageDialog(WindowManager.MAINWINDOW,
                                        "Exception : " + e.toString(), "Openning error",
                                        JOptionPane.ERROR_MESSAGE);
                            }
                        });
                    }
                }
            }
            table.setEnabled(true);
        }
    });
    table.addMouseListener(new MouseListener() {

        public void mouseClicked(MouseEvent me) {

        }

        public void mouseEntered(MouseEvent e) {
        }

        public void mouseExited(MouseEvent e) {
        }

        public void mousePressed(MouseEvent e) {
        }

        public void mouseReleased(MouseEvent me) {
            if (me.getButton() == 3 && table.getSelectedRowCount() > 0) {
                int row = table.convertRowIndexToModel(table.rowAtPoint(me.getPoint()));
                changeProjectitem.setVisible(isPatient(((FileTableModel) table.getModel()).getFile(row)));
                renameProjectitem.setVisible(isProject(((FileTableModel) table.getModel()).getFile(row)));
                Pmenu.show(me.getComponent(), me.getX(), me.getY());
            }
        }
    });
    //

    //}
    return tableScroll;
}

From source file:pah9qdmoviereviews.MovieReviewsFXMLController.java

public void ready(Stage stage, Scene scene) {
    this.stage = stage;
    this.scene = scene;

    movieReviewManager = new NYTMoviewReviewManager();
    movieReviewManager.addPropertyChangeSupport(((evt) -> {
        switch (evt.getPropertyName()) {
        case "Exception":
            Platform.runLater(() -> displayExceptionAlert((Exception) evt.getNewValue()));
            break;
        case "Add Movie Review":
            Platform.runLater(() -> {
                movieReviews.add((NYTMovieReview) evt.getNewValue());
                this.foundText.setText(("Found " + movieReviews.size() + " results for " + searchString + "."));
            });/*from   w  w  w.j a  v a2 s  .c  o  m*/
            break;
        case "Clear Movie Reviews":
            Platform.runLater(() -> movieReviews.clear());
            break;
        case "Completed":
            if (movieReviews.isEmpty())
                this.foundText.setText("No reviews found for " + searchString);
            break;
        default:
            Platform.runLater(
                    () -> displayExceptionAlert(new Exception("Invalid Property Change Support Property")));
            break;
        }

    }));

    movieReviews = FXCollections.observableArrayList();
    listView.setItems(movieReviews);
    listView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<NYTMovieReview>() {
        @Override
        public void changed(ObservableValue<? extends NYTMovieReview> observable, NYTMovieReview oldValue,
                NYTMovieReview newValue) {
            detailsBox.getChildren().clear();
            movieImage.setImage(null);
            if (newValue != null) {
                DateFormat dateFormat = new SimpleDateFormat("MMMM d, yyyy", Locale.ENGLISH);
                String pictureLink = newValue.getPictureLink();
                if (pictureLink != null && !pictureLink.isEmpty()) {
                    reviewBox.getChildren().remove(0);
                    reviewBox.getChildren().add(0, movieImage);
                    movieImage.setImage(new Image(pictureLink));
                } else {
                    reviewBox.getChildren().remove(0);
                    reviewBox.getChildren().add(0, missingImageText);
                    movieImage.setImage(null);
                }

                ArrayList<Label> labelArray = new ArrayList<>();
                if (!newValue.getDisplayTitle().isEmpty()) {
                    Label titleLabel = new Label(newValue.getDisplayTitle());
                    titleLabel.fontProperty().set(Font.font(20));
                    labelArray.add(titleLabel);
                }
                if (!newValue.getSummary().isEmpty()) {
                    labelArray.add(new Label("Summary: " + newValue.getSummary()));
                }
                if (!newValue.getMpaaRating().isEmpty()) {
                    labelArray.add(new Label("MPAA Rating: " + newValue.getMpaaRating()));
                }
                if (newValue.getPublicationDate() != null) {
                    labelArray.add(
                            new Label("Publication Date: " + dateFormat.format(newValue.getPublicationDate())));
                }
                if (newValue.getOpeningDate() != null) {
                    labelArray.add(new Label("Opening Date: " + dateFormat.format(newValue.getOpeningDate())));
                }

                labelArray.forEach((label) -> {
                    label.wrapTextProperty().set(true);
                });

                detailsBox.getChildren().addAll(labelArray);

                Button openButton = new Button("Open Review");
                openButton.setOnAction((event) -> {
                    try {
                        Desktop.getDesktop().browse(new URI(newValue.getArticleLink()));
                    } catch (Exception ex) {
                        displayExceptionAlert(ex);
                    }
                });

                detailsBox.getChildren().add(openButton);
            }
        }
    });

    HBox.setMargin(missingImageText, new Insets(15, 15, 15, 15));
    searchTextField.setOnKeyPressed((event) -> {
        if (event.getCode() == KeyCode.ENTER) {
            loadReviews(searchTextField.getText());
        }
    });
    //        searchTextField.textProperty().addListener((observable, oldValue, newValue) -> {
    //            if(newValue != null && !newValue.isEmpty())
    //                loadReviews(newValue);
    //        });
}

From source file:au.org.ala.delta.intkey.ui.WebSearchDialog.java

@Action
public void WebSearchDialog_search() {
    String term = txtSearch.getText().trim();
    if (!org.apache.commons.lang.StringUtils.isEmpty(term)) {
        SearchEngineDescriptor selected = (SearchEngineDescriptor) cmbSearchEngine.getSelectedItem();
        if (selected != null) {
            if (Desktop.isDesktopSupported()) {
                URI uri = URI.create(selected.getUrl(term));
                try {
                    Desktop.getDesktop().browse(uri);
                } catch (IOException e) {
                    e.printStackTrace();
                }// w ww .j a  v  a 2  s. c  o m
            }
        }
    }
}

From source file:com.limegroup.gnutella.util.Launcher.java

/**
 * Launches the Explorer/Finder and highlights the file.
 * /*w  ww. jav  a 2s.  c  o m*/
 * @param file the file to show in explorer
 * @return null, if not supported by platform; the launched process otherwise
 * @see #launchFile(File)
 */
public static void launchExplorer(File file) throws IOException, SecurityException {
    if (OSUtils.isWindows()) {
        String explorePath = file.getPath();
        try {
            explorePath = file.getCanonicalPath();
        } catch (IOException ignored) {
        }

        if (file.isDirectory()) {
            // launches explorer in the directory
            LimeProcess.exec(new String[] { "explorer", explorePath });
        } else {
            // launches explorer and highlights the file
            LimeProcess.exec(new String[] { "explorer", "/select,", explorePath });
        }

    } else if (OSUtils.isMacOSX()) {
        // launches the Finder and highlights the file
        LimeProcess.exec(selectFileCommand(file));
    } else if (OSUtils.isLinux()) {
        if (file.isDirectory()) {
            Desktop.getDesktop().open(file);
        } else if (file.isFile()) {
            Desktop.getDesktop().open(file.getParentFile());
        }
    }
}

From source file:org.sonarlint.intellij.ui.SonarLintRulePanel.java

private JEditorPane createEditor() {
    JEditorPane newEditor = new JEditorPane();
    newEditor.setEditorKit(kit);/*from  ww w.  ja v  a 2s.c o  m*/
    newEditor.setBorder(new EmptyBorder(10, 10, 10, 10));
    newEditor.setEditable(false);
    newEditor.setContentType("text/html");
    newEditor.addHyperlinkListener(e -> {
        if (HyperlinkEvent.EventType.ACTIVATED.equals(e.getEventType())) {
            Desktop desktop = Desktop.getDesktop();
            try {
                desktop.browse(e.getURL().toURI());
            } catch (Exception ex) {
                SonarLintConsole.get(project).error("Error opening browser: " + e.getURL(), ex);
            }
        }
    });

    return newEditor;
}

From source file:osu.beatmapdownloader.JFrame.java

public void dificultHelp() {
       String text = "More Info";
       L_difHelp.setText("<html><a href=\"\">" + text + "</a></html>");
       L_difHelp.setCursor(new Cursor(Cursor.HAND_CURSOR));
       L_difHelp.addMouseListener(new MouseAdapter() {
           @Override/*  www  .jav a2s .  c o m*/
           public void mouseClicked(MouseEvent e) {
               try {
                   Desktop.getDesktop().browse(new URI("https://osu.ppy.sh/forum/t/178700&start=0"));
               } catch (URISyntaxException | IOException ex) {
               }
           }
       });
   }

From source file:kihira.tails.client.gui.GuiExport.java

@Override
protected void actionPerformed(GuiButton button) {
    //Export to file
    if (button.id == 0 || button.id == 1 || button.id == 2) {
        AbstractClientPlayer player = this.mc.thePlayer;
        File file;/*from   ww w  .  j ava 2 s . c om*/

        this.exportMessage = "";
        this.exportLoc = null;
        if (button.id == 0)
            file = new File(System.getProperty("user.home"));
        else if (button.id == 1)
            file = new File(System.getProperty("user.dir"));
        else {
            JFileChooser fileChooser = new JFileChooser(new File(System.getProperty("user.dir")));
            fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            if (fileChooser.showSaveDialog(Display.getParent()) == JFileChooser.APPROVE_OPTION) {
                file = fileChooser.getSelectedFile();
            } else
                return;
        }

        if (file.exists() && file.canWrite()) {
            this.exportLoc = file.toURI();
            file = new File(file, File.separatorChar + player.getCommandSenderName() + ".png");

            if (!file.exists()) {
                try {
                    file.createNewFile();
                } catch (IOException e) {
                    setExportMessage(
                            EnumChatFormatting.DARK_RED + String.format("Failed to create skin file! %s", e));
                    e.printStackTrace();
                }
            }

            BufferedImage image = TextureHelper.writePartsDataToSkin(this.partsData, player);
            if (image != null) {
                try {
                    ImageIO.write(image, "png", file);
                } catch (IOException e) {
                    setExportMessage(
                            EnumChatFormatting.DARK_RED + String.format("Failed to save skin file! %s", e));
                    e.printStackTrace();
                }
            } else {
                setExportMessage(
                        EnumChatFormatting.DARK_RED + String.format("Failed to export skin, image was null!"));
                file.delete();
            }
        }

        if (Strings.isNullOrEmpty(this.exportMessage)) {
            savePartsData();
            this.openFolderButton.visible = true;
            setExportMessage(EnumChatFormatting.GREEN + I18n.format("tails.export.success", file));
        }
    }
    if (button.id == 3 && this.exportLoc != null) {
        try {
            Desktop.getDesktop().browse(this.exportLoc);
        } catch (IOException e) {
            setExportMessage(
                    EnumChatFormatting.DARK_RED + String.format("Failed to open export location: %s", e));
            e.printStackTrace();
        }
    }

    //Upload
    if (button.id == 10) {
        final BufferedImage image = TextureHelper.writePartsDataToSkin(this.partsData, this.mc.thePlayer);
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                exportMessage = I18n.format("tails.uploading");
                new ImgurUpload().uploadImage(image);
            }
        };
        runnable.run();
    }
}