Example usage for java.awt Desktop isDesktopSupported

List of usage examples for java.awt Desktop isDesktopSupported

Introduction

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

Prototype

public static boolean isDesktopSupported() 

Source Link

Document

Tests whether this class is supported on the current platform.

Usage

From source file:org.keycloak.adapters.installed.KeycloakInstalled.java

public boolean isDesktopSupported() {
    return Desktop.isDesktopSupported();
}

From source file:com.hmiard.blackwater.projects.Builder.java

/**
 * Asking the OS to open a directory or a file.
 *
 * @param path String// w w  w  .j a  v a  2  s  . co m
 * @throws IOException
 */
public static void openPath(String path) throws IOException {

    if (Desktop.isDesktopSupported()) {
        Desktop.getDesktop().open(new File(path));
    }
}

From source file:com.xmage.launcher.XMageLauncher.java

private static void openWebpage(String uri) {
    Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
    if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
        try {// w ww . ja  v  a 2s  . c o m
            desktop.browse(new URI(uri));
        } catch (URISyntaxException ex) {
            logger.error("Error: ", ex);
        } catch (IOException ex) {
            logger.error("Error: ", ex);
        }
    }
}

From source file:com.diversityarrays.update.UpdateDialog.java

private void openWebpage(URI uri) {
    Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
    if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
        try {//w  w w .ja  v  a 2  s .c o  m
            desktop.browse(uri);
        } catch (IOException e) {
            JOptionPane.showMessageDialog(new JFrame(), e.getMessage(),
                    Msg.ERRTITLE_BROWSER_OPEN_ERROR(getTitle()), JOptionPane.ERROR_MESSAGE);
            e.printStackTrace();
        }

    }
}

From source file:org.exist.launcher.Launcher.java

