Package edu.wpi.grip.ui.util
Class ControllerMap<C extends Controller,N extends javafx.scene.Node>
- java.lang.Object
-
- edu.wpi.grip.ui.util.ControllerMap<C,N>
-
- Type Parameters:
C
- The Controller type for ever node in this list.N
- The type of the Node being mapped to a Controller.
- All Implemented Interfaces:
java.util.Map<C,N>
public final class ControllerMap<C extends Controller,N extends javafx.scene.Node> extends java.lang.Object implements java.util.Map<C,N>
Keeps track of the Nodes in an observable list and provides mapping from aNode
to its respectiveController
. This makes it easy to keep track of what controller is mapped to what node without having to use a secondary backing list with index comparisons. This utility also provides helpful functionality like sorting the nodes in the list using a comparator.
-
-
Constructor Summary
Constructors Constructor Description ControllerMap(javafx.collections.ObservableList<N> nodesList)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(int index, C controller)
Adds the Node from this controller to the specified index in the observable list.boolean
add(C controller)
Adds a controller to the map.boolean
addAll(int index, java.util.Collection<C> controllers)
Adds all of the Nodes from this collection of controllers to the observable list at the specified index in the Observable List.boolean
addAll(C... controllers)
Adds multiple controllers to the map at once.boolean
addAll(java.util.Collection<C> controllers)
Adds multiple controllers to the map at once.void
clear()
boolean
containsKey(java.lang.Object key)
boolean
containsValue(java.lang.Object value)
java.util.Set<java.util.Map.Entry<C,N>>
entrySet()
N
get(java.lang.Object key)
C
getWithNode(N node)
Gets the Controller that maps to a specific Node.boolean
isEmpty()
java.util.Set<C>
keySet()
void
moveByDistance(C controller, int distance)
Moves the Node that is owned by this controller the specified distance.N
put(C key, N value)
void
putAll(java.util.Map<? extends C,? extends N> m)
N
remove(java.lang.Object key)
N
removeWithController(C controller)
Remove the Controller and the controllers Node.boolean
removeWithNode(N node)
Remove the Node and the nodes Controller.int
size()
void
sort(java.util.Comparator<? super C> c)
Allows sorting of the nodes using their respective controllersjava.util.Collection<N>
values()
-
-
-
Constructor Detail
-
ControllerMap
public ControllerMap(javafx.collections.ObservableList<N> nodesList)
- Parameters:
nodesList
- The list that that will be managed.
-
-
Method Detail
-
removeWithController
public N removeWithController(C controller)
Remove the Controller and the controllers Node.- Parameters:
controller
- The controller to remove- Returns:
- The Node that was removed from the list
-
removeWithNode
public boolean removeWithNode(N node)
Remove the Node and the nodes Controller.- Parameters:
node
- The Node to remove- Returns:
- true if successfully removed.
-
add
public boolean add(int index, C controller)
Adds the Node from this controller to the specified index in the observable list.- Parameters:
index
- The index to place the Nodecontroller
- The controller to get the node from- Returns:
true
if the observable list changed as a result of the call- See Also:
List.add(int, Object)
-
add
public boolean add(C controller)
Adds a controller to the map.- See Also:
List.add(Object)
-
addAll
public boolean addAll(int index, java.util.Collection<C> controllers)
Adds all of the Nodes from this collection of controllers to the observable list at the specified index in the Observable List.- Parameters:
index
- The index to place the nodescontrollers
- The controllers to get the nodes from- Returns:
true
if the observable list changed as a result of the call- See Also:
List.addAll(int, Collection)
-
addAll
public boolean addAll(java.util.Collection<C> controllers)
Adds multiple controllers to the map at once.- See Also:
List.addAll(Collection)
-
addAll
public boolean addAll(C... controllers)
Adds multiple controllers to the map at once.- See Also:
List.addAll(Collection)
-
getWithNode
public C getWithNode(N node)
Gets the Controller that maps to a specific Node.- Parameters:
node
- The node to do the lookup with.- Returns:
- The Controller that controls this node
-
moveByDistance
public void moveByDistance(C controller, int distance)
Moves the Node that is owned by this controller the specified distance.- Parameters:
controller
- The controller to use as a lookup key for the movedistance
- The distance to move the node. 0 means no movement.
-
put
public N put(C key, N value)
- Specified by:
put
in interfacejava.util.Map<C extends Controller,N extends javafx.scene.Node>
-
size
public int size()
- Specified by:
size
in interfacejava.util.Map<C extends Controller,N extends javafx.scene.Node>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty
in interfacejava.util.Map<C extends Controller,N extends javafx.scene.Node>
-
containsKey
public boolean containsKey(java.lang.Object key)
- Specified by:
containsKey
in interfacejava.util.Map<C extends Controller,N extends javafx.scene.Node>
-
containsValue
public boolean containsValue(java.lang.Object value)
- Specified by:
containsValue
in interfacejava.util.Map<C extends Controller,N extends javafx.scene.Node>
-
get
public N get(java.lang.Object key)
- Specified by:
get
in interfacejava.util.Map<C extends Controller,N extends javafx.scene.Node>
-
remove
public N remove(java.lang.Object key)
- Specified by:
remove
in interfacejava.util.Map<C extends Controller,N extends javafx.scene.Node>
-
putAll
public void putAll(java.util.Map<? extends C,? extends N> m)
- Specified by:
putAll
in interfacejava.util.Map<C extends Controller,N extends javafx.scene.Node>
-
clear
public void clear()
- Specified by:
clear
in interfacejava.util.Map<C extends Controller,N extends javafx.scene.Node>
-
keySet
public java.util.Set<C> keySet()
- Specified by:
keySet
in interfacejava.util.Map<C extends Controller,N extends javafx.scene.Node>
- Returns:
- An unmodifiable set of of keys for this map.
-
values
public java.util.Collection<N> values()
- Specified by:
values
in interfacejava.util.Map<C extends Controller,N extends javafx.scene.Node>
- Returns:
- An unmodifiable set of of values for this map.
-
entrySet
public java.util.Set<java.util.Map.Entry<C,N>> entrySet()
- Specified by:
entrySet
in interfacejava.util.Map<C extends Controller,N extends javafx.scene.Node>
-
sort
public void sort(java.util.Comparator<? super C> c)
Allows sorting of the nodes using their respective controllers- Parameters:
c
- Controller comparator to use.
-
-