|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--mvp.View
Class View is an abstract parent class for view classes in an MVP design. See Fisher SE lecture notes for further discussion of the MVP design methodology.
View implements Observer since it is often convenient for a view to observe its companion model, particularly when a model has multiple views that all need to change simultaneously when the model changes. View implements Serializable as a convenience for serializing models that refer to views. Typically, view data are not themselves worthy of serialization, but when a model refers to a view, that view needs to be Serializable in principle in order for serialization to proceed without problems.
Field Summary | |
protected java.awt.event.WindowAdapter |
closeAdapter
The exit-on-close listener |
protected boolean |
editable
True if this is editable |
protected Model |
model
The unique companion model for this |
protected Screen |
screen
The physical display screen for this. |
protected boolean |
shown
True if the window is displayed |
protected java.awt.Component |
widget
The outermost interactive element (i.e., "widget") for this. |
protected Window |
window
The physical UI window for this. |
Constructor Summary | |
View()
Construct this with a null screen and model. |
|
View(Screen screen,
Model model)
Construct a view with the given Screen and Model. |
Method Summary | |
java.awt.Component |
compose()
Compose the interface components of this, setting the window and/or widget fields to the top-level of the composition. |
Model |
getModel()
Return the model of this. |
java.awt.Component |
getWidget()
Return the widget of this. |
Window |
getWindow()
Return the window of this. |
void |
hide()
Remove the window of this from the screen, thereby physically undisplaying it. |
boolean |
isEditable()
Return true if this is currently editable. |
boolean |
isShown()
Return true if this is currently displayed on the screen. |
void |
run()
Run this by entering the screen's event loop, which will in turn display the window of this and any widgets within the window. |
void |
setEditable(boolean editable)
Set the editability of this to the given boolean value. |
void |
setExitOnClose(boolean exitOnClose)
Perform the necessary set up to call or not to call the companion model's exit method when the user closes this' window. |
void |
setModel(Model model)
Set the model of this to the given model, if the model is not already set. |
void |
show()
Insert the window of this into the screen, thereby physically displaying it. |
void |
show(int x,
int y)
Same specs as Show(), except the window is shown at the given x,y coordinate. |
void |
update(java.util.Observable o,
java.lang.Object arg)
Update the displayed data in this. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected Model model
protected Screen screen
protected Window window
protected java.awt.Component widget
protected boolean shown
protected boolean editable
protected java.awt.event.WindowAdapter closeAdapter
Constructor Detail |
public View(Screen screen, Model model)
pre: screen != null; post: (this'.screen == screen) && (this'.model == model) && (window' == null) && (shown' == false) && (editable' == false) && (closeAdapter == false);
public View()
post: (this'.screen == null) && (this'.model == null) && (window' == null) && (shown' == false) && (editable' == false) && (closeAdapter == false);
Method Detail |
public void run()
pre: not screen.isRunning(); post: screen'.isRunning() && forall (Component c | c in screen.getComponents()) c.IsDisplayed();where isRunning is an assumed predicate of Screen that returns true if the Screen's event-handling loop is running.
public java.awt.Component compose()
post: return == widget; // Compose must be specialized in subclasses.
public void show()
To move the window to some position other than the front, extract the window with this.getWindow and manipulate it with methods available in the Window class.
The screen position of the window will be selected by the underlying window manager. To show the window of this at a specific screen position, use the overloaded version of Show specified below.
pre: post: if (window != null) then screen'.IsDisplayed(window) && screen'.IsFrontmost(window) && shown' == true; else System.out.println("error");
public void show(int x, int y)
public void hide()
pre: ; // Note that the window may or may not be currently displayed post: not screen'.IsDisplayed(window) && (shown' == false);
public void update(java.util.Observable o, java.lang.Object arg)
post: ; // Update must be specialized in subclasses.
update
in interface java.util.Observer
public Model getModel()
public void setModel(Model model)
pre: this.model == null; post: this.model' == model;
public Window getWindow()
post: return == window;
public java.awt.Component getWidget()
post: return == widget;
public boolean isShown()
post: return == shown;
public boolean isEditable()
post: return == editable;
public void setEditable(boolean editable)
post: this'.editable == editable;
public void setExitOnClose(boolean exitOnClose)
pre: (window != null) post: if (exitOnClose == true) then (exists (WindowAdapter wa) (wa in window.getListeners(WindowAdapter.class)) && (wa.getClass().getDeclaredMethod( "windowClosing", {WindowEvent.class})).invokes( model.getClass().getDeclaredMethod("exit", null)) && (closeAdapter' == wa)) else !(exists (WindowAdapter wa) (wa in window.getListeners(WindowAdapter.class)) && (wa.getClass().getDeclaredMethod( "windowClosing", {WindowEvent.class})).invokes( model.getClass().getDeclaredMethod("exit", null))) && (closeAdapter' == null)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |