Search in sources :

Example 1 with Dragboard

use of javafx.scene.input.Dragboard in project cryptomator by cryptomator.

the class DraggableListCell method onDragDetected.

private void onDragDetected(MouseEvent event) {
    if (getItem() == null) {
        return;
    }
    final ClipboardContent content = new ClipboardContent();
    content.putString(Integer.toString(getIndex()));
    final Image snapshot = this.snapshot(new SnapshotParameters(), null);
    final Dragboard dragboard = startDragAndDrop(TransferMode.MOVE);
    dragboard.setDragView(snapshot);
    dragboard.setContent(content);
    event.consume();
}
Also used : SnapshotParameters(javafx.scene.SnapshotParameters) ClipboardContent(javafx.scene.input.ClipboardContent) BorderImage(javafx.scene.layout.BorderImage) Image(javafx.scene.image.Image) Dragboard(javafx.scene.input.Dragboard)

Example 2 with Dragboard

use of javafx.scene.input.Dragboard in project Gargoyle by callakrsos.

the class UtubeDownloaderComposite method initialize.

@FXML
public void initialize() {
    btnDownload.setDisable(true);
    this.txtDownloadLocation.setText(System.getProperty("user.home"));
    this.txtDownloadLocation.setPromptText("Downlaod Location");
    // this.lvDownlaodCont.setCellFactory(new Callback<ListView<UtubeItemDVO>, ListCell<UtubeItemDVO>>() {
    //
    // @Override
    // public ListCell<UtubeItemDVO> call(ListView<UtubeItemDVO> param) {
    // return new UtubeListCell();
    // }
    // });
    // this.lvDownlaodCont.setOnDragDetected(ev -> {
    // ev.setDragDetect(true);
    // });
    txtUtubeURL.setOnDragOver(ev -> {
        if (ev.getDragboard().hasUrl()) {
            ev.acceptTransferModes(TransferMode.LINK);
            ev.consume();
        }
    });
    txtUtubeURL.setOnDragDropped(ev -> {
        Dragboard dragboard = ev.getDragboard();
        String url = dragboard.getUrl();
        txtUtubeURL.setText(url);
    });
    txtUtubeURL.textProperty().addListener((oba, o, n) -> {
        btnDownload.setDisable(n.trim().isEmpty());
    });
    // 초기값
    this.cbQuality.getItems().addAll(YoutubeQuality.values());
    // 디폴트
    this.cbQuality.getSelectionModel().select(YoutubeQuality.p480);
    this.cbQuality.setCellFactory(new Callback<ListView<YoutubeQuality>, ListCell<YoutubeQuality>>() {

        @Override
        public ListCell<YoutubeQuality> call(ListView<YoutubeQuality> param) {
            return new TextFieldListCell<>(new StringConverter<YoutubeQuality>() {

                @Override
                public String toString(YoutubeQuality object) {
                    return object.name();
                }

                @Override
                public YoutubeQuality fromString(String string) {
                    return YoutubeQuality.valueOf(string);
                }
            });
        }
    });
    this.wasDownloading.addListener((oba, o, n) -> {
        if (n != null)
            this.btnDownload.setDisable(n.booleanValue());
    });
    this.downloadedFile.addListener((oba, o, n) -> {
        if (n != null && n.exists()) {
            //				btnOpen.setDisable(false);
            this.txtFileName.setText(n.getName());
        } else {
        //				btnOpen.setDisable(true);
        }
    });
}
Also used : ListView(javafx.scene.control.ListView) YoutubeQuality(com.github.axet.vget.vhs.YouTubeInfo.YoutubeQuality) ListCell(javafx.scene.control.ListCell) TextFieldListCell(javafx.scene.control.cell.TextFieldListCell) StringConverter(javafx.util.StringConverter) Dragboard(javafx.scene.input.Dragboard) FXML(javafx.fxml.FXML)

Example 3 with Dragboard

use of javafx.scene.input.Dragboard in project jabref by JabRef.

the class GroupTreeController method initialize.

