edu.umd.cfar.lamp.viper.gui.core
Class ViperViewMediator

java.lang.Object
  extended byedu.umd.cfar.lamp.viper.gui.core.ViperViewMediator

public class ViperViewMediator
extends java.lang.Object

Stands between a set of viper metadata and the user interface, providing information about user focus and limiting the scope that the user has to pay attention to. This is pretty ad hoc; it is certainly conceivable that the user would want multiple focii, or provide multiple filters. Later, we may move to a stream transformation type view, but this is just to test out some ideas.

Author:
davidm

Constructor Summary
ViperViewMediator()
          Creates a new ViperViewMediator without any data
 
Method Summary
 void addViperMediatorChangeListener(ViperMediatorChangeListener l)
          Adds a listener for ui notifications.
 void displayHotkeyBindings()
          Displays the current hotkey bindings in a new window.
 Descriptor duplicateDescriptor(Descriptor instance)
          Copies the given descriptor and adds it to the descriptor's parent sourcefile node.
 void fireCurrFileChange()
          Indicate that the currently selected sourcefile is no longer selected, and that another one might be.
 void fireDataChange(ViperChangeEvent vce)
          Indicate that the instance data of viper has changed.
 void fireFrameChange()
          Indicate that the there is a new current frame of interest.
 void fireMediaChange()
          Indicate that the underlying media has changed, although the metadata has not.
 void fireSchemaChange(ViperChangeEvent vce)
          Indicate that the schema of the file, and possibly wide sections of the instance data, has changed.
 ActionHistoryPane getActionHistory()
          Gets the undo/redo action history.
 java.awt.event.ActionListener getCreateInstanceActionListener()
           
 Frame getCurrentFrame()
          Gets the major moment as a Frame.
 Sourcefile getCurrFile()
          Gets the data associated with the current Sourcefile of interest.
 java.net.URI getCurrFileName()
          Gets the current media file name as a URI
 InstantInterval getCurrInterval(boolean frameBased)
          Gets a single frame interval surrounding the current instant of interest.
 ViperDataFactory getDataFactory()
          Gets the type factory, used for associating data types with attributes, that is currently in use.
 DataPlayer getDataPlayer()
          Gets the view of the media that currently has focus.
 java.awt.event.ActionListener getDeleteInstanceActionListener()
          Gets an action listener that tries to delete the currently selected descriptor, if it exists.
 java.awt.event.ActionListener getDisplayHotkeyBindingsActionListener()
          Gets an action that displays the current hotkey bindings.
 DisplayWithRespectToManager getDisplayWRTManager()
          Use this method to access the display wrt manager, and then you can add listeners to it.
 java.awt.event.ActionListener getDuplicateInstanceActionListener()
          Gets an action listener that tries to copy the selected object descriptor, if it exists.
 java.awt.event.ActionListener getExportCurrentFileActionListener()
          Gets an action object for the 'export current file as a .gtf file' option.
 java.net.URI getFileName()
          Gets the URI of the currently displayed metadata file.
 java.lang.String getFocalFile()
          Gets the current source media file that the user is annotating.
 InstantInterval getFocusInterval()
          Gets the span of interest.
 NodeVisibilityManager getHiders()
          Gets the manager of the set of hidden items.
 FileHistoryManager getHistoryManager()
          Gets the MRU file history manager.
 java.awt.event.ActionListener getImportConfigActionListener()
          Gets an action object that will import the viper schema of an existing file.
 java.awt.event.ActionListener getImportGTFFileActionListener()
          Gets an action object for the 'Import GTF into Current Media File' menu option.
 java.net.URI getLocalPathToFile(java.net.URI canonical)
          Finds the local version of the file.
 Instant getMajorMoment()
          Gets the current frame/time of interest.
 ChronicleMarkerModel getMarkerModel()
          Returns the model that should be used to display markers on a chronicle view, if one is attatched
 edu.umd.cfar.lamp.viper.gui.core.ViperViewMediator.MoveAttributeActionListener getMoveAttributeActionListener()
           
 java.awt.event.ActionListener getNewFileActionListener()
          Gets an action that will open a new, empty metadata file.
 java.awt.event.ActionListener getOpenFileActionListener()
          Gets the 'open file' action.
 PrefsManager getPrefs()
          Gets the associated application loader preference manager.
 ViperSubTree getPrimarySelection()
          Gets the current top-selection of the user.
 PropagateInterpolateModule getPropagator()
          Gets the propagation object.
 java.awt.event.ActionListener getRecentlyViewedFileActionListener()
          Gets an action that will open the recently viewed file referenced in the action command.
 edu.umd.cfar.lamp.viper.gui.core.ViperViewMediator.RedoActionListener getRedoActionListener()
          Gets an action that will redo the last undone action that hasn't been redone, if one exists.
 java.awt.event.ActionListener getSaveActionListener()
          Gets the 'Save Current File' action object.
 java.awt.event.ActionListener getSaveAsActionListener()
          Gets the 'Save File As...' action object.
 AttemptToPerformAction getSaveDiscardOrCancelDialogVeto()
          Gets a 'Save, Discard, or Cancel' dialog up.
 java.awt.event.ActionListener getSelectAttributeActionListener()
           
 java.awt.event.ActionListener getSelectDescriptorConfigActionListener()
           
 java.awt.event.ActionListener getSelectDescriptorInstanceActionListener()
           
 ViperSelectionSet getSelection()
          Gets the currently selected metadata item.
 java.awt.event.ActionListener getToggleDisplayInvalidActionListener()
          Gets an action that toggles the 'showing invalid' property.
 edu.umd.cfar.lamp.viper.gui.core.ViperViewMediator.UndoActionListener getUndoActionListener()
          Gets an action that will undo the last action.
 ViperData getViperData()
          Gets the underlying annotation information.
 boolean isShowingInvalid()
          Tests to see if the user should care about descriptors that are invalid at the current frame of interest.
 boolean isThisValidNow(Descriptor d)
          Tests to see if the descriptor is valid at the current frame/time of user interest.
 void modifyMostRecentlyUsed(java.net.URI filename)
          Indicate that the given file has been used, moving it to the top of the MRU list.
 void openCanonicalFileAsLocalFile(java.net.URI canonical, java.net.URI local, MediaElement fileInfo)
          Opens the file.
 void putCanonicalToLocalMapping(java.net.URI canonical, java.net.URI local)
          Adds the given mapping from canonical file name to local file name.
 void removeViperMediatorChangeListener(ViperMediatorChangeListener l)
          Removes a listener.
 void saveDiscardOrCancel(java.lang.Runnable ok)
          Prompts the user if she would like to save the changes, discard the changes, or cancel the current action.
 void saveDiscardOrCancelIfChanged(java.lang.Runnable ok)
          Brings up the save/discard/cancel prompt if there are any items in the action history (ie the file has been altered since it was opened/created); otherwise, just runs the Runnable.
 void setActionHistory(ActionHistoryPane ahp)
          Sets the action history panel.
 void setAttributeValueAtCurrentFrame(java.lang.Object val, Attribute a)
          Sets the value of an attribute (or the default value of an attribute, if val is an AttrConfig).
 void setAttributeValueAtSpan(java.lang.Object val, Attribute a, InstantInterval span)
          Sets the value of an attribute (or the default value of an attribute, if val is an AttrConfig).
 void setDataFactory(ViperDataFactory fact)
          Sets the attribute type factory.
 void setFileName(java.net.URI f)
          Load the metadata file from the given URI and set it to be the currently editing file.
 void setFocalFile(java.net.URI fname)
          Sets the media file the user is currently annotating.
 void setHistoryManager(FileHistoryManager manager)
          Sets the file history manager to use with the application.
 void setMajorMoment(Instant majorMoment)
          Sets the majorMoment.
 void setMarkerModel(ChronicleMarkerModel model)
          Sets the marker model.
 void setPrefs(PrefsManager manager)
          Sets the associated preference manager.
 void setPropagator(PropagateInterpolateModule propagator)
           
 void setShowingInvalid(boolean showingInvalid)
          Turns on/off the invalid descriptors in the spreadsheet view.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ViperViewMediator

