Commits

Jens Deters  committed 2ef84fa

Revert "Remove AWT Stack from TabPaneDetacher."

This reverts commit afb07c78491ec791cea54457939998417f293d26.

  • Participants
  • Parent commits 0e1131e

Comments (0)

Files changed (1)

File src/main/java/de/jensd/javafx/utils/TabPaneDetacher.java

  */
 package de.jensd.javafx.utils;
 
+import java.awt.MouseInfo;
+import java.awt.Point;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.SortedSet;
 import java.util.TreeSet;
-
 import javafx.scene.Cursor;
 import javafx.scene.Scene;
 import javafx.scene.SnapshotParameters;
 import javafx.scene.layout.Pane;
 import javafx.scene.transform.Transform;
 import javafx.stage.Stage;
+import javafx.stage.WindowEvent;
 
 /**
  * A simple Utility to make all {@link Tab}s of a {@link TabPane} detachable.
     private Tab currentTab;
     private final List<Tab> originalTabs;
     private final Map<Integer, Tab> tapTransferMap;
-    private MouseEvent mCurrentEvent;
     private String[] stylesheets;
 
     private TabPaneDetacher() {
         tabPane.getTabs().stream().forEach(t -> {
             t.setClosable(false);
         });
-        tabPane.setOnDragDetected(event -> {
-            if (event.getSource() instanceof TabPane) {
-                Pane rootPane = (Pane) tabPane.getScene().getRoot();
-                rootPane.setOnDragOver((DragEvent event1) -> {
-                    event1.acceptTransferModes(TransferMode.ANY);
-                    event1.consume();
-                });
-                currentTab = tabPane.getSelectionModel().getSelectedItem();
-                mCurrentEvent = event;
-                SnapshotParameters snapshotParams = new SnapshotParameters();
-                snapshotParams.setTransform(Transform.scale(0.4, 0.4));
-                WritableImage snapshot = currentTab.getContent().snapshot(snapshotParams, null);
-                Dragboard db = tabPane.startDragAndDrop(TransferMode.MOVE);
-                ClipboardContent clipboardContent = new ClipboardContent();
-                clipboardContent.put(DataFormat.PLAIN_TEXT, "detach");
-                db.setDragView(snapshot, 40, 40);
-                db.setContent(clipboardContent);
-            }
-            event.consume();
-        });
-        tabPane.setOnDragDone(event -> {
-            openTabInStage(currentTab,event);
-            tabPane.setCursor(Cursor.DEFAULT);
-            event.consume();
-        });
+        tabPane.setOnDragDetected(
+                (MouseEvent event) -> {
+                    if (event.getSource() instanceof TabPane) {
+                        Pane rootPane = (Pane) tabPane.getScene().getRoot();
+                        rootPane.setOnDragOver((DragEvent event1) -> {
+                            event1.acceptTransferModes(TransferMode.ANY);
+                            event1.consume();
+                        });
+                        currentTab = tabPane.getSelectionModel().getSelectedItem();
+                        SnapshotParameters snapshotParams = new SnapshotParameters();
+                        snapshotParams.setTransform(Transform.scale(0.4, 0.4));
+                        WritableImage snapshot = currentTab.getContent().snapshot(snapshotParams, null);
+                        Dragboard db = tabPane.startDragAndDrop(TransferMode.MOVE);
+                        ClipboardContent clipboardContent = new ClipboardContent();
+                        clipboardContent.put(DataFormat.PLAIN_TEXT, "detach");
+                        db.setDragView(snapshot, 40, 40);
+                        db.setContent(clipboardContent);
+                    }
+                    event.consume();
+                }
+        );
+        tabPane.setOnDragDone(
+                (DragEvent event) -> {
+                    openTabInStage(currentTab);
+                    tabPane.setCursor(Cursor.DEFAULT);
+                    event.consume();
+                }
+        );
         return this;
     }
 
      *
      * @param tab The {@link Tab} to get the content from.
      */
-    public void openTabInStage(final Tab tab, final DragEvent pDragEvent) {
+    public void openTabInStage(final Tab tab) {
         int originalTab = originalTabs.indexOf(tab);
         tapTransferMap.remove(originalTab);
         Pane content = (Pane) tab.getContent();
         Stage stage = new Stage();
         stage.setScene(scene);
         stage.setTitle(tab.getText());
-
-        double x = mCurrentEvent == null ? pDragEvent.getScreenX() : mCurrentEvent.getScreenX();
-        double y = mCurrentEvent == null ? pDragEvent.getScreenY() : mCurrentEvent.getScreenY();
-        stage.setX(x);
-        stage.setY(y);
-        
-        stage.setOnCloseRequest(t -> {
+        Point p = MouseInfo.getPointerInfo().getLocation();
+        stage.setX(p.x);
+        stage.setY(p.y);
+        stage.setOnCloseRequest((WindowEvent t) -> {
             stage.close();
             tab.setContent(content);
             int originalTabIndex = originalTabs.indexOf(tab);
             }
             tabPane.getSelectionModel().select(tab);
         });
-        stage.setOnShown(t -> tab.getTabPane().getTabs().remove(tab));
+        stage.setOnShown((WindowEvent t) -> {
+            tab.getTabPane().getTabs().remove(tab);
+        });
         stage.show();
     }