private PopupMenu createMenu() {

    final PopupMenu popup = new PopupMenu();
    startItem = new MenuItem("Start server");
    popup.add(startItem);//  w w  w . ja v  a 2  s. co m
    startItem.addActionListener(actionEvent -> {
        if (jetty.isPresent()) {
            jetty.ifPresent(server -> {
                if (server.isStarted()) {
                    showTrayMessage("Server already started", TrayIcon.MessageType.WARNING);
                } else {
                    server.run(new String[] { jettyConfig.toAbsolutePath().toString() }, null);
                    if (server.isStarted()) {
                        showTrayMessage("eXist-db server running on port " + server.getPrimaryPort(),
                                TrayIcon.MessageType.INFO);
                    }
                }
                setServiceState();
            });
        } else if (runningAsService.isPresent()) {
            showTrayMessage("Starting the eXistdb service. Please wait...", TrayIcon.MessageType.INFO);
            if (runningAsService.get().start()) {
                showTrayMessage("eXistdb service started", TrayIcon.MessageType.INFO);
            } else {
                showTrayMessage("Starting eXistdb service failed", TrayIcon.MessageType.ERROR);
            }
            setServiceState();
        }
    });

    stopItem = new MenuItem("Stop server");
    popup.add(stopItem);
    stopItem.addActionListener(actionEvent -> {
        if (jetty.isPresent()) {
            jetty.get().shutdown();
            setServiceState();
            showTrayMessage("eXist-db stopped", TrayIcon.MessageType.INFO);
        } else if (runningAsService.isPresent()) {
            if (runningAsService.get().stop()) {
                showTrayMessage("eXistdb service stopped", TrayIcon.MessageType.INFO);
            } else {
                showTrayMessage("Stopping eXistdb service failed", TrayIcon.MessageType.ERROR);
            }
            setServiceState();
        }
    });

    popup.addSeparator();
    final MenuItem configItem = new MenuItem("System Configuration");
    popup.add(configItem);
    configItem.addActionListener(e -> EventQueue.invokeLater(() -> {
        configDialog.open(false);
        configDialog.toFront();
        configDialog.repaint();
        configDialog.requestFocus();
    }));

    if (SystemUtils.IS_OS_WINDOWS) {
        canUseServices = true;
    } else {
        isRoot((root) -> canUseServices = root);
    }

    final String requiresRootMsg;
    if (canUseServices) {
        requiresRootMsg = "";
    } else {
        requiresRootMsg = " (requires root)";
    }

    installServiceItem = new MenuItem("Install as service" + requiresRootMsg);

    popup.add(installServiceItem);
    installServiceItem.setEnabled(canUseServices);
    installServiceItem.addActionListener(e -> SwingUtilities.invokeLater(this::installAsService));

    uninstallServiceItem = new MenuItem("Uninstall service" + requiresRootMsg);
    popup.add(uninstallServiceItem);
    uninstallServiceItem.setEnabled(canUseServices);
    uninstallServiceItem.addActionListener(e -> SwingUtilities.invokeLater(this::uninstallService));

    if (SystemUtils.IS_OS_WINDOWS) {
        showServices = new MenuItem("Show services console");
        popup.add(showServices);
        showServices.addActionListener(e -> SwingUtilities.invokeLater(this::showServicesConsole));
    }
    popup.addSeparator();

    final MenuItem toolbar = new MenuItem("Show tool window");
    popup.add(toolbar);
    toolbar.addActionListener(actionEvent -> EventQueue.invokeLater(() -> {
        utilityPanel.toFront();
        utilityPanel.setVisible(true);
    }));

    MenuItem item;

    if (Desktop.isDesktopSupported()) {
        popup.addSeparator();
        final Desktop desktop = Desktop.getDesktop();
        if (desktop.isSupported(Desktop.Action.BROWSE)) {
            dashboardItem = new MenuItem("Open Dashboard");
            popup.add(dashboardItem);
            dashboardItem.addActionListener(actionEvent -> dashboard(desktop));
            eXideItem = new MenuItem("Open eXide");
            popup.add(eXideItem);
            eXideItem.addActionListener(actionEvent -> eXide(desktop));
            item = new MenuItem("Open Java Admin Client");
            popup.add(item);
            item.addActionListener(actionEvent -> client());
            monexItem = new MenuItem("Open Monitoring and Profiling");
            popup.add(monexItem);
            monexItem.addActionListener(actionEvent -> monex(desktop));
        }
        if (desktop.isSupported(Desktop.Action.OPEN)) {
            popup.addSeparator();
            item = new MenuItem("Open exist.log");
            popup.add(item);
            item.addActionListener(new LogActionListener());
        }

        popup.addSeparator();
        quitItem = new MenuItem("Quit (and stop server)");
        popup.add(quitItem);
        quitItem.addActionListener(actionEvent -> shutdown(false));

        setServiceState();
    }
    return popup;
}

From source file:com.opendoorlogistics.studio.AppFrame.java

private SimpleAction initGotoWebsiteAction() {
    return new SimpleAction("Go to help website", "Go to www.opendoorlogistics for help", "help 16x16.png",
            "help 32x32.png") {

        @Override/*from www .j av a2s . c om*/
        public void actionPerformed(ActionEvent e) {
            if (Desktop.isDesktopSupported() && Desktop.getDesktop() != null) {
                Desktop desktop = Desktop.getDesktop();
                ExecutionReportImpl report = new ExecutionReportImpl();
                try {
                    desktop.browse(java.net.URI.create("www.opendoorlogistics.com"));
                } catch (Exception e2) {
                    report.setFailed(e2);
                    ExecutionReportDialog.show(AppFrame.this, "Failed to open website", report);
                }

            }
        }
    };
}

From source file:it.iit.genomics.cru.igb.bundles.mi.view.MITable.java