public ViperViewMediator()
Creates a new ViperViewMediator without any data

Method Detail

getDataFactory

public ViperDataFactory getDataFactory()
Gets the type factory, used for associating data types with attributes, that is currently in use.

Returns:
the type factory

setDataFactory

public void setDataFactory(ViperDataFactory fact)
Sets the attribute type factory. The attribute type factory allows different data types to be used with attributes, and provides parsing and serialization support for those types.

Parameters:
fact - the new data type factory

getFileName

public java.net.URI getFileName()
Gets the URI of the currently displayed metadata file.

Returns:
the currently loaded file's URI.
See Also:
LOCAL_HISTORY.Untitled

openCanonicalFileAsLocalFile

public void openCanonicalFileAsLocalFile(java.net.URI canonical,
                                         java.net.URI local,
                                         MediaElement fileInfo)
Opens the file. Warning: is asynchronous; when finished, it calls setDataPlayer. If you want to open a file synchronously, construct your own DataPlayer.

Parameters:
canonical - the name of the media file found in the viper data file
local - the actual location the file is stored on the user's disk

putCanonicalToLocalMapping

public void putCanonicalToLocalMapping(java.net.URI canonical,
                                       java.net.URI local)
Adds the given mapping from canonical file name to local file name.

Parameters:
canonical - the name that is found in the sourcefile element of the viper data file
local - the local name of the file

