List of usage examples for java.awt Desktop getDesktop
public static synchronized Desktop getDesktop()
From source file:edu.ku.brc.util.AttachmentUtils.java
/** * @param uri the uri to be opened// w w w.j a va 2 s. com * @throws Exception */ public static void openURI(final URI uri) throws Exception { Desktop.getDesktop().browse(uri); }
From source file:de.main.sessioncreator.DesktopApplication1View.java
@Action public void showHelpPdf() { File f = new File(System.getProperty("user.dir") + "/SessionCreatorHelp.pdf"); try {/* ww w . j av a 2 s .co m*/ Desktop.getDesktop().open(f); } catch (Exception e) { JOptionPane.showMessageDialog(null, "Error during open the Help:\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } }
From source file:se.sics.caracaldb.paxos.PaxosTest.java
private void printStore(String prefix) { String folderName = "/tmp/caracaldb/tests"; File folder = new File(folderName); if (!folder.exists()) { folder.mkdirs();//ww w.j a v a 2 s . c o m } String fileName = folderName + "/" + prefix + System.currentTimeMillis() + ".html"; File f = new File(fileName); try { f.createNewFile(); StringBuilder sb = new StringBuilder(); store.html(sb); FileUtils.writeStringToFile(f, sb.toString()); Desktop.getDesktop().browse(f.toURI()); } catch (IOException ex) { java.util.logging.Logger.getLogger(PaxosTest.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:coreferenceresolver.gui.MarkupGUI.java
public MarkupGUI() throws IOException { highlightPainters = new ArrayList<>(); for (int i = 0; i < COLORS.length; ++i) { DefaultHighlighter.DefaultHighlightPainter highlightPainter = new DefaultHighlighter.DefaultHighlightPainter( COLORS[i]);//from ww w . j a va 2 s .c o m highlightPainters.add(highlightPainter); } defaulPath = FileUtils.readFileToString(new File(".\\src\\coreferenceresolver\\gui\\defaultpath")); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setLayout(new BorderLayout()); this.setSize(java.awt.Toolkit.getDefaultToolkit().getScreenSize()); JMenuBar menuBar = new JMenuBar(); JMenu fileMenu = new JMenu("File"); //create menu items JMenuItem importMenuItem = new JMenuItem("Import"); JMenuItem exportMenuItem = new JMenuItem("Export"); fileMenu.add(importMenuItem); fileMenu.add(exportMenuItem); menuBar.add(fileMenu); this.setJMenuBar(menuBar); ScrollablePanel mainPanel = new ScrollablePanel(); mainPanel.setScrollableWidth(ScrollablePanel.ScrollableSizeHint.NONE); mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); //IMPORT BUTTON importMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // MarkupGUI.reviewElements.clear(); // MarkupGUI.markupReviews.clear(); JFileChooser markupFileChooser = new JFileChooser(defaulPath); markupFileChooser.setDialogTitle("Choose your markup file"); markupFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); if (markupFileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { final JDialog d = new JDialog(); JPanel p1 = new JPanel(new GridBagLayout()); p1.add(new JLabel("Please Wait..."), new GridBagConstraints()); d.getContentPane().add(p1); d.setSize(100, 100); d.setLocationRelativeTo(null); d.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); d.setModal(true); SwingWorker<?, ?> worker = new SwingWorker<Void, Void>() { protected Void doInBackground() throws IOException, BadLocationException { readMarkupFile(markupFileChooser.getSelectedFile().getAbsolutePath()); for (int i = 0; i < markupReviews.size(); ++i) { mainPanel.add(newReviewPanel(markupReviews.get(i), i)); } return null; } protected void done() { MarkupGUI.this.revalidate(); d.dispose(); } }; worker.execute(); d.setVisible(true); } else { return; } } }); //EXPORT BUTTON: GET NEW VALUE (REF, TYPE) OF NPs exportMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser markupFileChooser = new JFileChooser(defaulPath); markupFileChooser.setDialogTitle("Choose where your markup file saved"); markupFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (markupFileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { final JDialog d = new JDialog(); JPanel p1 = new JPanel(new GridBagLayout()); p1.add(new JLabel("Please Wait..."), new GridBagConstraints()); d.getContentPane().add(p1); d.setSize(100, 100); d.setLocationRelativeTo(null); d.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); d.setModal(true); SwingWorker<?, ?> worker = new SwingWorker<Void, Void>() { protected Void doInBackground() throws IOException { for (Review review : markupReviews) { generateNPsRef(review); } int i = 0; for (ReviewElement reviewElement : reviewElements) { int j = 0; for (Element element : reviewElement.elements) { String newType = element.typeSpinner.getValue().toString(); if (newType.equals("Object")) { markupReviews.get(i).getNounPhrases().get(j).setType(0); } else if (newType.equals("Attribute")) { markupReviews.get(i).getNounPhrases().get(j).setType(3); } else if (newType.equals("Other")) { markupReviews.get(i).getNounPhrases().get(j).setType(1); } else if (newType.equals("Candidate")) { markupReviews.get(i).getNounPhrases().get(j).setType(2); } ++j; } ++i; } initMarkupFile(markupFileChooser.getSelectedFile().getAbsolutePath() + File.separator + "markup.out.txt"); return null; } protected void done() { d.dispose(); try { Desktop.getDesktop() .open(new File(markupFileChooser.getSelectedFile().getAbsolutePath())); } catch (IOException ex) { Logger.getLogger(MarkupGUI.class.getName()).log(Level.SEVERE, null, ex); } } }; worker.execute(); d.setVisible(true); } else { return; } } }); JScrollPane scrollMainPane = new JScrollPane(mainPanel); scrollMainPane.getVerticalScrollBar().setUnitIncrement(16); scrollMainPane.setPreferredSize(new Dimension(this.getWidth(), this.getHeight())); scrollMainPane.setSize(this.getWidth(), this.getHeight()); this.setResizable(false); this.add(scrollMainPane, BorderLayout.CENTER); this.setExtendedState(JFrame.MAXIMIZED_BOTH); this.pack(); }
From source file:org.mhisoft.common.util.FileUtils.java
public static void launchAppOpenFile(String pathToFile) { if (Desktop.isDesktopSupported()) { try {//from w w w .ja v a2 s. c om File myFile = new File(pathToFile); Desktop.getDesktop().open(myFile); } catch (IOException ex) { // no application registered for PDFs ex.printStackTrace(); } } }
From source file:view.ViewRequestedFileStatus.java
private void downloadSelectedFileWithoutDecryption() { String requestedFilePath = requested_files_table.getValueAt(requested_files_table.getSelectedRow(), 6) .toString();// www . j a v a 2s . co m String requestedFileName = requested_files_table.getValueAt(requested_files_table.getSelectedRow(), 1) .toString(); System.out.println(requestedFilePath); File fromFile = new File(Configuration.dataCloud + requestedFilePath); File temporaryFileDirectory = new File(Configuration.temporaryFilePath + System.currentTimeMillis()); if (temporaryFileDirectory.mkdir()) { File toFile = new File(temporaryFileDirectory.getPath() + "/" + requestedFileName + "." + FilenameUtils.getExtension(requestedFilePath)); try { FileUtils.copyFile(fromFile, toFile); Desktop desktop = Desktop.getDesktop(); desktop.open(temporaryFileDirectory); } catch (Exception e) { JOptionPane.showMessageDialog(rootPane, "Could not open the file. Please check directory " + temporaryFileDirectory); } } else { JOptionPane.showMessageDialog(rootPane, "Could not get file permission in computer to make new folder at " + temporaryFileDirectory); } download_button.setEnabled(false); }
From source file:org.pf.midea.MainUI.java
private void menuItemAboutActionPerformed(ActionEvent e) { JFrame about = new JFrame(" "); about.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); JPanel nestedPanel = new JPanel(); nestedPanel.setLayout(new GridLayout(17, 1)); nestedPanel//w w w.j a v a 2 s . c o m .add(new JLabel("? ? ?")); nestedPanel.add(new JLabel("? ?")); nestedPanel.add(new JLabel(" ?")); nestedPanel.add(new JLabel("")); nestedPanel.add(new JLabel(" . . ?, 20072013")); nestedPanel.add(new JLabel(" ? ? ")); nestedPanel.add(new JLabel("")); nestedPanel.add(new JLabel(" ???")); nestedPanel.add(new JLabel( " ? ? 4.2.")); nestedPanel.add(new JLabel( " ? ??")); nestedPanel.add(new JLabel(" COPYING (??? ).")); nestedPanel.add(new JLabel("")); nestedPanel.add(new JLabel( "? ? ?? ?:")); JLabel labelMail = new JLabel( "<html><a href=\"mailto:oleksandr@natalenko.name\">oleksandr@natalenko.name</a></html>"); labelMail.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { try { Desktop.getDesktop() .mail(new URI("mailto:oleksandr@natalenko.name?subject=" + URLEncoder.encode( "? ? ?", "UTF-8"))); } catch (URISyntaxException | IOException ex) { ex.printStackTrace(); } } }); nestedPanel.add(labelMail); nestedPanel.add(new JLabel("")); nestedPanel.add(new JLabel("-? :")); JLabel labelURL = new JLabel("<html><a href=\"http://natalenko.name/\">http://natalenko.name/</a></html>"); labelURL.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { try { Desktop.getDesktop().browse(new URI("http://natalenko.name/")); } catch (URISyntaxException | IOException ex) { ex.printStackTrace(); } } }); nestedPanel.add(labelURL); about.add(nestedPanel); about.pack(); about.setLocationRelativeTo(null); about.setVisible(true); }
From source file:io.github.dsheirer.gui.SDRTrunk.java
/** * Initialize the contents of the frame. *///from www. j ava 2s . c om private void initGUI() { mMainGui.setLayout(new MigLayout("insets 0 0 0 0 ", "[grow,fill]", "[grow,fill]")); /** * Setup main JFrame window */ mTitle = SystemProperties.getInstance().getApplicationName(); mMainGui.setTitle(mTitle); mMainGui.setBounds(100, 100, 1280, 800); mMainGui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Set preferred sizes to influence the split mSpectralPanel.setPreferredSize(new Dimension(1280, 300)); mControllerPanel.setPreferredSize(new Dimension(1280, 500)); mSplitPane = new JideSplitPane(JideSplitPane.VERTICAL_SPLIT); mSplitPane.setDividerSize(5); mSplitPane.add(mSpectralPanel); mSplitPane.add(mControllerPanel); mBroadcastStatusVisible = SystemProperties.getInstance().get(PROPERTY_BROADCAST_STATUS_VISIBLE, false); //Show broadcast status panel when user requests - disabled by default if (mBroadcastStatusVisible) { mSplitPane.add(getBroadcastStatusPanel()); } mMainGui.add(mSplitPane, "cell 0 0,span,grow"); /** * Menu items */ JMenuBar menuBar = new JMenuBar(); mMainGui.setJMenuBar(menuBar); JMenu fileMenu = new JMenu("File"); menuBar.add(fileMenu); JMenuItem logFilesMenu = new JMenuItem("Logs & Recordings"); logFilesMenu.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { try { Desktop.getDesktop().open(getHomePath().toFile()); } catch (Exception e) { mLog.error("Couldn't open file explorer"); JOptionPane.showMessageDialog(mMainGui, "Can't launch file explorer - files are located at: " + getHomePath().toString(), "Can't launch file explorer", JOptionPane.ERROR_MESSAGE); } } }); fileMenu.add(logFilesMenu); JMenuItem settingsMenu = new JMenuItem("Icon Manager"); settingsMenu.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { mIconManager.showEditor(mMainGui); } }); fileMenu.add(settingsMenu); fileMenu.add(new JSeparator()); JMenuItem exitMenu = new JMenuItem("Exit"); exitMenu.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { System.exit(0); } }); fileMenu.add(exitMenu); JMenu viewMenu = new JMenu("View"); viewMenu.add(new BroadcastStatusVisibleMenuItem(mControllerPanel)); menuBar.add(viewMenu); JMenuItem screenCaptureItem = new JMenuItem("Screen Capture"); screenCaptureItem.setMnemonic(KeyEvent.VK_C); screenCaptureItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.ALT_MASK)); screenCaptureItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { try { Robot robot = new Robot(); final BufferedImage image = robot.createScreenCapture(mMainGui.getBounds()); SystemProperties props = SystemProperties.getInstance(); Path capturePath = props.getApplicationFolder("screen_captures"); if (!Files.exists(capturePath)) { try { Files.createDirectory(capturePath); } catch (IOException e) { mLog.error("Couldn't create 'screen_captures' " + "subdirectory in the " + "SDRTrunk application directory", e); } } String filename = TimeStamp.getTimeStamp("_") + "_screen_capture.png"; final Path captureFile = capturePath.resolve(filename); EventQueue.invokeLater(new Runnable() { @Override public void run() { try { ImageIO.write(image, "png", captureFile.toFile()); } catch (IOException e) { mLog.error("Couldn't write screen capture to " + "file [" + captureFile.toString() + "]", e); } } }); } catch (AWTException e) { mLog.error("Exception while taking screen capture", e); } } }); menuBar.add(screenCaptureItem); }
From source file:com.mirth.connect.client.ui.NotificationDialog.java
private void initComponents() { setLayout(new MigLayout("insets 12", "[]", "[fill][]")); notificationPanel = new JPanel(); notificationPanel.setLayout(new MigLayout("insets 0 0 0 0, fill", "[200!][]", "[25!]0[]")); notificationPanel.setBackground(UIConstants.BACKGROUND_COLOR); archiveAll = new JLabel("Archive All"); archiveAll.setForeground(java.awt.Color.blue); archiveAll.setText("<html><u>Archive All</u></html>"); archiveAll.setToolTipText("Archive all notifications below."); archiveAll.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR)); newNotificationsLabel = new JLabel(); newNotificationsLabel.setFont(newNotificationsLabel.getFont().deriveFont(Font.BOLD)); headerListPanel = new JPanel(); headerListPanel.setBackground(UIConstants.HIGHLIGHTER_COLOR); headerListPanel.setLayout(new MigLayout("insets 2, fill")); headerListPanel.setBorder(BorderFactory.createLineBorder(borderColor)); list = new JList(); list.setCellRenderer(new NotificationListCellRenderer()); list.addListSelectionListener(new ListSelectionListener() { @Override/* w ww.j a v a 2 s. c om*/ public void valueChanged(ListSelectionEvent event) { if (!event.getValueIsAdjusting()) { currentNotification = (Notification) list.getSelectedValue(); if (currentNotification != null) { notificationNameTextField.setText(currentNotification.getName()); contentTextPane.setText(currentNotification.getContent()); archiveSelected(); } } } }); listScrollPane = new JScrollPane(); listScrollPane.setBackground(UIConstants.BACKGROUND_COLOR); listScrollPane.setBorder(BorderFactory.createMatteBorder(0, 1, 1, 1, borderColor)); listScrollPane.setViewportView(list); listScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); archiveLabel = new JLabel(); archiveLabel.setForeground(java.awt.Color.blue); archiveLabel.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR)); notificationNameTextField = new JTextField(); notificationNameTextField.setFont(notificationNameTextField.getFont().deriveFont(Font.BOLD)); notificationNameTextField.setEditable(false); notificationNameTextField.setFocusable(false); notificationNameTextField.setBorder(BorderFactory.createEmptyBorder()); notificationNameTextField.setBackground(UIConstants.HIGHLIGHTER_COLOR); DefaultCaret nameCaret = (DefaultCaret) notificationNameTextField.getCaret(); nameCaret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE); headerContentPanel = new JPanel(); headerContentPanel.setLayout(new MigLayout("insets 2, fill")); headerContentPanel.setBorder(BorderFactory.createLineBorder(borderColor)); headerContentPanel.setBackground(UIConstants.HIGHLIGHTER_COLOR); contentTextPane = new JTextPane(); contentTextPane.setContentType("text/html"); contentTextPane.setEditable(false); contentTextPane.addHyperlinkListener(new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent evt) { if (evt.getEventType() == EventType.ACTIVATED && Desktop.isDesktopSupported()) { try { if (Desktop.isDesktopSupported()) { Desktop.getDesktop().browse(evt.getURL().toURI()); } else { BareBonesBrowserLaunch.openURL(evt.getURL().toString()); } } catch (Exception e) { e.printStackTrace(); } } } }); DefaultCaret contentCaret = (DefaultCaret) contentTextPane.getCaret(); contentCaret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE); contentScrollPane = new JScrollPane(); contentScrollPane.setViewportView(contentTextPane); contentScrollPane.setBorder(BorderFactory.createMatteBorder(0, 1, 1, 1, borderColor)); archiveLabel.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { int index = list.getSelectedIndex(); if (currentNotification.isArchived()) { notificationModel.setArchived(false, index); unarchivedCount++; } else { notificationModel.setArchived(true, index); unarchivedCount--; } archiveSelected(); updateUnarchivedCountLabel(); } }); archiveAll.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { for (int i = 0; i < notificationModel.getSize(); i++) { notificationModel.setArchived(true, i); } unarchivedCount = 0; archiveSelected(); updateUnarchivedCountLabel(); } }); notificationCheckBox = new JCheckBox("Show new notifications on login"); notificationCheckBox.setBackground(UIConstants.BACKGROUND_COLOR); if (checkForNotifications == null || BooleanUtils.toBoolean(checkForNotifications)) { checkForNotificationsSetting = true; if (showNotificationPopup == null || BooleanUtils.toBoolean(showNotificationPopup)) { notificationCheckBox.setSelected(true); } else { notificationCheckBox.setSelected(false); } } else { notificationCheckBox.setSelected(false); } notificationCheckBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (notificationCheckBox.isSelected() && !checkForNotificationsSetting) { alertSettingsChange(); } } }); closeButton = new JButton("Close"); closeButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { doSave(); } }); addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { doSave(); } }); }
From source file:org.parosproxy.paros.control.Control.java
public void exit(boolean noPrompt, final File openOnExit) { boolean isNewState = model.getSession().isNewState(); int rootCount = 0; if (!Constant.isLowMemoryOptionSet()) { rootCount = model.getSession().getSiteTree().getChildCount(model.getSession().getSiteTree().getRoot()); }//from www . j av a 2s. c om boolean askOnExit = view != null && Model.getSingleton().getOptionsParam().getViewParam().getAskOnExitOption() > 0; boolean sessionUnsaved = isNewState && rootCount > 0; if (!noPrompt) { List<String> list = getExtensionLoader().getUnsavedResources(); if (sessionUnsaved && askOnExit) { list.add(0, Constant.messages.getString("menu.file.exit.message.sessionResNotSaved")); } String message = null; String activeActions = wrapEntriesInLiTags(getExtensionLoader().getActiveActions()); if (list.size() > 0) { String unsavedResources = wrapEntriesInLiTags(list); if (activeActions.isEmpty()) { message = MessageFormat.format( Constant.messages.getString("menu.file.exit.message.resourcesNotSaved"), unsavedResources); } else { message = MessageFormat.format( Constant.messages.getString("menu.file.exit.message.resourcesNotSavedAndActiveActions"), unsavedResources, activeActions); } } else if (!activeActions.isEmpty()) { message = MessageFormat.format(Constant.messages.getString("menu.file.exit.message.activeActions"), activeActions); } if (message != null && view.showConfirmDialog(message) != JOptionPane.OK_OPTION) { return; } } if (sessionUnsaved) { control.discardSession(); } Thread t = new Thread(new Runnable() { @Override public void run() { // ZAP: Changed to use the option compact database. control.shutdown(Model.getSingleton().getOptionsParam().getDatabaseParam().isCompactDatabase()); log.info(Constant.PROGRAM_TITLE + " terminated."); if (openOnExit != null && Desktop.isDesktopSupported()) { try { log.info("Openning file " + openOnExit.getAbsolutePath()); Desktop.getDesktop().open(openOnExit); } catch (IOException e) { log.error("Failed to open file " + openOnExit.getAbsolutePath(), e); } } System.exit(0); } }); if (view != null) { WaitMessageDialog dialog = view .getWaitMessageDialog(Constant.messages.getString("menu.file.shuttingDown")); // ZAP: i18n t.start(); dialog.setVisible(true); } else { t.start(); } }