Example usage for javafx.scene.input ClipboardContent ClipboardContent

List of usage examples for javafx.scene.input ClipboardContent ClipboardContent

Introduction

In this page you can find the example usage for javafx.scene.input ClipboardContent ClipboardContent.

Prototype

ClipboardContent

Source Link

Usage

From source file:Main.java

public static void main(String[] args) {
    DataFormat fmt = new DataFormat("text/foo", "text/bar");
    Clipboard clipboard = Clipboard.getSystemClipboard();
    ClipboardContent content = new ClipboardContent();
    content.put(fmt, "Hello");
    clipboard.setContent(content);/*  w ww. j a  va  2 s . c o m*/
}

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);/*from  w  w w.j  a v  a  2s  . com*/

    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:Main.java

private void initializeListeners() {
    // drag from left to right
    leftListView.setOnDragDetected(new EventHandler<MouseEvent>() {
        @Override//from   w ww.j  av  a 2s. 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: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   ww  w .j av a  2s.c om
        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:com.bekwam.mavenpomupdater.ToolBarDelegate.java

public void copy() {
    if (log.isDebugEnabled()) {
        log.debug("[COPY] lftf=" + lastFocusedTF.getId());
    }//from   ww  w  . j a  va 2 s .  c  o m

    if (log.isDebugEnabled()) {
        log.debug("[COPY] copied=" + lastSelectedText);
    }

    ClipboardContent content = new ClipboardContent();
    content.putString(lastSelectedText);
    systemClipboard.setContent(content);
}

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 w w  w .  j  a v  a 2  s .c  o  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 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);/*ww w . j av  a  2 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: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);//from  w  w w.  j av  a 2  s  . c  om

            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:org.pdfsam.ui.dashboard.about.AboutDashboardPane.java

@Inject
public AboutDashboardPane(Pdfsam pdfsam) {
    getStyleClass().add("dashboard-container");
    VBox left = new VBox(5);
    addSectionTitle(pdfsam.name(), left);
    Label copyright = new Label("Copyright 2014 by Andrea Vacondio");
    AwesomeDude.setIcon(copyright, AwesomeIcon.COPYRIGHT);
    left.getChildren().addAll(new Label(String.format("ver. %s", pdfsam.version())), copyright);
    addHyperlink(null, "http://www.gnu.org/licenses/agpl-3.0.html", "GNU Affero General Public License v3",
            left);/*from   ww w  .j a  v a  2s  .c o  m*/
    addHyperlink(AwesomeIcon.HOME, "http://www.pdfsam.org", "www.pdfsam.org", left);
    addHyperlink(AwesomeIcon.RSS_SQUARE, "http://www.pdfsam.org/feed/",
            DefaultI18nContext.getInstance().i18n("Subscribe to the official news feed"), left);

    addSectionTitle(DefaultI18nContext.getInstance().i18n("Environment"), left);
    Label runtime = new Label(String.format("%s %s", System.getProperty("java.runtime.name"),
            System.getProperty("java.runtime.version")));
    Label fxRuntime = new Label(
            String.format("JavaFX %s", com.sun.javafx.runtime.VersionInfo.getRuntimeVersion()));
    Label memory = new Label(DefaultI18nContext.getInstance().i18n("Max memory {0}",
            FileUtils.byteCountToDisplaySize(Runtime.getRuntime().maxMemory())));
    Button copyButton = new Button(DefaultI18nContext.getInstance().i18n("Copy to clipboard"));
    AwesomeDude.setIcon(copyButton, AwesomeIcon.COPY);
    copyButton.getStyleClass().addAll(Style.BUTTON.css());
    copyButton.setId("copyEnvDetails");
    copyButton.setOnAction(a -> {
        ClipboardContent content = new ClipboardContent();
        writeContent(Arrays.asList(pdfsam.name(), pdfsam.version(), runtime.getText(), fxRuntime.getText(),
                memory.getText())).to(content);
        Clipboard.getSystemClipboard().setContent(content);
    });
    left.getChildren().addAll(runtime, fxRuntime, memory, copyButton);

    addSectionTitle(DefaultI18nContext.getInstance().i18n("Thanks to"), left);
    addHyperlink(null, "http://www.pdfsam.org/thanks_to",
            DefaultI18nContext.getInstance().i18n("The open source projects making PDFsam possible"), left);
    VBox right = new VBox(5);
    addSectionTitle(DefaultI18nContext.getInstance().i18n("Support"), right);
    addHyperlink(AwesomeIcon.BUG, "http://www.pdfsam.org/issue_tracker",
            DefaultI18nContext.getInstance().i18n("Bug and feature requests"), right);
    addHyperlink(AwesomeIcon.QUESTION_CIRCLE, "http://www.pdfsam.org/wiki", "HowTo wiki", right);
    addHyperlink(AwesomeIcon.YOUTUBE_PLAY, "http://www.pdfsam.org/quickstart_video",
            DefaultI18nContext.getInstance().i18n("Play the \"get started\" video"), right);

    addSectionTitle(DefaultI18nContext.getInstance().i18n("Contribute"), right);
    addHyperlink(AwesomeIcon.GITHUB, "http://www.pdfsam.org/scm",
            DefaultI18nContext.getInstance().i18n("Fork PDFsam on GitHub"), right);
    addHyperlink(AwesomeIcon.FLAG_ALT, "http://www.pdfsam.org/translate",
            DefaultI18nContext.getInstance().i18n("Translate"), right);
    addHyperlink(AwesomeIcon.DOLLAR, "http://www.pdfsam.org/donate",
            DefaultI18nContext.getInstance().i18n("Donate"), right);

    addSectionTitle(DefaultI18nContext.getInstance().i18n("Social"), right);
    addHyperlink(AwesomeIcon.TWITTER_SQUARE, "http://www.pdfsam.org/twitter",
            DefaultI18nContext.getInstance().i18n("Follow us on Twitter"), right);
    addHyperlink(AwesomeIcon.GOOGLE_PLUS_SQUARE, "http://www.pdfsam.org/gplus",
            DefaultI18nContext.getInstance().i18n("Follow us on Google Plus"), right);
    addHyperlink(AwesomeIcon.FACEBOOK_SQUARE, "http://www.pdfsam.org/facebook",
            DefaultI18nContext.getInstance().i18n("Like us on Facebook"), right);
    getChildren().addAll(left, right);

}

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);/*  w w  w.  j ava 2 s.c  o  m*/
    clipboard.setContent(content);
}