List of usage examples for java.awt.datatransfer StringSelection StringSelection
public StringSelection(String data)
From source file:org.gitools.ui.app.actions.data.CopyToClipboardSelectedLabelHeaderAction.java
@Override public void actionPerformed(ActionEvent e) { if (header == null) { return;/*from w ww . ja v a 2 s . co m*/ } StringBuilder content = new StringBuilder(); HeatmapDimension dimension = header.getHeatmapDimension(); for (String label : transform(filter(dimension, in(dimension.getSelected())), header.getIdentifierTransform())) { if (!isEmpty(label)) { content.append(label).append('\n'); } } Clipboard clipBoard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipBoard.setContents(new StringSelection(content.toString()), null); }
From source file:Main.java
@Override protected Transferable createTransferable(JComponent source) { JList<String> sourceList = (JList<String>) source; String data = sourceList.getSelectedValue(); Transferable t = new StringSelection(data); return t;//from ww w.j ava 2s . c o m }
From source file:io.neocdtv.simpleplayer.ui.PlaylistTransferHandler.java
@Override protected Transferable createTransferable(JComponent c) { return new StringSelection(exportString(c)); }
From source file:org.kuali.test.ui.base.BaseTable.java
/** * * @param config// ww w. j a v a 2 s . c om */ public BaseTable(TableConfiguration config) { super(new BaseTableModel(config)); for (int i = 0; i < config.getHeaders().length; ++i) { int cx = getColumnWidth(i); getColumnModel().getColumn(i).setWidth(cx); getColumnModel().getColumn(i).setPreferredWidth(cx); } getTableHeader().setReorderingAllowed(false); setShowHorizontalLines(true); setShowVerticalLines(true); setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN); popupMenu = new JPopupMenu(); JMenuItem m; popupMenu.add(m = new JMenuItem(Constants.COPY_ACTION)); m.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(new StringSelection(celldata), BaseTable.this); celldata = null; } }); MouseAdapter ma = new MouseAdapter() { private void myPopupEvent(MouseEvent e) { int col = BaseTable.this.columnAtPoint(e.getPoint()); int row = BaseTable.this.rowAtPoint(e.getPoint()); if ((col > -1) && (row > -1)) { if (BaseTable.this.getValueAt(row, col) != null) { celldata = BaseTable.this.getValueAt(row, col).toString(); popupMenu.show(BaseTable.this.getComponentAt(e.getX(), e.getY()), e.getX(), e.getY()); } } } @Override public void mousePressed(MouseEvent e) { if (e.isPopupTrigger()) { myPopupEvent(e); } } @Override public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger()) { myPopupEvent(e); } } }; addMouseListener(ma); initializing = false; }
From source file:TextTransferTest.java
/** * Copies the selected text to the system clipboard. *///from w w w .ja v a 2s. c om private void copy() { Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); String text = textArea.getSelectedText(); if (text == null) text = textArea.getText(); StringSelection selection = new StringSelection(text); clipboard.setContents(selection, null); }
From source file:net.sf.jabref.gui.fieldeditors.PreviewPanelTransferHandler.java
@Override protected Transferable createTransferable(JComponent component) { if (component instanceof JEditorPane) { // this method should be called from the preview panel only // the default TransferHandler implementation is aware of HTML // and returns an appropriate Transferable // as textTransferHandler.createTransferable() is not available and // I don't know any other method, I do the HTML conversion by hand // First, get the HTML of the selected text JEditorPane editorPane = (JEditorPane) component; StringWriter stringWriter = new StringWriter(); try {/* ww w .jav a 2s. c o m*/ editorPane.getEditorKit().write(stringWriter, editorPane.getDocument(), editorPane.getSelectionStart(), editorPane.getSelectionEnd()); } catch (BadLocationException | IOException e) { LOGGER.warn("Cannot write preview", e); } // Second, return the HTML (and text as fallback) return new HtmlTransferable(stringWriter.toString(), editorPane.getSelectedText()); } else { // if not called from the preview panel, return an error string return new StringSelection(Localization.lang("Operation not supported")); } }
From source file:corelyzer.util.StringUtility.java
public static void setClipboard(final String aString) { StringSelection stringSelection = new StringSelection(aString); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(stringSelection, new ClipboardOwner() { public void lostOwnership(final Clipboard clipboard, final Transferable transferable) { // do nothing }/*from w w w . j a v a2s . c om*/ }); }
From source file:Main.java
public void dragGestureRecognized(DragGestureEvent e) { try {/* ww w .ja v a 2s .c om*/ Transferable t = new StringSelection(getText()); e.startDrag(DragSource.DefaultCopyNoDrop, t, this); } catch (InvalidDnDOperationException e2) { System.out.println(e2); } }
From source file:org.datavyu.util.UIUtils.java
/** * "Copies" str to the clipboard.//from w w w . ja v a2 s . c om * @param str String to copy */ public static void setClipboard(final String str) { StringSelection ss = new StringSelection(str); Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, null); }
From source file:DNDList.java
/** * a drag gesture has been initiated/* w w w .j ava 2 s .com*/ * */ public void dragGestureRecognized(DragGestureEvent event) { Object selected = getSelectedValue(); if (selected != null) { StringSelection text = new StringSelection(selected.toString()); // as the name suggests, starts the dragging dragSource.startDrag(event, DragSource.DefaultMoveDrop, text, this); } else { System.out.println("nothing was selected"); } }