mutable
This subpackage contains the version of View
s that we primarily use in O1: views
to mutable domain models.
The top-level package o1 provides an alias to the ViewFrame class in this
package, so it is available to students as View
simply by importing o1.*
.
There is an alternative implementation of View
s in o1.gui.immutable.
Type members
Classlikes
Add this trait on a view to enable discarding its model object for another.
Add this trait on a view to enable discarding its model object for another.
A Swing-embeddable view (complete with a picture, a ticking clock, event handlers, etc.). It works like a ViewFrame except that it’s a Swing component, not a standalone GUI frame. See ViewFrame for an overview.
A Swing-embeddable view (complete with a picture, a ticking clock, event handlers, etc.). It works like a ViewFrame except that it’s a Swing component, not a standalone GUI frame. See ViewFrame for an overview.
- Type parameters:
- Model
the type of the model object
- Value parameters:
- initialDelay
an additional delay in milliseconds between calling start and the clock starting (optional; defaults to 600)
- initialModel
the model to be displayed in the view (the only required parameter). It usually makes sense to use a mutable object here and change its state via the event handlers (cf. o1.gui.immutable.ViewComponent).
- refreshPolicy
a policy for how eagerly the view should try to update the graphical representation of its model (optional; changing this may improve efficiency in some circumstances)
- tickRate
the clock of the view will tick roughly this many times per second (optional; defaults to 24)
This class provides a framework for building simple GUIs. Each instance of the class is a graphical
view to an object that represents a particular domain; that object is the model of the view.
A ViewFrame
displays the model as graphics within a GUI frame.
This class provides a framework for building simple GUIs. Each instance of the class is a graphical
view to an object that represents a particular domain; that object is the model of the view.
A ViewFrame
displays the model as graphics within a GUI frame.
This class is available under the alias View
in the top-level package o1, so students can
access it simply by importing o1.*
.
The key method in the class is makePic
, which the view calls automatically and repeatedly to
determine which Pic to display in the frame at each moment in time. Concrete view objects must
add an implementation for this abstract method.
A view listens to GUI events within the frame, but it doesn’t really do anything when notified
of an event; concrete instances of the class can override this behavior by overriding one of the
“on methods” (onClick
, onMouseMove
, etc.). The view also runs an internal clock and can react
to the passing of time (onTick
).
Just creating a view object is not enough to display it onscreen and start the clock; see the start method.
- Type parameters:
- Model
the type of the model object
- Value parameters:
- closeWhenDone
whether the
ViewFrame
should be hidden and its clock stopped once the view has reached a “done state” (as perisDone
) (optional; defaults tofalse
)- initialDelay
an additional delay in milliseconds between calling start and the clock starting (optional; defaults to 600)
- initialModel
the model to be displayed in the view (the only required parameter). It usually makes sense to use a mutable object here and change its state via the event handlers (cf. o1.gui.immutable.ViewFrame).
- refreshPolicy
a policy for how eagerly the view should try to update the graphical representation of its model (optional; changing this may improve efficiency in some circumstances)
- terminateOnClose
whether the entire application should exit when the
ViewFrame
is closed (optional; defaults totrue
)- tickRate
the clock of the view will tick roughly this many times per second (optional; defaults to 24)
- title
a string to be displayed in the frame’s title bar (optional)
Types
An alias for ViewFrame, which is the default sort of View
. (Cf. the alternative, ViewComponent.)
An alias for ViewFrame, which is the default sort of View
. (Cf. the alternative, ViewComponent.)