Adds unfinished code showing the idea of how dockable tabs are supposed to be implemented
All checks were successful
KnarCraft/Minecraft-Server-Launcher/pipeline/head This commit looks good

This commit is contained in:
Kristian Knarvik 2021-10-03 14:23:25 +02:00
parent 166d63f1b2
commit de0f1a6e37
2 changed files with 96 additions and 0 deletions

View File

@ -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 <p>The id of this tabbed pane</p>
*/
public String getTabbedPaneId() {
return tabbedPaneId;
}
}

View File

@ -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;
}
}