javafx.scene.input.Dragboard Java Examples
The following examples show how to use
javafx.scene.input.Dragboard.
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: DragAndDropUtil.java From pmd-designer with BSD 2-Clause "Simplified" License | 6 votes |
/** * Registers the given [source] javafx Node as a source for a drag * and drop even with {@link #NODE_RANGE_DATA_FORMAT} content. */ public static Subscription registerAsNodeDragSource(javafx.scene.Node source, Node data, DesignerRoot root) { source.setOnDragDetected(evt -> { // drag and drop Dragboard db = source.startDragAndDrop(TransferMode.LINK); ClipboardContent content = new ClipboardContent(); content.put(NODE_RANGE_DATA_FORMAT, TextRange.fullLine(data.getBeginLine(), 10000)); db.setContent(content); root.getService(DesignerRoot.IS_NODE_BEING_DRAGGED).setValue(true); evt.consume(); }); source.setOnDragDone(evt -> { if (evt.getDragboard().hasContent(NODE_RANGE_DATA_FORMAT)) { root.getService(DesignerRoot.IS_NODE_BEING_DRAGGED).setValue(false); } }); return () -> source.setOnDragDetected(null); }
Example #2
Source File: MarkdownEditorPane.java From markdown-writer-fx with BSD 2-Clause "Simplified" License | 6 votes |
private void onDragDropped(DragEvent event) { Dragboard db = event.getDragboard(); if (db.hasFiles()) { // drop files (e.g. from project file tree) List<File> files = db.getFiles(); if (!files.isEmpty()) smartEdit.insertLinkOrImage(dragCaret.getPosition(), files.get(0).toPath()); } else if (db.hasString()) { // drop text String newText = db.getString(); int insertPosition = dragCaret.getPosition(); SmartEdit.insertText(textArea, insertPosition, newText); SmartEdit.selectRange(textArea, insertPosition, insertPosition + newText.length()); } textArea.requestFocus(); event.setDropCompleted(true); event.consume(); }
Example #3
Source File: ArtistsMainController.java From MusicPlayer with MIT License | 6 votes |
AlbumCell() { super(); setAlignment(Pos.CENTER); setPrefHeight(140); setPrefWidth(140); albumArtwork.setFitWidth(130); albumArtwork.setFitHeight(130); albumArtwork.setPreserveRatio(true); albumArtwork.setSmooth(true); albumArtwork.setCache(true); this.setOnMouseClicked(event -> albumList.getSelectionModel().select(album)); this.setOnDragDetected(event -> { Dragboard db = this.startDragAndDrop(TransferMode.ANY); ClipboardContent content = new ClipboardContent(); content.putString("Album"); db.setContent(content); MusicPlayer.setDraggedItem(album); db.setDragView(this.snapshot(null, null), 75, 75); event.consume(); }); }
Example #4
Source File: ArtistsMainController.java From MusicPlayer with MIT License | 6 votes |
ArtistCell() { super(); artistImage.setFitWidth(40); artistImage.setFitHeight(40); artistImage.setPreserveRatio(true); artistImage.setSmooth(true); artistImage.setCache(true); title.setTextOverrun(OverrunStyle.CLIP); cell.getChildren().addAll(artistImage, title); cell.setAlignment(Pos.CENTER_LEFT); HBox.setMargin(artistImage, new Insets(0, 10, 0, 0)); this.setPrefWidth(248); this.setOnMouseClicked(event -> artistList.getSelectionModel().select(artist)); this.setOnDragDetected(event -> { Dragboard db = this.startDragAndDrop(TransferMode.ANY); ClipboardContent content = new ClipboardContent(); content.putString("Artist"); db.setContent(content); MusicPlayer.setDraggedItem(artist); db.setDragView(this.snapshot(null, null), 125, 25); event.consume(); }); }
Example #5
Source File: CardPileView.java From Solitaire with GNU General Public License v2.0 | 6 votes |
private EventHandler<DragEvent> createDragDroppedHandler(final ImageView pImageView, final Card pCard) { return new EventHandler<DragEvent>() { @Override public void handle(DragEvent pEvent) { Dragboard db = pEvent.getDragboard(); boolean success = false; if(db.hasString()) { GameModel.instance().getCardMove(new CardTransfer(db.getString()).getTop(), aIndex).perform(); success = true; } pEvent.setDropCompleted(success); pEvent.consume(); } }; }
Example #6
Source File: SuitStack.java From Solitaire with GNU General Public License v2.0 | 6 votes |
private EventHandler<DragEvent> createOnDragDroppedHandler() { return new EventHandler<DragEvent>() { public void handle(DragEvent pEvent) { Dragboard db = pEvent.getDragboard(); boolean success = false; if(db.hasString()) { CardTransfer transfer = new CardTransfer(pEvent.getDragboard().getString()); GameModel.instance().getCardMove(transfer.getTop(), aIndex).perform(); success = true; } pEvent.setDropCompleted(success); pEvent.consume(); } }; }
Example #7
Source File: ResourceConfigurationView.java From beatoraja with GNU General Public License v3.0 | 6 votes |
@FXML public void songPathDragDropped(final DragEvent ev) { Dragboard db = ev.getDragboard(); if (db.hasFiles()) { for (File f : db.getFiles()) { if (f.isDirectory()) { final String defaultPath = new File(".").getAbsoluteFile().getParent() + File.separatorChar;; String targetPath = f.getAbsolutePath(); if(targetPath.startsWith(defaultPath)) { targetPath = f.getAbsolutePath().substring(defaultPath.length()); } boolean unique = true; for (String path : bmsroot.getItems()) { if (path.equals(targetPath) || targetPath.startsWith(path + File.separatorChar)) { unique = false; break; } } if (unique) { bmsroot.getItems().add(targetPath); main.loadBMSPath(targetPath); } } } } }
Example #8
Source File: DockItem.java From phoebus with Eclipse Public License 1.0 | 6 votes |
/** Allow dragging this item */ private void handleDragDetected(final MouseEvent event) { // Disable dragging from a 'fixed' pane if (getDockPane().isFixed()) return; final Dragboard db = name_tab.startDragAndDrop(TransferMode.MOVE); final ClipboardContent content = new ClipboardContent(); content.put(DOCK_ITEM, getLabel()); db.setContent(content); final DockItem previous = dragged_item.getAndSet(this); if (previous != null) logger.log(Level.WARNING, "Already dragging " + previous); event.consume(); }
Example #9
Source File: SearchView.java From phoebus with Eclipse Public License 1.0 | 6 votes |
/** Allow dragging {@link ChannelInfo} from search view (into plot) */ private void setupDrag() { channel_table.setOnDragDetected(event -> { final List<ChannelInfo> selection = channel_table.getSelectionModel().getSelectedItems(); if (selection.size() > 0) { final Dragboard db = channel_table.startDragAndDrop(TransferMode.COPY); final ClipboardContent content = new ClipboardContent(); // Publish PV names as "PV1, PV2, ..." content.putString(selection.stream().map(ChannelInfo::getName).collect(Collectors.joining(", "))); // Copy into ArrayList which is for sure Serializable content.put(CHANNEL_INFOS, new ArrayList<>(selection)); db.setContent(content); } event.consume(); }); }
Example #10
Source File: AlarmTableUI.java From phoebus with Eclipse Public License 1.0 | 6 votes |
/** Enable dragging the PV name from a table cell. * @param cell Table cell */ static void enablePVDrag(TableCell<AlarmInfoRow, ?> cell) { // Tried to use table.setOnDragDetected() to drag PV names // from all selected cells, but with drag enabled on the table // it is no longer possible to resize columns: // Moving a column divider starts a drag. // So now hooking drag to table cell. cell.setOnDragDetected(event -> { // Anything to drag? if (cell.getTableRow() == null || cell.getTableRow().getItem() == null) return; final Dragboard db = cell.startDragAndDrop(TransferMode.COPY); final ClipboardContent content = new ClipboardContent(); content.putString(cell.getTableRow().getItem().pv.get()); db.setContent(content); event.consume(); }); }
Example #11
Source File: AlarmTreeView.java From phoebus with Eclipse Public License 1.0 | 6 votes |
/** For leaf nodes, drag PV name */ private void addDragSupport() { tree_view.setOnDragDetected(event -> { final ObservableList<TreeItem<AlarmTreeItem<?>>> items = tree_view.getSelectionModel().getSelectedItems(); if (items.size() != 1) return; final AlarmTreeItem<?> item = items.get(0).getValue(); if (! (item instanceof AlarmClientLeaf)) return; final Dragboard db = tree_view.startDragAndDrop(TransferMode.COPY); final ClipboardContent content = new ClipboardContent(); content.putString(item.getName()); db.setContent(content); event.consume(); }); }
Example #12
Source File: WidgetTransfer.java From phoebus with Eclipse Public License 1.0 | 6 votes |
/** * @param event The {@link DragEvent} containing the dragged data. * @param selection_tracker Used to get the grid steps from its model to be * used in offsetting multiple widgets. * @param widgets The container of the created widgets. */ private static void installWidgetsFromString ( final DragEvent event, final SelectedWidgetUITracker selection_tracker, final List<Widget> widgets ) { final Dragboard db = event.getDragboard(); final String xmlOrText = db.getString(); try { widgets.addAll(ModelReader.parseXML(xmlOrText).getChildren()); } catch ( Exception ex ) { installWidgetsFromString(event, xmlOrText, selection_tracker, widgets); } }
Example #13
Source File: NBTTreeView.java From mcaselector with MIT License | 6 votes |
private void onDragDetected(MouseEvent e) { if (getTreeItem() == getTreeView().getRoot()) { return; } Dragboard db = startDragAndDrop(TransferMode.MOVE); WritableImage wi = new WritableImage((int) getWidth(), (int) getHeight()); Image dbImg = snapshot(null, wi); db.setDragView(dbImg); if (USE_DRAGVIEW_OFFSET) { db.setDragViewOffsetX(getWidth() / 2); db.setDragViewOffsetY(getHeight() / 2); } ClipboardContent cbc = new ClipboardContent(); cbc.put(CLIPBOARD_DATAFORMAT, true); db.setContent(cbc); dragboardContent = getTreeItem(); e.consume(); }
Example #14
Source File: GroupResource.java From marathonv5 with Apache License 2.0 | 5 votes |
@Override public boolean droppable(Dragboard dragboard) { if (dragboard.hasFiles()) { return type.droppable(dragboard.getFiles(), getFilePath()); } return false; }
Example #15
Source File: CardDragHandler.java From Solitaire with GNU General Public License v2.0 | 5 votes |
@Override public void handle(MouseEvent pMouseEvent) { Dragboard db = aImageView.startDragAndDrop(TransferMode.ANY); CLIPBOARD_CONTENT.putString(aCard.getIDString()); db.setContent(CLIPBOARD_CONTENT); pMouseEvent.consume(); }
Example #16
Source File: MZmineGUI.java From mzmine3 with GNU General Public License v2.0 | 5 votes |
/** * The method activateSetOnDragDropped controlling what happens when something is dropped on window. * Implemented activateSetOnDragDropped to select the module according to the dropped file type and open dropped file * @param event - DragEvent */ public static void activateSetOnDragDropped(DragEvent event){ Dragboard dragboard = event.getDragboard(); boolean hasFileDropped = false; if (dragboard.hasFiles()) { hasFileDropped = true; for (File selectedFile:dragboard.getFiles()) { final String extension = FilenameUtils.getExtension(selectedFile.getName()); String[] rawDataFile = {"cdf","nc","mzData","mzML","mzXML","raw"}; final Boolean isRawDataFile = Arrays.asList(rawDataFile).contains(extension); final Boolean isMZmineProject = extension.equals("mzmine"); Class<? extends MZmineRunnableModule> moduleJavaClass = null; if(isMZmineProject) { moduleJavaClass = ProjectLoadModule.class; } else if(isRawDataFile){ moduleJavaClass = RawDataImportModule.class; } if(moduleJavaClass != null){ ParameterSet moduleParameters = MZmineCore.getConfiguration().getModuleParameters(moduleJavaClass); if(isMZmineProject){ moduleParameters.getParameter(projectFile).setValue(selectedFile); } else if (isRawDataFile){ File fileArray[] = { selectedFile }; moduleParameters.getParameter(fileNames).setValue(fileArray); } ParameterSet parametersCopy = moduleParameters.cloneParameterSet(); MZmineCore.runMZmineModule(moduleJavaClass, parametersCopy); } } } event.setDropCompleted(hasFileDropped); event.consume(); }
Example #17
Source File: ResourceConfigurationView.java From beatoraja with GNU General Public License v3.0 | 5 votes |
@FXML public void onSongPathDragOver(DragEvent ev) { Dragboard db = ev.getDragboard(); if (db.hasFiles()) { ev.acceptTransferModes(TransferMode.COPY_OR_MOVE); } ev.consume(); }
Example #18
Source File: MZmineGUI.java From mzmine3 with GNU General Public License v2.0 | 5 votes |
/** * The method activateSetOnDragOver controlling what happens when something is dragged over. * Implemented activateSetOnDragOver to accept when files are dragged over it. * @param event - DragEvent */ public static void activateSetOnDragOver(DragEvent event){ Dragboard dragBoard = event.getDragboard(); if (dragBoard.hasFiles()) { event.acceptTransferModes(TransferMode.COPY); } else { event.consume(); } }
Example #19
Source File: ApkInfoPrinterActivity.java From ApkToolPlus with Apache License 2.0 | 5 votes |
public void onDragDroppedHandleFiles(DragEvent event){ Dragboard db = event.getDragboard(); boolean success = false; if (db.hasFiles()) { success = true; for (File file : db.getFiles()) { showManifest(file); break; } } event.setDropCompleted(success); event.consume(); }
Example #20
Source File: ApkInfoPrinterActivity.java From ApkToolPlus with Apache License 2.0 | 5 votes |
public void onDragOverLinkFile(DragEvent event){ Dragboard db = event.getDragboard(); if (db.hasFiles()) { event.acceptTransferModes(TransferMode.LINK); } else { event.consume(); } }
Example #21
Source File: CardPileView.java From Solitaire with GNU General Public License v2.0 | 5 votes |
private EventHandler<MouseEvent> createDragDetectedHandler(final ImageView pImageView, final Card pCard) { return new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent pMouseEvent) { Dragboard db = pImageView.startDragAndDrop(TransferMode.ANY); CLIPBOARD_CONTENT.putString(CardTransfer.serialize(GameModel.instance().getSubStack(pCard, aIndex))); db.setContent(CLIPBOARD_CONTENT); pMouseEvent.consume(); } }; }
Example #22
Source File: SearchBox.java From mdict-java with GNU General Public License v3.0 | 5 votes |
protected void handleDrop(DragEvent event) { Dragboard db = event.getDragboard(); if(db.hasContent(DataFormat.PLAIN_TEXT)) { String val = (String) db.getContent(DataFormat.PLAIN_TEXT); ((TextField)event.getSource()).setText(val); event.consume(); } }
Example #23
Source File: SearchBox.java From mdict-java with GNU General Public License v3.0 | 5 votes |
protected void startDrag(MouseEvent event) { TextField textBox = ((TextField)event.getSource()); if(!"".equals(textBox.getSelectedText()) && textBox.getText().equals(textBox.getSelectedText())) { Dragboard db = textBox.startDragAndDrop(TransferMode.MOVE); snapshotter.setText(textBox.getText()); db.setDragView(snapshotter.snapshot(null, null)); ClipboardContent cc = new ClipboardContent(); cc.put(DataFormat.PLAIN_TEXT, textBox.getSelectedText()); db.setContent(cc); event.consume(); } }
Example #24
Source File: ProjectFileTreeView.java From markdown-writer-fx with BSD 2-Clause "Simplified" License | 5 votes |
private TreeCell<File> createCell(TreeView<File> treeView) { FileTreeCell treeCell = new FileTreeCell(); treeCell.setOnDragDetected(event -> { TreeItem<File> draggedItem = treeCell.getTreeItem(); Dragboard db = treeCell.startDragAndDrop(TransferMode.COPY); ClipboardContent content = new ClipboardContent(); content.putString(draggedItem.getValue().getAbsolutePath()); content.put(DataFormat.FILES, Collections.singletonList(draggedItem.getValue())); db.setContent(content); event.consume(); }); return treeCell; }
Example #25
Source File: MarkdownEditorPane.java From markdown-writer-fx with BSD 2-Clause "Simplified" License | 5 votes |
private void onDragOver(DragEvent event) { // check whether we can accept a drop Dragboard db = event.getDragboard(); if (db.hasString() || db.hasFiles()) event.acceptTransferModes(TransferMode.COPY); // move drag caret to mouse location if (event.isAccepted()) { CharacterHit hit = textArea.hit(event.getX(), event.getY()); dragCaret.moveTo(hit.getInsertionIndex()); } event.consume(); }
Example #26
Source File: Palette.java From phoebus with Eclipse Public License 1.0 | 5 votes |
private void hookDrag() { // Drag command out as XML command_list.setOnDragDetected(event -> { final ScanCommand command = command_list.getSelectionModel().getSelectedItem(); final Dragboard db = command_list.startDragAndDrop(TransferMode.COPY); db.setContent(ScanCommandDragDrop.createClipboardContent(command)); event.consume(); }); }
Example #27
Source File: ScanCommandTree.java From phoebus with Eclipse Public License 1.0 | 5 votes |
private void hookDrag() { final List<ScanCommand> commands = new ArrayList<>(); setOnDragDetected(event -> { // Only start drag on left (primary) button, // not also on right button which opens the context menu, // or the apple 'Command' button which is again for the context menu if (event.isPrimaryButtonDown() && !event.isMetaDown()) { commands.clear(); commands.addAll(getSelectedCommands()); if (! commands.isEmpty()) { // Would like to default to move, // allowing key modifiers for copy. // TransferMode.COPY_OR_MOVE will default to copy, // i.e. wrong order. // --> Deciding based on key modifier at start of drag // https://stackoverflow.com/questions/38699306/how-to-adjust-or-deviate-from-the-default-javafx-transfer-mode-behavior final Dragboard db = startDragAndDrop(event.isShortcutDown() ? TransferMode.COPY : TransferMode.MOVE); db.setContent(ScanCommandDragDrop.createClipboardContent(commands)); } } event.consume(); }); setOnDragDone(event -> { if (event.getTransferMode() == TransferMode.MOVE) undo.execute(new RemoveCommands(model, commands)); commands.clear(); }); }
Example #28
Source File: NBTTreeView.java From mcaselector with MIT License | 5 votes |
private void onDragDone(DragEvent e) { Dragboard db = e.getDragboard(); if (db.hasContent(CLIPBOARD_DATAFORMAT)) { dragboardContent = null; } if (dropTargetCell != null) { dropTargetCell.setInsertCssClass("drop-target", null); } setInsertParentCss(false); }
Example #29
Source File: NBTTreeView.java From mcaselector with MIT License | 5 votes |
private void onDragDropped(DragEvent e) { Dragboard db = e.getDragboard(); if (db.hasContent(CLIPBOARD_DATAFORMAT)) { // this treecell receives a foreign drop // get content and insert into this tag, before this tag or after this tag // and remove dropped tag from old location // we also don't want to do anything if the tag is dropped onto itself or if the target is invalid if (getTreeItem() != null && dragboardContent != getTreeItem() && dropTarget != null) { ((NBTTreeItem) dropTarget).moveHere(dropIndex, (NBTTreeItem) dragboardContent, getTreeView()); } dragboardContent = null; } }
Example #30
Source File: WidgetTransfer.java From phoebus with Eclipse Public License 1.0 | 5 votes |
/** * @param db The {@link Dragboard} containing the dragged data. * @param selection_tracker Used to get the grid steps from its model to be * used in offsetting multiple widgets. * @param widgets The container of the created widgets. * @param updates Updates to perform on widgets */ private static void installWidgetsFromFiles ( final Dragboard db, final SelectedWidgetUITracker selection_tracker, final List<Widget> widgets, final List<Runnable> updates ) { final List<File> files = db.getFiles(); if ( files.size() > 1 && files.stream().allMatch(f -> IMAGE_FILE_EXTENSIONS.contains(getExtension(f.toString()).toUpperCase())) ) { final List<String> fileNames = new ArrayList<>(files.size()); files.stream().forEach(f -> fileNames.add(resolveFile(f, selection_tracker.getModel()))); installSymbolWidgetFromImageFiles(fileNames, selection_tracker, widgets, updates); } else { for ( int i = 0; i < files.size(); i++ ) { final String fileName = resolveFile(files.get(i), selection_tracker.getModel()); final String extension = getExtension(fileName).toUpperCase(); if ( IMAGE_FILE_EXTENSIONS.contains(extension) ) { installPictureWidgetFromFile(fileName, selection_tracker, widgets, updates); } else if ( EMBEDDED_FILE_EXTENSIONS.contains(extension) ) { installEmbeddedDisplayWidgetFromFile(fileName, selection_tracker, widgets, updates); } } } }