org.nakedobjects.viewer.lightweight
Class AbstractView

java.lang.Object
  extended byorg.nakedobjects.viewer.lightweight.AbstractView
All Implemented Interfaces:
java.lang.Cloneable, View
Direct Known Subclasses:
AbstractObjectView, AbstractValueView, Workspace

public abstract class AbstractView
extends java.lang.Object
implements View

A View is the visual representation of the object the user is working with. A View knows who its parent is (another view), and which frame it belongs to. If the view is a part of the frame (it is a top-level view) then its parent wil be null. A View also knows it position within the frame.

Author:
rcm

Field Summary
static boolean DEBUG
           
static int DRAG_HANDLE_WIDTH
           
static int HPADDING
          Horizontal padding (||) between two components
protected static int ICON_SIZE
           
static int VPADDING
          Vertical padding (=) between two components
 
Constructor Summary
AbstractView()
           
 
Method Summary
 void addControl(Control control)
          Adds a control to this view.
protected  void assignId()
          Assigns a unique ID to this component
protected  Color backgroundColor()
           
 void calculateRepaintArea()
          Called to mark this view's on-screen state as invalid, i.e. it needs to be redrawn.
 boolean contains(Location mousePosition)
          Returns true if the pointer is within this objects bounds.
 Canvas createCanvas(java.awt.Graphics g)
           
 java.lang.String debugDetails()
          Returns debug details about this view.
protected  int defaultFieldHeight()
           
 void dispose()
          Default implementation, which does nothing, override when needed.
 void draw(Canvas canvas)
          Called by the frame, or the parent view, when this view must redraw itself.
 void entered()
          Default implementation, which does nothing, override when needed.
 void enteredSubview()
          Default implementation, which does nothing, override when needed.
 void exited()
          Default implementation, which does nothing, override when needed.
 void exitedSubview()
          Default implementation, which does nothing, override when needed.
 void firstClick(Click click)
          Called when the user clicks the mouse buttone within this view.
 Location getAbsoluteLocation()
          the location of this view relative to the containing java.awt.Window object.
 int getBaseline()
          Returns the postion of the baseline for adjacent label.
 Border getBorder()
           
 Bounds getBounds()
          Returns the bounding rectangle that describes where (within it parent), and how big, this view is.
 int getId()
           
 Location getLocation()
          Determines the location relative to this object's containing view
 java.lang.String getName()
           
 Padding getPadding()
           
 CompositeView getParent()
          Returns the View that this view belongs to.
 Size getSize()
          Determines the size of this view.
 Workspace getWorkspace()
          Returns the enclosing ApplicationFrame that this view is part of.
 View identifyView(Location mouseLocationer, View current)
          Returns the view that mouse pointer is over.
 boolean indicatesForView(Location mouseLocation)
          Default behaviour, returning true to indicate that the view itself is the target of the user's action - rather than what this view represents.
 void invalidateLayout()
          sets this view layout flag to show that the layout is no longer valid
 boolean isLayoutInvalid()
          Returns true when this views layout is not current, i.e. it needs to be laid out again.
 boolean isOpen()
          By default a vew is deemed to open, showing its content.
 boolean isReplaceable()
          By default a view can be replaced by another view representing the same object
 void layout()
          This method is called when the frame, or the parent view, needs this view to determine is spatial requirements and to lay out its compnents..
 void limitBounds()
           
 void menuOptions(MenuOptionSet options)
          Called when the popup menu is being populated for this view.
 void mouseMoved(Location at)
          Called as the mouse is moved around within this view.
 void print(Canvas canvas)
           
 void redraw()
          Requests that the frame repaints this view, and only this view.
 void removeControl(Control control)
          Removes a control from this view.
 void repaintAll()
          Calls repaint() on the the top-level owner of this view.
 void secondClick(Click click)
          Called when the user double-clicked this view.
 void setBorder(Border border)
           
 void setBounds(Location point, Size size)
           
 void setLayoutValid()
           
 void setLocation(Location point)
          Sets the location of this view.
 void setParent(CompositeView parent)
          Sets the parent of the view.
 void setSize(Size size)
           
