public final class InstanceContent extends AbstractLookup.Content
InstanceContent
ic = newInstanceContent()
;Lookup
lookup = newAbstractLookup(ic)
; ic.add(new Object ())
; ic.add(new Dimension (...))
;Dimension
theDim = lookup.lookup (Dimension
.class);
Modifier and Type | Class and Description |
---|---|
static interface |
InstanceContent.Convertor<T,R>
Convertor postpones an instantiation of an object.
|
Constructor and Description |
---|
InstanceContent()
Create a new, empty content.
|
InstanceContent(Executor notifyIn)
Creates a content associated with an executor to handle dispatch
of changes.
|
Modifier and Type | Method and Description |
---|---|
void |
add(Object inst)
Adds an instance to the lookup.
|
<T,R> void |
add(T inst,
InstanceContent.Convertor<T,R> conv)
Adds a convertible instance into the lookup.
|
void |
remove(Object inst)
Remove instance.
|
<T,R> void |
remove(T inst,
InstanceContent.Convertor<T,R> conv)
Remove instance added with a convertor.
|
<T,R> void |
set(Collection<T> col,
InstanceContent.Convertor<T,R> conv)
Changes all pairs in the lookup to new values.
|
addPair, removePair, setPairs
public InstanceContent()
public InstanceContent(Executor notifyIn)
notifyIn
- the executor to notify changes inpublic final void add(Object inst)
inst
already exists
in the lookup (equality is determined by object's Object.equals(java.lang.Object)
method) then the new instance replaces the old one
in the lookup but listener notifications are not delivered in
such case.inst
- instancepublic final <T,R> void add(T inst, InstanceContent.Convertor<T,R> conv)
inst
argument is just a key, not the actual value to appear in the lookup.
The value will be created on demand, later when it is really needed
by calling convertor
methods.
This method is useful to delay creation of heavy weight objects. Instead just register lightweight key and a convertor.
To remove registered object from lookup use InstanceContent.remove(java.lang.Object, org.openide.util.lookup.InstanceContent.Convertor)
with the same arguments.
T
- type of instanceR
- type to convert instance toinst
- instanceconv
- convertor which postponing an instantiation,
if conv==null
then the instance is registered directly.public final void remove(Object inst)
inst
- instancepublic final <T,R> void remove(T inst, InstanceContent.Convertor<T,R> conv)
T
- type of instanceR
- type to convert instance toinst
- instanceconv
- convertor, if conv==null
it is same like
remove(Object)public final <T,R> void set(Collection<T> col, InstanceContent.Convertor<T,R> conv)
T
- type of instanceR
- type to convert instance tocol
- the collection of (Item) objectsconv
- the convertor to use or null