Skip to content

Commit

Permalink
Fix double title bars with grouped floating frames
Browse files Browse the repository at this point in the history
A new `DialogFloatingContainer` implementation (`SingleTitleBarDialogFloatingContainer`) is provided which always leaves
itself undecorated, but which will decorate the root pane with dialog decorations when needed. The border is also always
set to a resize border rather than sometimes having it and sometimes not. A new `DockingManager`
implementation (`MapToolDockingManager`) is needed just to instantiate `SingleTitleBarDialogFloatingContainer`.
  • Loading branch information
kwvanderlinde committed Aug 27, 2023
1 parent c20e5da commit 339d417
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/main/java/net/rptools/maptool/client/ui/MapToolFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.google.common.eventbus.Subscribe;
import com.jidesoft.docking.DefaultDockableHolder;
import com.jidesoft.docking.DockableFrame;
import com.jidesoft.docking.DockingManager;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
Expand Down Expand Up @@ -71,6 +72,7 @@
import net.rptools.maptool.client.ui.assetpanel.AssetPanel;
import net.rptools.maptool.client.ui.commandpanel.CommandPanel;
import net.rptools.maptool.client.ui.connections.ClientConnectionPanel;
import net.rptools.maptool.client.ui.docking.MapToolDockingManager;
import net.rptools.maptool.client.ui.drawpanel.DrawPanelPopupMenu;
import net.rptools.maptool.client.ui.drawpanel.DrawPanelTreeCellRenderer;
import net.rptools.maptool.client.ui.drawpanel.DrawPanelTreeModel;
Expand Down Expand Up @@ -619,6 +621,11 @@ public DockableFrame getFrame(MTFrame frame) {
return frameMap.get(frame);
}

@Override
protected DockingManager createDockingManager(Container container) {
return new MapToolDockingManager(this, container);
}

private void initializeFrames() {
frameMap.put(
MTFrame.CONNECTIONS,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* This software Copyright by the RPTools.net development team, and
* licensed under the Affero GPL Version 3 or, at your option, any later
* version.
*
* MapTool Source Code is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public
* License * along with this source Code. If not, please visit
* <http://www.gnu.org/licenses/> and specifically the Affero license
* text at <http://www.gnu.org/licenses/agpl.html>.
*/
package net.rptools.maptool.client.ui.docking;

import com.jidesoft.docking.DefaultDockingManager;
import com.jidesoft.docking.DialogFloatingContainer;
import java.awt.Container;
import java.awt.Dialog;
import java.awt.Frame;
import java.awt.Window;
import javax.swing.RootPaneContainer;

/**
* Custom docking manager that creates custom floating containers.
*
* <p>This is how to use {@link SingleTitleBarDialogFloatingContainer} instead of the default
* implementation.
*/
public class MapToolDockingManager extends DefaultDockingManager {
public MapToolDockingManager(RootPaneContainer rootPaneContainer, Container container) {
super(rootPaneContainer, container);
}

@Override
protected DialogFloatingContainer createDialogFloatingContainer(
InternalEventManager internalEventManager, Window window) {
if (window instanceof Dialog dialog) {
return new SingleTitleBarDialogFloatingContainer(this, internalEventManager, dialog);
}

if (window instanceof Frame frame) {
return new SingleTitleBarDialogFloatingContainer(this, internalEventManager, frame);
}

throw new UnsupportedOperationException(
"JIDE Docking Framework doesn't support floating frames if rootPaneContainer is "
+ (window == null ? "null" : window.getClass().getName()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* This software Copyright by the RPTools.net development team, and
* licensed under the Affero GPL Version 3 or, at your option, any later
* version.
*
* MapTool Source Code is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public
* License * along with this source Code. If not, please visit
* <http://www.gnu.org/licenses/> and specifically the Affero license
* text at <http://www.gnu.org/licenses/agpl.html>.
*/
package net.rptools.maptool.client.ui.docking;

import com.jidesoft.docking.DialogFloatingContainer;
import com.jidesoft.docking.DockingManager;
import com.jidesoft.docking.DockingUtils;
import com.jidesoft.plaf.UIDefaultsLookup;
import java.awt.Dialog;
import java.awt.Frame;
import java.awt.HeadlessException;
import javax.swing.JRootPane;

/**
* Container implementation that only decorates the root pane and not the dialog itself.
*
* <p>The default implementation ({@link com.jidesoft.docking.DialogFloatingContainer}) always
* decorates both the dialog and the root pane when decorations are requested, resulting in
* redundant title bars for docked floating frames.
*/
public class SingleTitleBarDialogFloatingContainer extends DialogFloatingContainer {
public SingleTitleBarDialogFloatingContainer(
DockingManager dockingManager, FloatingContainerManager floatingContainerManager, Frame frame)
throws HeadlessException {
super(dockingManager, floatingContainerManager, frame);
}

public SingleTitleBarDialogFloatingContainer(
DockingManager dockingManager,
FloatingContainerManager floatingContainerManager,
Dialog dialog)
throws HeadlessException {
super(dockingManager, floatingContainerManager, dialog);
}

@Override
public void updateUndecorated() {
this.setVisible(false); // So we can change the decorations.

this.setUndecorated(true);

final var dockingManager = this.getDockingManager();
final var contentPane = this.getContentPane();
if (DockingUtils.shouldUseDecoratedFloatingContainer(dockingManager, contentPane)) {
this.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);
} else {
this.getRootPane().setWindowDecorationStyle(JRootPane.NONE);
}
this.setBorder(UIDefaultsLookup.getBorder("Resizable.resizeBorder"));

this.updateBorders();

if (!this.getDockingManager().getMainContainer().isShowing()) {
return;
}

this.setVisible(true);
}
}

0 comments on commit 339d417

Please sign in to comment.