Class ALspInteractiveLabelProvider
An ALspInteractiveLabelProvider
can provide a java.awt.Component
that can be shown to the user so he can modify the properties of the object. One can think of
this Component
as a rich, interactive label.
This provider is used by TLspInteractiveLabelsController
to provide an
interactive label when the user moves his mouse cursor over one of its labels. This provider is
asked if it can provide a Component
for the label with the canStartInteraction
method, and if it can it is then asked to provide
Component
for it with the startInteraction
method.
At all times there will be at most one interactive label active from a single
ALspInteractiveLabelProvider
. This means implementations can return the same
java.awt.Component
instance every time they are asked to provide an interactive
label.
Between two calls to startInteraction
, the label interaction will always be
stopped, either with stopInteraction
or otherwise with cancelInteraction
.
When it is needed to update an interactive labels during interaction, it is possible to
adjust the interactive label returned by startInteraction
. For example when an
interactive label contains a field with the location of its (moving) object, this label
can be updated by registering a model listener, listening to changes, and adjusting the
location text field when needed.
After modifying the interactive label during interaction, it is possible that its size
has changed. Implementations of this class should send a notification of this. This can be
done by calling fireInteractiveLabelChangedEvent
. To make sure that interactive labels are properly updated
because of a model change, updateInteractiveLabel()
is called. The implementation of
this call should make sure that interactive labels are properly updated, and that a change event
if fired.
- Since:
- 2012.0
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds achange listener
that is notified if an interactive label has changed.void
Adds aLabelInteractionListener
.abstract void
Cancels the interaction with the interactive label that was last provided.abstract boolean
canStartInteraction
(TLspLabelID aLabel, TLspContext aContext) This method determines whether or not thisALspInteractiveLabelProvider
can provide aComponent
for the specified label.abstract boolean
Returns whether or not the interactive label that was last provided can be stopped.protected void
This method should be called to fire an 'interaction cancelled' event.protected final void
fireInteractionStartedEvent
(TLspLabelID aLabel, TLspContext aContext, Component aInteractiveLabel) This method should be called to fire an 'interaction started' event.protected void
This method should be called to fire an 'interaction stopped' event.protected final void
Fire an event to notify that the interactive label has changed.void
Removes a givenchange listener
.void
Removes the givenLabelInteractionListener
.abstract Component
startInteraction
(TLspLabelID aLabel, TLspContext aContext) Returns a component, configured to display or edit the properties of the given view identifier.abstract boolean
Tells the interactive label that was last provided to stop editing.void
Updates the label while it is interactive.
-
Constructor Details
-
ALspInteractiveLabelProvider
public ALspInteractiveLabelProvider()
-
-
Method Details
-
canStartInteraction
This method determines whether or not this
ALspInteractiveLabelProvider
can provide aComponent
for the specified label. This method should be called before callingstartInteraction
.- Parameters:
aLabel
- The label for which to determine if aComponent
can be provided.aContext
- The context.- Returns:
true
if thisALspInteractiveLabelProvider
can provide aComponent
for the specified identifier,false
otherwise.
-
startInteraction
Returns a component, configured to display or edit the properties of the given view identifier. Before this method is called again, either
stopInteraction
orcancelInteraction
will be called - depending on user interaction - allowing the implementation to perform any necessary cleanup operations.This method will not be called unless
canStartInteraction
returns true for the same arguments.- Parameters:
aLabel
- The label for which theComponent
is requested.aContext
- The context.- Returns:
- A
Component
, configured to display or edit the properties of the given label.
-
canStopInteraction
public abstract boolean canStopInteraction()Returns whether or not the interactive label that was last provided can be stopped. For instance, if the interactive label is in a non-valid state, this method should return
false
.- Returns:
true
if the interactive label can be stopped,false
otherwise.- See Also:
-
stopInteraction
public abstract boolean stopInteraction()Tells the interactive label that was last provided to stop editing. Any outstanding changes should be persisted when this method is called.
This method is always called after the call to
startInteraction
and before the provided component is removed from the user interface.This method returns a boolean indicating whether or not the interactive label could be stopped. If the interactive label could not be stopped, this provider could choose to change the interactive label to visually indicate what prevents it from being stopped. For instance, if a text field in the interactive label contained invalid text, the text in the text field could be shown in red.
This method should return the same value as the
canStopInteraction
method. The reason that method exists is that that method does not imply that the client actually wants to stop, whereas this method does.- Returns:
true
if the interactive label could be stopped,false
otherwise.- See Also:
-
cancelInteraction
public abstract void cancelInteraction()Cancels the interaction with the interactive label that was last provided. Any outstanding changes should be discarded when this method is called.
This method is always called after the call to
startInteraction
and before the provided component is removed from the user interface. -
updateInteractiveLabel
public void updateInteractiveLabel()Updates the label while it is interactive. This can for example be needed when the domain object changes. In that case, this method should be overridden. The implementation should:
- Update the currently interactive label, for example by updating its
JLabel
s or other Swing components. - Call super.updateInteractiveLabel() at the end. This will make sure that a change event is fired.
This method is automatically called by
ALspSwingLabelStyler
when a model change event occurs for the currently interactive label. Because this method causes a change event to be fired,TLspInteractiveLabelsController
is notified as well.On the other hand, when a user action (for example a click on a button) causes the interactive label to be changed, this method can be called to make the actual change. Because this method should fire a change event, the styler and the
TLspInteractiveLabelsController
are notified of the change.- Since:
- 2016.0
- Update the currently interactive label, for example by updating its
-
addLabelInteractionListener
Adds aLabelInteractionListener
. This listener should be used to notify when interaction with an interactive label was stopped or cancelled.- Parameters:
aListener
- aLabelInteractionListener
.
-
removeLabelInteractionListener
Removes the givenLabelInteractionListener
. After calling this method, the given listener will not be notified when interaction with an interactive label was stopped or cancelled anymore.- Parameters:
aListener
- aLabelInteractionListener
.
-
fireInteractionStartedEvent
protected final void fireInteractionStartedEvent(TLspLabelID aLabel, TLspContext aContext, Component aInteractiveLabel) This method should be called to fire an 'interaction started' event. This method will call all listeners that were registered usingaddLabelInteractionListener
. Implementations should call this method when interaction has started.- Parameters:
aLabel
- the label.aContext
- the context.aInteractiveLabel
- the component used for the interactive label.- See Also:
-
fireInteractionStoppedEvent
protected void fireInteractionStoppedEvent()This method should be called to fire an 'interaction stopped' event. This method will call all listeners that were registered usingaddLabelInteractionListener
. Implementations should call this method when interaction has stopped.- See Also:
-
fireInteractionCancelledEvent
protected void fireInteractionCancelledEvent()This method should be called to fire an 'interaction cancelled' event. This method will call all listeners that were registered usingaddLabelInteractionListener
. Implementations should call this method when interaction has been cancelled.- See Also:
-
addInteractiveLabelChangeListener
Adds achange listener
that is notified if an interactive label has changed.- Parameters:
aListener
- a change listener- See Also:
-
removeInteractiveLabelChangeListener
Removes a givenchange listener
.- Parameters:
aListener
- a change listener- See Also:
-
fireInteractiveLabelChangedEvent
protected final void fireInteractiveLabelChangedEvent()Fire an event to notify that the interactive label has changed. This can for example be used when the interactive label is modified at runtime.
-