Package adams.gui.core
Class DragAndDropTreeNodeCollection<N extends BaseTreeNode>
- java.lang.Object
-
- adams.gui.core.DragAndDropTreeNodeCollection<N>
-
- Type Parameters:
N
- the type of node to handle
- All Implemented Interfaces:
Transferable
,Serializable
,Iterable<N>
,Collection<N>
- Direct Known Subclasses:
ClassTreeNodeCollection
,TreeNodeCollection
public class DragAndDropTreeNodeCollection<N extends BaseTreeNode> extends Object implements Transferable, Serializable, Collection<N>
Helper class for drag-n-drop in the DragAndDropTree.- Version:
- $Revision$
- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description DragAndDropTreeNodeCollection(N[] nodes)
Initializes the collection with all the nodes.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(N e)
Adds the node.boolean
addAll(Collection<? extends N> c)
Adds all the elements of the collection to this one.void
clear()
Removes all nodes.boolean
contains(Object o)
Checks whether the object is stored among the nodes.boolean
containsAll(Collection<?> c)
Checks whether all the elements of the specified collection are available in this one.Object
getTransferData(DataFlavor flavor)
Returns the nodes as transferable object in the requested flavor.DataFlavor[]
getTransferDataFlavors()
Returns the supported flavors.boolean
isDataFlavorSupported(DataFlavor flavor)
Returns whether the flavor is supported (only stringFlavor supported).boolean
isEmpty()
Returns whether the collection is empty.Iterator<N>
iterator()
Returns an iterator over the nodes.boolean
remove(Object o)
Removes the object from the collection.boolean
removeAll(Collection<?> c)
Removes all the elements from the collection that are also in this one.boolean
retainAll(Collection<?> c)
Removes all elements but the ones from the specified collection from this one.int
size()
Returns the size of the collection.Object[]
toArray()
Returns the nodes as array.<N> N[]
toArray(N[] a)
Returns the nodes as array.Transferable
toTransferable()
Turns the node/userObject into a transferable string.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Collection
equals, hashCode, parallelStream, removeIf, spliterator, stream, toArray
-
-
-
-
Field Detail
-
m_Nodes
protected ArrayList<N extends BaseTreeNode> m_Nodes
the nodes.
-
-
Constructor Detail
-
DragAndDropTreeNodeCollection
public DragAndDropTreeNodeCollection(N[] nodes)
Initializes the collection with all the nodes.- Parameters:
nodes
- the nodes for the collection
-
-
Method Detail
-
size
public int size()
Returns the size of the collection.- Specified by:
size
in interfaceCollection<N extends BaseTreeNode>
- Returns:
- the number of nodes stored
-
isEmpty
public boolean isEmpty()
Returns whether the collection is empty.- Specified by:
isEmpty
in interfaceCollection<N extends BaseTreeNode>
- Returns:
- true if no nodes stored
-
contains
public boolean contains(Object o)
Checks whether the object is stored among the nodes.- Specified by:
contains
in interfaceCollection<N extends BaseTreeNode>
- Parameters:
o
- the object to look for- Returns:
- true if the object can be located
-
iterator
public Iterator<N> iterator()
Returns an iterator over the nodes.- Specified by:
iterator
in interfaceCollection<N extends BaseTreeNode>
- Specified by:
iterator
in interfaceIterable<N extends BaseTreeNode>
- Returns:
- the node iterator
-
toArray
public Object[] toArray()
Returns the nodes as array.- Specified by:
toArray
in interfaceCollection<N extends BaseTreeNode>
- Returns:
- the nodes
-
toArray
public <N> N[] toArray(N[] a)
Returns the nodes as array.- Specified by:
toArray
in interfaceCollection<N extends BaseTreeNode>
- Parameters:
a
- the array to use- Returns:
- the nodes
-
add
public boolean add(N e)
Adds the node.- Specified by:
add
in interfaceCollection<N extends BaseTreeNode>
- Parameters:
e
- the node to add- Returns:
- true if the collection was modified
-
remove
public boolean remove(Object o)
Removes the object from the collection.- Specified by:
remove
in interfaceCollection<N extends BaseTreeNode>
- Parameters:
o
- the object to remove- Returns:
- true if the collection was modified
-
containsAll
public boolean containsAll(Collection<?> c)
Checks whether all the elements of the specified collection are available in this one.- Specified by:
containsAll
in interfaceCollection<N extends BaseTreeNode>
- Parameters:
c
- the collection to use for checking
-
addAll
public boolean addAll(Collection<? extends N> c)
Adds all the elements of the collection to this one.- Specified by:
addAll
in interfaceCollection<N extends BaseTreeNode>
- Parameters:
c
- the collection to add- Returns:
- true if the collection was modified
-
removeAll
public boolean removeAll(Collection<?> c)
Removes all the elements from the collection that are also in this one.- Specified by:
removeAll
in interfaceCollection<N extends BaseTreeNode>
- Parameters:
c
- the collection to remove- Returns:
- true if the collection was modified
-
retainAll
public boolean retainAll(Collection<?> c)
Removes all elements but the ones from the specified collection from this one.- Specified by:
retainAll
in interfaceCollection<N extends BaseTreeNode>
- Parameters:
c
- the collection to retain- Returns:
- true if the collection was modified
-
clear
public void clear()
Removes all nodes.- Specified by:
clear
in interfaceCollection<N extends BaseTreeNode>
-
getTransferDataFlavors
public DataFlavor[] getTransferDataFlavors()
Returns the supported flavors.- Specified by:
getTransferDataFlavors
in interfaceTransferable
- Returns:
- the flavors
-
isDataFlavorSupported
public boolean isDataFlavorSupported(DataFlavor flavor)
Returns whether the flavor is supported (only stringFlavor supported).- Specified by:
isDataFlavorSupported
in interfaceTransferable
- Parameters:
flavor
- the flavor to check- Returns:
- true if supported
-
getTransferData
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException
Returns the nodes as transferable object in the requested flavor.- Specified by:
getTransferData
in interfaceTransferable
- Parameters:
flavor
- the requested flavor- Returns:
- the converted nodes
- Throws:
UnsupportedFlavorException
- if the flavor is not supportedIOException
- if an IO operation fails
-
toTransferable
public Transferable toTransferable()
Turns the node/userObject into a transferable string. One node per line, separated by "\n", string representation obtained via the node's toString() method.- Returns:
- the generated string
-
-