protected static void setWorkspace(Workspace workspace)
           
 void thirdClick(Click click)
          Called when the user triple-clicks the mouse buttone within this view.
protected  boolean transparentBackground()
           
 void validateLayout()
          Reqests that this view tree needs to be laid out.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.nakedobjects.viewer.lightweight.View
getRequiredSize, makeView
 

Field Detail

VPADDING

public static final int VPADDING
Vertical padding (=) between two components


HPADDING

public static final int HPADDING
Horizontal padding (||) between two components


DRAG_HANDLE_WIDTH

public static final int DRAG_HANDLE_WIDTH

ICON_SIZE

protected static final int ICON_SIZE
See Also:
Constant Field Values

DEBUG

public static boolean DEBUG
Constructor Detail

AbstractView

public AbstractView()
Method Detail

getAbsoluteLocation

public final Location getAbsoluteLocation()
Description copied from interface: View
the location of this view relative to the containing java.awt.Window object.

Specified by:
getAbsoluteLocation in interface View
Returns:
Location

setBorder

public void setBorder(Border border)
Specified by:
setBorder in interface View

getBorder

public Border getBorder()
Specified by:
getBorder in interface View

setBounds

public final void setBounds(Location point,
                            Size size)
Specified by:
setBounds in interface View

getBounds

public final Bounds getBounds()
Description copied from interface: View
Returns the bounding rectangle that describes where (within it parent), and how big, this view is.

Specified by:
getBounds in interface View
Returns:
Bounds
See Also:
View.getSize(), View.getLocation()

getId

public int getId()
Specified by:
getId in interface View

isLayoutInvalid

public boolean isLayoutInvalid()
Description copied from interface: View
Returns true when this views layout is not current, i.e. it needs to be laid out again.

Specified by:
isLayoutInvalid in interface View

setLayoutValid

public void setLayoutValid()

setLocation

public final void setLocation(Location point)
Sets the location of this view. If this view is being moved then layout should be called subsequently.

Specified by:
setLocation in interface View
Parameters:
point -

getLocation

public final Location getLocation()
Description copied from interface: View
Determines the location relative to this object's containing view

Specified by:
getLocation in interface View
See Also:
View.getBounds()

getBaseline

public int getBaseline()
Returns the postion of the baseline for adjacent label. If the label is drawn on this baseline when top of the label rectangle and this view's rectangle are aligned then the label should share the baseline with whatever text is shown within the view.

Specified by:
getBaseline in interface View
Returns:
int the baseline to draw the label at.

getName

public java.lang.String getName()
Specified by:
getName in interface View

getPadding

public Padding getPadding()
Specified by:
getPadding in interface View

setParent

public void setParent(CompositeView parent)
Sets the parent of the view.


getParent

public CompositeView getParent()
Returns the View that this view belongs to. If null is returned then this view is a top-level view and is shown directly on the frame.

Specified by:
getParent in interface View

setSize

public final void setSize(Size size)
Specified by:
setSize in interface View

getSize

public final Size getSize()
Description copied from interface: View
Determines the size of this view.

Specified by:
getSize in interface View
See Also:
View.getBounds()

isOpen

public boolean isOpen()
By default a vew is deemed to open, showing its content.

Specified by:
isOpen in interface View
Returns:
true if it is showing the object's details; false if it is showing the object only.

isReplaceable

public boolean isReplaceable()
By default a view can be replaced by another view representing the same object

Specified by:
isReplaceable in interface View
Returns:
true if it can be replaced by another view; false if it can't be replaces

getWorkspace

public Workspace getWorkspace()
Returns the enclosing ApplicationFrame that this view is part of.

Specified by:
getWorkspace in interface View

addControl

public void addControl(Control control)
Adds a control to this view. If the specified control already exists for this view then it is ignored.

Parameters:
control -

contains

public final boolean contains(Location mousePosition)
Returns true if the pointer is within this objects bounds.

Specified by:
contains in interface View

calculateRepaintArea

public void calculateRepaintArea()
Description copied from interface: View
Called to mark this view's on-screen state as invalid, i.e. it needs to be redrawn.

