public class Context extends AbstractCollection<Object>
Command
s.
The Context has just one owner, a JComponent
. A reference to this owner is
held inside the context. The Context is stored as ClientProperty of the owner.
Both, a FocusListener
and a ContainerListener
will
be created for and registered with the owner.
The context contains references on its own child contexts on which it is registered as a
ContextListener
.
The context contains the collection of the components from the child contexts as cachedActiveChildsContextObjects. The context objects contains information for the commands. (For example: items, session, viewer...).
The contexts form a hierarchy reflecting the Component
hierarchy of the application's UI.
Command
,
CommandAction
,
ContextListener
Modifier and Type | Class and Description |
---|---|
static class |
Context.Ancestors
Enum used to determine whether the aggregated view includes elements of ancestor (parent,
grand-parent etc.) contexts.
|
static class |
Context.Children
Enum used to determine whether the aggregated view includes elements of child contexts.
|
Modifier and Type | Field and Description |
---|---|
static String |
PROPERTY_KEY
The ClientProperty key used by the GUI Component to store its context object in.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(Object o)
Ensures that this collection contains the specified element (optional operation).
|
void |
addChildContext(Context child)
Adds the context as child context and registers itself as
ContextListener . |
void |
addContextChangeListener(ContextListener contextListener)
Adds
ContextListener to the collection of the listeners. |
static boolean |
changed(JComponent c)
Propagate a context change for the Context associated with the given component.
|
void |
clear()
Removes all of the elements from this collection (optional operation).
|
void |
clearContextListeners()
Removes all
ContextListener from the collection of listeners. |
void |
contextChanged()
Propagate context changes to all parent contexts and actions that are registered as
ContextListener . |
static Context |
create(Context.Children ca,
Context.Ancestors aa)
Create an owner-less context with the given aggregation modes.
|
static Context |
get(JComponent component)
Get the context for a given component by looking at the client properties.
|
protected Collection<Context> |
getChildren()
Returns the child contexts.
|
JComponent |
getOwner()
Returns the owner.
|
Context |
getParent()
Return the parent context.
|
static Context |
getPrivateContext(JComponent component)
Get the context for a given component by looking at the client properties.
|
protected Collection<ContextListener> |
getRegisteredListeners()
Method getRegisteredListeners -
ContextListener . |
static Context |
install(JComponent owner,
Context.Children ca,
Context.Ancestors aa)
Install a context with the given aggregation mode on the given owner.
|
boolean |
isActive()
Returns the info if the context is active.
|
Iterator<Object> |
iterator()
Returns an iterator over the elements in this context.
|
boolean |
remove(Object o)
Removes a single instance of the specified element from this collection, if it is present
(optional operation).
|
void |
removeChildContext(Context child)
Removes the context from the collection of child contexts and unregisters itself as
ContextListener . |
void |
removeContextChangeListener(ContextListener contextListener)
Removes
ContextListener from the collection of listeners so that it doesn't receive
notifications any longer. |
void |
setActive(boolean active)
Sets the active.
|
int |
size()
Returns the number of elements in this collection.
|
String |
toString() |
addAll, contains, containsAll, isEmpty, removeAll, retainAll, toArray, toArray
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
equals, hashCode, parallelStream, removeIf, spliterator, stream
public static String PROPERTY_KEY
public static Context get(JComponent component)
component
- The JComponent
within which the Context
will be searched for. null
if no component in the hierarchy had a context.public static boolean changed(JComponent c)
c
- the changed componenttrue
if there was a context to which the change could be propagated,
false
otherwise.public static Context getPrivateContext(JComponent component)
null
if it doesn't have one. In contrast to get(JComponent)
,this method
doesn't look at ancestors in the component hierarchy.component
- component null
if no component in the hierarchy had a context.public static Context install(JComponent owner, Context.Children ca, Context.Ancestors aa)
owner
- the owner of this contextca
- the child aggregation mode.aa
- the ancestor aggregation mode.public static Context create(Context.Children ca, Context.Ancestors aa)
ca
- the child aggregation mode.aa
- the ancestor aggregation mode.public Iterator<Object> iterator()
iterator
in interface Iterable<Object>
iterator
in interface Collection<Object>
iterator
in class AbstractCollection<Object>
Iterator
over the elements in this context and possibly other contexts,
depending on aggregation modes.public void addChildContext(Context child)
ContextListener
.child
- which should be registered in the contextpublic void removeChildContext(Context child)
ContextListener
.child
- which should be removed from the list of the contextpublic void addContextChangeListener(ContextListener contextListener)
ContextListener
to the collection of the listeners. Information about context
changes is sent to listeners registered here.contextListener
- to add to the collection of listeners.ContextListener
public void removeContextChangeListener(ContextListener contextListener)
ContextListener
from the collection of listeners so that it doesn't receive
notifications any longer.contextListener
- to remove from the collection of listeners.ContextListener
public void clearContextListeners()
ContextListener
from the collection of listeners.ContextListener
public void contextChanged()
ContextListener
.ContextListener.contextChanged(Context)
public boolean add(Object o)
true
if this collection changed as a result of the call. (Returns false
if this collection does not permit duplicates and already contains the specified element.)
Collections that support this operation may place limitations on what elements may be added to
this collection. In particular, some collections will refuse to add null
elements,
and others will impose restrictions on the type of elements that may be added. Collection classes
should clearly specify in their documentation any restrictions on what elements may be added.
If a collection refuses to add a particular element for any reason other than that it already
contains the element, it must throw an exception (rather than returning
false
). This preserves the invariant that a collection always contains the
specified element after this call returns.
add
in interface Collection<Object>
add
in class AbstractCollection<Object>
o
- element whose presence in this collection is to be ensured.true
if this collection changed as a result of the callUnsupportedOperationException
- add
is not supported by this collection.ClassCastException
- class of the specified element prevents it from being added to this
collection.NullPointerException
- if the specified element is null and this collection does not
support null elements.IllegalArgumentException
- some aspect of this element prevents it from being added to this
collection.public void clear()
clear
in interface Collection<Object>
clear
in class AbstractCollection<Object>
UnsupportedOperationException
- if the clear
method is not supported by this
collection.public boolean remove(Object o)
e
such that
(o==null ? e==null : o.equals(e))
, if this collection contains one or more such
elements. Returns true if this collection contained the specified element (or equivalently, if
this collection changed as a result of the call).remove
in interface Collection<Object>
remove
in class AbstractCollection<Object>
o
- element to be removed from this collection, if present.true
if this collection changed as a result of the callClassCastException
- if the type of the specified element is incompatible with this
collection (optional).NullPointerException
- if the specified element is null and this collection does not
support null elements (optional).UnsupportedOperationException
- remove is not supported by this collection.public int size()
Integer.MAX_VALUE
elements, returns Integer.MAX_VALUE
.size
in interface Collection<Object>
size
in class AbstractCollection<Object>
public boolean isActive()
public void setActive(boolean active)
active
- true
- active, false
- not active.protected Collection<Context> getChildren()
protected Collection<ContextListener> getRegisteredListeners()
ContextListener
.public JComponent getOwner()
public String toString()
toString
in class AbstractCollection<Object>
public Context getParent()
Copyright © 2024 levigo holding gmbh. All rights reserved.