Skip to content

Commit

Permalink
Dockables can now indicate their tab preference (TOP or BOTTOM) and t…
Browse files Browse the repository at this point in the history
…his will be used when docking the dockable. (#143)

If any dockables in a tab group prefer TOP tabs, then the tab group will switch to top tabs. The tab group will continue to be top tabs even after all the dockables with TOP as the preference have been removed.
  • Loading branch information
andrewauclair authored Dec 3, 2023
1 parent 69ce480 commit b31692d
Show file tree
Hide file tree
Showing 14 changed files with 38 additions and 15 deletions.
7 changes: 7 additions & 0 deletions demo-single-app/src/basic/AlwaysDisplayedPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ of this software and associated documentation files (the "Software"), to deal
*/
package basic;

import javax.swing.*;

// Docking panel that is always displayed and cannot be closed
public class AlwaysDisplayedPanel extends SimplePanel {
// create a new basic.AlwaysDisplayedPanel with the given title and persistentID
Expand All @@ -42,4 +44,9 @@ public boolean isFloatingAllowed() {
public boolean isLimitedToRoot() {
return true;
}

@Override
public int getTabPosition() {
return SwingConstants.TOP;
}
}
4 changes: 4 additions & 0 deletions docking-api/src/ModernDocking/Dockable.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ default boolean getHasMoreOptions() {
return false;
}

default int getTabPosition() {
return SwingConstants.BOTTOM;
}

/**
* add the more options to the popup menu. defaults to an empty block to handle the case of hasMoreOptions() = false
*
Expand Down
2 changes: 1 addition & 1 deletion docking-api/src/ModernDocking/api/RootDockingPanelAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public void dock(Dockable dockable, DockingRegion region, double dividerProporti
if (panel != null) {
panel.dock(dockable, region, dividerProportion);
}
else if (Settings.alwaysDisplayTabsMode()) {
else if (Settings.alwaysDisplayTabsMode(dockable)) {
setPanel(new DockedTabbedPanel(docking, wrapper));
wrapper.setWindow(window);
}
Expand Down
2 changes: 1 addition & 1 deletion docking-api/src/ModernDocking/floating/FloatListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ public void mouseDragStarted(Point point) {
RootDockingPanelAPI currentRoot = DockingComponentUtils.rootForWindow(docking, originalWindow);

if (floatingPanel instanceof DisplayPanel) {
if (Settings.alwaysDisplayTabsMode()) {
if (Settings.alwaysDisplayTabsMode(((DisplayPanel) floatingPanel).getWrapper().getDockable())) {
floatingFrame = new TempFloatingFrame(Collections.singletonList(((DisplayPanel) floatingPanel).getWrapper()), 0, source, floatingPanel.getSize());
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public TempFloatingFrame(List<DockableWrapper> dockables, int selectedIndex, JCo
// 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) {
if (Settings.alwaysDisplayTabsMode(dockables.get(0).getDockable()) && usingFlatLaf) {
tabs.setTabPlacement(JTabbedPane.TOP);
}
else {
Expand Down
2 changes: 1 addition & 1 deletion docking-api/src/ModernDocking/internal/DisplayPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private void buildUI() {
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.weightx = 1.0;

if (!Settings.alwaysDisplayTabsMode() || wrapper.isUnpinned()) {
if (!Settings.alwaysDisplayTabsMode(wrapper.getDockable()) || wrapper.isUnpinned()) {
if (!(wrapper.getParent() instanceof DockedTabbedPanel) || ((DockedTabbedPanel) wrapper.getParent()).isUsingBottomTabs()) {
add((Component) wrapper.getHeaderUI(), gbc);
gbc.gridy++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ else if (region == DockingRegion.CENTER) {

DockingPanel newPanel;

if (Settings.alwaysDisplayTabsMode()) {
if (Settings.alwaysDisplayTabsMode(wrapper.getDockable())) {
newPanel = new DockedTabbedPanel(docking, wrapper);
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ public void dock(Dockable dockable, DockingRegion region, double dividerProporti

DockingPanel newPanel;

if (Settings.alwaysDisplayTabsMode()) {
if (Settings.alwaysDisplayTabsMode(wrapper.getDockable())) {
newPanel = new DockedTabbedPanel(docking, wrapper);
}
else {
Expand Down
15 changes: 10 additions & 5 deletions docking-api/src/ModernDocking/internal/DockedTabbedPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public DockedTabbedPanel(DockingAPI docking, 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) {
if (Settings.alwaysDisplayTabsMode(dockable.getDockable()) && usingFlatLaf) {
tabs.setTabPlacement(JTabbedPane.TOP);
}
else {
Expand All @@ -90,7 +90,7 @@ public DockedTabbedPanel(DockingAPI docking, DockableWrapper dockable) {

tabs.setTabLayoutPolicy(Settings.getTabLayoutPolicy());

if (Settings.alwaysDisplayTabsMode()) {
if (Settings.alwaysDisplayTabsMode(dockable.getDockable())) {
configureTrailingComponent();
}

Expand Down Expand Up @@ -179,12 +179,17 @@ public void addPanel(DockableWrapper dockable) {
panels.add(dockable);
tabs.add(dockable.getDockable().getTabText(), dockable.getDisplayPanel());

// if any of the dockables use top tab position, switch this tabbedpanel to top tabs
if (tabs.getTabPlacement() != SwingConstants.TOP && dockable.getDockable().getTabPosition() == SwingConstants.TOP) {
tabs.setTabPlacement(SwingConstants.TOP);
}

tabs.setToolTipTextAt(tabs.getTabCount() - 1, dockable.getDockable().getTabTooltip());
tabs.setIconAt(tabs.getTabCount() - 1, dockable.getDockable().getIcon());
tabs.setSelectedIndex(tabs.getTabCount() - 1);
selectedTab = tabs.getSelectedIndex();

if (Settings.alwaysDisplayTabsMode() && dockable.getDockable().isClosable()) {
if (Settings.alwaysDisplayTabsMode(dockable.getDockable()) && dockable.getDockable().isClosable()) {
dockable.getDisplayPanel().putClientProperty("JTabbedPane.tabClosable", true);
}

Expand Down Expand Up @@ -235,7 +240,7 @@ public void dock(Dockable dockable, DockingRegion region, double dividerProporti

DockingPanel newPanel;

if (Settings.alwaysDisplayTabsMode()) {
if (Settings.alwaysDisplayTabsMode(wrapper.getDockable())) {
newPanel = new DockedTabbedPanel(docking, wrapper);
}
else {
Expand Down Expand Up @@ -290,7 +295,7 @@ public void dockAtIndex(Dockable dockable, int index) {
public void undock(Dockable dockable) {
removePanel(DockingInternal.get(docking).getWrapper(dockable));

if (!Settings.alwaysDisplayTabsMode() && tabs.getTabCount() == 1 && parent != null) {
if (!Settings.alwaysDisplayTabsMode(dockable) && tabs.getTabCount() == 1 && parent != null) {
parent.replaceChild(this, new DockedSimplePanel(docking, panels.get(0)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void dock(String persistentID, DockingRegion region, double dividerPropor
if (node != null) {
node.dock(persistentID, region, dividerProportion);
}
else if (Settings.alwaysDisplayTabsMode()) {
else if (Settings.alwaysDisplayTabsMode(DockingInternal.get(docking).getDockable(persistentID))) {
node = new DockingTabPanelNode(docking, persistentID);
node.setParent(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ of this software and associated documentation files (the "Software"), to deal

import ModernDocking.DockingRegion;
import ModernDocking.api.DockingAPI;
import ModernDocking.internal.DockingInternal;
import ModernDocking.settings.Settings;

import javax.swing.*;
Expand Down Expand Up @@ -100,7 +101,7 @@ else if (region == DockingRegion.CENTER) {
DockingLayoutNode left;
DockingLayoutNode right;

if (Settings.alwaysDisplayTabsMode()) {
if (Settings.alwaysDisplayTabsMode(DockingInternal.get(docking).getDockable(persistentID))) {
if (orientation == JSplitPane.HORIZONTAL_SPLIT) {
left = region == DockingRegion.EAST ? this : new DockingTabPanelNode(docking, persistentID);
right = region == DockingRegion.EAST ? new DockingTabPanelNode(docking, persistentID) : this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void dock(String persistentID, DockingRegion region, double dividerPropor
DockingLayoutNode left;
DockingLayoutNode right;

if (Settings.alwaysDisplayTabsMode()) {
if (Settings.alwaysDisplayTabsMode(DockingInternal.get(docking).getDockable(persistentID))) {
left = region == DockingRegion.NORTH || region == DockingRegion.WEST ? new DockingTabPanelNode(docking, persistentID) : this;
right = region == DockingRegion.NORTH || region == DockingRegion.WEST ? this : new DockingTabPanelNode(docking, persistentID);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public void dock(String persistentID, DockingRegion region, double dividerPropor
DockingLayoutNode left;
DockingLayoutNode right;

if (Settings.alwaysDisplayTabsMode()) {
if (Settings.alwaysDisplayTabsMode(DockingInternal.get(docking).getDockable(persistentID))) {
left = region == DockingRegion.NORTH || region == DockingRegion.WEST ? new DockingTabPanelNode(docking, persistentID) : this;
right = region == DockingRegion.NORTH || region == DockingRegion.WEST ? this : new DockingTabPanelNode(docking, persistentID);
}
Expand Down
6 changes: 6 additions & 0 deletions docking-api/src/ModernDocking/settings/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ of this software and associated documentation files (the "Software"), to deal
*/
package ModernDocking.settings;

import ModernDocking.Dockable;

import javax.swing.*;

public class Settings {
Expand All @@ -32,6 +34,10 @@ public static boolean alwaysDisplayTabsMode() {
return alwaysDisplayTabsMode;
}

public static boolean alwaysDisplayTabsMode(Dockable dockable) {
return alwaysDisplayTabsMode || dockable.getTabPosition() == SwingConstants.TOP;
}

public static void setAlwaysDisplayTabMode(boolean alwaysDisplayTabsMode) {
Settings.alwaysDisplayTabsMode = alwaysDisplayTabsMode;
}
Expand Down

0 comments on commit b31692d

Please sign in to comment.