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:com.simiacryptus.util.Util.java

/**
 * Report./*from  w  w w.  ja va2  s.c  o  m*/
 *
 * @param fragments the fragments
 * @throws IOException the io exception
 */
public static void report(@javax.annotation.Nonnull final Stream<String> fragments) throws IOException {
    @javax.annotation.Nonnull
    final File outDir = new File("reports");
    outDir.mkdirs();
    final StackTraceElement caller = com.simiacryptus.util.Util
            .getLast(Arrays.stream(Thread.currentThread().getStackTrace())//
                    .filter(x -> x.getClassName().contains("simiacryptus")));
    @javax.annotation.Nonnull
    final File report = new File(outDir, caller.getClassName() + "_" + caller.getLineNumber() + ".html");
    @javax.annotation.Nonnull
    final PrintStream out = new PrintStream(new FileOutputStream(report));
    out.println("<html><head></head><body>");
    fragments.forEach(out::println);
    out.println("</body></html>");
    out.close();
    Desktop.getDesktop().browse(report.toURI());
}

From source file:gui.DownloadPanel.java

public void actionOpenFile() {
    try {/*from  w ww  . java 2s .  c o  m*/
        Desktop.getDesktop().open(new File(
                selectedDownload.getDownloadPath() + File.separator + selectedDownload.getDownloadName()));
    } catch (IOException e) {
        e.printStackTrace(); //todo
    }
}

From source file:gdt.jgui.entity.folder.JFolderFacetOpenItem.java

/**
 * Get the popup menu for the child node of the facet node 
 * in the digest view./*from   w w w  .j av  a2s.  c om*/
 * @return the popup menu.   
 */
@Override
public JPopupMenu getPopupMenu(final String digestLocator$) {
    JPopupMenu popup = new JPopupMenu();
    try {
        Properties locator = Locator.toProperties(digestLocator$);
        final String encodedSelection$ = locator.getProperty(JEntityDigestDisplay.SELECTION);
        byte[] ba = Base64.decodeBase64(encodedSelection$);
        final String selection$ = new String(ba, "UTF-8");
        //      System.out.println("JFolderFacetOpenItem:getPopupMenu:selection:="+selection$);
        locator = Locator.toProperties(selection$);
        String nodeType$ = locator.getProperty(JEntityDigestDisplay.NODE_TYPE);
        if (JEntityDigestDisplay.NODE_TYPE_FACET_OWNER.equals(nodeType$)) {
            JMenuItem openItem = new JMenuItem("Open");
            popup.add(openItem);
            openItem.setHorizontalTextPosition(JMenuItem.RIGHT);
            openItem.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    try {
                        Properties locator = Locator.toProperties(selection$);
                        String entihome$ = locator.getProperty(Entigrator.ENTIHOME);
                        String entityKey$ = locator.getProperty(EntityHandler.ENTITY_KEY);
                        File file = new File(entihome$ + "/" + entityKey$);
                        Desktop.getDesktop().open(file);
                    } catch (Exception ee) {
                        Logger.getLogger(JFieldsFacetOpenItem.class.getName()).info(ee.toString());
                    }
                }
            });
            JMenuItem editItem = new JMenuItem("Edit");
            popup.add(editItem);
            editItem.setHorizontalTextPosition(JMenuItem.RIGHT);
            editItem.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    try {
                        Properties locator = Locator.toProperties(selection$);
                        String entihome$ = locator.getProperty(Entigrator.ENTIHOME);
                        String entityKey$ = locator.getProperty(EntityHandler.ENTITY_KEY);
                        JFolderPanel fp = new JFolderPanel();
                        String fpLocator$ = fp.getLocator();
                        fpLocator$ = Locator.append(fpLocator$, Entigrator.ENTIHOME, entihome$);
                        fpLocator$ = Locator.append(fpLocator$, EntityHandler.ENTITY_KEY, entityKey$);
                        JConsoleHandler.execute(console, fpLocator$);
                    } catch (Exception ee) {
                        Logger.getLogger(JFieldsFacetOpenItem.class.getName()).info(ee.toString());
                    }
                }
            });
        }
        if (NODE_TYPE_FILE_NODE.equals(nodeType$)) {
            JMenuItem openItem = new JMenuItem("Open");
            popup.add(openItem);
            openItem.setHorizontalTextPosition(JMenuItem.RIGHT);
            openItem.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    try {
                        Properties locator = Locator.toProperties(selection$);
                        String filePath$ = locator.getProperty(JFolderPanel.FILE_PATH);
                        File file = new File(filePath$);
                        Desktop.getDesktop().open(file);
                    } catch (Exception ee) {
                        Logger.getLogger(JFieldsFacetOpenItem.class.getName()).info(ee.toString());
                    }
                }
            });
            String filePath$ = locator.getProperty(JFolderPanel.FILE_PATH);
            final File file = new File(filePath$);
            if (isTextFile(file)) {
                JMenuItem editItem = new JMenuItem("Edit");
                popup.add(editItem);
                editItem.setHorizontalTextPosition(JMenuItem.RIGHT);
                editItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        try {
                            InputStream is = new FileInputStream(file);
                            ByteArrayOutputStream bos = new ByteArrayOutputStream();
                            byte[] b = new byte[1024];
                            int bytesRead = 0;
                            while ((bytesRead = is.read(b)) != -1) {
                                bos.write(b, 0, bytesRead);
                            }
                            byte[] ba = bos.toByteArray();
                            is.close();
                            String text$ = new String(ba, "UTF-8");
                            JTextEditor te = new JTextEditor();
                            String teLocator$ = te.getLocator();
                            teLocator$ = Locator.append(teLocator$, Entigrator.ENTIHOME, entihome$);
                            teLocator$ = Locator.append(teLocator$, JTextEditor.TEXT, text$);
                            locator$ = Locator.append(locator$, JRequester.REQUESTER_ACTION,
                                    JFolderPanel.ACTION_EDIT_FILE);
                            locator$ = Locator.append(locator$, JFolderPanel.FILE_PATH, file.getPath());
                            locator$ = Locator.append(locator$, BaseHandler.HANDLER_METHOD, "response");
                            locator$ = Locator.append(locator$, JEntityDigestDisplay.SELECTION,
                                    encodedSelection$);
                            String requesterResponceLocator$ = Locator.compressText(locator$);
                            teLocator$ = Locator.append(teLocator$, JRequester.REQUESTER_RESPONSE_LOCATOR,
                                    requesterResponceLocator$);
                            JConsoleHandler.execute(console, teLocator$);
                        } catch (Exception ee) {
                            Logger.getLogger(getClass().getName()).info(ee.toString());
                        }
                    }
                });
            }
        }
        return popup;
    } catch (Exception e) {
        Logger.getLogger(getClass().getName()).severe(e.toString());
        return null;
    }
}

