Skip to content

Commit

Permalink
Overlay refactor. (#226)
Browse files Browse the repository at this point in the history
* Overlay refactor.
  • Loading branch information
andrewauclair authored Jun 28, 2024
1 parent 2ec448c commit 48400e3
Show file tree
Hide file tree
Showing 20 changed files with 1,641 additions and 1,747 deletions.
87 changes: 0 additions & 87 deletions demo-multi-app/basic_demo_layout.xml

This file was deleted.

11 changes: 6 additions & 5 deletions docking-api/src/ModernDocking/api/DockingAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ of this software and associated documentation files (the "Software"), to deal
import ModernDocking.exception.RootDockingPanelNotFoundException;
import ModernDocking.exception.RootDockingPanelRegistrationFailureException;
import ModernDocking.floating.FloatListener;
import ModernDocking.floating.Floating;
import ModernDocking.internal.*;
import ModernDocking.layouts.WindowLayout;
import ModernDocking.ui.ToolbarLocation;
Expand Down Expand Up @@ -218,7 +219,7 @@ public void registerDockingPanel(RootDockingPanelAPI panel, JFrame parent) {
}

rootPanels.put(parent, panel);
FloatListener.registerDockingWindow(this, parent, panel);
Floating.registerDockingWindow(this, parent, panel);

appStatePersister.addWindow(parent);
}
Expand All @@ -239,7 +240,7 @@ public void registerDockingPanel(RootDockingPanelAPI panel, JDialog parent) {
}

rootPanels.put(parent, panel);
FloatListener.registerDockingWindow(this, parent, panel);
Floating.registerDockingWindow(this, parent, panel);

appStatePersister.addWindow(parent);
}
Expand All @@ -257,7 +258,7 @@ public void deregisterDockingPanel(Window parent) {
}

rootPanels.remove(parent);
FloatListener.deregisterDockingWindow(parent);
Floating.deregisterDockingWindow(parent);

appStatePersister.removeWindow(parent);
}
Expand Down Expand Up @@ -645,15 +646,15 @@ public void undock(Dockable dockable) {
DockingListeners.fireUndockedEvent(dockable);

// make sure that can dispose this window, and we're not floating the last dockable in it
if (canDisposeWindow(window) && root.isEmpty() && !FloatListener.isFloating()) {
if (canDisposeWindow(window) && root.isEmpty() && !Floating.isFloating()) {
deregisterDockingPanel(window);
window.dispose();
}

appState.persist();

// force this dockable to dock again if we're not floating it
if (!dockable.isClosable() && !FloatListener.isFloating() && !deregistering) {
if (!dockable.isClosable() && !Floating.isFloating() && !deregistering) {
dock(dockable, mainWindow);
}
}
Expand Down
7 changes: 0 additions & 7 deletions docking-api/src/ModernDocking/api/RootDockingPanelAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,6 @@ protected RootDockingPanelAPI(DockingAPI docking, Window window) {
setLayout(new GridBagLayout());
this.docking = docking;

if (window instanceof JFrame) {
docking.registerDockingPanel(this, (JFrame) window);
}
else {
docking.registerDockingPanel(this, (JDialog) window);
}

southToolbar = new DockableToolbar(docking, window, this, ToolbarLocation.SOUTH);
westToolbar = new DockableToolbar(docking, window, this, ToolbarLocation.WEST);
eastToolbar = new DockableToolbar(docking, window, this, ToolbarLocation.EAST);
Expand Down
126 changes: 126 additions & 0 deletions docking-api/src/ModernDocking/floating/DisplayPanelFloatListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/*
Copyright (c) 2024 Andrew Auclair
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
package ModernDocking.floating;

import ModernDocking.Dockable;
import ModernDocking.DockingRegion;
import ModernDocking.api.DockingAPI;
import ModernDocking.api.RootDockingPanelAPI;
import ModernDocking.internal.DisplayPanel;
import ModernDocking.internal.DockableWrapper;
import ModernDocking.internal.DockingComponentUtils;
import ModernDocking.internal.FloatingFrame;
import ModernDocking.settings.Settings;

import javax.swing.*;
import java.awt.*;
import java.awt.dnd.DragGestureEvent;
import java.util.Collections;

public class DisplayPanelFloatListener extends FloatListener {
private final DockingAPI docking;
private final DisplayPanel panel;

public DisplayPanelFloatListener(DockingAPI docking, DisplayPanel panel) {
super(docking, panel);
this.docking = docking;
this.panel = panel;
}

public DisplayPanelFloatListener(DockingAPI docking, DisplayPanel panel, JComponent dragComponent) {
super(docking, panel, dragComponent);
this.docking = docking;
this.panel = panel;
}

@Override
protected boolean allowDrag(DragGestureEvent dragGestureEvent) {
return true;
}

public Dockable getDockable() {
return panel.getWrapper().getDockable();
}

@Override
protected Window getOriginalWindow() {
return panel.getWrapper().getWindow();
}

@Override
protected void undock() {
docking.undock(panel.getWrapper().getDockable());
}

@Override
protected JFrame createFloatingFrame() {
if (Settings.alwaysDisplayTabsMode(panel.getWrapper().getDockable())) {
return new TempFloatingFrame(Collections.singletonList(panel.getWrapper()), 0, panel, panel.getSize());
}
return new TempFloatingFrame(panel.getWrapper(), panel, panel.getSize());
}

@Override
protected boolean dropPanel(FloatUtilsFrame utilsFrame, JFrame floatingFrame, Point mousePosOnScreen) {
DockableWrapper floatingDockable = panel.getWrapper();

if (utilsFrame != null) {
Window targetFrame = DockingComponentUtils.findRootAtScreenPos(docking, mousePosOnScreen);
RootDockingPanelAPI root = DockingComponentUtils.rootForWindow(docking, targetFrame);

if (utilsFrame.isOverRootHandle()) {
docking.dock(floatingDockable.getDockable(), targetFrame, utilsFrame.rootHandleRegion());
}
else if (utilsFrame.isOverDockableHandle()) {
Dockable dockableAtPos = DockingComponentUtils.findDockableAtScreenPos(mousePosOnScreen, targetFrame);

docking.dock(floatingDockable.getDockable(), dockableAtPos, utilsFrame.dockableHandle());
}
else if (utilsFrame.isOverPinHandle()) {
docking.unpinDockable(floatingDockable.getDockable(), utilsFrame.pinRegion(), targetFrame, root);
}
else if (utilsFrame.isOverTab()) {
// TODO get the tab index, if none then we're adding to the end

// TODO get the tab panel and add panel, dock it I think?
}
else {
// docking to a dockable region
Dockable dockableAtPos = DockingComponentUtils.findDockableAtScreenPos(mousePosOnScreen, targetFrame);

DockingRegion region = utilsFrame.getDockableRegion(dockableAtPos, panel.getWrapper().getDockable(), mousePosOnScreen);

docking.dock(floatingDockable.getDockable(), dockableAtPos, region);
}
}
else if (floatingDockable.getDockable().isFloatingAllowed()) {
// floating
FloatingFrame newFloatingFrame = new FloatingFrame(docking, floatingDockable.getDockable(), mousePosOnScreen, floatingDockable.getDisplayPanel().getSize(), 0);
docking.dock(floatingDockable.getDockable(), newFloatingFrame);
}
else {
// failed to dock, restore the previous layout
return false;
}
return true;
}
}
Loading

0 comments on commit 48400e3

Please sign in to comment.