List of usage examples for javafx.scene.input ClipboardContent putString
public final boolean putString(String s)
From source file:wo.trade.Util.java
public static void copyToClipboard(String str) { Clipboard clipboard = Clipboard.getSystemClipboard(); final ClipboardContent content = new ClipboardContent(); content.putString(str); clipboard.setContent(content);/*from w w w. j a va 2s . c o m*/ }
From source file:io.bitsquare.common.util.Utilities.java
public static void copyToClipboard(String content) { try {//from w ww.j a v a2 s . co m if (content != null && content.length() > 0) { Clipboard clipboard = Clipboard.getSystemClipboard(); ClipboardContent clipboardContent = new ClipboardContent(); clipboardContent.putString(content); clipboard.setContent(clipboardContent); } } catch (Throwable e) { log.error("copyToClipboard failed " + e.getMessage()); e.printStackTrace(); } }
From source file:Main.java
@Override public void start(Stage primaryStage) { primaryStage.setTitle("Text Fonts"); Group root = new Group(); Scene scene = new Scene(root, 550, 250, Color.web("0x0000FF")); final Clipboard clipboard = Clipboard.getSystemClipboard(); final ClipboardContent content = new ClipboardContent(); content.putString("some text"); content.put(DataFormat.PLAIN_TEXT, "other text"); clipboard.setContent(content);/* ww w . ja v a 2s. co m*/ primaryStage.setScene(scene); primaryStage.show(); }
From source file:ubicrypt.ui.ctrl.ExportConfigCtrl.java
@Override public void initialize(final URL location, final ResourceBundle resources) { final ByteArrayOutputStream out = new ByteArrayOutputStream(); final ArmoredOutputStream armor = new ArmoredOutputStream(out); try {//from www . j a va2 s . c o m armor.write(IOUtils.toByteArray(pgpService .encrypt(Utils.marshallIs(ExportConfig.copyFrom(localConfig, keyPair.getPublicKey()))))); armor.close(); } catch (final IOException e) { log.error(e.getMessage(), e); } text.setText(out.toString()); copy.setOnMouseClicked(event -> { final Clipboard clipboard = Clipboard.getSystemClipboard(); final ClipboardContent content = new ClipboardContent(); content.putString(out.toString()); clipboard.setContent(content); }); cancel.setOnMouseClicked(event -> navigator.popLayer()); }
From source file:ubicrypt.ui.ctrl.SettingsController.java
@Override public void initialize(final URL location, final ResourceBundle resources) { String fxml = substringBefore(substringAfterLast(location.getFile(), "/"), ".fxml"); StackNavigator navigator = new StackNavigator(main, fxml, controllerFactory); copyPKClipboard.setOnMouseClicked(event -> { try {/*from ww w. ja v a2 s . co m*/ final ByteArrayOutputStream out = new ByteArrayOutputStream(); final ArmoredOutputStream armor = new ArmoredOutputStream(out); armor.write(PGPEC.signPK(keyPair.getPublicKey(), signKey).getEncoded()); armor.close(); final Clipboard clipboard = Clipboard.getSystemClipboard(); final ClipboardContent content = new ClipboardContent(); content.putString(new String(out.toByteArray())); clipboard.setContent(content); // anchor.getChildren().add(notification); final NotificationPane notification = new NotificationPane(main); notification.setText("Public Key copied in clipboard"); notification.show(); log.info("public key copied into clipboard"); } catch (final IOException e) { Throwables.propagate(e); } }); addNewPK.setOnMouseClicked(event -> navigator.browse("addNewPK")); importConfig.setOnMouseClicked(event -> navigator.browse("importConfig")); exportConfig.setOnMouseClicked(event -> navigator.browse("exportConfig")); }
From source file:Main.java
@Override public void start(Stage primaryStage) { Group root = new Group(); Scene scene = new Scene(root, 300, 250); root.getChildren().addAll(source, target); source.setOnDragDetected(new EventHandler<MouseEvent>() { public void handle(MouseEvent event) { /* drag was detected, start a drag-and-drop gesture*/ /* allow any transfer mode */ Dragboard db = source.startDragAndDrop(TransferMode.ANY); /* Put a string on a dragboard */ ClipboardContent content = new ClipboardContent(); content.putString(source.getText()); db.setContent(content);//w w w. j a v a 2 s . c o m event.consume(); } }); target.setOnDragOver(new EventHandler<DragEvent>() { public void handle(DragEvent event) { /* data is dragged over the target */ /* accept it only if it is not dragged from the same node * and if it has a string data */ if (event.getGestureSource() != target && event.getDragboard().hasString()) { /* allow for moving */ event.acceptTransferModes(TransferMode.MOVE); } event.consume(); } }); target.setOnDragEntered(new EventHandler<DragEvent>() { public void handle(DragEvent event) { /* the drag-and-drop gesture entered the target */ /* show to the user that it is an actual gesture target */ if (event.getGestureSource() != target && event.getDragboard().hasString()) { target.setFill(Color.GREEN); } event.consume(); } }); target.setOnDragExited(new EventHandler<DragEvent>() { public void handle(DragEvent event) { /* mouse moved away, remove the graphical cues */ target.setFill(Color.BLACK); event.consume(); } }); target.setOnDragDropped(new EventHandler<DragEvent>() { public void handle(DragEvent event) { /* data dropped */ /* if there is a string data on dragboard, read it and use it */ Dragboard db = event.getDragboard(); boolean success = false; if (db.hasString()) { target.setText(db.getString()); success = true; } /* let the source know whether the string was successfully * transferred and used */ event.setDropCompleted(success); event.consume(); } }); source.setOnDragDone(new EventHandler<DragEvent>() { public void handle(DragEvent event) { /* the drag and drop gesture ended */ /* if the data was successfully moved, clear it */ if (event.getTransferMode() == TransferMode.MOVE) { source.setText(""); } event.consume(); } }); primaryStage.setScene(scene); primaryStage.show(); }
From source file:com.bekwam.mavenpomupdater.ToolBarDelegate.java
public void copy() { if (log.isDebugEnabled()) { log.debug("[COPY] lftf=" + lastFocusedTF.getId()); }// w ww . j a v a 2s .co m if (log.isDebugEnabled()) { log.debug("[COPY] copied=" + lastSelectedText); } ClipboardContent content = new ClipboardContent(); content.putString(lastSelectedText); systemClipboard.setContent(content); }
From source file:Main.java
private void initializeListeners() { // drag from left to right leftListView.setOnDragDetected(new EventHandler<MouseEvent>() { @Override//ww w . jav a 2 s.co m public void handle(MouseEvent event) { if (leftListView.getSelectionModel().getSelectedItem() == null) { return; } Dragboard dragBoard = leftListView.startDragAndDrop(TransferMode.MOVE); ClipboardContent content = new ClipboardContent(); content.putString(leftListView.getSelectionModel().getSelectedItem().getName()); dragBoard.setContent(content); } }); rightListView.setOnDragOver(new EventHandler<DragEvent>() { @Override public void handle(DragEvent dragEvent) { dragEvent.acceptTransferModes(TransferMode.MOVE); } }); rightListView.setOnDragDropped(new EventHandler<DragEvent>() { @Override public void handle(DragEvent dragEvent) { String player = dragEvent.getDragboard().getString(); rightListView.getItems().addAll(new Student(player)); leftList.remove(new Student(player)); leftListView.setItems(leftList); dragEvent.setDropCompleted(true); } }); // drag from right to left rightListView.setOnDragDetected(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { Dragboard dragBoard = rightListView.startDragAndDrop(TransferMode.MOVE); ClipboardContent content = new ClipboardContent(); content.putString(rightListView.getSelectionModel().getSelectedItem().getName()); dragBoard.setContent(content); } }); leftListView.setOnDragOver(new EventHandler<DragEvent>() { @Override public void handle(DragEvent dragEvent) { dragEvent.acceptTransferModes(TransferMode.MOVE); } }); leftListView.setOnDragDropped(new EventHandler<DragEvent>() { @Override public void handle(DragEvent dragEvent) { String player = dragEvent.getDragboard().getString(); leftListView.getItems().remove(new Student(player)); rightList.remove(new Student(player)); dragEvent.setDropCompleted(true); } }); }
From source file:Main.java
@Override public void start(Stage stage) { stage.setTitle("Hello Drag And Drop"); Group root = new Group(); Scene scene = new Scene(root, 400, 200); scene.setFill(Color.LIGHTGREEN); final Text source = new Text(50, 100, "DRAG ME"); source.setScaleX(2.0);// w w w .ja v a2 s .c o m source.setScaleY(2.0); final Text target = new Text(250, 100, "DROP HERE"); target.setScaleX(2.0); target.setScaleY(2.0); source.setOnDragDetected(new EventHandler<MouseEvent>() { public void handle(MouseEvent event) { /* drag was detected, start drag-and-drop gesture*/ System.out.println("onDragDetected"); /* allow any transfer mode */ Dragboard db = source.startDragAndDrop(TransferMode.ANY); /* put a string on dragboard */ ClipboardContent content = new ClipboardContent(); content.putString(source.getText()); db.setContent(content); event.consume(); } }); target.setOnDragOver(new EventHandler<DragEvent>() { public void handle(DragEvent event) { /* data is dragged over the target */ System.out.println("onDragOver"); /* accept it only if it is not dragged from the same node * and if it has a string data */ if (event.getGestureSource() != target && event.getDragboard().hasString()) { /* allow for both copying and moving, whatever user chooses */ event.acceptTransferModes(TransferMode.COPY_OR_MOVE); } event.consume(); } }); target.setOnDragEntered(new EventHandler<DragEvent>() { public void handle(DragEvent event) { /* the drag-and-drop gesture entered the target */ System.out.println("onDragEntered"); /* show to the user that it is an actual gesture target */ if (event.getGestureSource() != target && event.getDragboard().hasString()) { target.setFill(Color.GREEN); } event.consume(); } }); target.setOnDragExited(new EventHandler<DragEvent>() { public void handle(DragEvent event) { /* mouse moved away, remove the graphical cues */ target.setFill(Color.BLACK); event.consume(); } }); target.setOnDragDropped(new EventHandler<DragEvent>() { public void handle(DragEvent event) { /* data dropped */ System.out.println("onDragDropped"); /* if there is a string data on dragboard, read it and use it */ Dragboard db = event.getDragboard(); boolean success = false; if (db.hasString()) { target.setText(db.getString()); success = true; } /* let the source know whether the string was successfully * transferred and used */ event.setDropCompleted(success); event.consume(); } }); source.setOnDragDone(new EventHandler<DragEvent>() { public void handle(DragEvent event) { /* the drag-and-drop gesture ended */ System.out.println("onDragDone"); /* if the data was successfully moved, clear it */ if (event.getTransferMode() == TransferMode.MOVE) { source.setText(""); } event.consume(); } }); root.getChildren().add(source); root.getChildren().add(target); stage.setScene(scene); stage.show(); }
From source file:org.pdfsam.support.io.ObjectCollectionWriter.java
@Override public void to(ClipboardContent clipboard) { try (StringWriter writer = new StringWriter()) { for (Object item : content) { writer.append(defaultLineSeparator(item.toString())); }//from w w w . j a v a2s. co m clipboard.putString(writer.toString()); } catch (Exception e) { LOG.error(DefaultI18nContext.getInstance().i18n("Error saving log file."), e); } }