@FXML
public void initialize() {
    viewModel = new GroupTreeViewModel(stateManager, dialogService, taskExecutor);
    // Set-up groups tree
    groupTree.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    // Set-up bindings
    Consumer<ObservableList<GroupNodeViewModel>> updateSelectedGroups = (newSelectedGroups) -> newSelectedGroups.forEach(this::selectNode);
    Consumer<List<TreeItem<GroupNodeViewModel>>> updateViewModel = (newSelectedGroups) -> {
        if (newSelectedGroups == null) {
            viewModel.selectedGroupsProperty().clear();
        } else {
            viewModel.selectedGroupsProperty().setAll(newSelectedGroups.stream().map(TreeItem::getValue).collect(Collectors.toList()));
        }
    };
    BindingsHelper.bindContentBidirectional(groupTree.getSelectionModel().getSelectedItems(), viewModel.selectedGroupsProperty(), updateSelectedGroups, updateViewModel);
    viewModel.filterTextProperty().bind(searchField.textProperty());
    groupTree.rootProperty().bind(EasyBind.map(viewModel.rootGroupProperty(), group -> new RecursiveTreeItem<>(group, GroupNodeViewModel::getChildren, GroupNodeViewModel::expandedProperty, viewModel.filterPredicateProperty())));
    // Icon and group name
    mainColumn.setCellValueFactory(cellData -> cellData.getValue().valueProperty());
    mainColumn.setCellFactory(new ViewModelTreeTableCellFactory<GroupNodeViewModel, GroupNodeViewModel>().withText(GroupNodeViewModel::getDisplayName).withIcon(GroupNodeViewModel::getIconCode, GroupNodeViewModel::getColor).withTooltip(GroupNodeViewModel::getDescription));
    // Number of hits
    PseudoClass anySelected = PseudoClass.getPseudoClass("any-selected");
    PseudoClass allSelected = PseudoClass.getPseudoClass("all-selected");
    numberColumn.setCellFactory(new ViewModelTreeTableCellFactory<GroupNodeViewModel, GroupNodeViewModel>().withGraphic(group -> {
        final StackPane node = new StackPane();
        node.getStyleClass().setAll("hits");
        if (!group.isRoot()) {
            BindingsHelper.includePseudoClassWhen(node, anySelected, group.anySelectedEntriesMatchedProperty());
            BindingsHelper.includePseudoClassWhen(node, allSelected, group.allSelectedEntriesMatchedProperty());
        }
        Text text = new Text();
        text.textProperty().bind(group.getHits().asString());
        text.getStyleClass().setAll("text");
        node.getChildren().add(text);
        node.setMaxWidth(Control.USE_PREF_SIZE);
        return node;
    }));
    // Arrow indicating expanded status
    disclosureNodeColumn.setCellValueFactory(cellData -> cellData.getValue().valueProperty());
    disclosureNodeColumn.setCellFactory(new ViewModelTreeTableCellFactory<GroupNodeViewModel, GroupNodeViewModel>().withGraphic(viewModel -> {
        final StackPane disclosureNode = new StackPane();
        disclosureNode.visibleProperty().bind(viewModel.hasChildrenProperty());
        disclosureNode.getStyleClass().setAll("tree-disclosure-node");
        final StackPane disclosureNodeArrow = new StackPane();
        disclosureNodeArrow.getStyleClass().setAll("arrow");
        disclosureNode.getChildren().add(disclosureNodeArrow);
        return disclosureNode;
    }).withOnMouseClickedEvent(group -> event -> group.toggleExpansion()));
    // Set pseudo-classes to indicate if row is root or sub-item ( > 1 deep)
    PseudoClass rootPseudoClass = PseudoClass.getPseudoClass("root");
    PseudoClass subElementPseudoClass = PseudoClass.getPseudoClass("sub");
    // Pseudo-classes for drag and drop
    PseudoClass dragOverBottom = PseudoClass.getPseudoClass("dragOver-bottom");
    PseudoClass dragOverCenter = PseudoClass.getPseudoClass("dragOver-center");
    PseudoClass dragOverTop = PseudoClass.getPseudoClass("dragOver-top");
    groupTree.setRowFactory(treeTable -> {
        TreeTableRow<GroupNodeViewModel> row = new TreeTableRow<>();
        row.treeItemProperty().addListener((ov, oldTreeItem, newTreeItem) -> {
            boolean isRoot = newTreeItem == treeTable.getRoot();
            row.pseudoClassStateChanged(rootPseudoClass, isRoot);
            boolean isFirstLevel = (newTreeItem != null) && (newTreeItem.getParent() == treeTable.getRoot());
            row.pseudoClassStateChanged(subElementPseudoClass, !isRoot && !isFirstLevel);
        });
        row.setDisclosureNode(null);
        row.disclosureNodeProperty().addListener((observable, oldValue, newValue) -> row.setDisclosureNode(null));
        row.contextMenuProperty().bind(EasyBind.monadic(row.itemProperty()).map(this::createContextMenuForGroup).orElse((ContextMenu) null));
        row.setOnDragDetected(event -> {
            TreeItem<GroupNodeViewModel> selectedItem = treeTable.getSelectionModel().getSelectedItem();
            if ((selectedItem != null) && (selectedItem.getValue() != null)) {
                Dragboard dragboard = treeTable.startDragAndDrop(TransferMode.MOVE);
                dragboard.setDragView(row.snapshot(null, null));
                ClipboardContent content = new ClipboardContent();
                content.put(DragAndDropDataFormats.GROUP, selectedItem.getValue().getPath());
                dragboard.setContent(content);
                event.consume();
            }
        });
        row.setOnDragOver(event -> {
            Dragboard dragboard = event.getDragboard();
            if ((event.getGestureSource() != row) && row.getItem().acceptableDrop(dragboard)) {
                event.acceptTransferModes(TransferMode.MOVE, TransferMode.LINK);
                removePseudoClasses(row, dragOverBottom, dragOverCenter, dragOverTop);
                switch(getDroppingMouseLocation(row, event)) {
                    case BOTTOM:
                        row.pseudoClassStateChanged(dragOverBottom, true);
                        break;
                    case CENTER:
                        row.pseudoClassStateChanged(dragOverCenter, true);
                        break;
                    case TOP:
                        row.pseudoClassStateChanged(dragOverTop, true);
                        break;
                }
            }
            event.consume();
        });
        row.setOnDragExited(event -> {
            removePseudoClasses(row, dragOverBottom, dragOverCenter, dragOverTop);
        });
        row.setOnDragDropped(event -> {
            Dragboard dragboard = event.getDragboard();
            boolean success = false;
            if (dragboard.hasContent(DragAndDropDataFormats.GROUP)) {
                String pathToSource = (String) dragboard.getContent(DragAndDropDataFormats.GROUP);
                Optional<GroupNodeViewModel> source = viewModel.rootGroupProperty().get().getChildByPath(pathToSource);
                if (source.isPresent()) {
                    source.get().draggedOn(row.getItem(), getDroppingMouseLocation(row, event));
                    success = true;
                }
            }
            if (dragboard.hasContent(DragAndDropDataFormats.ENTRIES)) {
                TransferableEntrySelection entrySelection = (TransferableEntrySelection) dragboard.getContent(DragAndDropDataFormats.ENTRIES);
                row.getItem().addEntriesToGroup(entrySelection.getSelection());
                success = true;
            }
            event.setDropCompleted(success);
            event.consume();
        });
        return row;
    });
    // Filter text field
    setupClearButtonField(searchField);
}
Also used : PseudoClass(javafx.css.PseudoClass) TreeItem(javafx.scene.control.TreeItem) Control(javafx.scene.control.Control) BindingsHelper(org.jabref.gui.util.BindingsHelper) DialogService(org.jabref.gui.DialogService) StackPane(javafx.scene.layout.StackPane) DragEvent(javafx.scene.input.DragEvent) TreeTableRow(javafx.scene.control.TreeTableRow) TransferMode(javafx.scene.input.TransferMode) Inject(javax.inject.Inject) TextFields(org.controlsfx.control.textfield.TextFields) TreeTableView(javafx.scene.control.TreeTableView) Dragboard(javafx.scene.input.Dragboard) ContextMenu(javafx.scene.control.ContextMenu) Localization(org.jabref.logic.l10n.Localization) Method(java.lang.reflect.Method) RecursiveTreeItem(org.jabref.gui.util.RecursiveTreeItem) ObjectProperty(javafx.beans.property.ObjectProperty) TextField(javafx.scene.control.TextField) MenuItem(javafx.scene.control.MenuItem) AbstractController(org.jabref.gui.AbstractController) Collectors(java.util.stream.Collectors) InvocationTargetException(java.lang.reflect.InvocationTargetException) Consumer(java.util.function.Consumer) FXML(javafx.fxml.FXML) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) Text(javafx.scene.text.Text) TreeTableColumn(javafx.scene.control.TreeTableColumn) TaskExecutor(org.jabref.gui.util.TaskExecutor) List(java.util.List) ActionEvent(javafx.event.ActionEvent) StateManager(org.jabref.gui.StateManager) SelectionMode(javafx.scene.control.SelectionMode) DragAndDropDataFormats(org.jabref.gui.DragAndDropDataFormats) EasyBind(org.fxmisc.easybind.EasyBind) ViewModelTreeTableCellFactory(org.jabref.gui.util.ViewModelTreeTableCellFactory) Optional(java.util.Optional) Log(org.apache.commons.logging.Log) ObservableList(javafx.collections.ObservableList) ClipboardContent(javafx.scene.input.ClipboardContent) LogFactory(org.apache.commons.logging.LogFactory) CustomTextField(org.controlsfx.control.textfield.CustomTextField) PseudoClass(javafx.css.PseudoClass) ViewModelTreeTableCellFactory(org.jabref.gui.util.ViewModelTreeTableCellFactory) ClipboardContent(javafx.scene.input.ClipboardContent) Text(javafx.scene.text.Text) ContextMenu(javafx.scene.control.ContextMenu) RecursiveTreeItem(org.jabref.gui.util.RecursiveTreeItem) ObservableList(javafx.collections.ObservableList) List(java.util.List) ObservableList(javafx.collections.ObservableList) TreeTableRow(javafx.scene.control.TreeTableRow) StackPane(javafx.scene.layout.StackPane) Dragboard(javafx.scene.input.Dragboard) FXML(javafx.fxml.FXML)

