Skip to content

Commit

Permalink
Experiment for #97
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewauclair committed Nov 18, 2023
1 parent 945d031 commit 3b4939e
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 10 deletions.
7 changes: 7 additions & 0 deletions demo-single-app/src/basic/MainFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,13 @@ public void setVisible(boolean visible) {
view.add(changeText);
view.add(actionListenDock(themes));

JMenuItem openDockableTabGroup = new JMenuItem("DockableTabGroup");
openDockableTabGroup.addActionListener( e-> {
DockableTabGroup group = new DockableTabGroup(new JPopupMenu(), JTabbedPane.TOP);
Docking.dock(group, two, one, DockingRegion.EAST);
});
view.add(openDockableTabGroup);

JMenuItem storeCurrentLayout = new JMenuItem("Store Current Layout...");
storeCurrentLayout.addActionListener(e -> {
String layoutName = JOptionPane.showInputDialog("Name of Layout");
Expand Down
43 changes: 43 additions & 0 deletions docking-api/src/ModernDocking/DockableTabGroup.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
Copyright (c) 2023 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;

import javax.swing.*;

public class DockableTabGroup {
private final JPopupMenu contextMenu;
private final int tabPlacement;

public DockableTabGroup(JPopupMenu contextMenu, int tabPlacement) {

this.contextMenu = contextMenu;
this.tabPlacement = tabPlacement;
}

public JPopupMenu getContextMenu() {
return contextMenu;
}

public int getTabPlacement() {
return tabPlacement;
}
}
15 changes: 15 additions & 0 deletions docking-api/src/ModernDocking/api/DockingAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import ModernDocking.Dockable;
import ModernDocking.DockableStyle;
import ModernDocking.DockableTabGroup;
import ModernDocking.DockingRegion;
import ModernDocking.event.DockingListener;
import ModernDocking.event.MaximizeListener;
Expand Down Expand Up @@ -451,6 +452,20 @@ public void dock(Dockable source, Dockable target, DockingRegion region, double
appState.persist();
}

public void dock(DockableTabGroup group, Dockable firstDockable, Dockable target, DockingRegion region) {
if (!isDocked(target)) {
throw new NotDockedException(target);
}

if (isDocked(firstDockable)) {
undock(firstDockable);
}

DockableWrapper wrapper = internals.getWrapper(target);

wrapper.getParent().dock(group, firstDockable, region, 0.5);
}

/**
* create a new FloatingFrame window for the given dockable, undock it from its current frame (if there is one) and dock it into the new frame
*
Expand Down
37 changes: 37 additions & 0 deletions docking-api/src/ModernDocking/internal/DockedSimplePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ of this software and associated documentation files (the "Software"), to deal
package ModernDocking.internal;

import ModernDocking.Dockable;
import ModernDocking.DockableTabGroup;
import ModernDocking.DockingRegion;
import ModernDocking.api.DockingAPI;
import ModernDocking.floating.FloatListener;
Expand Down Expand Up @@ -150,6 +151,42 @@ else if (region == DockingRegion.CENTER) {
repaint();
}

@Override
public void dock(DockableTabGroup group, Dockable firstDockable, DockingRegion region, double dividerProportion) {
if (region == DockingRegion.CENTER) {
return;
}

DockableWrapper wrapper = DockingInternal.get(docking).getWrapper(firstDockable);

DockedSplitPanel split = new DockedSplitPanel(docking, this.dockable.getWindow());
parent.replaceChild(this, split);

DockingPanel newPanel = new DockedTabbedPanel(docking, group, wrapper);

if (region == DockingRegion.EAST || region == DockingRegion.SOUTH) {
split.setLeft(this);
split.setRight(newPanel);
dividerProportion = 1.0 - dividerProportion;
}
else {
split.setLeft(newPanel);
split.setRight(this);
}

if (region == DockingRegion.EAST || region == DockingRegion.WEST) {
split.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
}
else {
split.setOrientation(JSplitPane.VERTICAL_SPLIT);
}

split.setDividerLocation(dividerProportion);

repaint();
revalidate();
}

@Override
public void undock(Dockable dockable) {
if (this.dockable.getDockable() == dockable) {
Expand Down
35 changes: 25 additions & 10 deletions docking-api/src/ModernDocking/internal/DockedTabbedPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ of this software and associated documentation files (the "Software"), to deal
package ModernDocking.internal;

import ModernDocking.Dockable;
import ModernDocking.DockableTabGroup;
import ModernDocking.DockingRegion;
import ModernDocking.api.DockingAPI;
import ModernDocking.floating.FloatListener;
Expand Down Expand Up @@ -67,24 +68,35 @@ public class DockedTabbedPanel extends DockingPanel implements ChangeListener {

private static Icon settingsIcon = new ImageIcon(Objects.requireNonNull(DockedTabbedPanel.class.getResource("/icons/settings.png")));

private int tabPlacement;

/**
* Create a new instance of DockedTabbedPanel
*
* @param dockable The first dockable in the tabbed pane
*/
public DockedTabbedPanel(DockingAPI docking, DockableWrapper dockable) {
this(docking, dockable, Settings.alwaysDisplayTabsMode());
}

public DockedTabbedPanel(DockingAPI docking, DockableWrapper dockable, boolean topTabs) {
this.docking = docking;
setLayout(new BorderLayout());

// set the initial border. Docking handles the border after this using a global AWT listener
setNotSelectedBorder();

// we only support tabs on top if we have FlatLaf because we can add a trailing component for our menu
boolean usingFlatLaf = tabs.getUI().getClass().getPackageName().startsWith("com.formdev.flatlaf");

// default to tabs on bottom. if we need to change it we will when the first dockable is added
tabs.setTabPlacement(JTabbedPane.BOTTOM);
// tabs.setTabPlacement(JTabbedPane.BOTTOM);
tabPlacement = topTabs && usingFlatLaf ? JTabbedPane.TOP : JTabbedPane.BOTTOM;
tabs.setTabPlacement(tabPlacement);

tabs.setTabLayoutPolicy(Settings.getTabLayoutPolicy());

if (Settings.alwaysDisplayTabsMode()) {
if (topTabs) {
configureTrailingComponent();
}

Expand All @@ -93,6 +105,10 @@ public DockedTabbedPanel(DockingAPI docking, DockableWrapper dockable) {
addPanel(dockable);
}

public DockedTabbedPanel(DockingAPI docking, DockableTabGroup group, DockableWrapper firstDockable) {
this(docking, firstDockable, group.getTabPlacement() == JTabbedPane.TOP);
}

public static void setSettingsIcon(Icon icon) {
settingsIcon = icon;
}
Expand Down Expand Up @@ -171,15 +187,14 @@ public void removeNotify() {
* @param dockable The dockable to add
*/
public void addPanel(DockableWrapper dockable) {
// we only support tabs on top if we have FlatLaf because we can add a trailing component for our menu
boolean usingFlatLaf = tabs.getUI().getClass().getPackageName().startsWith("com.formdev.flatlaf");

if (Settings.alwaysDisplayTabsMode() && usingFlatLaf) {
tabs.setTabPlacement(JTabbedPane.TOP);
}
else {
tabs.setTabPlacement(JTabbedPane.BOTTOM);
}

// if (Settings.alwaysDisplayTabsMode() && usingFlatLaf) {
// tabs.setTabPlacement(JTabbedPane.TOP);
// }
// else {
// tabs.setTabPlacement(JTabbedPane.BOTTOM);
// }

panels.add(dockable);
tabs.add(dockable.getDockable().getTabText(), dockable.getDisplayPanel());
Expand Down
3 changes: 3 additions & 0 deletions docking-api/src/ModernDocking/internal/DockingPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ of this software and associated documentation files (the "Software"), to deal
package ModernDocking.internal;

import ModernDocking.Dockable;
import ModernDocking.DockableTabGroup;
import ModernDocking.DockingRegion;

import javax.swing.*;
Expand All @@ -46,6 +47,8 @@ public abstract class DockingPanel extends JPanel {
*/
public abstract void dock(Dockable dockable, DockingRegion region, double dividerProportion);

public void dock(DockableTabGroup group, Dockable firstDockable, DockingRegion region, double dividerProportion) {}

/**
* undock the given dockable, returns true if the dockable was found and removed
*
Expand Down
3 changes: 3 additions & 0 deletions docking-single-app/src/ModernDocking/Docking.java
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,9 @@ public static void dock(Dockable source, Dockable target, DockingRegion region,
instance.dock(source, target, region, dividerProportion);
}

public static void dock(DockableTabGroup group, Dockable firstDockable, Dockable target, DockingRegion region) {
instance.dock(group, firstDockable, target, region);
}
/**
* create a new FloatingFrame window for the given dockable, undock it from its current frame (if there is one) and dock it into the new frame
*
Expand Down

0 comments on commit 3b4939e

Please sign in to comment.