M
- The type of model that the view will operate on. This can be
omitted if no model will ever be operated on by the view.C
- The type of controller that will operate on the view. This can be
omitted if no controller will ever operate on the view.public abstract class View<M extends Model,C extends Controller>
extends java.lang.Object
View
class describes all the basic functionality of a view
within the MVC architecture.
From Wikipedia:
A view requests information from the model that it uses to generate an output representation to the user.
Constructor and Description |
---|
View(Application application)
Initialize a new
View instance for the specified
Application . |
Modifier and Type | Method and Description |
---|---|
protected Application |
application()
Access the
Application that the View is associated with. |
protected C |
controller()
Access the
Controller operating on the View . |
protected void |
controller(C controller)
Set the
Controller operating on the View . |
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()
|
protected void |
model(M model)
|
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. |
abstract javax.swing.JComponent |
render()
Render the
View as a Swing component. |
public View(Application application)
View
instance for the specified
Application
.application
- The Application
that the View
is
associated with.protected final Application application()
Application
that the View
is associated with.Application
that the View
is associated with.protected final C controller()
Controller
operating on the View
.Controller
operating on the View
.protected final void controller(C controller)
Controller
operating on the View
.controller
- The controller operating on the view.public abstract javax.swing.JComponent render()
View
as a Swing component.
This method must be implemented by subclasses and is where the View
is rendered as a Swing component.
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.