Example 4 with Dragboard

use of javafx.scene.input.Dragboard in project POL-POM-5 by PlayOnLinux.

the class StepRepresentationBrowse method dragPane.

private Node dragPane() {
    final Text textLabel = new Text(textToShow);
    final Text dragLabel = new Text("Please click here, or drag a file to me.");
    textLabel.getStyleClass().add("boldLabel");
    dragLabel.getStyleClass().addAll("normalLabel");
    final VBox dragTarget = new VBox();
    dragTarget.getChildren().addAll(textLabel, dragLabel);
    dragTarget.setOnDragOver(event -> {
        if (event.getGestureSource() != dragTarget && event.getDragboard().hasFiles()) {
            event.acceptTransferModes(TransferMode.COPY_OR_MOVE);
        }
        event.consume();
    });
    dragTarget.setOnDragDropped(event -> {
        Dragboard db = event.getDragboard();
        boolean success = false;
        if (db.hasFiles()) {
            this.selectFile(db.getFiles().get(0));
            success = true;
        }
        event.setDropCompleted(success);
        event.consume();
    });
    dragTarget.setPrefSize(660, 308);
    dragTarget.getStyleClass().addAll("dragAndDropBox");
    dragTarget.setOnMouseClicked(event -> {
        final FileChooser fileChooser = new FileChooser();
        if (extensions != null) {
            fileChooser.setSelectedExtensionFilter(new FileChooser.ExtensionFilter(tr("Allowed files"), extensions));
        }
        fileChooser.setInitialDirectory(browseDirectory);
        File dialogResult = fileChooser.showOpenDialog(null);
        if (dialogResult != null) {
            selectFile(dialogResult);
        }
    });
    return dragTarget;
}
Also used : FileChooser(javafx.stage.FileChooser) Text(javafx.scene.text.Text) VBox(javafx.scene.layout.VBox) File(java.io.File) Dragboard(javafx.scene.input.Dragboard)

