@Override public void actionPerformed(ActionEvent e) { File f = FileUtil.toFile( matchingObject.getFileObject()); if (f != null) { String path = f.getPath(); Clipboard clipboard = Lookup.getDefault().lookup( ExClipboard.class); if (clipboard == null) { Toolkit toolkit = Toolkit.getDefaultToolkit(); if (toolkit != null) { clipboard = toolkit.getSystemClipboard(); } } if (clipboard != null) { StringSelection strSel = new StringSelection(path); clipboard.setContents(strSel, null); } } }
private static void makeSureSystemClipboardContainsString( Clipboard sys, NbClipboard clip ) throws InterruptedException { final CountDownLatch wait = new CountDownLatch(1); class FL implements FlavorListener { @Override public void flavorsChanged(FlavorEvent e) { wait.countDown(); } } FL fl = new FL(); sys.addFlavorListener(fl); StringSelection ss = new StringSelection("empty"); clip.setContents(ss, ss); wait.await(); }
public void testClipboard() throws Exception { MockServices.setServices(Cnv.class); Clipboard c = Lookup.getDefault().lookup(Clipboard.class); ExClipboard ec = Lookup.getDefault().lookup(ExClipboard.class); assertEquals("Clipboard == ExClipboard", c, ec); assertNotNull(Lookup.getDefault().lookup(ExClipboard.Convertor.class)); assertEquals(Cnv.class, Lookup.getDefault().lookup(ExClipboard.Convertor.class).getClass()); c.setContents(new ExTransferable.Single(DataFlavor.stringFlavor) { protected Object getData() throws IOException, UnsupportedFlavorException { return "17"; } }, null); Transferable t = c.getContents(null); assertTrue("still supports stringFlavor", t.isDataFlavorSupported(DataFlavor.stringFlavor)); assertEquals("correct string in clipboard", "17", t.getTransferData(DataFlavor.stringFlavor)); assertTrue("support Integer too", t.isDataFlavorSupported(MYFLAV)); assertEquals("correct Integer", new Integer(17), t.getTransferData(MYFLAV)); }
public void testOwnershipLostEvent() throws Exception { final int[] holder = new int[] { 0 }; ExTransferable transferable = ExTransferable.create (new StringSelection("A")); // listen on ownershipLost transferable.addTransferListener (new TransferListener () { public void accepted (int action) {} public void rejected () {} public void ownershipLost () { holder[0]++; } }); Clipboard c = Lookup.getDefault().lookup(Clipboard.class); c.setContents(transferable, null); assertTrue("Still has ownership", holder[0] == 0); c.setContents(new StringSelection("B"), null); assertTrue("Exactly one ownershipLost event have happened.", holder[0] == 1); }
void paste() throws IOException { Clipboard clip = java.awt.Toolkit.getDefaultToolkit().getSystemClipboard(); Transferable contents = clip.getContents(this); DataFlavor[] flavors = contents.getTransferDataFlavors(); for( int k=0 ; k<flavors.length ; k++) { try { if( flavors[k].getHumanPresentableName().indexOf("html")>=0 )continue; BufferedReader in = new BufferedReader( flavors[k].getReaderForText(contents)); System.out.println( flavors[k].getHumanPresentableName()); read( in ); break; } catch( UnsupportedFlavorException e) { } } }
static void stackToCLBD(List<JPDAThread> threads) { StringBuffer frameStr = new StringBuffer(512); for (JPDAThread t : threads) { if (frameStr.length() > 0) { frameStr.append('\n'); } frameStr.append("\""); frameStr.append(t.getName()); frameStr.append("\"\n"); appendStackInfo(frameStr, t); } Clipboard systemClipboard = getClipboard(); Transferable transferableText = new StringSelection(frameStr.toString()); systemClipboard.setContents( transferableText, null); }
/** * Description of the Method * * @param before Description of the Parameter * @return Description of the Return Value */ public int insertRows(boolean before) { int startRow = before ? getSelectionModel().getMinSelectionIndex() : getSelectionModel().getMaxSelectionIndex(); if (startRow < 0) { return 0; } if (startRow == 0) { before = false; } String trstring = null; try { Clipboard system = Toolkit.getDefaultToolkit().getSystemClipboard(); trstring = (String) (system.getContents(this) .getTransferData(DataFlavor.stringFlavor)); } catch (Exception e) { return 0; } ; return insertRowsAt(trstring, startRow, before); }
private void doCopy(ExplorerManager em) { Node[] sel = em.getSelectedNodes(); Transferable trans = ExplorerActionsImpl.getTransferableOwner(sel, true); Transferable ot = new OutlineTransferHandler().createOutlineTransferable(); if (trans != null) { if (ot != null) { trans = new TextAddedTransferable(trans, ot); } } else { trans = ot; } if (trans != null) { Clipboard clipboard = ExplorerActionsImpl.getClipboard(); if (clipboard != null) { clipboard.setContents(trans, new StringSelection("")); // NOI18N } } }
public void copy() { Caret caret = editor.getCaret(); long p0 = caret.getMark(); long p1 = caret.getDot(); if (p0 < 0 || p1 < 0) return; if (p0 > p1) { long t = p0; p0 = p1; p1 = t; } p1++; int[] data = new int[(int) (p1 - p0)]; HexModel model = editor.getModel(); for (long i = p0; i < p1; i++) { data[(int) (i - p0)] = model.get(i); } Clipboard clip = editor.getToolkit().getSystemClipboard(); clip.setContents(new Data(data), this); }
/** * Sets the clipboard context in textual-format. * * @param content */ @Messages({ "# {0} - copied file path", "CTL_Status_CopyToClipboardSingle=Copy to Clipboard: {0}", "# {0} - number of copied paths", "CTL_Status_CopyToClipboardMulti={0} paths were copied to clipboard" }) private void setClipboardContents(String content, int items) { Clipboard clipboard = Lookup.getDefault().lookup(ExClipboard.class); if (clipboard == null) { clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); } if (clipboard != null) { String statusText = items > 1 ? Bundle.CTL_Status_CopyToClipboardMulti(items) : Bundle.CTL_Status_CopyToClipboardSingle(content); StatusDisplayer.getDefault().setStatusText(statusText); clipboard.setContents(new StringSelection(content), null); } }
public CopySVGMenuItem(final FlagFrame frame) { setText("Copy SVG"); if (!OSUtils.isMacOS()) setMnemonic(KeyEvent.VK_S); setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputUtils.META_SHIFT_MASK)); if (frame == null) { setEnabled(false); } else { addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { SVGExporter s = new SVGExporter(frame.getFlagFile(), frame.getFlag()); String svg = s.exportToString(frame.getViewerWidth(), frame.getViewerHeight(), frame.getGlaze()); StringSelection ss = new StringSelection(svg); Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard(); cb.setContents(ss, ss); } }); } }
private void doPaste() { Clipboard clip = java.awt.Toolkit.getDefaultToolkit().getSystemClipboard(); try { Transferable content = clip.getContents(this); if (content == null) return; String txt = content .getTransferData(new DataFlavor(String.class, "String")) .toString(); document.replace( editor.getSelectionStart(), editor.getSelectionEnd() - editor.getSelectionStart(), txt, editorKit.getInputAttributes()); //editor.replaceSelection(content.getTransferData(new // DataFlavor(String.class, "String")).toString()); //editor.paste(); //insertHTML(content.getTransferData(new DataFlavor(String.class, // "String")).toString(), editor.getCaretPosition()); /* * Element el = * document.getParagraphElement(editor.getCaretPosition()); * insertTextInElement(el, content.getTransferData(new * DataFlavor(String.class, "String")).toString(), */ } catch (Exception ex) { ex.printStackTrace(); } }
NbClipboard( Clipboard systemClipboard ) { super("NBClipboard"); // NOI18N this.systemClipboard = systemClipboard; result = Lookup.getDefault().lookupResult(ExClipboard.Convertor.class); result.addLookupListener(this); systemClipboard.addFlavorListener(this); resultChanged(null); if (System.getProperty("netbeans.slow.system.clipboard.hack") != null) { slowSystemClipboard = Boolean.getBoolean("netbeans.slow.system.clipboard.hack"); // NOI18N } else if (Utilities.isMac()) { slowSystemClipboard = false; } else { slowSystemClipboard = true; } if (System.getProperty("sun.awt.datatransfer.timeout") == null) { // NOI18N System.setProperty("sun.awt.datatransfer.timeout", "1000"); // NOI18N } if (slowSystemClipboard) { Toolkit.getDefaultToolkit().addAWTEventListener( this, AWTEvent.WINDOW_EVENT_MASK); } }
@Override public Clipboard getSystemSelection() { SecurityManager security = System.getSecurityManager(); if (security != null) { security.checkPermission(AWTPermissions.ACCESS_CLIPBOARD_PERMISSION); } synchronized (this) { if (selection == null) { selection = new XClipboard("Selection", "PRIMARY"); } } return selection; }
private void doCopy() { /* * java.awt.datatransfer.Clipboard clip = * java.awt.Toolkit.getDefaultToolkit().getSystemClipboard(); try { * String text = editor.getSelectedText(); * //.getText(editor.getSelectionStart(), * editor.getSelectionEnd()-editor.getSelectionStart()); * clip.setContents(new java.awt.datatransfer.StringSelection(text), * null); } catch (Exception e) { e.printStackTrace(); */ Element el = document.getParagraphElement(editor.getSelectionStart()); if (el.getName().toUpperCase().equals("P-IMPLIED")) el = el.getParentElement(); String elName = el.getName(); StringWriter sw = new StringWriter(); String copy; java.awt.datatransfer.Clipboard clip = java.awt.Toolkit.getDefaultToolkit().getSystemClipboard(); try { editorKit.write( sw, document, editor.getSelectionStart(), editor.getSelectionEnd() - editor.getSelectionStart()); copy = sw.toString(); copy = copy.split("<" + elName + "(.*?)>")[1]; copy = copy.split("</" + elName + ">")[0]; clip.setContents( new java.awt.datatransfer.StringSelection(copy.trim()), null); } catch (Exception ex) { ex.printStackTrace(); } }
static Clipboard getClipboard() { Clipboard clipboard = org.openide.util.Lookup.getDefault().lookup(Clipboard.class); if (clipboard == null) { clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); } return clipboard; }
private void stackToCLBD() { JPDAThread t = debugger.getCurrentThread(); if (t == null) return ; StringBuffer frameStr = new StringBuffer(50); DebuggingActionsProvider.appendStackInfo(frameStr, t); Clipboard systemClipboard = DebuggingActionsProvider.getClipboard(); Transferable transferableText = new StringSelection(frameStr.toString()); systemClipboard.setContents( transferableText, null); }
private void updateSystemSelection() { if(component == null) return; Clipboard clip = null; try { clip = component.getToolkit().getSystemSelection(); } catch (SecurityException ex) { // XXX: ignore for now, there is no ExClipboard for SystemSelection Clipboard } if(clip != null) { StringBuilder builder = new StringBuilder(); boolean first = true; List<CaretInfo> sortedCarets = getSortedCarets(); for (CaretInfo caret : sortedCarets) { CaretItem caretItem = caret.getCaretItem(); if(caretItem.isSelection()) { if(!first) { builder.append("\n"); } else { first = false; } builder.append(getSelectedText(caretItem)); } } if(builder.length() > 0) { clip.setContents(new java.awt.datatransfer.StringSelection(builder.toString()), null); } } }
public void do_Copy_trace() { if (spikeTimesRecord != null) { StringBuilder sb = new StringBuilder(); sb.append(recordedMinTime+"\t0\n"); for (int i : spikeTimesRecord) { sb.append(i+"\t0\n"+i+"\t100\n"+i+"\t0\n"); } sb.append(recordedMaxTime+"\t0\n"); Toolkit toolkit = Toolkit.getDefaultToolkit(); Clipboard clipboard = toolkit.getSystemClipboard(); StringSelection strSel = new StringSelection(sb.toString()); clipboard.setContents(strSel, null); } }
/** If our clipboard is not found return the default system clipboard. */ public static Clipboard getClipboard() { if (GraphicsEnvironment.isHeadless()) { return null; } Clipboard c = Lookup.getDefault().lookup(Clipboard.class); if (c == null) { c = Toolkit.getDefaultToolkit().getSystemClipboard(); } return c; }
private void registerListener() { if (flavL == null) { Clipboard c = getClipboard(); if (c != null) { flavL = WeakListeners.create(FlavorListener.class, this, c); c.addFlavorListener(flavL); } } }
/** If our clipboard is not found return the default system clipboard. */ private static Clipboard getClipboard() { Clipboard c = Lookup.getDefault().lookup(Clipboard.class); if (c == null) { c = Toolkit.getDefaultToolkit().getSystemClipboard(); } return c; }
private static Clipboard getClipboard() { Clipboard clipboard = Lookup.getDefault().lookup(ExClipboard.class); if (clipboard == null) { clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); } return clipboard; }
@Override public Clipboard getSystemClipboard() { SecurityManager security = System.getSecurityManager(); if (security != null) { security.checkPermission(SecurityConstants.AWT.ACCESS_CLIPBOARD_PERMISSION); } synchronized (this) { if (clipboard == null) { clipboard = new WClipboard(); } } return clipboard; }
private ActiveTerm createActiveTerminal() { Clipboard aSystemClipboard = Lookup.getDefault().lookup(Clipboard.class); if (aSystemClipboard == null) { aSystemClipboard = getToolkit().getSystemClipboard(); } return new MyActiveTerm(aSystemClipboard); }
public void actionPerformed(ActionEvent e) { int row = table.getSelectedRow(); if (row < 0) return; AddressBookEntry entry = entries.get(row); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(new StringSelection(entry.address), null); }
/** * Gets an image from Clipboard. * * @return image */ public static Image getClipboardImage() { Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); try { return (Image) clipboard.getData(DataFlavor.imageFlavor); } catch (Exception e) { return null; } }
private void doPaste() { Clipboard clip = java.awt.Toolkit.getDefaultToolkit().getSystemClipboard(); try { Transferable content = clip.getContents(this); if (content == null) { return; } String txt = content .getTransferData(new DataFlavor(String.class, "String")) .toString(); document.replace( editor.getSelectionStart(), editor.getSelectionEnd() - editor.getSelectionStart(), txt, editorKit.getInputAttributes()); //editor.replaceSelection(content.getTransferData(new // DataFlavor(String.class, "String")).toString()); //editor.paste(); //insertHTML(content.getTransferData(new DataFlavor(String.class, // "String")).toString(), editor.getCaretPosition()); /* * Element el = * document.getParagraphElement(editor.getCaretPosition()); * insertTextInElement(el, content.getTransferData(new * DataFlavor(String.class, "String")).toString(), */ } catch (Exception ex) { ex.printStackTrace(); } }
public Clipboard getSystemSelection() { SecurityManager security = System.getSecurityManager(); if (security != null) { security.checkPermission(SecurityConstants.AWT.ACCESS_CLIPBOARD_PERMISSION); } synchronized (this) { if (selection == null) { selection = new XClipboard("Selection", "PRIMARY"); } } return selection; }
public void copy() { StringBuffer sb = new StringBuffer(); sb.append(tempInfo); Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard(); String tempString = sb.toString(); tempString = tempString.replaceAll("zoom.+",""); tempString = tempString.replaceAll("[\\(\\)=,\\w&&[^WESN\\d]]+",""); String [] result = tempString.split("\\s+"); tempString = ""; for ( int i =0; i < result.length; i++ ) { if ( result[i].indexOf("\u00B0") != -1 && result[i].indexOf("\u00B4") == -1 ) { result[i] = result[i].replaceAll("\\u00B0",""); } if ( i == 2 ) { if ( result[i].indexOf("W") != -1 ) { result[i] = "-" + result[i]; } result[i] = result[i].replaceAll("[WE]",""); } else if ( i == 3 ) { if ( result[i].indexOf("S") != -1 ) { result[i] = "-" + result[i]; } result[i] = result[i].replaceAll("[NS]",""); } tempString += result[i] + "\t"; } tempString = tempString.trim(); tempString = line.getCruiseID().trim() + "\t" + line.getID().trim() + "\t" + currentTime/1000.0 + "\t" + currentCDP + "\t" + tempString; StringSelection ss = new StringSelection(tempString + "\n"); c.setContents(ss, ss); }
/** * Gets called when the mouse was released on a Swing component * that has this object as a MouseListener. * * @param e The event that holds the information about the mouse click. */ @Override public void mouseReleased(MouseEvent e) { Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); Transferable clipData = clipboard.getContents(clipboard); if (clipData != null) { if (clipData.isDataFlavorSupported(DefaultTransferHandler.flavor)) { JComponent comp = (JComponent)e.getSource(); TransferHandler handler = comp.getTransferHandler(); handler.importData(comp, clipData); } } }
/** * This method puts the value of 'toClipboard' to the clipboard * In case of an SQL-Error, the SQL-Statement will be placed in * such a way and can be used in an external application as well. * @param toClipboard String which will be placed in the clipboard */ public void put2Clipboard(String toClipboard) { if (Application.isOperatingHeadless()==false) { // --- Only in case that Agent.GUI is operated with graphical representation ------ StringSelection data = new StringSelection(toClipboard); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(data, data); } }
/** * Copies the current chart to the system clipboard. * * @since 1.0.13 */ @Override public void doCopy() { Clipboard systemClipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); Insets insets = getInsets(); int w = getWidth() - insets.left - insets.right; int h = getHeight() - insets.top - insets.bottom; ChartTransferable selection = new ChartTransferable(this.chart, w, h); systemClipboard.setContents(selection, null); }
/** * Copies the current chart to the system clipboard. */ public static synchronized void copyChart(final JFreeChartPlotEngine engine) { Clipboard systemClipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); Insets insets = engine.getChartPanel().getInsets(); int w = engine.getChartPanel().getWidth() - insets.left - insets.right; int h = engine.getChartPanel().getHeight() - insets.top - insets.bottom; BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = img.createGraphics(); engine.getChartPanel().print(g2); g2.dispose(); systemClipboard.setContents(new TransferableImage(img), null); }
private String getLicenseKeyFromClipboard() { Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); try { String licenseFromClipboard = (String)clipboard.getData(DataFlavor.stringFlavor); if(ProductConstraintManager.INSTANCE.isLicenseValid(licenseFromClipboard)) { return licenseFromClipboard; } } catch (Exception var3) { ; } return null; }
private void copyLogs() { JTextArea textArea = service.docket.execute("featurea.scada.ide.modbusLogs.textArea"); String text = textArea.getText(); StringSelection stringSelection = new StringSelection(text); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(stringSelection, null); }