List of usage examples for java.awt.datatransfer StringSelection StringSelection
public StringSelection(String data)
From source file:org.fhaes.util.JTableSpreadsheetByRowAdapter.java
/** * TODO// w w w . j a v a 2s.c om */ public void doCopy() { log.debug("doCopy() called"); StringBuffer sbf = new StringBuffer(); // Check to ensure we have selected only a contiguous block of // cells // int numcols=mainTable.getSelectedColumnCount(); int numrows = mainTable.getSelectedRowCount(); int[] rowsselected = mainTable.getSelectedRows(); // int[] colsselected=mainTable.getSelectedColumns(); /* * log.debug("selected rows: "); for(int i : rowsselected) { log.debug(" - "+i); } log.debug("selected cols: "); for(int i : * colsselected) { log.debug(" - "+i); } * * if (!((numrows-1==rowsselected[rowsselected.length-1]-rowsselected[0] && numrows==rowsselected.length) && * (numcols-1==colsselected[colsselected.length-1]-colsselected[0] && numcols==colsselected.length))) { * JOptionPane.showMessageDialog(mainTable, "Invalid copy selection. Selected cells must be contiguous.", "Invalid", * JOptionPane.ERROR_MESSAGE); return; } */ // First add column headers for (int c = 0; c < mainTable.getColumnCount(); c++) { sbf.append(mainTable.getColumnName(c)); sbf.append("\t"); } sbf.append("\n"); for (int i = 0; i < numrows; i++) { for (int j = 0; j < mainTable.getColumnCount(); j++) { Object value = mainTable.getValueAt(rowsselected[i], j); sbf.append(value); sbf.append("\t"); } sbf.append("\n"); } stsel = new StringSelection(sbf.toString()); system = Toolkit.getDefaultToolkit().getSystemClipboard(); system.setContents(stsel, stsel); }
From source file:savant.view.swing.FrameCommandBar.java
/** * Create Tools menu for commandBar. This is common to all track types. *//*from w ww.j av a2s . c om*/ private JMenu createToolsMenu() { JMenu menu = new JMenu("Tools"); JMenuItem item = new JCheckBoxMenuItem("Lock X Axis"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { graphPane.setLocked(!graphPane.isLocked()); } }); menu.add(item); // TODO: experimental feature which doesn't quite work yet final JMenuItem itemy = new JCheckBoxMenuItem("Lock Y Axis"); itemy.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.out.println("Trying to locking Y max: " + !itemy.isSelected()); graphPane.setYMaxLocked(itemy.isSelected()); } }); //menu.add(itemy); item = new JMenuItem("Copy URL to Clipboard"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Toolkit.getDefaultToolkit().getSystemClipboard() .setContents(new StringSelection(mainTrack.getDataSource().getURI().toString()), null); } }); menu.add(item); DataFormat df = mainTrack.getDataFormat(); if (df == DataFormat.SEQUENCE) { menu.add(new JSeparator()); JMenuItem copyItem = new JMenuItem("Copy Sequence to Clipboard"); copyItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { try { LocationController lc = LocationController.getInstance(); byte[] seq = ((SequenceTrack) mainTrack).getSequence(lc.getReferenceName(), lc.getRange()); Toolkit.getDefaultToolkit().getSystemClipboard() .setContents(new StringSelection(new String(seq)), null); } catch (Throwable x) { LOG.error(x); DialogUtils.displayError("Unable to copy sequence to clipboard."); } } }); menu.add(copyItem); setAsGenomeButton = new JCheckBoxMenuItem("Set as Genome"); setAsGenomeButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Genome newGenome = Genome.createFromTrack(mainTrack); GenomeController.getInstance().setGenome(newGenome); } }); menu.add(setAsGenomeButton); menu.addMenuListener(new MenuAdapter() { @Override public void menuSelected(MenuEvent me) { Track seqTrack = (Track) GenomeController.getInstance().getGenome().getSequenceTrack(); if (seqTrack == mainTrack) { setAsGenomeButton.setSelected(true); setAsGenomeButton.setEnabled(false); setAsGenomeButton.setToolTipText("This track is already the reference sequence"); } else { setAsGenomeButton.setSelected(false); setAsGenomeButton.setEnabled(true); setAsGenomeButton.setToolTipText("Use this track as the reference sequence"); } } }); } else if (df == DataFormat.ALIGNMENT) { menu.add(new JSeparator()); item = new JMenuItem("Filter..."); item.setToolTipText("Control how records are filtered"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { new BAMFilterDialog(DialogUtils.getMainWindow(), (BAMTrack) mainTrack).setVisible(true); } }); menu.add(item); } else if (df == DataFormat.RICH_INTERVAL) { menu.add(new JSeparator()); final JMenuItem bookmarkAll = new JMenuItem("Bookmark All Features"); bookmarkAll.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { DataSource ds = (DataSource) mainTrack.getDataSource(); if (DialogUtils.askYesNo("Bookmark All Features ", String.format("This will create %d bookmarks. Are you sure you want to do this?", ds.getDictionaryCount())) == DialogUtils.YES) { ds.addDictionaryToBookmarks(); Savant.getInstance().displayBookmarksPanel(); } } }); menu.add(bookmarkAll); menu.addMenuListener(new MenuAdapter() { @Override public void menuSelected(MenuEvent me) { bookmarkAll.setEnabled(mainTrack.getDataSource() instanceof DataSource && ((DataSource) mainTrack.getDataSource()).getDictionaryCount() > 0); } }); } return menu; }
From source file:org.broad.igv.util.StringUtils.java
/** * Copy a text string to the clipboard/* ww w . j a v a2 s.c o m*/ * * @param text */ public static void copyTextToClipboard(String text) { StringSelection stringSelection = new StringSelection(text); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(stringSelection, null); }
From source file:org.apache.airavata.xbaya.ui.dialogs.monitor.MonitorWindow.java
private void init() { this.timeTextField = new XBayaTextField(); this.timeTextField.setEditable(false); XBayaLabel timeLabel = new XBayaLabel(EventDataRepository.Column.TIME.getName(), this.timeTextField); this.idTextField = new XBayaTextField(); this.idTextField.setEditable(false); XBayaLabel idLabel = new XBayaLabel(EventDataRepository.Column.ID.getName(), this.idTextField); this.statusTextField = new XBayaTextField(); this.statusTextField.setEditable(false); XBayaLabel statusLabel = new XBayaLabel(EventDataRepository.Column.STATUS.getName(), this.statusTextField); this.messageTextArea = new JEditorPane(XmlConstants.CONTENT_TYPE_HTML, ""); this.messageTextArea.setSize(500, 500); this.messageTextArea.setEditable(false); messageTextArea.setBackground(Color.WHITE); messageTextArea.addHyperlinkListener(new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent event) { if (event.getEventType() == EventType.ACTIVATED) { URL url = event.getURL(); try { BrowserLauncher.openURL(url.toString()); } catch (Exception e) { MonitorWindow.this.xbayaGUI.getErrorWindow().error(MonitorWindow.this.dialog.getDialog(), e.getMessage(), e); }/* w w w.ja va2s .c om*/ } } }); JScrollPane pane = new JScrollPane(messageTextArea); pane.setSize(500, 500); XBayaLabel messageLabel = new XBayaLabel(EventDataRepository.Column.MESSAGE.getName(), pane); GridPanel infoPanel = new GridPanel(); infoPanel.add(timeLabel); infoPanel.add(this.timeTextField); infoPanel.add(idLabel); infoPanel.add(this.idTextField); infoPanel.add(statusLabel); infoPanel.add(this.statusTextField); infoPanel.add(messageLabel); infoPanel.add(pane); infoPanel.layout(4, 2, 3, 1); JButton okButton = new JButton("OK"); okButton.addActionListener(new AbstractAction() { public void actionPerformed(ActionEvent e) { hide(); } }); JButton copyButton = new JButton("Copy to Clipboard"); copyButton.addActionListener(new AbstractAction() { public void actionPerformed(ActionEvent e) { Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(messageText), null); } }); JPanel buttonPanel = new JPanel(); buttonPanel.add(okButton); buttonPanel.add(copyButton); this.dialog = new XBayaDialog(this.xbayaGUI, "Notification", infoPanel, buttonPanel); this.dialog.setDefaultButton(okButton); }
From source file:net.sf.translate64.util.TranslateUtils.java
public static void setClipboardText(String text) { // create a new clipboard instance Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); // set the contents clipboard.setContents(new StringSelection(text), null); }
From source file:UploadUtils.ImgurUpload.java
/** * Copy image link to user's clipboard./* w ww . jav a2s . c o m*/ * This method could be called in onImageLink(String link) to copy the link to the user's clipboard. * @param imgurl the string to copy to the clipboard */ public static void copyToClipBoard(String imgurl) { Toolkit toolkit = Toolkit.getDefaultToolkit(); Clipboard clipboard = toolkit.getSystemClipboard(); StringSelection selection = new StringSelection(imgurl); clipboard.setContents(selection, null); }
From source file:simplesqlformatter.formatter.SQLFormatterEditor.java
private void copyToClipboard(final String copiedSQL) { final StringSelection sql = new StringSelection(copiedSQL); final Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard(); clip.setContents(sql, sql);//from w w w .ja va2 s .c o m }
From source file:org.jetbrains.jet.grammar.GrammarGenerator.java
private static void copyToClipboard(StringBuilder result) { Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(new StringSelection(result.toString()), new ClipboardOwner() { @Override/* w ww . j ava 2 s . c o m*/ public void lostOwnership(Clipboard clipboard, Transferable contents) { } }); }
From source file:uk.nhs.cfh.dsp.srth.desktop.modules.resultexplanationpanel.QueryStatisticsCollectionPanel.java
/** * Creates the statements panel.//from w w w.j a v a 2 s. c om * * @param textArea the text area * @param title the title * * @return the j panel */ private synchronized JPanel createStatementsPanel(final JTextArea textArea, String title) { JPanel panel = new JPanel(new BorderLayout()); panel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(), BorderFactory.createTitledBorder(title))); // create buttons for copy and export JButton copyButton = new JButton(new AbstractAction("Copy") { public void actionPerformed(ActionEvent event) { StringSelection selection = new StringSelection(textArea.getSelectedText()); // get contents of text area and copy to system clipboard Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(selection, QueryStatisticsCollectionPanel.this); } }); JButton exportButton = new JButton(new AbstractAction("Export") { public void actionPerformed(ActionEvent event) { // open a file dialog and export the contents FileDialog fd = new FileDialog(applicationService.getFrameView().getActiveFrame(), "Select file to export to", FileDialog.SAVE); fd.setVisible(true); String fileName = fd.getFile(); String fileDirectory = fd.getDirectory(); if (fileDirectory != null && fileName != null) { File file = new File(fileDirectory, fileName); try { String contents = textArea.getText(); FileWriter fw = new FileWriter(file); fw.flush(); fw.write(contents); fw.close(); // inform user // manager.getStatusMessageLabel().setText("Successfully saved contents to file "+fileName); logger.info("Successfully saved contents to file " + fileName); } catch (IOException e) { logger.warn(e.fillInStackTrace()); // manager.getStatusMessageLabel().setText("Errors saving contents to file "+fileName); } } } }); // create buttons panel JPanel buttonsPanel = new JPanel(); buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.LINE_AXIS)); buttonsPanel.add(Box.createHorizontalStrut(200)); buttonsPanel.add(copyButton); buttonsPanel.add(exportButton); panel.add(buttonsPanel, BorderLayout.SOUTH); panel.add(new JScrollPane(textArea), BorderLayout.CENTER); return panel; }
From source file:org.apache.openmeetings.screenshare.job.RemoteJob.java
private void paste(String charValue) { Clipboard clippy = getDefaultToolkit().getSystemClipboard(); try {/* w w w .j a v a 2s. c om*/ Transferable transferableText = new StringSelection(charValue); clippy.setContents(transferableText, null); if (SystemUtils.IS_OS_MAC) { // Macintosh simulate Insert press(157, 86); } else { // pressing CTRL+V == insert-mode press(KeyEvent.VK_CONTROL, KeyEvent.VK_V); } } catch (Exception e) { log.error("Unexpected exception while pressSpecialSign", e); } }