Specified by:
calculateRepaintArea in interface View

createCanvas

public Canvas createCanvas(java.awt.Graphics g)

debugDetails

public java.lang.String debugDetails()
Returns debug details about this view.

Specified by:
debugDetails in interface View
Returns:
String

dispose

public void dispose()
Default implementation, which does nothing, override when needed.

Specified by:
dispose in interface View

entered

public void entered()
Default implementation, which does nothing, override when needed.

Specified by:
entered in interface View

enteredSubview

public void enteredSubview()
Default implementation, which does nothing, override when needed.

Specified by:
enteredSubview in interface View

exited

public void exited()
Default implementation, which does nothing, override when needed.

Specified by:
exited in interface View

exitedSubview

public void exitedSubview()
Default implementation, which does nothing, override when needed.

Specified by:
exitedSubview in interface View

firstClick

public void firstClick(Click click)
Called when the user clicks the mouse buttone within this view.

Passes on to the control at the mouse location.

Specified by:
firstClick in interface View
Parameters:
click - the location within the current view where the mouse click took place

identifyView

public View identifyView(Location mouseLocationer,
                         View current)
Returns the view that mouse pointer is over. If it is over this view and not over any of it's components then this views reference is returned. Returns this view; should be overriden for container views.

Specified by:
identifyView in interface View
Parameters:
mouseLocationer -
current -
Returns:
View this view

indicatesForView

public boolean indicatesForView(Location mouseLocation)
Default behaviour, returning true to indicate that the view itself is the target of the user's action - rather than what this view represents.

Specified by:
indicatesForView in interface View
Parameters:
mouseLocation -
Returns:
true if the user is targeting the view itself, false if the user is targeting what is being represented

invalidateLayout

public void invalidateLayout()
Description copied from interface: View
sets this view layout flag to show that the layout is no longer valid

Specified by:
invalidateLayout in interface View

validateLayout

public final void validateLayout()
Description copied from interface: View
Reqests that this view tree needs to be laid out. The root view will start calling layout on each of the invalid views in the tree.

Specified by:
validateLayout in interface View

draw

public void draw(Canvas canvas)
Description copied from interface: View
Called by the frame, or the parent view, when this view must redraw itself.

Specified by:
draw in interface View

layout

public void layout()
This method is called when the frame, or the parent view, needs this view to determine is spatial requirements and to lay out its compnents..

Specified by:
layout in interface View

limitBounds

public void limitBounds()

menuOptions

public void menuOptions(MenuOptionSet options)
Description copied from interface: View
Called when the popup menu is being populated for this view. Any options that need to appear on the menu should be added to the menuOptions object.

Specified by:
menuOptions in interface View
Parameters:
options -

mouseMoved

public void mouseMoved(Location at)
Called as the mouse is moved around within this view. Does nothing; should be overriden when needed.

Specified by:
mouseMoved in interface View
Parameters:
at - the position relative to the top-left of this view

print

public void print(Canvas canvas)
Specified by:
print in interface View

removeControl

public void removeControl(Control control)
Removes a control from this view. If the specified control does not exist for this view then the request is ignored.

Parameters:
control -

repaintAll

public void repaintAll()
Calls repaint() on the the top-level owner of this view.


redraw

public void redraw()
Requests that the frame repaints this view, and only this view.

Specified by:
redraw in interface View

secondClick

public void secondClick(Click click)
Called when the user double-clicked this view. This method will have been preceded by a call to click.

Does nothing; should be overriden when needed.

Specified by:
secondClick in interface View

thirdClick

public void thirdClick(Click click)
Called when the user triple-clicks the mouse buttone within this view. This method will have been preceded by a call to doubleClick.

Does nothing; should be overriden when needed.

Specified by:
thirdClick in interface View

setWorkspace

protected static void setWorkspace(Workspace workspace)

assignId

protected void assignId()
Assigns a unique ID to this component


backgroundColor

protected Color backgroundColor()

defaultFieldHeight

protected int defaultFieldHeight()

transparentBackground

protected boolean transparentBackground()