-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
20 changed files
with
1,641 additions
and
1,747 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
docking-api/src/ModernDocking/floating/DisplayPanelFloatListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.