getLocalPathToFile

public java.net.URI getLocalPathToFile(java.net.URI canonical)
Finds the local version of the file. If no local version is present, returns the canonical version.

Parameters:
canonical - the file to look up
Returns:
the best chance at finding the file

setFileName

public void setFileName(java.net.URI f)
                 throws java.io.IOException
Load the metadata file from the given URI and set it to be the currently editing file. It also sets the first media file described in the file to be the focal file.

Parameters:
f - The file t load
Throws:
java.io.IOException - If the file cannot load, or if has errors. If the focal file cannot be loaded, no exception is thrown.

addViperMediatorChangeListener

public void addViperMediatorChangeListener(ViperMediatorChangeListener l)
Adds a listener for ui notifications.

Parameters:
l - the ui listener

removeViperMediatorChangeListener

public void removeViperMediatorChangeListener(ViperMediatorChangeListener l)
Removes a listener.

Parameters:
l - the listener to remove

fireMediaChange

public void fireMediaChange()
Indicate that the underlying media has changed, although the metadata has not.


fireCurrFileChange

public void fireCurrFileChange()
Indicate that the currently selected sourcefile is no longer selected, and that another one might be.


fireFrameChange

public void fireFrameChange()
Indicate that the there is a new current frame of interest.


fireDataChange

public void fireDataChange(ViperChangeEvent vce)
Indicate that the instance data of viper has changed.

Parameters:
vce - the change event that caused this to be called.

fireSchemaChange

public void fireSchemaChange(ViperChangeEvent vce)
Indicate that the schema of the file, and possibly wide sections of the instance data, has changed.

Parameters:
vce - the wrapped viper api change event, if any

modifyMostRecentlyUsed

public void modifyMostRecentlyUsed(java.net.URI filename)
Indicate that the given file has been used, moving it to the top of the MRU list.

Parameters:
filename - the file to touch

getFocalFile

public java.lang.String getFocalFile()
Gets the current source media file that the user is annotating.

Returns:
the current media file of interest. May be null.

setFocalFile

public void setFocalFile(java.net.URI fname)
                  throws java.io.IOException
Sets the media file the user is currently annotating.

Parameters:
fname - the name of the file to view
Throws:
java.io.IOException - if there is an error while loading the file

getCurrFile

public Sourcefile getCurrFile()
Gets the data associated with the current Sourcefile of interest.

Returns:
Sourcefile the Sourcefile that the Mediator currently regards as the focus

getCurrFileName

public java.net.URI getCurrFileName()
Gets the current media file name as a URI

Returns:
the source media name

getViperData

public ViperData getViperData()
Gets the underlying annotation information.

Returns:
the viper data object the user is currently editing

getDataPlayer

public DataPlayer getDataPlayer()
Gets the view of the media that currently has focus.

Returns:
DataPlayer Gets the DataPlayer for the current sourcefile

getFocusInterval

public InstantInterval getFocusInterval()
Gets the span of interest. Currently, this is just the span of the loaded media file.

Returns:
the media file's span

getMajorMoment

public Instant getMajorMoment()
Gets the current frame/time of interest. This is the one that is displayed in the frame view or on the spreadsheet, for example.

Returns:
the currrent Instant of interset

getCurrentFrame

public Frame getCurrentFrame()
Gets the major moment as a Frame.

Returns:
the current frame of interest

getCurrInterval

public InstantInterval getCurrInterval(boolean frameBased)
Gets a single frame interval surrounding the current instant of interest.

Parameters:
frameBased - true asks for the interval in terms of frames, while false will give the interval in time.
Returns:
the interval, in frame or time as requested

setMajorMoment

public void setMajorMoment(Instant majorMoment)
Sets the majorMoment.

Parameters:
majorMoment - The majorMoment to set

getNewFileActionListener