Example 5 with Dragboard

use of javafx.scene.input.Dragboard in project POL-POM-5 by PlayOnLinux.

the class DragableRepositoryListCell method changed.

@Override
public void changed(ObservableValue<? extends Number> observableValue, Number oldValue, Number newValue) {
    setOnDragDetected(event -> {
        if (getItem() == null) {
            return;
        }
        Dragboard dragboard = startDragAndDrop(TransferMode.MOVE);
        ClipboardContent content = new ClipboardContent();
        content.putString(getItem());
        dragboard.setContent(content);
        event.consume();
    });
    setOnDragOver(event -> {
        event.acceptTransferModes(TransferMode.MOVE);
        event.consume();
    });
    setOnDragEntered(event -> {
        setOpacity(0.3);
    });
    setOnDragExited(event -> {
        setOpacity(1);
    });
    setOnDragDropped(event -> {
        if (getItem() == null) {
            return;
        }
        Dragboard db = event.getDragboard();
        boolean success = false;
        if (db.hasString()) {
            ObservableList<String> items = getListView().getItems();
            int draggedIdx = items.indexOf(db.getString());
            int thisIdx = items.indexOf(getItem());
            items.set(draggedIdx, getItem());
            items.set(thisIdx, db.getString());
            List<String> itemscopy = new ArrayList<>(getListView().getItems());
            getListView().getItems().setAll(itemscopy);
            success = true;
        }
        event.setDropCompleted(success);
        event.consume();
    });
    setOnDragDone(event -> {
        onDragDone.accept(getItem(), newValue);
        event.consume();
    });
}
Also used : ClipboardContent(javafx.scene.input.ClipboardContent) ArrayList(java.util.ArrayList) Dragboard(javafx.scene.input.Dragboard)

Aggregations

Dragboard (javafx.scene.input.Dragboard)5 ClipboardContent (javafx.scene.input.ClipboardContent)3 FXML (javafx.fxml.FXML)2 Text (javafx.scene.text.Text)2 YoutubeQuality (com.github.axet.vget.vhs.YouTubeInfo.YoutubeQuality)1 File (java.io.File)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Optional (java.util.Optional)1 Consumer (java.util.function.Consumer)1 Collectors (java.util.stream.Collectors)1 ObjectProperty (javafx.beans.property.ObjectProperty)1 ObservableList (javafx.collections.ObservableList)1 PseudoClass (javafx.css.PseudoClass)1 ActionEvent (javafx.event.ActionEvent)1 SnapshotParameters (javafx.scene.SnapshotParameters)1 ContextMenu (javafx.scene.control.ContextMenu)1 Control (javafx.scene.control.Control)1