Skip to content

Commit

Permalink
Updates to drag drop support
Browse files Browse the repository at this point in the history
  • Loading branch information
Col-E committed Dec 14, 2020
1 parent 211d255 commit e25aa5f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 10 deletions.
44 changes: 37 additions & 7 deletions src/main/java/me/coley/recaf/ui/controls/SplitableTabPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
*/
public class SplitableTabPane extends TabPane {
private static final SnapshotParameters SNAPSHOT_PARAMETERS;
private static final String DROP_TARGET_STYLE = "drag-target";
private static final String TAB_DRAG_KEY = "split-tab";
private static final ObjectProperty<Tab> draggedTab = new SimpleObjectProperty<>();

Expand All @@ -46,6 +47,24 @@ public SplitableTabPane() {
dragEvent.consume();
}
});
setOnDragEntered(dragEvent -> {
Dragboard dragboard = dragEvent.getDragboard();
if (dragboard.hasString()
&& TAB_DRAG_KEY.equals(dragboard.getString())
&& draggedTab.get() != null
&& draggedTab.get().getTabPane() != selfPane) {
addStyle();
}
});
setOnDragExited(dragEvent -> {
Dragboard dragboard = dragEvent.getDragboard();
if (dragboard.hasString()
&& TAB_DRAG_KEY.equals(dragboard.getString())
&& draggedTab.get() != null
&& draggedTab.get().getTabPane() != selfPane) {
removeStyle();
}
});
// Setup start drag
setOnDragDetected(mouseEvent -> {
if (mouseEvent.getSource() instanceof TabPane) {
Expand All @@ -71,6 +90,7 @@ public SplitableTabPane() {
createTabStage(dragged).show();
setCursor(Cursor.DEFAULT);
dragEvent.consume();
removeStyle();
}
});
// Setup end dragging in the case where this is the tab-pane target
Expand All @@ -79,15 +99,18 @@ public SplitableTabPane() {
Tab dragged = draggedTab.get();
if (dragboard.hasString()
&& TAB_DRAG_KEY.equals(dragboard.getString())
&& dragged != null
&& dragged.getTabPane() != selfPane) {
SplitableTabPane owner = (SplitableTabPane) dragged.getTabPane();
owner.closeTab(dragged);
getTabs().add(dragged);
getSelectionModel().select(dragged);
&& dragged != null) {
if ( dragged.getTabPane() != selfPane)
{
SplitableTabPane owner = (SplitableTabPane) dragged.getTabPane();
owner.closeTab(dragged);
getTabs().add(dragged);
getSelectionModel().select(dragged);
}
dragEvent.setDropCompleted(true);
draggedTab.set(null);
dragEvent.consume();
removeStyle();
}
});
}
Expand Down Expand Up @@ -137,7 +160,6 @@ protected Stage createTabStage(Tab tab) {
BorderPane root = new BorderPane(tabPaneCopy);
Scene scene = new Scene(root, root.getPrefWidth(), root.getPrefHeight());
Stage stage = createStage(tab.getText(), scene);
stage.setTitle(tab.getText());
// Set location to mouse
Point mouseLocation = MouseInfo.getPointerInfo().getLocation();
stage.setX(mouseLocation.getX());
Expand Down Expand Up @@ -169,6 +191,14 @@ protected SplitableTabPane newTabPane() {
return new SplitableTabPane();
}

private void addStyle() {
getStyleClass().add(DROP_TARGET_STYLE);
}

private void removeStyle() {
getStyleClass().remove(DROP_TARGET_STYLE);
}

static {
SNAPSHOT_PARAMETERS = new SnapshotParameters();
SNAPSHOT_PARAMETERS.setTransform(Transform.scale(0.4, 0.4));
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/me/coley/recaf/ui/controls/ViewportTabs.java
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,8 @@ public void select(Tab tab) {

@Override
protected Stage createStage(String title, Scene scene) {
// Change title
title = "Split view";
// Create and update the stage
Stage stage = super.createStage(title, scene);
Stage stage = super.createStage("Split view", scene);
stage.getIcons().add(new Image(resource("icons/logo.png")));
controller.windows().reapplyStyle(scene);
return stage;
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/style/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
.monospaced {
-fx-font-family: 'monospaced';
}
.drag-target {
-fx-effect: innershadow(one-pass-box, rgba(15, 200, 255), 50, 0.333, 0, 0);
}
/* =========================
* == JFX Controls ==
* =========================
Expand Down

0 comments on commit e25aa5f

Please sign in to comment.