Skip to content

Commit

Permalink
More Fixes for Floating (#121)
Browse files Browse the repository at this point in the history
Fixing the issue with dragging completely not working.

Fixing some minor UI display issues with the new tab reordering overlay.
  • Loading branch information
andrewauclair authored Nov 16, 2023
1 parent 57bbfc7 commit 8b2607c
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 12 deletions.
36 changes: 28 additions & 8 deletions docking-api/src/ModernDocking/floating/FloatListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ private FloatListener(DockingAPI docking, JPanel dockable, JComponent dragSource
SwingUtilities.convertPointToScreen(mousePos, dragSource1);

DockedTabbedPanel tabs = (DockedTabbedPanel) source;

// if this tabbed panel is empty then remove the listeners
if (tabs.getDockables().isEmpty()) {
removeListeners();
return;
}

int targetTabIndex = tabs.getTargetTabIndex(mousePos);

if (targetTabIndex != -1) {
Expand Down Expand Up @@ -205,10 +212,11 @@ private void updateFramePosition(Point mousePosOnScreen) {
boolean overTab = dockable == null && tabbedPane != null && floatingPanel instanceof DisplayPanel;

if (overTab) {
int targetTabIndex = tabbedPane.getTargetTabIndex(mousePosOnScreen);
int targetTabIndex = tabbedPane.getTargetTabIndex(mousePosOnScreen, true);

Rectangle boundsAt;
boolean last = false;

if (targetTabIndex != -1) {
boundsAt = tabbedPane.getBoundsAt(targetTabIndex);

Expand All @@ -222,12 +230,24 @@ private void updateFramePosition(Point mousePosOnScreen) {
} else {
boundsAt = tabbedPane.getBoundsAt(tabbedPane.getTabCount() - 1);

Point p = new Point(boundsAt.x, boundsAt.y);
SwingUtilities.convertPointToScreen(p, tabbedPane);
SwingUtilities.convertPointFromScreen(p, activeUtilsFrame);
boundsAt.x = p.x;
boundsAt.y = p.y;
boundsAt.x += boundsAt.width;
Point tabPoint = new Point(tabbedPane.getX(), tabbedPane.getY());
SwingUtilities.convertPointToScreen(tabPoint, tabbedPane.getParent());

Point boundsPoint = new Point(boundsAt.x, boundsAt.y);
SwingUtilities.convertPointToScreen(boundsPoint, tabbedPane);

int widthToAdd = boundsAt.width;

if (boundsPoint.x + (boundsAt.width * 2) >= tabPoint.x + tabbedPane.getWidth()) {
boundsAt.width = Math.abs((tabPoint.x + tabbedPane.getWidth()) - (boundsPoint.x + boundsAt.width));
System.out.println("New width : " + boundsAt.width);
}

SwingUtilities.convertPointFromScreen(boundsPoint, activeUtilsFrame);

boundsAt.x = boundsPoint.x + widthToAdd;
boundsAt.y = boundsPoint.y;

last = true;
}

Expand Down Expand Up @@ -406,7 +426,7 @@ else if (dockableAtPos == null && root != null) {
if (tabbedPane != null) {
DockedTabbedPanel parent = (DockedTabbedPanel) tabbedPane.getParent();

int targetTabIndex = tabbedPane.getTargetTabIndex(point);
int targetTabIndex = tabbedPane.getTargetTabIndex(point, true);

Rectangle boundsAt;

Expand Down
7 changes: 6 additions & 1 deletion docking-api/src/ModernDocking/internal/CustomTabbedPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@
import java.util.stream.IntStream;

public class CustomTabbedPane extends JTabbedPane {
public int getTargetTabIndex(Point mousePosOnScreen) {
public int getTargetTabIndex(Point mousePosOnScreen, boolean ignoreY) {
SwingUtilities.convertPointFromScreen(mousePosOnScreen, this);

Point d = isTopBottomTabPlacement(getTabPlacement()) ? new Point(1, 0) : new Point(0, 1);

for (int i = 0; i < getTabCount(); i++) {
Rectangle tab = getBoundsAt(i);

if (ignoreY) {
// we only care to check the x value
mousePosOnScreen.y = tab.y;
}

if (tab.contains(mousePosOnScreen)) {
return i;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,6 @@ public void addNotify() {

@Override
public void removeNotify() {
floatListener.removeListeners();

tabs.removeChangeListener(this);

super.removeNotify();
Expand Down Expand Up @@ -432,7 +430,7 @@ public void updateTabInfo(Dockable dockable) {
}

public int getTargetTabIndex(Point point) {
return tabs.getTargetTabIndex(point);
return tabs.getTargetTabIndex(point, false);
}

public boolean isDraggingFromTabGutter(Point point) {
Expand Down
24 changes: 24 additions & 0 deletions docking-api/src/ModernDocking/layouts/DockingTabPanelNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ public DockingTabPanelNode(DockingAPI docking, String selectedTabID, Map<String,
*/
public void addTab(String persistentID) {
if (findNode(persistentID) != null) {
DockingSimplePanelNode node = null;
for (DockingSimplePanelNode tab : tabs) {
if (persistentID.equals(tab.getPersistentID())) {
node = tab;
}
}

// this is the selected tab, bump it up into the correct order
if (node != null) {
tabs.remove(node);
tabs.add(node);
}
return;
}
String className = DockingInternal.get(docking).getDockable(persistentID).getClass().getCanonicalName();
Expand All @@ -89,6 +101,18 @@ public void addTab(String persistentID) {
*/
public void addTab(String persistentID, Map<String, String> properties) {
if (findNode(persistentID) != null) {
DockingSimplePanelNode node = null;
for (DockingSimplePanelNode tab : tabs) {
if (persistentID.equals(tab.getPersistentID())) {
node = tab;
}
}

// this is the selected tab, bump it up into the correct order
if (node != null) {
tabs.remove(node);
tabs.add(node);
}
return;
}
String className = DockingInternal.get(docking).getDockable(persistentID).getClass().getCanonicalName();
Expand Down

0 comments on commit 8b2607c

Please sign in to comment.