bibliothek.gui.dock.util
Class DockUtilities

java.lang.Object
  extended by bibliothek.gui.dock.util.DockUtilities

public class DockUtilities
extends Object

A list of methods which can be used for different purposes. Methods related to the DockTheme can be found in DockUI.

Author:
Benjamin Sigg

Nested Class Summary
static class DockUtilities.DockVisitor
          A visitor used to visit the nodes of a dock-tree.
 
Constructor Summary
DockUtilities()
           
 
Method Summary
static boolean acceptable(DockStation parent, Dockable child)
          Tells whether the Dockable child can be dropped over parent.
static boolean acceptable(DockStation parent, Dockable old, Dockable next)
          Tells whether the Dockable next can be dropped over old.
static DockableProperty append(DockableProperty root, DockableProperty property)
          Creates a copy of root and sets property as the successor of the very last element in the property chain beginning at root.
static void checkLayoutLocked()
          Searches for a class or interface that is marked with LayoutLocked in the current callstack and prints a warning if found.
static void disableCheckLayoutLocked()
          Ensures that checkLayoutLocked() never prints out any warnings.
static Icon disabledIcon(JComponent parent, Icon icon)
          Gets a "disabled" icon according to the current look and feel.
static void ensureTreeValidity(DockStation newParent, Dockable newChild)
          Ensures that newChild has no parent, and that there will be no cycle when newChild is added to newParent
static void ensureTreeValidity(PerspectiveStation newParent, PerspectiveDockable newChild)
          Ensures that newChild has either no parent or newParent as parent, and that there will be no cycle when newChild is added to newParent
static Dockable getDirectChild(DockStation parent, Dockable subchild)
          Searches the one Dockable that is either subchild or a parent of subchild and whose parent is parent.
static DockableProperty getLastProperty(DockableProperty property)
          Gets the last successor in the property chain beginning at property.
static DockableProperty getPropertyChain(Dockable dockable)
          Gets a DockableProperty which describes the path from the root to dockable.
static DockableProperty getPropertyChain(DockStation ground, Dockable dockable)
          Creates a DockableProperty describing the path from ground to dockable.
static DockableProperty getPropertyChain(PerspectiveStation ground, PerspectiveDockable dockable)
          Creates a DockableProperty describing the path from ground to dockable.
static DockStation getRoot(DockElement element)
          Searches the station which is an ancestor of element and has no parent.
static Component getShowingComponent(Dockable dockable)
          Searches a Component which is showing and has something to do with dockable.
This method first checks Dockable and DockTitles, then it checks all DockElementRepresentatives.
static Image iconImage(Icon icon)
          Transforms icon into an image.
static boolean isAncestor(DockElement ancestor, DockElement child)
          Tells whether child is identical with ancestor or a child of ancestor.
static boolean isAncestor(PerspectiveElement ancestor, PerspectiveElement child)
          Tells whether child is identical with ancestor or a child of ancestor.
static List<Dockable> listDockables(DockElement root, boolean includeRoot)
          Lists all Dockables in the tree under root.
static Map<String,Icon> loadIcons(String list, String path, ClassLoader loader)
          Loads a map of icons.
static Map<String,Icon> loadIcons(String list, String path, Set<String> ignore, ClassLoader loader)
          Loads a map of icons.
static Path[] mergePlaceholders(Path[] base, Dockable dockable, PlaceholderStrategy strategy)
          Merges the array base with the placeholder that is associated with dockable, but only if that placeholder is not yet in base.
static void visit(Dockable dockable, DockUtilities.DockVisitor visitor)
          Visits dockable and all its children.
static void visit(DockElement element, DockUtilities.DockVisitor visitor)
          Visits element and all its children.
static void visit(DockStation station, DockUtilities.DockVisitor visitor)
          Visits station and all its children.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DockUtilities

public DockUtilities()
Method Detail

visit

public static void visit(Dockable dockable,
                         DockUtilities.DockVisitor visitor)
Visits dockable and all its children.

Parameters:
dockable - the first element to visit
visitor - a delegate

visit

public static void visit(DockStation station,
                         DockUtilities.DockVisitor visitor)
Visits station and all its children.

Parameters:
station - the first element to visit
visitor - a delegate

visit

public static void visit(DockElement element,
                         DockUtilities.DockVisitor visitor)
Visits element and all its children.

Parameters:
element - the first element to visit
visitor - a delegate

listDockables

public static List<Dockable> listDockables(DockElement root,
                                           boolean includeRoot)
Lists all Dockables in the tree under root.

Parameters:
root - the root of a tree of elements
includeRoot - whether root should be in the resulting list as well
Returns:
the list of found Dockables, might be empty but not null

isAncestor

public static boolean isAncestor(DockElement ancestor,
                                 DockElement child)
Tells whether child is identical with ancestor or a child of ancestor.

Parameters:
ancestor - an element
child - another element
Returns:
true if ancestor is a parent of or identical with child.

isAncestor

public static boolean isAncestor(PerspectiveElement ancestor,
                                 PerspectiveElement child)
Tells whether child is identical with ancestor or a child of ancestor.

Parameters:
ancestor - an element
child - another element
Returns:
true if ancestor is a parent of or identical with child.

getRoot

public static DockStation getRoot(DockElement element)
Searches the station which is an ancestor of element and has no parent.

Parameters:
element - the element whose oldest parent is searched
Returns:
the root, may be null if element has no parent

getDirectChild

public static Dockable getDirectChild(DockStation parent,
                                      Dockable subchild)
