javafx.scene.input.Clipboard Java Examples
The following examples show how to use
javafx.scene.input.Clipboard.
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: OpenLabelerController.java From OpenLabeler with Apache License 2.0 | 6 votes |
private void toClipboard(ObjectModel model) { Clipboard clipboard = Clipboard.getSystemClipboard(); Map<DataFormat, Object> content = new HashMap(); try { Marshaller marshaller = jaxbContext.createMarshaller(); StringWriter writer = new StringWriter(); // output pretty printed marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); marshaller.marshal(model, writer); content.put(DATA_FORMAT_JAXB, writer.toString()); content.put(DataFormat.PLAIN_TEXT, writer.toString()); clipboard.setContent(content); } catch (Exception ex) { LOG.log(Level.WARNING, "Unable to put content to clipboard", ex); } }
Example #2
Source File: SupportInfoPane.java From OpenLabeler with Apache License 2.0 | 6 votes |
public SupportInfoPane() { FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/SupportInfoPane.fxml")); loader.setRoot(this); loader.setController(this); try { loader.load(); } catch (Exception ex) { LOG.log(Level.SEVERE, "Unable to load FXML", ex); } ButtonType copyToClipboard = new ButtonType(bundle.getString("label.copyToClipboard"), ButtonBar.ButtonData.APPLY); getButtonTypes().addAll(copyToClipboard, ButtonType.CLOSE); final Button btn = (Button) lookupButton(copyToClipboard); btn.addEventFilter(ActionEvent.ACTION, event -> { final ClipboardContent content = new ClipboardContent(); content.put(DataFormat.PLAIN_TEXT, text.getText()); Clipboard.getSystemClipboard().setContent(content); event.consume(); }); }
Example #3
Source File: ClipboardHelper.java From openchemlib-js with BSD 3-Clause "New" or "Revised" License | 6 votes |
public static StereoMolecule paste() { StereoMolecule mol = null; // Native clipboard // ClipboardHandler handler = new ClipboardHandler(); // mol = handler.pasteMolecule(); if(mol!=null) { System.out.println("Got molecule from native clipboard"); } else { // JavaFx clipboard final Clipboard clipboard = Clipboard.getSystemClipboard(); mol = readContent(clipboard); if(mol!=null) { System.out.println("Got molecule from standard clipboard"); } } return mol; }
Example #4
Source File: MsSpectrumPlotWindowController.java From old-mzmine3 with GNU General Public License v2.0 | 6 votes |
public void handleCopySpectra(Event event) { StringBuilder sb = new StringBuilder(); for (MsSpectrumDataSet dataset : datasets) { MsSpectrum spectrum = dataset.getSpectrum(); String spectrumString = TxtExportAlgorithm.spectrumToString(spectrum); String splash = SplashCalculationAlgorithm.calculateSplash(spectrum); sb.append("# "); sb.append(dataset.getName()); sb.append("\n"); sb.append("# SPLASH ID: "); sb.append(splash); sb.append("\n"); sb.append(spectrumString); sb.append("\n"); } final Clipboard clipboard = Clipboard.getSystemClipboard(); final ClipboardContent content = new ClipboardContent(); content.putString(sb.toString()); clipboard.setContent(content); }
Example #5
Source File: ItemItemController.java From logbook-kai with MIT License | 6 votes |
/** * 艦隊分析 */ @FXML void kancolleFleetanalysis() { try { List<KancolleFleetanalysisItem> list = SlotItemCollection.get().getSlotitemMap().values().stream() .filter(item -> item.getLocked()) .map(KancolleFleetanalysisItem::toItem) .sorted(Comparator.comparing(KancolleFleetanalysisItem::getId) .thenComparing(Comparator.comparing(KancolleFleetanalysisItem::getLv))) .collect(Collectors.toList()); ObjectMapper mapper = new ObjectMapper(); String input = mapper.writeValueAsString(list); ClipboardContent content = new ClipboardContent(); content.putString(input); Clipboard.getSystemClipboard().setContent(content); } catch (Exception e) { LoggerHolder.get().error("艦隊分析のロック装備をクリップボードにコピーに失敗しました", e); } }
Example #6
Source File: PasteFileAction.java From jmonkeybuilder with Apache License 2.0 | 6 votes |
@Override @FxThread protected void execute(@Nullable ActionEvent event) { super.execute(event); var clipboard = Clipboard.getSystemClipboard(); if (clipboard == null) { return; } List<File> files = unsafeCast(clipboard.getContent(DataFormat.FILES)); if (files == null || files.isEmpty()) { return; } var currentFile = getElement().getFile(); var isCut = "cut".equals(clipboard.getContent(EditorUtil.JAVA_PARAM)); if (isCut) { files.forEach(file -> moveFile(currentFile, file.toPath())); } else { files.forEach(file -> copyFile(currentFile, file.toPath())); } clipboard.clear(); }
Example #7
Source File: LyricsTextArea.java From Quelea with GNU General Public License v3.0 | 6 votes |
public LyricsTextArea() { textArea = new InlineCssTextArea(); ContextMenu contextMenu = new ContextMenu(); Clipboard systemClipboard = Clipboard.getSystemClipboard(); MenuItem paste = new MenuItem(LabelGrabber.INSTANCE.getLabel("paste.label")); contextMenu.setOnShown(e -> { paste.setDisable(!systemClipboard.hasContent(DataFormat.PLAIN_TEXT)); }); paste.setOnAction(e -> { String clipboardText = systemClipboard.getString(); textArea.insertText(textArea.getCaretPosition(), clipboardText); }); contextMenu.getItems().add(paste); textArea.setContextMenu(contextMenu); textArea.textProperty().addListener((ObservableValue<? extends String> observable, String oldValue, String newValue) -> { Platform.runLater(this::refreshStyle); }); textArea.setStyle("-fx-font-family: monospace; -fx-font-size: 10pt;"); textArea.setUndoManager(UndoManagerFactory.zeroHistorySingleChangeUM(textArea.richChanges())); getChildren().add(new VirtualizedScrollPane<>(textArea)); textArea.getStyleClass().add("text-area"); }
Example #8
Source File: RegionBaseRepresentation.java From phoebus with Eclipse Public License 1.0 | 6 votes |
/** Copy PV name to clipboard when middle button clicked * @param event Mouse pressed event */ private void hookMiddleButtonCopy(final MouseEvent event) { if (event.getButton() != MouseButton.MIDDLE) return; final String pv_name = ((PVWidget)model_widget).propPVName().getValue(); // Copy to copy/paste clipboard final ClipboardContent content = new ClipboardContent(); content.putString(pv_name); Clipboard.getSystemClipboard().setContent(content); // Copy to the 'selection' buffer used by X11 // for middle-button copy/paste // Note: This is AWT API! // JavaFX has no API, https://bugs.openjdk.java.net/browse/JDK-8088117 if (Toolkit.getDefaultToolkit().getSystemSelection() != null) Toolkit.getDefaultToolkit().getSystemSelection().setContents(new StringSelection(pv_name), null); }
Example #9
Source File: DisplayEditor.java From phoebus with Eclipse Public License 1.0 | 6 votes |
/** Copy currently selected widgets to clipboard * @return Widgets that were copied or <code>null</code> */ public List<Widget> copyToClipboard() { if (selection_tracker.isInlineEditorActive()) return null; final List<Widget> widgets = selection.getSelection(); if (widgets.isEmpty()) return null; final String xml; try { xml = ModelWriter.getXML(widgets); } catch (Exception ex) { logger.log(Level.WARNING, "Cannot create content for clipboard", ex); return null; } final ClipboardContent content = new ClipboardContent(); content.putString(xml); Clipboard.getSystemClipboard().setContent(content); return widgets; }
Example #10
Source File: LogsView.java From trex-stateless-gui with Apache License 2.0 | 5 votes |
/** * Copy logs to clipboard */ public void copyToClipboard() { final Clipboard clipboard = Clipboard.getSystemClipboard(); final ClipboardContent content = new ClipboardContent(); content.putString(sb.toString()); clipboard.setContent(content); }
Example #11
Source File: ScanCommandDragDrop.java From phoebus with Eclipse Public License 1.0 | 5 votes |
public static List<ScanCommand> getCommands(final Clipboard db) { try { return XMLCommandReader.readXMLString(db.getString()); } catch (Exception ex) { logger.log(Level.WARNING, "Cannot de-serialize commands", ex); } return Collections.emptyList(); }
Example #12
Source File: ThreadElement.java From jstackfx with Apache License 2.0 | 5 votes |
protected void defineContextMenu(final Text text) { final MenuItem copy = new MenuItem("Copy"); copy.setOnAction(event -> { Clipboard.getSystemClipboard().setContent(Collections.singletonMap(DataFormat.PLAIN_TEXT, text.getText())); }); final ContextMenu menu = new ContextMenu(copy); text.setOnContextMenuRequested(event -> { menu.show(text, event.getScreenX(), event.getScreenY()); }); }
Example #13
Source File: UIUtils.java From cute-proxy with BSD 2-Clause "Simplified" License | 5 votes |
/** * Copy text to clipboard */ public static void copyToClipBoard(String text) { Clipboard clipboard = Clipboard.getSystemClipboard(); ClipboardContent content = new ClipboardContent(); content.putString(text); clipboard.setContent(content); }
Example #14
Source File: ShipTablePane.java From logbook-kai with MIT License | 5 votes |
/** * すべての艦をクリップボードにコピーする。 */ public static void copyAll() { ClipboardContent content = new ClipboardContent(); content.putString(text(ShipCollection.get() .getShipMap() .values())); Clipboard.getSystemClipboard().setContent(content); }
Example #15
Source File: CopyFileAction.java From jmonkeybuilder with Apache License 2.0 | 5 votes |
@Override @FxThread protected void execute(@Nullable ActionEvent event) { super.execute(event); var files = getElements().stream() .map(ResourceElement::getFile) .collect(toArray(Path.class)); var clipboard = Clipboard.getSystemClipboard(); clipboard.setContent(EditorUtil.addCopiedFile(files, new ClipboardContent())); }
Example #16
Source File: CopyNodeAction.java From jmonkeybuilder with Apache License 2.0 | 5 votes |
@Override @FxThread protected void process() { super.process(); final TreeNode<?> node = getNode(); final ClipboardContent content = new ClipboardContent(); content.put(DATA_FORMAT, node.getObjectId()); final Clipboard clipboard = Clipboard.getSystemClipboard(); clipboard.setContent(content); }
Example #17
Source File: PasteFiles.java From phoebus with Eclipse Public License 1.0 | 5 votes |
/** @param Node Node for error dialog * @param target_item Item (directory) into which files from clipboard should be copied */ public PasteFiles(final Node node, final TreeItem<FileInfo> target_item) { super(Messages.Paste, ImageCache.getImageView(ImageCache.class, "/icons/paste.png")); setOnAction(event -> { final Clipboard clipboard = Clipboard.getSystemClipboard(); final List<File> files = clipboard.getFiles(); final File directory = target_item.getValue().file; JobManager.schedule(getText(), monitor -> { try { for (File original : files) { FileHelper.copy(original, directory); final File new_file = new File(directory, original.getName()); Platform.runLater(() -> { final ObservableList<TreeItem<FileInfo>> siblings = target_item.getChildren(); siblings.add(new FileTreeItem(((FileTreeItem)target_item).getMonitor(), new_file)); FileTreeItem.sortSiblings(siblings); }); } } catch (Exception ex) { ExceptionDetailsErrorDialog.openError(node, Messages.Paste, "Failed to paste files", ex); } }); }); }
Example #18
Source File: CopyPath.java From phoebus with Eclipse Public License 1.0 | 5 votes |
/** @param items Items which paths to copy to clipboard */ public CopyPath(final List<TreeItem<FileInfo>> items) { super(Messages.CopyPathClp, ImageCache.getImageView(ImageCache.class, "/icons/copy.png")); setOnAction(event -> { final Clipboard clipboard = Clipboard.getSystemClipboard(); final ClipboardContent content = new ClipboardContent(); content.putString(items.stream().map(item -> item.getValue().file.getAbsolutePath()).collect(Collectors.joining(", "))); content.putFiles(items.stream().map(item -> item.getValue().file).collect(Collectors.toList())); clipboard.setContent(content); }); }
Example #19
Source File: CutTextEventHandler.java From jfxvnc with Apache License 2.0 | 5 votes |
public CutTextEventHandler() { Platform.runLater(() -> { clipboard = Clipboard.getSystemClipboard(); clipTask = new Timeline(new KeyFrame(Duration.millis(500), (event) -> { if (clipboard.hasString()) { String newString = clipboard.getString(); if (newString == null) { return; } if (clipTextProperty.get() == null) { clipTextProperty.set(newString); return; } if (newString != null && !clipTextProperty.get().equals(newString)) { fire(new ClientCutText(newString.replace("\r\n", "\n"))); clipTextProperty.set(newString); } } })); clipTask.setCycleCount(Animation.INDEFINITE); }); enabled.addListener((l, o, n) -> Platform.runLater(() -> { if (n) { clipTask.play(); } else { clipTask.stop(); clipTextProperty.set(null); } })); }
Example #20
Source File: GroupResource.java From marathonv5 with Apache License 2.0 | 5 votes |
public void paste(int index, Clipboard clipboard, Operation operation) { if (!clipboard.hasFiles() || !type.droppable(clipboard.getFiles(), getFilePath())) { return; } List<File> files = clipboard.getFiles(); ObservableList<TreeItem<Resource>> cs = getChildren(); for (File file : files) { GroupEntry ge = null; try { if (Constants.isSuiteFile(file)) { ge = new GroupGroupEntry(GroupEntryType.SUITE, file.toPath().toString()); } else if (Constants.isFeatureFile(file)) { ge = new GroupGroupEntry(GroupEntryType.FEATURE, file.toPath().toString()); } else if (Constants.isStoryFile(file)) { ge = new GroupGroupEntry(GroupEntryType.STORY, file.toPath().toString()); } else if (Constants.isIssueFile(file)) { ge = new GroupGroupEntry(GroupEntryType.ISSUE, file.toPath().toString()); } else if (Constants.isTestFile(file)) { ge = getTestEntry(file); } } catch (IOException e) { e.printStackTrace(); continue; } cs.add(index, new GroupEntryResource(ge)); group.getEntries().add(index, ge); index++; } try { Group.updateFile(group); } catch (IOException e1) { e1.printStackTrace(); } Event.fireEvent(this, new ResourceModificationEvent(ResourceModificationEvent.UPDATE, this)); return; }
Example #21
Source File: ExceptionController.java From BetonQuest-Editor with GNU General Public License v3.0 | 5 votes |
@FXML private void copy() { try { Clipboard clipboard = Clipboard.getSystemClipboard(); ClipboardContent content = new ClipboardContent(); String string = stackTrace.getText(); // add 4 spaces before each line so when pasted on GitHub it's formatted as code content.putString(" " + string.replace("\n", "\n ").trim()); clipboard.setContent(content); } catch (Exception e) { ExceptionController.display(e); } }
Example #22
Source File: SamplePage.java From javamoney-examples with Apache License 2.0 | 5 votes |
public void initView() { try { // check if 3d sample and on supported platform loadCode(); // create code view WebView webView = getWebView(); webView.setPrefWidth(300); engine.loadContent(htmlCode); ToolBar codeToolBar = new ToolBar(); codeToolBar.setId("code-tool-bar"); Button copyCodeButton = new Button("Copy Source"); copyCodeButton.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent actionEvent) { Map<DataFormat, Object> clipboardContent = new HashMap<DataFormat, Object>(); clipboardContent.put(DataFormat.PLAIN_TEXT, rawCode); clipboardContent.put(DataFormat.HTML, htmlCode); Clipboard.getSystemClipboard().setContent(clipboardContent); } }); codeToolBar.getItems().addAll(copyCodeButton); setTop(codeToolBar); setCenter(webView); } catch (Exception e) { e.printStackTrace(); setCenter(new Text("Failed to create sample because of [" + e.getMessage() + "]")); } }
Example #23
Source File: ScanCommandTree.java From phoebus with Eclipse Public License 1.0 | 5 votes |
/** Copy selected commands to clipboard */ List<ScanCommand> copyToClipboard() { final Clipboard clip = Clipboard.getSystemClipboard(); final List<ScanCommand> copied = getSelectedCommands(); clip.setContent(ScanCommandDragDrop.createClipboardContent(copied)); return copied; }
Example #24
Source File: CopyPropertiesAction.java From phoebus with Eclipse Public License 1.0 | 5 votes |
private void selectPropertiesToCopy(final Node parent, final Widget widget) { final SelectWidgetPropertiesDialog dialog = new SelectWidgetPropertiesDialog(widget); DialogHelper.positionDialog(dialog, parent, -200, -400); final Optional<List<WidgetProperty<?>>> result = dialog.showAndWait(); if (! result.isPresent()) return; final List<WidgetProperty<?>> properties = result.get(); if (properties.isEmpty()) return; // Place XML for selected properties on clipboard try { final ByteArrayOutputStream buf = new ByteArrayOutputStream(); final ModelWriter model_writer = new ModelWriter(buf); model_writer.getWriter().writeStartElement("properties"); for (WidgetProperty<?> prop : properties) model_writer.writeProperty(prop); model_writer.getWriter().writeEndElement(); model_writer.close(); final String xml = buf.toString(); final ClipboardContent content = new ClipboardContent(); content.putString(xml); Clipboard.getSystemClipboard().setContent(content); } catch (Exception ex) { ExceptionDetailsErrorDialog.openError("Copy Properties", "Cannot copy properties", ex); } }
Example #25
Source File: BrowsableDirectoryFieldUITest.java From pdfsam with GNU Affero General Public License v3.0 | 5 votes |
@Test public void copyPasteInQuotes() { WaitForAsyncUtils.waitForAsyncFx(2000, () -> { Clipboard clipboard = Clipboard.getSystemClipboard(); ClipboardContent content = new ClipboardContent(); content.putString("\"my path\""); clipboard.setContent(content); }); BrowsableDirectoryField victim = lookup(".victim-blank").queryAs(BrowsableDirectoryField.class); clickOn(victim); press(KeyCode.CONTROL, KeyCode.V).release(KeyCode.V, KeyCode.CONTROL); FxAssert.verifyThat(victim, v -> v.getTextField().getText().equals("my path")); }
Example #26
Source File: PastePropertiesAction.java From phoebus with Eclipse Public License 1.0 | 5 votes |
private boolean clipboardHasProperties() { final String xml = Clipboard.getSystemClipboard().getString(); if (xml == null) return false; return xml.contains("<display") && xml.contains("<properties>"); }
Example #27
Source File: JFreeChartUtils.java From old-mzmine3 with GNU General Public License v2.0 | 5 votes |
public static void exportToClipboard(ChartViewer chartNode) { final Clipboard clipboard = Clipboard.getSystemClipboard(); final ClipboardContent content = new ClipboardContent(); final int width = (int) chartNode.getWidth(); final int height = (int) chartNode.getHeight(); WritableImage img = new WritableImage(width, height); SnapshotParameters params = new SnapshotParameters(); chartNode.snapshot(params, img); content.putImage(img); clipboard.setContent(content); }
Example #28
Source File: EditorFrame.java From JetUML with GNU General Public License v3.0 | 5 votes |
/** * Copies the current image to the clipboard. */ public void copyToClipboard() { DiagramTab frame = getSelectedDiagramTab(); final Image image = ImageCreator.createImage(frame.getDiagram()); final Clipboard clipboard = Clipboard.getSystemClipboard(); final ClipboardContent content = new ClipboardContent(); content.putImage(image); clipboard.setContent(content); Alert alert = new Alert(AlertType.INFORMATION, RESOURCES.getString("dialog.to_clipboard.message"), ButtonType.OK); alert.initOwner(aMainStage); alert.setHeaderText(RESOURCES.getString("dialog.to_clipboard.title")); alert.showAndWait(); }
Example #29
Source File: ClipboardHelper.java From openchemlib-js with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static List<DataFormat> getAcceptedFormats(Clipboard clipboard) { Set<DataFormat> formats = clipboard.getContentTypes(); List<DataFormat> res = new ArrayList<DataFormat>(); for (DataFormat dataFormat : MoleculeDataFormats.DATA_FORMATS) { for (DataFormat f : formats) { if (f.equals(dataFormat)) { res.add(f); break; } } } return res; }
Example #30
Source File: LRInspectorViewer.java From megan-ce with GNU General Public License v3.0 | 5 votes |
/** * copy all selected alignments */ public void copy() { final String selection = getSelection(dir.getDocument().getProgressListener()); Platform.runLater(() -> { final Clipboard clipboard = Clipboard.getSystemClipboard(); final ClipboardContent content = new ClipboardContent(); content.putString(selection); clipboard.setContent(content); }); }