Compare commits
1 Commits
master
...
Dockable-C
Author | SHA1 | Date | |
---|---|---|---|
de0f1a6e37 |
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user