functional/ControlsTests/src/javafx/draganddrop/DragDropWithControls.java

Print this page

        

*** 48,65 **** import javafx.geometry.Orientation; import javafx.scene.Node; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.scene.control.Button; - import javafx.scene.control.ButtonBuilder; import javafx.scene.control.CheckBox; import javafx.scene.control.ChoiceBox; import javafx.scene.control.Label; import javafx.scene.control.Separator; import javafx.scene.control.TextField; import javafx.scene.image.Image; ! import javafx.scene.image.ImageViewBuilder; import javafx.scene.input.Clipboard; import javafx.scene.input.ClipboardContent; import javafx.scene.input.DataFormat; import javafx.scene.input.DragEvent; import javafx.scene.input.Dragboard; --- 48,64 ---- import javafx.geometry.Orientation; import javafx.scene.Node; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.CheckBox; import javafx.scene.control.ChoiceBox; import javafx.scene.control.Label; import javafx.scene.control.Separator; import javafx.scene.control.TextField; import javafx.scene.image.Image; ! import javafx.scene.image.ImageView; import javafx.scene.input.Clipboard; import javafx.scene.input.ClipboardContent; import javafx.scene.input.DataFormat; import javafx.scene.input.DragEvent; import javafx.scene.input.Dragboard;
*** 291,309 **** createControlCombo(sourceControlPane, true), new Text("Source transfer modes:"), createTMSelect(sourceModes)); VBox rbox = new VBox(10); ! rbox.getChildren().addAll(new Text("Data formats:"), ! createFormatSelect(sourceFormats), ! ButtonBuilder.create().text("Put to clipboard") ! .id(ID_TO_CLIPBOARD_BUTTON) ! .onAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent t) { Clipboard.getSystemClipboard().setContent(prepareClipboardContent()); } ! }).build()); HBox hbox = new HBox(10); hbox.getChildren().addAll(lbox, new Separator(Orientation.VERTICAL), rbox); final Text fileHdr = new Text("Files to drag (1):"); --- 290,309 ---- createControlCombo(sourceControlPane, true), new Text("Source transfer modes:"), createTMSelect(sourceModes)); VBox rbox = new VBox(10); ! Button b = new Button("Put to clipboard"); ! b.setId(ID_TO_CLIPBOARD_BUTTON); ! b.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent t) { Clipboard.getSystemClipboard().setContent(prepareClipboardContent()); } ! }); ! rbox.getChildren().addAll(new Text("Data formats:"), ! createFormatSelect(sourceFormats), ! b); HBox hbox = new HBox(10); hbox.getChildren().addAll(lbox, new Separator(Orientation.VERTICAL), rbox); final Text fileHdr = new Text("Files to drag (1):");
*** 340,353 **** btns.getChildren().addAll(add, clear); useCustomViewCB = new CheckBox("Use custom drag view."); VBox box = new VBox(10); box.getChildren().addAll(hbox, new Separator(), fileHdr, fileNames, tb, btns, useCustomViewCB, new Text("Image: "), ! ImageViewBuilder.create().image(CONTENT_IMAGE).id(ID_SRC_IMAGE).build(), log); if (parameters.size() > 0) { box.setStyle("-fx-background-color: " + parameters.get(0) + ";"); } return box; --- 340,356 ---- btns.getChildren().addAll(add, clear); useCustomViewCB = new CheckBox("Use custom drag view."); VBox box = new VBox(10); + ImageView i = new ImageView(); + i.setImage(CONTENT_IMAGE); + i.setId(ID_SRC_IMAGE); box.getChildren().addAll(hbox, new Separator(), fileHdr, fileNames, tb, btns, useCustomViewCB, new Text("Image: "), ! i, log); if (parameters.size() > 0) { box.setStyle("-fx-background-color: " + parameters.get(0) + ";"); } return box;
*** 368,383 **** VBox lbox = new VBox(10); lbox.getChildren().addAll(targetControlPane, new Separator(), new Text("Target control type:"), createControlCombo(targetControlPane, false), new Text("Target transfer modes:"), createTMSelect(targetModes)); VBox rbox = new VBox(10); ! rbox.getChildren().addAll(new Text("Data formats:"), createFormatSelect(targetFormats), ! ButtonBuilder.create().text("paste from clipboard").id(ID_FROM_CLIPBOARD_BUTTON).onAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent t) { getDataFromClipboard(Clipboard.getSystemClipboard()); } ! }).build()); VBox content = new VBox(10); content.getChildren().addAll(new Text("Transfered content:"), transferedContentPane); hbox.getChildren().addAll(lbox, new Separator(Orientation.VERTICAL), rbox, --- 371,388 ---- VBox lbox = new VBox(10); lbox.getChildren().addAll(targetControlPane, new Separator(), new Text("Target control type:"), createControlCombo(targetControlPane, false), new Text("Target transfer modes:"), createTMSelect(targetModes)); VBox rbox = new VBox(10); ! Button b = new Button("paste from clipboard"); ! b.setId(ID_FROM_CLIPBOARD_BUTTON); ! b.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent t) { getDataFromClipboard(Clipboard.getSystemClipboard()); } ! }); ! rbox.getChildren().addAll(new Text("Data formats:"), createFormatSelect(targetFormats), b); VBox content = new VBox(10); content.getChildren().addAll(new Text("Transfered content:"), transferedContentPane); hbox.getChildren().addAll(lbox, new Separator(Orientation.VERTICAL), rbox,
*** 398,407 **** --- 403,415 ---- cb.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<NodeFactory>() { @Override public void changed(ObservableValue<? extends NodeFactory> ov, NodeFactory t, NodeFactory t1) { Node ctrl = null; ctrl = t1.createNode(); + if (ctrl instanceof ImageView) { + ctrl.setPickOnBounds(true); + } if (source) { ctrl.setId(ID_DRAG_SOURCE); } else { ctrl.setId(ID_DRAG_TARGET); }
*** 567,577 **** log("Dropped URL: " + cb.getUrl()); gotData = true; } if (targetFormats.contains(DataFormat.IMAGE) && cb.hasImage()) { receivedContent.put(DataFormat.IMAGE, cb.getImage()); ! transferedContentPane.getChildren().addAll(new Text("Image: "), ImageViewBuilder.create().image(cb.getImage()).id(ID_RECEIVED_IMAGE).build()); log("Dropped image: " + cb.getImage()); gotData = true; } if (targetFormats.contains(DataFormat.FILES) && cb.hasFiles()) { log("Dropped files:"); --- 575,587 ---- log("Dropped URL: " + cb.getUrl()); gotData = true; } if (targetFormats.contains(DataFormat.IMAGE) && cb.hasImage()) { receivedContent.put(DataFormat.IMAGE, cb.getImage()); ! ImageView i = new ImageView(cb.getImage()); ! i.setId(ID_RECEIVED_IMAGE); ! transferedContentPane.getChildren().addAll(new Text("Image: "), i); log("Dropped image: " + cb.getImage()); gotData = true; } if (targetFormats.contains(DataFormat.FILES) && cb.hasFiles()) { log("Dropped files:");