repo
stringclasses
1k values
file_url
stringlengths
96
373
file_path
stringlengths
11
294
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
6 values
commit_sha
stringclasses
1k values
retrieved_at
stringdate
2026-01-04 14:45:56
2026-01-04 18:30:23
truncated
bool
2 classes
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-api/src/io/github/andrewauclair/moderndocking/layouts/ApplicationLayout.java
docking-api/src/io/github/andrewauclair/moderndocking/layouts/ApplicationLayout.java
/* Copyright (c) 2022 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 io.github.andrewauclair.moderndocking.layouts; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; /** * Layout of the entire application, including all open frames with docking roots */ public class ApplicationLayout { private static class FrameLayout { private final WindowLayout layout; private final boolean isMainFrame; private FrameLayout(WindowLayout layout, boolean isMainFrame) { this.layout = layout; this.isMainFrame = isMainFrame; } } /** * List of all the FrameLayouts in this ApplicationLayout */ private final List<FrameLayout> layouts = new ArrayList<>(); /** * Create an empty ApplicationLayout */ public ApplicationLayout() { } /** * Create an ApplicationLayout from a WindowLayout * @param mainFrame Layout of the application main frame */ public ApplicationLayout(WindowLayout mainFrame) { layouts.add(new FrameLayout(mainFrame, true)); } /** * Add a WindowLayout as the main frame * <p> * Note: This will remove the current main frame layout in this ApplicationLayout, if one exists * * @param layout Layout of the application main frame */ public void setMainFrame(WindowLayout layout) { for (FrameLayout frameLayout : layouts) { if (frameLayout.isMainFrame) { layouts.remove(frameLayout); break; } } layouts.add(new FrameLayout(layout, true)); } /** * Add a new WindowLayout * * @param layout Layout to add to this ApplicationLayout */ public void addFrame(WindowLayout layout) { layouts.add(new FrameLayout(layout, layout.isMainFrame())); } /** * Get the layout of the main frame stored in this ApplicationLayout * * @return The layout of the main frame, or null, if there is no main frame layout */ public WindowLayout getMainFrameLayout() { for (FrameLayout frameLayout : layouts) { if (frameLayout.isMainFrame) { return frameLayout.layout; } } return null; } /** * Get all the floating frame layouts in this ApplicationLayout * * @return All layouts in this ApplicationLayout that are not the main frame */ public List<WindowLayout> getFloatingFrameLayouts() { return layouts.stream() .filter(layout -> !layout.isMainFrame) .map(layout -> layout.layout) .collect(Collectors.toList()); } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-api/src/io/github/andrewauclair/moderndocking/layouts/DockingLayoutNode.java
docking-api/src/io/github/andrewauclair/moderndocking/layouts/DockingLayoutNode.java
/* Copyright (c) 2022 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 io.github.andrewauclair.moderndocking.layouts; import io.github.andrewauclair.moderndocking.DockingRegion; /** * Base interface for docking layout nodes, simple, split, tab and empty */ public interface DockingLayoutNode { /** * Find a node in the layout * * @param persistentID Persistent ID to search for * @return The layout node, if found. null if not found. */ DockingLayoutNode findNode(String persistentID); /** * Dock a new persistent ID into this node * * @param persistentID Persistent ID of dockable to add * @param region Region to dock into * @param dividerProportion Proportion to use if in a splitpane */ void dock(String persistentID, DockingRegion region, double dividerProportion); /** * Replace an existing layout node child * * @param child Child to replace * @param newChild Child to add */ void replaceChild(DockingLayoutNode child, DockingLayoutNode newChild); /** * Get the parent of this node * * @return Parent of node, null if root. */ DockingLayoutNode getParent(); /** * Set the parent of this node * * @param parent New parent */ void setParent(DockingLayoutNode parent); }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-api/src/io/github/andrewauclair/moderndocking/layouts/DockingSimplePanelNode.java
docking-api/src/io/github/andrewauclair/moderndocking/layouts/DockingSimplePanelNode.java
/* Copyright (c) 2022-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 io.github.andrewauclair.moderndocking.layouts; import io.github.andrewauclair.moderndocking.Dockable; import io.github.andrewauclair.moderndocking.DockingRegion; import io.github.andrewauclair.moderndocking.Property; import io.github.andrewauclair.moderndocking.api.DockingAPI; import io.github.andrewauclair.moderndocking.internal.DockingInternal; import io.github.andrewauclair.moderndocking.settings.Settings; import java.util.Collections; import java.util.HashMap; import java.util.Map; import javax.swing.JSplitPane; /** * Docking layout node for a simple panel. A that contains a single dockable. */ public class DockingSimplePanelNode implements DockingLayoutNode { private final DockingAPI docking; private final String persistentID; private final String className; private String anchor = ""; private String titleText; private String tabText; private Map<String, Property> properties = new HashMap<>(); private DockingLayoutNode parent; /** * Create a new DockingSimplePanelNode with just a persistent ID * * @param docking The docking instance for this node * @param persistentID The persistent ID of the contained dockable * @param className The name of the dockable class to instantiate, if dockable is not found * @param anchor The anchor associated with this node */ public DockingSimplePanelNode(DockingAPI docking, String persistentID, String className, String anchor, String titleText, String tabText) { this.docking = docking; this.persistentID = persistentID; this.className = className; this.anchor = anchor; this.titleText = titleText; this.tabText = tabText; } /** * Create a new DockingSimplePanelNode with properties * * @param docking The docking instance for this node * @param persistentID The persistent ID of the contained dockable * @param className The name of the dockable class to instantiate, if dockable is not found * @param anchor The anchor associated with this node * @param properties Properties of the dockable */ public DockingSimplePanelNode(DockingAPI docking, String persistentID, String className, String anchor, String titleText, String tabText, Map<String, Property> properties) { this.docking = docking; this.persistentID = persistentID; this.className = className; this.anchor = anchor; this.titleText = titleText; this.tabText = tabText; this.properties.putAll(properties); } @Override public DockingLayoutNode getParent() { return parent; } public void setParent(DockingLayoutNode parent) { this.parent = parent; } @Override public DockingLayoutNode findNode(String persistentID) { if (this.persistentID.equals(persistentID)) { return this; } return null; } @Override public void dock(String persistentID, DockingRegion region, double dividerProportion) { if (getParent() instanceof DockingTabPanelNode) { getParent().dock(persistentID, region, dividerProportion); } else if (region == DockingRegion.CENTER) { DockingTabPanelNode tab = new DockingTabPanelNode(docking, persistentID, "", anchor, titleText, tabText); Dockable dockable = DockingInternal.get(docking).getDockable(persistentID); tab.addTab(this.persistentID, "", anchor, titleText, tabText); tab.addTab(persistentID, "", anchor, dockable.getTitleText(), dockable.getTabText()); parent.replaceChild(this, tab); } else { int orientation = region == DockingRegion.EAST || region == DockingRegion.WEST ? JSplitPane.HORIZONTAL_SPLIT : JSplitPane.VERTICAL_SPLIT; DockingLayoutNode left; DockingLayoutNode right; if (Settings.alwaysDisplayTabsMode()) { if (orientation == JSplitPane.HORIZONTAL_SPLIT) { left = region == DockingRegion.EAST ? this : new DockingTabPanelNode(docking, persistentID, "", anchor, titleText, tabText); right = region == DockingRegion.EAST ? new DockingTabPanelNode(docking, persistentID, "", anchor, titleText, tabText) : this; } else { left = region == DockingRegion.SOUTH ? this : new DockingTabPanelNode(docking, persistentID, "", anchor, titleText, tabText); right = region == DockingRegion.SOUTH ? new DockingTabPanelNode(docking, persistentID, "", anchor, titleText, tabText) : this; } } else { if (orientation == JSplitPane.HORIZONTAL_SPLIT) { left = region == DockingRegion.EAST ? this : new DockingSimplePanelNode(docking, persistentID, className, anchor, titleText, tabText); right = region == DockingRegion.EAST ? new DockingSimplePanelNode(docking, persistentID, className, anchor, titleText, tabText) : this; } else { left = region == DockingRegion.SOUTH ? this : new DockingSimplePanelNode(docking, persistentID, className, anchor, titleText, tabText); right = region == DockingRegion.SOUTH ? new DockingSimplePanelNode(docking, persistentID, className, anchor, titleText, tabText) : this; } } if (region == DockingRegion.EAST || region == DockingRegion.SOUTH) { dividerProportion = 1.0 - dividerProportion; } DockingLayoutNode oldParent = parent; DockingSplitPanelNode split = new DockingSplitPanelNode(docking, left, right, orientation, dividerProportion, anchor); oldParent.replaceChild(this, split); } } @Override public void replaceChild(DockingLayoutNode child, DockingLayoutNode newChild) { } /** * Get Persistent ID of the contained dockable * * @return Persistent ID */ public String getPersistentID() { return persistentID; } /** * The name of the class of the application dockable panel * * @return Class name */ public String getClassName() { return className; } /** * Get the properties of the dockable * * @return properties map */ public Map<String, Property> getProperties() { return Collections.unmodifiableMap(properties); } /** * Set the properties of the dockable * * @param properties New properties for the dockable */ public void setProperties(Map<String, Property> properties) { this.properties = new HashMap<>(properties); } /** * The persistent ID of the anchor this node is associated with * * @return Anchor this node is associated with or null */ public String getAnchor() { return anchor; } public String getTitleText() { return titleText; } public String getTabText() { return tabText; } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-api/src/io/github/andrewauclair/moderndocking/layouts/EmptyPanelNode.java
docking-api/src/io/github/andrewauclair/moderndocking/layouts/EmptyPanelNode.java
/* Copyright (c) 2022 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 io.github.andrewauclair.moderndocking.layouts; import io.github.andrewauclair.moderndocking.DockingRegion; /** * Used to avoid issues with null nodes when root layout nodes are empty */ public class EmptyPanelNode implements DockingLayoutNode { /** * Create new instance */ public EmptyPanelNode() { } @Override public DockingLayoutNode findNode(String persistentID) { return null; } @Override public void dock(String persistentID, DockingRegion region, double dividerProportion) { } @Override public void replaceChild(DockingLayoutNode child, DockingLayoutNode newChild) { } @Override public DockingLayoutNode getParent() { return null; } @Override public void setParent(DockingLayoutNode parent) { } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-api/src/io/github/andrewauclair/moderndocking/layouts/DockingLayouts.java
docking-api/src/io/github/andrewauclair/moderndocking/layouts/DockingLayouts.java
/* Copyright (c) 2022 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 io.github.andrewauclair.moderndocking.layouts; import io.github.andrewauclair.moderndocking.Property; import io.github.andrewauclair.moderndocking.api.DockingAPI; import io.github.andrewauclair.moderndocking.api.RootDockingPanelAPI; import io.github.andrewauclair.moderndocking.event.DockingLayoutEvent; import io.github.andrewauclair.moderndocking.event.DockingLayoutListener; import io.github.andrewauclair.moderndocking.internal.DockableProperties; import io.github.andrewauclair.moderndocking.internal.DockableWrapper; import io.github.andrewauclair.moderndocking.internal.DockedAnchorPanel; import io.github.andrewauclair.moderndocking.internal.DockedSimplePanel; import io.github.andrewauclair.moderndocking.internal.DockedSplitPanel; import io.github.andrewauclair.moderndocking.internal.DockedTabbedPanel; import io.github.andrewauclair.moderndocking.internal.DockingComponentUtils; import io.github.andrewauclair.moderndocking.internal.DockingInternal; import io.github.andrewauclair.moderndocking.internal.DockingPanel; import io.github.andrewauclair.moderndocking.internal.InternalRootDockingPanel; import java.awt.Dimension; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.swing.JSplitPane; /** * Manage storage, persistence and restoration of application layouts */ public class DockingLayouts { private static final List<DockingLayoutListener> listeners = new ArrayList<>(); private static final Map<String, ApplicationLayout> layouts = new HashMap<>(); /** * Unused. All methods are static */ private DockingLayouts() { } /** * Add a new layouts listener * * @param listener New listener to add */ public static void addLayoutsListener(DockingLayoutListener listener) { listeners.add(listener); } /** * Remove a layout listener * * @param listener Listener to remove */ public static void removeLayoutsListener(DockingLayoutListener listener) { listeners.remove(listener); } /** * Store a new layout with the given name * * @param name The name of the layout * @param layout The layout to store */ public static void addLayout(String name, ApplicationLayout layout) { removeLayout(name); layouts.put(name, layout); listeners.forEach(l -> l.layoutChange(new DockingLayoutEvent(DockingLayoutEvent.ID.ADDED, name, layout))); } /** * Remove a layout with the given name * * @param name The name of the layout */ public static void removeLayout(String name) { ApplicationLayout layout = layouts.remove(name); if (layout != null) { listeners.forEach(l -> l.layoutChange(new DockingLayoutEvent(DockingLayoutEvent.ID.REMOVED, name, layout))); } } /** * Send out docking layout restored events * * @param layout The layout that has been restored */ public static void layoutRestored(ApplicationLayout layout) { listeners.forEach(l -> l.layoutChange(new DockingLayoutEvent(DockingLayoutEvent.ID.RESTORED, "current", layout))); } /** * Send out docking layout persisted events * * @param layout The layout that has been restored */ public static void layoutPersisted(ApplicationLayout layout) { listeners.forEach(l -> l.layoutChange(new DockingLayoutEvent(DockingLayoutEvent.ID.PERSISTED, "current", layout))); } /** * Lookup a layout by name * * @param name Name of the layout to find * * @return The layout, or null if it is not found */ public static ApplicationLayout getLayout(String name) { return layouts.get(name); } /** * Get a list of names of all layouts * * @return List of layout names */ public static List<String> getLayoutNames() { return new ArrayList<>(layouts.keySet()); } /** * Create a layout from an existing window * * @param docking Docking instance * @param root The root of the window to get the layout for * * @return Layout of the window */ public static WindowLayout layoutFromRoot(DockingAPI docking, RootDockingPanelAPI root) { InternalRootDockingPanel internalRoot = DockingInternal.get(docking).getRootPanels().entrySet().stream() .filter(entry -> entry.getValue().getRootPanel() == root) .findFirst() .map(Map.Entry::getValue) .get(); WindowLayout layout = new WindowLayout(DockingComponentUtils.windowForRoot(docking, root), panelToNode(docking, internalRoot.getPanel())); layout.setWestAutoHideToolbarIDs(internalRoot.getWestAutoHideToolbarIDs()); layout.setEastAutoHideToolbarIDs(internalRoot.getEastAutoHideToolbarIDs()); layout.setSouthAutoHideToolbarIDs(internalRoot.getSouthAutoHideToolbarIDs()); DockingInternal internal = DockingInternal.get(docking); Dimension size = root.getSize(); for (String id : internalRoot.getWestAutoHideToolbarIDs()) { layout.setSlidePosition(id, internalRoot.getSlidePosition(internal.getDockable(id)) / (double) size.width); } for (String id : internalRoot.getEastAutoHideToolbarIDs()) { layout.setSlidePosition(id, internalRoot.getSlidePosition(internal.getDockable(id)) / (double) size.width); } for (String id : internalRoot.getSouthAutoHideToolbarIDs()) { layout.setSlidePosition(id, internalRoot.getSlidePosition(internal.getDockable(id)) / (double) size.height); } return layout; } /** * Convert a displayed panel into its layout node representation * * @param docking The docking instance the panel belongs to * @param panel The panel to convert * * @return The resulting layout node */ private static DockingLayoutNode panelToNode(DockingAPI docking, DockingPanel panel) { DockingLayoutNode node; if (panel instanceof DockedSimplePanel) { DockableWrapper wrapper = ((DockedSimplePanel) panel).getWrapper(); Map<String, Property> properties = DockableProperties.saveProperties(wrapper); node = new DockingSimplePanelNode(docking, wrapper.getDockable().getPersistentID(), wrapper.getDockable().getClass().getTypeName(), panel.getAnchor(), wrapper.getDockable().getTitleText(), wrapper.getDockable().getTabText(), properties); } else if (panel instanceof DockedSplitPanel) { node = splitPanelToNode(docking, (DockedSplitPanel) panel); } else if (panel instanceof DockedTabbedPanel) { node = tabbedPanelToNode(docking, (DockedTabbedPanel) panel); } else if (panel instanceof DockedAnchorPanel) { DockableWrapper wrapper = ((DockedAnchorPanel) panel).getWrapper(); node = new DockingAnchorPanelNode(docking, wrapper.getDockable().getPersistentID(), wrapper.getClass().getTypeName()); } else if (panel == null) { // the main frame root node contains a null panel if there is nothing docked node = new EmptyPanelNode(); } else { throw new RuntimeException("Unknown panel"); } return node; } private static DockingLayoutNode splitPanelToNode(DockingAPI docking, DockedSplitPanel panel) { JSplitPane splitPane = panel.getSplitPane(); int orientation = splitPane.getOrientation(); int height = splitPane.getHeight(); int dividerSize = splitPane.getDividerSize(); int dividerLocation = splitPane.getDividerLocation(); int width = splitPane.getWidth(); double dividerProportion = orientation == JSplitPane.VERTICAL_SPLIT ? dividerLocation / (float) (height - dividerSize) : dividerLocation / (float) (width - dividerSize); return new DockingSplitPanelNode(docking, panelToNode(docking, panel.getLeft()), panelToNode(docking, panel.getRight()), splitPane.getOrientation(), dividerProportion, panel.getAnchor()); } private static DockingLayoutNode tabbedPanelToNode(DockingAPI docking, DockedTabbedPanel panel) { DockableWrapper wrapper = DockingInternal.get(docking).getWrapper(DockingInternal.get(docking).getDockable(panel.getSelectedTabID())); DockingTabPanelNode node = new DockingTabPanelNode(docking, panel.getSelectedTabID(), "", panel.getAnchor(), wrapper.getDockable().getTitleText(), wrapper.getDockable().getTabText(), DockableProperties.saveProperties(wrapper)); for (DockableWrapper dockable : panel.getDockables()) { node.addTab(dockable.getDockable().getPersistentID(), dockable.getClass().getTypeName(), dockable.getAnchor(), dockable.getDockable().getTitleText(), dockable.getDockable().getTabText(), DockableProperties.saveProperties(dockable)); } return node; } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-api/src/io/github/andrewauclair/moderndocking/layouts/DockingTabPanelNode.java
docking-api/src/io/github/andrewauclair/moderndocking/layouts/DockingTabPanelNode.java
/* Copyright (c) 2022 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 io.github.andrewauclair.moderndocking.layouts; import io.github.andrewauclair.moderndocking.Dockable; import io.github.andrewauclair.moderndocking.DockingRegion; import io.github.andrewauclair.moderndocking.Property; import io.github.andrewauclair.moderndocking.api.DockingAPI; import io.github.andrewauclair.moderndocking.internal.DockingInternal; import io.github.andrewauclair.moderndocking.settings.Settings; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Optional; import javax.swing.JSplitPane; /** * Docking layout node for a tabbed panel. A that contains multiple dockables in a JTabbedPane. */ public class DockingTabPanelNode implements DockingLayoutNode { private final List<DockingSimplePanelNode> tabs = new ArrayList<>(); private final DockingAPI docking; private String selectedTabID; private String anchor = ""; private DockingLayoutNode parent; /** * Create a new tab panel node with a single dockable to start * * @param docking The docking instance this node belongs to * @param selectedTabID Persistent ID of first dockable * @param selectedTabClassName The name of the class for the selected tab, used to create the dockable if not found * @param anchor The anchor associated with this node */ public DockingTabPanelNode(DockingAPI docking, String selectedTabID, String selectedTabClassName, String anchor, String titleText, String tabText) { this.docking = docking; addTab(selectedTabID, selectedTabClassName, anchor, titleText, tabText); this.selectedTabID = selectedTabID; } /** * Create a new tab panel node with a single dockable to start * * @param docking The docking instance this node belongs to * @param selectedTabID Persistent ID of first dockable * @param anchor The anchor associated with this node * @param selectedTabClassName The name of the class for the selected tab, used to create the dockable if not found * @param properties Properties of the dockable */ public DockingTabPanelNode(DockingAPI docking, String selectedTabID, String selectedTabClassName, String anchor, String titleText, String tabText, Map<String, Property> properties) { this.docking = docking; addTab(selectedTabID, selectedTabClassName, anchor, titleText, tabText, properties); this.selectedTabID = selectedTabID; } /** * Add a new dockable to the tab panel * * @param persistentID Dockable persistent ID to add * @param className The name of the class for this dockable */ public void addTab(String persistentID, String className, String anchor, String titleText, String tabText) { if (findNode(persistentID) != null) { DockingSimplePanelNode node = null; for (DockingSimplePanelNode tab : tabs) { if (persistentID.equals(tab.getPersistentID())) { node = tab; } } // this is the selected tab, bump it up into the correct order if (node != null) { tabs.remove(node); tabs.add(node); } return; } if (className.isEmpty()) { try { className = DockingInternal.get(docking).getDockable(persistentID).getClass().getTypeName(); } catch (Exception ignored) { } } DockingSimplePanelNode tab = new DockingSimplePanelNode(docking, persistentID, className, anchor, titleText, tabText); tab.setParent(this); tabs.add(tab); } /** * Add a new dockable to the tab panel * * @param persistentID Dockable persistent ID to add * @param className The name of the class for this dockable * @param properties Properties of the dockable */ public void addTab(String persistentID, String className, String anchor, String titleText, String tabText, Map<String, Property> properties) { if (findNode(persistentID) != null) { DockingSimplePanelNode node = null; for (DockingSimplePanelNode tab : tabs) { if (persistentID.equals(tab.getPersistentID())) { node = tab; } } // this is the selected tab, bump it up into the correct order if (node != null) { tabs.remove(node); tabs.add(node); } return; } if (className.isEmpty()) { try { className = DockingInternal.get(docking).getDockable(persistentID).getClass().getTypeName(); } catch (Exception ignored) { } } DockingSimplePanelNode tab = new DockingSimplePanelNode(docking, persistentID, className, anchor, titleText, tabText, properties); tab.setParent(this); tabs.add(tab); } /** * Set the properties that belong to a tab in this node * * @param persistentID The persistent ID of the dockable tab we're setting properties for * @param properties The properties of the dockable */ public void setProperties(String persistentID, Map<String, Property> properties) { Optional<DockingSimplePanelNode> first = tabs.stream() .filter(dockingSimplePanelNode -> dockingSimplePanelNode.getPersistentID().equals(persistentID)) .findFirst(); first.ifPresent(dockingSimplePanelNode -> dockingSimplePanelNode.setProperties(properties)); } /** * Get a list of the persistent IDs in the tab panel * * @return List of persistent IDs */ public List<DockingSimplePanelNode> getPersistentIDs() { return new ArrayList<>(tabs); } /** * Get the persistent ID of the selected tab * * @return persistent ID */ public String getSelectedTabID() { return selectedTabID; } @Override public DockingLayoutNode getParent() { return parent; } @Override public void setParent(DockingLayoutNode parent) { this.parent = parent; } @Override public DockingLayoutNode findNode(String persistentID) { for (DockingSimplePanelNode tab : tabs) { if (persistentID.equals(tab.getPersistentID())) { return tab; } } return null; } @Override public void dock(String persistentID, DockingRegion region, double dividerProportion) { if (region == DockingRegion.CENTER) { Dockable dockable = DockingInternal.get(docking).getDockable(persistentID); String className = dockable.getClass().getTypeName(); addTab(persistentID, className, anchor, dockable.getTitleText(), dockable.getTabText()); } else { int orientation = region == DockingRegion.EAST || region == DockingRegion.WEST ? JSplitPane.HORIZONTAL_SPLIT : JSplitPane.VERTICAL_SPLIT; DockingLayoutNode left; DockingLayoutNode right; Dockable dockable = DockingInternal.get(docking).getDockable(persistentID); String className = dockable.getClass().getTypeName(); if (Settings.alwaysDisplayTabsMode()) { left = region == DockingRegion.NORTH || region == DockingRegion.WEST ? new DockingTabPanelNode(docking, persistentID, className, anchor, dockable.getTitleText(), dockable.getTabText()) : this; right = region == DockingRegion.NORTH || region == DockingRegion.WEST ? this : new DockingTabPanelNode(docking, persistentID, className, anchor, dockable.getTitleText(), dockable.getTabText()); } else { left = region == DockingRegion.NORTH || region == DockingRegion.WEST ? new DockingSimplePanelNode(docking, persistentID, className, anchor, dockable.getTitleText(), dockable.getTabText()) : this; right = region == DockingRegion.NORTH || region == DockingRegion.WEST ? this : new DockingSimplePanelNode(docking, persistentID, className, anchor, dockable.getTitleText(), dockable.getTabText()); } if (region == DockingRegion.EAST || region == DockingRegion.SOUTH) { dividerProportion = 1.0 - dividerProportion; } DockingLayoutNode oldParent = parent; DockingSplitPanelNode split = new DockingSplitPanelNode(docking, left, right, orientation, dividerProportion, anchor); oldParent.replaceChild(this, split); } } @Override public void replaceChild(DockingLayoutNode child, DockingLayoutNode newChild) { } /** * Bring the layout node to front by setting it as the selected tab * * @param node Tab to set as selected */ public void bringToFront(DockingLayoutNode node) { for (DockingSimplePanelNode tab : tabs) { if (tab == node) { selectedTabID = tab.getPersistentID(); break; } } } public String getAnchor() { return anchor; } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-api/src/io/github/andrewauclair/moderndocking/layouts/DockingAnchorPanelNode.java
docking-api/src/io/github/andrewauclair/moderndocking/layouts/DockingAnchorPanelNode.java
/* Copyright (c) 2025 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 io.github.andrewauclair.moderndocking.layouts; import io.github.andrewauclair.moderndocking.DockingRegion; import io.github.andrewauclair.moderndocking.Property; import io.github.andrewauclair.moderndocking.api.DockingAPI; import java.util.HashMap; import java.util.Map; /** * Layout node representing a docking anchor for Window and Application layouts */ public class DockingAnchorPanelNode implements DockingLayoutNode { private final DockingAPI docking; private final String persistentID; private final String className; private Map<String, Property> properties = new HashMap<>(); private DockingLayoutNode parent; /** * Create a new DockingAnchorPanelNode with just a persistent ID * * @param docking The docking instance * @param persistentID The persistent ID of the anchor * @param className The name of the anchor class to instantiate, if dockable is not found */ public DockingAnchorPanelNode(DockingAPI docking, String persistentID, String className) { this.docking = docking; this.persistentID = persistentID; this.className = className; } @Override public DockingLayoutNode findNode(String persistentID) { if (this.persistentID.equals(persistentID)) { return this; } return null; } @Override public void dock(String persistentID, DockingRegion region, double dividerProportion) { // TODO I think we need to handle something here } @Override public void replaceChild(DockingLayoutNode child, DockingLayoutNode newChild) { } @Override public DockingLayoutNode getParent() { return parent; } public void setParent(DockingLayoutNode parent) { this.parent = parent; } /** * Get Persistent ID of the contained dockable * * @return Persistent ID */ public String getPersistentID() { return persistentID; } /** * Get the class name of the anchor * * @return Name of the class */ public String getClassName() { return className; } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-api/src/io/github/andrewauclair/moderndocking/event/DockingLayoutListener.java
docking-api/src/io/github/andrewauclair/moderndocking/event/DockingLayoutListener.java
/* 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 io.github.andrewauclair.moderndocking.event; /** * Listen for changes to layouts */ public interface DockingLayoutListener { /** * A layout has changed * * @param e Information about the layout that has changed */ void layoutChange(DockingLayoutEvent e); }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-api/src/io/github/andrewauclair/moderndocking/event/DockingLayoutEvent.java
docking-api/src/io/github/andrewauclair/moderndocking/event/DockingLayoutEvent.java
/* 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 io.github.andrewauclair.moderndocking.event; import io.github.andrewauclair.moderndocking.layouts.ApplicationLayout; /** * Event used when the application layout has changed */ public class DockingLayoutEvent { /** * The ID of the layout event */ public enum ID { /** * Layout has been added */ ADDED, /** * Layout has been removed */ REMOVED, /** * Layout has been restored */ RESTORED, /** * Layout has been saved to a file */ PERSISTED } private final ID id; private final String layoutName; private final ApplicationLayout layout; /** * Create a new docking layout event * * @param id ID of event that has occurred * @param layoutName The name of the layout changed * @param layout The application layout that changed */ public DockingLayoutEvent(ID id, String layoutName, ApplicationLayout layout) { this.id = id; this.layoutName = layoutName; this.layout = layout; } /** * The ID of this event * * @return Event ID */ public ID getID() { return id; } /** * The name of the layout in this event * * @return Layout name */ public String getLayoutName() { return layoutName; } /** * The application layout in this event * * @return Application layout */ public ApplicationLayout getLayout() { return layout; } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-api/src/io/github/andrewauclair/moderndocking/event/DockingListener.java
docking-api/src/io/github/andrewauclair/moderndocking/event/DockingListener.java
/* Copyright (c) 2022 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 io.github.andrewauclair.moderndocking.event; /** * Listener interface used to listen for docking events */ public interface DockingListener { /** * Called when docking events occur * * @param e The docking event */ void dockingChange(DockingEvent e); }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-api/src/io/github/andrewauclair/moderndocking/event/DockingEvent.java
docking-api/src/io/github/andrewauclair/moderndocking/event/DockingEvent.java
/* 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 io.github.andrewauclair.moderndocking.event; import io.github.andrewauclair.moderndocking.Dockable; /** * Event used when a dockable is docked, undocked, shown, or hidden */ public class DockingEvent { /** * The ID of a docking event. Describes what type of event occurred */ public enum ID { /** * Dockable has been docked */ DOCKED, /** * Dockable has been undocked */ UNDOCKED, /** * Dockable has been shown */ SHOWN, /** * Dockable has been hidden */ HIDDEN, /** * Dockable has been assigned to an Auto Hide toolbar */ AUTO_HIDE_ENABLED, /** * Dockable has been removed from an Auto Hide toolbar */ AUTO_HIDE_DISABLED } private final ID id; private final Dockable dockable; private final boolean temporary; /** * Create a new docking event * * @param id The ID of the event * @param dockable The dockable which has been effected */ public DockingEvent(ID id, Dockable dockable) { this.id = id; this.dockable = dockable; this.temporary = false; } /** * Create a new docking event * * @param id The ID of the event * @param dockable The dockable which has been effected * @param temporary Is this a temporary event which will be followed by another, permanent, event? */ public DockingEvent(ID id, Dockable dockable, boolean temporary) { this.id = id; this.dockable = dockable; this.temporary = temporary; } /** * The type of event that has occurred * * @return Event ID */ public ID getID() { return id; } /** * Get the dockable which has been effected * * @return Dockable for this event */ public Dockable getDockable() { return dockable; } /** * Check if this docking event is temporary. for example: the dockable has been undocked because of a user floating the dockable * * @return Whether this event is a temporary docking event */ public boolean isTemporary() { return temporary; } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-api/src/io/github/andrewauclair/moderndocking/event/MaximizeListener.java
docking-api/src/io/github/andrewauclair/moderndocking/event/MaximizeListener.java
/* Copyright (c) 2022 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 io.github.andrewauclair.moderndocking.event; import io.github.andrewauclair.moderndocking.Dockable; /** * Interface for creating listeners for maximize events */ public interface MaximizeListener { /** * Maximized state of dockable has changed * * @param dockable Dockable that has changed * @param maximized New maximized state */ void maximized(Dockable dockable, boolean maximized); }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-api/src/io/github/andrewauclair/moderndocking/event/NewFloatingFrameListener.java
docking-api/src/io/github/andrewauclair/moderndocking/event/NewFloatingFrameListener.java
/* Copyright (c) 2025 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 io.github.andrewauclair.moderndocking.event; import io.github.andrewauclair.moderndocking.Dockable; import io.github.andrewauclair.moderndocking.api.RootDockingPanelAPI; import javax.swing.JFrame; /** * Used to inform the application that a new floating frame has been created */ public interface NewFloatingFrameListener { /** * Called when a new floating frame is created when restoring a window layout or when dropping a tab group of dockables * <p> * NOTE: Modern Docking will close and dispose of all FloatingFrames it creates * * @param frame The new floating frame created by Modern Docking * @param root The root panel of the frame. Provided in case the application wishes to rebuild the layout */ void newFrameCreated(JFrame frame, RootDockingPanelAPI root); /** * Called when a new floating frame is created by ModernDocking. The frame will already be visible * and the dockable will already be docked. * <p> * NOTE: ModernDocking will close and dispose of all FloatingFrames it creates * * @param frame The new floating frame created by Modern Docking * @param root The root panel of the frame. Provided in case the application wishes to rebuild the layout * @param dockable The dockable that this floating frame was created for and that is currently docked in the frame */ void newFrameCreated(JFrame frame, RootDockingPanelAPI root, Dockable dockable); }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-api/src/io/github/andrewauclair/moderndocking/internal/DockableToolbar.java
docking-api/src/io/github/andrewauclair/moderndocking/internal/DockableToolbar.java
/* Copyright (c) 2022 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 io.github.andrewauclair.moderndocking.internal; import io.github.andrewauclair.moderndocking.Dockable; import io.github.andrewauclair.moderndocking.api.DockingAPI; import io.github.andrewauclair.moderndocking.api.RootDockingPanelAPI; import io.github.andrewauclair.moderndocking.ui.DockingSettings; import io.github.andrewauclair.moderndocking.ui.ToolbarLocation; import io.github.andrewauclair.moderndocking.internal.util.CombinedIcon; import io.github.andrewauclair.moderndocking.internal.util.RotatedIcon; import io.github.andrewauclair.moderndocking.internal.util.TextIcon; import io.github.andrewauclair.moderndocking.internal.util.UnselectableButtonGroup; import java.awt.Color; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import java.awt.Window; import java.awt.event.ComponentEvent; import java.awt.event.ComponentListener; import java.util.ArrayList; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; import javax.swing.BorderFactory; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JLayeredPane; import javax.swing.JPanel; import javax.swing.JToggleButton; import javax.swing.UIManager; /** * This class is a special panel used to display toolbars on the West, East or South side of a frame to display dockables * that are auto hide enabled */ public class DockableToolbar extends JPanel implements ComponentListener { /** * The docking instance this toolbar belongs to */ private final DockingAPI docking; /** * The window this toolbar is in */ private final Window window; /** * The root docking panel of the window */ private final RootDockingPanelAPI root; /** * The location of this toolbar. Either WEST, SOUTH or EAST */ private final ToolbarLocation location; private static class Entry { private final Dockable dockable; private final JToggleButton button; private final DockedAutoHidePanel panel; private Entry(Dockable dockable, JToggleButton button, DockedAutoHidePanel panel) { this.dockable = dockable; this.button = button; this.panel = panel; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } Entry panel = (Entry) o; return Objects.equals(dockable, panel.dockable); } @Override public int hashCode() { return Objects.hash(dockable); } } /** * The dockables that are assigned to this auto-hide toolbar */ private final List<Entry> dockables = new ArrayList<>(); /** * The group of all the toolbar buttons for the auto-hide dockables */ private final UnselectableButtonGroup buttonGroup = new UnselectableButtonGroup(); /** * Create a new dockable toolbar for the window, its root and a location (west, south or east) * * @param docking The docking instance * @param window The window this toolbar is attached to * @param root The root of the attached window * @param location The location of this toolbar within the window */ public DockableToolbar(DockingAPI docking, Window window, RootDockingPanelAPI root, ToolbarLocation location) { super(new GridBagLayout()); this.docking = docking; // the window must be a JFrame or a JDialog to support pinning (we need a JLayeredPane) assert window instanceof JFrame || window instanceof JDialog; this.window = window; this.root = root; this.location = location; addComponentListener(this); } /** * Get the location within the window that this toolbar is docked * * @return Location, west, south or east */ public ToolbarLocation getDockedLocation() { return location; } /** * Check if this toolbar is vertical (east or west) * * @return True if vertical */ public boolean isVertical() { return location == ToolbarLocation.EAST || location == ToolbarLocation.WEST; } private void createContents() { removeAll(); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 0; for (Entry dockable : dockables) { add(dockable.button, gbc); if (isVertical()) { gbc.gridy++; } else { gbc.gridx++; } } if (isVertical()) { gbc.weighty = 1.0; } else { gbc.weightx = 1.0; } add(new JLabel(""), gbc); } private void updateButtons() { for (Entry entry : dockables) { boolean isSelected = buttonGroup.getSelection() == entry.button.getModel(); if (entry.panel.isVisible() && !isSelected) { DockingListeners.fireHiddenEvent(entry.dockable); } else if (!entry.panel.isVisible() && isSelected) { DockingListeners.fireShownEvent(entry.dockable); } else if (isSelected) { DockingListeners.fireShownEvent(entry.dockable); } // set only a single panel visible entry.panel.setVisible(isSelected); if (isSelected) { Color color = DockingSettings.getHighlighterSelectedBorder(); entry.panel.setBorder(BorderFactory.createLineBorder(color, 2)); } } } /** * Add a new dockable to this toolbar * * @param dockable Dockable to add */ public void addDockable(Dockable dockable) { if (!hasDockable(dockable)) { JToggleButton button = new JToggleButton(); button.setIcon(dockable.getIcon()); if (isVertical()) { TextIcon textIcon = new TextIcon(button, dockable.getTabText(), TextIcon.Layout.HORIZONTAL); RotatedIcon rotatedIcon = new RotatedIcon(textIcon, location == ToolbarLocation.WEST ? RotatedIcon.Rotate.UP : RotatedIcon.Rotate.DOWN); if (dockable.getIcon() != null) { button.setIcon(new CombinedIcon(dockable.getIcon(), rotatedIcon)); } else { button.setIcon(rotatedIcon); } Insets insets = UIManager.getInsets("Button.margin"); if (insets == null) { insets = new Insets(0, 0, 0, 0); } // purposefully putting them in this order to set the margins of a vertical button //noinspection SuspiciousNameCombination Insets margin = new Insets(insets.left, insets.top, insets.left, insets.top); button.setMargin(margin); } else { button.setText(dockable.getTabText()); } DockedAutoHidePanel panel = new DockedAutoHidePanel(docking, dockable, root, this); DockingInternal.get(docking).getWrapper(dockable).setWindow(window); // update all the buttons and panels button.addActionListener(e -> updateButtons()); buttonGroup.add(button); dockables.add(new Entry(dockable, button, panel)); JLayeredPane layeredPane; if (window instanceof JFrame) { layeredPane = ((JFrame) window).getLayeredPane(); } else { layeredPane = ((JDialog) window).getLayeredPane(); } layeredPane.add(panel, root.getAutoHideLayer()); createContents(); } } /** * Remove a dockable from this toolbar * * @param dockable Dockable to remove */ public void removeDockable(Dockable dockable) { for (Entry entry : dockables) { if (entry.dockable == dockable) { JLayeredPane layeredPane; if (window instanceof JFrame) { layeredPane = ((JFrame) window).getLayeredPane(); } else { layeredPane = ((JDialog) window).getLayeredPane(); } layeredPane.remove(entry.panel); break; } } if (dockables.removeIf(panel -> panel.dockable.equals(dockable))) { createContents(); } } /** * Check if this toolbar contains a certain dockable * * @param dockable Dockable to search for * @return Is dockable contained in this toolbar? */ public boolean hasDockable(Dockable dockable) { return dockables.stream() .anyMatch(panel -> panel.dockable.equals(dockable)); } /** * Check if this toolbar should be displayed. * * @return True if there are 1 or more dockables in the toolbar */ public boolean shouldDisplay() { return !dockables.isEmpty(); } /** * Hide all the dockables in the toolbar */ public void hideAll() { buttonGroup.setSelected(buttonGroup.getSelection(), false); updateButtons(); } /** * Get a list of the persistent IDs of the dockables in this toolbar * * @return List of persistent IDs */ public List<String> getPersistentIDs() { return dockables.stream() .map(entry -> entry.dockable.getPersistentID()) .collect(Collectors.toList()); } public int getSlidePosition(Dockable dockable) { for (Entry entry : dockables) { if (entry.dockable == dockable) { return entry.panel.getSlidePosition(); } } return 0; } public void setSlidePosition(Dockable dockable, int position) { for (Entry entry : dockables) { if (entry.dockable == dockable) { entry.panel.setSize(entry.panel.getWidth(), position); } } } @Override public void componentResized(ComponentEvent e) { } @Override public void componentMoved(ComponentEvent e) { } @Override public void componentShown(ComponentEvent e) { dockables.forEach(dockable -> dockable.panel.componentResized(e)); } @Override public void componentHidden(ComponentEvent e) { } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-api/src/io/github/andrewauclair/moderndocking/internal/DockingComponentUtils.java
docking-api/src/io/github/andrewauclair/moderndocking/internal/DockingComponentUtils.java
/* Copyright (c) 2022-2024 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 io.github.andrewauclair.moderndocking.internal; import io.github.andrewauclair.moderndocking.Dockable; import io.github.andrewauclair.moderndocking.api.DockingAPI; import io.github.andrewauclair.moderndocking.api.RootDockingPanelAPI; import io.github.andrewauclair.moderndocking.exception.RootDockingPanelNotFoundException; import java.awt.Component; import java.awt.Container; import java.awt.Point; import java.awt.Rectangle; import java.awt.Window; import java.util.Optional; import javax.swing.JDialog; import javax.swing.SwingUtilities; /** * set of internal utilities for dealing with the component hierarchy of dockables */ public class DockingComponentUtils { /** * Not used. All methods in this class are static */ private DockingComponentUtils() { } // // /** * used to clear all anchors before we undock components. This is done to prevent the anchor from being readded * * @param container Container to undock all components from */ public static void clearAnchors(Container container) { for (Component component : container.getComponents()) { if (component instanceof DockedSimplePanel) { ((DockedSimplePanel) component).setAnchor(""); } else if (component instanceof DockedSplitPanel) { ((DockedSplitPanel) component).setAnchor(""); } else if (component instanceof DockedTabbedPanel) { ((DockedTabbedPanel) component).setAnchor(""); } else if (component instanceof Container) { clearAnchors((Container) component); } } } /** * used to undock all dockables in a container. called when a frame is to be disposed * * @param docking The docking instance * @param container Container to undock all components from */ public static void undockComponents(DockingAPI docking, Container container) { for (Component component : container.getComponents()) { if (component instanceof DisplayPanel) { docking.undock(((DisplayPanel) component).getWrapper().getDockable()); } else if (component instanceof Container) { undockComponents(docking, (Container) component); } } } /** * search for a root panel on the screen at a specific position * * @param docking The docking instance * @param screenPos The screen position to search at * @return The window at screenPos. null if not found. */ public static Window findRootAtScreenPos(DockingAPI docking, Point screenPos) { for (Window window : docking.getRootPanels().keySet()) { Rectangle bounds = new Rectangle(window.getX(), window.getY(), window.getWidth(), window.getHeight()); if (bounds.contains(screenPos) && window.isVisible()) { return window; } } return null; } /** * Find the window that a dockable is docked to * * @param docking The docking instance * @param dockable The dockable to find a window for. * @return The window containing the dockable. null if not found. */ public static Window findWindowForDockable(DockingAPI docking, Dockable dockable) { return DockingInternal.get(docking).getWrapper(dockable).getWindow(); } /** * find the root for the given window, throws an exception if the window doesn't have a root panel * * @param docking The docking instance * @param window The window to find a root for * @return The root of the given window */ public static InternalRootDockingPanel rootForWindow(DockingAPI docking, Window window) { if (docking.getRootPanels().containsKey(window)) { return DockingInternal.get(docking).getRootPanels().get(window); } throw new RootDockingPanelNotFoundException(window); } /** * Find the window for a given root * * @param docking The docking instance * @param root The root to find a window for * @return The window for the root or null */ public static Window windowForRoot(DockingAPI docking, RootDockingPanelAPI root) { Optional<Window> first = docking.getRootPanels().keySet().stream() .filter(frame -> docking.getRootPanels().get(frame) == root) .findFirst(); return first.orElse(null); } /** * find a dockable at a given screen position * * @param docking The docking instance * @param screenPos Screen position to check for a dockable at * @return Dockable under the screen position, or null if none is found */ public static Dockable findDockableAtScreenPos(DockingAPI docking, Point screenPos) { Window window = findRootAtScreenPos(docking, screenPos); // no window found at the location, return null if (window == null) { return null; } return findDockableAtScreenPos(screenPos, window); } /** * find a dockable at a given screen position, limited to a single window * * @param screenPos Screen position to check for a dockable at * @param window The window to check * @return Dockable under the screen position, or null if none is found */ public static Dockable findDockableAtScreenPos(Point screenPos, Window window) { // window is null so there's no dockable to find if (window == null) { return null; } Point framePoint = new Point(screenPos); SwingUtilities.convertPointFromScreen(framePoint, window); Component component = SwingUtilities.getDeepestComponentAt(window, framePoint.x, framePoint.y); // no component found at the position, return null if (component == null) { return null; } while (!(component instanceof DisplayPanel) && component.getParent() != null) { component = component.getParent(); } // didn't find a Dockable, return null if (!(component instanceof DisplayPanel)) { return null; } return ((DisplayPanel) component).getWrapper().getDockable(); } /** * Find an instance of our CustomTabbedPane at the position in the window * * @param screenPos The screen position on the window to check * @param window The window to check * * @return Instance of CustomTabbedPane that was found or null */ public static CustomTabbedPane findTabbedPaneAtPos(Point screenPos, Window window) { // window is null so there's no dockable to find if (window == null) { return null; } Point framePoint = new Point(screenPos); SwingUtilities.convertPointFromScreen(framePoint, window); Component component = SwingUtilities.getDeepestComponentAt(window, framePoint.x, framePoint.y); // no component found at the position, return null if (component == null) { return null; } while (!(component instanceof CustomTabbedPane) && component.getParent() != null) { component = component.getParent(); } // didn't find a Dockable, return null if (!(component instanceof CustomTabbedPane)) { return null; } return (CustomTabbedPane) component; } /** * find a docking panel at a given screen position * * @param docking The docking instance * @param screenPos Screen position to check for a dockable at * @return DockingPanel under the screen position, or null if none is found */ public static DockingPanel findDockingPanelAtScreenPos(DockingAPI docking, Point screenPos) { Window window = findRootAtScreenPos(docking, screenPos); // no window found at the location, return null if (window == null) { return null; } return findDockingPanelAtScreenPos(screenPos, window); } /** * find a docking panel at a given screen position. limited to a single window * * @param screenPos Screen position to check for a dockable at * @param window The window to check * @return DockingPanel under the screen position, or null if none is found */ public static DockingPanel findDockingPanelAtScreenPos(Point screenPos, Window window) { // no window found at the location, return null if (window == null) { return null; } Point framePoint = new Point(screenPos); SwingUtilities.convertPointFromScreen(framePoint, window); Component component = SwingUtilities.getDeepestComponentAt(window, framePoint.x, framePoint.y); // no component found at the position, return null if (component == null) { return null; } while (!(component instanceof DockingPanel) && component.getParent() != null) { component = component.getParent(); } // didn't find a Dockable, return null if (!(component instanceof DockingPanel)) { return null; } return (DockingPanel) component; } /** * remove panels from window if they return false for allowFloating() and there are no other dockables in the window * * @param docking The docking instance * @param window The window to remove illegal floating dockables from */ public static void removeIllegalFloats(DockingAPI docking, Window window) { // don't touch any dockables on a JDialog, they are their own little environment if (window instanceof JDialog) { return; } InternalRootDockingPanel root = rootForWindow(docking, window); if (docking.canDisposeWindow(window) && root != null) { if (shouldUndock(root)) { undockIllegalFloats(root); } } docking.getAppState().persist(); } private static boolean shouldUndock(Container container) { for (Component component : container.getComponents()) { if (component instanceof DisplayPanel) { DisplayPanel panel = (DisplayPanel) component; // there is at least one dockable that is allowed to float alone, we shouldn't undock if (panel.getWrapper().getDockable().isFloatingAllowed()) { return false; } } else if (component instanceof Container) { if (!shouldUndock((Container) component)) { return false; } } } return true; } private static void undockIllegalFloats(Container container) { for (Component component : container.getComponents()) { if (component instanceof DisplayPanel) { DisplayPanel panel = (DisplayPanel) component; DockableWrapper wrapper = panel.getWrapper(); Dockable dockable = wrapper.getDockable(); wrapper.getParent().undock(dockable); DockingListeners.fireUndockedEvent(dockable, false); } else if (component instanceof Container) { undockIllegalFloats((Container) component); } } } /** * Finds the first dockable of a specified type. The main frame is searched first and then * any other frames that exist * * @param docking The docking instance * @param type The type to search for * * @return The first Dockable of the given type, if any exist */ public static Optional<Dockable> findFirstDockableOfType(DockingAPI docking, int type) { InternalRootDockingPanel mainRoot = rootForWindow(docking, docking.getMainWindow()); Optional<Dockable> mainPanelDockable = findDockableOfType(type, mainRoot.getPanel()); if (mainPanelDockable.isPresent()) { return mainPanelDockable; } for (RootDockingPanelAPI panel : docking.getRootPanels().values()) { Optional<Dockable> dockable = findDockableOfType(type, panel); if (dockable.isPresent()) { return dockable; } } return Optional.empty(); } private static Optional<Dockable> findDockableOfType(int type, Container container) { if (container == null) { return Optional.empty(); } for (Component component : container.getComponents()) { if (component instanceof DisplayPanel) { DisplayPanel panel = (DisplayPanel) component; DockableWrapper wrapper = panel.getWrapper(); Dockable dockable = wrapper.getDockable(); if (dockable.getType() == type) { return Optional.of(dockable); } } else if (component instanceof Container) { Optional<Dockable> dockableOfType = findDockableOfType(type, (Container) component); if (dockableOfType.isPresent()) { return dockableOfType; } } } return Optional.empty(); } /** * Check if an anchor is empty * * @param docking The docking instance * @param anchor The anchor to check * * @return The window for the root or null */ public static boolean isAnchorEmpty(DockingAPI docking, Dockable anchor) { try { InternalRootDockingPanel root = DockingComponentUtils.rootForWindow(docking, DockingComponentUtils.findWindowForDockable(docking, anchor)); for (DockingPanel child : root.getChildren()) { if (isAnchorNotEmpty(child)) { return false; } } } catch (RootDockingPanelNotFoundException ignored) { } return true; } private static boolean isAnchorNotEmpty(DockingPanel child) { if (child.getAnchor() != "") { return true; } for (DockingPanel childChild : child.getChildren()) { if (isAnchorNotEmpty(childChild)) { return true; } } return false; } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-api/src/io/github/andrewauclair/moderndocking/internal/DockableWrapper.java
docking-api/src/io/github/andrewauclair/moderndocking/internal/DockableWrapper.java
/* Copyright (c) 2022 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 io.github.andrewauclair.moderndocking.internal; import io.github.andrewauclair.moderndocking.Dockable; import io.github.andrewauclair.moderndocking.Property; import io.github.andrewauclair.moderndocking.api.DockingAPI; import io.github.andrewauclair.moderndocking.internal.floating.DisplayPanelFloatListener; import io.github.andrewauclair.moderndocking.internal.floating.FloatListener; import io.github.andrewauclair.moderndocking.ui.DockingHeaderUI; import io.github.andrewauclair.moderndocking.ui.HeaderController; import io.github.andrewauclair.moderndocking.ui.HeaderModel; import java.awt.Window; import java.util.Collections; import java.util.HashMap; import java.util.Map; /** * internal wrapper around the Dockable implemented by the application. * lets us provide access to the dockable and its parent in the hierarchy */ public class DockableWrapper { private final HeaderController headerController; private Window window; // TODO this is suddenly very confusing to me. This is really just the display panel it's connected to. which for simple panels is direct, but for tabbed, it's not private DockingPanel parent = null; private final Dockable dockable; private final DockingAPI docking; private String anchor = ""; private final DockingHeaderUI headerUI; private final DisplayPanel displayPanel; private DockingPanel internalPanel; private final FloatListener floatListener; private boolean maximized = false; private boolean hidden = false; private boolean isAnchor = false; private InternalRootDockingPanel root; private final Map<String, Property> properties = new HashMap<>(); /** * Create a new wrapper for the dockable * * @param docking The docking instance * @param dockable Dockable to contain in this wrapper * @param isAnchor Is this wrapper an anchor instead of a dockable */ public DockableWrapper(DockingAPI docking, Dockable dockable, boolean isAnchor) { this.docking = docking; this.dockable = dockable; this.isAnchor = isAnchor; HeaderModel headerModel = new HeaderModel(dockable, docking); headerController = new HeaderController(dockable, docking, headerModel); headerUI = dockable.createHeaderUI(headerController, headerModel); headerController.setUI(headerUI); displayPanel = new DisplayPanel(this, isAnchor); floatListener = new DisplayPanelFloatListener(docking, displayPanel); } /** * Get the window for the dockable * * @return The window that the contained dockable is in */ public Window getWindow() { return window; } /** * Set the new window of the dockable * * @param window New window */ public void setWindow(Window window) { this.window = window; } /** * Set the new parent of the dockable * * @param parent New parent */ public void setParent(DockingPanel parent) { this.parent = parent; displayPanel.parentChanged(); } /** * Get the contained dockable * * @return The dockable contained in this wrapper */ public Dockable getDockable() { return dockable; } /** * Get the float listener tied to the display panel of this dockable * * @return Float listener */ public FloatListener getFloatListener() { return floatListener; } /** * Remove any listeners that this wrapper has added for the dockable */ public void removeListeners() { headerController.removeListeners(); floatListener.removeListeners(); } /** * Get the parent of this wrapper * * @return Parent of wrapper */ public DockingPanel getParent() { return parent; } /** * Check if the dockable is maximized * * @return Whether the dockable is maximized */ public boolean isMaximized() { return maximized; } /** * Set the dockable to maximized * * @param maximized Maximized flag */ public void setMaximized(boolean maximized) { this.maximized = maximized; } /** * Check if the dockable is auto hide enabled * * @return Whether the dockable is auto hide enabled */ public boolean isHidden() { return hidden; } /** * Set the dockable to auto hide * * @param hidden Hidden flag */ public void setHidden(boolean hidden) { this.hidden = hidden; displayPanel.parentChanged(); } /** * Check if this wrapper represents an anchor instead of a dockable * * @return Is this wrapper an anchor? */ public boolean isAnchor() { return isAnchor; } public String getAnchor() { return anchor; } public void setAnchor(String anchor) { this.anchor = anchor; } /** * Get the header UI of the dockable * * @return Header UI instance */ public DockingHeaderUI getHeaderUI() { return headerUI; } /** * Get the display panel * * @return Display panel instance */ public DisplayPanel getDisplayPanel() { return displayPanel; } public DockingPanel getInternalPanel() { return internalPanel; } public void setInternalPanel(DockingPanel panel) { this.internalPanel = panel; } /** * Change the root that this dockable is in * * @param root New root of dockable */ public void setRoot(InternalRootDockingPanel root) { this.root = root; } /** * Get the root that contains this dockable * * @return Root panel containing dockable */ public InternalRootDockingPanel getRoot() { return root; } /** * Get the properties for this dockable * * @return Map of properties for this dockable */ public Map<String, Property> getProperties() { return Collections.unmodifiableMap(properties); } /** * Get the value of a property * * @param propertyName The name of the property to lookup * @return Value of property, or null if it does not exist */ public Property getProperty(String propertyName) { return properties.get(propertyName); } /** * Set a new value for a property. The property will be created if missing * * @param propertyName The name of the property to set * @param value The new value of the property */ public void setProperty(String propertyName, Property value) { properties.put(propertyName, value); } /** * Remove a property from this dockable * * @param propertyName The name of the property to remove */ public void removeProperty(String propertyName) { properties.remove(propertyName); } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-api/src/io/github/andrewauclair/moderndocking/internal/DockingPanel.java
docking-api/src/io/github/andrewauclair/moderndocking/internal/DockingPanel.java
/* Copyright (c) 2022 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 io.github.andrewauclair.moderndocking.internal; import io.github.andrewauclair.moderndocking.Dockable; import io.github.andrewauclair.moderndocking.DockingRegion; import java.util.List; import javax.swing.JPanel; /** * Docking panel with docking regions of: north, south, east, west and center */ public abstract class DockingPanel extends JPanel { /** * Create a new docking panel. Nothing to initialize */ public DockingPanel() { } /** * Retrieve the anchor that is associated with this dockable * * @return The anchor for this dockable */ public abstract String getAnchor(); /** * Set the anchor that is associated with this dockable * * @param anchor The anchor for this dockable */ public void setAnchor(String anchor) { } /** * Set the parent of this DockingPanel * * @param parent The new parent of this panel */ public abstract void setParent(DockingPanel parent); /** * Dock a dockable to this panel * * @param dockable The dockable to dock * @param region The region to dock into * @param dividerProportion The proportion to use if docking as a split pane */ public abstract void dock(Dockable dockable, DockingRegion region, double dividerProportion); /** * undock the given dockable, returns true if the dockable was found and removed * * @param dockable Dockable to undock */ public abstract void undock(Dockable dockable); /** * Replace one of the children in this panel with a new child * * @param child The child to replace * @param newChild The new child to add */ public abstract void replaceChild(DockingPanel child, DockingPanel newChild); /** * Remove the specified child from this panel * * @param child Child to remove */ public abstract void removeChild(DockingPanel child); /** * Get a list of the children for this docking panel * * @return Children */ public abstract List<DockingPanel> getChildren(); /** * Check if this dockable is docked in an Auto Hide toolbar * * @return Is the dockable in an Auto Hide toolbar? */ public boolean isInAutoHideToolbar() { return false; } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-api/src/io/github/andrewauclair/moderndocking/internal/DockedAutoHidePanel.java
docking-api/src/io/github/andrewauclair/moderndocking/internal/DockedAutoHidePanel.java
/* Copyright (c) 2022 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 io.github.andrewauclair.moderndocking.internal; import io.github.andrewauclair.moderndocking.Dockable; import io.github.andrewauclair.moderndocking.api.DockingAPI; import io.github.andrewauclair.moderndocking.api.RootDockingPanelAPI; import io.github.andrewauclair.moderndocking.ui.ToolbarLocation; import io.github.andrewauclair.moderndocking.internal.util.SlideBorder; import java.awt.Dimension; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Point; import java.awt.event.ComponentEvent; import java.awt.event.ComponentListener; import java.awt.event.MouseEvent; import java.awt.event.MouseMotionListener; import javax.swing.JPanel; import javax.swing.SwingUtilities; /** * Special JPanel used to contain a dockable within a docking toolbar */ public class DockedAutoHidePanel extends JPanel implements ComponentListener, MouseMotionListener { private final DockingAPI docking; /** * The root that this auto hide panel belongs to */ private final RootDockingPanelAPI root; /** * The toolbar that contains the dockable in this auto hide panel */ private final DockableToolbar toolbar; private final SlideBorder slideBorder; /** * Flag indicating if the panel has been configured. Configuration doesn't occur until the panel is setVisible(true) */ private boolean configured = false; /** * Create a new DockedAutoHidePanel to contain a dockable on a docking toolbar * * @param docking The docking instance * @param dockable The dockable contained on this panel * @param root The root panel of the Window * @param toolbar The toolbar this panel is in */ public DockedAutoHidePanel(DockingAPI docking, Dockable dockable, RootDockingPanelAPI root, DockableToolbar toolbar) { this.docking = docking; this.root = root; this.toolbar = toolbar; setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 0; DockableWrapper wrapper = DockingInternal.get(docking).getWrapper(dockable); DockedSimplePanel panel = new DockedSimplePanel(docking, wrapper, "", wrapper.getDisplayPanel(), false); slideBorder = new SlideBorder(toolbar.getDockedLocation()); if (toolbar.getDockedLocation() == ToolbarLocation.SOUTH) { gbc.weightx = 1.0; gbc.fill = GridBagConstraints.HORIZONTAL; add(slideBorder, gbc); gbc.weightx = 1.0; gbc.weighty = 1.0; gbc.fill = GridBagConstraints.BOTH; gbc.gridy++; add(panel, gbc); } else if (toolbar.getDockedLocation() == ToolbarLocation.EAST) { gbc.weighty = 1.0; gbc.fill = GridBagConstraints.VERTICAL; add(slideBorder, gbc); gbc.weightx = 1.0; gbc.weighty = 1.0; gbc.fill = GridBagConstraints.BOTH; gbc.gridx++; add(panel, gbc); } else { gbc.weightx = 1.0; gbc.weighty = 1.0; gbc.fill = GridBagConstraints.BOTH; add(panel, gbc); gbc.weightx = 0.0; gbc.weighty = 1.0; gbc.fill = GridBagConstraints.VERTICAL; gbc.gridx++; add(slideBorder, gbc); } } @Override public void addNotify() { super.addNotify(); slideBorder.addMouseMotionListener(this); root.addComponentListener(this); addComponentListener(this); } @Override public void removeNotify() { slideBorder.removeMouseMotionListener(this); root.removeComponentListener(this); removeComponentListener(this); super.removeNotify(); } @Override public void setVisible(boolean visible) { super.setVisible(visible); setLocationAndSize(0); if (!configured) { configured = true; } } public int getSlidePosition() { if (toolbar.getDockedLocation() == ToolbarLocation.SOUTH) { return getHeight(); } return getWidth(); } private void setLocationAndSize(int widthDifference) { Point toolbarLocation = toolbar.getLocation(); SwingUtilities.convertPointToScreen(toolbarLocation, toolbar.getParent()); Dimension toolbarSize = toolbar.getSize(); // this panel will be in a layered pane without a layout manager // we must configure the size and position ourselves if (toolbar.isVertical()) { int width = (int) (root.getWidth() / 4.0); int height = toolbarSize.height; if (configured) { width = getWidth() + widthDifference; } width = Math.max(100, width); width = Math.min(width, getParent().getWidth() - 100); Point location = new Point(toolbarLocation.x + toolbarSize.width, toolbarLocation.y); Dimension size = new Dimension(width, height); if (toolbar.getDockedLocation() == ToolbarLocation.EAST) { location.x = toolbarLocation.x - width; } SwingUtilities.convertPointFromScreen(location, getParent()); setLocation(location); setSize(size); } else { int width = toolbarSize.width; int height = (int) (root.getHeight() / 4.0); if (configured) { height = getHeight() + widthDifference; } height = Math.max(100, height); height = Math.min(height, getParent().getHeight() - 100); Point location = new Point(toolbarLocation.x, toolbarLocation.y - height); Dimension size = new Dimension(width, height); SwingUtilities.convertPointFromScreen(location, getParent()); setLocation(location); setSize(size); } revalidate(); repaint(); } @Override public void componentResized(ComponentEvent e) { // component has resized, update the location and size of the auto hide panel if (e.getComponent() == root) { setLocationAndSize(0); } } @Override public void componentMoved(ComponentEvent e) { } @Override public void componentShown(ComponentEvent e) { } @Override public void componentHidden(ComponentEvent e) { } @Override public void mouseDragged(MouseEvent e) { // dragging the divider, update the size and location of the auto hide panel if (toolbar.getDockedLocation() == ToolbarLocation.SOUTH) { setLocationAndSize(-e.getY()); } else if (toolbar.getDockedLocation() == ToolbarLocation.WEST) { setLocationAndSize(e.getX()); } else { setLocationAndSize(-e.getX()); } docking.getAppState().persist(); } @Override public void mouseMoved(MouseEvent e) { } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-api/src/io/github/andrewauclair/moderndocking/internal/FloatingFrame.java
docking-api/src/io/github/andrewauclair/moderndocking/internal/FloatingFrame.java
/* Copyright (c) 2022 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 io.github.andrewauclair.moderndocking.internal; import io.github.andrewauclair.moderndocking.Dockable; import io.github.andrewauclair.moderndocking.api.DockingAPI; import io.github.andrewauclair.moderndocking.api.RootDockingPanelAPI; import io.github.andrewauclair.moderndocking.internal.floating.TempFloatingFrame; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.Point; import javax.swing.BorderFactory; import javax.swing.JFrame; import javax.swing.JLayeredPane; import javax.swing.SwingUtilities; /** * This class is used when a floating dockable is dropped outside any existing frames */ public class FloatingFrame extends JFrame { /** * The docking instance this floating frame belongs to */ private final DockingAPI docking; /** * The root docking panel for this floating frame */ private RootDockingPanelAPI root; /** * Create a new floating frame * * @param docking The docking instance this frame belongs to */ public FloatingFrame(DockingAPI docking) { this.docking = docking; setLayout(new BorderLayout()); setIconImages(docking.getMainWindow().getIconImages()); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); // create and add the root root = new RootDockingPanelAPI(docking, this){}; root.setBorder(BorderFactory.createEmptyBorder(0, 5, 5, 5)); add(root, BorderLayout.CENTER); // allow pinning for this frame docking.configureAutoHide(this, JLayeredPane.MODAL_LAYER, true); setVisible(true); pack(); } /** * Create a new floating frame with size, location, and state * * @param docking The docking instance this frame belongs to * @param location The location of the frame * @param size The size of the frame * @param state The state of the frame */ public FloatingFrame(DockingAPI docking, Point location, Dimension size, int state) { this.docking = docking; setLocation(location); setSize(size); setExtendedState(state); setIconImages(docking.getMainWindow().getIconImages()); setLayout(new BorderLayout()); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); // create and add the root RootDockingPanelAPI root = new RootDockingPanelAPI(docking, this){}; root.setBorder(BorderFactory.createEmptyBorder(0, 5, 5, 5)); add(root, BorderLayout.CENTER); // allow pinning for this frame docking.configureAutoHide(this, JLayeredPane.MODAL_LAYER, true); setVisible(true); } /** * Create a new floating frame. this is used when calling Docking.newWindow or when restoring the layout from a file * * @param docking The docking instance this window belongs to * @param dockable The dockable the window will contain * @param mousePosOnScreen The position of the mouse on screen * @param size The size of the window * @param state The state of the window */ public FloatingFrame(DockingAPI docking, Dockable dockable, Point mousePosOnScreen, Dimension size, int state) { this.docking = docking; DisplayPanel displayPanel = DockingInternal.get(docking).getWrapper(dockable).getDisplayPanel(); Point point = displayPanel.getLocation(); SwingUtilities.convertPointToScreen(point, displayPanel.getParent()); Point location = new Point(mousePosOnScreen); location.x -= mousePosOnScreen.x - point.x; location.y -= mousePosOnScreen.y - point.y; setLocation(location); setSize(size); setExtendedState(state); setIconImages(docking.getMainWindow().getIconImages()); setLayout(new BorderLayout()); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); // create and add the root RootDockingPanelAPI root = new RootDockingPanelAPI(docking, this){}; root.setBorder(BorderFactory.createEmptyBorder(0, 5, 5, 5)); add(root, BorderLayout.CENTER); // allow pinning for this frame docking.configureAutoHide(this, JLayeredPane.MODAL_LAYER, true); setVisible(true); finalizeSize(dockable, location, size); } /** * Create a floating frame from a temporary frame as a result of docking * * @param docking The docking instance this window belongs to * @param dockable The dockable the window will contain * @param floatingFrame The floating frame to set the frame size and location from */ public FloatingFrame(DockingAPI docking, Dockable dockable, TempFloatingFrame floatingFrame) { this.docking = docking; setLayout(new BorderLayout()); setIconImages(docking.getMainWindow().getIconImages()); // size the frame to the dockable size + the border size of the frame Dimension size = DockingInternal.get(docking).getWrapper(dockable).getDisplayPanel().getSize(); setSize(size); // dispose this frame when it closes setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); // set the location of this frame to the floating frame location setLocation(floatingFrame.getLocation()); // create and add the root RootDockingPanelAPI root = new RootDockingPanelAPI(docking, this){}; add(root, BorderLayout.CENTER); // allow pinning on this frame docking.configureAutoHide(this, JLayeredPane.MODAL_LAYER, true); // finally, dock the dockable and show this frame docking.dock(dockable, this); setVisible(true); Point onScreenPoint = floatingFrame.getLocation(); Dimension onScreenSize = floatingFrame.getSize(); finalizeSize(dockable, onScreenPoint, onScreenSize); } private void finalizeSize(Dockable dockable, Point onScreenPoint, Dimension onScreenSize) { SwingUtilities.invokeLater(() -> { // adjust the floating frame such that the dockable is in the correct location DisplayPanel displayPanel = DockingInternal.get(docking).getWrapper(dockable).getDisplayPanel(); Point point = displayPanel.getLocation(); SwingUtilities.convertPointToScreen(point, displayPanel.getParent()); Point finalPoint = new Point(this.getX() - (point.x - onScreenPoint.x), FloatingFrame.this.getY() - (point.y - onScreenPoint.y)); // make sure we keep the new frame on the screen finalPoint.y = Math.max(0, finalPoint.y); setLocation(finalPoint); Dimension currentPanelSize = displayPanel.getSize(); Dimension currentFrameSize = getSize(); Dimension newSize = new Dimension(currentFrameSize.width - currentPanelSize.width + onScreenSize.width, currentFrameSize.height - currentPanelSize.height + onScreenSize.height); setSize(newSize); }); } /** * Get the root panel * * @return Root of the floating frame */ public RootDockingPanelAPI getRoot() { return root; } @Override public void dispose() { // deregister the root panel now that we're disposing this frame docking.deregisterDockingPanel(this); super.dispose(); } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-api/src/io/github/andrewauclair/moderndocking/internal/DockingInternal.java
docking-api/src/io/github/andrewauclair/moderndocking/internal/DockingInternal.java
/* Copyright (c) 2022-2024 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 io.github.andrewauclair.moderndocking.internal; import io.github.andrewauclair.moderndocking.Dockable; import io.github.andrewauclair.moderndocking.DockingProperty; import io.github.andrewauclair.moderndocking.DockingRegion; import io.github.andrewauclair.moderndocking.api.DockingAPI; import io.github.andrewauclair.moderndocking.api.RootDockingPanelAPI; import io.github.andrewauclair.moderndocking.exception.DockableNotFoundException; import io.github.andrewauclair.moderndocking.exception.DockableRegistrationFailureException; import io.github.andrewauclair.moderndocking.exception.RootDockingPanelRegistrationFailureException; import io.github.andrewauclair.moderndocking.internal.floating.Floating; import io.github.andrewauclair.moderndocking.ui.DefaultHeaderUI; import io.github.andrewauclair.moderndocking.ui.DockingHeaderUI; import io.github.andrewauclair.moderndocking.ui.HeaderController; import io.github.andrewauclair.moderndocking.ui.HeaderModel; import java.awt.Dimension; import java.awt.Window; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.function.BiFunction; import java.util.stream.Collectors; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.SwingUtilities; /** * Internal utilities for the library */ public class DockingInternal { private final Map<String, DockableWrapper> anchors = new HashMap<>(); private final Map<String, DockableWrapper> dockables = new HashMap<>(); private final DockingAPI docking; private final Map<Window, InternalRootDockingPanel> rootPanels = new HashMap<>(); private static final Map<DockingAPI, DockingInternal> internals = new HashMap<>(); private final AppStatePersister appStatePersister; private boolean deregistering = false; /** * Create a new instance of our internal helper for the docking instance * * @param docking Docking instance */ public DockingInternal(DockingAPI docking) { this.docking = docking; this.appStatePersister = new AppStatePersister(docking); internals.put(docking, this); } /** * Lookup the internal helper for a docking instance * * @param docking The instance to find a helper for * @return The internal helper or null if not found */ public static DockingInternal get(DockingAPI docking) { return internals.get(docking); } /** * Remove an internal helper * * @param docking The docking instance */ public static void remove(DockingAPI docking) { internals.remove(docking); } /** * Get a map of RootDockingPanels to their Windows * * @return map of root panels */ public Map<Window, InternalRootDockingPanel> getRootPanels() { return rootPanels; } /** * Get access to the registered dockables * * @return List of registered dockables */ public List<Dockable> getDockables() { return dockables.values().stream() .map(DockableWrapper::getDockable) .collect(Collectors.toList()); } /** * registration function for DockingPanel * * @param panel Panel to register * @param parent The parent frame of the panel */ public void registerDockingPanel(RootDockingPanelAPI panel, JFrame parent) { if (rootPanels.containsKey(parent)) { throw new RootDockingPanelRegistrationFailureException(panel, parent); } Optional<Window> window = rootPanels.entrySet().stream() .filter(entry -> entry.getValue().getRootPanel() == panel) .findFirst() .map(Map.Entry::getKey); if (window.isPresent()) { throw new RootDockingPanelRegistrationFailureException(panel, window.get()); } InternalRootDockingPanel internalRoot = new InternalRootDockingPanel(docking, panel); rootPanels.put(parent, internalRoot); Floating.registerDockingWindow(docking, parent, internalRoot); appStatePersister.addWindow(parent); } /** * Register a RootDockingPanel * * @param panel RootDockingPanel to register * @param parent The parent JDialog of the panel */ public void registerDockingPanel(RootDockingPanelAPI panel, JDialog parent) { if (rootPanels.containsKey(parent)) { throw new RootDockingPanelRegistrationFailureException(panel, parent); } Optional<Window> window = rootPanels.entrySet().stream() .filter(entry -> entry.getValue().getRootPanel() == panel) .findFirst() .map(Map.Entry::getKey); if (window.isPresent()) { throw new RootDockingPanelRegistrationFailureException(panel, parent); } InternalRootDockingPanel internalRoot = new InternalRootDockingPanel(docking, panel); rootPanels.put(parent, internalRoot); Floating.registerDockingWindow(docking, parent, internalRoot); appStatePersister.addWindow(parent); } /** * Deregister a docking root panel * * @param parent The parent of the panel that we're deregistering */ public void deregisterDockingPanel(Window parent) { if (rootPanels.containsKey(parent)) { InternalRootDockingPanel root = rootPanels.get(parent); DockingComponentUtils.undockComponents(docking, root); } rootPanels.remove(parent); Floating.deregisterDockingWindow(parent); appStatePersister.removeWindow(parent); } /** * register a dockable with the framework * * @param dockable The dockable to register */ public void registerDockable(Dockable dockable) { if (dockables.containsKey(dockable.getPersistentID())) { throw new DockableRegistrationFailureException(dockable.getPersistentID()); } if (dockable.getTabText() == null) { throw new RuntimeException("Dockable '" + dockable.getPersistentID() + "' should not return 'null' for tabText()"); } validateDockingProperties(dockable); dockables.put(dockable.getPersistentID(), new DockableWrapper(docking, dockable, false)); } /** * Register an anchor with the framework * * @param anchor The anchor to register */ public void registerDockingAnchor(Dockable anchor) { if (anchors.containsKey(anchor.getPersistentID())) { throw new DockableRegistrationFailureException(anchor.getPersistentID()); } anchors.put(anchor.getPersistentID(), new DockableWrapper(docking, anchor, true)); } /** * Deregister an anchor with the framework * * @param anchor The anchor to deregister */ public void deregisterDockingAnchor(Dockable anchor) { anchors.remove(anchor.getPersistentID()); } private void validateDockingProperties(Dockable dockable) { List<Field> dockingPropFields = Arrays.stream(dockable.getClass().getDeclaredFields()) .filter(field -> field.getAnnotation(DockingProperty.class) != null) .collect(Collectors.toList()); if (dockingPropFields.size() > 0) { try { Method updateProperties = dockable.getClass().getMethod("updateProperties"); if (updateProperties.getDeclaringClass() == Dockable.class) { throw new RuntimeException("Dockable class " + dockable.getClass().getSimpleName() + " contains DockingProperty instances and should override updateProperties"); } } catch (NoSuchMethodException ignored) { // updateProperties has a default implementation in Dockable, so we will always find it and this exception should never happen } } for (Field field : dockingPropFields) { try { // make sure we can access the field if it is private/protected. only try this if we're sure we can't already access it // because it may result in an IllegalAccessException for trying if (!field.canAccess(dockable)) { field.setAccessible(true); } // grab the property and store the value by its name DockingProperty property = field.getAnnotation(DockingProperty.class); try { DockableProperties.validateProperty(field, property); } catch (Exception e) { // TODO possibly make a new DockingPropertyException throw new RuntimeException(String.format("Dockable: '%s' (%s), default value: '%s' for field '%s' (%s) is invalid", dockable.getPersistentID(), dockable.getClass().getSimpleName(), property.defaultValue(), field.getName(), field.getType().getSimpleName()), e); } } catch (SecurityException e) { // TODO handle this better e.printStackTrace(); } } } /** * Dockables must be deregistered so it can be properly disposed * * @param dockable The dockable to deregister */ public void deregisterDockable(Dockable dockable) { getWrapper(dockable).removeListeners(); dockables.remove(dockable.getPersistentID()); } // internal function to get the dockable wrapper public DockableWrapper getWrapper(Dockable dockable) { if (dockables.containsKey(dockable.getPersistentID())) { return dockables.get(dockable.getPersistentID()); } if (anchors.containsKey(dockable.getPersistentID())) { return anchors.get(dockable.getPersistentID()); } throw new DockableNotFoundException(dockable.getPersistentID()); } public boolean hasDockable(String persistentID) { return dockables.containsKey(persistentID); } public boolean hasAnchor(String persistentID) { return anchors.containsKey(persistentID); } /** * Find a dockable with the given persistent ID * @param persistentID persistent ID to search for * @return found dockable * @throws DockableNotFoundException if the dockable has not been found */ public Dockable getDockable(String persistentID) { if (dockables.containsKey(persistentID)) { return dockables.get(persistentID).getDockable(); } // TODO I'm not 100% sure about this one if (anchors.containsKey(persistentID)) { return anchors.get(persistentID).getDockable(); } throw new DockableNotFoundException(persistentID); } public void undock(Dockable dockable, boolean isTemporary) { if (!docking.isDocked(dockable)) { // nothing to undock return; } Window window = DockingComponentUtils.findWindowForDockable(docking, dockable); // TODO something about DockingStateAPI.restoreAnchor is causing a null here Objects.requireNonNull(window); InternalRootDockingPanel root = DockingComponentUtils.rootForWindow(docking, window); Objects.requireNonNull(root); DockableWrapper wrapper = getWrapper(dockable); wrapper.setRoot(root); if (docking.isHidden(dockable)) { root.undock(dockable); wrapper.setParent(null); wrapper.setHidden(false); } else { wrapper.getParent().undock(dockable); } wrapper.setWindow(null); DockingListeners.fireUndockedEvent(dockable, isTemporary); // make sure that can dispose this window, and we're not floating the last dockable in it if (docking.canDisposeWindow(window) && root.isEmpty() && !Floating.isFloating()) { deregisterDockingPanel(window); window.dispose(); } docking.getAppState().persist(); // force this dockable to dock again if we're not floating it if (!dockable.isClosable() && !Floating.isFloating() && !isDeregistering(docking)) { docking.dock(dockable, docking.getMainWindow()); } } public void fireDockedEventForFrame(Window window) { // everything has been restored, go through the list of dockables and fire docked events for the ones that are docked List<DockableWrapper> wrappers = dockables.values().stream() .filter(wrapper -> wrapper.getWindow() == window) .collect(Collectors.toList()); for (DockableWrapper wrapper : wrappers) { DockingListeners.fireDockedEvent(wrapper.getDockable()); } } /** * everything has been restored, go through the list of dockables and fire docked events for the ones that are docked * * @param docking The docking instance */ public static void fireDockedEventForAll(DockingAPI docking) { for (Dockable dockable : DockingInternal.get(docking).getDockables()) { if (docking.isDocked(dockable)) { DockingListeners.fireDockedEvent(dockable); } } } /** * Force a UI update on all dockables when changing look and feel. This ensures that any dockables not part of a free (i.e. not docked) * are properly updated with the new look and feel */ public void updateLAF() { for (DockableWrapper wrapper : dockables.values()) { SwingUtilities.updateComponentTreeUI(wrapper.getDisplayPanel()); wrapper.getHeaderUI().update(); } for (DockableWrapper wrapper : anchors.values()) { SwingUtilities.updateComponentTreeUI(wrapper.getDisplayPanel()); } for (InternalRootDockingPanel root : rootPanels.values()) { root.updateLAF(); updateLAF(root.getPanel()); } } private void updateLAF(DockingPanel panel) { if (panel instanceof DockedTabbedPanel) { ActiveDockableHighlighter.setNotSelectedBorder(panel); } else if (panel instanceof DockedSimplePanel) { DockedSimplePanel simplePanel = (DockedSimplePanel) panel; if (simplePanel.getParent() instanceof DockedTabbedPanel) { DockedTabbedPanel tabbedPanel = (DockedTabbedPanel) simplePanel.getParent(); if (tabbedPanel.getDockables().size() == 1) { ActiveDockableHighlighter.setNotSelectedBorder(panel); } } else { ActiveDockableHighlighter.setNotSelectedBorder(panel); } } else if (panel instanceof DockedSplitPanel) { DockedSplitPanel splitPanel = (DockedSplitPanel) panel; updateLAF(splitPanel.getLeft()); updateLAF(splitPanel.getRight()); } if (panel != null) { SwingUtilities.updateComponentTreeUI(panel); } } /** * Function used to create a new instance of the Header UI. This allows us to replace the function in the Modern Docking UI Extension */ public static BiFunction<HeaderController, HeaderModel, DockingHeaderUI> createHeaderUI = DefaultHeaderUI::new; /** * Create an instance of the default header specified with createHeaderUI * * @param headerController The header controller to use for the docking header * @param headerModel The header model to use for the docking heade * * @return A new instance of a DockingHeaderUI */ public static DockingHeaderUI createDefaultHeaderUI(HeaderController headerController, HeaderModel headerModel) { return createHeaderUI.apply(headerController, headerModel); } /** * Get the wrapper for an anchor * * @param anchor Anchor Persistent ID * * @return Anchor wrapper or null */ public DockableWrapper getAnchor(String anchor) { return anchors.get(anchor); } public void dockToLargestAnchorPanel(Dockable dockable, String anchor) { Optional<Dockable> biggest = docking.getDockables().stream() .filter(d -> docking.isDocked(d)) .filter(d -> getWrapper(d).getAnchor() == anchor) .sorted((o1, o2) -> { Dimension sizeA = getWrapper(o1).getParent().getSize(); Dimension sizeB = getWrapper(o2).getParent().getSize(); return Integer.compare(sizeB.height * sizeB.width, sizeA.height * sizeA.width); }) .findFirst(); if (biggest.isPresent()) { docking.dock(dockable, biggest.get(), DockingRegion.CENTER); } } public static boolean isDeregistering(DockingAPI docking) { return internals.get(docking).deregistering; } public static void setDeregistering(DockingAPI docking, boolean deregistering) { internals.get(docking).deregistering = deregistering; } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-api/src/io/github/andrewauclair/moderndocking/internal/CustomTabbedPane.java
docking-api/src/io/github/andrewauclair/moderndocking/internal/CustomTabbedPane.java
/* 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 io.github.andrewauclair.moderndocking.internal; import java.awt.Point; import java.awt.Rectangle; import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; import javax.swing.AbstractAction; import javax.swing.JComponent; import javax.swing.JTabbedPane; import javax.swing.KeyStroke; import javax.swing.SwingUtilities; /** * Custom JTabbedPane to be used by Modern Docking in order to add keyboard shortcuts for moving between tabs */ public class CustomTabbedPane extends JTabbedPane { /** * Create a new instance and configure the keyboard shortcuts */ public CustomTabbedPane() { setFocusable(false); getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put( KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, KeyEvent.ALT_DOWN_MASK), "press-left" ); getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put( KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, KeyEvent.ALT_DOWN_MASK), "press-right" ); getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put( KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, KeyEvent.ALT_DOWN_MASK | KeyEvent.ALT_GRAPH_DOWN_MASK), "press-left" ); getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put( KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, KeyEvent.ALT_DOWN_MASK | KeyEvent.ALT_GRAPH_DOWN_MASK), "press-right" ); getActionMap().put("press-left", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { int newIndex = getSelectedIndex() - 1; if (newIndex < 0) { newIndex = getTabCount() - 1; } setSelectedIndex(newIndex); } } ); getActionMap().put("press-right", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { int newIndex = getSelectedIndex() + 1; if (newIndex >= getTabCount()) { newIndex = 0; } setSelectedIndex(newIndex); } } ); } /** * Find the index of the tab that our mouse is over * * @param mousePosOnScreen The position of the mouse on screen * @param ignoreY Only check if we're within the X bounds * * @return The index of the tab at the mouse position, or -1 if none is found */ public int getTargetTabIndex(Point mousePosOnScreen, boolean ignoreY) { // convert the screen mouse position to a position on the tabbed pane Point newPoint = new Point(mousePosOnScreen); SwingUtilities.convertPointFromScreen(newPoint, this); Point d = isTopBottomTabPlacement(getTabPlacement()) ? new Point(1, 0) : new Point(0, 1); for (int i = 0; i < getTabCount(); i++) { Rectangle tab = getBoundsAt(i); if (ignoreY) { // we only care to check the x value newPoint.y = tab.y; } if (tab.contains(newPoint)) { return i; } } return -1; } /** * Check if the tab preference is TOP or BOTTOM * * @param tabPlacement The tab placement * @return true if tab is TOP or BOTTOM */ public static boolean isTopBottomTabPlacement(int tabPlacement) { return tabPlacement == TOP || tabPlacement == BOTTOM; } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-api/src/io/github/andrewauclair/moderndocking/internal/InternalRootDockingPanel.java
docking-api/src/io/github/andrewauclair/moderndocking/internal/InternalRootDockingPanel.java
/* Copyright (c) 2024 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 io.github.andrewauclair.moderndocking.internal; import io.github.andrewauclair.moderndocking.Dockable; import io.github.andrewauclair.moderndocking.DockableTabPreference; import io.github.andrewauclair.moderndocking.DockingRegion; import io.github.andrewauclair.moderndocking.api.DockingAPI; import io.github.andrewauclair.moderndocking.api.RootDockingPanelAPI; import io.github.andrewauclair.moderndocking.settings.Settings; import io.github.andrewauclair.moderndocking.ui.ToolbarLocation; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Window; import java.util.Collections; import java.util.List; import javax.swing.SwingUtilities; /** * Internal wrapper panel for the applications root docking panel. This is used to add the auto-hide toolbars */ public class InternalRootDockingPanel extends DockingPanel { /** * The docking instance this internal root docking panel belongs to */ private final DockingAPI docking; /** * The application root docking panel this internal panel wraps */ private final RootDockingPanelAPI rootPanel; /** * The first panel contained in the root */ private DockingPanel panel = null; /** * South toolbar of this panel. Only created if pinning is supported. */ private DockableToolbar southToolbar = null; /** * West toolbar of this panel. Only created if pinning is supported. */ private DockableToolbar westToolbar = null; /** * East toolbar of this panel. Only created if pinning is supported. */ private DockableToolbar eastToolbar = null; /** * Create new instance * * @param docking Docking instance * @param rootPanel Root panel from application */ public InternalRootDockingPanel(DockingAPI docking, RootDockingPanelAPI rootPanel) { this.docking = docking; this.rootPanel = rootPanel; setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 0; gbc.weightx = 1; gbc.weighty = 1; gbc.fill = GridBagConstraints.BOTH; rootPanel.add(this, gbc); southToolbar = new DockableToolbar(docking, rootPanel.getWindow(), rootPanel, ToolbarLocation.SOUTH); westToolbar = new DockableToolbar(docking, rootPanel.getWindow(), rootPanel, ToolbarLocation.WEST); eastToolbar = new DockableToolbar(docking, rootPanel.getWindow(), rootPanel, ToolbarLocation.EAST); } /** * Get the application root that we're wrapping * * @return Application window root */ public RootDockingPanelAPI getRootPanel() { return rootPanel; } /** * Get the main panel contained in this root panel * * @return Main panel */ public DockingPanel getPanel() { return panel; } /** * Check if this root is empty * * @return True if empty */ public boolean isEmpty() { if (southToolbar != null && southToolbar.shouldDisplay()) { return false; } if (westToolbar != null && westToolbar.shouldDisplay()) { return false; } if (eastToolbar != null && eastToolbar.shouldDisplay()) { return false; } return panel == null; } /** * Set the main panel * * @param panel New main panel */ public void setPanel(DockingPanel panel) { this.panel = panel; if (panel != null) { this.panel.setParent(this); createContents(); } } private boolean removeExistingPanel() { remove(rootPanel.getEmptyPanel()); if (panel != null) { remove(panel); panel = null; return true; } return false; } @Override public void removeNotify() { // this class has a default constructor which could be called and docking would be null if (docking != null) { Window rootWindow = (Window) SwingUtilities.getRoot(this); docking.deregisterDockingPanel(rootWindow); } super.removeNotify(); } @Override public String getAnchor() { return null; } @Override public void setParent(DockingPanel parent) { } @Override public void dock(Dockable dockable, DockingRegion region, double dividerProportion) { DockableWrapper wrapper = DockingInternal.get(docking).getWrapper(dockable); // pass docking to panel if it exists // panel does not exist, create new simple panel if (panel != null) { panel.dock(dockable, region, dividerProportion); } else if (Settings.defaultTabPreference() == DockableTabPreference.TOP_ALWAYS) { setPanel(new DockedTabbedPanel(docking, wrapper, "")); wrapper.setWindow(rootPanel.getWindow()); } else { setPanel(new DockedSimplePanel(docking, wrapper, "")); wrapper.setWindow(rootPanel.getWindow()); } } @Override public void undock(Dockable dockable) { if (rootPanel.isLocationSupported(ToolbarLocation.WEST) && westToolbar.hasDockable(dockable)) { westToolbar.removeDockable(dockable); } else if (rootPanel.isLocationSupported(ToolbarLocation.EAST) && eastToolbar.hasDockable(dockable)) { eastToolbar.removeDockable(dockable); } else if (rootPanel.isLocationSupported(ToolbarLocation.SOUTH) && southToolbar.hasDockable(dockable)) { southToolbar.removeDockable(dockable); } createContents(); } @Override public void replaceChild(DockingPanel child, DockingPanel newChild) { if (panel == child) { setPanel(newChild); } } @Override public void removeChild(DockingPanel child) { if (child == panel) { if (removeExistingPanel()) { createContents(); } } } public List<DockingPanel> getChildren() { return Collections.singletonList(panel); } /** * Remove a dockable from its toolbar and pin it back into the root * * @param dockable Dockable to pin */ public void setDockableShown(Dockable dockable) { // if the dockable is currently unpinned, remove it from the toolbar, then adjust the toolbars if (rootPanel.isLocationSupported(ToolbarLocation.WEST) && westToolbar.hasDockable(dockable)) { westToolbar.removeDockable(dockable); dock(dockable, DockingRegion.WEST, 0.25f); } else if (rootPanel.isLocationSupported(ToolbarLocation.EAST) && eastToolbar.hasDockable(dockable)) { eastToolbar.removeDockable(dockable); dock(dockable, DockingRegion.EAST, 0.25f); } else if (rootPanel.isLocationSupported(ToolbarLocation.SOUTH) && southToolbar.hasDockable(dockable)) { southToolbar.removeDockable(dockable); dock(dockable, DockingRegion.SOUTH, 0.25f); } createContents(); } /** * set a dockable to be unpinned at the given location * * @param dockable Dockable to unpin * @param location Toolbar to unpin to */ public void setDockableHidden(Dockable dockable, ToolbarLocation location) { if (!rootPanel.isAutoHideSupported()) { return; } switch (location) { case WEST: { if (rootPanel.isLocationSupported(ToolbarLocation.WEST)) { westToolbar.addDockable(dockable); } break; } case SOUTH: { if (rootPanel.isLocationSupported(ToolbarLocation.SOUTH)) { southToolbar.addDockable(dockable); } break; } case EAST: { if (rootPanel.isLocationSupported(ToolbarLocation.EAST)) { eastToolbar.addDockable(dockable); } break; } } createContents(); } /** * Get a list of the unpinned dockables on the specified toolbar * * @param location Toolbar location * @return List of unpinned dockables */ public java.util.List<String> hiddenPersistentIDs(ToolbarLocation location) { switch (location) { case WEST: return westToolbar.getPersistentIDs(); case EAST: return eastToolbar.getPersistentIDs(); case SOUTH: return southToolbar.getPersistentIDs(); } return Collections.emptyList(); } public int getSlidePosition(Dockable dockable) { if (southToolbar.hasDockable(dockable)) { return southToolbar.getSlidePosition(dockable); } else if (westToolbar.hasDockable(dockable)) { return westToolbar.getSlidePosition(dockable); } return eastToolbar.getSlidePosition(dockable); } public void setSlidePosition(Dockable dockable, int position) { if (southToolbar.hasDockable(dockable)) { southToolbar.setSlidePosition(dockable, position); } } private void createContents() { removeAll(); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 0; gbc.weightx = 0.0; gbc.weighty = 0.0; gbc.fill = GridBagConstraints.VERTICAL; if (rootPanel.isAutoHideSupported() && westToolbar.shouldDisplay()) { add(westToolbar, gbc); gbc.gridx++; } gbc.weightx = 1.0; gbc.weighty = 1.0; gbc.fill = GridBagConstraints.BOTH; if (panel == null) { add(rootPanel.getEmptyPanel(), gbc); } else { add(panel, gbc); } gbc.gridx++; gbc.weightx = 0.0; gbc.weighty = 0.0; gbc.fill = GridBagConstraints.VERTICAL; if (rootPanel.isAutoHideSupported() && eastToolbar.shouldDisplay()) { add(eastToolbar, gbc); } gbc.gridx = 0; gbc.gridy++; gbc.gridwidth = 3; gbc.weightx = 1.0; gbc.fill = GridBagConstraints.HORIZONTAL; if (rootPanel.isAutoHideSupported() && southToolbar.shouldDisplay()) { add(southToolbar, gbc); } revalidate(); repaint(); } /** * Hide all unpinned panels on the west, south and east toolbars */ public void hideHiddenPanels() { if (westToolbar != null) { westToolbar.hideAll(); } if (southToolbar != null) { southToolbar.hideAll(); } if (eastToolbar != null) { eastToolbar.hideAll(); } } /** * Get a list of IDs for unpinned dockables on the west toolbar * * @return Persistent IDs */ public java.util.List<String> getWestAutoHideToolbarIDs() { if (westToolbar == null) { return Collections.emptyList(); } return westToolbar.getPersistentIDs(); } /** * Get a list of IDs for unpinned dockables on the east toolbar * * @return Persistent IDs */ public java.util.List<String> getEastAutoHideToolbarIDs() { if (eastToolbar == null) { return Collections.emptyList(); } return eastToolbar.getPersistentIDs(); } /** * Get a list of IDs for unpinned dockables on the south toolbar * * @return Persistent IDs */ public List<String> getSouthAutoHideToolbarIDs() { if (southToolbar == null) { return Collections.emptyList(); } return southToolbar.getPersistentIDs(); } /** * Update the look and feel of the toolbars and empty panel */ public void updateLAF() { if (southToolbar != null) { SwingUtilities.updateComponentTreeUI(southToolbar); } if (westToolbar != null) { SwingUtilities.updateComponentTreeUI(westToolbar); } if (eastToolbar != null) { SwingUtilities.updateComponentTreeUI(eastToolbar); } if (rootPanel.getEmptyPanel() != null) { SwingUtilities.updateComponentTreeUI(rootPanel.getEmptyPanel()); } } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-api/src/io/github/andrewauclair/moderndocking/internal/FailedDockable.java
docking-api/src/io/github/andrewauclair/moderndocking/internal/FailedDockable.java
/* Copyright (c) 2022 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 io.github.andrewauclair.moderndocking.internal; import io.github.andrewauclair.moderndocking.Dockable; import io.github.andrewauclair.moderndocking.api.DockingAPI; import javax.swing.JPanel; /** * Represents a dockable that has failed to load from a layout file. * <p> * These are stripped out after restoring from the layout. */ public class FailedDockable extends JPanel implements Dockable { /** * The docking instance this failed dockable belongs to */ private final DockingAPI docking; /** * Persistent ID that no dockable has been registered for */ private final String persistentID; /** * Create a new FailedDockable * * @param docking The docking instance this failed dockable belongs to * @param persistentID Persistent ID that has failed to load */ public FailedDockable(DockingAPI docking, String persistentID) { this.docking = docking; this.persistentID = persistentID; docking.registerDockable(this); } /** * Deregister this dockable */ public void destroy() { docking.deregisterDockable(this); } @Override public String getPersistentID() { return persistentID; } @Override public int getType() { return 0; } @Override public String getTabText() { return "Failed"; } @Override public boolean isFloatingAllowed() { return false; } @Override public boolean isClosable() { return false; } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-api/src/io/github/andrewauclair/moderndocking/internal/DockableProperties.java
docking-api/src/io/github/andrewauclair/moderndocking/internal/DockableProperties.java
/* 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 io.github.andrewauclair.moderndocking.internal; import io.github.andrewauclair.moderndocking.Dockable; import io.github.andrewauclair.moderndocking.DockingProperty; import io.github.andrewauclair.moderndocking.Property; import io.github.andrewauclair.moderndocking.api.LayoutPersistenceAPI; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.Serializable; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.util.Arrays; import java.util.Base64; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.logging.Level; import java.util.logging.Logger; import java.util.stream.Collectors; /** * Internal utilities for managing dockable properties */ public class DockableProperties { private static boolean loadingLegacyFile = false; private static final Logger logger = Logger.getLogger(DockableProperties.class.getPackageName()); /** * Unused. All methods are static */ private DockableProperties() { } /** * If true, we're loading a file from before 0.12.0 * * @param legacy Legacy flag */ public static void setLoadingLegacyFile(boolean legacy) { loadingLegacyFile = legacy; } /** * Set the values of properties on a dockable * * @param wrapper The dockable to update * @param properties The properties to set on the dockable DockingProperty annotated fields */ public static void configureProperties(DockableWrapper wrapper, Map<String, Property> properties) { Dockable dockable = wrapper.getDockable(); // remove any existing properties for (String key : wrapper.getProperties().keySet()) { wrapper.removeProperty(key); } // add all properties to the wrapper for (String key : properties.keySet()) { wrapper.setProperty(key, properties.get(key)); } List<Field> dockingPropFields = Arrays.stream(dockable.getClass().getDeclaredFields()) .filter(field -> field.getAnnotation(DockingProperty.class) != null) .collect(Collectors.toList()); for (Field field : dockingPropFields) { try { // make sure we can access the field if it is private/protected. only try this if we're sure we can't already access it // because it may result in an IllegalAccessException for trying if (!field.canAccess(dockable)) { field.setAccessible(true); } // grab the property and store the value by its name DockingProperty property = field.getAnnotation(DockingProperty.class); if (properties.containsKey(property.name())) { Property prop = properties.get(property.name()); try { if (loadingLegacyFile) { Property.StringProperty legacyProp = (Property.StringProperty) properties.get(property.name()); prop = parseProperty(prop.getName(), field.getType().getSimpleName().toString(), legacyProp.getValue()); } DockableProperties.validateProperty(field, prop); } catch (Exception e) { // TODO possibly make a new DockingPropertyException throw new RuntimeException(String.format("Dockable: '%s' (%s), default value: '%s' for field '%s' (%s) is invalid", dockable.getPersistentID(), dockable.getClass().getSimpleName(), property.defaultValue(), field.getName(), field.getType().getSimpleName()), e); } setProperty(dockable, field, prop); // remove the property from the wrapper as it is more specific than the static props wrapper.removeProperty(property.name()); } else { // set the default of the type setProperty(dockable, field, createProperty(field, property)); } } catch (IllegalAccessException | SecurityException e) { // TODO handle this better e.printStackTrace(); } } dockable.updateProperties(); } /** * Get the properties from the dockable as a map * * @param wrapper The dockable to get properties for * * @return Map of properties */ public static Map<String, Property> saveProperties(DockableWrapper wrapper) { Dockable dockable = wrapper.getDockable(); Map<String, Property> properties = new HashMap<>(wrapper.getProperties()); List<Field> dockingPropFields = Arrays.stream(dockable.getClass().getDeclaredFields()) .filter(field -> field.getAnnotation(DockingProperty.class) != null) .collect(Collectors.toList()); for (Field field : dockingPropFields) { try { // make sure we can access the field if it is private/protected field.setAccessible(true); // grab the property and store the value by its name DockingProperty property = field.getAnnotation(DockingProperty.class); properties.put(property.name(), getProperty(wrapper, property.name(), field)); } catch (IllegalAccessException ignore) { } } return properties; } // throws if validation failed /** * Validate a property instance * * @param field The field for the property * @param property The docking property annotation */ public static void validateProperty(Field field, DockingProperty property) { createProperty(field, property); } /** * Validate a property * * @param field The field for the property * @param property The internal property instance */ public static void validateProperty(Field field, Property property) { Objects.requireNonNull(field); Objects.requireNonNull(property); Property prop = createProperty(field, property.getName(), property.toString()); if (prop.getType() != property.getType()) { throw new RuntimeException("Type of property does not match type of value."); } } /** * Parse a property string into the proper type * * @param property Property name * @param type Type of property * @param value The string value of the property * * @return Instance of Property with the proper Java class type */ public static Property parseProperty(String property, String type, String value) { if (type.equals("byte")) { return new Property.ByteProperty(property, value.isEmpty() ? (byte) 0 : Byte.parseByte(value)); } else if (type.equals("short")) { return new Property.ShortProperty(property, value.isEmpty() ? (short) 0 : Short.parseShort(value)); } else if (type.equals("int")) { return new Property.IntProperty(property, value.isEmpty() ? 0 : Integer.parseInt(value)); } else if (type.equals("long")) { return new Property.LongProperty(property, value.isEmpty() ? (long) 0 : Long.parseLong(value)); } else if (type.equals("float")) { return new Property.FloatProperty(property, value.isEmpty() ? 0.0f : Float.parseFloat(value)); } else if (type.equals("double")) { return new Property.DoubleProperty(property, value.isEmpty() ? 0.0 : Double.parseDouble(value)); } else if (type.equals("char")) { return new Property.CharacterProperty(property, value.isEmpty() ? '\0' : value.charAt(0)); } else if (type.equals("boolean")) { return new Property.BooleanProperty(property, !value.isEmpty() && Boolean.parseBoolean(value)); } else if (type.equals("String")) { return new Property.StringProperty(property, value); } else if (type.equals("Serializable")) { byte[] data = Base64.getDecoder().decode(value); try (ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(data))) { return new Property.SerializableProperty(property, (Serializable) in.readObject()); } catch (IOException | ClassNotFoundException e) { throw new RuntimeException(e); } } else { throw new RuntimeException("Unsupported property type"); } } private static Property createProperty(Field field, DockingProperty property) { String value = ""; if (!Objects.equals(property.defaultValue(), "__no_default_value__")) { value = property.defaultValue(); } return createProperty(field, property.name(), value); } private static Property createProperty(Field field, String property, String value) { Class<?> type = field.getType(); if (type == byte.class) { return new Property.ByteProperty(property, value.isEmpty() ? (byte) 0 : Byte.parseByte(value)); } else if (type == short.class) { return new Property.ShortProperty(property, value.isEmpty() ? (short) 0 : Short.parseShort(value)); } else if (type == int.class) { return new Property.IntProperty(property, value.isEmpty() ? 0 : Integer.parseInt(value)); } else if (type == long.class) { return new Property.LongProperty(property, value.isEmpty() ? (long) 0 : Long.parseLong(value)); } else if (type == float.class) { return new Property.FloatProperty(property, value.isEmpty() ? 0.0f : Float.parseFloat(value)); } else if (type == double.class) { return new Property.DoubleProperty(property, value.isEmpty() ? 0.0 : Double.parseDouble(value)); } else if (type == char.class) { return new Property.CharacterProperty(property, value.isEmpty() ? '\0' : value.charAt(0)); } else if (type == boolean.class) { return new Property.BooleanProperty(property, !value.isEmpty() && Boolean.parseBoolean(value)); } else if (type == String.class) { return new Property.StringProperty(property, value); } else if (Serializable.class.isInstance(type)) { if (value.isEmpty()) { try { return new Property.SerializableProperty(property, (Serializable) type.getConstructor().newInstance()); } catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException ex) { throw new RuntimeException(ex); } } byte[] data = Base64.getDecoder().decode(value); try (ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(data))) { return new Property.SerializableProperty(property, (Serializable) in.readObject()); } catch (IOException | ClassNotFoundException e) { throw new RuntimeException(e); } } // else if (type.isEnum()) { // return Integer.toString(((Enum<?>) field.get(dockable)).ordinal()); // return ""; // } else { throw new RuntimeException("Unsupported property type"); } } private static Property getProperty(DockableWrapper wrapper, String property, Field field) throws IllegalAccessException { Dockable dockable = wrapper.getDockable(); Class<?> type = field.getType(); if (type == byte.class) { return new Property.ByteProperty(property, (byte) field.get(dockable)); } else if (type == short.class) { return new Property.ShortProperty(property, (short) field.get(dockable)); } else if (type == int.class) { return new Property.IntProperty(property, (int) field.get(dockable)); } else if (type == long.class) { return new Property.LongProperty(property, (long) field.get(dockable)); } else if (type == float.class) { return new Property.FloatProperty(property, (float) field.get(dockable)); } else if (type == double.class) { return new Property.DoubleProperty(property, (double) field.get(dockable)); } else if (type == char.class) { return new Property.CharacterProperty(property, (char) field.get(dockable)); } else if (type == boolean.class) { return new Property.BooleanProperty(property, (boolean) field.get(dockable)); } else if (type == String.class) { return new Property.StringProperty(property, (String) field.get(dockable)); } else if (Serializable.class.isInstance(type)) { return new Property.SerializableProperty(property, (Serializable) field.get(dockable)); } // else if (type.isEnum()) { // return Integer.toString(((Enum<?>) field.get(dockable)).ordinal()); // return ""; // } else { throw new RuntimeException("Unsupported property type"); } } private static void setProperty(Dockable dockable, Field field, Property value) throws IllegalAccessException { Class<?> type = field.getType(); if (type == byte.class) { field.set(dockable, ((Property.ByteProperty) value).getValue()); } else if (type == short.class) { field.set(dockable, ((Property.ShortProperty) value).getValue()); } else if (type == int.class) { field.set(dockable, ((Property.IntProperty) value).getValue()); } else if (type == long.class) { field.set(dockable, ((Property.LongProperty) value).getValue()); } else if (type == float.class) { field.set(dockable, ((Property.FloatProperty) value).getValue()); } else if (type == double.class) { field.set(dockable, ((Property.DoubleProperty) value).getValue()); } else if (type == char.class) { field.set(dockable, ((Property.CharacterProperty) value).getValue()); } else if (type == boolean.class) { field.set(dockable, ((Property.BooleanProperty) value).getValue()); } else if (type == String.class) { field.set(dockable, ((Property.StringProperty) value).getValue()); } else if (Serializable.class.isInstance(type)) { Serializable serializable = ((Property.SerializableProperty) value).getValue(); field.set(dockable, type.cast(serializable)); } // else if (type.isEnum()) { // int ordinal = Integer.parseInt(value); // // field.set(dockable, type.getEnumConstants()[ordinal]); // } else { throw new RuntimeException("Unsupported property type"); } } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-api/src/io/github/andrewauclair/moderndocking/internal/DockedSimplePanel.java
docking-api/src/io/github/andrewauclair/moderndocking/internal/DockedSimplePanel.java
/* Copyright (c) 2022 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 io.github.andrewauclair.moderndocking.internal; import io.github.andrewauclair.moderndocking.Dockable; import io.github.andrewauclair.moderndocking.DockingRegion; import io.github.andrewauclair.moderndocking.api.DockingAPI; import io.github.andrewauclair.moderndocking.settings.Settings; import java.awt.BorderLayout; import java.awt.Color; import java.util.Collections; import java.util.List; import javax.swing.BorderFactory; import javax.swing.JSplitPane; import javax.swing.UIManager; /** * simple docking panel that only has a single Dockable in the center */ public class DockedSimplePanel extends DockingPanel { /** * Wrapper of the dockable in this simple panel */ private final DockableWrapper dockable; /** * The docking instance this panel belongs to */ private final DockingAPI docking; /** * The anchor this panel belongs to, if any */ private String anchor = ""; /** * Parent panel of this simple panel */ private DockingPanel parent; /** * Should we add the 1 pixel empty border used by the active dockable highlighter? */ private final boolean addHighlightBorder; /** * Create a new instance of DockedSimplePanel with a wrapper * * @param docking Instance of the docking framework that this panel belongs to * @param dockable Wrapper of the dockable in this simple panel * @param anchor The anchor associated with this docking panel */ public DockedSimplePanel(DockingAPI docking, DockableWrapper dockable, String anchor) { this(docking, dockable, anchor, dockable.getDisplayPanel()); } /** * Create a new instance of DockedSimplePanel with a wrapper * * @param docking Instance of the docking framework that this panel belongs to * @param dockable Wrapper of the dockable in this simple panel * @param anchor The anchor associated with this docking panel * @param displayPanel The panel to display in the DockedSimplePanel for this dockable */ public DockedSimplePanel(DockingAPI docking, DockableWrapper dockable, String anchor, DisplayPanel displayPanel) { this(docking, dockable, anchor, displayPanel, true); } /** * Create a new instance of DockedSimplePanel with a wrapper * * @param docking Instance of the docking framework that this panel belongs to * @param dockable Wrapper of the dockable in this simple panel * @param anchor The anchor associated with this docking panel * @param displayPanel The panel to display in the DockedSimplePanel for this dockable * @param addHighlightBorder Use the active dockable highlighter borders */ public DockedSimplePanel(DockingAPI docking, DockableWrapper dockable, String anchor, DisplayPanel displayPanel, boolean addHighlightBorder) { this.addHighlightBorder = addHighlightBorder; setLayout(new BorderLayout()); if (addHighlightBorder) { setNotSelectedBorder(); } dockable.setParent(this); dockable.setAnchor(anchor); this.dockable = dockable; this.docking = docking; this.anchor = anchor; add(displayPanel, BorderLayout.CENTER); } /** * Get the wrapper of the dockable contained in this simple panel * * @return Contained dockable */ public DockableWrapper getWrapper() { return dockable; } @Override public String getAnchor() { return anchor; } @Override public void setAnchor(String anchor) { this.anchor = anchor; } @Override public void setParent(DockingPanel parent) { this.parent = parent; } @Override public void dock(Dockable dockable, DockingRegion region, double dividerProportion) { // docking to CENTER: Simple -> Tabbed // docking else where: Simple -> Split DockableWrapper wrapper = DockingInternal.get(docking).getWrapper(dockable); wrapper.setWindow(this.dockable.getWindow()); if (getParent() instanceof DockedTabbedPanel) { ((DockedTabbedPanel) parent).addPanel(wrapper); } else if (region == DockingRegion.CENTER) { DockedTabbedPanel tabbedPanel = new DockedTabbedPanel(docking, this.dockable, anchor); tabbedPanel.addPanel(wrapper); DockingListeners.fireHiddenEvent(this.dockable.getDockable()); parent.replaceChild(this, tabbedPanel); } else { DockedSplitPanel split = new DockedSplitPanel(docking, this.dockable.getWindow(), anchor); parent.replaceChild(this, split); DockingPanel newPanel; if (wrapper.isAnchor()) { newPanel = new DockedAnchorPanel(docking, wrapper); } else if (Settings.alwaysDisplayTabsMode()) { newPanel = new DockedTabbedPanel(docking, wrapper, anchor); } else { newPanel = new DockedSimplePanel(docking, wrapper, anchor); } 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); } revalidate(); repaint(); } @Override public void undock(Dockable dockable) { if (this.dockable.getDockable() == dockable) { remove(this.dockable.getDisplayPanel()); DockableWrapper anchorWrapper = DockingInternal.get(docking).getAnchor(anchor); anchor = ""; if (anchorWrapper == null || !DockingComponentUtils.isAnchorEmpty(docking, anchorWrapper.getDockable())) { parent.removeChild(this); } else { anchor = ""; parent.replaceChild(this, new DockedAnchorPanel(docking, anchorWrapper)); anchorWrapper.setWindow(DockingInternal.get(docking).getWrapper(dockable).getWindow()); } this.dockable.setParent(null); revalidate(); repaint(); } } @Override public void replaceChild(DockingPanel child, DockingPanel newChild) { // no-op, simple panel has no children } @Override public void removeChild(DockingPanel child) { // no-op, simple panel has no children } @Override public List<DockingPanel> getChildren() { return Collections.emptyList(); } @Override public boolean isInAutoHideToolbar() { return !addHighlightBorder; } private void setNotSelectedBorder() { if (!Settings.isActiveHighlighterEnabled()) { return; } Color color = UIManager.getColor("Component.borderColor"); setBorder( BorderFactory.createCompoundBorder( BorderFactory.createEmptyBorder(1, 1, 1, 1), BorderFactory.createLineBorder(color, 1) ) ); } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-api/src/io/github/andrewauclair/moderndocking/internal/DisplayPanel.java
docking-api/src/io/github/andrewauclair/moderndocking/internal/DisplayPanel.java
/* Copyright (c) 2022 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 io.github.andrewauclair.moderndocking.internal; import io.github.andrewauclair.moderndocking.settings.Settings; import java.awt.Component; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import javax.swing.JPanel; import javax.swing.JScrollPane; /** * The internal JPanel used to display the Dockable plus its header */ public class DisplayPanel extends JPanel { /** * Dockable contained in this display panel */ private final DockableWrapper wrapper; /** * Is this display panel for an anchor? Tells us to hide the header */ private final boolean isAnchor; /** * Create a new internal display panel for the dockable * * @param wrapper Wrapper for the dockable that this panel will represent * @param isAnchor Is this display panel an anchor? Used to hide the header */ public DisplayPanel(DockableWrapper wrapper, boolean isAnchor) { this.wrapper = wrapper; this.isAnchor = isAnchor; setLayout(new GridBagLayout()); buildUI(); } private void buildUI() { removeAll(); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 0; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.weightx = 1.0; if (!isAnchor) { if (!Settings.alwaysDisplayTabsMode() || wrapper.isHidden()) { if (!(wrapper.getParent() instanceof DockedTabbedPanel) || ((DockedTabbedPanel) wrapper.getParent()).isUsingBottomTabs()) { add((Component) wrapper.getHeaderUI(), gbc); gbc.gridy++; } } } gbc.weighty = 1.0; gbc.fill = GridBagConstraints.BOTH; if (wrapper.getDockable().isWrappableInScrollpane()) { add(new JScrollPane((Component) wrapper.getDockable()), gbc); } else { add((Component) wrapper.getDockable(), gbc); } } /** * Get the wrapper used in this panel * * @return Wrapper for this panel */ public DockableWrapper getWrapper() { return wrapper; } /** * The parent for this display panel has changed and the panel needs to be updated for the new parent */ public void parentChanged() { buildUI(); } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-api/src/io/github/andrewauclair/moderndocking/internal/ActiveDockableHighlighter.java
docking-api/src/io/github/andrewauclair/moderndocking/internal/ActiveDockableHighlighter.java
/* Copyright (c) 2022 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 io.github.andrewauclair.moderndocking.internal; import io.github.andrewauclair.moderndocking.Dockable; import io.github.andrewauclair.moderndocking.api.DockingAPI; import io.github.andrewauclair.moderndocking.exception.DockableRegistrationFailureException; import io.github.andrewauclair.moderndocking.settings.Settings; import io.github.andrewauclair.moderndocking.ui.DockingSettings; import java.awt.AWTEvent; import java.awt.Color; import java.awt.Toolkit; import java.awt.Window; import java.awt.event.AWTEventListener; import java.awt.event.MouseEvent; import java.beans.PropertyChangeListener; import javax.swing.BorderFactory; import javax.swing.SwingUtilities; import javax.swing.UIManager; /** * This class is responsible for adding a selected border around the dockable at the current mouse position. * <p> * Using an AWT Event Listener we can listen for global MOUSE_ENTERED and MOUSE_EXITED to add/remove the border. */ public class ActiveDockableHighlighter { private final AWTEventListener awtEventListener; private final PropertyChangeListener propertyChangeListener; // the current active panel private DockingPanel activePanel = null; /** * Default constructor to create the highlighter * * @param docking Docking instance */ public ActiveDockableHighlighter(DockingAPI docking) { // use an AWT event listener to set a border around the dockable that the mouse is currently over awtEventListener = e -> { if (Settings.isActiveHighlighterEnabled() && (e.getID() == MouseEvent.MOUSE_ENTERED || e.getID() == MouseEvent.MOUSE_EXITED)) { DockingPanel dockable = DockingComponentUtils.findDockingPanelAtScreenPos(docking, ((MouseEvent) e).getLocationOnScreen()); if (activePanel != null && dockable == null) { setNotSelectedBorder(activePanel); activePanel = null; } if (activePanel != dockable && (dockable instanceof DockedSimplePanel || dockable instanceof DockedTabbedPanel || dockable instanceof DockedAnchorPanel)) { if (activePanel != null) { setNotSelectedBorder(activePanel); } activePanel = dockable; setSelectedBorder(); } } else if (e.getID() == MouseEvent.MOUSE_PRESSED) { Dockable dockable = DockingComponentUtils.findDockableAtScreenPos(docking, ((MouseEvent) e).getLocationOnScreen()); if (dockable != null) { Window window = DockingComponentUtils.findWindowForDockable(docking, dockable); if (!DockingInternal.get(docking).getWrapper(dockable).isHidden()) { try { InternalRootDockingPanel root = DockingComponentUtils.rootForWindow(docking, window); root.hideHiddenPanels(); } catch (DockableRegistrationFailureException ignore) { } } } } }; Toolkit.getDefaultToolkit().addAWTEventListener(awtEventListener, AWTEvent.MOUSE_EVENT_MASK); propertyChangeListener = e -> { if (Settings.isActiveHighlighterEnabled() && "lookAndFeel".equals(e.getPropertyName())) { SwingUtilities.invokeLater(() -> { if (activePanel != null) { setSelectedBorder(); } }); } }; UIManager.addPropertyChangeListener(propertyChangeListener); } /** * Removing the active dockable highlighter listeners */ public void removeListeners() { Toolkit.getDefaultToolkit().removeAWTEventListener(awtEventListener); UIManager.removePropertyChangeListener(propertyChangeListener); } /** * Set the selected border on the active panel that the mouse is over */ private void setSelectedBorder() { Color color = DockingSettings.getHighlighterSelectedBorder(); activePanel.setBorder(BorderFactory.createLineBorder(color, 2)); } /** * Change the border back to not selected. Done when the mouse moves off the panel * * @param panel The panel to change the border on */ public static void setNotSelectedBorder(DockingPanel panel) { Color color = DockingSettings.getHighlighterNotSelectedBorder(); panel.setBorder( BorderFactory.createCompoundBorder( BorderFactory.createEmptyBorder(1, 1, 1, 1), BorderFactory.createLineBorder(color, 1) ) ); } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-api/src/io/github/andrewauclair/moderndocking/internal/DockedAnchorPanel.java
docking-api/src/io/github/andrewauclair/moderndocking/internal/DockedAnchorPanel.java
/* Copyright (c) 2025 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 io.github.andrewauclair.moderndocking.internal; import io.github.andrewauclair.moderndocking.Dockable; import io.github.andrewauclair.moderndocking.DockingRegion; import io.github.andrewauclair.moderndocking.api.DockingAPI; import io.github.andrewauclair.moderndocking.settings.Settings; import java.awt.BorderLayout; import java.util.Collections; import java.util.List; /** * Docking panel that wraps the application anchor panel for display */ public class DockedAnchorPanel extends DockingPanel { /** * The docking instance this anchor belongs to */ private final DockingAPI docking; /** * The wrapper for the anchor */ private final DockableWrapper anchor; /** * Parent panel of this simple panel */ private DockingPanel parent; /** * Create a new anchor panel to wrap the application anchor * * @param docking The docking instance this panel belongs to * @param anchor The anchor wrapper to associate with this panel */ public DockedAnchorPanel(DockingAPI docking, DockableWrapper anchor) { setLayout(new BorderLayout()); anchor.setParent(this); this.docking = docking; this.anchor = anchor; add(anchor.getDisplayPanel(), BorderLayout.CENTER); } @Override public String getAnchor() { return null; } @Override public void setParent(DockingPanel parent) { this.parent = parent; } @Override public void dock(Dockable dockable, DockingRegion region, double dividerProportion) { // when docking to an anchor we replace the anchor with the new dockable always DockableWrapper wrapper = DockingInternal.get(docking).getWrapper(dockable); if (parent.getChildren().contains(this)) { DockingPanel newPanel; if (Settings.alwaysDisplayTabsMode()) { newPanel = new DockedTabbedPanel(docking, wrapper, anchor.getDockable().getPersistentID()); } else { newPanel = new DockedSimplePanel(docking, wrapper, anchor.getDockable().getPersistentID()); } parent.replaceChild(this, newPanel); } else { // find the largest dockable on screen that references this anchor DockingInternal.get(docking).dockToLargestAnchorPanel(dockable, anchor.getDockable().getPersistentID()); } } @Override public void undock(Dockable dockable) { parent.removeChild(this); } @Override public void replaceChild(DockingPanel child, DockingPanel newChild) { } @Override public void removeChild(DockingPanel child) { } public List<DockingPanel> getChildren() { return Collections.emptyList(); } /** * Get the wrapper for the anchor * * @return Dockable wrapper for this anchor */ public DockableWrapper getWrapper() { return anchor; } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-api/src/io/github/andrewauclair/moderndocking/internal/DockedSplitPanel.java
docking-api/src/io/github/andrewauclair/moderndocking/internal/DockedSplitPanel.java
/* Copyright (c) 2022-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 io.github.andrewauclair.moderndocking.internal; import io.github.andrewauclair.moderndocking.Dockable; import io.github.andrewauclair.moderndocking.DockingRegion; import io.github.andrewauclair.moderndocking.api.DockingAPI; import io.github.andrewauclair.moderndocking.settings.Settings; import java.awt.BorderLayout; import java.awt.Window; import java.awt.event.ComponentAdapter; import java.awt.event.ComponentEvent; import java.awt.event.HierarchyEvent; import java.awt.event.HierarchyListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.util.Arrays; import java.util.List; import javax.swing.JSplitPane; import javax.swing.plaf.basic.BasicSplitPaneDivider; import javax.swing.plaf.basic.BasicSplitPaneUI; /** * DockingPanel that has a split pane with 2 dockables, split can be vertical or horizontal */ public class DockedSplitPanel extends DockingPanel implements MouseListener, PropertyChangeListener { /** * Panel in the left/top part of the split */ private DockingPanel left = null; /** * Panel in the right/bottom part of the split */ private DockingPanel right = null; /** * The split pane we're controlling */ private final JSplitPane splitPane = new JSplitPane(); /** * The parent panel of this split panel */ private DockingPanel parent; /** * The docking instance this panel belongs to */ private final DockingAPI docking; /** * The window this panel is in */ private final Window window; /** * The anchor this panel belongs to, if any */ private String anchor = ""; /** * the last divider proportion that setDividerLocation was called with */ private double lastRequestedDividerProportion; /** * Create a new DockedSplitPanel * * @param docking The docking instance * @param window The window this panel is in. Used to tell the child DockableWrappers what Window they are a part of * @param anchor The anchor associated with this docking panel */ public DockedSplitPanel(DockingAPI docking, Window window, String anchor) { this.docking = docking; this.window = window; this.anchor = anchor; setLayout(new BorderLayout()); splitPane.setContinuousLayout(true); splitPane.setResizeWeight(0.5); splitPane.setBorder(null); splitPane.addPropertyChangeListener(JSplitPane.DIVIDER_LOCATION_PROPERTY, this); setDividerLocation(splitPane.getResizeWeight()); lastRequestedDividerProportion = splitPane.getResizeWeight(); if (splitPane.getUI() instanceof BasicSplitPaneUI) { ((BasicSplitPaneUI) splitPane.getUI()).getDivider().addMouseListener(this); } add(splitPane, BorderLayout.CENTER); } /** * Retrieve the last double that we used to set the divider proportion with. This helps us properly * restore divider locations when restoring from a layout. * * @return Requested divider proportion */ public double getLastRequestedDividerProportion() { return lastRequestedDividerProportion; } /** * Set the divider location of the splitpane. Tricks are needed to properly set the position. * The position cannot be set until the JSplitPane is displayed on screen. * * @param proportion The new proportion of the splitpane */ public void setDividerLocation(final double proportion) { lastRequestedDividerProportion = proportion; // calling setDividerLocation on a JSplitPane that isn't visible does nothing, so we need to check if it is showing first if (splitPane.isShowing()) { if (splitPane.getWidth() > 0 && splitPane.getHeight() > 0) { splitPane.setDividerLocation(proportion); } else { // split hasn't been completely calculated yet, wait until componentResize splitPane.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { // remove this listener, it's a one off splitPane.removeComponentListener(this); // call the function again, this time it should actually set the divider location setDividerLocation(proportion); } }); } } else { // split hasn't been shown yet, wait until it's showing splitPane.addHierarchyListener(new HierarchyListener() { @Override public void hierarchyChanged(HierarchyEvent e) { boolean isShowingChangeEvent = (e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0; if (isShowingChangeEvent && splitPane.isShowing()) { // remove this listener, it's a one off splitPane.removeHierarchyListener(this); // call the function again, this time it might set the size or wait for componentResize setDividerLocation(proportion); } } }); } } /** * Used to set the real divider location, which is set as an int, not a double. * * @param location The new proportion of the splitpane */ public void setDividerLocation(final int location) { if (splitPane.isShowing()) { if ((splitPane.getWidth() > 0) && (splitPane.getHeight() > 0)) { splitPane.setDividerLocation(location); docking.getAppState().persist(); } else { // split hasn't been completely calculated yet, wait until componentResize splitPane.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { // remove this listener, it's a one off splitPane.removeComponentListener(this); // call the function again, this time it should actually set the divider location setDividerLocation(location); } }); } } else { // split hasn't been shown yet, wait until it's showing splitPane.addHierarchyListener(new HierarchyListener() { @Override public void hierarchyChanged(HierarchyEvent e) { boolean isShowingChangeEvent = (e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0; if (isShowingChangeEvent && splitPane.isShowing()) { // remove this listener, it's a one off splitPane.removeHierarchyListener(this); // call the function again, this time it might set the size or wait for componentResize setDividerLocation(location); } } }); } } /** * Access to the underlying JSplitPane. This is required so that we can pull a bunch of values for saving layouts. * * @return The JSplitPane used by this DockedSplitPanel */ public JSplitPane getSplitPane() { return splitPane; } /** * Get the left/top component of the split * * @return Left/top component in the split */ public DockingPanel getLeft() { return left; } /** * Set the panel in the left/top of split * * @param panel New left/top panel */ public void setLeft(DockingPanel panel) { left = panel; left.setParent(this); // left.setAnchor(anchor); // remember where the divider was and put it back int dividerLocation = splitPane.getDividerLocation(); splitPane.setLeftComponent(panel); splitPane.setDividerLocation(dividerLocation); } /** * Get the right/bottom component of the split * * @return Right/bottom component in the split */ public DockingPanel getRight() { return right; } /** * Set the right panel of the split * * @param panel New right panel */ public void setRight(DockingPanel panel) { right = panel; right.setParent(this); // right.setAnchor(anchor); // remember where the divider was and put it back int dividerLocation = splitPane.getDividerLocation(); splitPane.setRightComponent(panel); splitPane.setDividerLocation(dividerLocation); } /** * Set the orientation of the split pane * * @param orientation New orientation of the split pane */ public void setOrientation(int orientation) { splitPane.setOrientation(orientation); if (splitPane.getUI() instanceof BasicSplitPaneUI) { // grab the divider from the UI and remove the border from it BasicSplitPaneDivider divider = ((BasicSplitPaneUI) splitPane.getUI()) .getDivider(); if (divider != null && divider.getBorder() != null) { divider.setBorder(null); } } } @Override public String getAnchor() { return anchor; } @Override public void setAnchor(String anchor) { this.anchor = anchor; } @Override public void setParent(DockingPanel parent) { this.parent = parent; } @Override public void dock(Dockable dockable, DockingRegion region, double dividerProportion) { DockableWrapper wrapper = DockingInternal.get(docking).getWrapper(dockable); // docking to the center of a split isn't something we allow // wouldn't be difficult to support, but isn't a complication we want in this framework if (region == DockingRegion.CENTER) { region = splitPane.getOrientation() == JSplitPane.HORIZONTAL_SPLIT ? DockingRegion.WEST : DockingRegion.NORTH; } wrapper.setWindow(window); DockedSplitPanel split = new DockedSplitPanel(docking, window, anchor); parent.replaceChild(this, split); DockingPanel newPanel; if (Settings.alwaysDisplayTabsMode()) { newPanel = new DockedTabbedPanel(docking, wrapper, anchor); } else { newPanel = new DockedSimplePanel(docking, wrapper, anchor); } 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); } @Override public void undock(Dockable dockable) { } @Override public void replaceChild(DockingPanel child, DockingPanel newChild) { if (left == child) { setLeft(newChild); } else if (right == child) { setRight(newChild); } } @Override public void removeChild(DockingPanel child) { // safety against partially configured layout restorations if (parent == null) { return; } if (left == child) { parent.replaceChild(this, right); } else if (right == child) { parent.replaceChild(this, left); } } public List<DockingPanel> getChildren() { return Arrays.asList(left, right); } @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() >= 2) { setDividerLocation(splitPane.getResizeWeight()); } } @Override public void mousePressed(MouseEvent e) { } @Override public void mouseReleased(MouseEvent e) { docking.getAppState().persist(); } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { } @Override public void propertyChange(PropertyChangeEvent evt) { docking.getAppState().persist(); } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-api/src/io/github/andrewauclair/moderndocking/internal/DockedTabbedPanel.java
docking-api/src/io/github/andrewauclair/moderndocking/internal/DockedTabbedPanel.java
/* Copyright (c) 2022-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 io.github.andrewauclair.moderndocking.internal; import io.github.andrewauclair.moderndocking.Dockable; import io.github.andrewauclair.moderndocking.DockableTabPreference; import io.github.andrewauclair.moderndocking.DockingRegion; import io.github.andrewauclair.moderndocking.api.DockingAPI; import io.github.andrewauclair.moderndocking.internal.floating.DockedTabbedPanelFloatListener; import io.github.andrewauclair.moderndocking.internal.floating.FloatListener; import io.github.andrewauclair.moderndocking.internal.floating.Floating; import io.github.andrewauclair.moderndocking.settings.Settings; import io.github.andrewauclair.moderndocking.ui.DockingSettings; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Point; import java.awt.Rectangle; import java.awt.dnd.DragGestureListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.function.IntConsumer; import javax.swing.BorderFactory; import javax.swing.Icon; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JSplitPane; import javax.swing.JTabbedPane; import javax.swing.SwingConstants; import javax.swing.SwingUtilities; import javax.swing.UIManager; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; /** * DockingPanel that has a JTabbedPane inside its center */ public class DockedTabbedPanel extends DockingPanel implements ChangeListener { /** * Wrapper objects of the contained dockables in this tabbed panel */ private final List<DockableWrapper> panels = new ArrayList<>(); /** * The listener using this tabbed panel */ private FloatListener floatListener; /** * All the drag listeners tied to this tabbed panel */ private List<DragGestureListener> listeners = new ArrayList<>(); /** * The JTabbedPane to display */ private final CustomTabbedPane tabs = new CustomTabbedPane(); /** * The docking instance this tabbed panel is tied to */ private final DockingAPI docking; /** * The anchor this tabbed panel belongs to */ private String anchor = ""; /** * The parent of this DockedTabbedPanel */ private DockingPanel parent; /** * The selected tab index. default to -1 and set properly when state changes */ private int selectedTab = -1; private static Icon settingsIcon = new ImageIcon(Objects.requireNonNull(DockedTabbedPanel.class.getResource("/api_icons/settings.png"))); /** * Create a new instance of DockedTabbedPanel * * @param docking The docking instance * @param dockable The first dockable in the tabbed pane * @param anchor The anchor associated with this docking panel */ public DockedTabbedPanel(DockingAPI docking, DockableWrapper dockable, String anchor) { this.docking = docking; this.anchor = anchor; 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"); if (Settings.alwaysDisplayTabsMode() && usingFlatLaf) { tabs.setTabPlacement(JTabbedPane.TOP); } else { tabs.setTabPlacement(JTabbedPane.BOTTOM); } tabs.setTabLayoutPolicy(Settings.getTabLayoutPolicy()); if (Settings.alwaysDisplayTabsMode()) { configureTrailingComponent(); } add(tabs, BorderLayout.CENTER); addPanel(dockable); } public static void setSettingsIcon(Icon icon) { settingsIcon = icon; } private void configureTrailingComponent() { JPanel panel = new JPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.anchor = GridBagConstraints.EAST; gbc.fill = GridBagConstraints.NONE; gbc.gridwidth = 1; gbc.gridheight = 1; gbc.weightx = 1.0; gbc.weighty = 0.0; JButton menu = new JButton(settingsIcon); setupButton(menu); menu.addActionListener(e -> { DockableWrapper dockable = panels.get(tabs.getSelectedIndex()); dockable.getHeaderUI().displaySettingsMenu(menu); }); panel.add(menu, gbc); tabs.putClientProperty("JTabbedPane.trailingComponent", panel); tabs.putClientProperty("JTabbedPane.tabCloseCallback", (IntConsumer) tabIndex -> { Dockable dockable = panels.get(tabIndex).getDockable(); if (dockable.requestClose()) { docking.undock(dockable); } }); } // sets the button up for being on a toolbar private void setupButton(JButton button) { Color color = DockingSettings.getHeaderBackground(); button.setBackground(color); button.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); button.setFocusable(false); button.setOpaque(false); button.setContentAreaFilled(false); button.addMouseListener(new MouseAdapter() { @Override public void mouseEntered(MouseEvent e) { button.setContentAreaFilled(true); button.setOpaque(true); } @Override public void mouseExited(MouseEvent e) { button.setContentAreaFilled(false); button.setOpaque(false); } }); } @Override public void addNotify() { super.addNotify(); tabs.addChangeListener(this); floatListener = new DockedTabbedPanelFloatListener(docking, this, tabs); } @Override public void removeNotify() { tabs.removeChangeListener(this); floatListener = null; super.removeNotify(); } /** * Add a new panel to this tabbed panel. * * @param dockable The dockable to add */ public void addPanel(DockableWrapper dockable) { panels.add(dockable); tabs.add(dockable.getDockable().getTabText(), dockable.getDisplayPanel()); DragGestureListener draggingFromTabPanel = dge -> { Point dragOrigin = new Point(dge.getDragOrigin()); SwingUtilities.convertPointToScreen(dragOrigin, dge.getComponent()); int targetTabIndex = tabs.getTargetTabIndex(dragOrigin, true); if (targetTabIndex != -1) { DockableWrapper dockableWrapper = panels.get(targetTabIndex); if (dockableWrapper == dockable) { dockableWrapper.getFloatListener().startDrag(dge); } } }; listeners.add(draggingFromTabPanel); dockable.getFloatListener().addAlternateDragSource(tabs, draggingFromTabPanel); DockableTabPreference tabPreference = Settings.defaultTabPreference(); // 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 (tabPreference == DockableTabPreference.TOP_ALWAYS && usingFlatLaf) { tabs.setTabPlacement(SwingConstants.TOP); } else if (tabPreference == DockableTabPreference.BOTTOM_ALWAYS) { tabs.setTabPlacement(SwingConstants.BOTTOM); } else if (tabPreference == DockableTabPreference.TOP && usingFlatLaf) { // in the normal top preference case, only switch if we add a dockable that prefers the top tab position if (dockable.getDockable().getTabPreference() == DockableTabPreference.TOP) { tabs.setTabPlacement(SwingConstants.TOP); } } // 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()) { dockable.getDisplayPanel().putClientProperty("JTabbedPane.tabClosable", true); } dockable.setParent(this); dockable.setAnchor(anchor); } /** * Remove a panel from this DockedTabbedPanel. This is done when the dockable is closed or docked elsewhere * * @param dockable The dockable to remove */ public void removePanel(DockableWrapper dockable) { if (panels.contains(dockable)) { int index = panels.indexOf(dockable); dockable.getFloatListener().removeAlternateDragSource(listeners.get(index)); listeners.remove(index); tabs.remove(dockable.getDisplayPanel()); panels.remove(dockable); dockable.setParent(null); } } /** * Get a list of the dockables in this tabbed panel * * @return List of persistent IDs of dockable tabs */ public List<DockableWrapper> getDockables() { return Collections.unmodifiableList(panels); } @Override public String getAnchor() { return anchor; } @Override public void setAnchor(String anchor) { this.anchor = anchor; } @Override public void setParent(DockingPanel parent) { this.parent = parent; } @Override public void dock(Dockable dockable, DockingRegion region, double dividerProportion) { DockableWrapper wrapper = DockingInternal.get(docking).getWrapper(dockable); wrapper.setWindow(panels.get(0).getWindow()); if (region == DockingRegion.CENTER) { addPanel(wrapper); } else { DockedSplitPanel split = new DockedSplitPanel(docking, panels.get(0).getWindow(), anchor); parent.replaceChild(this, split); DockingPanel newPanel; if (wrapper.isAnchor()) { newPanel = new DockedAnchorPanel(docking, wrapper); } else if (Settings.alwaysDisplayTabsMode()) { newPanel = new DockedTabbedPanel(docking, wrapper, anchor); } else { newPanel = new DockedSimplePanel(docking, wrapper, anchor); } 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); } revalidate(); repaint(); } /** * Dock a dockable at the specific index. Other dockables will be moved to the right one index * * @param dockable The dockable to dock * @param index The index to dock at */ public void dockAtIndex(Dockable dockable, int index) { DockableWrapper wrapper = DockingInternal.get(docking).getWrapper(dockable); wrapper.setWindow(panels.get(0).getWindow()); addPanel(DockingInternal.get(docking).getWrapper(dockable)); if (index != -1) { int lastIndex = tabs.getTabCount() - 1; for (int i = index; i < lastIndex; i++) { DockableWrapper panel = panels.get(index); removePanel(panel); addPanel(panel); } tabs.setSelectedIndex(index); } } @Override public void undock(Dockable dockable) { removePanel(DockingInternal.get(docking).getWrapper(dockable)); if (!Floating.isFloatingTabbedPane() && !Settings.alwaysDisplayTabsMode() && panels.size() == 1 && parent != null && panels.get(0).getDockable().getTabPreference() != DockableTabPreference.TOP) { parent.replaceChild(this, new DockedSimplePanel(docking, panels.get(0), anchor)); } // protect against bad instances when failing to restore a layout if (parent != null && panels.isEmpty()) { DockableWrapper anchorWrapper = DockingInternal.get(docking).getAnchor(anchor); anchor = ""; if (anchorWrapper == null || !DockingComponentUtils.isAnchorEmpty(docking, anchorWrapper.getDockable())) { parent.removeChild(this); } else { anchor = ""; parent.replaceChild(this, new DockedAnchorPanel(docking, anchorWrapper)); anchorWrapper.setWindow(DockingInternal.get(docking).getWrapper(dockable).getWindow()); } } } @Override public void replaceChild(DockingPanel child, DockingPanel newChild) { // no-op, docked tab can't have panel children, wrappers only } @Override public void removeChild(DockingPanel child) { // no-op, docked tab can't have panel children, wrappers only } public List<DockingPanel> getChildren() { return Collections.emptyList(); } private void setNotSelectedBorder() { Color color = UIManager.getColor("Component.borderColor"); setBorder( BorderFactory.createCompoundBorder( BorderFactory.createEmptyBorder(1, 1, 1, 1), BorderFactory.createLineBorder(color, 1) ) ); } /** * Set the specified dockable as the selected tab in the tab pane * * @param dockable Dockable to bring to front */ public void bringToFront(Dockable dockable) { for (int i = 0; i < panels.size(); i++) { DockableWrapper panel = panels.get(i); if (panel.getDockable() == dockable) { if (tabs.getSelectedIndex() != i) { if (tabs.getSelectedIndex() != -1) { DockingListeners.fireHiddenEvent(panels.get(tabs.getSelectedIndex()).getDockable()); } DockingListeners.fireShownEvent(panels.get(i).getDockable()); } tabs.setSelectedIndex(i); selectedTab = tabs.getSelectedIndex(); } } } /** * Get the persistent ID of the selected tab * * @return The persistent ID of the selected tab */ public String getSelectedTabID() { return panels.get(tabs.getSelectedIndex()).getDockable().getPersistentID(); } public int getSelectedTabIndex() { return tabs.getSelectedIndex(); } @Override public void stateChanged(ChangeEvent e) { docking.getAppState().persist(); if (tabs.getSelectedIndex() == -1) { return; } if (selectedTab != -1 && !Floating.isFloating()) { DockingListeners.fireHiddenEvent(panels.get(selectedTab).getDockable()); } selectedTab = tabs.getSelectedIndex(); if (selectedTab != -1) { DockingListeners.fireShownEvent(panels.get(selectedTab).getDockable()); } } /** * Check if this tabbed panel is using top tabs * * @return Are the tabs placed on the top? */ public boolean isUsingTopTabs() { return tabs.getTabPlacement() == JTabbedPane.TOP; } /** * Check if this tabbed panel is using bottom tabs * * @return Are the tabs placed on the bottom? */ public boolean isUsingBottomTabs() { return tabs.getTabPlacement() == JTabbedPane.BOTTOM; } /** * Get the tab component for a dockable * * @param wrapper The dockable to find * * @return The tab component or null */ public Component getTabForDockable(DockableWrapper wrapper) { for (int i = 0; i < panels.size(); i++) { DockableWrapper panel = panels.get(i); if (panel.getDockable() == wrapper.getDockable()) { return tabs.getTabComponentAt(i); } } return null; } public void updateTabInfo(Dockable dockable) { for (int i = 0; i < panels.size(); i++) { DockableWrapper panel = panels.get(i); if (panel.getDockable() == dockable) { tabs.setTitleAt(i, dockable.getTabText()); tabs.setToolTipTextAt(i, dockable.getTabTooltip()); Component tabComponent = tabs.getTabComponentAt(i); if (tabComponent instanceof JLabel) { ((JLabel) tabComponent).setText(dockable.getTabText()); ((JLabel) tabComponent).setToolTipText(dockable.getTabTooltip()); } } } } public int getTargetTabIndex(Point mousePosOnScreen) { return tabs.getTargetTabIndex(mousePosOnScreen, false); } /** * Get the index of a specific panel * * @param displayPanel The panel to look for * @return The index of the panel or -1 if not found */ public int getIndexOfPanel(DisplayPanel displayPanel) { for (int i = 0; i < panels.size(); i++) { if (panels.get(i).getDisplayPanel() == displayPanel) { return i; } } return -1; } /** * Check if a drag has started in the "gutter" of a tabbed panel * * @param point The point of the drag * * @return Are we dragging from the tabbed panel? */ public boolean isDraggingFromTabGutter(Point point) { Rectangle boundsAt = tabs.getBoundsAt(0); return boundsAt.y <= point.y && (boundsAt.y + boundsAt.height) >= point.y; } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-api/src/io/github/andrewauclair/moderndocking/internal/AppStatePersister.java
docking-api/src/io/github/andrewauclair/moderndocking/internal/AppStatePersister.java
/* Copyright (c) 2022 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 io.github.andrewauclair.moderndocking.internal; import io.github.andrewauclair.moderndocking.api.DockingAPI; import java.awt.Window; import java.awt.event.ComponentAdapter; import java.awt.event.ComponentEvent; import java.awt.event.WindowEvent; import java.awt.event.WindowStateListener; /** * simple internal class that calls AppState.persist() whenever a frame resizes, moves or changes state */ public class AppStatePersister extends ComponentAdapter implements WindowStateListener { private final DockingAPI docking; /** * Create a new persister for the docking instance * * @param docking Docking instance */ public AppStatePersister(DockingAPI docking) { this.docking = docking; } /** * Add a window to this persister. The persister will listen for any changes to the window and trigger the * auto persistence. * * @param window The window to add */ public void addWindow(Window window) { window.addComponentListener(this); window.addWindowStateListener(this); } /** * Remove a window from this persister. This will stop the persister from listening to events. * * @param window The window to remove */ public void removeWindow(Window window) { window.removeComponentListener(this); window.removeWindowStateListener(this); } @Override public void componentResized(ComponentEvent e) { docking.getAppState().persist(); } @Override public void componentMoved(ComponentEvent e) { docking.getAppState().persist(); } @Override public void windowStateChanged(WindowEvent e) { docking.getAppState().persist(); } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-api/src/io/github/andrewauclair/moderndocking/internal/DockingListeners.java
docking-api/src/io/github/andrewauclair/moderndocking/internal/DockingListeners.java
/* Copyright (c) 2022 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 io.github.andrewauclair.moderndocking.internal; import io.github.andrewauclair.moderndocking.Dockable; import io.github.andrewauclair.moderndocking.api.RootDockingPanelAPI; import io.github.andrewauclair.moderndocking.event.DockingEvent; import io.github.andrewauclair.moderndocking.event.DockingListener; import io.github.andrewauclair.moderndocking.event.MaximizeListener; import io.github.andrewauclair.moderndocking.event.NewFloatingFrameListener; import java.util.ArrayList; import java.util.List; import javax.swing.JFrame; /** * Manager class for docking and maximize listeners */ public class DockingListeners { private static final List<MaximizeListener> maximizeListeners = new ArrayList<>(); private static final List<DockingListener> dockingListeners = new ArrayList<>(); private static final List<NewFloatingFrameListener> newFloatingFrameListeners = new ArrayList<>(); /** * Unused. All methods are static */ private DockingListeners() { } /** * Add a new maximize listener. Will be called when a dockable is maximized * * @param listener Listener to add */ public static void addMaximizeListener(MaximizeListener listener) { if (!maximizeListeners.contains(listener)) { maximizeListeners.add(listener); } } /** * Remove a previously added maximize listener. No-op if the listener isn't in the list * * @param listener Listener to remove */ public static void removeMaximizeListener(MaximizeListener listener) { maximizeListeners.remove(listener); } /** * Fire a new maximize event * * @param dockable Dockable that has changed * @param maximized New maximized state */ public static void fireMaximizeEvent(Dockable dockable, boolean maximized) { List<MaximizeListener> listeners = new ArrayList<>(maximizeListeners); listeners.forEach(listener -> listener.maximized(dockable, maximized)); } /** * Add a new docking listener * * @param listener Listener to add */ public static void addDockingListener(DockingListener listener) { if (!dockingListeners.contains(listener)) { dockingListeners.add(listener); } } /** * Remove a docking listener * * @param listener Listener to remove */ public static void removeDockingListener(DockingListener listener) { dockingListeners.remove(listener); } /** * Add a new floating frame listener * * @param listener Listener to add */ public static void addNewFloatingFrameListener(NewFloatingFrameListener listener) { newFloatingFrameListeners.add(listener); } /** * Remove a floating frame listener * * @param listener Listener to remove */ public static void removeNewFloatingFrameListener(NewFloatingFrameListener listener) { newFloatingFrameListeners.remove(listener); } /** * Fire a new floating frame event * * @param frame The frame that was created * @param root The root of the frame */ public static void fireNewFloatingFrameEvent(JFrame frame, RootDockingPanelAPI root) { List<NewFloatingFrameListener> listeners = new ArrayList<>(newFloatingFrameListeners); listeners.forEach(listener -> listener.newFrameCreated(frame, root)); } /** * Fire a new floating frame event * * @param frame The frame that was created * @param root The root of the frame * @param dockable The dockable in the frame */ public static void fireNewFloatingFrameEvent(JFrame frame, RootDockingPanelAPI root, Dockable dockable) { List<NewFloatingFrameListener> listeners = new ArrayList<>(newFloatingFrameListeners); listeners.forEach(listener -> listener.newFrameCreated(frame, root, dockable)); } /** * Fire a new docked event * * @param dockable Dockable that was docked */ public static void fireDockedEvent(Dockable dockable) { List<DockingListener> listeners = new ArrayList<>(dockingListeners); listeners.forEach(listener -> listener.dockingChange(new DockingEvent(DockingEvent.ID.DOCKED, dockable, false))); } /** * Fire a new undocked event * * @param dockable Dockable that was undocked */ public static void fireUndockedEvent(Dockable dockable, boolean isTemporary) { List<DockingListener> listeners = new ArrayList<>(dockingListeners); listeners.forEach(listener -> listener.dockingChange(new DockingEvent(DockingEvent.ID.UNDOCKED, dockable, isTemporary))); } /** * Fire a new auto hide enabled event * * @param dockable Dockable that was auto hide enabled */ public static void fireAutoShownEvent(Dockable dockable) { List<DockingListener> listeners = new ArrayList<>(dockingListeners); listeners.forEach(listener -> listener.dockingChange(new DockingEvent(DockingEvent.ID.AUTO_HIDE_ENABLED, dockable, false))); } /** * Fire a new auto hide disabled event * * @param dockable Dockable that was auto hide disabled */ public static void fireAutoHiddenEvent(Dockable dockable) { List<DockingListener> listeners = new ArrayList<>(dockingListeners); listeners.forEach(listener -> listener.dockingChange(new DockingEvent(DockingEvent.ID.AUTO_HIDE_DISABLED, dockable, false))); } /** * Fire a new shown event * * @param dockable Dockable that was shown */ public static void fireShownEvent(Dockable dockable) { List<DockingListener> listeners = new ArrayList<>(dockingListeners); listeners.forEach(listener -> listener.dockingChange(new DockingEvent(DockingEvent.ID.SHOWN, dockable, false))); } /** * Fire a new hidden event * * @param dockable Dockable that was hidden */ public static void fireHiddenEvent(Dockable dockable) { List<DockingListener> listeners = new ArrayList<>(dockingListeners); listeners.forEach(listener -> listener.dockingChange(new DockingEvent(DockingEvent.ID.HIDDEN, dockable, false))); } /** * Fire a new docking event * * @param e Docking event to fire */ public static void fireDockingEvent(DockingEvent e) { List<DockingListener> listeners = new ArrayList<>(dockingListeners); listeners.forEach(listener -> listener.dockingChange(e)); } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-api/src/io/github/andrewauclair/moderndocking/internal/util/UnselectableButtonGroup.java
docking-api/src/io/github/andrewauclair/moderndocking/internal/util/UnselectableButtonGroup.java
package io.github.andrewauclair.moderndocking.internal.util; import java.util.Enumeration; import java.util.Vector; import javax.swing.AbstractButton; import javax.swing.ButtonGroup; import javax.swing.ButtonModel; /** * special form of ButtonGroup that allows the currently selected button to deselected * found from this answer: <a href="https://stackoverflow.com/a/51867860">stackoverflow</a> */ public class UnselectableButtonGroup extends ButtonGroup { /** * the list of buttons participating in this group */ protected final Vector<AbstractButton> buttons = new Vector<>(); /** * The current selection. */ ButtonModel selection = null; /** * Creates a new <code>ButtonGroup</code>. */ public UnselectableButtonGroup() { } /** * Adds the button to the group. * * @param b the button to be added */ public void add(AbstractButton b) { if (b == null) { return; } buttons.addElement(b); if (b.isSelected()) { if (selection == null) { selection = b.getModel(); } else { b.setSelected(false); } } b.getModel().setGroup(this); } /** * Removes the button from the group. * * @param b the button to be removed */ public void remove(AbstractButton b) { if (b == null) { return; } buttons.removeElement(b); if (b.getModel() == selection) { selection = null; } b.getModel().setGroup(null); } /** * Clears the selection such that none of the buttons in the * <code>ButtonGroup</code> are selected. * * @since 1.6 */ public void clearSelection() { if (selection != null) { ButtonModel oldSelection = selection; selection = null; oldSelection.setSelected(false); } } /** * Returns all the buttons that are participating in this group. * * @return an <code>Enumeration</code> of the buttons in this group */ public Enumeration<AbstractButton> getElements() { return buttons.elements(); } /** * Returns the model of the selected button. * * @return the selected button model */ public ButtonModel getSelection() { return selection; } /** * Sets the selected value for the <code>ButtonModel</code>. Only one * button in the group may be selected at a time. * * @param model the <code>ButtonModel</code> * @param selected <code>true</code> if this button is to be selected, * otherwise <code>false</code> */ public void setSelected(ButtonModel model, boolean selected) { if (selected) { if (model != selection) { ButtonModel oldSelection = selection; selection = model; if (oldSelection != null) { oldSelection.setSelected(false); } model.setSelected(true); } } else if (selection != null) { ButtonModel oldSelection = selection; selection = null; oldSelection.setSelected(false); } } /** * Returns whether a <code>ButtonModel</code> is selected. * * @return <code>true</code> if the button is selected, otherwise * returns <code>false</code> */ public boolean isSelected(ButtonModel model) { return model == selection; } /** * Returns the number of buttons in the group. * * @return the button count * @since 1.3 */ public int getButtonCount() { return buttons.size(); } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-api/src/io/github/andrewauclair/moderndocking/internal/util/RotatedIcon.java
docking-api/src/io/github/andrewauclair/moderndocking/internal/util/RotatedIcon.java
package io.github.andrewauclair.moderndocking.internal.util; import java.awt.Component; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.RenderingHints; import javax.swing.Icon; /** * The RotatedIcon allows you to change the orientation of an Icon by * rotating the Icon before it is painted. This class supports the following * orientations: * * <ul> * <li>DOWN - rotated 90 degrees * <li>UP (default) - rotated -90 degrees * <li>UPSIDE_DOWN - rotated 180 degrees * <li>ABOUT_CENTER - the icon is rotated by the specified degrees about its center. * </ul> */ public class RotatedIcon implements Icon { /** * Rotation state */ public enum Rotate { /** * Rotation down */ DOWN, /** * Rotation up */ UP, /** * Rotation upside down */ UPSIDE_DOWN, /** * Rotation center */ ABOUT_CENTER } private final Icon icon; private final Rotate rotate; private double degrees; private boolean circularIcon; /** * Convenience constructor to create a RotatedIcon that is rotated DOWN. * * @param icon the Icon to rotate */ public RotatedIcon(Icon icon) { this(icon, Rotate.UP); } /** * Create a RotatedIcon * * @param icon the Icon to rotate * @param rotate the direction of rotation */ public RotatedIcon(Icon icon, Rotate rotate) { this.icon = icon; this.rotate = rotate; } /** * Create a RotatedIcon. The icon will rotate about its center. This * constructor will automatically set Rotate enum to ABOUT_CENTER. * * @param icon the Icon to rotate * @param degrees the degrees of rotation */ public RotatedIcon(Icon icon, double degrees) { this(icon, degrees, false); } /** * Create a RotatedIcon. The icon will rotate about its center. This * constructor will automatically set Rotate enum to ABOUT_CENTER. * * @param icon the Icon to rotate * @param degrees the degrees of rotation * @param circularIcon treat the icon as circular so its size doesn't change */ public RotatedIcon(Icon icon, double degrees, boolean circularIcon) { this(icon, Rotate.ABOUT_CENTER); setDegrees( degrees ); setCircularIcon( circularIcon ); } /** * Gets the Icon to be rotated * * @return the Icon to be rotated */ public Icon getIcon() { return icon; } /** * Gets Rotate enum which indicates the direction of rotation * * @return Rotate enum */ public Rotate getRotate() { return rotate; } /** * Gets the degrees of rotation. Only used for Rotate.ABOUT_CENTER. * * @return the degrees of rotation */ public double getDegrees() { return degrees; } /** * Set the degrees of rotation. Only used for Rotate.ABOUT_CENTER. * This method only sets the degress of rotation, it will not cause * the Icon to be repainted. You must invoke repaint() on any * component using this icon for it to be repainted. * * @param degrees the degrees of rotation */ public void setDegrees(double degrees) { this.degrees = degrees; } /** * Is the image circular or rectangular? Only used for Rotate.ABOUT_CENTER. * When true, the icon width/height will not change as the Icon is rotated. * * @return true for a circular Icon, false otherwise */ public boolean isCircularIcon() { return circularIcon; } /** * Set the Icon as circular or rectangular. Only used for Rotate.ABOUT_CENTER. * When true, the icon width/height will not change as the Icon is rotated. * * @param circularIcon true for a circular Icon, false otherwise */ public void setCircularIcon(boolean circularIcon) { this.circularIcon = circularIcon; } // // Implement the Icon Interface // /** * Gets the width of this icon. * * @return the width of the icon in pixels. */ @Override public int getIconWidth() { if (rotate == Rotate.ABOUT_CENTER) { if (circularIcon) return icon.getIconWidth(); else { double radians = Math.toRadians( degrees ); double sin = Math.abs( Math.sin( radians ) ); double cos = Math.abs( Math.cos( radians ) ); return (int)Math.floor(icon.getIconWidth() * cos + icon.getIconHeight() * sin); } } else if (rotate == Rotate.UPSIDE_DOWN) return icon.getIconWidth(); else return icon.getIconHeight(); } /** * Gets the height of this icon. * * @return the height of the icon in pixels. */ @Override public int getIconHeight() { if (rotate == Rotate.ABOUT_CENTER) { if (circularIcon) return icon.getIconHeight(); else { double radians = Math.toRadians( degrees ); double sin = Math.abs( Math.sin( radians ) ); double cos = Math.abs( Math.cos( radians ) ); return (int)Math.floor(icon.getIconHeight() * cos + icon.getIconWidth() * sin); } } else if (rotate == Rotate.UPSIDE_DOWN) return icon.getIconHeight(); else return icon.getIconWidth(); } /** * Paint the icons of this compound icon at the specified location * * @param c The component on which the icon is painted * @param g the graphics context * @param x the X coordinate of the icon's top-left corner * @param y the Y coordinate of the icon's top-left corner */ @Override public void paintIcon(Component c, Graphics g, int x, int y) { Graphics2D g2 = (Graphics2D)g.create(); int cWidth = icon.getIconWidth() / 2; int cHeight = icon.getIconHeight() / 2; int xAdjustment = (icon.getIconWidth() % 2) == 0 ? 0 : -1; int yAdjustment = (icon.getIconHeight() % 2) == 0 ? 0 : -1; if (rotate == Rotate.DOWN) { g2.translate(x + cHeight, y + cWidth); g2.rotate( Math.toRadians( 90 ) ); icon.paintIcon(c, g2, -cWidth, yAdjustment - cHeight); } else if (rotate == Rotate.UP) { g2.translate(x + cHeight, y + cWidth); g2.rotate( Math.toRadians( -90 ) ); icon.paintIcon(c, g2, xAdjustment - cWidth, -cHeight); } else if (rotate == Rotate.UPSIDE_DOWN) { g2.translate(x + cWidth, y + cHeight); g2.rotate( Math.toRadians( 180 ) ); icon.paintIcon(c, g2, xAdjustment - cWidth, yAdjustment - cHeight); } else if (rotate == Rotate.ABOUT_CENTER) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setClip(x, y, getIconWidth(), getIconHeight()); g2.translate((getIconWidth() - icon.getIconWidth()) / 2, (getIconHeight() - icon.getIconHeight()) / 2); g2.rotate(Math.toRadians(degrees), x + cWidth, y + cHeight); icon.paintIcon(c, g2, x, y); } g2.dispose(); } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-api/src/io/github/andrewauclair/moderndocking/internal/util/CombinedIcon.java
docking-api/src/io/github/andrewauclair/moderndocking/internal/util/CombinedIcon.java
/* 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 io.github.andrewauclair.moderndocking.internal.util; import java.awt.Component; import java.awt.Graphics; import javax.swing.Icon; /** * Special Icon to combine multiple Icons. * <p> * We use this to combine an image icon and rotated text icon on West/East docking toolbars */ public class CombinedIcon implements Icon { /** * The amount of padding to add between the two icons */ private static final int PADDING = 2; private final Icon top; private final Icon bottom; /** * Create a new CombinedIcon * * @param top The icon to display on the top * @param bottom The icon to display on the bottom */ public CombinedIcon(Icon top, Icon bottom) { this.top = top; this.bottom = bottom; } @Override public int getIconHeight() { return top.getIconHeight() + PADDING + bottom.getIconHeight(); } @Override public int getIconWidth() { return Math.max(top.getIconWidth(), bottom.getIconWidth()); } @Override public void paintIcon(Component c, Graphics g, int x, int y) { top.paintIcon(c, g, x, y); bottom.paintIcon(c, g, x, y + PADDING + top.getIconHeight()); } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-api/src/io/github/andrewauclair/moderndocking/internal/util/TextIcon.java
docking-api/src/io/github/andrewauclair/moderndocking/internal/util/TextIcon.java
package io.github.andrewauclair.moderndocking.internal.util; import java.awt.Color; import java.awt.Component; import java.awt.Font; import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.Toolkit; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.util.Map; import javax.swing.Icon; import javax.swing.JComponent; /** * The TextIcon will paint a String of text as an Icon. The Icon * can be used by any Swing component that supports icons. * TextIcon supports two different layout styles: * <ul> * <li>Horizontally - does normal rendering of the text by using the * Graphics.drawString(...) method * <li>Vertically - Each character is displayed on a separate line * </ul> * * TextIcon was designed to be rendered on a specific JComponent as it * requires FontMetrics information in order to calculate its size and to do * the rendering. Therefore, it should only be added to component it was * created for. * By default, the text will be rendered using the Font and foreground color * of its associated component. However, this class does allow you to override * these properties. Also starting in JDK6 the desktop renderering hints will * be used to renderer the text. For versions not supporting the rendering * hints antialiasing will be turned on. */ public class TextIcon implements Icon, PropertyChangeListener { /** * Layout of text icon */ public enum Layout { /** * Text is horizontal in the icon */ HORIZONTAL, /** * Text is vertical in the icon */ VERTICAL } private final JComponent component; private final Layout layout; private String text; private Font font; private Color foreground; private int padding; // Used for the implementation of Icon interface private int iconWidth; private int iconHeight; // Used for Layout.VERTICAL to save reparsing the text every time the // icon is repainted private String[] strings; private int[] stringWidths; /** * Convenience constructor to create a TextIcon with a HORIZONTAL layout. * * @param component the component to which the icon will be added * @param text the text to be rendered on the Icon */ public TextIcon(JComponent component, String text) { this(component, text, Layout.HORIZONTAL); } /** * Create a TextIcon specifying all the properties. * * @param component the component to which the icon will be added * @param text the text to be rendered on the Icon * @param layout specify the layout of the text. Must be one of * the Layout enums: HORIZONTAL or VERTICAL */ public TextIcon(JComponent component, String text, Layout layout) { this.component = component; this.layout = layout; setText( text ); component.addPropertyChangeListener("font", this); } /** * Get the Layout enum * * @return the Layout enum */ public Layout getLayout() { return layout; } /** * Get the text String that will be rendered on the Icon * * @return the text of the Icon */ public String getText() { return text; } /** * Set the text to be rendered on the Icon * * @param text the text to be rendered on the Icon */ public void setText(String text) { this.text = text; calculateIconDimensions(); } /** * Get the Font used to render the text. This will default to the Font * of the component unless the Font has been overridden by using the * setFont() method. * * @return the Font used to render the text */ public Font getFont() { if (font == null) { return component.getFont(); } else { return font; } } /** * Set the Font to be used for rendering the text * * @param font the Font to be used for rendering the text */ public void setFont(Font font) { this.font = font; calculateIconDimensions(); } /** * Get the foreground Color used to render the text. This will default to * the foreground Color of the component unless the foreground Color has * been overridden by using the setForeground() method. * * @return the Color used to render the text */ public Color getForeground() { if (foreground == null) { return component.getForeground(); } else { return foreground; } } /** * Set the foreground Color to be used for rendering the text * * @param foreground the foreground Color to be used for rendering the text */ public void setForeground(Color foreground) { this.foreground = foreground; component.repaint(); } /** * Get the padding used when rendering the text * * @return the padding specified in pixels */ public int getPadding() { return padding; } /** * By default, the size of the Icon is based on the size of the rendered * text. You can specify some padding to be added to the start and end * of the text when it is rendered. * * @param padding the padding amount in pixels */ public void setPadding(int padding) { this.padding = padding; calculateIconDimensions(); } /** * Calculate the size of the Icon using the FontMetrics of the Font. */ private void calculateIconDimensions() { Font font = getFont(); FontMetrics fm = component.getFontMetrics( font ); if (layout == Layout.HORIZONTAL) { iconWidth = fm.stringWidth( text ) + (padding * 2); iconHeight = fm.getHeight(); } else if (layout == Layout.VERTICAL) { int maxWidth = 0; strings = new String[text.length()]; stringWidths = new int[text.length()]; // Find the widest character in the text string for (int i = 0; i < text.length(); i++) { strings[i] = text.substring(i, i + 1); stringWidths[i] = fm.stringWidth( strings[i] ); maxWidth = Math.max(maxWidth, stringWidths[i]); } // Add a minimum of 2 extra pixels, plus the leading value, // on each side of the character. iconWidth = maxWidth + ((fm.getLeading() + 2) * 2); // Decrease then normal gap betweens lines of text by taking into // account the descent. iconHeight = (fm.getHeight() - fm.getDescent()) * text.length(); iconHeight += padding * 2; } component.revalidate(); } // // Implement the Icon Interface // /** * Gets the width of this icon. * * @return the width of the icon in pixels. */ @Override public int getIconWidth() { return iconWidth; } /** * Gets the height of this icon. * * @return the height of the icon in pixels. */ @Override public int getIconHeight() { return iconHeight; } /** * Paint the icons of this compound icon at the specified location * * @param c The component to which the icon is added * @param g the graphics context * @param x the X coordinate of the icon's top-left corner * @param y the Y coordinate of the icon's top-left corner */ @Override public void paintIcon(Component c, Graphics g, int x, int y) { Graphics2D g2 = (Graphics2D)g.create(); // The "desktophints" is supported in JDK6 Toolkit toolkit = Toolkit.getDefaultToolkit(); Map map = (Map)(toolkit.getDesktopProperty("awt.font.desktophints")); if (map != null) { g2.addRenderingHints(map); } else { g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); } g2.setFont( getFont() ); g2.setColor( getForeground() ); FontMetrics fm = g2.getFontMetrics(); if (layout == Layout.HORIZONTAL) { g2.translate(x, y + fm.getAscent()); g2.drawString(text, padding, 0); } else if (layout == Layout.VERTICAL) { int offsetY = fm.getAscent() - fm.getDescent() + padding; int incrementY = fm.getHeight() - fm.getDescent(); for (int i = 0; i < text.length(); i++) { int offsetX = Math.round((getIconWidth() - stringWidths[i]) / 2.0f); g2.drawString(strings[i], x + offsetX, y + offsetY); offsetY += incrementY; } } g2.dispose(); } // // Implement the PropertyChangeListener interface // public void propertyChange(PropertyChangeEvent e) { // Handle font change when using the default font if (font == null) { calculateIconDimensions(); } } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-api/src/io/github/andrewauclair/moderndocking/internal/util/SlideBorder.java
docking-api/src/io/github/andrewauclair/moderndocking/internal/util/SlideBorder.java
/* Copyright (c) 2022 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 io.github.andrewauclair.moderndocking.internal.util; import io.github.andrewauclair.moderndocking.ui.ToolbarLocation; import java.awt.Cursor; import java.awt.Dimension; import javax.swing.JPanel; /** * Panel that provides a slider for unpinned dockables when they are displayed */ public class SlideBorder extends JPanel { /** * The location of the toolbar that this slide border is for. Used to determine the correct orientation of the panel */ private final ToolbarLocation location; /** * Create a SlideBorder with the given toolbar location * * @param location Location of the toolbar */ public SlideBorder(ToolbarLocation location) { this.location = location; setCursor(location == ToolbarLocation.SOUTH ? Cursor.getPredefinedCursor(Cursor.N_RESIZE_CURSOR) : Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR)); } @Override public Dimension getMinimumSize() { Dimension size = super.getMinimumSize(); if (location == ToolbarLocation.SOUTH) { size.height = 6; } else { size.width = 6; } return size; } @Override public Dimension getPreferredSize() { Dimension size = super.getPreferredSize(); if (location == ToolbarLocation.SOUTH) { size.height = 6; } else { size.width = 6; } return size; } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-api/src/io/github/andrewauclair/moderndocking/internal/floating/FloatingOverlay.java
docking-api/src/io/github/andrewauclair/moderndocking/internal/floating/FloatingOverlay.java
/* Copyright (c) 2024 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 io.github.andrewauclair.moderndocking.internal.floating; import io.github.andrewauclair.moderndocking.Dockable; import io.github.andrewauclair.moderndocking.DockableStyle; import io.github.andrewauclair.moderndocking.DockingRegion; import io.github.andrewauclair.moderndocking.api.DockingAPI; import io.github.andrewauclair.moderndocking.internal.CustomTabbedPane; import io.github.andrewauclair.moderndocking.internal.DockingInternal; import io.github.andrewauclair.moderndocking.internal.InternalRootDockingPanel; import io.github.andrewauclair.moderndocking.ui.DockingSettings; import java.awt.Component; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Point; import java.awt.Rectangle; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.SwingUtilities; /** * Utility for displaying the overlay highlight over the target frame while floating a dockable */ public class FloatingOverlay { // determines how close to the edge the user has to drag the panel before they see an overlay other than CENTER private static final double REGION_SENSITIVITY = 0.35; /** * Is this overlay visible? */ private boolean visible = false; /** * the top left location where the overlay starts */ private Point location = new Point(0, 0); /** * the total size of the overlay, used for drawing */ private Dimension size = new Dimension(0, 0); private Rectangle targetTab = null; private final DockingAPI docking; private final JFrame utilFrame; private Point prevLocation = location; private Dimension prevSize = size; /** * Create a new overlay, attached to a utility frame * * @param docking The docking instance this overlay belongs to * @param utilFrame The utility frame this overlay is tied to */ public FloatingOverlay(DockingAPI docking, JFrame utilFrame) { this.docking = docking; this.utilFrame = utilFrame; } /** * Check if the overlay needs to be redrawn * * @return True if the overlay requires a redraw */ public boolean requiresRedraw() { return !location.equals(prevLocation) || !size.equals(prevSize); } /** * Overlay has been redrawn. Clear the flag */ public void clearRedraw() { prevLocation = location; prevSize = size; } /** * Update the overlay for a new region in the root panel * * @param rootPanel The root panel that we're showing root handles in * @param region The region of the handle the mouse is over */ public void updateForRoot(InternalRootDockingPanel rootPanel, DockingRegion region) { setVisible(true); targetTab = null; Point point = rootPanel.getLocation(); Dimension size = rootPanel.getSize(); point = SwingUtilities.convertPoint(rootPanel.getParent(), point, utilFrame); final double DROP_SIZE = 4; prevLocation = new Point(this.location); prevSize = new Dimension(this.size); switch (region) { case WEST: { size = new Dimension((int) (size.width / DROP_SIZE), size.height); break; } case NORTH: { size = new Dimension(size.width, (int) (size.height / DROP_SIZE)); break; } case EAST: { point.x += size.width - (size.width / DROP_SIZE); size = new Dimension((int) (size.width / DROP_SIZE), size.height); break; } case SOUTH: { point.y += size.height - (size.height / DROP_SIZE); size = new Dimension(size.width, (int) (size.height / DROP_SIZE)); break; } } this.location = point; this.size = size; } /** * Update the overlay for a new target dockable * * @param targetDockable The new target dockable * @param floatingDockable The dockable being floated * @param mousePosOnScreen The position of the mouse on screen * @param region The region of the dockable the overlay is over */ public void updateForDockable(Dockable targetDockable, Dockable floatingDockable, Point mousePosOnScreen, DockingRegion region) { setVisible(true); prevLocation = new Point(this.location); prevSize = new Dimension(this.size); targetTab = null; if (region == null) { region = getRegion(targetDockable, floatingDockable, mousePosOnScreen); } JComponent component = DockingInternal.get(docking).getWrapper(targetDockable).getDisplayPanel(); Point point = component.getLocation(); Dimension size = component.getSize(); point = SwingUtilities.convertPoint(component.getParent(), point, utilFrame); final double DROP_SIZE = 2; switch (region) { case WEST: { size.width /= (int) DROP_SIZE; break; } case NORTH: { size = new Dimension(size.width, (int) (size.height / DROP_SIZE)); break; } case EAST: { point.x += size.width / DROP_SIZE; size = new Dimension((int) (size.width / DROP_SIZE), size.height); break; } case SOUTH: { point.y += size.height / DROP_SIZE; size = new Dimension(size.width, (int) (size.height / DROP_SIZE)); break; } } this.location = point; this.size = size; } /** * Update the overlay for dispay over a tab * * @param tabbedPane The tabbed pane the mouse is over * @param mousePosOnScreen The mouse position on screen */ public void updateForTab(CustomTabbedPane tabbedPane, Point mousePosOnScreen) { setVisible(true); prevLocation = new Point(this.location); prevSize = new Dimension(this.size); Component componentAt = tabbedPane.getComponentAt(0); location = componentAt.getLocation(); SwingUtilities.convertPointToScreen(location, tabbedPane); SwingUtilities.convertPointFromScreen(location, utilFrame); size = componentAt.getSize(); int targetTabIndex = tabbedPane.getTargetTabIndex(mousePosOnScreen, true); if (targetTabIndex != -1) { targetTab = tabbedPane.getBoundsAt(targetTabIndex); Point p = new Point(targetTab.x, targetTab.y); SwingUtilities.convertPointToScreen(p, tabbedPane); SwingUtilities.convertPointFromScreen(p, utilFrame); targetTab.x = p.x; targetTab.y = p.y; targetTab.width /= 2; } else { targetTab = tabbedPane.getBoundsAt(tabbedPane.getTabCount() - 1); Point tabPoint = new Point(tabbedPane.getX(), tabbedPane.getY()); SwingUtilities.convertPointToScreen(tabPoint, tabbedPane.getParent()); Point boundsPoint = new Point(targetTab.x, targetTab.y); SwingUtilities.convertPointToScreen(boundsPoint, tabbedPane); int widthToAdd = targetTab.width; if (boundsPoint.x + (targetTab.width * 2) >= tabPoint.x + tabbedPane.getWidth()) { targetTab.width = Math.abs((tabPoint.x + tabbedPane.getWidth()) - (boundsPoint.x + targetTab.width)); } SwingUtilities.convertPointFromScreen(boundsPoint, utilFrame); targetTab.x = boundsPoint.x + widthToAdd; targetTab.y = boundsPoint.y; } } /** * Set the visibility of the overlay * * @param visible New visibility */ public void setVisible(boolean visible) { this.visible = visible; } /** * Check which region the overlay is over * * @param targetDockable The target dockable * @param floatingDockable The dockable that is being floated * @param mousePosOnScreen The mouse position on screen * * @return The region the overlay is over, or null */ public DockingRegion getRegion(Dockable targetDockable, Dockable floatingDockable, Point mousePosOnScreen) { JComponent component = DockingInternal.get(docking).getWrapper(targetDockable).getDisplayPanel(); Point framePoint = new Point(mousePosOnScreen); SwingUtilities.convertPointFromScreen(framePoint, utilFrame); Point point = (component).getLocation(); Dimension size = component.getSize(); point = SwingUtilities.convertPoint(component.getParent(), point, utilFrame); double horizontalPct = (framePoint.x - point.x) / (double) size.width; double verticalPct = (framePoint.y - point.y) / (double) size.height; double horizontalEdgeDist = horizontalPct > 0.5 ? 1.0 - horizontalPct : horizontalPct; double verticalEdgeDist = verticalPct > 0.5 ? 1.0 - verticalPct : verticalPct; if (horizontalEdgeDist < verticalEdgeDist) { if (horizontalPct < REGION_SENSITIVITY && isRegionAllowed(targetDockable, DockingRegion.WEST) && isRegionAllowed(floatingDockable, DockingRegion.WEST)) { return DockingRegion.WEST; } else if (horizontalPct > (1.0 - REGION_SENSITIVITY) && isRegionAllowed(targetDockable, DockingRegion.EAST) && isRegionAllowed(floatingDockable, DockingRegion.EAST)) { return DockingRegion.EAST; } } else { if (verticalPct < REGION_SENSITIVITY && isRegionAllowed(targetDockable, DockingRegion.NORTH) && isRegionAllowed(floatingDockable, DockingRegion.NORTH)) { return DockingRegion.NORTH; } else if (verticalPct > (1.0 - REGION_SENSITIVITY) && isRegionAllowed(targetDockable, DockingRegion.SOUTH) && isRegionAllowed(floatingDockable, DockingRegion.SOUTH)) { return DockingRegion.SOUTH; } } return DockingRegion.CENTER; } /** * Is the mouse currently over a tab? Renders a different overlay * @return Over tab */ public boolean isOverTab() { return targetTab != null; } /** * Paint the overlay * * @param g Graphics instance */ public void paint(Graphics g) { if (!visible) { return; } g.setColor(DockingSettings.getOverlayBackground()); g.fillRect(location.x, location.y, size.width, size.height); if (targetTab != null) { g.fillRect(targetTab.x, targetTab.y, targetTab.width, targetTab.height); } } // check if the floating dockable is allowed to dock to this region private boolean isRegionAllowed(Dockable dockable, DockingRegion region) { if (dockable == null) { return true; } if (dockable.getStyle() == DockableStyle.BOTH) { return true; } if (region == DockingRegion.NORTH || region == DockingRegion.SOUTH) { return dockable.getStyle() == DockableStyle.HORIZONTAL; } return dockable.getStyle() == DockableStyle.VERTICAL; } /** * Check if this overlay is visible * * @return Is visible */ public boolean isVisible() { return visible; } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-api/src/io/github/andrewauclair/moderndocking/internal/floating/TempFloatingFrame.java
docking-api/src/io/github/andrewauclair/moderndocking/internal/floating/TempFloatingFrame.java
/* Copyright (c) 2022 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 io.github.andrewauclair.moderndocking.internal.floating; import io.github.andrewauclair.moderndocking.internal.DockableWrapper; import io.github.andrewauclair.moderndocking.settings.Settings; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Cursor; import java.awt.Dimension; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import java.awt.Point; import java.util.Collections; import java.util.List; import javax.swing.BorderFactory; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTabbedPane; import javax.swing.SwingUtilities; import javax.swing.UIManager; /** * this is a frame used temporarily when floating a panel */ public class TempFloatingFrame extends JFrame { private static final int BORDER_SIZE = 2; /** * The dockables that we are currently floating */ private final List<DockableWrapper> dockables; /** * The selected index in the group of dockables */ private final int selectedIndex; /** * Create a new temporary floating frame for a floating dockable * * @param dockable The dockable that we are currently floating * @param dragSrc The source of the drag. Used to assign the frame to the proper screen location * @param size The desired size of the frame */ public TempFloatingFrame(DockableWrapper dockable, JComponent dragSrc, Dimension size) { setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setTitle("Temp Floating Frame"); dockables = Collections.emptyList(); selectedIndex = 0; build(dockable.getDisplayPanel(), dragSrc, size); } /** * Create a new temporary floating frame for a floating dockable * * @param dockables The dockables that we are currently floating * @param selectedIndex The selected index in the group of dockables * @param dragSrc The source of the drag. Used to assign the frame to the proper screen location * @param size The desired size of the frame */ public TempFloatingFrame(List<DockableWrapper> dockables, int selectedIndex, JComponent dragSrc, Dimension size) { setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setTitle("Temp Floating Frame"); this.dockables = dockables; this.selectedIndex = selectedIndex; JTabbedPane tabs = new JTabbedPane(); // 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); } for (DockableWrapper dockable : dockables) { tabs.add(dockable.getDockable().getTabText(), dockable.getDisplayPanel()); } tabs.setSelectedIndex(selectedIndex); build(tabs, dragSrc, size); } /** * Create a new temporary floating frame to contain a dockable that has started to float * * @param dockable Dockable in the floating frame * @param dragSrc The source of the drag */ private void build(JComponent dockable, JComponent dragSrc, Dimension size) { setLayout(new BorderLayout()); // keep it simple, just use border layout setUndecorated(true); // hide the frame setType(Type.UTILITY); // keeps the frame from appearing in the task bar frames setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); // this frame is only showing while moving // size the frame to the dockable size setSize(size); // set the frame position to match the current dockable position Point newPoint = new Point(dragSrc.getLocation()); // when dragging from a tab there is no parent for the drag source if (dragSrc.getParent() != null) { SwingUtilities.convertPointToScreen(newPoint, dragSrc.getParent()); } setLocation(newPoint); // put the dockable in a panel with a border around it to make it look better JPanel panel = new JPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.insets = new Insets(0, 0, 0, 0); gbc.gridy = 0; gbc.gridx = 0; gbc.weightx = 1.0; gbc.weighty = 1.0; gbc.fill = GridBagConstraints.BOTH; // set a border around the panel in the component focus color. this lets us distinguish the dockable panel from other windows. Color color = UIManager.getColor("Component.focusColor"); panel.setBorder(BorderFactory.createLineBorder(color, BORDER_SIZE)); panel.add(dockable, gbc); add(panel, BorderLayout.CENTER); setVisible(true); } /** * The dockables that are in this temporary floating frame * * @return List of dockables */ public List<DockableWrapper> getDockables() { return dockables; } /** * The selected dockable index * * @return Selected index */ public int getSelectedIndex() { return selectedIndex; } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-api/src/io/github/andrewauclair/moderndocking/internal/floating/DockableHandles.java
docking-api/src/io/github/andrewauclair/moderndocking/internal/floating/DockableHandles.java
/* Copyright (c) 2024 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 io.github.andrewauclair.moderndocking.internal.floating; import io.github.andrewauclair.moderndocking.Dockable; import io.github.andrewauclair.moderndocking.DockableStyle; import io.github.andrewauclair.moderndocking.DockingRegion; import io.github.andrewauclair.moderndocking.ui.DockingSettings; import java.awt.Color; import java.awt.Component; import java.awt.Dimension; import java.awt.Graphics2D; import java.awt.Point; import java.awt.Polygon; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JScrollPane; import javax.swing.SwingUtilities; import static io.github.andrewauclair.moderndocking.internal.floating.DockingHandle.HANDLE_ICON_SIZE; /** * Class for handling all of the docking handle operations while floating a dockable */ public class DockableHandles { private final DockingHandle dockableCenter = new DockingHandle(DockingRegion.CENTER, false); private final DockingHandle dockableWest = new DockingHandle(DockingRegion.WEST, false); private final DockingHandle dockableNorth = new DockingHandle(DockingRegion.NORTH, false); private final DockingHandle dockableEast = new DockingHandle(DockingRegion.EAST, false); private final DockingHandle dockableSouth = new DockingHandle(DockingRegion.SOUTH, false); private final JFrame frame; private final Dockable targetDockable; private final Dockable floatingDockable; /** * Create a new instance for the frame and target dockable * * @param frame The frame to display these handles on * @param targetDockable The target dockable the mouse is over */ public DockableHandles(JFrame frame, Dockable targetDockable) { this.frame = frame; this.targetDockable = targetDockable; this.floatingDockable = null; setupHandle(frame, dockableCenter); setupHandle(frame, dockableWest); setupHandle(frame, dockableNorth); setupHandle(frame, dockableEast); setupHandle(frame, dockableSouth); setDockableHandleLocations(); } /** * Create a new instance for the frame and target dockable * * @param frame The frame to display these handles on * @param targetDockable The target dockable the mouse is over * @param floatingDockable The dockable is floating */ public DockableHandles(JFrame frame, Dockable targetDockable, Dockable floatingDockable) { this.frame = frame; this.targetDockable = targetDockable; this.floatingDockable = floatingDockable; setupHandle(frame, dockableCenter); setupHandle(frame, dockableWest); setupHandle(frame, dockableNorth); setupHandle(frame, dockableEast); setupHandle(frame, dockableSouth); setDockableHandleLocations(); } /** * The mouse has moved. Update all the handles for mouse over events * * @param mousePosOnScreen The new mouse position on screen */ public void mouseMoved(Point mousePosOnScreen) { Point framePoint = new Point(mousePosOnScreen); SwingUtilities.convertPointFromScreen(framePoint, frame); dockableCenter.mouseMoved(framePoint); dockableWest.mouseMoved(framePoint); dockableNorth.mouseMoved(framePoint); dockableEast.mouseMoved(framePoint); dockableSouth.mouseMoved(framePoint); } private void setupHandle(JFrame frame, DockingHandle label) { label.setVisible(false); frame.add(label); } private void setDockableHandleLocations() { dockableCenter.setVisible(true); dockableWest.setVisible(isRegionAllowed(targetDockable, DockingRegion.WEST)); dockableNorth.setVisible(isRegionAllowed(targetDockable, DockingRegion.NORTH)); dockableEast.setVisible(isRegionAllowed(targetDockable, DockingRegion.EAST)); dockableSouth.setVisible(isRegionAllowed(targetDockable, DockingRegion.SOUTH)); if (floatingDockable != null) { if (!isRegionAllowed(floatingDockable, DockingRegion.WEST)) { dockableWest.setVisible(false); } if (!isRegionAllowed(floatingDockable, DockingRegion.NORTH)) { dockableNorth.setVisible(false); } if (!isRegionAllowed(floatingDockable, DockingRegion.EAST)) { dockableEast.setVisible(false); } if (!isRegionAllowed(floatingDockable, DockingRegion.SOUTH)) { dockableSouth.setVisible(false); } } if (((Component) targetDockable).getParent() != null) { Point location = ((Component) targetDockable).getLocation(); Dimension size = ((Component) targetDockable).getSize(); // if this dockable is wrapped in a JScrollPane we need to set the handle to the center of the JScrollPane // not to the center of the dockable (which will more than likely be at a different location) if (targetDockable.isWrappableInScrollpane()) { Component parent = ((Component) targetDockable).getParent(); while (parent != null && !(parent instanceof JScrollPane)) { parent = parent.getParent(); } if (parent != null) { JScrollPane display = (JScrollPane) parent; location = display.getLocation(); size = display.getSize(); } } location.x += size.width / 2; location.y += size.height / 2; location.y -= (int) (HANDLE_ICON_SIZE * (1.75/2)); SwingUtilities.convertPointToScreen(location, ((Component) targetDockable).getParent()); SwingUtilities.convertPointFromScreen(location, frame); setLocation(dockableCenter, location.x, location.y); setLocation(dockableWest, location.x - handleSpacing(dockableWest), location.y); setLocation(dockableNorth, location.x, location.y - handleSpacing(dockableNorth)); setLocation(dockableEast, location.x + handleSpacing(dockableEast), location.y); setLocation(dockableSouth, location.x, location.y + handleSpacing(dockableSouth)); } } private void setLocation(Component component, int x, int y) { component.setLocation(x - (HANDLE_ICON_SIZE / 2), y - (HANDLE_ICON_SIZE / 2)); } private boolean isRegionAllowed(Dockable dockable, DockingRegion region) { if (dockable.getStyle() == DockableStyle.BOTH) { return true; } if (region == DockingRegion.NORTH || region == DockingRegion.SOUTH) { return dockable.getStyle() == DockableStyle.HORIZONTAL; } return dockable.getStyle() == DockableStyle.VERTICAL; } /** * Paint the handles * * @param g2 The graphics instance */ public void paint(Graphics2D g2) { int centerX = dockableCenter.getX() + (dockableCenter.getWidth() / 2); int centerY = dockableCenter.getY() + (dockableCenter.getWidth() / 2); int spacing = handleSpacing(dockableCenter) - dockableCenter.getWidth(); int half_icon = dockableCenter.getWidth() / 2; int one_and_a_half_icons = (int) (dockableCenter.getWidth() * 1.5); // create a polygon of the docking handles background Polygon poly = new Polygon( new int[] { centerX - half_icon - spacing, centerX + half_icon + spacing, centerX + half_icon + spacing, centerX + half_icon + (spacing * 2), centerX + one_and_a_half_icons + (spacing * 2), centerX + one_and_a_half_icons + (spacing * 2), centerX + half_icon + (spacing * 2), centerX + half_icon + spacing, centerX + half_icon + spacing, centerX - half_icon - spacing, centerX - half_icon - spacing, centerX - half_icon - (spacing * 2), centerX - one_and_a_half_icons - (spacing * 2), centerX - one_and_a_half_icons - (spacing * 2), centerX - half_icon - (spacing * 2), centerX - half_icon - spacing, centerX - half_icon - spacing }, new int[] { centerY - one_and_a_half_icons - (spacing * 2), centerY - one_and_a_half_icons - (spacing * 2), centerY - half_icon - (spacing * 2), centerY - half_icon - spacing, centerY - half_icon - spacing, centerY + half_icon + spacing, centerY + half_icon + spacing, centerY + half_icon + (spacing * 2), centerY + one_and_a_half_icons + (spacing * 2), centerY + one_and_a_half_icons + (spacing * 2), centerY + half_icon + (spacing * 2), centerY + half_icon + spacing, centerY + half_icon + spacing, centerY - half_icon - spacing, centerY - half_icon - spacing, centerY - half_icon - (spacing * 2), centerY - one_and_a_half_icons - (spacing * 2), }, 17 ); Color background = DockingSettings.getHandleBackground();//DockingProperties.getHandlesBackground(); Color border = DockingSettings.getHandleForeground();//DockingProperties.getHandlesBackgroundBorder(); // draw the dockable handles background over the root handles in case they overlap // fill the dockable handles background g2.setColor(background); g2.fillPolygon(poly.xpoints, poly.ypoints, poly.npoints); // draw the dockable handles border g2.setColor(border); g2.drawPolygon(poly.xpoints, poly.ypoints, poly.npoints); // draw the docking handles over the docking handles background dockableCenter.paintHandle(g2); dockableEast.paintHandle(g2); dockableWest.paintHandle(g2); dockableNorth.paintHandle(g2); dockableSouth.paintHandle(g2); } private int handleSpacing(JLabel handle) { return handle.getWidth() + 8; } /** * Find the region of the docking handle the mouse is over * * @return Region the mouse is over or null */ public DockingRegion getRegion() { if (dockableCenter.isMouseOver()) { return DockingRegion.CENTER; } if (dockableEast.isMouseOver()) { return DockingRegion.EAST; } if (dockableWest.isMouseOver()) { return DockingRegion.WEST; } if (dockableNorth.isMouseOver()) { return DockingRegion.NORTH; } if (dockableSouth.isMouseOver()) { return DockingRegion.SOUTH; } return null; } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-api/src/io/github/andrewauclair/moderndocking/internal/floating/RootDockingHandles.java
docking-api/src/io/github/andrewauclair/moderndocking/internal/floating/RootDockingHandles.java
/* Copyright (c) 2024 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 io.github.andrewauclair.moderndocking.internal.floating; import io.github.andrewauclair.moderndocking.Dockable; import io.github.andrewauclair.moderndocking.DockableStyle; import io.github.andrewauclair.moderndocking.DockingRegion; import io.github.andrewauclair.moderndocking.api.RootDockingPanelAPI; import io.github.andrewauclair.moderndocking.internal.InternalRootDockingPanel; import io.github.andrewauclair.moderndocking.ui.ToolbarLocation; import java.awt.Component; import java.awt.Dimension; import java.awt.Graphics2D; import java.awt.Point; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.SwingUtilities; import static io.github.andrewauclair.moderndocking.internal.floating.DockingHandle.HANDLE_ICON_SIZE; /** * Collection of the handles for the root of a window */ public class RootDockingHandles { private final DockingHandle rootCenter = new DockingHandle(DockingRegion.CENTER, true); private final DockingHandle rootWest = new DockingHandle(DockingRegion.WEST, true); private final DockingHandle rootNorth = new DockingHandle(DockingRegion.NORTH, true); private final DockingHandle rootEast = new DockingHandle(DockingRegion.EAST, true); private final DockingHandle rootSouth = new DockingHandle(DockingRegion.SOUTH, true); private final DockingHandle pinWest = new DockingHandle(DockingRegion.WEST); private final DockingHandle pinEast = new DockingHandle(DockingRegion.EAST); private final DockingHandle pinSouth = new DockingHandle(DockingRegion.SOUTH); private final JFrame frame; private final InternalRootDockingPanel rootPanel; private DockingRegion mouseOverRegion = null; private DockingRegion mouseOverPin = null; /** * Create a new instance of the root docking handles * * @param frame The frame this root docking handle belongs to * @param rootPanel The root panel for the frame */ public RootDockingHandles(JFrame frame, InternalRootDockingPanel rootPanel) { this.frame = frame; this.rootPanel = rootPanel; setupHandle(frame, rootCenter); setupHandle(frame, rootWest); setupHandle(frame, rootNorth); setupHandle(frame, rootEast); setupHandle(frame, rootSouth); setupHandle(frame, pinWest); setupHandle(frame, pinEast); setupHandle(frame, pinSouth); } /** * Update the handle positions within the frame */ public void updateHandlePositions() { setRootHandleLocations(); } /** * Change the dockable that is being floated * * @param dockable New floating dockable or null */ public void setFloatingDockable(Dockable dockable) { if (dockable == null) { pinWest.setVisible(false); pinEast.setVisible(false); pinSouth.setVisible(false); return; } rootCenter.setVisible(rootPanel.isEmpty()); RootDockingPanelAPI root = rootPanel.getRootPanel(); if (dockable.isAutoHideAllowed()) { boolean verticalAllowed = dockable.getAutoHideStyle() == DockableStyle.BOTH || dockable.getAutoHideStyle() == DockableStyle.VERTICAL; boolean southAllowed = dockable.getAutoHideStyle() == DockableStyle.BOTH || dockable.getAutoHideStyle() == DockableStyle.HORIZONTAL; pinWest.setVisible(verticalAllowed && root.isLocationSupported(ToolbarLocation.WEST)); pinEast.setVisible(verticalAllowed && root.isLocationSupported(ToolbarLocation.EAST)); pinSouth.setVisible(southAllowed && root.isLocationSupported(ToolbarLocation.SOUTH)); } } /** * The mouse has moved on screen, and we need to check its position against all the root docking handles * * @param mousePosOnScreen New mouse position on screen */ public void mouseMoved(Point mousePosOnScreen) { Point framePoint = new Point(mousePosOnScreen); SwingUtilities.convertPointFromScreen(framePoint, frame); rootCenter.mouseMoved(framePoint); rootWest.mouseMoved(framePoint); rootNorth.mouseMoved(framePoint); rootEast.mouseMoved(framePoint); rootSouth.mouseMoved(framePoint); mouseOverRegion = null; if (rootCenter.isMouseOver()) mouseOverRegion = DockingRegion.CENTER; if (rootWest.isMouseOver()) mouseOverRegion = DockingRegion.WEST; if (rootNorth.isMouseOver()) mouseOverRegion = DockingRegion.NORTH; if (rootEast.isMouseOver()) mouseOverRegion = DockingRegion.EAST; if (rootSouth.isMouseOver()) mouseOverRegion = DockingRegion.SOUTH; pinWest.mouseMoved(framePoint); pinEast.mouseMoved(framePoint); pinSouth.mouseMoved(framePoint); mouseOverPin = null; if (pinWest.isMouseOver()) mouseOverPin = DockingRegion.WEST; if (pinEast.isMouseOver()) mouseOverPin = DockingRegion.EAST; if (pinSouth.isMouseOver()) mouseOverPin = DockingRegion.SOUTH; } private void setupHandle(JFrame frame, DockingHandle label) { label.setVisible(true); frame.add(label); } private void setRootHandleLocations() { Point location = rootPanel.getRootPanel().getLocation(); Dimension size = rootPanel.getRootPanel().getSize(); location.x += size.width / 2; location.y += size.height / 2; SwingUtilities.convertPointToScreen(location, rootPanel.getRootPanel().getParent()); SwingUtilities.convertPointFromScreen(location, frame); setLocation(rootCenter, location.x, location.y); setLocation(rootWest, location.x - (size.width / 2) + rootHandleSpacing(rootWest), location.y); setLocation(rootNorth, location.x, location.y - (size.height / 2) + rootHandleSpacing(rootNorth)); setLocation(rootEast, location.x + (size.width / 2) - rootHandleSpacing(rootEast), location.y); setLocation(rootSouth, location.x, location.y + (size.height / 2) - rootHandleSpacing(rootSouth)); setLocation(pinWest, location.x - (size.width / 2) + rootHandleSpacing(pinWest), location.y - (size.height / 3)); setLocation(pinEast, location.x + (size.width / 2) - rootHandleSpacing(pinEast), location.y - (size.height / 3)); setLocation(pinSouth, location.x - (size.width / 3), location.y + (size.height / 2) - rootHandleSpacing(pinSouth)); } private int rootHandleSpacing(JLabel handle) { return handle.getWidth() + 16; } private void setLocation(Component component, int x, int y) { component.setLocation(x - (HANDLE_ICON_SIZE / 2), y - (HANDLE_ICON_SIZE / 2)); } /** * Paint the handles * * @param g2 Graphics2D instance to use */ public void paint(Graphics2D g2) { // draw root handles rootCenter.paintHandle(g2); rootEast.paintHandle(g2); rootWest.paintHandle(g2); rootNorth.paintHandle(g2); rootSouth.paintHandle(g2); pinWest.paintHandle(g2); pinEast.paintHandle(g2); pinSouth.paintHandle(g2); } /** * Check if the mouse is over a root handle * * @return Is the mouse over a root handle? */ public boolean isOverHandle() { return rootCenter.isMouseOver() || rootEast.isMouseOver() || rootWest.isMouseOver() || rootNorth.isMouseOver() || rootSouth.isMouseOver(); } /** * Check if the mouse is over an auto-hide handle * * @return Is the mouse over an auto-hide handle? */ public boolean isOverPinHandle() { return pinEast.isMouseOver() || pinSouth.isMouseOver() || pinWest.isMouseOver(); } /** * Get the root region that the mouse is over * * @return Root region or null */ public DockingRegion getRegion() { if (rootCenter.isMouseOver()) { return DockingRegion.CENTER; } if (rootEast.isMouseOver()) { return DockingRegion.EAST; } if (rootWest.isMouseOver()) { return DockingRegion.WEST; } if (rootNorth.isMouseOver()) { return DockingRegion.NORTH; } if (rootSouth.isMouseOver()) { return DockingRegion.SOUTH; } return null; } /** * Get the auto-hide region that the mouse is over * * @return Auto-hide region or null */ public ToolbarLocation getPinRegion() { if (pinEast.isMouseOver()) { return ToolbarLocation.EAST; } else if (pinWest.isMouseOver()) { return ToolbarLocation.WEST; } else if (pinSouth.isMouseOver()) { return ToolbarLocation.SOUTH; } return null; } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-api/src/io/github/andrewauclair/moderndocking/internal/floating/DockedTabbedPanelFloatListener.java
docking-api/src/io/github/andrewauclair/moderndocking/internal/floating/DockedTabbedPanelFloatListener.java
/* Copyright (c) 2024 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 io.github.andrewauclair.moderndocking.internal.floating; import io.github.andrewauclair.moderndocking.Dockable; import io.github.andrewauclair.moderndocking.DockingRegion; import io.github.andrewauclair.moderndocking.api.DockingAPI; import io.github.andrewauclair.moderndocking.internal.DockableWrapper; import io.github.andrewauclair.moderndocking.internal.DockedTabbedPanel; import io.github.andrewauclair.moderndocking.internal.DockingComponentUtils; import io.github.andrewauclair.moderndocking.internal.DockingInternal; import io.github.andrewauclair.moderndocking.internal.DockingListeners; import io.github.andrewauclair.moderndocking.internal.FloatingFrame; import java.awt.Point; import java.awt.Window; import java.awt.dnd.DragGestureEvent; import java.util.ArrayList; import java.util.List; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.SwingUtilities; /** * Listener for drag events on tab groups */ public class DockedTabbedPanelFloatListener extends FloatListener { private final DockingAPI docking; /** * The tabbed panel we're listening to */ protected final DockedTabbedPanel tabs; /** * Create a new instance, tied to the tabbed panel * * @param docking The docking instance this listener belongs to * @param tabs The tabbed panel to listen for drags on * @param dragComponent The drag component to add the drag listener to */ public DockedTabbedPanelFloatListener(DockingAPI docking, DockedTabbedPanel tabs, JComponent dragComponent) { super(docking, tabs, dragComponent); this.docking = docking; this.tabs = tabs; } @Override protected boolean allowDrag(DragGestureEvent dragGestureEvent) { // if we're dragging from a tab then we need to use the normal drag event Point dragOrigin = new Point(dragGestureEvent.getDragOrigin()); SwingUtilities.convertPointToScreen(dragOrigin, dragGestureEvent.getComponent()); int targetTabIndex = tabs.getTargetTabIndex(dragOrigin); return targetTabIndex == -1; } @Override protected Window getOriginalWindow() { return SwingUtilities.windowForComponent(tabs); } @Override protected void undock() { List<DockableWrapper> wrappers = new ArrayList<>(tabs.getDockables()); for (DockableWrapper wrapper : wrappers) { DockingInternal.get(docking).undock(wrapper.getDockable(), true); } } @Override protected JFrame createFloatingFrame() { Floating.setFloatingTabbedPane(true); List<DockableWrapper> wrappers = new ArrayList<>(tabs.getDockables()); return new TempFloatingFrame(wrappers, tabs.getSelectedTabIndex(), tabs, tabs.getSize()); } @Override protected boolean dropPanel(FloatUtilsFrame utilsFrame, JFrame floatingFrame, Point mousePosOnScreen) { if (!(floatingFrame instanceof TempFloatingFrame)) { return false; } Floating.setFloatingTabbedPane(false); TempFloatingFrame tempFloatingFrame = (TempFloatingFrame) floatingFrame; List<DockableWrapper> dockables = new ArrayList<>(tempFloatingFrame.getDockables()); Dockable selectedDockable = dockables.get(tempFloatingFrame.getSelectedIndex()).getDockable(); if (utilsFrame == null) { for (DockableWrapper dockable : dockables) { // don't allow dockables that can't be closed or are limited to their window to move to another window if (dockable.getDockable().isLimitedToWindow() || !dockable.getDockable().isClosable()) { return false; } } boolean first = true; Dockable firstDockable = null; FloatingFrame newFrame = null; for (DockableWrapper dockable : dockables) { if (first) { first = false; newFrame = new FloatingFrame(docking, dockable.getDockable(), tempFloatingFrame); firstDockable = dockable.getDockable(); } else { docking.dock(dockable.getDockable(), firstDockable, DockingRegion.CENTER); } } if (selectedDockable != null) { docking.bringToFront(selectedDockable); } if (newFrame != null) { final FloatingFrame frame = newFrame; SwingUtilities.invokeLater(() -> { DockingListeners.fireNewFloatingFrameEvent(frame, frame.getRoot()); }); } return true; } boolean first = true; Dockable firstDockable = null; Window targetWindow = DockingComponentUtils.findRootAtScreenPos(docking, mousePosOnScreen); Dockable dockableAtPos = DockingComponentUtils.findDockableAtScreenPos(mousePosOnScreen, targetWindow); DockingRegion region = dockableAtPos == null ? DockingRegion.CENTER : utilsFrame.getDockableRegion(dockableAtPos, null, mousePosOnScreen); if (utilsFrame.isOverDockableHandle()) { region = utilsFrame.dockableHandle(); } for (DockableWrapper dockable : dockables) { // don't allow dockables that can't be closed or are limited to their window to move to another window if (targetWindow != originalWindow && (dockable.getDockable().isLimitedToWindow() || !dockable.getDockable().isClosable())) { return false; } if (first) { if (utilsFrame.isOverRootHandle()) { docking.dock(dockable.getDockable(), targetWindow, utilsFrame.rootHandleRegion()); } else if (dockableAtPos != null) { docking.dock(dockable.getDockable(), dockableAtPos, region); } firstDockable = dockable.getDockable(); } else { docking.dock(dockable.getDockable(), firstDockable, DockingRegion.CENTER); } first = false; } if (selectedDockable != null) { docking.bringToFront(selectedDockable); } return true; } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-api/src/io/github/andrewauclair/moderndocking/internal/floating/DisplayPanelFloatListener.java
docking-api/src/io/github/andrewauclair/moderndocking/internal/floating/DisplayPanelFloatListener.java
/* Copyright (c) 2024 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 io.github.andrewauclair.moderndocking.internal.floating; import io.github.andrewauclair.moderndocking.Dockable; import io.github.andrewauclair.moderndocking.DockingRegion; import io.github.andrewauclair.moderndocking.api.DockingAPI; import io.github.andrewauclair.moderndocking.internal.CustomTabbedPane; import io.github.andrewauclair.moderndocking.internal.DisplayPanel; import io.github.andrewauclair.moderndocking.internal.DockableWrapper; import io.github.andrewauclair.moderndocking.internal.DockedTabbedPanel; import io.github.andrewauclair.moderndocking.internal.DockingComponentUtils; import io.github.andrewauclair.moderndocking.internal.DockingInternal; import io.github.andrewauclair.moderndocking.internal.DockingListeners; import io.github.andrewauclair.moderndocking.internal.FloatingFrame; import io.github.andrewauclair.moderndocking.internal.InternalRootDockingPanel; import io.github.andrewauclair.moderndocking.settings.Settings; import java.awt.Point; import java.awt.Window; import java.awt.dnd.DragGestureEvent; import java.util.Collections; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.SwingUtilities; /** * Floating listener used for floating individual panels */ public class DisplayPanelFloatListener extends FloatListener { private final DockingAPI docking; private final DisplayPanel panel; /** * Create a new float listener for the specific display panel * * @param docking Docking instance * @param panel The display panel to listen to */ public DisplayPanelFloatListener(DockingAPI docking, DisplayPanel panel) { super(docking, panel); this.docking = docking; this.panel = panel; } /** * Create a new float listener for the specific display panel * * @param docking Docking instance * @param panel The display panel to listen to * @param dragComponent The component to add the drag listener to */ public DisplayPanelFloatListener(DockingAPI docking, DisplayPanel panel, JComponent dragComponent) { super(docking, panel, dragComponent); this.docking = docking; this.panel = panel; } @Override protected boolean allowDrag(DragGestureEvent dragGestureEvent) { return true; } /** * Get the dockable that this float listener is listening to for drag events * * @return Dockable this panel is tied to */ public Dockable getDockable() { return panel.getWrapper().getDockable(); } @Override protected Window getOriginalWindow() { return panel.getWrapper().getWindow(); } @Override protected void undock() { DockingInternal.get(docking).undock(panel.getWrapper().getDockable(), true); } @Override protected JFrame createFloatingFrame() { if (Settings.alwaysDisplayTabsMode()) { return new TempFloatingFrame(Collections.singletonList(panel.getWrapper()), 0, panel, panel.getSize()); } return new TempFloatingFrame(panel.getWrapper(), panel, panel.getSize()); } @Override protected boolean dropPanel(FloatUtilsFrame utilsFrame, JFrame floatingFrame, Point mousePosOnScreen) { DockableWrapper floatingDockable = panel.getWrapper(); if (utilsFrame != null) { Window targetWindow = DockingComponentUtils.findRootAtScreenPos(docking, mousePosOnScreen); InternalRootDockingPanel root = DockingComponentUtils.rootForWindow(docking, targetWindow); Dockable dockableAtPos = DockingComponentUtils.findDockableAtScreenPos(mousePosOnScreen, targetWindow); // don't allow dockables that can't be closed or are limited to their window to move to another window if (targetWindow != originalWindow && (floatingDockable.getDockable().isLimitedToWindow() || !floatingDockable.getDockable().isClosable())) { return false; } if (utilsFrame.isOverRootHandle()) { docking.dock(floatingDockable.getDockable(), targetWindow, utilsFrame.rootHandleRegion()); } else if (utilsFrame.isOverDockableHandle()) { docking.dock(floatingDockable.getDockable(), dockableAtPos, utilsFrame.dockableHandle()); } else if (utilsFrame.isOverPinHandle()) { docking.autoHideDockable(floatingDockable.getDockable(), utilsFrame.pinRegion(), targetWindow); } else if (utilsFrame.isOverTab()) { CustomTabbedPane tabbedPane = DockingComponentUtils.findTabbedPaneAtPos(mousePosOnScreen, targetWindow); DockedTabbedPanel dockingTabPanel = (DockedTabbedPanel) DockingComponentUtils.findDockingPanelAtScreenPos(mousePosOnScreen, targetWindow); if (tabbedPane != null && dockingTabPanel != null) { int tabIndex = tabbedPane.getTargetTabIndex(mousePosOnScreen, true); if (tabIndex == -1) { dockingTabPanel.dock(floatingDockable.getDockable(), DockingRegion.CENTER, 1.0); } else { dockingTabPanel.dockAtIndex(floatingDockable.getDockable(), tabIndex); } } else { // failed to dock, restore the previous layout return false; } } else if (dockableAtPos != null) { // docking to a dockable region DockingRegion region = utilsFrame.getDockableRegion(dockableAtPos, panel.getWrapper().getDockable(), mousePosOnScreen); docking.dock(floatingDockable.getDockable(), dockableAtPos, region); } else if (floatingDockable.getDockable().isFloatingAllowed()) { // floating FloatingFrame newFloatingFrame = new FloatingFrame(docking, floatingDockable.getDockable(), mousePosOnScreen, floatingDockable.getDisplayPanel().getSize(), 0); docking.dock(floatingDockable.getDockable(), newFloatingFrame); SwingUtilities.invokeLater(() -> { docking.bringToFront(floatingDockable.getDockable()); DockingListeners.fireNewFloatingFrameEvent(newFloatingFrame, newFloatingFrame.getRoot(), floatingDockable.getDockable()); }); } else { // failed to dock, restore the previous layout return false; } } else if (floatingDockable.getDockable().isFloatingAllowed()) { // floating FloatingFrame newFloatingFrame = new FloatingFrame(docking, floatingDockable.getDockable(), mousePosOnScreen, floatingDockable.getDisplayPanel().getSize(), 0); docking.dock(floatingDockable.getDockable(), newFloatingFrame); SwingUtilities.invokeLater(() -> { docking.bringToFront(floatingDockable.getDockable()); DockingListeners.fireNewFloatingFrameEvent(newFloatingFrame, newFloatingFrame.getRoot(), floatingDockable.getDockable()); }); } else { // failed to dock, restore the previous layout return false; } return true; } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-api/src/io/github/andrewauclair/moderndocking/internal/floating/Floating.java
docking-api/src/io/github/andrewauclair/moderndocking/internal/floating/Floating.java
/* Copyright (c) 2024 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 io.github.andrewauclair.moderndocking.internal.floating; import io.github.andrewauclair.moderndocking.api.DockingAPI; import io.github.andrewauclair.moderndocking.internal.InternalRootDockingPanel; import java.awt.Window; import java.util.HashMap; import java.util.Map; import javax.swing.SwingUtilities; /** * Small utility class for floating feature */ public class Floating { private static final Map<Window, FloatUtilsFrame> utilFrames = new HashMap<>(); private static boolean isFloating = false; private static boolean isFloatingTabbedPane = false; /** * Unused. All methods are static */ private Floating() { } /** * Register a new docking window and create a utility frame for it * * @param docking The docking instance this window is for * @param window The window being registered * @param root The internal root in the window */ public static void registerDockingWindow(DockingAPI docking, Window window, InternalRootDockingPanel root) { SwingUtilities.invokeLater(() -> utilFrames.put(window, new FloatUtilsFrame(docking, window, root))); } /** * Deregister a window. Used when a window is closed * * @param window The window to deregister */ public static void deregisterDockingWindow(Window window) { utilFrames.remove(window); } /** * Lookup the utility frame for a window * * @param window The window to search for * * @return Utility frame or null */ public static FloatUtilsFrame frameForWindow(Window window) { return utilFrames.get(window); } /** * Check if we have a dockable actively floating * * @return Are we floating a dockable? */ public static boolean isFloating() { return isFloating; } /** * Set the floating state * * @param floating New floating state */ public static void setFloating(boolean floating) { isFloating = floating; } /** * Check if we're floating a tabbed pane instead of a simple panel * * @return Are we floating a tabbed pane? */ public static boolean isFloatingTabbedPane() { return isFloatingTabbedPane; } /** * Set the floating tabbed pane flag * * @param floating New floating tabbed pane state */ public static void setFloatingTabbedPane(boolean floating) { isFloatingTabbedPane = floating; } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-api/src/io/github/andrewauclair/moderndocking/internal/floating/FloatUtilsFrame.java
docking-api/src/io/github/andrewauclair/moderndocking/internal/floating/FloatUtilsFrame.java
/* Copyright (c) 2024 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 io.github.andrewauclair.moderndocking.internal.floating; import io.github.andrewauclair.moderndocking.Dockable; import io.github.andrewauclair.moderndocking.DockingRegion; import io.github.andrewauclair.moderndocking.api.DockingAPI; import io.github.andrewauclair.moderndocking.internal.CustomTabbedPane; import io.github.andrewauclair.moderndocking.internal.DockingComponentUtils; import io.github.andrewauclair.moderndocking.internal.InternalRootDockingPanel; import io.github.andrewauclair.moderndocking.ui.ToolbarLocation; import java.awt.*; import java.awt.dnd.DragSource; import java.awt.dnd.DragSourceDragEvent; import java.awt.dnd.DragSourceMotionListener; import java.awt.event.ComponentEvent; import java.awt.event.ComponentListener; import java.awt.event.WindowEvent; import java.awt.event.WindowListener; import java.awt.image.BufferStrategy; import java.util.ArrayList; import java.util.List; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.SwingUtilities; /** * A special invisible frame that's used to provide docking handles and overlays */ public class FloatUtilsFrame extends JFrame implements DragSourceMotionListener, ComponentListener, WindowListener { /** * The window this utility frame is tied to */ private final Window referenceDockingWindow; /** * The internal root of the reference docking window */ private final InternalRootDockingPanel root; /** * The root docking handles to render */ private final RootDockingHandles rootHandles; /** * The overlay to render */ private final FloatingOverlay overlay; /** * The active floating listener */ private FloatListener floatListener; /** * The temporary frame used for floating */ private JFrame floatingFrame; /** * The source of the drag that was started */ private DragSource dragSource; /** * The currently floating dockable */ private Dockable currentDockable; /** * Handles to display on target dockables */ private DockableHandles dockableHandles; private List<Window> windowStack = new ArrayList<>(); /** * create a strategy for multi-buffering. */ BufferStrategy bs; /** * Render panel used to render the utilities. Do this so we're not painting directly onto the transparent frame */ JPanel renderPanel = new JPanel() { @Override protected void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g.create(); rootHandles.paint(g2); if (dockableHandles != null) { dockableHandles.paint(g2); } overlay.paint(g); g2.dispose(); } }; /** * Create a new instance for a specific window * * @param docking The docking instance * @param referenceDockingWindow The window that this utils frame is tied to * @param root The root within the reference window */ public FloatUtilsFrame(DockingAPI docking, Window referenceDockingWindow, InternalRootDockingPanel root) { this.referenceDockingWindow = referenceDockingWindow; this.root = root; this.rootHandles = new RootDockingHandles(this, root); this.overlay = new FloatingOverlay(docking, this); setTitle("Utils Frame"); this.referenceDockingWindow.addComponentListener(this); SwingUtilities.invokeLater(this::setSizeAndLocation); orderFrames(); referenceDockingWindow.addWindowListener(this); addWindowListener(this); setLayout(null); // don't use a layout manager for this custom painted frame setUndecorated(true); // don't want to see a frame border setType(Type.UTILITY); // hide this frame from the task bar setBackground(new Color(0, 0, 0, 0)); // don't want a background for this frame getRootPane().setBackground(new Color(0, 0, 0, 0)); // don't want a background for the root pane either. Workaround for a FlatLaf macOS issue. getContentPane().setBackground(new Color(0, 0, 0, 0)); // don't want a background for the content frame either. // always use the render panel on Windows if (System.getProperty("os.name").contains("Windows")) { add(renderPanel); renderPanel.setOpaque(false); } else { // handle Linux differently. if we have multi-buffer, use the render panel, else, use a buffer strategy GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration(); BufferCapabilities bufferCapabilities = gc.getBufferCapabilities(); if (bufferCapabilities.isMultiBufferAvailable()) { add(renderPanel); renderPanel.setOpaque(false); } try { if (getContentPane() instanceof JComponent) { ((JComponent) getContentPane()).setOpaque(false); } } catch (IllegalComponentStateException e) { // TODO we need to handle platforms that don't support translucent display // this exception indicates that the platform doesn't support changing the opacity } } } /** * Activate this utilities frame and display it * * @param floatListener The float listener that started the drag * @param floatingFrame The frame that contains the floating dockable * @param dragSource The source of the drag * @param mousePosOnScreen The mouse position on screen */ public void activate(FloatListener floatListener, JFrame floatingFrame, DragSource dragSource, Point mousePosOnScreen) { this.floatListener = floatListener; this.floatingFrame = floatingFrame; this.dragSource = dragSource; dragSource.addDragSourceMotionListener(this); floatingFrame.addWindowListener(this); mouseMoved(mousePosOnScreen); if (floatListener instanceof DisplayPanelFloatListener) { Dockable floatingDockable = ((DisplayPanelFloatListener) floatListener).getDockable(); rootHandles.setFloatingDockable(floatingDockable); } setVisible(true); if (!System.getProperty("os.name").contains("Windows")) { GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration(); BufferCapabilities bufferCapabilities = gc.getBufferCapabilities(); if (!bufferCapabilities.isMultiBufferAvailable()) { createBufferStrategy(2); bs = this.getBufferStrategy(); } } orderFrames(); } /** * Floating has ended, deactivate the utilities */ public void deactivate() { setVisible(false); if (dragSource != null) { dragSource.removeDragSourceMotionListener(this); } if (floatingFrame != null) { floatingFrame.removeWindowListener(this); } floatListener = null; floatingFrame = null; dragSource = null; currentDockable = null; dockableHandles = null; } @Override public void dragMouseMoved(DragSourceDragEvent event) { SwingUtilities.invokeLater(() -> mouseMoved(event.getLocation())); } private void mouseMoved(Point mousePosOnScreen) { if (dragSource == null) { return; } rootHandles.mouseMoved(mousePosOnScreen); if (dockableHandles != null) { dockableHandles.mouseMoved(mousePosOnScreen); } boolean prevVisible = overlay.isVisible(); // hide the overlay. it will be marked visible again if we update it overlay.setVisible(false); if (!referenceDockingWindow.getBounds().contains(mousePosOnScreen)) { return; } Dockable dockable = DockingComponentUtils.findDockableAtScreenPos(mousePosOnScreen, referenceDockingWindow); Dockable floatingDockable = null; if (floatListener instanceof DisplayPanelFloatListener) { floatingDockable = ((DisplayPanelFloatListener) floatListener).getDockable(); } if (dockable != currentDockable) { if (dockable == null) { dockableHandles = null; } else if (floatListener instanceof DisplayPanelFloatListener) { dockableHandles = new DockableHandles(this, dockable, floatingDockable); } else { dockableHandles = new DockableHandles(this, dockable); } } currentDockable = dockable; if (rootHandles.isOverHandle()) { if (!floatingFrame.isVisible()) { changeVisibility(floatingFrame, true); } overlay.updateForRoot(root, rootHandles.getRegion()); } else if (dockableHandles != null) { if (!floatingFrame.isVisible()) { changeVisibility(floatingFrame, true); } overlay.updateForDockable(currentDockable, floatingDockable, mousePosOnScreen, dockableHandles.getRegion()); } else if (currentDockable == null && floatListener instanceof DisplayPanelFloatListener) { CustomTabbedPane tabbedPane = DockingComponentUtils.findTabbedPaneAtPos(mousePosOnScreen, referenceDockingWindow); changeVisibility(floatingFrame, tabbedPane == null); if (tabbedPane != null) { overlay.updateForTab(tabbedPane, mousePosOnScreen); } } else if (!floatingFrame.isVisible()) { changeVisibility(floatingFrame, true); } repaint(); if (overlay.requiresRedraw() || prevVisible != overlay.isVisible()) { repaint(); overlay.clearRedraw(); } } private void changeVisibility(JFrame frame, boolean visible) { if (frame.isVisible() != visible) { frame.setVisible(visible); orderFrames(); } } private void orderFrames() { windowStack.clear(); windowStack.add(this); if (floatingFrame != null) { windowStack.add(floatingFrame); } windowStack.add(referenceDockingWindow); SwingUtilities.invokeLater(referenceDockingWindow::toFront); } @Override public void paint(Graphics g) { if (bs == null) { super.paint(g); return; } g = bs.getDrawGraphics(); Graphics2D g2 = (Graphics2D) bs.getDrawGraphics(); g2.clearRect(0, 0, getWidth(), getHeight()); rootHandles.paint(g2); if (dockableHandles != null) { dockableHandles.paint(g2); } overlay.paint(g); g2.dispose(); bs.show(); } @Override public void componentResized(ComponentEvent e) { SwingUtilities.invokeLater(this::setSizeAndLocation); } @Override public void componentMoved(ComponentEvent e) { SwingUtilities.invokeLater(this::setSizeAndLocation); } @Override public void componentShown(ComponentEvent e) { } @Override public void componentHidden(ComponentEvent e) { } /** * Check if the mouse is over a root handle * * @return Is the mouse over a root handle? */ public boolean isOverRootHandle() { return rootHandles.isOverHandle(); } /** * Get the root region that's selected * * @return Root region or null */ public DockingRegion rootHandleRegion() { return rootHandles.getRegion(); } /** * Check if the mouse is over an auto-hide handle * * @return Is the mouse over an auto-hide handle? */ public boolean isOverPinHandle() { return rootHandles.isOverPinHandle(); } /** * Get the auto-hide region * * @return Auto-hide region or null */ public ToolbarLocation pinRegion() { return rootHandles.getPinRegion(); } /** * Check if the mouse is over a dockable handle * * @return Is the mouse over a dockable handle? */ public boolean isOverDockableHandle() { if (dockableHandles == null) { return false; } return dockableHandles.getRegion() != null; } /** * Check if the mouse is over a tab * * @return Is the mouse over a tab? */ public boolean isOverTab() { return overlay.isOverTab(); } /** * Get the handle the mouse is over in the target dockable * * @return Region in the target dockable or null */ public DockingRegion dockableHandle() { if (dockableHandles == null) { return null; } return dockableHandles.getRegion(); } /** * Get the current region the dockable is over * * @param targetDockable The dockable the mouse is over * @param floatingDockable The active floating dockable * @param mousePosOnScreen The mouse position on screen * * @return The docking region or null */ public DockingRegion getDockableRegion(Dockable targetDockable, Dockable floatingDockable, Point mousePosOnScreen) { return overlay.getRegion(targetDockable, floatingDockable, mousePosOnScreen); } private void setSizeAndLocation() { // skip for now if the reference window is not showing // we can't get its location on screen if it's not on screen if (!referenceDockingWindow.isShowing()) { return; } int padding = (int) (DockingHandle.HANDLE_ICON_SIZE * 1.75); Point location = new Point(referenceDockingWindow.getLocationOnScreen()); Dimension size = new Dimension(referenceDockingWindow.getSize()); location.x -= padding; location.y -= padding; size.width += padding * 2; size.height += padding * 2; // set location and size based on the reference docking frame setLocation(location); setSize(size); renderPanel.setSize(size); rootHandles.updateHandlePositions(); revalidate(); repaint(); } @Override public void windowOpened(WindowEvent e) { } @Override public void windowClosing(WindowEvent e) { } @Override public void windowClosed(WindowEvent e) { } @Override public void windowIconified(WindowEvent e) { } @Override public void windowDeiconified(WindowEvent e) { } @Override public void windowActivated(WindowEvent e) { // System.out.println("windowActivated " + ((JFrame) e.getWindow()).getTitle()); windowStack.remove(e.getWindow()); windowStack.add(e.getWindow()); // expected: // reference window // floating window // utils window if (windowStack.size() == 3 && windowStack.get(0) == referenceDockingWindow && windowStack.get(1) == floatingFrame && windowStack.get(2) == this) { // perfect // System.out.println("Windows are in proper order 1"); } else if (windowStack.size() == 2 && windowStack.get(0) == referenceDockingWindow && windowStack.get(1) == this) { // perfect // System.out.println("Windows are in proper order 2"); } else if (windowStack.get(0) != referenceDockingWindow) { // reference window isn't at the bottom, figure out which frame is out of order if (windowStack.get(0) == floatingFrame) { // System.out.println("first frame is floating frame, bring to front"); SwingUtilities.invokeLater(floatingFrame::toFront); } else if (windowStack.get(0) == this) { // System.out.println("First frame is utils frame, bring to front"); SwingUtilities.invokeLater(this::toFront); } } else if (windowStack.size() > 1 && windowStack.get(1) != floatingFrame) { // System.out.println("Second frame is not floating frame, bring utils to front"); SwingUtilities.invokeLater(this::toFront); } } @Override public void windowDeactivated(WindowEvent e) { } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-api/src/io/github/andrewauclair/moderndocking/internal/floating/FloatListener.java
docking-api/src/io/github/andrewauclair/moderndocking/internal/floating/FloatListener.java
/* Copyright (c) 2024 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 io.github.andrewauclair.moderndocking.internal.floating; import io.github.andrewauclair.moderndocking.api.DockingAPI; import io.github.andrewauclair.moderndocking.internal.DisplayPanel; import io.github.andrewauclair.moderndocking.internal.DockedTabbedPanel; import io.github.andrewauclair.moderndocking.internal.DockingComponentUtils; import io.github.andrewauclair.moderndocking.internal.InternalRootDockingPanel; import io.github.andrewauclair.moderndocking.layouts.WindowLayout; import java.awt.*; import java.awt.datatransfer.StringSelection; import java.awt.dnd.DnDConstants; import java.awt.dnd.DragGestureEvent; import java.awt.dnd.DragGestureListener; import java.awt.dnd.DragGestureRecognizer; import java.awt.dnd.DragSource; import java.awt.dnd.DragSourceAdapter; import java.awt.dnd.DragSourceDragEvent; import java.awt.dnd.DragSourceDropEvent; import java.awt.dnd.DragSourceListener; import java.awt.dnd.DragSourceMotionListener; import java.awt.dnd.InvalidDnDOperationException; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.SwingUtilities; /** * Base class for float listeners. Listen for drags that might be dockable floating events */ public abstract class FloatListener extends DragSourceAdapter implements DragSourceMotionListener, DragSourceListener { private final DockingAPI docking; private final JPanel panel; private final JComponent dragComponent; // our drag source to support dragging the dockables private final DragSource dragSource = new DragSource(); private Point dragComponentDragOffset = new Point(); protected Window originalWindow; private WindowLayout originalWindowLayout; private JFrame floatingFrame; private Window currentUtilWindow; private FloatUtilsFrame currentUtilFrame; private DragGestureRecognizer alternateDragGesture; /** * Create a new listener for a specific panel * * @param docking The docking instance * @param panel The panel to listen for drags on */ public FloatListener(DockingAPI docking, DisplayPanel panel) { this(docking, panel, (JComponent) panel.getWrapper().getHeaderUI()); } /** * Create a new listener for a specific panel * * @param docking The docking instance * @param panel The panel to listen for drags on * @param dragComponent The component to add the drag listeners to */ public FloatListener(DockingAPI docking, DisplayPanel panel, JComponent dragComponent) { this(docking, (JPanel) panel, dragComponent); } /** * Create a new listener for a tabbed panel * * @param docking The docking instance * @param tabs The tabbed panel to listen for drags on * @param dragComponent The component to add drag listeners to */ public FloatListener(DockingAPI docking, DockedTabbedPanel tabs, JComponent dragComponent) { this(docking, (JPanel) tabs, dragComponent); } private FloatListener(DockingAPI docking, JPanel panel, JComponent dragComponent) { this.docking = docking; this.panel = panel; this.dragComponent = dragComponent; if (dragComponent != null) { dragSource.addDragSourceMotionListener(this); dragSource.createDefaultDragGestureRecognizer(dragComponent, DnDConstants.ACTION_MOVE, this::startDrag); } } /** * Add an alternate drag source, used for dragging from tabs * * @param dragComponent Drag component to add * @param listener The drag gesture listener to add */ public void addAlternateDragSource(JComponent dragComponent, DragGestureListener listener) { alternateDragGesture = dragSource.createDefaultDragGestureRecognizer(dragComponent, DnDConstants.ACTION_MOVE, listener); } /** * Remove the alternate drag source * * @param listener The listener to remove */ public void removeAlternateDragSource(DragGestureListener listener) { alternateDragGesture.removeDragGestureListener(listener); alternateDragGesture = null; } /** * Get the panel that we're listening to * * @return Dockable panel */ public JPanel getPanel() { return panel; } /** * Check if this listener is interested in the drag * * @param dragGestureEvent The drag event that is in progress * @return True if this listener wishes to handle the drag */ protected abstract boolean allowDrag(DragGestureEvent dragGestureEvent); /** * Start a new drag * * @param dragGestureEvent The drag gesture */ public void startDrag(DragGestureEvent dragGestureEvent) { // if there is already a floating panel, don't float this one if (Floating.isFloating()) { return; } if (!allowDrag(dragGestureEvent)) { return; } try { dragSource.startDrag(dragGestureEvent, Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR), new StringSelection(""), this); } catch (InvalidDnDOperationException ignored) { // someone beat us to it return; } currentUtilWindow = null; Floating.setFloating(true); dragStarted(dragGestureEvent.getDragOrigin()); Point mouseOnScreen = new Point(dragGestureEvent.getDragOrigin()); SwingUtilities.convertPointToScreen(mouseOnScreen, dragGestureEvent.getComponent()); updateFramePosition(mouseOnScreen); } private void dragStarted(Point dragOrigin) { dragComponentDragOffset = new Point(dragOrigin); // force the drag offset to be inset from the edge slightly dragComponentDragOffset.y = Math.max(5, dragComponentDragOffset.y); dragComponentDragOffset.x = Math.max(5, dragComponentDragOffset.x); originalWindow = getOriginalWindow(); originalWindowLayout = docking.getDockingState().getWindowLayout(originalWindow); floatingFrame = createFloatingFrame(); undock(); DockingComponentUtils.removeIllegalFloats(docking, originalWindow); InternalRootDockingPanel currentRoot = DockingComponentUtils.rootForWindow(docking, originalWindow); // hide the original window if it is not the main window of the app if (currentRoot.isEmpty() && docking.getMainWindow() != originalWindow) { // originalWindow.setVisible(false); } } /** * Remove our drag source motion listener */ public void removeListeners() { dragSource.removeDragSourceMotionListener(this); } @Override public void dragMouseMoved(DragSourceDragEvent event) { if (!Floating.isFloating()) { return; } updateFramePosition(event.getLocation()); } private void updateFramePosition(Point mousePosOnScreen) { // update the frames position to our mouse position Point framePos = new Point(mousePosOnScreen.x - dragComponentDragOffset.x, mousePosOnScreen.y - dragComponentDragOffset.y); floatingFrame.setLocation(framePos); checkForFrameSwitch(mousePosOnScreen); } private void checkForFrameSwitch(Point mousePosOnScreen) { // find the frame at our current position Window frame = DockingComponentUtils.findRootAtScreenPos(docking, mousePosOnScreen); if (frame != currentUtilWindow) { if (currentUtilFrame != null) { currentUtilFrame.deactivate(); } currentUtilWindow = frame; currentUtilFrame = Floating.frameForWindow(currentUtilWindow); if (currentUtilFrame != null) { currentUtilFrame.activate(this, floatingFrame, dragSource, mousePosOnScreen); } } } @Override public void dragDropEnd(DragSourceDropEvent event) { if (!Floating.isFloating()) { return; } dropFloatingPanel(event.getLocation()); InternalRootDockingPanel currentRoot = DockingComponentUtils.rootForWindow(docking, originalWindow); if (currentRoot.isEmpty() && docking.canDisposeWindow(originalWindow)) { originalWindow.dispose(); } Floating.setFloating(false); } private void dropFloatingPanel(Point mousePosOnScreen) { if (!Floating.isFloating()) { return; } boolean docked = dropPanel(currentUtilFrame, floatingFrame, mousePosOnScreen); if (currentUtilFrame != null) { currentUtilFrame.deactivate(); } if (!docked) { docking.getDockingState().restoreWindowLayout(originalWindow, originalWindowLayout); } floatingFrame.dispose(); floatingFrame = null; } /** * Get the original window that the dockable started in at the start of this floating event * * @return The original window of the dockable */ protected abstract Window getOriginalWindow(); /** * Undock the dockable now that a drag has started */ protected abstract void undock(); /** * Create a new floating frame to contain a dockable * * @return The new frame */ protected abstract JFrame createFloatingFrame(); /** * Drop the floating panel * * @param utilsFrame The utils frame that provides the docking handles and overlay * @param floatingFrame The floating frame that contains the floating dockable * @param mousePosOnScreen The position of the mouse on screen * * @return Did we successfully dock the floating dockable? */ protected abstract boolean dropPanel(FloatUtilsFrame utilsFrame, JFrame floatingFrame, Point mousePosOnScreen); }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-api/src/io/github/andrewauclair/moderndocking/internal/floating/DockingHandle.java
docking-api/src/io/github/andrewauclair/moderndocking/internal/floating/DockingHandle.java
/* Copyright (c) 2022 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 io.github.andrewauclair.moderndocking.internal.floating; import io.github.andrewauclair.moderndocking.DockingRegion; import io.github.andrewauclair.moderndocking.ui.DockingSettings; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Point; import java.awt.Rectangle; import java.awt.Stroke; import javax.swing.JLabel; /** * Special label used to draw the docking handles on an overlay */ public class DockingHandle extends JLabel { /** * The size to draw the docking handle, in pixels */ public static final int HANDLE_ICON_SIZE = 32; private static final Stroke dashed = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[]{3}, 0); /** * The region that this docking handle display is drawing */ private final DockingRegion region; /** * Flag indicating whether this handle display is for the root handles */ private final boolean isRoot; /** * This docking handle represents an auto-hide handle */ private final boolean isPin; /** * The mouse is currently over this handle */ private boolean mouseOver = false; /** * Create a new DockingHandle * * @param region The region of this DockingHandle * @param isRoot Is this the root docking handle? */ public DockingHandle(DockingRegion region, boolean isRoot) { this.region = region; this.isRoot = isRoot; this.isPin = false; // set the bounds (we're not in a layout manager) and make sure this handle isn't visible setBounds(0, 0, HANDLE_ICON_SIZE, HANDLE_ICON_SIZE); setVisible(false); } /** * Create a new handle for the given region * * @param region Docking region of the handle */ public DockingHandle(DockingRegion region) { this.region = region; this.isRoot = false; this.isPin = true; // set the bounds (we're not in a layout manager) and make sure this handle isn't visible setBounds(0, 0, HANDLE_ICON_SIZE, HANDLE_ICON_SIZE); setVisible(false); } /** * Mouse has moved on the screen * * @param mousePosition The new mouse position */ public void mouseMoved(Point mousePosition) { mouseOver = getBounds().contains(mousePosition); } /** * Check if the mouse is over this handle * * @return Is mouse over handle? */ public boolean isMouseOver() { if (!isVisible()) { return false; } return mouseOver; } /** * Get the region for this handle * * @return Region this DockingHandle represents */ public DockingRegion getRegion() { return region; } /** * Check if this DockingHandle is for the root of the panel * * @return Whether this is the root docking handle */ public boolean isRoot() { return isRoot; } /** * Check if this DockingHandle is for pinning * * @return Whether this is a pinning handle */ public boolean isPin() { return isPin; } /** * Paint the handle * * @param g2 used to draw the dashed lines on top */ public void paintHandle(Graphics2D g2) { if (!isVisible()) { return; } Color background = DockingSettings.getHandleBackground(); Color hover = DockingSettings.getHandleForeground(); Color outline = DockingSettings.getHandleForeground(); // each root handle has its own background. we have to draw them here. // the dockables all share one big root that is drawn in DockingHandles if (isRoot || isPin) { g2.setColor(background); drawBackground(g2); } if (mouseOver && isPin) { int quarterWidth = getWidth() / 4; int x1 = getX() + quarterWidth; g2.fillRect(x1, getY(), getWidth() / 2, getHeight() / 2); } else if (mouseOver) { g2.setColor(hover); fillMouseOverRegion(g2); } // draw the outline over the mouse over g2.setColor(outline); // only draw the dashed line if the region isn't center and these are not root handles if (region != DockingRegion.CENTER && !isRoot && !isPin) { drawDashedLine(g2); } if (isRoot && region != DockingRegion.CENTER) { drawRootOutline(g2); } else if (isPin) { int quarterWidth = getWidth() / 4; int x1 = getX() + quarterWidth; g2.drawLine(x1, getY(), x1 + (getWidth() / 2), getY()); g2.drawLine(x1, getY()+ (getHeight() / 2), x1 + (getWidth() / 2), getY()+ (getHeight() / 2)); g2.drawLine(x1, getY(), x1, getY() + (getHeight() / 2)); g2.drawLine(x1 + (getWidth() / 2), getY(), x1 + (getWidth() / 2), getY() + (getHeight() / 2)); g2.drawLine(x1 + quarterWidth, getY() + (getHeight() / 2), x1 + quarterWidth, getY() + (getHeight())); } else { g2.drawRect(getX(), getY(), getWidth(), getHeight()); } } private void drawBackground(Graphics g) { int spacing = 8; int x = getX() - spacing; int y = getY() - spacing; int width = getWidth() + (spacing * 2); int height = getHeight() + (spacing * 2); g.fillRect(x, y, width, height); Color border = DockingSettings.getHandleForeground(); g.setColor(border); g.drawRect(x, y, width, height); } private void drawRootOutline(Graphics g) { boolean north = region == DockingRegion.NORTH; boolean south = region == DockingRegion.SOUTH; boolean east = region == DockingRegion.EAST; int halfWidth = getWidth() / 2; int x = east ? getX() + halfWidth : getX(); int y = south ? getY() + halfWidth : getY(); int width = north || south ? getWidth() : halfWidth; int height = north || south ? halfWidth : getHeight(); if (region == DockingRegion.CENTER) { g.drawRect(getX(), getY(), getWidth(), getHeight()); } else { g.drawRect(x, y, width, height); } } private void fillMouseOverRegion(Graphics g) { boolean north = region == DockingRegion.NORTH; boolean south = region == DockingRegion.SOUTH; boolean east = region == DockingRegion.EAST; int halfWidth = getWidth() / 2; int x = east ? getX() + halfWidth : getX(); int y = south ? getY() + halfWidth : getY(); int width = north || south ? getWidth() : halfWidth; int height = north || south ? halfWidth : getHeight(); if (region == DockingRegion.CENTER) { g.fillRect(getX(), getY(), getWidth(), getHeight()); } else { g.fillRect(x, y, width, height); } } private void drawDashedLine(Graphics2D g2) { Stroke currentStroke = g2.getStroke(); g2.setStroke(dashed); boolean north = region == DockingRegion.NORTH; boolean south = region == DockingRegion.SOUTH; int halfWidth = getWidth() / 2; int x = north || south ? getX() : getX() + halfWidth; int y = north || south ? getY() + halfWidth : getY(); int x2 = north || south ? getX() + getWidth() : getX() + halfWidth; int y2 = north || south ? getY() + halfWidth : getY() + getHeight(); if (region == DockingRegion.CENTER) { g2.drawLine(getX(), getY(), getWidth(), getHeight()); } else { g2.drawLine(x, y, x2, y2); } g2.setStroke(currentStroke); } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-api/src/io/github/andrewauclair/moderndocking/ui/DefaultDockingPanel.java
docking-api/src/io/github/andrewauclair/moderndocking/ui/DefaultDockingPanel.java
/* 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 io.github.andrewauclair.moderndocking.ui; import io.github.andrewauclair.moderndocking.Dockable; import io.github.andrewauclair.moderndocking.DockableStyle; import io.github.andrewauclair.moderndocking.event.DockingEvent; import io.github.andrewauclair.moderndocking.event.DockingListener; import java.util.ArrayList; import java.util.List; import javax.swing.Icon; import javax.swing.JMenu; import javax.swing.JPanel; import javax.swing.JPopupMenu; /** * Default implementation of the Dockable interface. Useful for GUI builders where you can set each property. */ public class DefaultDockingPanel extends JPanel implements Dockable, DockingListener { /** * Persistent ID for the dockable in this panel */ private String persistentID; /** * The type for this dockable */ private int type; /** * Tab text to display on tabbed panes */ private String tabText = ""; /** * Icon to use on tabbed panes, auto-hide toolbars, and windows */ private Icon icon; /** * Is this dockable allowed to float? */ private boolean floatingAllowed; /** * Is this dockable limited to its starting window? */ private boolean limitedToWindow; /** * What positions is this dockable allowed to be in? */ private DockableStyle style; /** * Can the user close this dockable? */ private boolean canBeClosed; /** * Can this dockable be displayed on an auto-hide toolbar? */ private boolean allowAutoHide; /** * Is min/max an option for this dockable? */ private boolean allowMinMax; /** * Extra menu options to display on context menu */ private List<JMenu> moreOptions = new ArrayList<>(); /** * Listeners listening to docking changes for this dockable */ private final List<DockingListener> listeners = new ArrayList<>(); /** * Create a new instance */ public DefaultDockingPanel() { } /** * Create a new instance with the specific persistent ID and text * @param persistentID The persistent ID of the dockable * @param text The text to display on title bar and tabs */ public DefaultDockingPanel(String persistentID, String text) { this.persistentID = persistentID; this.tabText = text; } /** * Retrieve the persistent ID of the dockable * * @return Persistent ID */ @Override public String getPersistentID() { return persistentID; } /** * Set the persistent ID of the dockable * * @param persistentID New persistent ID */ public void setPersistentID(String persistentID) { this.persistentID = persistentID; } @Override public int getType() { return type; } /** * Set the type of the dockable * * @param type New type */ public void setType(int type) { this.type = type; } @Override public String getTabText() { return tabText; } /** * Set the tab text of the dockable * * @param tabText New tab text */ public void setTabText(String tabText) { this.tabText = tabText; } @Override public Icon getIcon() { return icon; } /** * Set the icon of this dockable * * @param icon The dockables icon to display on tabs and toolbars */ public void setIcon(Icon icon) { this.icon = icon; } @Override public boolean isFloatingAllowed() { return floatingAllowed; } /** * Set floating allowed flag * * @param isFloatingAllowed New flag value */ public void setFloatingAllowed(boolean isFloatingAllowed) { this.floatingAllowed = isFloatingAllowed; } @Override public boolean isLimitedToWindow() { return limitedToWindow; } /** * Set the limited to window flag * * @param limitToWindow New flag value */ public void setLimitedToWindow(boolean limitToWindow) { this.limitedToWindow = limitToWindow; } @Override public DockableStyle getStyle() { return style; } /** * Set the style of the dockable * * @param style New style */ public void setStyle(DockableStyle style) { this.style = style; } @Override public boolean isClosable() { return canBeClosed; } /** * Set the close button support for this dockable * * @param canBeClosed Can this dockable be closed? */ public void setClosable(boolean canBeClosed) { this.canBeClosed = canBeClosed; } @Override public boolean isAutoHideAllowed() { return allowAutoHide; } /** * Set the auto hide support on this dockable * * @param allowAutoHide Is auto hide allowed */ public void setAutoHideAllowed(boolean allowAutoHide) { this.allowAutoHide = allowAutoHide; } @Override public boolean isMinMaxAllowed() { return allowMinMax; } /** * Set the min/max support on this dockable * * @param allowMinMax Is min/max supported */ public void setMinMaxAllowed(boolean allowMinMax) { this.allowMinMax = allowMinMax; } @Override public boolean hasMoreMenuOptions() { return !moreOptions.isEmpty(); } /** * Set the additional options to be displayed on the menu * * @param options Additional menu options */ public void setMoreOptions(List<JMenu> options) { moreOptions = options; } @Override public void addMoreOptions(JPopupMenu menu) { for (JMenu option : moreOptions) { menu.add(option); } } /** * Add a new docking listener * * @param listener Listener to add */ public void addDockingListener(DockingListener listener) { listeners.add(listener); } /** * Remove a docking listener * * @param listener Listener to remove */ public void removeDockingListener(DockingListener listener) { listeners.remove(listener); } @Override public void dockingChange(DockingEvent e) { if (e.getDockable() == this) { listeners.forEach(listener -> listener.dockingChange(e)); } } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-api/src/io/github/andrewauclair/moderndocking/ui/DropdownUI.java
docking-api/src/io/github/andrewauclair/moderndocking/ui/DropdownUI.java
/* Copyright (c) 2022 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 io.github.andrewauclair.moderndocking.ui; import javax.swing.JButton; import javax.swing.plaf.basic.BasicComboBoxUI; // TODO This isn't used right now. I think I was trying to make a dropdown that could be used to swap panels instead of putting them in a tabbed pane. /** * An unused (yet) UI for custom dropdowns */ public class DropdownUI extends BasicComboBoxUI { /** * Unused */ public DropdownUI() { } /** * Unused * * @return Arrow button */ @Override protected JButton createArrowButton() { JButton button = super.createArrowButton(); button.setBackground(comboBox.getBackground()); return button; } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-api/src/io/github/andrewauclair/moderndocking/ui/DefaultHeaderUI.java
docking-api/src/io/github/andrewauclair/moderndocking/ui/DefaultHeaderUI.java
/* Copyright (c) 2022 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 io.github.andrewauclair.moderndocking.ui; import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.Objects; import javax.swing.BorderFactory; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JCheckBoxMenuItem; import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JMenu; import javax.swing.JMenuItem; import javax.swing.JPanel; import javax.swing.JPopupMenu; import javax.swing.SwingUtilities; import javax.swing.UIManager; import javax.swing.event.AncestorEvent; import javax.swing.event.AncestorListener; /** * This can be replaced by the user or with the docking-ui FlatLaf header UI */ public class DefaultHeaderUI extends JPanel implements DockingHeaderUI, AncestorListener { /** * Header controller which determines what menu options are enabled */ private final HeaderController headerController; /** * Header model which provides values to the UI */ private final HeaderModel headerModel; /** * Label that displays the name of the dockable */ protected final JLabel titleLabel = new JLabel(); /** * Settings button. Displays a popup menu when pressed */ protected final JButton settings = new JButton(); /** * Close button that shows an X and when pressed undocks the dockable */ protected final JButton close = new JButton(); /** * Label that is displayed when the dockable is maximized */ protected final JLabel maximizedIndicator = new JLabel("Maximized"); /** * Popup menu that is displayed when the settings button is pressed */ private final JPopupMenu settingsMenu = new JPopupMenu(); /** * Menu option to auto hide the dockable. Available when the dockable is auto hide enabled */ private final JCheckBoxMenuItem autoHide = new JCheckBoxMenuItem("Auto Hide"); /** * Option to move the dockable to its own window */ private final JMenuItem window = new JMenuItem("Window"); /** * Option to maximize the dockable */ private final JCheckBoxMenuItem maximizeOption = new JCheckBoxMenuItem("Maximize"); /** * Used to ensure that the header UI is only initialized once when added to its parent */ protected boolean initialized = false; /** * Override the background color of the header with a new color */ private Color backgroundOverride = null; /** * Override the foreground color of the header with a new color */ private Color foregroundOverride = null; /** * Create a new DefaultHeaderUI * * @param headerController Header controller to use for this UI * @param headerModel Header model to use for this UI */ public DefaultHeaderUI(HeaderController headerController, HeaderModel headerModel) { this.headerController = headerController; this.headerModel = headerModel; setOpaque(true); // delay the actual init of the UI in case the dockable object is partially constructed JComponent component = (JComponent) headerModel.dockable; component.addAncestorListener(this); } @Override public void displaySettingsMenu(JButton settings) { SwingUtilities.updateComponentTreeUI(settingsMenu); settingsMenu.show(settings, settings.getWidth(), settings.getHeight()); } /** * Initialize the header UI components */ protected void init() { if (initialized) { return; } initialized = true; try { settings.setIcon(new ImageIcon(Objects.requireNonNull(getClass().getResource("/api_icons/settings.png")))); close.setIcon(new ImageIcon(Objects.requireNonNull(getClass().getResource("/api_icons/close.png")))); } catch (Exception ignored) { } settings.addActionListener(e -> displaySettingsMenu(settings)); settings.addActionListener(e -> this.settingsMenu.show(settings, settings.getWidth(), settings.getHeight())); close.addActionListener(e -> headerController.close()); setupButton(settings); setupButton(close); configureColors(); setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 0; gbc.insets = new Insets(1, 6, 1, 2); JLabel iconLabel = new JLabel(headerModel.icon()); add(iconLabel, gbc); gbc.gridx++; gbc.insets = new Insets(0, 0, 0, 0); gbc.fill = GridBagConstraints.HORIZONTAL; gbc.weightx = 1.0; titleLabel.setText(headerModel.titleText()); titleLabel.setBorder(BorderFactory.createEmptyBorder(0, 6, 0, 0)); titleLabel.setFont(titleLabel.getFont().deriveFont(Font.BOLD)); titleLabel.setMinimumSize(new Dimension(0, 28)); titleLabel.setPreferredSize(new Dimension(0, 28)); add(titleLabel, gbc); gbc.gridx++; gbc.weightx = 0.2; maximizedIndicator.setVisible(false); maximizedIndicator.setFont(maximizedIndicator.getFont().deriveFont(Font.BOLD)); add(maximizedIndicator, gbc); gbc.gridx++; gbc.fill = GridBagConstraints.NONE; gbc.weightx = 0; if (headerModel.hasMoreOptions() || headerModel.isMaximizeAllowed() || headerModel.isAutoHideAllowed() || (headerModel.isFloatingAllowed() && !headerModel.isDockableAloneInWindow())) { addOptions(); add(settings, gbc); gbc.gridx++; } if (headerModel.isCloseAllowed()) { add(close, gbc); gbc.gridx++; } } /** * Configure the background and foreground colors of the header */ protected void configureColors() { Color color = DockingSettings.getHeaderBackground(); setBackground(color); setForeground(DockingSettings.getHeaderForeground()); setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, DockingSettings.getHighlighterNotSelectedBorder())); UIManager.addPropertyChangeListener(e -> { if ("lookAndFeel".equals(e.getPropertyName())) { Color bg = DockingSettings.getHeaderBackground(); SwingUtilities.invokeLater(() -> { setBackground(bg); setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, DockingSettings.getHighlighterNotSelectedBorder())); }); SwingUtilities.updateComponentTreeUI(settingsMenu); } else if (e.getPropertyName().equals("ModernDocking.titlebar.background")) { Color bg = DockingSettings.getHeaderBackground(); SwingUtilities.invokeLater(() -> setBackground(bg)); } }); } private void addOptions() { headerModel.addMoreOptions(settingsMenu); if (settingsMenu.getComponentCount() > 0) { settingsMenu.addSeparator(); } autoHide.addActionListener(e -> headerController.toggleAutoHide()); window.addActionListener(e -> headerController.newWindow()); JMenu viewMode = new JMenu("View Mode"); viewMode.add(autoHide); viewMode.add(window); settingsMenu.add(viewMode); settingsMenu.addSeparator(); settingsMenu.add(maximizeOption); maximizeOption.addActionListener(e -> { boolean maxed = headerModel.isMaximized(); maximizeOption.setSelected(!maxed); maximizedIndicator.setVisible(!maxed); if (maxed) { headerController.minimize(); } else { headerController.maximize(); } }); } private void setupButton(JButton button) { button.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); button.setFocusable(false); button.setOpaque(false); button.setContentAreaFilled(false); button.addMouseListener(new MouseAdapter() { @Override public void mouseEntered(MouseEvent e) { button.setContentAreaFilled(true); button.setOpaque(true); } @Override public void mouseExited(MouseEvent e) { button.setContentAreaFilled(false); button.setOpaque(false); } }); } @Override public void setBackgroundOverride(Color color) { backgroundOverride = color; } @Override public void setForegroundOverride(Color color) { foregroundOverride = color; } @Override public void setBackground(Color bg) { if (backgroundOverride != null) { bg = backgroundOverride; } super.setBackground(bg); if (close != null) close.setBackground(bg); if (settings != null) settings.setBackground(bg); } @Override public void setForeground(Color fg) { if (foregroundOverride != null) { fg = foregroundOverride; } super.setForeground(fg); if (titleLabel != null) titleLabel.setForeground(fg); if (close != null) close.setForeground(fg); if (settings != null) settings.setForeground(fg); } @Override public void update() { titleLabel.setText(headerModel.titleText()); maximizedIndicator.setVisible(headerModel.isMaximized()); maximizeOption.setSelected(headerModel.isMaximized()); maximizeOption.setEnabled(headerModel.isMaximizeAllowed()); autoHide.setEnabled(headerModel.isAutoHideAllowed()); autoHide.setSelected(headerModel.isAutoHideEnabled()); window.setEnabled(headerModel.isFloatingAllowed() && !headerModel.isDockableAloneInWindow()); } @Override public void ancestorAdded(AncestorEvent event) { init(); } @Override public void ancestorRemoved(AncestorEvent event) { } @Override public void ancestorMoved(AncestorEvent event) { } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-api/src/io/github/andrewauclair/moderndocking/ui/HeaderModel.java
docking-api/src/io/github/andrewauclair/moderndocking/ui/HeaderModel.java
/* Copyright (c) 2022 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 io.github.andrewauclair.moderndocking.ui; import io.github.andrewauclair.moderndocking.Dockable; import io.github.andrewauclair.moderndocking.api.DockingAPI; import io.github.andrewauclair.moderndocking.internal.DockingComponentUtils; import io.github.andrewauclair.moderndocking.internal.DockingInternal; import java.awt.Window; import javax.swing.Icon; import javax.swing.JPopupMenu; /** * Model for the header of a dockable. Provides wrapper access to functions in the dockable */ public class HeaderModel { /** * Dockable for this model */ public final Dockable dockable; private final DockingAPI docking; /** * Create a new model for the given dockable * * @param docking The docking instance this header belongs to * @param dockable Dockable for the model */ public HeaderModel(Dockable dockable, DockingAPI docking) { this.dockable = dockable; this.docking = docking; } /** * Get the title text of dockable * * @return Title text */ public String titleText() { return dockable.getTitleText(); } /** * Get the icon to display for the dockable * * @return Dockable icon */ public Icon icon() { return dockable.getIcon(); } /** * Check if auto-hide is allowed for this dockable * * @return Is auto-hide allowed? */ public boolean isAutoHideAllowed() { return dockable.isAutoHideAllowed(); } /** * Check if auto-hide is enabled for this dockable * * @return Is auto-hide enabled? */ public boolean isAutoHideEnabled() { return docking.isHidden(dockable); } /** * helper function to determine if the header min/max option should be enabled * * @return Is min/max allowed for this dockable */ public boolean isMaximizeAllowed() { return dockable.isMinMaxAllowed(); } /** * Check if the dockable is currently maximized * * @return Is dockable maximized? */ public boolean isMaximized() { return docking.isMaximized(dockable); } /** * Check if this dockable can be closed * * @return Are we allowed to close this dockable? */ public boolean isCloseAllowed() { return dockable.isClosable(); } /** * Check if there are more menu options to display * * @return True if there are more options to add to the context menu */ public boolean hasMoreOptions() { return dockable.hasMoreMenuOptions(); } /** * Check if floating is allowed for this dockable * * @return Are we allowed to float this dockable? */ public boolean isFloatingAllowed() { return dockable.isFloatingAllowed(); } /** * Check if the dockable is in a window by itself * * @return Are we alone in this window? */ public boolean isDockableAloneInWindow() { Window window = DockingComponentUtils.findWindowForDockable(docking, dockable); long dockables = DockingInternal.get(docking).getDockables().stream() .filter(otherDockable -> DockingInternal.get(docking).getWrapper(otherDockable).getWindow() == window) .count(); return dockables == 1; } /** * Add the extra options to the context menu * * @param menu Menu to add options to */ public void addMoreOptions(JPopupMenu menu) { dockable.addMoreOptions(menu); } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-api/src/io/github/andrewauclair/moderndocking/ui/ToolbarLocation.java
docking-api/src/io/github/andrewauclair/moderndocking/ui/ToolbarLocation.java
/* 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 io.github.andrewauclair.moderndocking.ui; /** * Location of the toolbar. Toolbars are supported to the West, South and East of a window */ public enum ToolbarLocation { /** * Toolbar is on the west of the root panel */ WEST, /** * Toolbar is on the south of the root panel */ SOUTH, /** * Toolbar is on the east of the root panel */ EAST }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-api/src/io/github/andrewauclair/moderndocking/ui/DockingHeaderUI.java
docking-api/src/io/github/andrewauclair/moderndocking/ui/DockingHeaderUI.java
/* Copyright (c) 2022 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 io.github.andrewauclair.moderndocking.ui; import java.awt.Color; import javax.swing.JButton; /** * Interface used for defining Docking header UIs that can be updated */ public interface DockingHeaderUI { /** * Update the UI */ void update(); /** * Display the settings menu * * @param settings Settings button to display menu at */ void displaySettingsMenu(JButton settings); /** * Set the background color override of the header UI * * @param color Background color. null to clear override */ void setBackgroundOverride(Color color); /** * Set the foreground color override of the header UI * * @param color Foreground color. null to clear override */ void setForegroundOverride(Color color); }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-api/src/io/github/andrewauclair/moderndocking/ui/DockingSettings.java
docking-api/src/io/github/andrewauclair/moderndocking/ui/DockingSettings.java
/* 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 io.github.andrewauclair.moderndocking.ui; import java.awt.Color; import javax.swing.UIManager; /** * Settings for theme related configuration items */ public class DockingSettings { /* * colors: * handle background * handle foreground * overlay background * active highlighter * header background * header foreground * * all of these colors should have default names that they pull from the look and feel when using flatlaf. defaults they use for system * look and feels. options to change the colors that it pulls from in flatlaf. Ability to change the default colors, the names used to * pull from FlatLaf and a separate set of ModernDocking specific properties that can be added to look and feel properties. * * other: * borders on titles * shape of docking handles * square corners vs rounded corners * size of docking handles * */ private static final String handleBackground = "ModernDocking.handleBackground"; private static final String handleForeground = "ModernDocking.handleForeground"; private static final String overlayBackground = "ModernDocking.overlayBackground"; private static final String highlighterSelectedBorder = "ModernDocking.highlighterSelectedBorder"; private static final String highlighterNotSelectedBorder = "ModernDocking.highlighterNotSelectedBorder"; private static final String headerBackground = "ModernDocking.headerBackground"; private static final String headerForeground = "ModernDocking.headerForeground"; private static final String themeHandleBackground = "TableHeader.background"; private static final String themeHandleForeground = "TableHeader.foreground"; private static final String themeHighlighterSelectedBorder = "Component.focusColor"; private static final String themeHighlighterNotSelectedBorder = "Component.borderColor"; private static final String themeHeaderBackground = "TableHeader.background"; private static final String themeHeaderForeground = "TableHeader.foreground"; private static final Color defaultHandleBackground = Color.white; private static final Color defaultHandleForeground = Color.black; private static final Color defaultHighlightColor = Color.BLUE; private static final Color overlayBackgroundOpaque = new Color(0x42c0ff); private static final Color defaultOverlayBackground = new Color(overlayBackgroundOpaque.getRed() / 255f, overlayBackgroundOpaque.getGreen() / 255f, overlayBackgroundOpaque.getBlue() / 255f, 85 / 255f); private static final Color defaultHeaderBackground = Color.white; private static final Color defaultHeaderForeground = Color.black; private static String currentHandleBackground = themeHandleBackground; private static String currentHandleForeground = themeHandleForeground; private static String currentHighlightSelectedBorder = themeHighlighterSelectedBorder; private static String currentHighlightNotSelectedBorder = themeHighlighterNotSelectedBorder; private static String currentOverlayBackground = overlayBackground; private static String currentHeaderBackground = themeHeaderBackground; private static String currentHeaderForeground = themeHeaderForeground; /** * Unused. All methods are static */ private DockingSettings() { } /** * Set a new property to use for the background color on Docking Handles * * @param property The new background property name */ public static void setHandleBackgroundProperty(String property) { currentHandleBackground = property; } /** * Get the current handle background color * * @return Handle background color */ public static Color getHandleBackground() { if (UIManager.get(handleBackground) != null) { return UIManager.getColor(handleBackground); } if (UIManager.get(currentHandleBackground) != null) { return UIManager.getColor(currentHandleBackground); } // TODO I wonder if we should attempt the theme property again here, assuming the user has changd the current property return defaultHandleBackground; } /** * Set a new property to use for the foreground color on Docking Handles * * @param property The new foreground property name */ public static void setHandleForegroundProperty(String property) { currentHandleForeground = property; } /** * Get the current handle foreground color * * @return Handle foreground color */ public static Color getHandleForeground() { if (UIManager.get(handleForeground) != null) { return UIManager.getColor(handleForeground); } if (UIManager.get(currentHandleForeground) != null) { return UIManager.getColor(currentHandleForeground); } return defaultHandleForeground; } /** * Set a new property to use for the background color of the floating overlay display * * @param property The new background color property */ public static void setOverlayBackgroundProperty(String property) { currentOverlayBackground = property; } /** * Get the overlay background color * * @return Overlay background color */ public static Color getOverlayBackground() { if (UIManager.get(currentOverlayBackground) != null) { return UIManager.getColor(currentOverlayBackground); } if (UIManager.get(overlayBackground) != null) { return UIManager.getColor(overlayBackground); } return defaultOverlayBackground; } /** * Set a new property to use for the border color used by the active dockable highlighter * * @param property The new selected border color property */ public static void setHighlighterSelectedBorderProperty(String property) { currentHighlightSelectedBorder = property; } /** * Get the selected border color for the active dockable highlighter * * @return Selected border color */ public static Color getHighlighterSelectedBorder() { if (UIManager.get(currentHighlightSelectedBorder) != null) { return UIManager.getColor(currentHighlightSelectedBorder); } if (UIManager.get(highlighterSelectedBorder) != null) { return UIManager.getColor(highlighterSelectedBorder); } return defaultHighlightColor; } /** * Define a color property to use when a panel is not highlighted by the active dockable highlighter * * @param property UIManager property name to use for not selected border color */ public static void setHighlighterNotSelectedBorderProperty(String property) { currentHighlightNotSelectedBorder = property; } /** * Get the not selected border color for the active dockable highlighter * * @return Highlighter not selected border color */ public static Color getHighlighterNotSelectedBorder() { if (UIManager.get(currentHighlightNotSelectedBorder) != null) { return UIManager.getColor(currentHighlightNotSelectedBorder); } if (UIManager.get(highlighterNotSelectedBorder) != null) { return UIManager.getColor(highlighterNotSelectedBorder); } return defaultHighlightColor; } /** * Set a new property to use for the default background color of docking headers * * @param property The new background color property */ public static void setHeaderBackgroundProperty(String property) { currentHeaderBackground = property; } /** * Get the header background color * * @return Current header background color */ public static Color getHeaderBackground() { if (UIManager.get(currentHeaderBackground) != null) { return UIManager.getColor(currentHeaderBackground); } if (UIManager.get(headerBackground) != null) { return UIManager.getColor(headerBackground); } return defaultHeaderBackground; } /** * Set a new property to use for the default foreground color of docking headers * * @param property The new foreground color property */ public static void setHeaderForegroundProperty(String property) { currentHeaderForeground = property; } /** * Get the header foreground color * * @return Current header foreground color */ public static Color getHeaderForeground() { if (UIManager.get(currentHeaderForeground) != null) { return UIManager.getColor(currentHeaderForeground); } if (UIManager.get(headerForeground) != null) { return UIManager.getColor(headerForeground); } return defaultHeaderForeground; } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-api/src/io/github/andrewauclair/moderndocking/ui/HeaderController.java
docking-api/src/io/github/andrewauclair/moderndocking/ui/HeaderController.java
/* Copyright (c) 2022 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 io.github.andrewauclair.moderndocking.ui; import io.github.andrewauclair.moderndocking.Dockable; import io.github.andrewauclair.moderndocking.api.DockingAPI; import io.github.andrewauclair.moderndocking.event.DockingEvent; import io.github.andrewauclair.moderndocking.event.DockingListener; import io.github.andrewauclair.moderndocking.event.MaximizeListener; import io.github.andrewauclair.moderndocking.internal.DockingListeners; /** * Controller for the header of dockables. Responsible for controlling the state of all buttons on the header. */ public class HeaderController implements MaximizeListener, DockingListener { /** * The dockable this header controller references */ private final Dockable dockable; /** * The docking instance the dockable belongs to */ private final DockingAPI docking; /** * The header model controlled */ private final HeaderModel model; /** * The header UI */ private DockingHeaderUI ui; /** * Create a new header controller for a dockable * * @param dockable The dockable this header controller uses * @param docking The docking instance the dockable belongs to * @param model The header model for the dockable */ public HeaderController(Dockable dockable, DockingAPI docking, HeaderModel model) { this.dockable = dockable; this.docking = docking; this.model = model; DockingListeners.addMaximizeListener(this); DockingListeners.addDockingListener(this); } /** * Change the header UI we're controlling * * @param ui New header UI */ public void setUI(DockingHeaderUI ui) { this.ui = ui; } /** * Remove the docking listeners that we've added */ public void removeListeners() { DockingListeners.removeMaximizeListener(this); DockingListeners.removeDockingListener(this); } /** * Flip the auto-hide flag */ public void toggleAutoHide() { if (model.isAutoHideEnabled()) { docking.autoShowDockable(dockable); } else { docking.autoHideDockable(dockable); } } /** * Launch the dockable in a new window */ public void newWindow() { docking.newWindow(dockable); } /** * Minimize the dockable */ public void minimize() { docking.minimize(dockable); } /** * Maximize the dockable */ public void maximize() { docking.maximize(dockable); } /** * Close the dockable */ public void close() { if (dockable.requestClose()) { docking.undock(dockable); } } @Override public void maximized(Dockable dockable, boolean maximized) { ui.update(); } @Override public void dockingChange(DockingEvent e) { ui.update(); } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/demo-single-app/src/basic/FloatingSample.java
demo-single-app/src/basic/FloatingSample.java
/* Copyright (c) 2022 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 basic; import io.github.andrewauclair.moderndocking.Dockable; import io.github.andrewauclair.moderndocking.DockingRegion; import io.github.andrewauclair.moderndocking.app.Docking; import io.github.andrewauclair.moderndocking.app.RootDockingPanel; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.Point; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.SwingUtilities; public class FloatingSample extends JFrame { private static class DockingPanel extends JPanel implements Dockable { private final String id; public DockingPanel(String id) { this.id = id; JButton floatPanel = new JButton("Float This Panel"); floatPanel.addActionListener(e -> { Point location = getLocationOnScreen(); location.x += 250; Docking.newWindow(this, location, new Dimension(150, 150)); }); add(floatPanel); } @Override public String getPersistentID() { return id; } @Override public int getType() { return 0; } @Override public String getTabText() { return id; } @Override public boolean isFloatingAllowed() { return true; } @Override public boolean isClosable() { return false; } }; public FloatingSample() { setSize(300, 200); Docking.initialize(this); RootDockingPanel root = new RootDockingPanel(this); add(root, BorderLayout.CENTER); DockingPanel alpha = new DockingPanel("Alpha"); DockingPanel bravo = new DockingPanel("Bravo"); Docking.registerDockable(alpha); Docking.registerDockable(bravo); Docking.dock(alpha, this); Docking.dock(bravo, alpha, DockingRegion.WEST); } public static void main(String[] args) { SwingUtilities.invokeLater(() -> new FloatingSample().setVisible(true)); } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/demo-single-app/src/basic/SimplePanel.java
demo-single-app/src/basic/SimplePanel.java
/* Copyright (c) 2022 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 basic; import io.github.andrewauclair.moderndocking.DockableStyle; import io.github.andrewauclair.moderndocking.DockingProperty; import io.github.andrewauclair.moderndocking.DynamicDockableParameters; import io.github.andrewauclair.moderndocking.ui.DockingHeaderUI; import io.github.andrewauclair.moderndocking.ui.HeaderController; import io.github.andrewauclair.moderndocking.ui.HeaderModel; import java.awt.Color; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.util.Objects; import java.util.Random; import javax.swing.JCheckBox; import javax.swing.JLabel; import javax.swing.JRadioButton; import javax.swing.JTextField; public class SimplePanel extends BasePanel { public static final String STRING_TEST_PROP = "test"; public static final String STRING_TEST1_PROP = "test1"; public static final String TEST_INT_1_PROP = "test_int_1"; private String titleText = ""; private String tabText = ""; public boolean limitToWindow = false; private Color backgroundColor = null; private Color foregroundColor = null; @DockingProperty(name = "test", defaultValue = "one") private String test; @DockingProperty(name = "test1", defaultValue = "two") private String test1; @DockingProperty(name = "test2", defaultValue = "three") private String test2; @DockingProperty(name = "test3", defaultValue = "four") private String test3; @DockingProperty(name = "test4", defaultValue = "five") private String test4; @DockingProperty(name = "test5", defaultValue = "six") private String test5; @DockingProperty(name = "test6", defaultValue = "seven") private String test6; @DockingProperty(name = "test7", defaultValue = "eight") private String test7; @DockingProperty(name = "test8", defaultValue = "nine") private String test8; @DockingProperty(name = "test9", defaultValue = "ten") private String test9; @DockingProperty(name = "test10", defaultValue = "eleven") private String test10; @DockingProperty(name = "test11", defaultValue = "twelve") private String test11; @DockingProperty(name = "test_int_1", defaultValue = "5") private int test_int_1; @DockingProperty(name = "test_int_2", defaultValue = "15") private int test_int_2; // @DockingProperty(name = "toolbar_location", defaultValue = "1") // private DockableToolbar.Location toolbarLocation; private final JLabel test_int_label = new JLabel(); private static final Random rand = new Random(); private DockingHeaderUI headerUI; private DockableStyle style; public SimplePanel(String tabText, String title, String persistentID, DockableStyle style) { this(tabText, title, persistentID); this.style = style; } public SimplePanel(String tabText, String title, String persistentID) { this(new DynamicDockableParameters(persistentID, tabText, title)); } public SimplePanel(DynamicDockableParameters parameters) { super(parameters.getTabText(), parameters.getTitleText(), parameters.getPersistentID()); titleText = parameters.getTitleText(); tabText = parameters.getTabText(); style = DockableStyle.BOTH; setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); add(test_int_label, gbc); gbc.gridy++; int numberOfControls = rand.nextInt(15); for (int i = 0; i < numberOfControls; i++) { int randControl = rand.nextInt(4); switch (randControl) { case 0: add(new JLabel("Label Here"), gbc); break; case 1: add(new JTextField(), gbc); break; case 2: add(new JCheckBox(), gbc); break; case 3: add(new JRadioButton(), gbc); break; } if (rand.nextBoolean()) { gbc.gridy++; } else { gbc.gridx++; } } } public void setTitleBackground(Color color) { this.backgroundColor = color; headerUI.setBackgroundOverride(backgroundColor); } public void setTitleForeground(Color color) { this.foregroundColor = color; headerUI.setForegroundOverride(foregroundColor); } @Override public DockingHeaderUI createHeaderUI(HeaderController headerController, HeaderModel headerModel) { headerUI = super.createHeaderUI(headerController, headerModel); headerUI.setBackgroundOverride(backgroundColor); headerUI.setForegroundOverride(foregroundColor); return headerUI; } @Override public int getType() { return 1; } @Override public boolean isMinMaxAllowed() { return true; } @Override public boolean isLimitedToWindow() { return limitToWindow; } @Override public DockableStyle getStyle() { return style; } @Override public String getTitleText() { if (titleText == null || titleText.isEmpty()) { return super.getTitleText(); } return titleText; } @Override public String getTabText() { if (tabText == null || tabText.isEmpty()) { return super.getTabText(); } return tabText; } @Override public String getTabTooltip() { return tabText; } public void setTabText(String tabText) { Objects.requireNonNull(tabText); this.tabText = tabText; } @Override public void updateProperties() { System.out.println("Set props for " + getPersistentID()); System.out.println(test); System.out.println(test1); System.out.println(test2); System.out.println(test3); System.out.println(test4); System.out.println(test5); System.out.println(test6); System.out.println(test7); System.out.println(test8); System.out.println(test9); System.out.println(test10); System.out.println(test11); System.out.println(test_int_1); test_int_label.setText(String.valueOf(test_int_1)); } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/demo-single-app/src/basic/Anchor.java
demo-single-app/src/basic/Anchor.java
/* Copyright (c) 2025 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 basic; import io.github.andrewauclair.moderndocking.Dockable; import io.github.andrewauclair.moderndocking.DockableStyle; import java.awt.Color; import javax.swing.BorderFactory; import javax.swing.JLabel; import javax.swing.JPanel; public class Anchor extends JPanel implements Dockable { public Anchor() { setBorder(BorderFactory.createLineBorder(Color.RED)); add(new JLabel("This is an anchor")); } @Override public String getPersistentID() { return "anchor"; } @Override public String getTabText() { return ""; } @Override public DockableStyle getStyle() { return DockableStyle.CENTER_ONLY; } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/demo-single-app/src/basic/BasePanel.java
demo-single-app/src/basic/BasePanel.java
/* Copyright (c) 2022 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 basic; import io.github.andrewauclair.moderndocking.Dockable; import io.github.andrewauclair.moderndocking.app.Docking; import java.awt.BorderLayout; import javax.swing.JPanel; public abstract class BasePanel extends JPanel implements Dockable { private final String tabText; private final String title; private final String persistentID; public BasePanel(String tabText, String title, String persistentID) { super(new BorderLayout()); this.tabText = tabText; this.title = title; this.persistentID = persistentID; JPanel panel = new JPanel(); add(panel, BorderLayout.CENTER); // the single call to register any docking panel extending this abstract class Docking.registerDockable(this); } @Override public String getPersistentID() { return persistentID; } @Override public String getTabText() { return tabText; } @Override public String getTitleText() { return title; } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/demo-single-app/src/basic/IncorrectDynamicDockable.java
demo-single-app/src/basic/IncorrectDynamicDockable.java
/* Copyright (c) 2024 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 basic; public class IncorrectDynamicDockable extends BasePanel { public IncorrectDynamicDockable() { super("Incorrect Dynamic Dockable", "Incorrect", "incorrect-dynamic-dockable"); } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/demo-single-app/src/basic/FixedSizePanel.java
demo-single-app/src/basic/FixedSizePanel.java
/* Copyright (c) 2024 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 basic; import io.github.andrewauclair.moderndocking.Dockable; import java.awt.Dimension; public class FixedSizePanel extends BasePanel implements Dockable { public FixedSizePanel() { super("Fixed Size", "Fixed Size", "fixed-size"); } @Override public Dimension getMinimumSize() { return new Dimension(300, 300); } @Override public boolean isWrappableInScrollpane() { return false; } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/demo-single-app/src/basic/DialogWithDocking.java
demo-single-app/src/basic/DialogWithDocking.java
/* 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 basic; import io.github.andrewauclair.moderndocking.DockableStyle; import io.github.andrewauclair.moderndocking.DockingRegion; import io.github.andrewauclair.moderndocking.api.RootDockingPanelAPI; import io.github.andrewauclair.moderndocking.app.Docking; import io.github.andrewauclair.moderndocking.app.RootDockingPanel; import javax.swing.JDialog; public class DialogWithDocking extends JDialog { private final RootDockingPanelAPI root; private final ToolPanel output; private final ToolPanel explorer; private final SimplePanel one; DialogWithDocking() { root = new RootDockingPanel(this); setModalityType(ModalityType.TOOLKIT_MODAL); add(root); output = new ToolPanel("output", "output-dialog", DockableStyle.HORIZONTAL); explorer = new ToolPanel("explorer", "explorer-dialog", DockableStyle.VERTICAL); one = new SimplePanel("The First Panel", "one", "one-dialog"); output.limitToWindow = true; explorer.limitToWindow = true; one.limitToWindow = true; Docking.dock(one, this); Docking.dock(explorer, one, DockingRegion.EAST); Docking.dock(output, this, DockingRegion.SOUTH); setSize(500, 500); pack(); setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); } @Override public void removeNotify() { Docking.deregisterDockingPanel(this); Docking.deregisterDockable(output); Docking.deregisterDockable(explorer); Docking.deregisterDockable(one); super.removeNotify(); } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/demo-single-app/src/basic/ScrollingWithToolbarPanel.java
demo-single-app/src/basic/ScrollingWithToolbarPanel.java
package basic; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JToolBar; public class ScrollingWithToolbarPanel extends BasePanel { public ScrollingWithToolbarPanel() { super("scrolling", "Scrolling With Toolbar", "scroll-with-toolbar"); setLayout(new GridBagLayout()); JToolBar toolBar = new JToolBar(); toolBar.add(new JButton("Add")); toolBar.add(new JButton("Remove")); JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 0; gbc.weightx = 1; gbc.weighty = 0; gbc.fill = GridBagConstraints.HORIZONTAL; for (int i = 0; i < 30; i++) { panel.add(new JLabel("label " + i), gbc); gbc.gridy++; } gbc.gridy = 0; add(toolBar, gbc); gbc.gridy++; gbc.weightx = 1; gbc.weighty = 1; gbc.fill = GridBagConstraints.BOTH; add(new JScrollPane(panel), gbc); } @Override public boolean isWrappableInScrollpane() { return false; } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/demo-single-app/src/basic/MainFrame.java
demo-single-app/src/basic/MainFrame.java
/* Copyright (c) 2022-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 basic; import com.formdev.flatlaf.FlatDarkLaf; import com.formdev.flatlaf.FlatLaf; import com.formdev.flatlaf.FlatLightLaf; import com.formdev.flatlaf.intellijthemes.FlatSolarizedDarkIJTheme; import com.formdev.flatlaf.intellijthemes.materialthemeuilite.FlatMTGitHubDarkIJTheme; import exception.FailOnThreadViolationRepaintManager; import io.github.andrewauclair.moderndocking.Dockable; import io.github.andrewauclair.moderndocking.DockableStyle; import io.github.andrewauclair.moderndocking.DockableTabPreference; import io.github.andrewauclair.moderndocking.DockingRegion; import io.github.andrewauclair.moderndocking.Property; import io.github.andrewauclair.moderndocking.api.RootDockingPanelAPI; import io.github.andrewauclair.moderndocking.api.WindowLayoutBuilderAPI; import io.github.andrewauclair.moderndocking.app.AppState; import io.github.andrewauclair.moderndocking.app.ApplicationLayoutMenuItem; import io.github.andrewauclair.moderndocking.app.DockableMenuItem; import io.github.andrewauclair.moderndocking.app.Docking; import io.github.andrewauclair.moderndocking.app.DockingState; import io.github.andrewauclair.moderndocking.app.LayoutPersistence; import io.github.andrewauclair.moderndocking.app.LayoutsMenu; import io.github.andrewauclair.moderndocking.app.RootDockingPanel; import io.github.andrewauclair.moderndocking.app.WindowLayoutBuilder; import io.github.andrewauclair.moderndocking.event.NewFloatingFrameListener; import io.github.andrewauclair.moderndocking.exception.DockingLayoutException; import io.github.andrewauclair.moderndocking.ext.ui.DockingUI; import io.github.andrewauclair.moderndocking.layouts.ApplicationLayout; import io.github.andrewauclair.moderndocking.layouts.DockingLayouts; import io.github.andrewauclair.moderndocking.layouts.DynamicDockableCreationListener; import io.github.andrewauclair.moderndocking.settings.Settings; import java.awt.Color; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import java.io.File; import java.util.Map; import java.util.Objects; import java.util.Random; import java.util.concurrent.Callable; import javax.swing.ImageIcon; import javax.swing.JCheckBoxMenuItem; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.SwingUtilities; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; import picocli.CommandLine; public class MainFrame extends JFrame implements Callable<Integer> { private final File layoutFile; @CommandLine.Option(names = "--laf", defaultValue = "light", description = "look and feel to use. one of: system, light, dark, github-dark or solarized-dark") String lookAndFeel; @CommandLine.Option(names = "--enable-edt-violation-detector", defaultValue = "false", description = "enable the Event Dispatch Thread (EDT) violation checker") boolean edtViolationDetector; @CommandLine.Option(names = "--ui-scale", defaultValue = "1", description = "scale to use for the FlatLaf.uiScale value") int uiScale; @CommandLine.Option(names = "--always-use-tabs", defaultValue = "false", description = "always use tabs, even when there is only 1 dockable in the tab group") boolean alwaysUseTabs; @CommandLine.Option(names = "--tab-location", defaultValue = "NONE", description = "Location to display tabs. values: ${COMPLETION-CANDIDATES}") DockableTabPreference tabLocation; @CommandLine.Option(names = "--create-docking-instance", defaultValue = "false", description = "create a separate instance of the framework for this MainFrame") boolean createDockingInstance; public MainFrame(File layoutFile) { this.layoutFile = layoutFile; setSize(800, 600); setTitle("Modern Docking Basic Demo"); if (alwaysUseTabs) { if (tabLocation == DockableTabPreference.TOP) { Settings.setDefaultTabPreference(DockableTabPreference.TOP_ALWAYS); } else { Settings.setDefaultTabPreference(DockableTabPreference.BOTTOM_ALWAYS); } } else { Settings.setDefaultTabPreference(tabLocation); } Settings.setActiveHighlighterEnabled(false); Docking.initialize(this); DockingUI.initialize(); Docking.addNewFloatingFrameListener(new NewFloatingFrameListener() { @Override public void newFrameCreated(JFrame frame, RootDockingPanelAPI root) { frame.setTitle("Testing New Floating Frame Listener"); } @Override public void newFrameCreated(JFrame frame, RootDockingPanelAPI root, Dockable dockable) { frame.setTitle("Testing New Floating Frame Listener"); } }); Docking.setUserDynamicDockableCreationListener(new DynamicDockableCreationListener() { @Override public Dockable createDockable(String persistentID, String className, String titleText, String tabText, Map<String, Property> properties) { SimplePanel test = new SimplePanel("this was custom", "user dynamic dockable creation", persistentID); return test; } }); JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); JMenu file = new JMenu("File"); menuBar.add(file); JCheckBoxMenuItem persistOn = new JCheckBoxMenuItem("Auto Persist Layout"); file.add(persistOn); persistOn.setSelected(true); persistOn.addActionListener(e -> AppState.setAutoPersist(persistOn.isSelected())); JMenuItem saveLayout = new JMenuItem("Save Layout to File..."); file.add(saveLayout); saveLayout.addActionListener(e -> { JFileChooser chooser = new JFileChooser(); int result = chooser.showSaveDialog(MainFrame.this); if (result == JFileChooser.APPROVE_OPTION) { File selectedFile = chooser.getSelectedFile(); ApplicationLayout layout = DockingState.getApplicationLayout(); try { LayoutPersistence.saveLayoutToFile(selectedFile, layout); } catch (DockingLayoutException ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(MainFrame.this, "Failed to save layout"); } } }); JMenuItem loadLayout = new JMenuItem("Load Layout from File..."); file.add(loadLayout); JMenuItem createPanel = new JMenuItem("Create Panel..."); createPanel.addActionListener(e -> { String panelName = JOptionPane.showInputDialog("Panel name"); SimplePanel panel = new SimplePanel(panelName, panelName, panelName); Docking.dock(panel, MainFrame.this, DockingRegion.EAST); }); file.add(createPanel); loadLayout.addActionListener(e -> { JFileChooser chooser = new JFileChooser(); int result = chooser.showOpenDialog(MainFrame.this); if (result == JFileChooser.APPROVE_OPTION) { File selectedFile = chooser.getSelectedFile(); ApplicationLayout layout = null; try { layout = LayoutPersistence.loadApplicationLayoutFromFile(selectedFile); } catch (DockingLayoutException ex) { ex.printStackTrace(); } if (layout != null) { DockingState.restoreApplicationLayout(layout); } } }); JMenu window = new JMenu("Window"); window.add(new LayoutsMenu()); menuBar.add(window); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); SimplePanel one = new SimplePanel("one", "Panel One", "one"); SimplePanel two = new SimplePanel("two", "Panel Two", "two"); SimplePanel three = new SimplePanel("three", "Panel Three", "three"); SimplePanel four = new SimplePanel("four", "Panel Four", "four"); SimplePanel five = new SimplePanel("five", "Panel Five", "five"); SimplePanel six = new SimplePanel("six", "Panel Six", "six"); SimplePanel seven = new SimplePanel("seven", "Panel Seven", "seven", DockableStyle.CENTER_ONLY); SimplePanel eight = new SimplePanel("eight", "Panel Eight", "eight"); ToolPanel explorer = new ToolPanel("Explorer", "explorer", DockableStyle.VERTICAL, new ImageIcon(Objects.requireNonNull(getClass().getResource("/icons/light/icons8-vga-16.png")))); ToolPanel output = new OutputPanel("Output", "output", DockableStyle.HORIZONTAL, new ImageIcon(Objects.requireNonNull(getClass().getResource("/icons/light/icons8-vga-16.png")))); AlwaysDisplayedPanel alwaysDisplayed = new AlwaysDisplayedPanel("always displayed", "always-displayed"); ScrollingWithToolbarPanel scrolling = new ScrollingWithToolbarPanel(); FixedSizePanel fixedSize = new FixedSizePanel(); PropertiesDemoPanel propertiesDemoPanel = new PropertiesDemoPanel(); ThemesPanel themes = new ThemesPanel(); one.setTitleBackground(new Color(0xa1f2ff)); two.setTitleBackground(new Color(0xdda1ff)); three.setTitleBackground(new Color(0xffaea1)); four.setTitleBackground(new Color(0xc3ffa1)); one.setTitleForeground(Color.black); two.setTitleForeground(Color.black); three.setTitleForeground(Color.black); four.setTitleForeground(Color.black); JMenuItem changeText = new JMenuItem("Change tab text"); changeText.addActionListener(e -> { String rand = generateString("abcdefg", 4); one.setTabText(rand); Docking.updateTabInfo("one"); }); JMenu view = new JMenu("View"); menuBar.add(view); JMenuItem bringtofront = new JMenuItem("Bring One to Front"); bringtofront.addActionListener(e -> { Docking.bringToFront("one"); }); view.add(bringtofront); JMenuItem createNewDockable = new JMenuItem("Generate Random Dockable"); createNewDockable.addActionListener(e -> { SimplePanel rand = new SimplePanel("rand", generateString("alpha", 6), generateString("abcdefg", 10)); Docking.dock(rand, one, DockingRegion.WEST); }); view.add(createNewDockable); JMenuItem createDynamicDockable = new JMenuItem("Create Dynamic Dockable"); createDynamicDockable.addActionListener(e -> { IncorrectDynamicDockable incorrect = new IncorrectDynamicDockable(); Docking.dock(incorrect, one, DockingRegion.CENTER); }); view.add(createDynamicDockable); view.add(actionListenDock(one)); JMenuItem oneToCenter = new JMenuItem("one (to center of window)"); oneToCenter.addActionListener(e -> Docking.dock("one", this)); view.add(oneToCenter); view.add(actionListenDock(two)); view.add(actionListenDock(three)); view.add(actionListenDock(four)); view.add(actionListenDock(five)); view.add(actionListenDock(six)); view.add(actionListenDock(seven)); view.add(actionListenDock(eight)); view.add(actionListenDock(explorer)); view.add(actionListenDock(output)); view.add(actionListenDock(fixedSize)); view.add(new DockableMenuItem("non-existent-dockable", "Does Not Exist")); view.add(actionListenDock(propertiesDemoPanel)); view.add(new DockableMenuItem(() -> ((Dockable) alwaysDisplayed).getPersistentID(), ((Dockable) alwaysDisplayed).getTabText())); view.add(changeText); view.add(actionListenDock(themes)); view.add(actionListenDock(scrolling)); Anchor anchor = new Anchor(); Docking.registerDockingAnchor(anchor); JMenuItem createAnchor = new JMenuItem("Create Anchor"); createAnchor.addActionListener(e -> { Docking.dock(anchor, one, DockingRegion.EAST); }); view.add(createAnchor); JMenuItem storeCurrentLayout = new JMenuItem("Store Current Layout..."); storeCurrentLayout.addActionListener(e -> { String layoutName = JOptionPane.showInputDialog("Name of Layout"); DockingLayouts.addLayout(layoutName, DockingState.getApplicationLayout()); }); window.add(storeCurrentLayout); JMenuItem restoreDefaultLayout = new ApplicationLayoutMenuItem("default", "Restore Default Layout"); window.add(restoreDefaultLayout); setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridy++; gbc.weightx = 1.0; gbc.weighty = 1.0; gbc.fill = GridBagConstraints.BOTH; RootDockingPanel dockingPanel = new RootDockingPanel(this); // dockingPanel.setPinningSupported(false); gbc.insets = new Insets(0, 5, 5, 5); add(dockingPanel, gbc); gbc.gridy++; gbc.weighty = 0; gbc.fill = GridBagConstraints.NONE; WindowLayoutBuilderAPI layoutBuilder = new WindowLayoutBuilder(alwaysDisplayed.getPersistentID()) .dock(one.getPersistentID(), alwaysDisplayed.getPersistentID()) .dock(two.getPersistentID(), one.getPersistentID(), DockingRegion.SOUTH) .dockToRoot(three.getPersistentID(), DockingRegion.WEST) .dock(four.getPersistentID(), two.getPersistentID(), DockingRegion.CENTER) .dock(propertiesDemoPanel.getPersistentID(), four.getPersistentID(), DockingRegion.CENTER) .dockToRoot(output.getPersistentID(), DockingRegion.SOUTH) .dockToRoot(themes.getPersistentID(), DockingRegion.EAST) .dock(explorer.getPersistentID(), themes.getPersistentID(), DockingRegion.CENTER) .display(themes.getPersistentID()); layoutBuilder.setProperty(one.getPersistentID(), SimplePanel.STRING_TEST_PROP, "value"); layoutBuilder.setProperty(one.getPersistentID(), SimplePanel.TEST_INT_1_PROP, 100); ApplicationLayout defaultLayout = layoutBuilder.buildApplicationLayout(); DockingLayouts.addLayout("default", defaultLayout); // AppState.setDefaultApplicationLayout(defaultLayout); } static Random rng = new Random(); public static String generateString(String characters, int length) { char[] text = new char[length]; for (int i = 0; i < length; i++) { text[i] = characters.charAt(rng.nextInt(characters.length())); } return new String(text); } private JMenuItem actionListenDock(Dockable dockable) { return new DockableMenuItem(dockable.getPersistentID(), dockable.getTabText()); } public static void main(String[] args) { SwingUtilities.invokeLater(() -> new CommandLine(new MainFrame(new File("basic_demo_layout.xml"))).execute(args)); } private void configureLookAndFeel() { try { FlatLaf.registerCustomDefaultsSource("docking"); System.setProperty("flatlaf.uiScale", String.valueOf(uiScale)); switch (lookAndFeel) { case "light": UIManager.setLookAndFeel(new FlatLightLaf()); break; case "dark": UIManager.setLookAndFeel(new FlatDarkLaf()); break; case "github-dark": UIManager.setLookAndFeel(new FlatMTGitHubDarkIJTheme()); break; case "solarized-dark": UIManager.setLookAndFeel(new FlatSolarizedDarkIJTheme()); break; default: try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) { throw new RuntimeException(ex); } break; } FlatLaf.updateUI(); } catch (Exception e) { e.printStackTrace(); try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) { throw new RuntimeException(ex); } } UIManager.getDefaults().put("TabbedPane.contentBorderInsets", new Insets(0, 0, 0, 0)); UIManager.getDefaults().put("TabbedPane.tabsOverlapBorder", true); if (edtViolationDetector) { // this is an app to test the docking framework, we want to make sure we detect EDT violations as soon as possible FailOnThreadViolationRepaintManager.install(); } } @Override public Integer call() { configureLookAndFeel(); // now that the main frame is set up with the defaults, we can restore the layout AppState.setPersistFile(layoutFile); try { AppState.restore(); } catch (DockingLayoutException e) { // something happened trying to load the layout file, record it here e.printStackTrace(); } AppState.setAutoPersist(true); SwingUtilities.invokeLater(() -> setVisible(true)); return 0; } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/demo-single-app/src/basic/ToolPanel.java
demo-single-app/src/basic/ToolPanel.java
/* Copyright (c) 2022 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 basic; import io.github.andrewauclair.moderndocking.DockableStyle; import javax.swing.Icon; import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JPopupMenu; public class ToolPanel extends BasePanel { private final DockableStyle style; private final Icon icon; public boolean limitToWindow = false; public ToolPanel(String title, String persistentID, DockableStyle style) { super(title, title, persistentID); this.style = style; this.icon = null; } public ToolPanel(String title, String persistentID, DockableStyle style, Icon icon) { super(title, title, persistentID); this.style = style; this.icon = icon; } @Override public int getType() { return 0; } @Override public Icon getIcon() { return icon; } @Override public boolean isFloatingAllowed() { return false; } @Override public boolean isLimitedToWindow() { return limitToWindow; } @Override public DockableStyle getStyle() { return style; } @Override public DockableStyle getAutoHideStyle() { return style; } @Override public boolean isClosable() { return true; } @Override public boolean requestClose() { return JOptionPane.showConfirmDialog(null, "Are you sure you want to close this panel?", "Close Panel", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION; } @Override public boolean isAutoHideAllowed() { return true; } @Override public boolean isMinMaxAllowed() { return false; } @Override public boolean hasMoreMenuOptions() { return true; } @Override public void addMoreOptions(JPopupMenu menu) { menu.add(new JMenuItem("Something")); menu.add(new JMenuItem("Else")); } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/demo-single-app/src/basic/AlwaysDisplayedPanel.java
demo-single-app/src/basic/AlwaysDisplayedPanel.java
/* Copyright (c) 2022 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 basic; import io.github.andrewauclair.moderndocking.DockableTabPreference; // 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 public AlwaysDisplayedPanel(String title, String persistentID) { super(title, title, persistentID); } @Override public boolean isClosable() { return false; } @Override public boolean isFloatingAllowed() { return false; } @Override public boolean isLimitedToWindow() { return true; } @Override public DockableTabPreference getTabPreference() { return DockableTabPreference.TOP; } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/demo-single-app/src/basic/ThemesPanel.java
demo-single-app/src/basic/ThemesPanel.java
/* 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 basic; import com.formdev.flatlaf.FlatDarkLaf; import com.formdev.flatlaf.FlatLaf; import com.formdev.flatlaf.FlatLightLaf; import com.formdev.flatlaf.intellijthemes.FlatSolarizedDarkIJTheme; import com.formdev.flatlaf.intellijthemes.materialthemeuilite.FlatMTGitHubDarkIJTheme; import io.github.andrewauclair.moderndocking.Dockable; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import javax.swing.BorderFactory; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.ListSelectionModel; import javax.swing.SwingUtilities; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; import javax.swing.table.DefaultTableModel; public class ThemesPanel extends BasePanel implements Dockable { public ThemesPanel() { super("Themes", "Themes", "themes"); JTable table = new JTable() { @Override public boolean isCellEditable(int row, int column) { return false; } }; table.setTableHeader(null); //table.setBorder(BorderFactory.createEmptyBorder()); DefaultTableModel model = new DefaultTableModel(0, 1); model.addRow(new Object[] { "FlatLaf Light"}); model.addRow(new Object[] { "FlatLaf Dark"}); model.addRow(new Object[] { "Github Dark"}); model.addRow(new Object[] { "Solarized Dark"}); table.setModel(model); setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 0; gbc.weightx = 1; gbc.weighty = 1; gbc.fill = GridBagConstraints.BOTH; JScrollPane comp = new JScrollPane(table); comp.setBorder(BorderFactory.createEmptyBorder()); add(comp, gbc); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.getSelectionModel().addListSelectionListener(e -> { if (table.getSelectedRow() == -1) { return; } String lookAndFeel = (String) model.getValueAt(table.getSelectedRow(), 0); SwingUtilities.invokeLater(() -> { try { switch (lookAndFeel) { case "FlatLaf Light": UIManager.setLookAndFeel(new FlatLightLaf()); break; case "FlatLaf Dark": UIManager.setLookAndFeel(new FlatDarkLaf()); break; case "Github Dark": UIManager.setLookAndFeel(new FlatMTGitHubDarkIJTheme()); break; case "Solarized Dark": UIManager.setLookAndFeel(new FlatSolarizedDarkIJTheme()); break; } FlatLaf.updateUI(); } catch (UnsupportedLookAndFeelException ex) { throw new RuntimeException(ex); } }); }); } @Override public int getType() { return 1; } @Override public boolean isFloatingAllowed() { return false; } @Override public boolean isClosable() { return false; } @Override public boolean isWrappableInScrollpane() { return false; } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/demo-single-app/src/basic/Example.java
demo-single-app/src/basic/Example.java
/* Copyright (c) 2022-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 basic; import io.github.andrewauclair.moderndocking.Dockable; import io.github.andrewauclair.moderndocking.DockableStyle; import io.github.andrewauclair.moderndocking.DockingRegion; import io.github.andrewauclair.moderndocking.app.AppState; import io.github.andrewauclair.moderndocking.app.Docking; import io.github.andrewauclair.moderndocking.app.RootDockingPanel; import io.github.andrewauclair.moderndocking.exception.DockingLayoutException; import java.awt.BorderLayout; import java.io.File; import javax.swing.Icon; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.SwingUtilities; public class Example extends JFrame { public Example() { // common Java Swing setup setTitle("Basic Modern Docking basic.Example"); setSize(300, 300); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // create the single Docking instance for the life of the program Docking.initialize(this); // set the auto persist file // auto persist is off by default and we will leave it that way until we're done configuring the default layout // that way we're not persisting the default layout and overwriting the file before we load the file AppState.setPersistFile(new File("example_layout.xml")); // restore the layout from the auto persist file after the UI has loaded SwingUtilities.invokeLater(() -> { try { AppState.restore(); } catch (DockingLayoutException e) { e.printStackTrace(); } // now that we've restored the layout we can turn on auto persist AppState.setAutoPersist(true); }); Panel panel1 = new Panel("one"); Panel panel2 = new Panel("two"); Panel panel3 = new Panel("three"); Panel panel4 = new Panel("four"); // create the root panel and add it to the frame RootDockingPanel rootPanel = new RootDockingPanel(this); add(rootPanel, BorderLayout.CENTER); // dock our first panel into the center of the frame Docking.dock(panel1, this); // dock the second panel to the center of the first panel Docking.dock(panel2, panel1, DockingRegion.CENTER); // dock the third panel to the east of the second panel Docking.dock(panel3, panel2, DockingRegion.EAST); // dock the fourth panel to the frame south Docking.dock(panel4, this, DockingRegion.SOUTH); } public static void main(String[] args) { SwingUtilities.invokeLater(() -> { Example example = new Example(); example.setVisible(true); }); } // all dockables must be at least Component public static class Panel extends JPanel implements Dockable { private final String name; public Panel(String name) { this.name = name; // register the dockable with the Docking framework in order to use it Docking.registerDockable(this); } @Override public String getPersistentID() { return name; } @Override public int getType() { return 0; } @Override public String getTabText() { return name; } @Override public Icon getIcon() { return null; } @Override public boolean isFloatingAllowed() { return false; } @Override public boolean isLimitedToWindow() { return false; } @Override public DockableStyle getStyle() { return DockableStyle.BOTH; } @Override public boolean isClosable() { return false; } @Override public boolean isAutoHideAllowed() { return false; } @Override public boolean isMinMaxAllowed() { return false; } } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/demo-single-app/src/basic/OutputPanel.java
demo-single-app/src/basic/OutputPanel.java
package basic; import io.github.andrewauclair.moderndocking.DockableStyle; import io.github.andrewauclair.moderndocking.DockingProperty; import io.github.andrewauclair.moderndocking.app.AppState; import java.util.Enumeration; import java.util.HashMap; import java.util.Map; import javax.swing.BorderFactory; import javax.swing.Icon; import javax.swing.JMenuItem; import javax.swing.JPopupMenu; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.event.ChangeEvent; import javax.swing.event.ListSelectionEvent; import javax.swing.event.TableColumnModelEvent; import javax.swing.event.TableColumnModelListener; import javax.swing.table.DefaultTableModel; import javax.swing.table.TableColumn; public class OutputPanel extends ToolPanel { @DockingProperty(name = "first-column-name", defaultValue = "one") private String firstColumnName; private final JTable table = new JTable(new DefaultTableModel(new String[] { "one", "two"}, 0)); private final Map<String, String> properties = new HashMap<>(); public OutputPanel(String title, String persistentID, DockableStyle style, Icon icon) { super(title, persistentID, style, icon); table.setBorder(BorderFactory.createEmptyBorder()); JScrollPane comp = new JScrollPane(table); comp.setBorder(BorderFactory.createEmptyBorder()); add(comp); updateColumnsProp(); updateColumnSizesProp(); table.getColumnModel().addColumnModelListener(new TableColumnModelListener() { @Override public void columnAdded(TableColumnModelEvent e) { } @Override public void columnRemoved(TableColumnModelEvent e) { } @Override public void columnMoved(TableColumnModelEvent e) { updateColumnsProp(); AppState.persist(); } @Override public void columnMarginChanged(ChangeEvent e) { updateColumnSizesProp(); AppState.persist(); } @Override public void columnSelectionChanged(ListSelectionEvent e) { } }); } private void updateColumnsProp() { Enumeration<TableColumn> columns = table.getColumnModel().getColumns(); StringBuilder prop = new StringBuilder(); while (columns.hasMoreElements()) { prop.append(columns.nextElement().getHeaderValue().toString()); prop.append(","); } properties.put("columns", prop.toString()); } private void updateColumnSizesProp() { Enumeration<TableColumn> columns = table.getColumnModel().getColumns(); StringBuilder prop = new StringBuilder(); while (columns.hasMoreElements()) { prop.append(columns.nextElement().getWidth()); prop.append(","); } properties.put("column-sizes", prop.toString()); } @Override public void addMoreOptions(JPopupMenu menu) { JMenuItem rename = new JMenuItem("Rename"); rename.addActionListener(e -> { firstColumnName = "changed"; table.getColumnModel().getColumn(0).setHeaderValue(firstColumnName); }); menu.add(rename); } @Override public void updateProperties() { // properties have now been loaded, use them table.getColumnModel().getColumn(0).setHeaderValue(firstColumnName); } @Override public boolean isWrappableInScrollpane() { return false; } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/demo-single-app/src/basic/PropertiesDemoPanel.java
demo-single-app/src/basic/PropertiesDemoPanel.java
/* 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 basic; import io.github.andrewauclair.moderndocking.DockingProperty; import io.github.andrewauclair.moderndocking.DockingRegion; import io.github.andrewauclair.moderndocking.app.AppState; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.util.ArrayList; import java.util.Collections; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JLabel; import javax.swing.JTextField; import javax.swing.text.AttributeSet; import javax.swing.text.BadLocationException; import javax.swing.text.Document; import javax.swing.text.DocumentFilter; import javax.swing.text.PlainDocument; public class PropertiesDemoPanel extends BasePanel { @DockingProperty(name = "sample_byte", defaultValue = "0") private byte byteValue; @DockingProperty(name = "sample_short", defaultValue = "0") private short shortValue; @DockingProperty(name = "sample_int", defaultValue = "0") private int intValue; @DockingProperty(name = "sample_long", defaultValue = "0") private long longValue; @DockingProperty(name = "sample_float") private float floatValue; @DockingProperty(name = "sample_double") private double doubleValue; @DockingProperty(name = "sample_char", defaultValue = "a") private char charValue; @DockingProperty(name = "sample_boolean", defaultValue = "false") private boolean booleanValue; @DockingProperty(name = "sample_string") private String stringValue; @DockingProperty(name = "list_ints") private ArrayList<Integer> ints = new ArrayList<>(); // @DockingProperty(name = "sample_enum", defaultValue = "0") // private DockingRegion dockingRegion; private final JTextField byteField = new JTextField(); private final JTextField shortField = new JTextField(); private final JTextField intField = new JTextField(); private final JTextField longField = new JTextField(); private final JTextField floatField = new JTextField(); private final JTextField doubleField = new JTextField(); private final JTextField charField = new JTextField(); private final JTextField booleanField = new JTextField(); private final JTextField stringField = new JTextField(); private final JComboBox<DockingRegion> enumField = new JComboBox<>(); public PropertiesDemoPanel() { super("props", "Properties Demo", "props-demo"); PlainDocument doc = (PlainDocument) byteField.getDocument(); doc.setDocumentFilter(new MyIntFilter()); setLayout(new GridBagLayout()); removeAll(); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 0; add(new JLabel("Byte:"), gbc); gbc.gridx++; add(byteField, gbc); gbc.gridx = 0; gbc.gridy++; add(new JLabel("Short:"), gbc); gbc.gridx++; add(shortField, gbc); gbc.gridx = 0; gbc.gridy++; add(new JLabel("Integer:"), gbc); gbc.gridx++; add(intField, gbc); gbc.gridx = 0; gbc.gridy++; add(new JLabel("Long:"), gbc); gbc.gridx++; add(longField, gbc); gbc.gridx = 0; gbc.gridy++; add(new JLabel("Float:"), gbc); gbc.gridx++; add(floatField, gbc); gbc.gridx = 0; gbc.gridy++; add(new JLabel("Double:"), gbc); gbc.gridx++; add(doubleField, gbc); gbc.gridx = 0; gbc.gridy++; add(new JLabel("Char:"), gbc); gbc.gridx++; add(charField, gbc); gbc.gridx = 0; gbc.gridy++; add(new JLabel("Boolean:"), gbc); gbc.gridx++; add(booleanField, gbc); gbc.gridx = 0; gbc.gridy++; add(new JLabel("String:"), gbc); gbc.gridx++; add(stringField, gbc); gbc.gridx = 0; gbc.gridy++; JButton save = new JButton("Save"); add(save); save.addActionListener(e -> { AppState.setProperty(this, "static-prop-test", "5"); byteValue = Byte.parseByte(byteField.getText()); shortValue = Short.parseShort(shortField.getText()); intValue = Integer.parseInt(intField.getText()); longValue = Long.parseLong(longField.getText()); floatValue = Float.parseFloat(floatField.getText()); doubleValue = Double.parseDouble(doubleField.getText()); charValue = charField.getText().length() > 0 ? charField.getText().charAt(0) : ' '; booleanValue = Boolean.parseBoolean(booleanField.getText()); stringValue = stringField.getText(); ints.add(1); ints.add(2); ints.add(3); AppState.persist(); }); } @Override public void updateProperties() { System.out.println("static-prop-test: " + AppState.getProperty(this, "static-prop-test")); byteField.setText(Byte.toString(byteValue)); shortField.setText(Short.toString(shortValue)); intField.setText(Integer.toString(intValue)); longField.setText(Long.toString(longValue)); floatField.setText(Float.toString(floatValue)); doubleField.setText(Double.toString(doubleValue)); charField.setText(String.valueOf(charValue)); booleanField.setText(Boolean.toString(booleanValue)); stringField.setText(stringValue); ints.stream().forEach(integer -> System.out.println("integer = " + integer)); } static class MyIntFilter extends DocumentFilter { @Override public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException { Document doc = fb.getDocument(); StringBuilder sb = new StringBuilder(); sb.append(doc.getText(0, doc.getLength())); sb.insert(offset, string); if (test(sb.toString())) { super.insertString(fb, offset, string, attr); } else { // warn the user and don't allow the insert } } private boolean test(String text) { try { Integer.parseInt(text); return true; } catch (NumberFormatException e) { return false; } } @Override public void replace(FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException { Document doc = fb.getDocument(); StringBuilder sb = new StringBuilder(); sb.append(doc.getText(0, doc.getLength())); sb.replace(offset, offset + length, text); if (test(sb.toString())) { super.replace(fb, offset, length, text, attrs); } else { // warn the user and don't allow the insert } } @Override public void remove(FilterBypass fb, int offset, int length) throws BadLocationException { Document doc = fb.getDocument(); StringBuilder sb = new StringBuilder(); sb.append(doc.getText(0, doc.getLength())); sb.delete(offset, offset + length); if (test(sb.toString())) { super.remove(fb, offset, length); } else { // warn the user and don't allow the insert } } } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/demo-single-app/src/tests/WindowLayoutBuilderTests.java
demo-single-app/src/tests/WindowLayoutBuilderTests.java
/* 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 tests; import basic.SimplePanel; import com.formdev.flatlaf.FlatDarkLaf; import com.formdev.flatlaf.FlatLaf; import com.formdev.flatlaf.FlatLightLaf; import exception.FailOnThreadViolationRepaintManager; import io.github.andrewauclair.moderndocking.DockingRegion; import io.github.andrewauclair.moderndocking.app.ApplicationLayoutMenuItem; import io.github.andrewauclair.moderndocking.app.Docking; import io.github.andrewauclair.moderndocking.app.RootDockingPanel; import io.github.andrewauclair.moderndocking.app.WindowLayoutBuilder; import io.github.andrewauclair.moderndocking.event.DockingLayoutEvent; import io.github.andrewauclair.moderndocking.event.DockingLayoutListener; import io.github.andrewauclair.moderndocking.layouts.DockingLayouts; import java.awt.Insets; import java.util.ArrayList; import java.util.List; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.SwingUtilities; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; public class WindowLayoutBuilderTests extends JFrame implements DockingLayoutListener { private final JMenu layout; WindowLayoutBuilderTests() { setTitle("DockingLayoutBuilder Tests"); setSize(500, 500); Docking.initialize(this); List<SimplePanel> panels = new ArrayList<>(); for (int i = 1; i <= 16; i++) { panels.add(new SimplePanel(String.valueOf(i), String.valueOf(i), String.valueOf(i))); } JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); layout = new JMenu("Layout"); menuBar.add(layout); DockingLayouts.addLayoutsListener(this); buildLayouts(); add(new RootDockingPanel(this)); } private void buildLayouts() { DockingLayouts.addLayout("simple (1)", new WindowLayoutBuilder("1") .buildApplicationLayout()); DockingLayouts.addLayout("tabs (1, 2)", new WindowLayoutBuilder("1") .dock("2", "1") .display("1") .buildApplicationLayout()); DockingLayouts.addLayout("split( west (2), east (1) )", new WindowLayoutBuilder("1") .dock("2", "1", DockingRegion.WEST) .buildApplicationLayout()); DockingLayouts.addLayout("split( north (1), south (2) )", new WindowLayoutBuilder("1") .dock("2", "1", DockingRegion.SOUTH) .buildApplicationLayout()); DockingLayouts.addLayout("split( west (1), east (2) )", new WindowLayoutBuilder("1") .dock("2", "1", DockingRegion.EAST) .buildApplicationLayout()); DockingLayouts.addLayout("split( north (2), south (1) )", new WindowLayoutBuilder("1") .dock("2", "1", DockingRegion.NORTH) .buildApplicationLayout()); DockingLayouts.addLayout("split( west (2) east (1) south (3) )", new WindowLayoutBuilder("1") .dock("2", "1", DockingRegion.WEST) .dockToRoot("3", DockingRegion.SOUTH) .buildApplicationLayout()); DockingLayouts.addLayout("split( west( simple (2) ), east( split( north (1), south (3) ) ) )", new WindowLayoutBuilder("1") .dock("2", "1", DockingRegion.WEST) .dock("3", "1", DockingRegion.SOUTH) .buildApplicationLayout()); DockingLayouts.addLayout("split( west( tabs (1, 2) ), east( split( north (3), south ( split( west (4), east (5) ) ) ) ) )", new WindowLayoutBuilder("1") .dock("2", "1") .dock("3", "2", DockingRegion.EAST) .dock("4", "3", DockingRegion.SOUTH) .dock("5", "4", DockingRegion.EAST) .buildApplicationLayout()); DockingLayouts.addLayout("split( west (1, .25), east (2) )", new WindowLayoutBuilder("2") .dock("1", "2", DockingRegion.WEST, .25) .buildApplicationLayout()); DockingLayouts.addLayout("split( west (1), east (2, .25) )", new WindowLayoutBuilder("1") .dock("2", "1", DockingRegion.EAST, .25) .buildApplicationLayout()); DockingLayouts.addLayout("split( north (1, .25), south (2) )", new WindowLayoutBuilder("2") .dock("1", "2", DockingRegion.NORTH, .25) .buildApplicationLayout()); DockingLayouts.addLayout("split( north (1), south (2, .25) )", new WindowLayoutBuilder("1") .dock("2", "1", DockingRegion.SOUTH, .25) .buildApplicationLayout()); DockingLayouts.addLayout("split( west (1, .25), east ( tab( 2, 3 ) ) )", new WindowLayoutBuilder("2") .dock("3", "2") .dock("1", "2", DockingRegion.WEST, .25) .buildApplicationLayout()); DockingLayouts.addLayout("split( west ( tabs( 1, 3 ) ), east (2, .25) )", new WindowLayoutBuilder("1") .dock("3", "1") .dock("2", "1", DockingRegion.EAST, .25) .buildApplicationLayout()); DockingLayouts.addLayout("split( north (1, .25), south ( tabs( 2, 3 ) ) )", new WindowLayoutBuilder("2") .dock("3", "2") .dock("1", "2", DockingRegion.NORTH, .25) .buildApplicationLayout()); DockingLayouts.addLayout("split( north ( tabs( 1, 3 ) ), south (2, .25) )", new WindowLayoutBuilder("1") .dock("3", "1") .dock("2", "1", DockingRegion.SOUTH, .25) .buildApplicationLayout()); DockingLayouts.addLayout("dock to root east/west", new WindowLayoutBuilder("1") .dockToRoot("2", DockingRegion.EAST) .dockToRoot("3", DockingRegion.WEST) .buildApplicationLayout()); DockingLayouts.addLayout("dock to root north/south", new WindowLayoutBuilder("1") .dockToRoot("2", DockingRegion.NORTH) .dockToRoot("3", DockingRegion.SOUTH) .buildApplicationLayout()); } public static void main(String[] args) { SwingUtilities.invokeLater(() -> { configureLookAndFeel(args); WindowLayoutBuilderTests mainFrame = new WindowLayoutBuilderTests(); mainFrame.setVisible(true); }); } private static void configureLookAndFeel(String[] args) { try { FlatLaf.registerCustomDefaultsSource("docking"); if (args.length > 1) { System.setProperty("flatlaf.uiScale", args[1]); } if (args.length > 0 && args[0].equals("light")) { UIManager.setLookAndFeel(new FlatLightLaf()); } else if (args.length > 0 && args[0].equals("dark")) { UIManager.setLookAndFeel(new FlatDarkLaf()); } else { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) { throw new RuntimeException(ex); } } FlatLaf.updateUI(); } catch (Exception e) { e.printStackTrace(); try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) { throw new RuntimeException(ex); } } UIManager.getDefaults().put("TabbedPane.contentBorderInsets", new Insets(0, 0, 0, 0)); UIManager.getDefaults().put("TabbedPane.tabsOverlapBorder", true); // this is an app to test the docking framework, we want to make sure we detect EDT violations as soon as possible FailOnThreadViolationRepaintManager.install(); } @Override public void layoutChange(DockingLayoutEvent e) { switch (e.getID()) { case ADDED: layout.add(new ApplicationLayoutMenuItem(e.getLayoutName())); break; case REMOVED: for (int i = 0; i < layout.getItemCount(); i++) { if (layout.getItem(i).getName().equals(e.getLayoutName())) { layout.remove(i); break; } } break; } } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/demo-single-app/src/tests/TranslucentTest.java
demo-single-app/src/tests/TranslucentTest.java
/* 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 tests; import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; import javax.swing.JFrame; import javax.swing.SwingUtilities; import static java.awt.GraphicsDevice.WindowTranslucency.PERPIXEL_TRANSLUCENT; import static java.awt.GraphicsDevice.WindowTranslucency.PERPIXEL_TRANSPARENT; import static java.awt.GraphicsDevice.WindowTranslucency.TRANSLUCENT; public class TranslucentTest extends JFrame { public TranslucentTest() { // Determine what the default GraphicsDevice can support. GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gd = ge.getDefaultScreenDevice(); System.out.println("Is uniform translucency supported: " + gd.isWindowTranslucencySupported(TRANSLUCENT)); System.out.println("Is per-pixel translucency supported: " + gd.isWindowTranslucencySupported(PERPIXEL_TRANSLUCENT)); System.out.println("Is shaped window supported: " + gd.isWindowTranslucencySupported(PERPIXEL_TRANSPARENT)); } public static void main(String[] args) { SwingUtilities.invokeLater(() -> new TranslucentTest().setVisible(true)); } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/demo-single-app/src/tests/DeregisterTests.java
demo-single-app/src/tests/DeregisterTests.java
/* 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 tests; import io.github.andrewauclair.moderndocking.DockingRegion; import io.github.andrewauclair.moderndocking.app.Docking; import io.github.andrewauclair.moderndocking.app.RootDockingPanel; import io.github.andrewauclair.moderndocking.ext.ui.DockingUI; import io.github.andrewauclair.moderndocking.ui.DefaultDockingPanel; import java.awt.BorderLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.SwingUtilities; public class DeregisterTests extends JFrame { public DeregisterTests() { setSize(300, 200); Docking.initialize(this); DockingUI.initialize(); RootDockingPanel root = new RootDockingPanel(this); add(root, BorderLayout.CENTER); DefaultDockingPanel one = new DefaultDockingPanel("one", "One"); DefaultDockingPanel two = new DefaultDockingPanel("two", "Two"); Docking.registerDockable(one); Docking.registerDockable(two); JButton openOneInNewWindow = new JButton("Open in new window"); openOneInNewWindow.addActionListener(e -> Docking.newWindow("one")); one.add(openOneInNewWindow); JButton openTwoInNewWindow = new JButton("Open in new window"); openTwoInNewWindow.addActionListener(e -> Docking.newWindow(two)); two.add(openTwoInNewWindow); Docking.dock(one, this); Docking.dock(two, one, DockingRegion.WEST); JMenuItem deregisterOne = new JMenuItem("Deregister One"); deregisterOne.addActionListener(e -> Docking.deregisterDockable(one)); JMenuItem deregisterDockables = new JMenuItem("Deregister All Dockables"); deregisterDockables.addActionListener(e -> Docking.deregisterAllDockables()); JMenuItem registerOne = new JMenuItem("Register One"); registerOne.addActionListener(e -> { Docking.registerDockable(one); if (Docking.isDocked(two)) { Docking.dock(one, two, DockingRegion.EAST); } else { Docking.dock(one, this); } }); JMenuItem registerDockables = new JMenuItem("Register Dockables"); registerDockables.addActionListener(e -> { Docking.registerDockable(one); Docking.registerDockable(two); Docking.dock(one, this); Docking.dock(two, one, DockingRegion.WEST); }); JMenu testing = new JMenu("Testing"); testing.add(deregisterOne); testing.add(deregisterDockables); testing.add(registerOne); testing.add(registerDockables); JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); menuBar.add(testing); } public static void main(String[] args) { SwingUtilities.invokeLater(() -> new DeregisterTests().setVisible(true)); } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/demo-single-app/src/editor/EditorExample.java
demo-single-app/src/editor/EditorExample.java
package editor; import com.formdev.flatlaf.FlatLaf; import com.formdev.flatlaf.FlatLightLaf; import io.github.andrewauclair.moderndocking.Dockable; import io.github.andrewauclair.moderndocking.DockingProperty; import io.github.andrewauclair.moderndocking.DockingRegion; import io.github.andrewauclair.moderndocking.DynamicDockableParameters; import io.github.andrewauclair.moderndocking.app.AppState; import io.github.andrewauclair.moderndocking.app.Docking; import io.github.andrewauclair.moderndocking.app.RootDockingPanel; import io.github.andrewauclair.moderndocking.app.WindowLayoutBuilder; import io.github.andrewauclair.moderndocking.event.DockingEvent; import io.github.andrewauclair.moderndocking.event.DockingListener; import io.github.andrewauclair.moderndocking.exception.DockingLayoutException; import java.io.FileInputStream; import java.io.IOException; import java.util.Scanner; import javax.swing.*; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeCellRenderer; import javax.swing.tree.TreePath; import java.awt.*; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.io.File; public class EditorExample { public static class FilePanel extends JPanel implements Dockable, DockingListener { private File file; @DockingProperty(name = "file-path", required = true, defaultValue = "") private String filePath; private DynamicDockableParameters parameters; private final JTextArea area = new JTextArea(); public FilePanel(File file) { parameters = new DynamicDockableParameters(file.getName(), file.getName(), file.getName()); Docking.registerDockable(this); this.file = file; filePath = file.getAbsolutePath(); createContents(); displayFileContents(); } public FilePanel(DynamicDockableParameters parameters) { this.parameters = parameters; Docking.registerDockable(this); createContents(); } private void createContents() { area.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.weightx = 1; gbc.weighty = 1; gbc.fill = GridBagConstraints.BOTH; add(new JScrollPane(area), gbc); } private void displayFileContents() { try (FileInputStream input = new FileInputStream(file)) { Scanner scanner = new Scanner(input); while (scanner.hasNext()) { area.append(scanner.nextLine() + '\n'); } } catch (IOException e) { } } @Override public void updateProperties() { file = new File(filePath); displayFileContents(); } @Override public String getPersistentID() { return parameters.getPersistentID(); } @Override public String getTabText() { return parameters.getTabText(); } @Override public void dockingChange(DockingEvent e) { // TODO what's the right way to deregister when we close a dockable? // if (e.getID() == DockingEvent.ID.UNDOCKED) { // Docking.deregisterDockable(this); // Docking.removeDockingListener(this); // } } } public static class FileAnchor extends JPanel implements Dockable { public FileAnchor() { Docking.registerDockingAnchor(this); setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.anchor = GridBagConstraints.CENTER; add(new JLabel("Dock files here"), gbc); } @Override public String getPersistentID() { return "files"; } @Override public String getTabText() { return ""; } } public static class FolderPanel extends JPanel implements Dockable { private final DefaultMutableTreeNode root = new DefaultMutableTreeNode(); public FolderPanel(File folder) { Docking.registerDockable(this); addFiles(folder, root); JTree tree = new JTree(root); tree.setEditable(false); tree.expandPath(new TreePath(root)); tree.setCellRenderer(new DefaultTreeCellRenderer() { @Override public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { Component comp = super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); if (comp instanceof JLabel) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) value; File file = (File) node.getUserObject(); if (file != null) { ((JLabel) comp).setText(file.getName()); } } if(sel && !hasFocus) { setBackgroundSelectionColor(UIManager.getColor("Panel.background")); setTextSelectionColor(UIManager.getColor("Panel.foreground")); } else { setTextSelectionColor(UIManager.getColor("Tree.selectionForeground")); setBackgroundSelectionColor(UIManager.getColor("Tree.selectionBackground")); } return comp; } }); tree.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { int row = tree.getRowForLocation(e.getX(), e.getY()); TreePath path = tree.getPathForRow(row); if (path != null) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); File file = (File) node.getUserObject(); if (file.isFile()) { FilePanel panel = new FilePanel(file); Docking.dock(panel, "files", DockingRegion.CENTER); } } } } }); setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.weightx = 1; gbc.weighty = 1; gbc.fill = GridBagConstraints.BOTH; add(tree, gbc); } private void addFiles(File folder, DefaultMutableTreeNode parent) { DefaultMutableTreeNode fileNode = new DefaultMutableTreeNode(folder); parent.add(fileNode); if (!folder.isDirectory() || folder.listFiles() == null) { return; } for (File file : folder.listFiles()) { if (file.isDirectory()) { addFiles(file, fileNode); } else { DefaultMutableTreeNode child = new DefaultMutableTreeNode(file); fileNode.add(child); } } } @Override public String getPersistentID() { return "folder"; } @Override public String getTabText() { return "Folder"; } } public static class InfoPanel extends JPanel implements Dockable { public InfoPanel() { Docking.registerDockable(this); } @Override public String getPersistentID() { return "info"; } @Override public String getTabText() { return "Info"; } @Override public String getTitleText() { return "File Information"; } } public static void main(String[] args) { SwingUtilities.invokeLater(() -> { FlatLaf.setup(new FlatLightLaf()); RootDockingPanel root = new RootDockingPanel(); JFrame mainFrame = new JFrame(); mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); mainFrame.add(root); mainFrame.setSize(300, 300); mainFrame.setVisible(true); Docking.initialize(mainFrame); Docking.registerDockingPanel(root, mainFrame); new InfoPanel(); new FileAnchor(); new FolderPanel(new File(".")); AppState.setAutoPersist(true); AppState.setPersistFile(new File(System.getProperty("java.io.tmpdir") + "/editor-example-layout.xml")); // AppState.setDefaultApplicationLayout( // new WindowLayoutBuilder("info") // .dock("folder", "info", DockingRegion.NORTH) // .dock("files", "folder", DockingRegion.EAST) // .buildApplicationLayout() // ); AppState.setDefaultApplicationLayout( new WindowLayoutBuilder("info") .dock("folder", "info", DockingRegion.NORTH) .dock("files", "folder", DockingRegion.EAST) .buildApplicationLayout() ); try { AppState.restore(); } catch (DockingLayoutException e) { throw new RuntimeException(e); } }); } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/demo-single-app/src/exception/CheckThreadViolationRepaintManager.java
demo-single-app/src/exception/CheckThreadViolationRepaintManager.java
/* * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * <p> * http://www.apache.org/licenses/LICENSE-2.0 * <p> * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. * <p> * Copyright 2012-2015 the original author or authors. */ package exception; import java.lang.ref.WeakReference; import java.util.Objects; import javax.swing.JComponent; import javax.swing.RepaintManager; import static javax.swing.SwingUtilities.isEventDispatchThread; /** * <p> * This class is used to detect Event Dispatch Thread rule violations<br> * See <a href="http://java.sun.com/docs/books/tutorial/uiswing/misc/threads.html">How to Use Threads</a> for more info * </p> * * <p> * This is a modification of original idea of Scott Delap.<br> * </p> * * @author Scott Delap * @author Alexander Potochkin * <p> * <a href="https://swinghelper.dev.java.net/">...</a> */ abstract class CheckThreadViolationRepaintManager extends RepaintManager { private final boolean completeCheck; private WeakReference<JComponent> lastComponent; CheckThreadViolationRepaintManager() { // it is recommended to pass the complete check this(true); } CheckThreadViolationRepaintManager(boolean completeCheck) { this.completeCheck = completeCheck; } @Override public synchronized void addInvalidComponent(JComponent component) { checkThreadViolations(Objects.requireNonNull(component)); super.addInvalidComponent(component); } @Override public void addDirtyRegion(JComponent component, int x, int y, int w, int h) { checkThreadViolations(Objects.requireNonNull(component)); super.addDirtyRegion(component, x, y, w, h); } private void checkThreadViolations(JComponent c) { if (!isEventDispatchThread() && (completeCheck || c.isShowing())) { boolean imageUpdate = false; boolean repaint = false; boolean fromSwing = false; StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace(); for (StackTraceElement st : stackTrace) { if (repaint && st.getClassName().startsWith("javax.swing.")) { fromSwing = true; } if (repaint && "imageUpdate".equals(st.getMethodName())) { imageUpdate = true; } if ("repaint".equals(st.getMethodName())) { repaint = true; fromSwing = false; } } if (imageUpdate) { // assuming it is java.awt.image.ImageObserver.imageUpdate(...) // image was asynchronously updated, that's ok return; } if (repaint && !fromSwing) { // no problems here, since repaint() is thread safe return; } // ignore the last processed component if (lastComponent != null && c == lastComponent.get()) { return; } lastComponent = new WeakReference<>(c); violationFound(c, stackTrace); } } abstract void violationFound(JComponent c, StackTraceElement[] stackTrace); }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/demo-single-app/src/exception/EdtViolationException.java
demo-single-app/src/exception/EdtViolationException.java
/* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Copyright 2012-2015 the original author or authors. */ package exception; /** * Error thrown when an EDT violation is detected. For more details, please read the <a * href="http://java.sun.com/javase/6/docs/api/javax/swing/package-summary.html#threading" target="_blank">Swing's * Threading Policy</a>. * * @author Alex Ruiz */ public class EdtViolationException extends RuntimeException { /** * Creates a new {@link EdtViolationException}. * * @param message the detail message. */ public EdtViolationException(String message) { super(message); } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/demo-single-app/src/exception/FailOnThreadViolationRepaintManager.java
demo-single-app/src/exception/FailOnThreadViolationRepaintManager.java
/* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Copyright 2012-2015 the original author or authors. */ package exception; import javax.swing.JComponent; import javax.swing.RepaintManager; /** * <p> * Fails a test when a Event Dispatch Thread rule violation is detected. See <a * href="http://java.sun.com/docs/books/tutorial/uiswing/misc/threads.html">How to Use Threads</a> for more information. * </p> * * @author Alex Ruiz */ public class FailOnThreadViolationRepaintManager extends CheckThreadViolationRepaintManager { /** * the {@link RepaintManager} that was installed before {@link #install()} has been called. */ private static RepaintManager previousRepaintManager; /** * <p> * Creates a new {@link FailOnThreadViolationRepaintManager} and sets it as the current repaint manager. * </p> * * <p> * On Sun JVMs, this method will install the new repaint manager the first time only. Once installed, subsequent calls * to this method will not install new repaint managers. This optimization may not work on non-Sun JVMs, since we use * reflection to check if a {@code CheckThreadViolationRepaintManager.java} is already installed. * </p> * * @return the created (and installed) repaint manager. * @see #uninstall() * @see RepaintManager#setCurrentManager(RepaintManager) */ public static FailOnThreadViolationRepaintManager install() { Object m = currentRepaintManager(); if (m instanceof FailOnThreadViolationRepaintManager) { return (FailOnThreadViolationRepaintManager) m; } return installNew(); } /** * <p> * Tries to restore the repaint manager before installing the {@link FailOnThreadViolationRepaintManager} via * {@link #install()}. * </p> * * @return the restored (and installed) repaint manager. * @see #install() * @see RepaintManager#setCurrentManager(RepaintManager) */ public static RepaintManager uninstall() { RepaintManager restored = previousRepaintManager; setCurrentManager(restored); previousRepaintManager = null; return restored; } private static RepaintManager currentRepaintManager() { try { RepaintManager repaintManager = RepaintManager.currentManager(null); if (repaintManager != null) { return repaintManager; } } catch (RuntimeException e) { return null; } return null; } private static FailOnThreadViolationRepaintManager installNew() { FailOnThreadViolationRepaintManager m = new FailOnThreadViolationRepaintManager(); previousRepaintManager = currentRepaintManager(); setCurrentManager(m); return m; } public FailOnThreadViolationRepaintManager() { } public FailOnThreadViolationRepaintManager(boolean completeCheck) { super(completeCheck); } /** * Throws a {@link EdtViolationException} when an EDT access violation is found. * * @param c the component involved in the EDT violation. * @param stackTraceElements stack trace elements to be set to the thrown exception. * @throws EdtViolationException when an EDT access violation is found. */ @Override void violationFound(JComponent c, StackTraceElement[] stackTraceElements) { EdtViolationException e = new EdtViolationException("EDT violation detected"); e.setStackTrace(stackTraceElements); throw e; } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/demo-single-app/src/packets/PacketListPanel.java
demo-single-app/src/packets/PacketListPanel.java
/* 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 packets; import io.github.andrewauclair.moderndocking.Dockable; import io.github.andrewauclair.moderndocking.app.Docking; import javax.swing.JPanel; public class PacketListPanel extends JPanel implements Dockable { private static int packetListCount = 0; public PacketListPanel() { Docking.registerDockable(this); } @Override public String getPersistentID() { return "packets"; } @Override public String getTabText() { return "Packets"; } @Override public boolean isFloatingAllowed() { return false; } @Override public boolean isLimitedToWindow() { return true; } @Override public boolean isClosable() { return packetListCount > 1; } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/demo-single-app/src/packets/PacketBytesPanel.java
demo-single-app/src/packets/PacketBytesPanel.java
/* 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 packets; import io.github.andrewauclair.moderndocking.Dockable; import io.github.andrewauclair.moderndocking.DockableStyle; import io.github.andrewauclair.moderndocking.app.Docking; import javax.swing.JPanel; public class PacketBytesPanel extends JPanel implements Dockable { public PacketBytesPanel() { Docking.registerDockable(this); } @Override public String getPersistentID() { return "packet-bytes"; } @Override public String getTabText() { return "Bytes"; } @Override public DockableStyle getStyle() { return null; } @Override public boolean isAutoHideAllowed() { return true; } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/demo-single-app/src/packets/MainFrame.java
demo-single-app/src/packets/MainFrame.java
/* 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 packets; import com.formdev.flatlaf.FlatDarkLaf; import com.formdev.flatlaf.FlatLaf; import com.formdev.flatlaf.FlatLightLaf; import exception.FailOnThreadViolationRepaintManager; import io.github.andrewauclair.moderndocking.app.AppState; import io.github.andrewauclair.moderndocking.app.DockableMenuItem; import io.github.andrewauclair.moderndocking.app.Docking; import io.github.andrewauclair.moderndocking.app.RootDockingPanel; import io.github.andrewauclair.moderndocking.exception.DockingLayoutException; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import java.io.File; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.SwingUtilities; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; public class MainFrame extends JFrame { private final PacketBytesPanel bytesPanel; private final PacketInfoPanel infoPanel; public MainFrame() { Docking.initialize(this); setTitle("Package Capture Demo"); setSize(800, 600); JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); JMenu view = new JMenu("View"); bytesPanel = new PacketBytesPanel(); view.add(new DockableMenuItem(bytesPanel)); infoPanel = new PacketInfoPanel(); view.add(new DockableMenuItem(infoPanel)); menuBar.add(view); setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 0; gbc.weightx = 1.0; gbc.weighty = 1.0; gbc.fill = GridBagConstraints.BOTH; RootDockingPanel dockingPanel = new RootDockingPanel(this); add(dockingPanel, gbc); } public static void main(String[] args) { SwingUtilities.invokeLater(() -> { configureLookAndFeel(args); MainFrame mainFrame = new MainFrame(); mainFrame.setVisible(true); // now that the main frame is setup with the defaults, we can restore the layout AppState.setPersistFile(new File("auto_persist_layout.xml")); try { AppState.restore(); } catch (DockingLayoutException e) { e.printStackTrace(); } AppState.setAutoPersist(true); }); } private static void configureLookAndFeel(String[] args) { try { FlatLaf.registerCustomDefaultsSource( "docking" ); if (args.length > 1) { System.setProperty("flatlaf.uiScale", args[1]); } if (args.length > 0 && args[0].equals("light")) { UIManager.setLookAndFeel(new FlatLightLaf()); } else if (args.length > 0 && args[0].equals("dark")) { UIManager.setLookAndFeel(new FlatDarkLaf()); } else { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) { throw new RuntimeException(ex); } } FlatLaf.updateUI(); } catch (Exception e) { e.printStackTrace(); try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) { throw new RuntimeException(ex); } } UIManager.getDefaults().put("TabbedPane.contentBorderInsets", new Insets(0,0,0,0)); UIManager.getDefaults().put("TabbedPane.tabsOverlapBorder", true); // this is an app to test the docking framework, we want to make sure we detect EDT violations as soon as possible FailOnThreadViolationRepaintManager.install(); } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/demo-single-app/src/packets/PacketInfoPanel.java
demo-single-app/src/packets/PacketInfoPanel.java
/* 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 packets; import io.github.andrewauclair.moderndocking.Dockable; import io.github.andrewauclair.moderndocking.DockableStyle; import io.github.andrewauclair.moderndocking.app.Docking; import javax.swing.JPanel; public class PacketInfoPanel extends JPanel implements Dockable { public PacketInfoPanel() { Docking.registerDockable(this); } @Override public String getPersistentID() { return "packet-info"; } @Override public String getTabText() { return "Info"; } @Override public boolean isFloatingAllowed() { return false; } @Override public boolean isLimitedToWindow() { return true; } @Override public DockableStyle getStyle() { return null; } @Override public boolean isAutoHideAllowed() { return true; } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/demo-single-app/src/examples/TopTabsMode.java
demo-single-app/src/examples/TopTabsMode.java
package examples; public class TopTabsMode { }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/demo-single-app/src/examples/UpdateTabInfo.java
demo-single-app/src/examples/UpdateTabInfo.java
package examples; public class UpdateTabInfo { }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/demo-single-app/src/examples/Display.java
demo-single-app/src/examples/Display.java
package examples; public class Display { }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/demo-single-app/src/examples/BringToFront.java
demo-single-app/src/examples/BringToFront.java
package examples; public class BringToFront { }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/demo-single-app/src/examples/Maximize.java
demo-single-app/src/examples/Maximize.java
package examples; public class Maximize { }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/demo-single-app/src/examples/Docking_dock.java
demo-single-app/src/examples/Docking_dock.java
/* Copyright (c) 2022 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 examples; import io.github.andrewauclair.moderndocking.Dockable; import io.github.andrewauclair.moderndocking.DockingRegion; import io.github.andrewauclair.moderndocking.app.Docking; import io.github.andrewauclair.moderndocking.app.RootDockingPanel; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.Point; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.SwingUtilities; public class Docking_dock extends JFrame { private static class DockingPanel extends JPanel implements Dockable { private final String id; public DockingPanel(String id) { this.id = id; JButton floatPanel = new JButton("Float This Panel"); floatPanel.addActionListener(e -> { Point location = getLocationOnScreen(); location.x += 250; Docking.newWindow(this, location, new Dimension(150, 150)); }); add(floatPanel); } @Override public String getPersistentID() { return id; } @Override public String getTabText() { return id; } @Override public boolean isClosable() { return false; } }; public Docking_dock() { setSize(300, 200); Docking.initialize(this); RootDockingPanel root = new RootDockingPanel(this); add(root, BorderLayout.CENTER); DockingPanel alpha = new DockingPanel("Alpha"); DockingPanel bravo = new DockingPanel("Bravo"); DockingPanel charlie = new DockingPanel("Charlie"); DockingPanel delta = new DockingPanel("Delta"); Docking.registerDockable(alpha); Docking.registerDockable(bravo); Docking.registerDockable(charlie); Docking.registerDockable(delta); Docking.dock(alpha, this); Docking.dock(bravo, alpha, DockingRegion.WEST); } public static void main(String[] args) { SwingUtilities.invokeLater(() -> new Docking_dock().setVisible(true)); } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/demo-single-app/src/examples/NewWindow.java
demo-single-app/src/examples/NewWindow.java
package examples; import io.github.andrewauclair.moderndocking.DockingRegion; import io.github.andrewauclair.moderndocking.app.Docking; import io.github.andrewauclair.moderndocking.app.RootDockingPanel; import io.github.andrewauclair.moderndocking.ext.ui.DockingUI; import io.github.andrewauclair.moderndocking.ui.DefaultDockingPanel; import java.awt.BorderLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.SwingUtilities; public class NewWindow extends JFrame { public NewWindow() { setSize(300, 200); DockingUI.initialize(); RootDockingPanel root = new RootDockingPanel(this); add(root, BorderLayout.CENTER); DefaultDockingPanel one = new DefaultDockingPanel("one", "One"); DefaultDockingPanel two = new DefaultDockingPanel("two", "Two"); JButton openOneInNewWindow = new JButton("Open in new window"); openOneInNewWindow.addActionListener(e -> Docking.newWindow("one")); one.add(openOneInNewWindow); JButton openTwoInNewWindow = new JButton("Open in new window"); openTwoInNewWindow.addActionListener(e -> Docking.newWindow(two)); two.add(openTwoInNewWindow); Docking.dock(one, this); Docking.dock(two, one, DockingRegion.WEST); } public static void main(String[] args) { SwingUtilities.invokeLater(() -> new NewWindow().setVisible(true)); } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-ui/src/module-info.java
docking-ui/src/module-info.java
/** * Module for the Modern Docking framework */ module modern_docking.ui_ext { requires modern_docking.api; requires java.desktop; requires com.formdev.flatlaf.extras; exports io.github.andrewauclair.moderndocking.ext.ui; }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-ui/src/io/github/andrewauclair/moderndocking/ext/ui/FlatLafHeaderUI.java
docking-ui/src/io/github/andrewauclair/moderndocking/ext/ui/FlatLafHeaderUI.java
/* Copyright (c) 2022-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 io.github.andrewauclair.moderndocking.ext.ui; import com.formdev.flatlaf.extras.FlatSVGIcon; import io.github.andrewauclair.moderndocking.ui.DefaultHeaderUI; import io.github.andrewauclair.moderndocking.ui.DockingHeaderUI; import io.github.andrewauclair.moderndocking.ui.DockingSettings; import io.github.andrewauclair.moderndocking.ui.HeaderController; import io.github.andrewauclair.moderndocking.ui.HeaderModel; import java.awt.Color; /** * Custom DefaultHeaderUI that uses SVG Icons for settings and close when using FlatLaf */ public class FlatLafHeaderUI extends DefaultHeaderUI implements DockingHeaderUI { /** * Settings icon for the header. Uses an SVG icon for sharper icons */ private final FlatSVGIcon settingsIcon = new FlatSVGIcon(FlatLafHeaderUI.class.getResource("/ui_ext_icons/settings.svg")); /** * Close icon for the header. Uses an SVG icon for sharper icons */ private final FlatSVGIcon closeIcon = new FlatSVGIcon(FlatLafHeaderUI.class.getResource("/ui_ext_icons/close.svg")); /** * Construct a new FlatLafHeaderUI * * @param headerController Header controller to use for this UI * @param headerModel Header model to use for this UI */ public FlatLafHeaderUI(HeaderController headerController, HeaderModel headerModel) { super(headerController, headerModel); if (!settingsIcon.hasFound()) { throw new RuntimeException("settings.svg icon not found"); } if (!closeIcon.hasFound()) { throw new RuntimeException("close.svg icon not found"); } setBackground(DockingSettings.getHeaderBackground()); Color foreground = DockingSettings.getHeaderForeground(); settingsIcon.setColorFilter(new FlatSVGIcon.ColorFilter(color -> foreground)); closeIcon.setColorFilter(new FlatSVGIcon.ColorFilter(color -> foreground)); } @Override protected void init() { super.init(); settings.setIcon(settingsIcon); close.setIcon(closeIcon); } @Override public void setForeground(Color fg) { super.setForeground(fg); if (settingsIcon != null) { settingsIcon.setColorFilter(new FlatSVGIcon.ColorFilter(color -> fg)); } if (closeIcon != null) { closeIcon.setColorFilter(new FlatSVGIcon.ColorFilter(color -> fg)); } } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-ui/src/io/github/andrewauclair/moderndocking/ext/ui/DockingUI.java
docking-ui/src/io/github/andrewauclair/moderndocking/ext/ui/DockingUI.java
/* 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 io.github.andrewauclair.moderndocking.ext.ui; import com.formdev.flatlaf.extras.FlatSVGIcon; import io.github.andrewauclair.moderndocking.internal.DockedTabbedPanel; import io.github.andrewauclair.moderndocking.internal.DockingInternal; import java.awt.Color; import java.beans.PropertyChangeListener; import javax.swing.SwingUtilities; import javax.swing.UIManager; /** * Primary class for the Modern Docking UI Extension. Used to initialize extra UI functionality within Modern Docking API */ public class DockingUI { private static boolean initialized = false; private static PropertyChangeListener propertyChangeListener; private static final FlatSVGIcon settingsIcon = new FlatSVGIcon(DockingUI.class.getResource("/ui_ext_icons/settings.svg")); /** * This class should not be instantiated */ private DockingUI() { } /** * Initialize the FlatLaf UI extension. This reconfigures the docking framework to use FlatLaf SVG icons and color filters. */ public static void initialize() { if (initialized) { return; } initialized = true; DockingInternal.createHeaderUI = FlatLafHeaderUI::new; if (!settingsIcon.hasFound()) { throw new RuntimeException("settings.svg icon not found"); } DockedTabbedPanel.setSettingsIcon(settingsIcon); Color foreground = UIManager.getColor("TableHeader.foreground"); settingsIcon.setColorFilter(new FlatSVGIcon.ColorFilter(color -> foreground)); propertyChangeListener = e -> { if ("lookAndFeel".equals(e.getPropertyName())) { SwingUtilities.invokeLater(() -> { Color newForeground = UIManager.getColor("TableHeader.foreground"); settingsIcon.setColorFilter(new FlatSVGIcon.ColorFilter(color -> newForeground)); }); } }; UIManager.addPropertyChangeListener(propertyChangeListener); } /** * Change the color property used for the settings icon on JTabbedPanes * * @param property The new color property to use */ public static void setSettingsIconColorProperty(String property) { if (!initialized) { return; } Color foreground = UIManager.getColor(property); if (foreground == null) { throw new RuntimeException("Color for UI property '" + property + "' not found"); } settingsIcon.setColorFilter(new FlatSVGIcon.ColorFilter(color -> foreground)); UIManager.removePropertyChangeListener(propertyChangeListener); propertyChangeListener = e -> { if ("lookAndFeel".equals(e.getPropertyName())) { SwingUtilities.invokeLater(() -> { Color newForeground = UIManager.getColor("TableHeader.foreground"); settingsIcon.setColorFilter(new FlatSVGIcon.ColorFilter(color -> newForeground)); }); } }; UIManager.addPropertyChangeListener(propertyChangeListener); } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-single-app/src/module-info.java
docking-single-app/src/module-info.java
/** * Module for the Modern Docking framework */ module modern_docking.single_app { requires modern_docking.api; requires java.desktop; requires java.logging; exports io.github.andrewauclair.moderndocking.app; }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-single-app/src/io/github/andrewauclair/moderndocking/app/LayoutsMenu.java
docking-single-app/src/io/github/andrewauclair/moderndocking/app/LayoutsMenu.java
/* Copyright (c) 2022 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 io.github.andrewauclair.moderndocking.app; import io.github.andrewauclair.moderndocking.event.DockingLayoutEvent; import io.github.andrewauclair.moderndocking.event.DockingLayoutListener; import io.github.andrewauclair.moderndocking.layouts.DockingLayouts; import javax.swing.JMenu; import javax.swing.JMenuItem; /** * Custom JMenu that displays all the layouts in DockingLayouts as menu items */ public class LayoutsMenu extends JMenu implements DockingLayoutListener { /** * Create a new layouts menu. Add a listener for when layouts change. */ public LayoutsMenu() { super("Layouts"); DockingLayouts.addLayoutsListener(this); rebuildOptions(); } private void rebuildOptions() { removeAll(); for (String name : DockingLayouts.getLayoutNames()) { JMenuItem item = new JMenuItem(name); item.addActionListener(e -> DockingState.restoreApplicationLayout(DockingLayouts.getLayout(name))); add(item); } } @Override public void layoutChange(DockingLayoutEvent e) { rebuildOptions(); } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-single-app/src/io/github/andrewauclair/moderndocking/app/WindowLayoutBuilder.java
docking-single-app/src/io/github/andrewauclair/moderndocking/app/WindowLayoutBuilder.java
/* 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 io.github.andrewauclair.moderndocking.app; import io.github.andrewauclair.moderndocking.api.WindowLayoutBuilderAPI; public class WindowLayoutBuilder extends WindowLayoutBuilderAPI { public WindowLayoutBuilder(String firstID) { super(Docking.getSingleInstance(), firstID); } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-single-app/src/io/github/andrewauclair/moderndocking/app/DockableMenuItem.java
docking-single-app/src/io/github/andrewauclair/moderndocking/app/DockableMenuItem.java
/* Copyright (c) 2022 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 io.github.andrewauclair.moderndocking.app; import io.github.andrewauclair.moderndocking.Dockable; import io.github.andrewauclair.moderndocking.internal.DockingInternal; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.function.Supplier; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JCheckBoxMenuItem; /** * Special JCheckBoxMenuItem that handles updating the checkbox for us based on the docking state of the dockable */ public class DockableMenuItem extends JCheckBoxMenuItem implements ActionListener { private static final Logger logger = Logger.getLogger(DockableMenuItem.class.getPackageName()); /** * Persistent ID provider. Used when the persistent ID isn't known at compile time. * Used when this menu item is added to a menu (using addNotify) */ private final Supplier<String> persistentIDProvider; /** * The persistent ID of the dockable which will be displayed when this dockable is clicked */ private final String persistentID; /** * Create a new DockableMenuItem * * @param dockable The dockable to dock when this menu item is selected */ public DockableMenuItem(Dockable dockable) { this(dockable.getPersistentID(), dockable.getTabText()); } /** * Create a new dockable menu to display a dockable * * @param persistentID The dockable this menu item refers to * @param text The display text for this menu item */ public DockableMenuItem(String persistentID, String text) { super(text); this.persistentIDProvider = null; this.persistentID = persistentID; addActionListener(this); } /** * Create a new dockable menu to display a dockable and use a supplier for the persistent ID * * @param persistentIDProvider Provides the persistent ID that will be displayed * @param text The display text for this menu item */ public DockableMenuItem(Supplier<String> persistentIDProvider, String text) { super(text); this.persistentIDProvider = persistentIDProvider; this.persistentID = ""; addActionListener(this); } @Override public void addNotify() { super.addNotify(); // update the menu item, it's about to be displayed DockingInternal internal = DockingInternal.get(Docking.getSingleInstance()); String id = persistentIDProvider != null ? persistentIDProvider.get() : persistentID; if (internal.hasDockable(id)) { Dockable dockable = internal.getDockable(id); setSelected(Docking.isDocked(dockable)); } else { setVisible(false); logger.log(Level.INFO, "Hiding DockableMenuItem for \"" + getText() + ".\" No dockable with persistentID '" + id + "' registered."); } } @Override public void actionPerformed(ActionEvent e) { DockingInternal internal = DockingInternal.get(Docking.getSingleInstance()); String id = persistentIDProvider != null ? persistentIDProvider.get() : persistentID; if (internal.hasDockable(id)) { Dockable dockable = internal.getDockable(id); Docking.display(dockable); // set this menu item to the state of the dockable, should be docked at this point setSelected(Docking.isDocked(dockable)); } else { logger.log(Level.SEVERE, "DockableMenuItem for \"" + getText() + "\" action failed. No dockable with persistentID '" + id + "' registered."); } } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-single-app/src/io/github/andrewauclair/moderndocking/app/RootDockingPanel.java
docking-single-app/src/io/github/andrewauclair/moderndocking/app/RootDockingPanel.java
/* 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 io.github.andrewauclair.moderndocking.app; import io.github.andrewauclair.moderndocking.api.RootDockingPanelAPI; import io.github.andrewauclair.moderndocking.ui.ToolbarLocation; import java.awt.Window; import java.util.EnumSet; public class RootDockingPanel extends RootDockingPanelAPI { public RootDockingPanel() { } public RootDockingPanel(Window window) { super(Docking.getSingleInstance(), window); } public RootDockingPanel(Window window, EnumSet<ToolbarLocation> supportedToolbars) { super(Docking.getSingleInstance(), window, supportedToolbars); } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-single-app/src/io/github/andrewauclair/moderndocking/app/AppState.java
docking-single-app/src/io/github/andrewauclair/moderndocking/app/AppState.java
/* 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 io.github.andrewauclair.moderndocking.app; import io.github.andrewauclair.moderndocking.Dockable; import io.github.andrewauclair.moderndocking.Property; import io.github.andrewauclair.moderndocking.api.AppStateAPI; import io.github.andrewauclair.moderndocking.exception.DockingLayoutException; import io.github.andrewauclair.moderndocking.layouts.ApplicationLayout; import java.io.File; /** * Handle persistence and restoration of Application layouts */ public class AppState { private static final AppStateAPI instance = new AppStateAPI(Docking.getSingleInstance()){}; /** * This class should not be instantiated */ private AppState() { } /** * Set whether the framework should auto persist the application layout to a file when * docking changes, windows resize, etc. * * @param autoPersist Should the framework auto persist the application layout to a file? */ public static void setAutoPersist(boolean autoPersist) { instance.setAutoPersist(autoPersist); } /** * Are we currently auto persisting to a file? * * @return True - we are auto persisting, False - we are not auto persisting */ public static boolean isAutoPersist() { return instance.isAutoPersist(); } /** * Set the file that should be used for auto persistence. This will be written as an XML file. * * @param file File to persist layout to */ public static void setPersistFile(File file) { instance.setPersistFile(file); } /** * Retrieve the file that we are persisting the application layout into * * @return The file we are currently persisting to */ public static File getPersistFile() { return instance.getPersistFile(); } /** * Sets the pause state of the auto persistence * * @param paused Whether auto persistence should be enabled */ public static void setPaused(boolean paused) { instance.setPaused(paused); } /** * Gets the pause state of the auto persistence * * @return Whether auto persistence is enabled */ public static boolean isPaused() { return instance.isPaused(); } /** * Used to persist the current app layout to the layout file. * This is a no-op if auto persistence is turned off, it's paused or there is no file */ public static void persist() { instance.persist(); } /** * Restore the application layout from the auto persist file. * * @return true if and only if a layout is restored from a file. Restoring from the default layout will return false. * @throws DockingLayoutException Thrown for any issues with the layout file. */ public static boolean restore() throws DockingLayoutException { return instance.restore(); } /** * Set the default layout used by the application. This layout is restored after the application has loaded * and there is no persisted layout or the persisted layout fails to load. * * @param layout Default layout */ public static void setDefaultApplicationLayout(ApplicationLayout layout) { instance.setDefaultApplicationLayout(layout); } /** * Get the property for a dockable by name * * @param dockable The dockable to get a property for * @param propertyName The property to search for * * @return The property instance of the dockable, or null if not found */ public static Property getProperty(Dockable dockable, String propertyName) { return instance.getProperty(dockable, propertyName); } /** * Set the value of a property on the dockable. If the property does not exist, it will be created * * @param dockable The dockable to set a property for * @param propertyName The name of the property we're setting * @param value The value of the property */ public static void setProperty(Dockable dockable, String propertyName, String value) { instance.setProperty(dockable, propertyName, new Property.StringProperty(propertyName, value)); } /** * Remove the property from the dockable * * @param dockable The dockable to remove the property from * @param propertyName The property to remove */ public static void removeProperty(Dockable dockable, String propertyName) { instance.removeProperty(dockable, propertyName); } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-single-app/src/io/github/andrewauclair/moderndocking/app/DockingState.java
docking-single-app/src/io/github/andrewauclair/moderndocking/app/DockingState.java
/* 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 io.github.andrewauclair.moderndocking.app; import io.github.andrewauclair.moderndocking.api.DockingStateAPI; import io.github.andrewauclair.moderndocking.layouts.ApplicationLayout; import io.github.andrewauclair.moderndocking.layouts.WindowLayout; import java.awt.Window; public class DockingState { private static final DockingStateAPI instance = new DockingStateAPI(Docking.getSingleInstance()){}; /** * This class should not be instantiated */ private DockingState() { } /** * Get the current window layout of a window * * @param window The window to get a layout for * * @return The window layout */ public static WindowLayout getWindowLayout(Window window) { return instance.getWindowLayout(window); } /** * Get the current application layout of the application * * @return Layout of the application */ public static ApplicationLayout getApplicationLayout() { return instance.getApplicationLayout(); } /** * Restore the application layout, creating any necessary windows * * @param layout Application layout to restore */ public static void restoreApplicationLayout(ApplicationLayout layout) { instance.restoreApplicationLayout(layout); } /** * Restore the layout of a single window * * @param window Window to restore the layout onto * @param layout The layout to restore */ public static void restoreWindowLayout(Window window, WindowLayout layout) { instance.restoreWindowLayout(window, layout); } /** * Restore the layout of a single window, preserving the current size and position of the window * * @param window Window to restore the layout onto * @param layout The layout to restore */ public static void restoreWindowLayout_PreserveSizeAndPos(Window window, WindowLayout layout) { instance.restoreWindowLayout_PreserveSizeAndPos(window, layout); } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-single-app/src/io/github/andrewauclair/moderndocking/app/Docking.java
docking-single-app/src/io/github/andrewauclair/moderndocking/app/Docking.java
/* Copyright (c) 2022-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 io.github.andrewauclair.moderndocking.app; import io.github.andrewauclair.moderndocking.Dockable; import io.github.andrewauclair.moderndocking.DockingRegion; import io.github.andrewauclair.moderndocking.api.DockingAPI; import io.github.andrewauclair.moderndocking.api.RootDockingPanelAPI; import io.github.andrewauclair.moderndocking.event.DockingListener; import io.github.andrewauclair.moderndocking.event.MaximizeListener; import io.github.andrewauclair.moderndocking.event.NewFloatingFrameListener; import io.github.andrewauclair.moderndocking.internal.DockingInternal; import io.github.andrewauclair.moderndocking.internal.DockingListeners; import io.github.andrewauclair.moderndocking.layouts.DynamicDockableCreationListener; import io.github.andrewauclair.moderndocking.ui.ToolbarLocation; import java.awt.Dimension; import java.awt.Point; import java.awt.Window; import java.util.List; import java.util.Map; import javax.swing.JDialog; import javax.swing.JFrame; /** * Convenience class for apps that only need a single instance of the docking framework. Working with the static functions * is easier than passing an instance of the Docking class all over the app codebase. */ public class Docking { private static DockingAPI instance; /** * This class should not be instantiated */ private Docking() { } /** * Create the one and only instance of the Docking class for the application * @param mainWindow The main window of the application */ public static void initialize(Window mainWindow) { if (instance == null) { instance = new DockingAPI(mainWindow){}; } } /** * Uninitialize the docking framework so that it can be initialized again with a new window */ public static void uninitialize() { instance.uninitialize(); instance = null; } /** * Get a map of RootDockingPanels to their Windows * * @return map of root panels */ public static Map<Window, RootDockingPanelAPI> getRootPanels() { return instance.getRootPanels(); } /** * Get the main window instance * * @return main window */ public static Window getMainWindow() { return instance.getMainWindow(); } /** * register a dockable with the framework * * @param dockable Dockable to register */ public static void registerDockable(Dockable dockable) { instance.registerDockable(dockable); } /** * Check if a dockable has already been registered * * @param persistentID The persistent ID to look for * * @return Is the dockable registered? */ public static boolean isDockableRegistered(String persistentID) { return instance.isDockableRegistered(persistentID); } /** * Dockables must be deregistered so it can be properly disposed * * @param dockable Dockable to deregister */ public static void deregisterDockable(Dockable dockable) { instance.deregisterDockable(dockable); } /** * Deregister all dockables that have been registered. This action will also undock all dockables. */ public static void deregisterAllDockables() { instance.deregisterAllDockables(); } public static List<Dockable> getDockables() { return instance.getDockables(); } /** * registration function for DockingPanel * * @param panel Panel to register * @param parent The parent frame of the panel */ public static void registerDockingPanel(RootDockingPanelAPI panel, JFrame parent) { instance.registerDockingPanel(panel, parent); } /** * Register a RootDockingPanel * * @param panel RootDockingPanel to register * @param parent The parent JDialog of the panel */ public static void registerDockingPanel(RootDockingPanelAPI panel, JDialog parent) { instance.registerDockingPanel(panel, parent); } /** * Deregister a docking root panel * * @param parent The parent of the panel that we're deregistering */ public static void deregisterDockingPanel(Window parent) { instance.deregisterDockingPanel(parent); } /** * Deregister all registered panels. Additionally, dispose any windows created by Modern Docking. */ public static void deregisterAllDockingPanels() { instance.deregisterAllDockingPanels(); } public static void registerDockingAnchor(Dockable anchor) { instance.registerDockingAnchor(anchor); } public static void deregisterDockingAnchor(Dockable anchor) { instance.deregisterDockingAnchor(anchor); } /** * 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 static void configureAutoHide(Window window, int layer, boolean allow) { instance.configureAutoHide(window, layer, allow); } /** * Check if auto hide is allowed for a dockable * * @param dockable Dockable to check * @return Whether the dockable can be hidden */ public static boolean autoHideAllowed(Dockable dockable) { return instance.autoHideAllowed(dockable); } /** * Check if auto hide is allowed for a dockable * * @param dockable Dockable to check * @return Whether the dockable can be hidden */ public static boolean isAutoHideAllowed(Dockable dockable) { return instance.isAutoHideAllowed(dockable); } /** * docks a dockable to the center of the given window * <p> * NOTE: This will only work if the window root docking node is empty. Otherwise, this does nothing. * * @param persistentID The persistentID of the dockable to dock * @param window The window to dock into */ public static void dock(String persistentID, Window window) { instance.dock(persistentID, window); } /** * docks a dockable to the center of the given window * <p> * NOTE: This will only work if the window root docking node is empty. Otherwise, this does nothing. * * @param dockable The dockable to dock * @param window The window to dock into */ public static void dock(Dockable dockable, Window window) { instance.dock(dockable, window); } /** * docks a dockable into the specified region of the root of the window with 25% divider proportion * * @param persistentID The persistentID of the dockable to dock * @param window The window to dock into * @param region The region to dock into */ public static void dock(String persistentID, Window window, DockingRegion region) { instance.dock(persistentID, window, region); } /** * docks a dockable into the specified region of the root of the window with 25% divider proportion * * @param dockable The dockable to dock * @param window The window to dock into * @param region The region to dock into */ public static void dock(Dockable dockable, Window window, DockingRegion region) { instance.dock(dockable, window, region); } /** * docks a dockable into the specified region of the window with the specified divider proportion * * @param persistentID The persistentID of the dockable to dock * @param window The window to dock into * @param region The region to dock into * @param dividerProportion The proportion to use if docking in a split pane */ public static void dock(String persistentID, Window window, DockingRegion region, double dividerProportion) { instance.dock(persistentID, window, region, dividerProportion); } /** * docks a dockable into the specified region of the window with the specified divider proportion * * @param dockable The dockable to dock * @param window The window to dock into * @param region The region to dock into * @param dividerProportion The proportion to use if docking in a split pane */ public static void dock(Dockable dockable, Window window, DockingRegion region, double dividerProportion) { instance.dock(dockable, window, region, dividerProportion); } /** * docks the target to the source in the specified region with 50% divider proportion * * @param sourcePersistentID The persistentID of the source dockable to dock the target dockable to * @param targetPersistentID The persistentID of the target dockable * @param region The region on the source dockable to dock into */ public static void dock(String sourcePersistentID, String targetPersistentID, DockingRegion region) { instance.dock(sourcePersistentID, targetPersistentID, region); } /** * docks the target to the source in the specified region with 50% divider proportion * * @param sourcePersistentID The persistentID of the source dockable to dock the target dockable to * @param target The target dockable * @param region The region on the source dockable to dock into */ public static void dock(String sourcePersistentID, Dockable target, DockingRegion region) { instance.dock(sourcePersistentID, target, region); } /** * docks the target to the source in the specified region with 50% divider proportion * * @param source The source dockable to dock the target dockable to * @param targetPersistentID The persistentID of the target dockable * @param region The region on the source dockable to dock into */ public static void dock(Dockable source, String targetPersistentID, DockingRegion region) { instance.dock(source, targetPersistentID, region); } /** * docks the target to the source in the specified region with 50% divider proportion * * @param source The source dockable to dock the target dockable to * @param target The target dockable * @param region The region on the source dockable to dock into */ public static void dock(Dockable source, Dockable target, DockingRegion region) { instance.dock(source, target, region); } /** * docks the target to the source in the specified region with the specified divider proportion * * @param sourcePersistentID The persistentID of the source dockable to dock the target dockable to * @param targetPersistentID The persistentID of the target dockable * @param region The region on the source dockable to dock into * @param dividerProportion The proportion to use if docking in a split pane */ public static void dock(String sourcePersistentID, String targetPersistentID, DockingRegion region, double dividerProportion) { instance.dock(sourcePersistentID, targetPersistentID, region, dividerProportion); } /** * docks the target to the source in the specified region with the specified divider proportion * * @param source The source dockable to dock the target dockable to * @param target The target dockable * @param region The region on the source dockable to dock into * @param dividerProportion The proportion to use if docking in a split pane */ public static void dock(Dockable source, Dockable target, DockingRegion region, double dividerProportion) { instance.dock(source, target, region, dividerProportion); } /** * 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 * * @param persistentID The persistent ID of the dockable to float in a new window */ public static void newWindow(String persistentID) { instance.newWindow(persistentID); } /** * 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 * * @param dockable The dockable to float in a new window */ public static void newWindow(Dockable dockable) { instance.newWindow(dockable); } /** * 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 * * @param persistentID The persistent ID of the dockable to float in a new window * @param location The screen location to display the new frame at * @param size The size of the new frame */ public static void newWindow(String persistentID, Point location, Dimension size) { instance.newWindow(persistentID, location, size); } /** * 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 * * @param dockable The dockable to float in a new window * @param location The screen location to display the new frame at * @param size The size of the new frame */ public static void newWindow(Dockable dockable, Point location, Dimension size) { instance.newWindow(dockable, location, size); } /** * bring the specified dockable to the front if it is in a tabbed panel * * @param persistentID The persistent ID of the dockable */ public static void bringToFront(String persistentID) { bringToFront(DockingInternal.get(instance).getDockable(persistentID)); } /** * bring the specified dockable to the front if it is in a tabbed panel * * @param dockable Dockable to bring to the front */ public static void bringToFront(Dockable dockable) { instance.bringToFront(dockable); } /** * undock a dockable * * @param persistentID The persistentID of the dockable to undock */ public static void undock(String persistentID) { instance.undock(persistentID); } /** * undock a dockable * * @param dockable The dockable to undock */ public static void undock(Dockable dockable) { instance.undock(dockable); } /** * check if a dockable is currently docked * * @param persistentID The persistentID of the dockable to check * @return Whether the dockable is docked */ public static boolean isDocked(String persistentID) { return instance.isDocked(persistentID); } /** * check if a dockable is currently docked * * @param dockable The dockable to check * @return Whether the dockable is docked */ public static boolean isDocked(Dockable dockable) { return instance.isDocked(dockable); } /** * check if a dockable is currently hidden * * @param persistentID The persistentID of the dockable to check * @return Whether the dockable is hidden */ public static boolean isHidden(String persistentID) { return instance.isHidden(persistentID); } /** * check if a dockable is currently hidden * * @param dockable The dockable to check * @return Whether the dockable is hidden */ public static boolean isHidden(Dockable dockable) { return instance.isHidden(dockable); } /** * check if the window can be disposed. Windows can be disposed if they are not the main window and are not maximized * * @param window Window to check * @return Boolean indicating if the specified Window can be disposed */ public static boolean canDisposeWindow(Window window) { return instance.canDisposeWindow(window); } /** * checks if a dockable is currently maximized * * @param dockable The dockable to check * @return Whether the dockable is maximized */ public static boolean isMaximized(Dockable dockable) { return instance.isMaximized(dockable); } /** * maximizes a dockable * * @param dockable Dockable to maximize */ public static void maximize(Dockable dockable) { instance.maximize(dockable); } /** * minimize a dockable if it is currently maximized * * @param dockable Dockable to minimize */ public static void minimize(Dockable dockable) { instance.minimize(dockable); } public void autoShowDockable(Dockable dockable) { instance.autoShowDockable(dockable); } public void autoShowDockable(String persistentID) { instance.autoShowDockable(persistentID); } public void autoHideDockable(Dockable dockable) { instance.autoHideDockable(dockable); } public void autoHideDockable(String persistentID) { instance.autoHideDockable(persistentID); } public void autoHideDockable(Dockable dockable, ToolbarLocation location) { instance.autoHideDockable(dockable, location); } public void autoHideDockable(String persistentID, ToolbarLocation location) { instance.autoHideDockable(persistentID, location); } public void autoHideDockable(Dockable dockable, ToolbarLocation location, Window window) { instance.autoHideDockable(dockable, location, window); } public void autoHideDockable(String persistentID, ToolbarLocation location, Window window) { instance.autoHideDockable(persistentID, location, window); } /** * display a dockable * * @param persistentID The persistentID of the dockable to display */ public static void display(String persistentID) { instance.display(persistentID); } /** * Display a dockable * <p> * if the dockable is already docked, then bringToFront is called. * if it is not docked, then dock is called, docking it with dockables of the same type * * @param dockable The dockable to display */ public static void display(Dockable dockable) { instance.display(dockable); } /** * update the tab text on a dockable if it is in a tabbed panel * * @param persistentID The persistentID of the dockable to update */ public static void updateTabInfo(String persistentID) { instance.updateTabInfo(persistentID); } /** * update the tab text on a dockable if it is in a tabbed panel * * @param dockable The dockable to update */ public static void updateTabInfo(Dockable dockable) { instance.updateTabInfo(dockable); } /** * Add a new maximize listener. Will be called when a dockable is maximized * * @param listener Listener to add */ public static void addMaximizeListener(MaximizeListener listener) { instance.addMaximizeListener(listener); } /** * Remove a previously added maximize listener. No-op if the listener isn't in the list * * @param listener Listener to remove */ public static void removeMaximizeListener(MaximizeListener listener) { instance.removeMaximizeListener(listener); } /** * Add a new docking listener * * @param listener Listener to add */ public static void addDockingListener(DockingListener listener) { instance.addDockingListener(listener); } /** * Remove a docking listener * * @param listener Listener to remove */ public static void removeDockingListener(DockingListener listener) { instance.removeDockingListener(listener); } /** * Add a new floating frame listener * * @param listener Listener to add */ public static void addNewFloatingFrameListener(NewFloatingFrameListener listener) { DockingListeners.addNewFloatingFrameListener(listener); } /** * Remove a floating frame listener * * @param listener Listener to remove */ public static void removeNewFloatingFrameListener(NewFloatingFrameListener listener) { DockingListeners.removeNewFloatingFrameListener(listener); } public static void setUserDynamicDockableCreationListener(DynamicDockableCreationListener listener) { instance.setUserDynamicDockableCreationListener(listener); } public static DockingAPI getSingleInstance() { if (instance == null) { throw new RuntimeException("No docking instance available."); } return instance; } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false
andrewauclair/ModernDocking
https://github.com/andrewauclair/ModernDocking/blob/cb69cbcf9bad74d73b1e32de5f813e86872d20e6/docking-single-app/src/io/github/andrewauclair/moderndocking/app/ApplicationLayoutMenuItem.java
docking-single-app/src/io/github/andrewauclair/moderndocking/app/ApplicationLayoutMenuItem.java
/* 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 io.github.andrewauclair.moderndocking.app; import io.github.andrewauclair.moderndocking.layouts.ApplicationLayout; import io.github.andrewauclair.moderndocking.layouts.DockingLayouts; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JMenuItem; import javax.swing.JOptionPane; /** * Special JMenuItem which will restore an ApplicationLayout when selected */ public class ApplicationLayoutMenuItem extends JMenuItem implements ActionListener { /** * The name of the ApplicationLayout, used to get the layout from DockingLayouts */ private final String layoutName; /** * Create a new ApplicationLayoutMenuItem for the specified layout. The layout name will be used as the display text. * * @param layoutName Name of the ApplicationLayout this ApplicationLayoutMenuItem will restore */ public ApplicationLayoutMenuItem(String layoutName) { super(layoutName); this.layoutName = layoutName; addActionListener(this); } /** * Create a new ApplicationLayoutMenuItem for the specified layout * * @param layoutName Name of the ApplicationLayout this ApplicationLayoutMenuItem will restore * @param text Display text of the JMenuItem */ public ApplicationLayoutMenuItem(String layoutName, String text) { super(text); this.layoutName = layoutName; addActionListener(this); } @Override public void actionPerformed(ActionEvent e) { ApplicationLayout layout = DockingLayouts.getLayout(layoutName); if (layout == null) { JOptionPane.showMessageDialog(this, "Layout " + layoutName + " does not exist."); } else { DockingState.restoreApplicationLayout(layout); } } }
java
MIT
cb69cbcf9bad74d73b1e32de5f813e86872d20e6
2026-01-05T02:41:37.174237Z
false