java.awt.datatransfer.StringSelection Java Examples
The following examples show how to use
java.awt.datatransfer.StringSelection.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InsertRecordDialog.java From netbeans with Apache License 2.0 | 6 votes |
private void copy() { StringBuilder strBuffer = new StringBuilder(); int numcols = insertRecordTableUI.getSelectedColumnCount(); int numrows = insertRecordTableUI.getSelectedRowCount(); int[] rowsselected = insertRecordTableUI.getSelectedRows(); int[] colsselected = insertRecordTableUI.getSelectedColumns(); 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(null, "Invalid Copy Selection", "Invalid Copy Selection", JOptionPane.ERROR_MESSAGE); return; } for (int i = 0; i < numrows; i++) { for (int j = 0; j < numcols; j++) { strBuffer.append(insertRecordTableUI.getValueAt(rowsselected[i], colsselected[j])); if (j < numcols - 1) { strBuffer.append("\t"); } } strBuffer.append("\n"); } StringSelection stringSelection = new StringSelection(strBuffer.toString()); clipBoard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipBoard.setContents(stringSelection, stringSelection); }
Example #2
Source File: DragAction.java From constellation with Apache License 2.0 | 6 votes |
public DraggableButton(final Action action) { super(action); addMouseListener(new MouseAdapter() { @Override public void mousePressed(final MouseEvent event) { getTransferHandler().exportAsDrag(DraggableButton.this, event, TransferHandler.COPY); } }); t = new TransferHandler("graph") { @Override public Transferable createTransferable(final JComponent c) { return new StringSelection("graphSelection"); } }; setTransferHandler(t); source = new DragSource(); source.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_COPY, this); }
Example #3
Source File: BrowserUnavailableDialogFactory.java From rapidminer-studio with GNU Affero General Public License v3.0 | 6 votes |
/** * Creates a Copy Button * * @param text * Text to copy into clipboard * @return */ private static JButton makeCopyButton(String text) { Action copyAction = new ResourceAction(true, "browser_unavailable.copy") { private static final long serialVersionUID = 1L; @Override public void loggedActionPerformed(ActionEvent e) { StringSelection stringSelection = new StringSelection(text); Clipboard clpbrd = Toolkit.getDefaultToolkit().getSystemClipboard(); clpbrd.setContents(stringSelection, null); } }; JButton copyButton = new JButton(copyAction); return copyButton; }
Example #4
Source File: CopyNodeLabelCommand.java From megan-ce with GNU General Public License v3.0 | 6 votes |
public void actionPerformed(ActionEvent event) { ViewerBase viewer = (ViewerBase) getViewer(); StringBuilder buf = new StringBuilder(); boolean first = true; for (String label : viewer.getSelectedNodeLabels(true)) { if (label != null) { if (first) first = false; else buf.append(" "); buf.append(label); } } if (buf.toString().length() > 0) { StringSelection selection = new StringSelection(buf.toString()); Toolkit.getDefaultToolkit().getSystemClipboard().setContents(selection, null); } }
Example #5
Source File: BibtexSearchView.java From slr-toolkit with Eclipse Public License 1.0 | 6 votes |
private void makeActions() { exportKeysAction = new Action() { @Override public void run() { List<Document> docs = (List<Document>) viewer.getInput(); String ret = ""; for (Document d : docs) { ret += d.getKey() + ","; } ret = ret.substring(0, ret.length() - 1); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); StringSelection s = new StringSelection(ret); clipboard.setContents(s, null); System.out.println(ret); } }; exportKeysAction.setText("Copy Keys"); exportKeysAction.setToolTipText("Copy Bibtex Keys to Clipboard"); exportKeysAction.setImageDescriptor( PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_COPY)); IActionBars bars = getViewSite().getActionBars(); bars.getToolBarManager().add(exportKeysAction); }
Example #6
Source File: TestMethodNode.java From netbeans with Apache License 2.0 | 6 votes |
@Override @NbBundle.Messages("LBL_CopyStackTrace=&Copy Stack Trace") public Action[] getActions(boolean context) { List<Action> actions = new ArrayList<Action>(); if ((testcase.getTrouble() != null) && (testcase.getTrouble().getComparisonFailure() != null)){ actions.add(new DiffViewAction(testcase)); } if (testcase.getTrouble() != null && testcase.getTrouble().getStackTrace() != null) { StringBuilder callStack = new StringBuilder(); for(String stack : testcase.getTrouble().getStackTrace()) { if(stack != null) { callStack.append(stack.concat("\n")); } } if (callStack.length() > 0) { final String trace = callStack.toString(); actions.add(new AbstractAction(Bundle.LBL_CopyStackTrace()) { @Override public void actionPerformed(ActionEvent e) { Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(trace), null); } }); } } return actions.toArray(new Action[actions.size()]); }
Example #7
Source File: IPCommand.java From seppuku with GNU General Public License v3.0 | 6 votes |
@Override public void exec(String input) { if (!this.clamp(input, 1, 1)) { this.printUsage(); return; } final Minecraft mc = Minecraft.getMinecraft(); if(mc.getCurrentServerData() != null) { final StringSelection contents = new StringSelection(mc.getCurrentServerData().serverIP); final Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(contents, null); Seppuku.INSTANCE.logChat("Copied IP to clipboard"); }else{ Seppuku.INSTANCE.errorChat("Error, Join a server"); } }
Example #8
Source File: ClipboardHook.java From Spark-Reader with GNU General Public License v3.0 | 6 votes |
public static void setClipBoardAndUpdate(String text) { try { StringSelection selection = new StringSelection(text); Toolkit.getDefaultToolkit().getSystemClipboard().setContents(selection, selection); }catch(IllegalStateException e) { try { Thread.sleep(1); } catch (InterruptedException ignored) {} setClipBoardAndUpdate(text);//try again later } }
Example #9
Source File: NoteTableTab.java From dsworkbench with Apache License 2.0 | 6 votes |
private boolean copyToInternalClipboard() { List<Note> selection = getSelectedNotes(); StringBuilder b = new StringBuilder(); int cnt = 0; for (Note a : selection) { b.append(Note.toInternalRepresentation(a)).append("\n"); cnt++; } try { Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(b.toString()), null); showSuccess(cnt + ((cnt == 1) ? " Notiz kopiert" : " Notizen kopiert")); return true; } catch (HeadlessException hex) { showError("Fehler beim Kopieren der Notizen"); } return false; }
Example #10
Source File: HTMLMinifyClipboard.java From minifierbeans with Apache License 2.0 | 6 votes |
protected final void htmlMinify(final Node[] activatedNodes) { final EditorCookie editorCookie = Utilities.actionsGlobalContext().lookup(EditorCookie.class); for (final JEditorPane pane : editorCookie.getOpenedPanes()) { if (pane.isShowing() && pane.getSelectionEnd() > pane.getSelectionStart()) { try { StringSelection content = new StringSelection(selectedSourceAsMinify(pane)); Toolkit.getDefaultToolkit().getSystemClipboard(). setContents(content, content); return; } catch (final HeadlessException e) { org.openide.ErrorManager.getDefault().notify(e); } } } }
Example #11
Source File: ClientGlobals.java From gepard with MIT License | 6 votes |
public static void unexpectedError(Exception e, Controller ctrl) { // handles any unexpected errors // asks the user to send an error report to the developer String guidump = ctrl.getGUIDump(); String msg; msg = "An unexpected error occured!\nStack trace & GUI details copied to clipboard."; JOptionPane.showMessageDialog(null, msg, "Error", JOptionPane.ERROR_MESSAGE); String report = stack2string(e) + "\n\n\n\n" + guidump; StringSelection stringSelection = new StringSelection (report); Clipboard clpbrd = Toolkit.getDefaultToolkit ().getSystemClipboard (); clpbrd.setContents (stringSelection, null); }
Example #12
Source File: Hk2WSNode.java From netbeans with Apache License 2.0 | 6 votes |
@Override public Transferable clipboardCopy() { String result = ""; PayaraModule commonModule = lu.lookup(PayaraModule.class); if (commonModule != null) { Map<String, String> ip = commonModule.getInstanceProperties(); String host = ip.get(PayaraModule.HTTPHOST_ATTR); if (null == host) { host = ip.get(PayaraModule.HOSTNAME_ATTR); } String httpPort = ip.get(PayaraModule.HTTPPORT_ATTR); String url = ip.get(PayaraModule.URL_ATTR); if (url == null || !url.contains("ee6wc")) { result = Utils.getHttpListenerProtocol(host, httpPort) + "://" + host + ":" + httpPort + "/" + ws.getTestURL(); } else { result = "http" + "://" + host + ":" + httpPort + "/" + ws.getTestURL(); } if (result.endsWith("//")) { result = result.substring(0, result.length() - 1); } } return new StringSelection(result); }
Example #13
Source File: FriendTaggingPlugin.java From plugins with GNU General Public License v3.0 | 5 votes |
/** * This method combines the list of usernames on local players friend/ignore list into a comma delimited string * and then copies it to the clipboard. */ private void friendIgnoreToClipboard() { StringBuilder friendsList = new StringBuilder(); NameableContainer<Friend> friendContainer = client.getFriendContainer(); NameableContainer<Ignore> ignoreContainer = client.getIgnoreContainer(); String[] friendsIgnores = ArrayUtils.addAll(Arrays.stream(friendContainer.getMembers()).map(Nameable::getName).toArray(String[]::new), Arrays.stream(ignoreContainer.getMembers()).map(Nameable::getName).toArray(String[]::new)); HashSet<String> names = new HashSet<>(Arrays.asList(friendsIgnores)); names.forEach(n -> friendsList.append(n.toLowerCase()).append(",")); StringSelection namesSelection = new StringSelection(friendsList.toString()); Toolkit.getDefaultToolkit().getSystemClipboard().setContents(namesSelection, namesSelection); }
Example #14
Source File: BuildFacade.java From setupmaker with Apache License 2.0 | 5 votes |
public void copyToClipboard(Sequence<String> data) { if (data.getLength() > 0) { String selCb = ""; // full selection data string for (int i = 0; i < data.getLength(); i++) { // concat selection with line ends selCb = String.format("%s%s%n", selCb, data.get(i));//selCb += sel.get(i) + "\n"; } Out.print(LOG_LEVEL.DEBUG, "Copied to Clipboard: "+ selCb); StringSelection selection = new StringSelection(selCb); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(selection, selection); } }
Example #15
Source File: DProviderInfo.java From keystore-explorer with GNU General Public License v3.0 | 5 votes |
private void copyPressed() { String info = getNodeContents((TreeNode) jtrProviders.getModel().getRoot(), 0); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); StringSelection copy = new StringSelection(info); clipboard.setContents(copy, copy); }
Example #16
Source File: CopyHandler.java From jeveassets with GNU General Public License v2.0 | 5 votes |
private static void toClipboard(final String text, int retries) { if (text == null) { return; } if (text.length() == 0) { return; } Toolkit toolkit = Toolkit.getDefaultToolkit(); StringSelection selection = new StringSelection(text); Clipboard clipboard = toolkit.getSystemClipboard(); try { clipboard.setContents(selection, null); } catch (IllegalStateException ex) { if (retries < 3) { //Retry 3 times retries++; LOG.info("Retrying copy to clipboard (" + retries + " of 3)" ); try { Thread.sleep(100); } catch (InterruptedException ex1) { //No problem } toClipboard(text, retries); } else { LOG.error(ex.getMessage(), ex); } } }
Example #17
Source File: CopyBlazeTargetPathAction.java From intellij with Apache License 2.0 | 5 votes |
@Override protected void actionPerformedInBlazeProject(Project project, AnActionEvent e) { Label label = findTarget(project, e); if (label != null) { CopyPasteManager.getInstance().setContents(new StringSelection(label.toString())); } }
Example #18
Source File: CopyCommand.java From megan-ce with GNU General Public License v3.0 | 5 votes |
public void actionPerformed(ActionEvent event) { final String selected = ((InspectorWindow) getViewer()).getSelection(); if (selected.length() > 0) { StringSelection selection = new StringSelection(selected); Toolkit.getDefaultToolkit().getSystemClipboard().setContents(selection, null); } }
Example #19
Source File: LinkBrowser.java From launcher with BSD 2-Clause "Simplified" License | 5 votes |
/** * Open swing message box with specified message and copy data to clipboard * @param message message to show */ private static void showMessageBox(final String message, final String data) { SwingUtilities.invokeLater(() -> { final int result = JOptionPane.showConfirmDialog(null, message, "Message", JOptionPane.OK_CANCEL_OPTION); if (result == JOptionPane.OK_OPTION) { final StringSelection stringSelection = new StringSelection(data); Toolkit.getDefaultToolkit().getSystemClipboard().setContents(stringSelection, null); } }); }
Example #20
Source File: DocValuesDialogFactory.java From lucene-solr with Apache License 2.0 | 5 votes |
private void copyValues() { List<String> values = valueList.getSelectedValuesList(); if (values.isEmpty()) { values = getAllVlues(); } Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); StringSelection selection = new StringSelection(String.join("\n", values)); clipboard.setContents(selection, null); }
Example #21
Source File: CodeEditorHandlerThread.java From collect-earth with MIT License | 5 votes |
private void sendThroughClipboard(WebElement textArea, String contents) { Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); StringSelection clipboardtext = new StringSelection(contents); clipboard.setContents(clipboardtext, null); Keys controlChar = Keys.CONTROL; if (SystemUtils.IS_OS_MAC || SystemUtils.IS_OS_MAC_OSX) { controlChar = Keys.COMMAND; } textArea.sendKeys(Keys.chord(controlChar, "a")); textArea.sendKeys(Keys.chord(controlChar, "v")); }
Example #22
Source File: CopyContentAction.java From raccoon4 with Apache License 2.0 | 5 votes |
@Override public void actionPerformed(ActionEvent e) { if (globals.get(Traits.class).isAvailable("4.0.x")) { StringSelection s = new StringSelection(panel.getContentString()); Toolkit.getDefaultToolkit().getSystemClipboard().setContents(s, null); } else { globals.get(LifecycleManager.class).sendBusMessage(new JTextField()); } }
Example #23
Source File: CompositeTableCellRenderer.java From jetbrains-plugin-graph-database-support with Apache License 2.0 | 5 votes |
@Override public void keyReleased(KeyEvent e) { if (e.isControlDown()) { if (e.getKeyCode() == KeyEvent.VK_C) { // Copy List<TreePath> v = Arrays.asList(((Tree) e.getComponent()).getSelectionModel().getSelectionPaths()); String str = SerialisationHelper.convertToCsv(v); StringSelection selection = new StringSelection(str); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(selection, selection); } } }
Example #24
Source File: CapabilityTable.java From arcusplatform with Apache License 2.0 | 5 votes |
protected void copy(int row, Point toastPoint /* mmmmm.... toast points */) { AttributeDefinition definition = model.getValue(row); String name = getAttributeName(definition); Object value = getValue(name); StringSelection selection = new StringSelection(getCopyValue(definition, name, value)); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(selection, null); Toast.showToast(table, "Copied to Clipboard", toastPoint, 1000); }
Example #25
Source File: Lizzie.java From mylizzie with GNU General Public License v3.0 | 5 votes |
public static void copyGameToClipboardInSgf() { try { Game game = snapshotCurrentGame(); String sgfContent = writeSgfToString(game); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); Transferable transferableString = new StringSelection(sgfContent); clipboard.setContents(transferableString, null); } catch (Exception e) { logger.error("Error in copying game to clipboard."); } }
Example #26
Source File: CopySourceAction.java From JHelper with GNU Lesser General Public License v3.0 | 5 votes |
@Override protected void performAction(AnActionEvent e) { Project project = e.getProject(); if (project == null) throw new NotificationException("No project found", "Are you in any project?"); Configurator configurator = project.getComponent(Configurator.class); Configurator.State configuration = configurator.getState(); RunManagerEx runManager = RunManagerEx.getInstanceEx(project); RunnerAndConfigurationSettings selectedConfiguration = runManager.getSelectedConfiguration(); if (selectedConfiguration == null) { return; } RunConfiguration runConfiguration = selectedConfiguration.getConfiguration(); if (!(runConfiguration instanceof TaskConfiguration)) { Notificator.showNotification( "Not a JHelper configuration", "You have to choose JHelper Task to copy", NotificationType.WARNING ); return; } CodeGenerationUtils.generateSubmissionFileForTask(project, (TaskConfiguration)runConfiguration); VirtualFile file = project.getBaseDir().findFileByRelativePath(configuration.getOutputFile()); if (file == null) throw new NotificationException("Couldn't find output file"); Document document = FileDocumentManager.getInstance().getDocument(file); if (document == null) throw new NotificationException("Couldn't open output file"); StringSelection selection = new StringSelection(document.getText()); Toolkit.getDefaultToolkit().getSystemClipboard().setContents(selection, selection); }
Example #27
Source File: SupportRefillSettingsPanel.java From dsworkbench with Apache License 2.0 | 5 votes |
private void copyDefRequests() { REFTargetElement[] selection = getSelectedElements(); if (selection.length == 0) { jStatusLabel.setText("Keine Einträge gewählt"); return; } boolean extended = (JOptionPaneHelper.showQuestionConfirmBox(this, "Erweiterte BB-Codes verwenden (nur für Forum und Notizen geeignet)?", "Erweiterter BB-Code", "Nein", "Ja") == JOptionPane.YES_OPTION); SimpleDateFormat df = new SimpleDateFormat("dd.MM.yy HH:mm:ss"); StringBuilder b = new StringBuilder(); b.append("Ich benötige die aufgelisteten oder vergleichbare Unterstützungen in den folgenden Dörfern:\n\n"); TroopAmountFixed split = splitAmountPanel.getAmounts(); for (REFTargetElement defense : selection) { Village target = defense.getVillage(); int needed = defense.getNeededSupports(); TroopAmountFixed need = new TroopAmountFixed(); for (UnitHolder unit: DataHolder.getSingleton().getUnits()) { need.setAmountForUnit(unit, needed * split.getAmountForUnit(unit)); } if (extended) { b.append("[table]\n"); b.append("[**]").append(target.toBBCode()).append("[|]"); b.append("[img]").append(UnitTableInterface.createDefenderUnitTableLink(need)).append("[/img][/**]\n"); b.append("[/table]\n"); } else { b.append(buildSimpleRequestTable(target, need, defense)); } } try { Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(b.toString()), null); jStatusLabel.setText("Unterstützungsanfragen in die Zwischenablage kopiert"); } catch (HeadlessException hex) { jStatusLabel.setText("Fehler beim Kopieren in die Zwischenablage"); } }
Example #28
Source File: ClipboardKeyAdapter.java From gameserver with Apache License 2.0 | 5 votes |
private void copyToClipboard(boolean isCut) { int numCols = table.getSelectedColumnCount(); int numRows = table.getSelectedRowCount(); int[] rowsSelected = table.getSelectedRows(); int[] colsSelected = table.getSelectedColumns(); if (numRows != rowsSelected[rowsSelected.length - 1] - rowsSelected[0] + 1 || numRows != rowsSelected.length || numCols != colsSelected[colsSelected.length - 1] - colsSelected[0] + 1 || numCols != colsSelected.length) { JOptionPane.showMessageDialog(null, "无效的拷贝", "无效的拷贝", JOptionPane.ERROR_MESSAGE); return; } StringBuffer excelStr = new StringBuffer(); for (int i = 0; i < numRows; i++) { for (int j = 0; j < numCols; j++) { Object value = table.getValueAt(rowsSelected[i], colsSelected[j]); excelStr.append(escape(value)); if (isCut) { table.setValueAt(null, rowsSelected[i], colsSelected[j]); } if (j < numCols - 1) { excelStr.append(CELL_BREAK); } } excelStr.append(LINE_BREAK); } StringSelection sel = new StringSelection(excelStr.toString()); CLIPBOARD.setContents(sel, sel); }
Example #29
Source File: ImageUtils.java From markdown-image-kit with MIT License | 5 votes |
/** * 把文本设置到剪贴板(复制) * * @param text the text */ public static void setStringToClipboard(String text) { // 获取系统剪贴板 Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); // 封装文本内容 Transferable trans = new StringSelection(text); // 把文本内容设置到系统剪贴板 clipboard.setContents(trans, null); }
Example #30
Source File: MainPanel.java From java-swing-tips with MIT License | 5 votes |
protected LabelTransferable(DataFlavor localObjectFlavor, DragPanel panel) { // this.dh = dh; this.localObjectFlavor = localObjectFlavor; this.panel = panel; String txt = panel.draggingLabel.getText(); this.ss = Objects.nonNull(txt) ? new StringSelection(txt + "\n") : null; }