public java.awt.event.ActionListener getNewFileActionListener()
Gets an action that will open a new, empty metadata file.

Returns:
an "Open New File" action object

saveDiscardOrCancelIfChanged

public void saveDiscardOrCancelIfChanged(java.lang.Runnable ok)
Brings up the save/discard/cancel prompt if there are any items in the action history (ie the file has been altered since it was opened/created); otherwise, just runs the Runnable. If there is no history manager, it always prompts the user.

Parameters:
ok - To execute if the user doesn't cancel.

saveDiscardOrCancel

public void saveDiscardOrCancel(java.lang.Runnable ok)
Prompts the user if she would like to save the changes, discard the changes, or cancel the current action. If the user selects save or discard, the given runnable is executed. Note, it is executed in the ui thread.

Parameters:
ok - to run if the user selects 'okay'

getRecentlyViewedFileActionListener

public java.awt.event.ActionListener getRecentlyViewedFileActionListener()
Gets an action that will open the recently viewed file referenced in the action command.

Returns:
the MRU file opener action

getRedoActionListener

public edu.umd.cfar.lamp.viper.gui.core.ViperViewMediator.RedoActionListener getRedoActionListener()
Gets an action that will redo the last undone action that hasn't been redone, if one exists.

Returns:
a redo action object

getUndoActionListener

public edu.umd.cfar.lamp.viper.gui.core.ViperViewMediator.UndoActionListener getUndoActionListener()
Gets an action that will undo the last action.

Returns:
an undo action object

getOpenFileActionListener

public java.awt.event.ActionListener getOpenFileActionListener()
Gets the 'open file' action.

Returns:
an open file action

duplicateDescriptor

public Descriptor duplicateDescriptor(Descriptor instance)
Copies the given descriptor and adds it to the descriptor's parent sourcefile node.

Parameters:
instance - the descriptor to copy
Returns:
the new descriptor

getSaveDiscardOrCancelDialogVeto

public AttemptToPerformAction getSaveDiscardOrCancelDialogVeto()
Gets a 'Save, Discard, or Cancel' dialog up.

Returns:
an action attemptor

getSaveActionListener

public java.awt.event.ActionListener getSaveActionListener()
Gets the 'Save Current File' action object.

Returns:
a save action

getSaveAsActionListener

public java.awt.event.ActionListener getSaveAsActionListener()
Gets the 'Save File As...' action object.

Returns:
a 'Save File As...' action object

getExportCurrentFileActionListener

public java.awt.event.ActionListener getExportCurrentFileActionListener()
Gets an action object for the 'export current file as a .gtf file' option.

Returns:
an 'export' action

getImportGTFFileActionListener

public java.awt.event.ActionListener getImportGTFFileActionListener()
Gets an action object for the 'Import GTF into Current Media File' menu option.

Returns:
an import gtf action object

getImportConfigActionListener

public java.awt.event.ActionListener getImportConfigActionListener()
Gets an action object that will import the viper schema of an existing file.

Returns:
an import config action object

getPrefs

public PrefsManager getPrefs()
Gets the associated application loader preference manager.

Returns:
the preferences

setPrefs

public void setPrefs(PrefsManager manager)
Sets the associated preference manager.

Parameters:
manager - a set of preferences that describes the applications and the user preferences for it

getHistoryManager

public FileHistoryManager getHistoryManager()
Gets the MRU file history manager.

Returns:
the file history

setHistoryManager

public void setHistoryManager(FileHistoryManager manager)
Sets the file history manager to use with the application.

Parameters:
manager - the file history

getActionHistory

public ActionHistoryPane getActionHistory()
Gets the undo/redo action history.

Returns:
the undo/redo panel

setActionHistory

public void setActionHistory(ActionHistoryPane ahp)
Sets the action history panel.

Parameters:
ahp - the new event history panel

getCreateInstanceActionListener

public java.awt.event.ActionListener getCreateInstanceActionListener()
Returns:
ActionListener

getDeleteInstanceActionListener

public java.awt.event.ActionListener getDeleteInstanceActionListener()
Gets an action listener that tries to delete the currently selected descriptor, if it exists.

Returns:
ActionListener

getDuplicateInstanceActionListener

public java.awt.event.ActionListener getDuplicateInstanceActionListener()
Gets an action listener that tries to copy the selected object descriptor, if it exists.

Returns:
ActionListener

getSelectAttributeActionListener

public java.awt.event.ActionListener getSelectAttributeActionListener()
Returns:
ActionListener