Searches the one Dockable that is either subchild or a parent of subchild and whose parent is parent.

Parameters:
parent - the parent of the result
subchild - a direct or indirect child of parent
Returns:
the child or null if subchild is no child of parent

append

public static DockableProperty append(DockableProperty root,
                                      DockableProperty property)
Creates a copy of root and sets property as the successor of the very last element in the property chain beginning at root.

Parameters:
root - the root of the chain, can be null
property - the new last element of the chain
Returns:
the root of the new chain

getLastProperty

public static DockableProperty getLastProperty(DockableProperty property)
Gets the last successor in the property chain beginning at property.

Parameters:
property - the start of the chain
Returns:
the end of the chain

getPropertyChain

public static DockableProperty getPropertyChain(Dockable dockable)
Gets a DockableProperty which describes the path from the root to dockable.

Parameters:
dockable - a Dockable whose location is searched
Returns:
the properties or null if dockable has no parent

getPropertyChain

public static DockableProperty getPropertyChain(DockStation ground,
                                                Dockable dockable)
Creates a DockableProperty describing the path from ground to dockable.

Parameters:
ground - the base of the property
dockable - an indirect child of ground
Returns:
a property for the path ground to dockable.
Throws:
IllegalArgumentException - if ground is not an ancestor of dockable

getPropertyChain

public static DockableProperty getPropertyChain(PerspectiveStation ground,
                                                PerspectiveDockable dockable)
Creates a DockableProperty describing the path from ground to dockable.

Parameters:
ground - the base of the property
dockable - an indirect child of ground
Returns:
a property for the path ground to dockable.
Throws:
IllegalArgumentException - if ground is not an ancestor of dockable

getShowingComponent

public static Component getShowingComponent(Dockable dockable)
Searches a Component which is showing and has something to do with dockable.
This method first checks Dockable and DockTitles, then it checks all DockElementRepresentatives.

Parameters:
dockable - a Dockable for which a Component has to be found
Returns:
a showing component or null

ensureTreeValidity

public static void ensureTreeValidity(DockStation newParent,
                                      Dockable newChild)
Ensures that newChild has no parent, and that there will be no cycle when newChild is added to newParent

Parameters:
newParent - the element that becomes parent of newChild
newChild - the element that becomes child of newParent
Throws:
NullPointerException - if either newParent or newChild is null
IllegalArgumentException - if there would be a cycle introduced
IllegalStateException - if the old parent of newChild does not allow to remove its child

ensureTreeValidity

public static void ensureTreeValidity(PerspectiveStation newParent,
                                      PerspectiveDockable newChild)
Ensures that newChild has either no parent or newParent as parent, and that there will be no cycle when newChild is added to newParent

Parameters:
newParent - the element that becomes parent of newChild
newChild - the element that becomes child of newParent
Throws:
NullPointerException - if either newParent or newChild is null
IllegalArgumentException - if there would be a cycle introduced
IllegalStateException - if the old parent of newChild does not allow to remove its child

disabledIcon

public static Icon disabledIcon(JComponent parent,
                                Icon icon)
Gets a "disabled" icon according to the current look and feel.

Parameters:
parent - the component on which the icon will be painted, can be null
icon - an icon or null
Returns:
a disabled version of icon or null

iconImage

public static Image iconImage(Icon icon)
Transforms icon into an image.

Parameters:
icon - some icon
Returns:
the image of the icon or null

loadIcons

public static Map<String,Icon> loadIcons(String list,
                                         String path,
                                         ClassLoader loader)
Loads a map of icons.

Parameters:
list - a path to a property-file containing key-path-pairs.
path - the base path to the icons, will be added before any path of the property file, can be null
loader - used to transform paths into urls.
Returns:
the map of Icons, the map can be empty if no icons were found
See Also:
Properties.load(InputStream)

loadIcons

public static Map<String,Icon> loadIcons(String list,
                                         String path,
                                         Set<String> ignore,
                                         ClassLoader loader)
Loads a map of icons.

Parameters:
list - a path to a property-file containing key-path-pairs.
path - the base path to the icons, will be added before any path of the property file, can be null
ignore - keys that are already present in ignore are not loaded, can be null
loader - used to transform paths into urls.
Returns:
the map of Icons, the map can be empty if no icons were found
See Also:
Properties.load(InputStream)

mergePlaceholders

public static Path[] mergePlaceholders(Path[] base,
                                       Dockable dockable,
                                       PlaceholderStrategy strategy)
Merges the array base with the placeholder that is associated with dockable, but only if that placeholder is not yet in base.

Parameters:
base - some basic array, can be null
dockable - the dockable whose placeholder is to be stored, can be null
strategy - a strategy to find the placeholder of dockable, can be null
Returns:
either a new and larger array than base, base itself, or null if base was null and no additional placeholder was found

acceptable

public static boolean acceptable(DockStation parent,
                                 Dockable child)
Tells whether the Dockable child can be dropped over parent.

Parameters:
parent - the new parent
child - the new child
Returns:
true if the parent and the child accept each other

acceptable

public static boolean acceptable(DockStation parent,
                                 Dockable old,
                                 Dockable next)
Tells whether the Dockable next can be dropped over old.

Parameters:
parent - the parent of old
old - the existing child
next - the new child
Returns:
true if the parent and the child accept each other

disableCheckLayoutLocked

public static void disableCheckLayoutLocked()
Ensures that checkLayoutLocked() never prints out any warnings.


checkLayoutLocked

public static void checkLayoutLocked()
Searches for a class or interface that is marked with LayoutLocked in the current callstack and prints a warning if found.