public MITable(MITableModel model, IgbService service, final MIQuery query) {
    super(model);

    this.query = query;
    igbLogger = IGBLogger.getInstance(query.getLabel());
    this.igbService = service;

    this.SymSelectionListener = new MouseListener() {

        @SuppressWarnings("unchecked")
        @Override//from w w w  . j  av  a 2 s. c o m
        public void mouseClicked(MouseEvent e) {

            if (e.getComponent().isEnabled() && e.getButton() == MouseEvent.BUTTON1) {

                if (getSelectedRow() >= 0) {
                    int modelRow = convertRowIndexToModel(getSelectedRow());

                    MIResult interaction = ((MITableModel) getModel()).getResult(modelRow);

                    structuresPanel.setCurrentInteraction(interaction);
                }

                MITable table = (MITable) e.getComponent();
                int modelRow = convertRowIndexToModel(table.getSelectedRow());
                int column = table.getSelectedColumn();

                if (e.getClickCount() == 1) {
                    if (column == MITableModel.TRACK_COLUMN) {
                        Object value = table.getValueAt(table.getSelectedRow(), column);

                        if (value instanceof JButton) {
                            MIResult result = ((MITableModel) table.getModel()).getResult(modelRow);

                            TypeContainerAnnot interactorTrack = result.createTrack();

                            igbService.addTrack(interactorTrack, interactorTrack.getID());

                            igbService.getSeqMapView().updatePanel();

                            for (TierGlyph t : igbService.getAllTierGlyphs()) {

                                if (TierGlyph.TierType.ANNOTATION.equals(t.getTierType())
                                        && (t.getAnnotStyle().getTrackName().equals(interactorTrack.getID()))) {

                                    SimpleTrackStyle style = new SimpleTrackStyle(interactorTrack.getID(),
                                            false) {

                                        @Override
                                        public boolean drawCollapseControl() {
                                            return false;
                                        }
                                    };

                                    t.getAnnotStyle().copyPropertiesFrom(style);
                                    t.getAnnotStyle().setColorProvider(new RGB());
                                    interactorTrack.setProperty(TrackLineParser.ITEM_RGB, "on");
                                }
                            }

                            igbService.getSeqMapView().updatePanel();

                            ((JButton) value).setText(interactorTrack.getID());
                            ((JButton) value).setEnabled(false);

                            updateUI();
                        }
                    }
                } else {
                    // symmetry: zoom-in
                    if (column == MITableModel.SYMS1_COLUMN) {
                        MoleculeEntry entry = ((MITableModel) table.getModel()).getResult(modelRow)
                                .getInteractor1();
                        if (query.getTaxid().equals(entry.getTaxid())) {
                            Collection<SeqSymmetry> syms = ((MITableModel) table.getModel()).getResult(modelRow)
                                    .getSymmetries1();
                            zoomToSym(syms);
                        }
                    } else if (column == MITableModel.SYMS2_COLUMN) {
                        MoleculeEntry entry = ((MITableModel) table.getModel()).getResult(modelRow)
                                .getInteractor2();
                        if (query.getTaxid().equals(entry.getTaxid())) {
                            Collection<SeqSymmetry> syms = ((MITableModel) table.getModel()).getResult(modelRow)
                                    .getSymmetries2();
                            zoomToSym(syms);
                        }
                    }

                    // Protein: link to uniprot
                    if (column == MITableModel.INTERACTOR1_COLUMN
                            || column == MITableModel.INTERACTOR2_COLUMN) {

                        MIResult miResult = ((MITableModel) table.getModel()).getResult(modelRow);

                        String id;
                        String taxid;

                        MoleculeEntry interactor;
                        if (column == MITableModel.INTERACTOR1_COLUMN) {
                            interactor = miResult.getInteractor1();
                        } else {
                            interactor = miResult.getInteractor2();
                        }

                        taxid = interactor.getTaxid();

                        String query;
                        String anchor = "";
                        switch (taxid) {
                        case MoleculeEntry.TAXID_DNA:
                        case MoleculeEntry.TAXID_RNA:
                            if (miResult.getInteractionStructures().isEmpty()) {
                                return;
                            }
                            query = "http://www.pdb.org/pdb/explore/explore.do?structureId="
                                    + miResult.getInteractionStructures().iterator().next().getStructureID();
                            break;
                        case MoleculeEntry.TAXID_LIGAND:
                            if (miResult.getInteractionStructures().isEmpty()) {
                                return;
                            }
                            query = DrugBankMapper.getInstance().isDrug(interactor.getGeneName())
                                    ? DrugBankMapper.getInstance().getDrugBankLink(interactor.getGeneName())
                                    : "http://www.ebi.ac.uk/pdbe-srv/pdbechem/chemicalCompound/show/"
                                            + interactor.getGeneName();
                            break;
                        case MoleculeEntry.TAXID_MODIFICATION:
                            query = "http://www.uniprot.org/uniprot/"
                                    + miResult.getInteractor1().getUniprotAc();
                            anchor = "#ptm_processing";
                            break;
                        default:
                            id = interactor.getUniprotAc();
                            query = "http://www.uniprot.org/uniprot/" + id;
                            break;
                        }
                        try {
                            URI uri = new URI(URIUtil.encodeQuery(query) + anchor);

                            Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
                            if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
                                desktop.browse(uri);
                            }
                        } catch (IOException ioe) {
                            JOptionPane.showMessageDialog(null, "Cannot reach Uniprot website.");
                            return;
                        } catch (URISyntaxException ue) {
                            JOptionPane.showMessageDialog(null, "Cannot reach Uniprot website: " + query);
                        }
                    }

                    // interaction type: link to psicquic
                    if (column == MITableModel.INTERACTION_TYPE_COLUMN) {

                        MIResult miResult = ((MITableModel) table.getModel()).getResult(modelRow);

                        String queryURL;
                        String idA = miResult.getInteractor1().getUniprotAc();
                        String idB = miResult.getInteractor2().getUniprotAc();

                        if (null == miResult.getPsicquicUrl()) {
                            // from the structure database
                            if (query.searchDSysMap()) {
                                queryURL = "http://http://dsysmap.irbbarcelona.org/results.php?type=proteins&neigh=2&value="
                                        + idA + "," + idB;
                            } else if (query.searchInteractome3D()) {
                                try {
                                    queryURL = "http://interactome3d.irbbarcelona.org/interaction.php?ids="
                                            + idA + ";" + idB + "&dataset="
                                            + it.iit.genomics.cru.bridges.interactome3d.ws.Utils
                                                    .getDataset(query.getTaxid());
                                } catch (Interactome3DException e3d) {
                                    // it will never happend: if the taxid was not known by 
                                    // I3D, we wouldn't have an interaction
                                    return;
                                }

                            } else {
                                return;
                            }
                        } else {

                            if (false == idA.equals(idB)) {
                                queryURL = miResult.getPsicquicUrl() + "query/id:"
                                        + miResult.getInteractor1().getUniprotAc() + "* AND id:"
                                        + miResult.getInteractor2().getUniprotAc() + "*";
                            } else {
                                queryURL = miResult.getPsicquicUrl() + "query/idA:"
                                        + miResult.getInteractor1().getUniprotAc() + "* AND idB:"
                                        + miResult.getInteractor2().getUniprotAc() + "*";
                            }
                        }
                        try {
                            URI uri = new URI(URIUtil.encodeQuery(queryURL));

                            Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
                            if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
                                desktop.browse(uri);
                            }
                        } catch (IOException ioe) {
                            JOptionPane.showMessageDialog(null, "Cannot reach psicquic server.");
                        } catch (URISyntaxException ue) {
                            JOptionPane.showMessageDialog(null, "Cannot reach psicquic server: " + queryURL);
                        }

                    }
                }
            }

        }

        @Override
        public void mousePressed(MouseEvent me) {
        }

        @Override
        public void mouseReleased(MouseEvent me) {
        }

        @Override
        public void mouseEntered(MouseEvent me) {
        }

        @Override
        public void mouseExited(MouseEvent me) {
        }
    };

    TableRowSorter<MITableModel> sorter = new MITableRowSorter(model);
    setRowSorter(sorter);

    sorter.setRowFilter(evidenceRowFilter());
    model.fireTableDataChanged();
    this.getTableHeader().setReorderingAllowed(false);

    TableCellRenderer rend = getTableHeader().getDefaultRenderer();
    TableColumnModel tcm = getColumnModel();
    for (int j = 0; j < tcm.getColumnCount(); j += 1) {
        TableColumn tc = tcm.getColumn(j);
        TableCellRenderer rendCol = tc.getHeaderRenderer(); // likely null
        if (rendCol == null) {
            rendCol = rend;
        }
        Component c = rendCol.getTableCellRendererComponent(this, tc.getHeaderValue(), false, false, 0, j);
        tc.setPreferredWidth(c.getPreferredSize().width);
    }

    TableCellRenderer buttonRenderer = new JTableButtonRenderer();

    getColumn(model.getColumnName(MITableModel.TRACK_COLUMN)).setCellRenderer(buttonRenderer);

    getColumn(model.getColumnName(MITableModel.SYMS1_COLUMN)).setCellRenderer(new GeneRenderer());
    getColumn(model.getColumnName(MITableModel.SYMS2_COLUMN)).setCellRenderer(new GeneRenderer());

    getColumn(model.getColumnName(MITableModel.INTERACTOR1_COLUMN)).setCellRenderer(new MoleculeRenderer());
    getColumn(model.getColumnName(MITableModel.INTERACTOR2_COLUMN)).setCellRenderer(new MoleculeRenderer());

    getColumn(model.getColumnName(MITableModel.INTERACTION_TYPE_COLUMN))
            .setCellRenderer(new EvidenceRenderer());

    getColumn(model.getColumnName(MITableModel.STRUCTURES_COLUMN)).setCellRenderer(new StructuresRenderer());

    setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);

    int smallWidth = 75;
    int mediumWidth = 120;
    int largeWidth = 200;
    getColumnModel().getColumn(MITableModel.TRACK_COLUMN).setMinWidth(smallWidth);

    getColumnModel().getColumn(MITableModel.STRUCTURES_COLUMN).setMinWidth(smallWidth);
    getColumnModel().getColumn(MITableModel.STRUCTURES_COLUMN).setMaxWidth(smallWidth);
    getColumnModel().getColumn(MITableModel.STRUCTURES_COLUMN).setPreferredWidth(smallWidth);

    addMouseListener(SymSelectionListener);

    getSelectionModel().addListSelectionListener(new RowSelectionListener());

}

