List of usage examples for java.awt.datatransfer StringSelection StringSelection
public StringSelection(String data)
From source file:biz.wolschon.finance.jgnucash.accountProperties.AccountProperties.java
private JPopupMenu createAccountIDPopupMenu() { final JPopupMenu accountIDPopupMenu = new JPopupMenu(); JMenuItem copyAccountIDMenuItem = new JMenuItem("copy"); copyAccountIDMenuItem.addActionListener(new ActionListener() { @Override/*from ww w. j a v a 2s . c om*/ public void actionPerformed(final ActionEvent arg0) { Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(new StringSelection(myAccount.getId()), AccountProperties.this); } }); accountIDPopupMenu.add(copyAccountIDMenuItem); return accountIDPopupMenu; }
From source file:cn.lambdalib.cgui.gui.component.TextBox.java
private void saveClipboardContent() { Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard(); StringSelection ss = new StringSelection(content); cb.setContents(ss, ss);// www . j a v a2s.c o m }
From source file:Good_GUi.java
private void jLabel3MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel3MouseClicked box += "Processing...\n"; jTextArea1.setText(box);// w w w . j a v a 2 s . c om String url = jTextField1.getText(); HttpClient httpClient = new DefaultHttpClient(); try { URIBuilder uriBuilder = new URIBuilder("https://eastus2.api.cognitive.microsoft.com/vision/v1.0/ocr"); uriBuilder.setParameter("language", "unk"); uriBuilder.setParameter("detectOrientation ", "true"); URI uri = uriBuilder.build(); HttpPost request = new HttpPost(uri); // Request headers - replace this example key with your valid subscription key. request.setHeader("Content-Type", "application/json"); request.setHeader("Ocp-Apim-Subscription-Key", "43a031e5db9f438aac7c50a7df692016"); // Request body. Replace the example URL with the URL of a JPEG image containing text. StringEntity requestEntity = new StringEntity("{\"url\":\"" + jTextField1.getText() + "\"}"); request.setEntity(requestEntity); HttpResponse response = httpClient.execute(request); HttpEntity entity = response.getEntity(); String s = EntityUtils.toString(entity); ArrayList<String> list = new ArrayList<>(); if (s.contains("Invalid")) { box += "Can't fetch the image @ " + url + "\n"; jTextArea1.setText(box); } else { System.out.println(s); String[] splitted = s.split("}"); for (String c : splitted) { list.add(c.substring(c.lastIndexOf(":") + 2).replaceAll("\"", "")); } String out = ""; for (int i = 0; i < list.size(); i++) { out += list.get(i) + " "; } out.replaceAll(" ", " "); String x = ""; for (int i = 0; i < out.length(); i++) { x += out.substring(i, i + 1); } try { PrintWriter writer = new PrintWriter("ITT.txt", "UTF-8"); writer.println(x); writer.close(); box += "Success! File saved as ITT.txt\n"; jTextArea1.setText(box); ProcessBuilder pb = new ProcessBuilder("Notepad.exe", "ITT.txt"); pb.start(); } catch (IOException e) { box += e.toString(); jTextArea1.setText(box); } Parser p = new Parser(x); p.parse(); StringSelection stringSelection = new StringSelection(p.toString()); java.awt.datatransfer.Clipboard clpbrd = Toolkit.getDefaultToolkit().getSystemClipboard(); clpbrd.setContents(stringSelection, null); JOptionPane.showMessageDialog(null, "Github data copied to clipboard!"); } } catch (Exception e) { box += e.toString() + "\n"; jTextField1.setText(box); } }
From source file:org.gitools.ui.platform.dialog.ExceptionGlassPane.java
private void copyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_copyButtonActionPerformed StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); pw.println(cause.getMessage());/*from w w w . j a v a 2 s. co m*/ cause.printStackTrace(pw); pw.close(); Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard(); StringSelection ss = new StringSelection(sw.toString()); cb.setContents(ss, ss); }
From source file:org.fhcrc.cpl.viewer.gui.SpectrumComponent.java
protected void copyChartData() { if (null == _chart || null == _spectrum) return;/* w w w. j a v a 2 s .c o m*/ XYPlot xyplot; if (_chart.getPlot() instanceof XYPlot) { xyplot = _chart.getXYPlot(); } else { // UNDONE: return; } ValueAxis domainAxis = xyplot.getDomainAxis(); Range range = domainAxis.getRange(); double min = range.getLowerBound(); double max = range.getUpperBound(); float[] x = _spectrum[0]; float[] y = _spectrum[1]; int start = Arrays.binarySearch(x, (float) min); if (start < 0) start = -(start + 1); int end = Arrays.binarySearch(x, (float) max); if (end < 0) end = -(end + 1); StringBuffer sb = new StringBuffer(20 * (end - start)); for (int i = start; i < end; i++) sb.append(x[i]).append('\t').append(y[i]).append('\n'); StringSelection sel = new StringSelection(sb.toString()); Toolkit.getDefaultToolkit().getSystemClipboard().setContents(sel, sel); }
From source file:ExtendedDnDDemo.java
protected Transferable createTransferable(JComponent c) { return new StringSelection(exportString(c)); }
From source file:org.zanata.page.webtrans.EditorPage.java
/** * Simulate a paste from the user's clipboard into the indicated row * * @param rowIndex//from w w w . j av a2 s . c o m * row to enter text * @param text * text to be entered * @return new EditorPage */ public EditorPage pasteIntoRowAtIndex(final long rowIndex, final String text) { log.info("Paste at {} the text {}", rowIndex, text); WebElement we = readyElement(By.id(String.format(TARGET_ID_FMT, rowIndex, Plurals.SourceSingular.index()))); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(new StringSelection(text), null); we.click(); we.sendKeys(Keys.LEFT_CONTROL + "v"); return new EditorPage(getDriver()); }
From source file:screenieup.MixtapeUpload.java
/** * Copy upload link to clipboard./*from w ww .j a v a2s. co m*/ */ public void copyToClipBoard(String string) { Toolkit toolkit = Toolkit.getDefaultToolkit(); Clipboard clipboard = toolkit.getSystemClipboard(); StringSelection selection = new StringSelection(string); clipboard.setContents(selection, null); System.out.println("Image URL copied to clipboard."); }
From source file:com.jk.framework.util.FakeRunnable.java
/** * Copy to clipboard./*from w ww.j av a 2 s . c o m*/ * * @param aString * String */ public static void copyToClipboard(final String aString) { final StringSelection stringSelection = new StringSelection(aString); final Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(stringSelection, stringSelection); }
From source file:update.updateTest.java
@Test public void buildMainUpdate() throws Exception { String URL = "http://sg-o.de/upd/V8/DecredJWallet.jar"; String Updater = "https://github.com/SG-O/DcrdJGUIUpdater/releases/download/0.1/DcrdUpdater.jar"; String RelativeURL = "DecredJWallet.jar.update"; String RelativeUpdater = "DcrdUpdater.jar"; File temp = File.createTempFile("dcrd", Long.toString(System.nanoTime())); if (!(temp.delete())) { System.out.println("Could not create temp dir"); assertTrue(false);/*from w w w.j av a 2s .c o m*/ return; } if (!(temp.mkdir())) { System.out.println("Could not create temp dir"); assertTrue(false); return; } downloadUpdateItem tmpDow = new downloadUpdateItem("generatedown1.tmp", URL, temp, ""); System.out.println("Downloading1..."); tmpDow.execute(); tmpDow = new downloadUpdateItem("generatedown2.tmp", Updater, temp, ""); System.out.println("Downloading2..."); tmpDow.execute(); System.out.println("Hashing"); String hashResult1 = downloadUpdateItem.hash(new File(temp, "generatedown1.tmp")); String hashResult2 = downloadUpdateItem.hash(new File(temp, "generatedown2.tmp")); FileUtils.deleteDirectory(temp); String message = "[{\"ID\":\"" + RelativeURL + "\",\"type\":1,\"url\":\"" + URL + "\",\"hash\":\"" + hashResult1 + "\"},{\"ID\":\"" + RelativeUpdater + "\",\"type\":1,\"url\":\"" + Updater + "\",\"hash\":\"" + hashResult2 + "\"},{\"relativeSource\":\"\",\"ID\":\"" + RelativeURL + "\",\"relativeDest\":\"" + RelativeURL + "\",\"type\":2},{\"relativeSource\":\"\",\"ID\":\"" + RelativeUpdater + "\",\"relativeDest\":\"" + RelativeUpdater + "\",\"type\":2},{\"ID\":\"" + RelativeUpdater + "\",\"type\":4}]"; String sig = update.signString(message, "D:\\key.der"); JSONArray tmpMes = new JSONArray(message); JSONObject obj = new JSONObject(); obj.put("Commands", tmpMes); obj.put("Signature", sig); System.out.println("Output:"); System.out.println(obj); StringSelection selection = new StringSelection(obj.toString()); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(selection, selection); }