getSelectDescriptorConfigActionListener

public java.awt.event.ActionListener getSelectDescriptorConfigActionListener()
Returns:
ActionListener

getSelectDescriptorInstanceActionListener

public java.awt.event.ActionListener getSelectDescriptorInstanceActionListener()
Returns:
ActionListener

getMoveAttributeActionListener

public edu.umd.cfar.lamp.viper.gui.core.ViperViewMediator.MoveAttributeActionListener getMoveAttributeActionListener()
Returns:
MoveAttributeActionListener

setAttributeValueAtCurrentFrame

public void setAttributeValueAtCurrentFrame(java.lang.Object val,
                                            Attribute a)
Sets the value of an attribute (or the default value of an attribute, if val is an AttrConfig). Also knows about dynamic v. static, and uses the MajorMoment of the mediator to set dynamic attributes for one frame only.

Parameters:
val - the new value
a - the attribute on which to set the value

setAttributeValueAtSpan

public void setAttributeValueAtSpan(java.lang.Object val,
                                    Attribute a,
                                    InstantInterval span)
Sets the value of an attribute (or the default value of an attribute, if val is an AttrConfig). Also knows about dynamic v. static, and uses the MajorMoment of the mediator to set dynamic attributes for one frame only. Note that in the case of nillable attributes, setting the value to 'null' won't change the descriptor's valid range. For convenience, setting the attribute to non-null changes the enclosing descriptor instance's range to include the span. Also, you will only be able to set values on spans that are contained by the enclosing descriptor (e.g. valid frames). You can cheat by passing a TemporalRange object as the value; this will just replace the current attribute value.

Parameters:
val - the new value
a - the attribute on which to set the value
span - the instant interval at which to set the value

isThisValidNow

public boolean isThisValidNow(Descriptor d)
Tests to see if the descriptor is valid at the current frame/time of user interest.

Parameters:
d - the descriptor
Returns:
if the descriptor is valid at the current moment

getPropagator

public PropagateInterpolateModule getPropagator()
Gets the propagation object.

Returns:
an object that supports propagation and interpolation of the currently loaded data set

getHiders

public NodeVisibilityManager getHiders()
Gets the manager of the set of hidden items.

Returns:
an object which controls which descriptors or attributes should be hidden

getSelection

public ViperSelectionSet getSelection()
Gets the currently selected metadata item.

Returns:
the selection object

getPrimarySelection

public ViperSubTree getPrimarySelection()
Gets the current top-selection of the user. This is the most recent selected element, and contained within the selection returned in getSelection()

Returns:
the last element selected

getMarkerModel

public ChronicleMarkerModel getMarkerModel()
Returns the model that should be used to display markers on a chronicle view, if one is attatched

Returns:
the marker model, or the set of user and system defined moments on the currently viewed source file that are important for some reason or other.

setMarkerModel

public void setMarkerModel(ChronicleMarkerModel model)
Sets the marker model. Doesn't set the marker model on the displayed chronicle; rather, the displayed chronicle should call this to allow other components access to its marker model.

Parameters:
model - the model that is the reference marker model

getDisplayWRTManager

public DisplayWithRespectToManager getDisplayWRTManager()
Use this method to access the display wrt manager, and then you can add listeners to it. The DWRT manager controls what the current 'display with respect to' object is; this attribute is used to center or resize the display, keeping the element fixed in location, orientation, or even shape.

Returns:
the dwrt manager

displayHotkeyBindings

public void displayHotkeyBindings()
Displays the current hotkey bindings in a new window.


getDisplayHotkeyBindingsActionListener

public java.awt.event.ActionListener getDisplayHotkeyBindingsActionListener()
Gets an action that displays the current hotkey bindings.

Returns:
a 'display hotkey bindings' action object

isShowingInvalid

public boolean isShowingInvalid()
Tests to see if the user should care about descriptors that are invalid at the current frame of interest.

Returns:
if client views should show information about objects that aren't valid at the current major moment

setShowingInvalid

public void setShowingInvalid(boolean showingInvalid)
Turns on/off the invalid descriptors in the spreadsheet view.

Parameters:
showingInvalid - the new value

getToggleDisplayInvalidActionListener

public java.awt.event.ActionListener getToggleDisplayInvalidActionListener()
Gets an action that toggles the 'showing invalid' property.

Returns:
an action which shows/hides the invalid descriptors in the spreadsheet, and any other appropriate view

setPropagator

public void setPropagator(PropagateInterpolateModule propagator)