From source file:dpfmanager.shell.modules.threading.core.ThreadingService.java

/**
 * Show report//from   w  w w. j av a 2s.  c o m
 */
private void showToUser(String internal, Configuration config) {
    String name = "";
    String path;
    if (config.getFormats().contains("HTML")) {
        name = "report.html";
    } else if (config.getFormats().contains("PDF")) {
        name = "report.pdf";
    }

    path = internal + name;
    if (config.getOutput() != null) {
        path = config.getOutput() + "/" + name;
    }
    File file = new File(path);
    if (file.exists() && Desktop.isDesktopSupported()) {
        try {
            String fullPath = file.getAbsolutePath();
            fullPath = fullPath.replaceAll("\\\\", "/");
            Desktop.getDesktop().browse(new URI("file:///" + fullPath.replaceAll(" ", "%20")));
        } catch (Exception e) {
            context.send(BasicConfig.MODULE_MESSAGE, new ExceptionMessage(bundle.getString("browserError"), e));
        }
    } else {
        context.send(BasicConfig.MODULE_MESSAGE,
                new LogMessage(getClass(), Level.DEBUG, bundle.getString("deskServError")));
    }
}

From source file:com.konifar.material_icon_generator.MaterialDesignIconGenerateDialog.java

private void initLabelLink(JLabel label, final String url) {
    label.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    label.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent event) {
            if (event.getClickCount() > 0) {
                if (Desktop.isDesktopSupported()) {
                    Desktop desktop = Desktop.getDesktop();
                    try {
                        URI uri = new URI(url);
                        desktop.browse(uri);
                    } catch (IOException e) {
                        e.printStackTrace();
                    } catch (URISyntaxException e) {
                        e.printStackTrace();
                    }//from   w ww.j  a v  a 2 s .  co  m
                }
            }
        }
    });
}

From source file:se.trixon.toolbox.idiot.IdiotTopComponent.java

private void openDirectoryButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openDirectoryButtonActionPerformed
    if (!Desktop.isDesktopSupported()) {
        return;/* ww w.  j  a  v  a  2  s. c o  m*/
    }

    try {
        Desktop desktop = Desktop.getDesktop();
        File dest = new File(tasksPanel.getSelectedTask().getDestination()).getParentFile();

        desktop.open(dest);
    } catch (Exception ex) {
        NbMessage.error(Dict.Dialog.TITLE_IO_ERROR.toString(),
                Dict.Dialog.ERROR_CANT_OPEN_DIRECTORY.toString());
    }
}