edu.washington.biostr.sig.brainj3d.doevents
Class AbstractDataController<V extends DataView>

java.lang.Object
  extended by edu.washington.biostr.sig.brainj3d.doevents.AbstractDataController<V>
All Implemented Interfaces:
CommandListener, Controller, DataController, Listener
Direct Known Subclasses:
BrainInfoAtlasController, MapController, SimpleController, SurfaceAppearanceController, VolumeDataController

public abstract class AbstractDataController<V extends DataView>
extends Object
implements DataController, Listener, CommandListener

The default data controller handles most simple work that a data controller needs to do. It listens for SHObjects and fires a ParameterEvent with the name and value. It also handles state change events that target the data view.

Author:
eider

Nested Class Summary
protected  class AbstractDataController.SetValues
           
 
Constructor Summary
AbstractDataController(Class<?> viewClass)
           
 
Method Summary
 void addListener(CommandListener l)
          add a listener that fires on events that cause a change to this.
 boolean doCommand(DoCommand cmd)
          By default do nothing
protected  void fireCommand(DoCommand cmd)
           
protected  void fireStateChange(State state)
           
protected  V getCastView()
           
 DataKey getDataKey()
           
 V getDataView()
           
 boolean getEdit()
          Return true if we are in edit mode.
 String getEditButtonText()
          Get the text for the edit button.
protected abstract  Executor getGUIThread()
          Get the GUI thread.
 DoTarget getTarget()
          Get the target.
 void initUI()
           
 boolean isEditable()
          Set to true if this has components that can be enabled/disabled with edit mode.
 boolean isFocus()
          Within a set, a single Controller should have the focus.
 boolean isVisible()
          Return the value that visible was set to.
protected  void monitorUpdates(DataKey target, CommandListener listener)
          Monitor updates to the specified targets parameters.
 void removeListener(CommandListener l)
           
 void requestFocus()
          Request focus.
 DataController setDataView(DataView view, DataKey dataKey)
          This is called when the view is set.
 void setDoTarget(DoTarget target)
          Set the target.
 boolean setEdit(boolean edit)
          By default do nothing
 void setFocus(boolean focus)
          Set the focus.
protected abstract  void setGUIValues(Map<String,Object> g)
          Set the GUI values.
 boolean setState(State s)
          If the state has our key as the ident, send it to the data view, and call setGUIValues(Map) if the value is not temporary.
 void setVisible(boolean visible)
          Set the visibility state.
 void somethingHappened(Event evt)
          If evt instanceof SHPropertyEvent then we automatically dispatch a ParemeterEvent with evt.getName() as the name, the DataKey as the target and evt.getData() as the data.
If this doesn't work for all of the GUI elements, than override this and handle those elements individually with a fallthrough like:
else {
super.somethingHappened(evt)
}
 void updateGUIValues()
           
protected abstract  void viewWasSet(V view, DataKey key)
          This is called when the data view is set.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface edu.washington.biostr.sig.brainj3d.doevents.Controller
getControl, getControlName
 

Constructor Detail

AbstractDataController

public AbstractDataController(Class<?> viewClass)
Method Detail

addListener

public void addListener(CommandListener l)
add a listener that fires on events that cause a change to this.

Specified by:
addListener in interface DataController
Parameters:
l -

removeListener

public void removeListener(CommandListener l)
Specified by:
removeListener in interface DataController

fireStateChange

protected void fireStateChange(State state)

fireCommand

protected void fireCommand(DoCommand cmd)

setDataView

public final DataController setDataView(DataView view,
                                        DataKey dataKey)
This is called when the view is set. it in turn calls viewWasSet. This also calls setGUIValues() with the parameters in the GUI thread (after viewWasSet()) TODO make this not final

Specified by:
setDataView in interface DataController
Returns:
this

getCastView

protected V getCastView()

getDataView

public V getDataView()
Specified by:
getDataView in interface DataController

setEdit

public boolean setEdit(boolean edit)
By default do nothing

Specified by:
setEdit in interface DataController
Returns:
false

viewWasSet

protected abstract void viewWasSet(V view,
                                   DataKey key)
This is called when the data view is set.

Parameters:
view -
key -

getEdit

public boolean getEdit()
Description copied from interface: DataController
Return true if we are in edit mode.

Specified by:
getEdit in interface DataController
Returns:
by default false

getTarget

public DoTarget getTarget()
Description copied from interface: Controller
Get the target.

Specified by:
getTarget in interface Controller
Returns:

setDoTarget

public void setDoTarget(DoTarget target)
Description copied from interface: Controller
Set the target.

Specified by:
setDoTarget in interface Controller

isVisible

public boolean isVisible()
Description copied from interface: Controller
Return the value that visible was set to.

Specified by:
isVisible in interface Controller
Returns:

setVisible

public void setVisible(boolean visible)
Description copied from interface: Controller
Set the visibility state. Visibility is determined externally.

Specified by:
setVisible in interface Controller

isFocus

public boolean isFocus()
Description copied from interface: Controller
Within a set, a single Controller should have the focus.

Specified by:
isFocus in interface Controller
Returns:

setFocus

public void setFocus(boolean focus)
Description copied from interface: Controller
Set the focus. A single controller should have the focus with a set.

Specified by:
setFocus in interface Controller

doCommand

public boolean doCommand(DoCommand cmd)
By default do nothing

Specified by:
doCommand in interface CommandListener
Returns:
by default false

setState

public boolean setState(State s)
If the state has our key as the ident, send it to the data view, and call setGUIValues(Map) if the value is not temporary.

Specified by:
setState in interface CommandListener
Returns:
true if anything changed.

updateGUIValues

public void updateGUIValues()

setGUIValues

protected abstract void setGUIValues(Map<String,Object> g)
Set the GUI values. This will be called in the GUI thread.

Parameters:
g -

getGUIThread

protected abstract Executor getGUIThread()
Get the GUI thread. This can be accomplished simply by getting the thread attached to an SwingHTMLObject (using the getExecutor() method).
Note:
this cannot get it itself because it has no GUI objects.

Returns:

requestFocus

public void requestFocus()
Request focus. For those DataControllers using a viewport, use the following code:
if (getTarget() instanceof ViewPort)
{
((ViewPort) getTarget()).requestFocus(getDataKey());
}
Note:
This cannot directly use the above code because it should depend on the viewport.

Specified by:
requestFocus in interface Controller

somethingHappened

public void somethingHappened(Event evt)
If evt instanceof SHPropertyEvent then we automatically dispatch a ParemeterEvent with evt.getName() as the name, the DataKey as the target and evt.getData() as the data.
If this doesn't work for all of the GUI elements, than override this and handle those elements individually with a fallthrough like:
else {
super.somethingHappened(evt)
}

Specified by:
somethingHappened in interface Listener

getDataKey

public DataKey getDataKey()
Returns:
Returns the dataKey.

getEditButtonText

public String getEditButtonText()
Description copied from interface: DataController
Get the text for the edit button.

Specified by:
getEditButtonText in interface DataController
Returns:

isEditable

public boolean isEditable()
Set to true if this has components that can be enabled/disabled with edit mode.

Returns:
false by default.

monitorUpdates

protected void monitorUpdates(DataKey target,
                              CommandListener listener)
Monitor updates to the specified targets parameters.

Parameters:
target - The target to monitor or null to monitor all Parameter changes
listener -

initUI

public void initUI()
Specified by:
initUI in interface DataController


Copyright © 2006 University of Washington. All Rights Reserved.