diff --git a/src/main/java/net/knarcraft/minecraftserverlauncher/userinterface/JDockableTabbedPane.java b/src/main/java/net/knarcraft/minecraftserverlauncher/userinterface/JDockableTabbedPane.java new file mode 100644 index 0000000..dc6d8e4 --- /dev/null +++ b/src/main/java/net/knarcraft/minecraftserverlauncher/userinterface/JDockableTabbedPane.java @@ -0,0 +1,35 @@ +package net.knarcraft.minecraftserverlauncher.userinterface; + +import javax.swing.*; + +/** + * An extended JTabbedPane with dockable tabs + */ +public class JDockableTabbedPane extends JTabbedPane { + + private String tabbedPaneId; + + public JDockableTabbedPane(String tabbedPaneId) { + super(); + this.tabbedPaneId = tabbedPaneId; + } + + public JDockableTabbedPane(String tabbedPaneId, int tabPlacement) { + super(tabPlacement); + this.tabbedPaneId = tabbedPaneId; + } + + public JDockableTabbedPane(String tabbedPaneId, int tabPlacement, int tabLayoutPolicy) { + super(tabPlacement, tabLayoutPolicy); + this.tabbedPaneId = tabbedPaneId; + } + + /** + * Gets the id of this tabbed pane + * @return
The id of this tabbed pane
+ */ + public String getTabbedPaneId() { + return tabbedPaneId; + } + +} diff --git a/src/main/java/net/knarcraft/minecraftserverlauncher/userinterface/TabDragListener.java b/src/main/java/net/knarcraft/minecraftserverlauncher/userinterface/TabDragListener.java new file mode 100644 index 0000000..c70b59f --- /dev/null +++ b/src/main/java/net/knarcraft/minecraftserverlauncher/userinterface/TabDragListener.java @@ -0,0 +1,61 @@ +package net.knarcraft.minecraftserverlauncher.userinterface; + +import javax.swing.event.MouseInputAdapter; +import java.awt.*; +import java.awt.event.MouseEvent; + +/** + * A listener for detecting the dragging of a tab to make it dock or undock + */ +public class TabDragListener extends MouseInputAdapter { + + Point dragStartPoint; + Component draggedComponent; + String draggedTabTitle; + JDockableTabbedPane tabbedPaneToListenTo; + + public TabDragListener(JDockableTabbedPane tabbedPaneToListenTo) { + this.tabbedPaneToListenTo = tabbedPaneToListenTo; + } + + @Override + public void mousePressed(MouseEvent e) { + dragStartPoint = e.getPoint(); + + //Loop through tabbed panes to find the dragged one + for (int i = 0; i < tabbedPaneToListenTo.getTabCount(); i++) { + Rectangle bounds = tabbedPaneToListenTo.getBoundsAt(i); + if (bounds.contains(dragStartPoint)) { + draggedComponent = tabbedPaneToListenTo.getComponentAt(i); + draggedTabTitle = tabbedPaneToListenTo.getTitleAt(i); + break; + } + } + } + + @Override + public void mouseDragged(MouseEvent e) { + Point dragEndPoint = e.getPoint(); + if (draggedComponent != null) { + // check for a significant drag + //TODO: Check if tab is dragged onto another JDockableTabbedPane with the same id + if (Math.abs(dragEndPoint.getY() - dragStartPoint.getY()) > 30) { + + //TODO: Undock by creating a new JDockableTabbedPane with the same id + //TODO: If dragging onto another JDockableTabbedPane with the same id, combine + //TODO: Make the listener keep track of all its created windows + //TODO: If a child window is closed, dock its tab to the main window + //TODO: Keep track of the original window vs. the child window + //undock(draggedComponent, draggedTabTitle); + draggedComponent = null; + } + } + } + + @Override + public void mouseReleased(MouseEvent arg0) { + draggedComponent = null; + draggedTabTitle = null; + } + +}