Skip to content

Commit

Permalink
Rename Pin/Unpin Feature to Auto-Hide (#163)
Browse files Browse the repository at this point in the history
* WIP

Some of the renames are done.

* Update to Gradle 8.5 (#144)

* Module Improvements. (#146)

Modern Docking modules work properly now.

* Docking UI extension settings icon color can now be set to a different UIManager property. (#154)

* The internal package is now only exported to the other modern docking modules. (#155)

* Disable the focus on the JTabbedPanes used for docking and add support for alt + left arrow and alt + right arrow to move between tabs. (#160)

* Scrolling panel with toolbar at top example. (#159)

* The internal package is now only exported to the other modern docking modules. (#167)

* Fixing exception related to aalto-xml usage. (#172)

* Fixing docking-single-app dependencies. (#173)

* Fixing docking-single-app dependencies.

* Notes to future me to not mess this up again.

* Making an official 0.11 release so that we can make some API changes for a 0.12-SNAPSHOT release. (#177)

* Fixes for #174, #175 and #176 for exception improvements. (#178)

* Fixes for #174, #175 and #176 for exception improvements.

* Make sure we're on 0.12.0-SNAPSHOT in main after this change.

* More changes for auto hide.
  • Loading branch information
andrewauclair authored Jun 22, 2024
1 parent fbe68a4 commit c48292e
Show file tree
Hide file tree
Showing 28 changed files with 297 additions and 176 deletions.
2 changes: 1 addition & 1 deletion demo-single-app/src/basic/Example.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public boolean isClosable() {
}

@Override
public boolean isPinningAllowed() {
public boolean isAutoHideAllowed() {
return false;
}

Expand Down
2 changes: 2 additions & 0 deletions demo-single-app/src/basic/MainFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ of this software and associated documentation files (the "Software"), to deal

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.io.File;
import java.util.Objects;
import java.util.Random;
Expand Down
4 changes: 2 additions & 2 deletions demo-single-app/src/basic/ToolPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public DockableStyle getStyle() {
}

@Override
public DockableStyle getPinningStyle() {
public DockableStyle getAutoHideStyle() {
return style;
}

Expand All @@ -82,7 +82,7 @@ public boolean isClosable() {
}

@Override
public boolean isPinningAllowed() {
public boolean isAutoHideAllowed() {
return true;
}

Expand Down
4 changes: 0 additions & 4 deletions demo-single-app/src/examples/Pinning.java

This file was deleted.

2 changes: 1 addition & 1 deletion demo-single-app/src/packets/PacketInfoPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public boolean isClosable() {
}

@Override
public boolean isPinningAllowed() {
public boolean isAutoHideAllowed() {
return true;
}

Expand Down
34 changes: 25 additions & 9 deletions docking-api/src/ModernDocking/Dockable.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,20 @@ default DockableStyle getStyle() {
}

/**
* pinning style of the dockable. separate from getStyle, which is used for docking. this option allows the dockable to have different
* preferences on pinning than it does on docking.
*
* @return The pinning style of this dockable
* @deprecated Replaced with getAutoHideStyle. Will be removed in future release.
*/
@Deprecated(since = "0.12.0", forRemoval = true)
default DockableStyle getPinningStyle() {
return getAutoHideStyle();
}

/**
* auto hide style of the dockable. separate from getStyle, which is used for docking. this option allows the dockable to have different
* preferences on auto hide than it does on docking.
*
* @return The auto hide style of this dockable
*/
default DockableStyle getAutoHideStyle() {
return DockableStyle.BOTH;
}

Expand All @@ -136,13 +144,21 @@ default boolean isClosable() {
}

/**
* helper function to determine if the header pin option should be enabled
* NOTE: this is a suggestion. If the parent frame of the dockable does not support pinning then the button will be hidden regardless.
* pinning is supported on all Modern Docking FloatingFrames and can be enabled for other frames with configurePinning in Docking
*
* @return True if pinning is allowed
* @deprecated Replaced with isAutoHideAllowed. Will be removed in future release.
*/
@Deprecated(since = "0.12.0", forRemoval = true)
default boolean isPinningAllowed() {
return isAutoHideAllowed();
}

/**
* helper function to determine if the header auto hide option should be enabled
* NOTE: this is a suggestion. If the parent frame of the dockable does not support auto hiding then the button will be hidden regardless.
* auto hide is supported on all Modern Docking FloatingFrames and can be enabled for other frames with configureAutoHide in Docking
*
* @return True if auto hide is allowed
*/
default boolean isAutoHideAllowed() {
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions docking-api/src/ModernDocking/api/AppStateAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@ public void actionPerformed(ActionEvent e) {

DockingLayouts.layoutPersisted(layout);

logger.log(Level.INFO, "ModernDocking: Persisted Layout Successfully");
logger.log(Level.FINE, "ModernDocking: Persisted Layout Successfully");
}
catch (DockingLayoutException ex) {
logger.log(Level.INFO, ex.getMessage(), ex);
logger.log(Level.WARNING, ex.getMessage(), ex);
}
}
// we're done with the timer for now. null it out
Expand Down
76 changes: 50 additions & 26 deletions docking-api/src/ModernDocking/api/DockingAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -279,20 +279,36 @@ public void deregisterAllDockingPanels() {
}

/**
* allows the user to configure pinning per window. by default pinning is only enabled on the frames the docking framework creates
*
* @param window The window to configure pinning on
* @param layer The layout to use for pinning in the JLayeredPane
* @param allow Whether pinning is allowed on this Window
* @deprecated Replaced with configureAutoHide. Will be removed in a future release.
*/
@Deprecated(since = "0.12.0", forRemoval = true)
public void configurePinning(Window window, int layer, boolean allow) {
configureAutoHide(window, layer, allow);
}

/**
* allows the user to configure auto hide per window. by default auto hide is only enabled on the frames the docking framework creates
*
* @param window The window to configure auto hide on
* @param layer The layout to use for auto hide in the JLayeredPane
* @param allow Whether auto hide is allowed on this Window
*/
public void configureAutoHide(Window window, int layer, boolean allow) {
if (!rootPanels.containsKey(window)) {
throw new RootDockingPanelNotFoundException(window);
}

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

/**
* @deprecated Replaced with configureAutoHide. Will be removed in a future release.
*/
@Deprecated(since = "0.12.0", forRemoval = true)
public boolean pinningAllowed(Dockable dockable) {
return autoHideAllowed(dockable);
}

/**
Expand All @@ -301,10 +317,10 @@ public void configurePinning(Window window, int layer, boolean allow) {
* @param dockable Dockable to check
* @return Whether the dockable can be pinned
*/
public boolean pinningAllowed(Dockable dockable) {
public boolean autoHideAllowed(Dockable dockable) {
RootDockingPanelAPI root = DockingComponentUtils.rootForWindow(this, DockingComponentUtils.findWindowForDockable(this, dockable));

return dockable.isPinningAllowed() && root.isPinningSupported();
return dockable.isAutoHideAllowed() && root.isAutoHideSupported();
}

/**
Expand Down Expand Up @@ -616,10 +632,10 @@ public void undock(Dockable dockable) {

wrapper.setRoot(root);

if (isUnpinned(dockable)) {
if (isHidden(dockable)) {
root.undock(dockable);
wrapper.setParent(null);
wrapper.setUnpinned(false);
wrapper.setHidden(false);
}
else {
wrapper.getParent().undock(dockable);
Expand Down Expand Up @@ -668,8 +684,8 @@ public boolean isDocked(Dockable dockable) {
* @param persistentID The persistentID of the dockable to check
* @return Whether the dockable is unpinned
*/
public boolean isUnpinned(String persistentID) {
return isUnpinned(internals.getDockable(persistentID));
public boolean isHidden(String persistentID) {
return isHidden(internals.getDockable(persistentID));
}

/**
Expand All @@ -678,8 +694,8 @@ public boolean isUnpinned(String persistentID) {
* @param dockable The dockable to check
* @return Whether the dockable is unpinned
*/
public boolean isUnpinned(Dockable dockable) {
return internals.getWrapper(dockable).isUnpinned();
public boolean isHidden(Dockable dockable) {
return internals.getWrapper(dockable).isHidden();
}

/**
Expand Down Expand Up @@ -758,6 +774,14 @@ public void minimize(Dockable dockable) {
}
}

public void autoShowDockable(Dockable dockable) {
pinDockable(dockable);
}

public void autoHideDockable(Dockable dockable) {
unpinDockable(dockable);
}

/**
* pin a dockable. only valid if the dockable is unpinned
*
Expand All @@ -767,12 +791,12 @@ public void pinDockable(Dockable dockable) {
Window window = DockingComponentUtils.findWindowForDockable(this, dockable);
RootDockingPanelAPI root = DockingComponentUtils.rootForWindow(this, window);

if (internals.getWrapper(dockable).isUnpinned()) {
root.setDockablePinned(dockable);
if (internals.getWrapper(dockable).isHidden()) {
root.setDockableShown(dockable);

internals.getWrapper(dockable).setUnpinned(false);
internals.getWrapper(dockable).setHidden(false);

DockingListeners.firePinnedEvent(dockable);
DockingListeners.fireAutoShownEvent(dockable);
}
}

Expand All @@ -781,7 +805,7 @@ public void pinDockable(Dockable dockable) {
* @param dockable Dockable to unpin
*/
public void unpinDockable(Dockable dockable) {
if (isUnpinned(dockable)) {
if (isHidden(dockable)) {
return;
}

Expand All @@ -797,7 +821,7 @@ public void unpinDockable(Dockable dockable) {
posInFrame.x += component.getWidth() / 2;
posInFrame.y += component.getHeight() / 2;

boolean allowedSouth = dockable.getPinningStyle() == DockableStyle.BOTH || dockable.getPinningStyle() == DockableStyle.HORIZONTAL;
boolean allowedSouth = dockable.getAutoHideStyle() == DockableStyle.BOTH || dockable.getAutoHideStyle() == DockableStyle.HORIZONTAL;

int westDist = posInFrame.x;
int eastDist = window.getWidth() - posInFrame.x;
Expand Down Expand Up @@ -839,7 +863,7 @@ public void unpinDockable(Dockable dockable, ToolbarLocation location) {
* @param location Toolbar location to unpin the dockable to
*/
public void unpinDockable(Dockable dockable, ToolbarLocation location, Window window, RootDockingPanelAPI root) {
if (isUnpinned(dockable)) {
if (isHidden(dockable)) {
return;
}

Expand All @@ -852,18 +876,18 @@ public void unpinDockable(Dockable dockable, ToolbarLocation location, Window wi
posInFrame.x += component.getWidth() / 2;
posInFrame.y += component.getHeight() / 2;

if (!root.isPinningSupported()) {
if (!root.isAutoHideSupported()) {
return;
}
undock(dockable);

// reset the window, undocking the dockable sets it to null
internals.getWrapper(dockable).setWindow(window);
internals.getWrapper(dockable).setUnpinned(true);
internals.getWrapper(dockable).setHidden(true);

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

DockingListeners.fireUnpinnedEvent(dockable);
DockingListeners.fireAutoHiddenEvent(dockable);
DockingListeners.fireHiddenEvent(dockable);
}

Expand Down
24 changes: 12 additions & 12 deletions docking-api/src/ModernDocking/api/DockingStateAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,25 +170,25 @@ public void restoreWindowLayout(Window window, WindowLayout layout) {

restoreProperSplitLocations(root);

for (String id : layout.getWestUnpinnedToolbarIDs()) {
for (String id : layout.getWestAutoHideToolbarIDs()) {
Dockable dockable = getDockable(docking, id);
root.setDockableUnpinned(dockable, ToolbarLocation.WEST);
root.hideUnpinnedPanels();
getWrapper(dockable).setUnpinned(true);
root.setDockableHidden(dockable, ToolbarLocation.WEST);
root.hideHiddenPanels();
getWrapper(dockable).setHidden(true);
}

for (String id : layout.getEastUnpinnedToolbarIDs()) {
for (String id : layout.getEastAutoHideToolbarIDs()) {
Dockable dockable = getDockable(docking, id);
root.setDockableUnpinned(dockable, ToolbarLocation.EAST);
root.hideUnpinnedPanels();
getWrapper(dockable).setUnpinned(true);
root.setDockableHidden(dockable, ToolbarLocation.EAST);
root.hideHiddenPanels();
getWrapper(dockable).setHidden(true);
}

for (String id : layout.getSouthUnpinnedToolbarIDs()) {
for (String id : layout.getSouthAutoHideToolbarIDs()) {
Dockable dockable = getDockable(docking, id);
root.setDockableUnpinned(dockable, ToolbarLocation.SOUTH);
root.hideUnpinnedPanels();
getWrapper(dockable).setUnpinned(true);
root.setDockableHidden(dockable, ToolbarLocation.SOUTH);
root.hideHiddenPanels();
getWrapper(dockable).setHidden(true);
}

if (layout.getMaximizedDockable() != null) {
Expand Down
12 changes: 6 additions & 6 deletions docking-api/src/ModernDocking/api/LayoutPersistenceAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ private void saveLayoutToFile(XMLStreamWriter writer, WindowLayout layout, boole
writer.writeStartElement("westToolbar");
writer.writeCharacters(NL);

for (String id : layout.getWestUnpinnedToolbarIDs()) {
for (String id : layout.getWestAutoHideToolbarIDs()) {
writer.writeStartElement("dockable");
writer.writeAttribute("id", id);
writer.writeEndElement();
Expand All @@ -249,7 +249,7 @@ private void saveLayoutToFile(XMLStreamWriter writer, WindowLayout layout, boole
writer.writeStartElement("eastToolbar");
writer.writeCharacters(NL);

for (String id : layout.getEastUnpinnedToolbarIDs()) {
for (String id : layout.getEastAutoHideToolbarIDs()) {
writer.writeStartElement("dockable");
writer.writeAttribute("id", id);
writer.writeEndElement();
Expand All @@ -261,7 +261,7 @@ private void saveLayoutToFile(XMLStreamWriter writer, WindowLayout layout, boole
writer.writeStartElement("southToolbar");
writer.writeCharacters(NL);

for (String id : layout.getSouthUnpinnedToolbarIDs()) {
for (String id : layout.getSouthAutoHideToolbarIDs()) {
writer.writeStartElement("dockable");
writer.writeAttribute("id", id);
writer.writeEndElement();
Expand Down Expand Up @@ -439,9 +439,9 @@ private WindowLayout readLayoutFromReader(XMLStreamReader reader) throws XMLStre

WindowLayout layout = new WindowLayout(isMainFrame, location, size, state, readNodeFromFile(reader, "layout"));

layout.setWestUnpinnedToolbarIDs(westToolbar);
layout.setEastUnpinnedToolbarIDs(eastToolbar);
layout.setSouthUnpinnedToolbarIDs(southToolbar);
layout.setWestAutoHideToolbarIDs(westToolbar);
layout.setEastAutoHideToolbarIDs(eastToolbar);
layout.setSouthAutoHideToolbarIDs(southToolbar);

layout.setMaximizedDockable(maximizedDockable);

Expand Down
Loading

0 comments on commit c48292e

Please sign in to comment.