M
- The type of model that the controller will operate on.V
- The type of view that the controller will operate on.public abstract class Controller<M extends Model,V extends View>
extends java.lang.Object
Controller
class describes all the basic functionality of a
controller within the MVC architecture.
From Wikipedia:
A controller can send commands to the model to update the model's state (e.g., editing a document). It can also send commands to its associated view to change the view's presentation of the model (e.g., by scrolling through a document).
Constructor and Description |
---|
Controller(Application application)
Initialize a new
Controller instance for the specified
Application . |
Modifier and Type | Method and Description |
---|---|
protected Application |
application()
Access the
Application that the Controller is associated
with. |
protected boolean |
emit(java.lang.String event)
Emit an event with the specified name.
|
protected <T> boolean |
emit(java.lang.String event,
T data)
Emit an event with the specified name and data.
|
protected M |
model()
Access the
Model that the Controller operates on. |
protected <T> boolean |
off(java.lang.String event,
java.util.function.Consumer<T> consumer)
Detach a
Consumer from the specified event. |
protected <T> boolean |
on(java.lang.String event,
java.util.function.Consumer<T> consumer)
Attach a
Consumer to the specified event. |
protected V |
view()
Access the
View that the Controller operates on. |
public Controller(Application application)
Controller
instance for the specified
Application
.application
- The Application
that the Controller
is
associated with.protected final Application application()
Application
that the Controller
is associated
with.Application
that the Controller
is associated
with.protected final M model()
Model
that the Controller
operates on.Model
that the Controller
operates on.protected final V view()
View
that the Controller
operates on.View
that the Controller
operates on.protected final boolean emit(java.lang.String event)
event
- The name of the event to emit.Consumer
.protected final <T> boolean emit(java.lang.String event, T data)
T
- The type of data to utilize in Consumers
.event
- The name of the event to emit.data
- The data to pass on to Consumers
.Consumer
.protected final <T> boolean on(java.lang.String event, java.util.function.Consumer<T> consumer)
Consumer
to the specified event.T
- The type of data to utilize in Consumers
.event
- The name of the event to attach the Consumer
to.consumer
- The Consumer
to attach to the specified event.Consumers
attached to the
specified event.protected final <T> boolean off(java.lang.String event, java.util.function.Consumer<T> consumer)
Consumer
from the specified event.T
- The type of data to utilize in Consumers
.event
- The name of the event to detach the Consumer
from.consumer
- The Consumer
to detach from the specified event.Consumers
attached to the
specified event.