Skip to content

Commit

Permalink
Issue #179
Browse files Browse the repository at this point in the history
Creating a new InternalRootDockingPanel and moving most of the methods from RootDockingPanelAPI to it.

RootDockingPanelAPI extends JPanel instead of DockingPanel now.

No deprecation warning is being given for this change because all of these methods were already considered internal, but not explicitly documented as such.
  • Loading branch information
andrewauclair committed Jul 3, 2024
1 parent c3bc560 commit bdffd14
Show file tree
Hide file tree
Showing 16 changed files with 568 additions and 469 deletions.
87 changes: 25 additions & 62 deletions docking-api/src/ModernDocking/api/DockingAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,8 @@ public class DockingAPI {
// this may look unused, but we need to create an instance of it to make it work
private final ActiveDockableHighlighter activeDockableHighlighter = new ActiveDockableHighlighter(this);

private final AppStatePersister appStatePersister = new AppStatePersister(this);

// map of all the root panels in the application
private final Map<Window, RootDockingPanelAPI> rootPanels = new HashMap<>();
// private final Map<Window, InternalRootDockingPanel> rootPanels = new HashMap<>();

private final AppStateAPI appState = new AppStateAPI(this);
private final DockingStateAPI dockingState = new DockingStateAPI(this);
Expand Down Expand Up @@ -115,7 +113,9 @@ public void uninitialize() {
* @return map of root panels
*/
public Map<Window, RootDockingPanelAPI> getRootPanels() {
return rootPanels;
Map<Window, RootDockingPanelAPI> panels = new HashMap<>();
internals.getRootPanels().forEach((window, internalRootDockingPanel) -> panels.put(window, internalRootDockingPanel.getRootPanel()));
return panels;
}

/**
Expand Down Expand Up @@ -202,26 +202,7 @@ public List<Dockable> getDockables() {
* @param parent The parent frame of the panel
*/
public void registerDockingPanel(RootDockingPanelAPI panel, JFrame parent) {
if (rootPanels.containsKey(parent)) {
throw new RootDockingPanelRegistrationFailureException(panel, parent);
}

if (rootPanels.containsValue(panel)) {
// we already checked above that we have this value
//noinspection OptionalGetWithoutIsPresent
Window window = rootPanels.entrySet().stream()
.filter(entry -> entry.getValue() == panel)
.findFirst()
.map(Map.Entry::getKey)
.get();

throw new RootDockingPanelRegistrationFailureException(panel, window);
}

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

appStatePersister.addWindow(parent);
internals.registerDockingPanel(panel, parent);
}

/**
Expand All @@ -231,18 +212,7 @@ public void registerDockingPanel(RootDockingPanelAPI panel, JFrame parent) {
* @param parent The parent JDialog of the panel
*/
public void registerDockingPanel(RootDockingPanelAPI panel, JDialog parent) {
if (rootPanels.containsKey(parent)) {
throw new RootDockingPanelRegistrationFailureException(panel, parent);
}

if (rootPanels.containsValue(panel)) {
throw new RootDockingPanelRegistrationFailureException(panel, parent);
}

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

appStatePersister.addWindow(parent);
internals.registerDockingPanel(panel, parent);
}

/**
Expand All @@ -251,16 +221,7 @@ public void registerDockingPanel(RootDockingPanelAPI panel, JDialog parent) {
* @param parent The parent of the panel that we're deregistering
*/
public void deregisterDockingPanel(Window parent) {
if (rootPanels.containsKey(parent)) {
RootDockingPanelAPI root = rootPanels.get(parent);

DockingComponentUtils.undockComponents(this, root);
}

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

appStatePersister.removeWindow(parent);
internals.deregisterDockingPanel(parent);
}

/**
Expand Down Expand Up @@ -295,13 +256,13 @@ public void configurePinning(Window window, int layer, boolean allow) {
* @param allow Whether auto hide is allowed on this Window
*/
public void configureAutoHide(Window window, int layer, boolean allow) {
if (!rootPanels.containsKey(window)) {
if (!internals.getRootPanels().containsKey(window)) {
throw new RootDockingPanelNotFoundException(window);
}

RootDockingPanelAPI root = DockingComponentUtils.rootForWindow(this, window);
root.setAutoHideSupported(allow);
root.setAutoHideLayer(layer);
InternalRootDockingPanel root = DockingComponentUtils.rootForWindow(this, window);
root.getRootPanel().setAutoHideSupported(allow);
root.getRootPanel().setAutoHideLayer(layer);
}

/**
Expand All @@ -319,9 +280,9 @@ public boolean pinningAllowed(Dockable dockable) {
* @return Whether the dockable can be pinned
*/
public boolean autoHideAllowed(Dockable dockable) {
RootDockingPanelAPI root = DockingComponentUtils.rootForWindow(this, DockingComponentUtils.findWindowForDockable(this, dockable));
InternalRootDockingPanel root = DockingComponentUtils.rootForWindow(this, DockingComponentUtils.findWindowForDockable(this, dockable));

return dockable.isAutoHideAllowed() && root.isAutoHideSupported();
return dockable.isAutoHideAllowed() && root.getRootPanel().isAutoHideSupported();
}

/**
Expand Down Expand Up @@ -369,7 +330,7 @@ public void dock(String persistentID, Window window, DockingRegion region) {
* @param region The region to dock into
*/
public void dock(Dockable dockable, Window window, DockingRegion region) {
RootDockingPanelAPI root = rootPanels.get(window);
InternalRootDockingPanel root = internals.getRootPanels().get(window);

if (root == null) {
throw new RootDockingPanelNotFoundException(window);
Expand Down Expand Up @@ -404,7 +365,7 @@ public void dock(String persistentID, Window window, DockingRegion region, doubl
* @param dividerProportion The proportion to use if docking in a split pane
*/
public void dock(Dockable dockable, Window window, DockingRegion region, double dividerProportion) {
RootDockingPanelAPI root = rootPanels.get(window);
InternalRootDockingPanel root = internals.getRootPanels().get(window);

if (root == null) {
throw new RootDockingPanelNotFoundException(window);
Expand Down Expand Up @@ -625,7 +586,7 @@ public void undock(Dockable dockable) {

Objects.requireNonNull(window);

RootDockingPanelAPI root = DockingComponentUtils.rootForWindow(this, window);
InternalRootDockingPanel root = DockingComponentUtils.rootForWindow(this, window);

Objects.requireNonNull(root);

Expand Down Expand Up @@ -736,7 +697,7 @@ public boolean isMaximized(Dockable dockable) {
*/
public void maximize(Dockable dockable) {
Window window = DockingComponentUtils.findWindowForDockable(this, dockable);
RootDockingPanelAPI root = DockingComponentUtils.rootForWindow(this, window);
InternalRootDockingPanel root = DockingComponentUtils.rootForWindow(this, window);

// can only maximize one panel per root
if (!dockingState.maximizeRestoreLayout.containsKey(window) && root != null) {
Expand Down Expand Up @@ -790,7 +751,7 @@ public void autoHideDockable(Dockable dockable) {
*/
public void pinDockable(Dockable dockable) {
Window window = DockingComponentUtils.findWindowForDockable(this, dockable);
RootDockingPanelAPI root = DockingComponentUtils.rootForWindow(this, window);
InternalRootDockingPanel root = DockingComponentUtils.rootForWindow(this, window);

if (internals.getWrapper(dockable).isHidden()) {
root.setDockableShown(dockable);
Expand All @@ -811,7 +772,7 @@ public void unpinDockable(Dockable dockable) {
}

Window window = DockingComponentUtils.findWindowForDockable(this, dockable);
RootDockingPanelAPI root = DockingComponentUtils.rootForWindow(this, window);
InternalRootDockingPanel root = DockingComponentUtils.rootForWindow(this, window);

Component component = (Component) dockable;

Expand Down Expand Up @@ -853,9 +814,9 @@ else if (east) {
*/
public void unpinDockable(Dockable dockable, ToolbarLocation location) {
Window window = DockingComponentUtils.findWindowForDockable(this, dockable);
RootDockingPanelAPI root = DockingComponentUtils.rootForWindow(this, window);
InternalRootDockingPanel root = DockingComponentUtils.rootForWindow(this, window);

unpinDockable(dockable, location, window, root);
unpinDockable(dockable, location, window, root.getRootPanel());
}

/**
Expand All @@ -868,11 +829,13 @@ public void unpinDockable(Dockable dockable, ToolbarLocation location, Window wi
return;
}

InternalRootDockingPanel internalRoot = internals.getRootPanels().get(window);

Component component = (Component) dockable;

Point posInFrame = component.getLocation();
SwingUtilities.convertPointToScreen(posInFrame, component.getParent());
SwingUtilities.convertPointFromScreen(posInFrame, root);
SwingUtilities.convertPointFromScreen(posInFrame, internalRoot);

posInFrame.x += component.getWidth() / 2;
posInFrame.y += component.getHeight() / 2;
Expand All @@ -886,7 +849,7 @@ public void unpinDockable(Dockable dockable, ToolbarLocation location, Window wi
internals.getWrapper(dockable).setWindow(window);
internals.getWrapper(dockable).setHidden(true);

root.setDockableHidden(dockable, location);
internalRoot.setDockableHidden(dockable, location);

DockingListeners.fireAutoHiddenEvent(dockable);
DockingListeners.fireHiddenEvent(dockable);
Expand Down
14 changes: 7 additions & 7 deletions docking-api/src/ModernDocking/api/DockingStateAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected DockingStateAPI(DockingAPI docking) {

@Deprecated(forRemoval = true)
public RootDockState getRootState(Window window) {
RootDockingPanelAPI root = DockingComponentUtils.rootForWindow(docking, window);
InternalRootDockingPanel root = DockingComponentUtils.rootForWindow(docking, window);

if (root == null) {
throw new RootDockingPanelNotFoundException(window);
Expand All @@ -68,7 +68,7 @@ public RootDockState getRootState(Window window) {
}

public WindowLayout getWindowLayout(Window window) {
RootDockingPanelAPI root = DockingComponentUtils.rootForWindow(docking, window);
InternalRootDockingPanel root = DockingComponentUtils.rootForWindow(docking, window);

if (root == null) {
throw new RootDockingPanelNotFoundException(window);
Expand All @@ -80,7 +80,7 @@ public WindowLayout getWindowLayout(Window window) {
return maxLayout;
}

return DockingLayouts.layoutFromRoot(docking, root);
return DockingLayouts.layoutFromRoot(docking, root.getRootPanel());
}

/**
Expand Down Expand Up @@ -146,7 +146,7 @@ public void restoreApplicationLayout(ApplicationLayout layout) {
* @param layout The layout to restore
*/
public void restoreWindowLayout(Window window, WindowLayout layout) {
RootDockingPanelAPI root = DockingComponentUtils.rootForWindow(docking, window);
InternalRootDockingPanel root = DockingComponentUtils.rootForWindow(docking, window);

if (root == null) {
throw new RootDockingPanelNotFoundException(window);
Expand All @@ -168,7 +168,7 @@ public void restoreWindowLayout(Window window, WindowLayout layout) {
// undock and destroy any failed dockables
undockFailedComponents(docking, root);

restoreProperSplitLocations(root);
restoreProperSplitLocations(root.getRootPanel());

for (String id : layout.getWestAutoHideToolbarIDs()) {
Dockable dockable = getDockable(docking, id);
Expand Down Expand Up @@ -220,7 +220,7 @@ public void restoreWindowLayout_PreserveSizeAndPos(Window window, WindowLayout l

@Deprecated(forRemoval = true)
public void restoreState(Window window, RootDockState state) {
RootDockingPanelAPI root = DockingComponentUtils.rootForWindow(docking, window);
InternalRootDockingPanel root = DockingComponentUtils.rootForWindow(docking, window);

if (root == null) {
throw new RootDockingPanelNotFoundException(window);
Expand All @@ -234,7 +234,7 @@ public void restoreState(Window window, RootDockState state) {
try {
root.setPanel(restoreState(docking, state.getState(), window));

restoreProperSplitLocations(root);
restoreProperSplitLocations(root.getRootPanel());
}
finally {
docking.getAppState().setPaused(paused);
Expand Down
Loading

0 comments on commit bdffd14

Please sign in to comment.