From source file:is.iclt.jcorpald.CorpaldView.java

private void openFolder() {
    try {/*from   w  w  w.  j a v  a  2  s . c  o m*/
        String str = FilenameUtils.separatorsToUnix(model.getFileName());
        str = str.substring(0, str.lastIndexOf("/"));
        Desktop.getDesktop().open(new File(str));
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:org.richie.codeGen.ui.CodeGenMainUI.java

@Override
public void actionPerformed(ActionEvent e) {
    if (e.getSource() == openPdmFileItem) {
        openPdmFile();/*from  w ww .j a v  a2  s  .  co  m*/
    } else if (e.getSource() == templateConfigItem) {
        TemplateConfigWin win = new TemplateConfigWin(getGenAndPreviewPanel());
        win.setModal(true);
        win.setBounds(this.getX() + 100, this.getY() + 30, win.getWidth(), win.getHeight());
        win.setVisible(true);
    } else if (e.getSource() == consConfigItem) {
        ConstantConfigWin win = new ConstantConfigWin(getGenAndPreviewPanel());
        win.setModal(true);
        win.setBounds(this.getX() + 250, this.getY() + 30, win.getWidth(), win.getHeight());
        win.setVisible(true);
    } else if (e.getSource() == dataTypeConfigItem) {
        BaseDataConfigWin win = new BaseDataConfigWin();
        win.setModal(true);
        win.setBounds(this.getX() + 250, this.getY() + 30, win.getWidth(), win.getHeight());
        win.setVisible(true);
    } else if (e.getSource() == helpDoc) {
        try {
            Desktop.getDesktop().open(new File(FileUtils.getHelpPath()));
        } catch (IOException e1) {
            log.error("", e1);
        }
    } else if (e.getSource() == miAbout) {
        JOptionPane.showMessageDialog(this,
                "codeGen-" + Version.getVersionNumber() + "\nelfkingw?  elfkingw@gmail.com",
                "", JOptionPane.INFORMATION_MESSAGE);
    }
}

From source file:gdt.jgui.entity.query.JQueryPanel.java

/**
 * Get the context menu.//  w  w  w  .  j ava 2 s.c om
 * @return the context menu.
 */
@Override
public JMenu getContextMenu() {
    menu = new JMenu("Context");
    menu.addMenuListener(new MenuListener() {
        @Override
        public void menuSelected(MenuEvent e) {
            menu.removeAll();
            //            System.out.println("BookmarksEditor:getConextMenu:menu selected");
            JMenuItem selectItem = new JMenuItem("Select");
            selectItem.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    showHeader();
                    showContent();
                }
            });
            menu.add(selectItem);
            JMenuItem clearHeader = new JMenuItem("Clear all");
            clearHeader.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    clearHeader();
                    showHeader();
                    showContent();
                }
            });
            menu.add(clearHeader);
            Entigrator entigrator = console.getEntigrator(entihome$);
            Sack query = entigrator.getEntityAtKey(entityKey$);
            if (query.getElementItem("parameter", "noreset") == null) {
                JMenuItem resetItem = new JMenuItem("Reset");
                resetItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        int response = JOptionPane.showConfirmDialog(console.getContentPanel(),
                                "Reset source to default ?", "Confirm", JOptionPane.YES_NO_OPTION,
                                JOptionPane.QUESTION_MESSAGE);
                        if (response == JOptionPane.YES_OPTION)
                            reset();
                    }
                });
                menu.add(resetItem);
            }
            JMenuItem folderItem = new JMenuItem("Open folder");
            folderItem.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    try {
                        File file = new File(entihome$ + "/" + entityKey$);
                        Desktop.getDesktop().open(file);
                    } catch (Exception ee) {
                        Logger.getLogger(getClass().getName()).info(ee.toString());
                    }
                }
            });
            menu.add(folderItem);

            menu.addSeparator();
            JMenuItem addHeader = new JMenuItem("Add column");
            addHeader.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    addHeader();
                }
            });
            menu.add(addHeader);
            JMenuItem removeColumn = new JMenuItem("Remove column ");
            removeColumn.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    removeColumn();
                }
            });
            menu.add(removeColumn);
            ListSelectionModel lsm = table.getSelectionModel();
            if (!lsm.isSelectionEmpty()) {
                JMenuItem excludeRows = new JMenuItem("Exclude rows ");
                excludeRows.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        Entigrator entigrator = console.getEntigrator(entihome$);
                        Sack query = entigrator.getEntityAtKey(entityKey$);
                        if (!query.existsElement("exclude"))
                            query.createElement("exclude");
                        //else
                        //   query.clearElement("exclude");
                        ListSelectionModel lsm = table.getSelectionModel();
                        int minIndex = lsm.getMinSelectionIndex();
                        int maxIndex = lsm.getMaxSelectionIndex();
                        for (int i = minIndex; i <= maxIndex; i++) {
                            if (lsm.isSelectedIndex(i)) {
                                System.out.println("JQueryPanel:exclude rows:label=" + table.getValueAt(i, 1));
                                query.putElementItem("exclude",
                                        new Core(null, (String) table.getValueAt(i, 1), null));
                            }
                        }
                        entigrator.save(query);
                        showHeader();
                        showContent();
                    }
                });
                menu.add(excludeRows);
            }
        }

        @Override
        public void menuDeselected(MenuEvent e) {
        }

        @Override
        public void menuCanceled(MenuEvent e) {
        }
    });
    return menu;
}

From source file:gui.DownloadPanel.java

public void actionOpenFolder() {
    try {/*w w  w . j av  a2s  .c  o m*/
        Desktop.getDesktop().open(selectedDownload.getDownloadPath());
    } catch (IOException e) {
        e.printStackTrace(); //todo
    }
}

From source file:is.iclt.jcorpald.CorpaldView.java

private void openTextEditor() {
    try {//www. ja va2  s .  c  o  m
        Desktop.getDesktop().open(model.getResultFile());
    } catch (IOException e) {
        e.printStackTrace();
    }
}

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  .  jav  a2s  . c o  m
                }
            }
        }
    });
}

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

/**
 * Show report//from  w  w  w .  j  a v 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")));
    }
}