net.sourceforge.nite.gui.timelineviewer
Class TimeGrid

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by net.sourceforge.nite.gui.timelineviewer.TimeGrid
All Implemented Interfaces:
java.awt.event.MouseListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, NOMElementSelector, QueryResultHandler, ScrollingTimeHandler, TimeHandler

public class TimeGrid
extends javax.swing.JPanel
implements ScrollingTimeHandler, java.awt.event.MouseListener, NOMElementSelector, QueryResultHandler

A simple timeline. This can display layers of elements Influenced but not the same as the Timeline in JFerret by Mike Flynn. This should be used with TimeBlob. To allow this class to create new elements, you need to pass a valid class to @link #setElementCreator.

Author:
Craig Nicol, Jonathan Kilgour, Mike Flynn
See Also:
TimeBlob, Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.BaselineResizeBehavior
 
Field Summary
 
Fields inherited from class javax.swing.JComponent
TOOL_TIP_TEXT_KEY, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
TimeGrid()
           
TimeGrid(NiteTimeline ntl)
           
 
Method Summary
 void acceptQueryResult(NOMElement result)
          Query Result Handling
 void acceptQueryResults(java.util.List results)
          accept a query result as a list of NOMElements
 void acceptTimeChange(double systemTime)
          Accept a new time (generally from another registered TimeHandler).
 void acceptTimeSpanChange(double start, double end)
          Accept a new time span from another registered time handler.
 void addCustomLayer(javax.swing.JComponent clayer)
           
 void addLayerHeader(javax.swing.JScrollPane jsp)
           
 void addNOMElementSelectionListener(NOMElementSelectionListener l)
           
 void addTimeHeader(javax.swing.JScrollPane jsp)
           
 void drawGrid(java.awt.Graphics g)
          Draw a grid on the background, representing time.
 int getBlobFatness()
          get width of all blobs (or height if horizontal)
 Clock getClock()
          Return the Clock that is currently syncronising this TimeHandler
 java.awt.Color getColour(TimeBlob tb)
          return Color of given Blob
 java.awt.Dimension getDimension(TimeBlob tb)
          return dimension of given Blob in screen pixels
 int getHeight(net.sourceforge.nite.gui.timelineviewer.TimedComponent tb)
          return height of given Blob in screen pixels
 boolean getHighlighted(TimeBlob tb)
           
 double getMaxTime()
          find the largest end time handled by this TimeHandler.
 int getMaxTimeInMilliseconds()
           
 double getMaxTimeInSeconds()
          return the latest end time of any blob
 java.awt.Color getQueryHighlightColor()
           
 TimeBlob getSelectedBlob()
           
 java.awt.Color getSelectedColor()
           
 java.util.List getSelectedElements()
           
 java.awt.Color getTimeHighlightColor()
           
 int getWidth(net.sourceforge.nite.gui.timelineviewer.TimedComponent tb)
          return width of given TimedComponent in screen pixels
 int getX(net.sourceforge.nite.gui.timelineviewer.TimedComponent tb)
          get X position of Blob in screen pixels
 int getY(net.sourceforge.nite.gui.timelineviewer.TimedComponent tb)
          get Y position of Blob in screen pixels
 boolean isHorizontal()
          get orientation of grid - true = horizontal; false = vertical
 boolean isQueryResult(TimeBlob tb)
           
 int layerPos(net.sourceforge.nite.gui.timelineviewer.TimedComponent tb)
          calculate pos of layer taking recursive layer into account
 void mouseClicked(java.awt.event.MouseEvent e)
           
 void mouseEntered(java.awt.event.MouseEvent e)
           
 void mouseExited(java.awt.event.MouseEvent e)
           
 void mousePressed(java.awt.event.MouseEvent e)
           
 void mouseReleased(java.awt.event.MouseEvent e)
           
 void registerLayer(java.lang.String layername, int maxdepth)
          Called when a new layer is added - make sure the layer has a colour and location (and max recursive depth
 void removeNOMElementSelectionListener(NOMElementSelectionListener l)
           
 void reset()
           
 void setBlobFatness(int val)
          set width of all blobs (or height if horizontal)
 void setBlobLabel(boolean val)
          set property where we try to show labels on Blobs
 void setCanEditElements(boolean canEditElements)
          Does the grid allow the start and end points of existing elements to be edited?
 void setClock(Clock clock)
          Set the Clock to which this TimeHandler is registered
 void setElementCreator(TimelineNOMElementCreator elementCreator)
           
 void setHorizontal(boolean horiz)
          set orientation of grid - true = horizontal; false = vertical
 void setLayerColour(java.lang.String layername, java.awt.Color col)
          set orientation of grid - true = horizontal; false = vertical
 void setQueryHighlightColor(java.awt.Color color)
          set the colour of the highlighting for queries
 void setScale(int pix)
          set scale of grid - the number is the number of milliseconds per pixel (default is 1000) NOTE: This automatically redraws the window
 void setSelected(TimeBlob tb)
           
 void setSelectedColor(java.awt.Color selectedColor)
           
 void setSnapToTime(boolean snapToTime)
          Do certain mouse actions snap to the current time? Currently only affects: Creation of new blobs (when clock is running).
 void setTime(double time)
          Broadcast a new time.
 void setTimeHighlightColor(java.awt.Color color)
          Change the Color used for all registered TimeHandlers to highlight times
 void setTimeline(NiteTimeline ntl)
          Assign a timeline to this timegrid (essential if you want to create blobs using delegates)
 void setTimeSpan(double start, double end)
          Broadcast a new span to all registered TimeHandlers.
 boolean showLabels()
          return true if Blobs should have labels
 void testCustomLayer()
           
 int timeToPixels(int timeinmilliseconds)
          translate time in milliseconds to pixels onscreen
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TimeGrid

public TimeGrid()

TimeGrid

public TimeGrid(NiteTimeline ntl)
Method Detail

reset

public void reset()

addTimeHeader

public void addTimeHeader(javax.swing.JScrollPane jsp)

addLayerHeader

public void addLayerHeader(javax.swing.JScrollPane jsp)

testCustomLayer

public void testCustomLayer()

addCustomLayer

public void addCustomLayer(javax.swing.JComponent clayer)

getMaxTimeInSeconds

public double getMaxTimeInSeconds()
return the latest end time of any blob


getMaxTimeInMilliseconds

public int getMaxTimeInMilliseconds()

setSnapToTime

public void setSnapToTime(boolean snapToTime)
Do certain mouse actions snap to the current time? Currently only affects:

Parameters:
snapToTime - the value to set

setCanEditElements

public void setCanEditElements(boolean canEditElements)
Does the grid allow the start and end points of existing elements to be edited?

Parameters:
canEditElements - the canEditElements to set

setScale

public void setScale(int pix)
set scale of grid - the number is the number of milliseconds per pixel (default is 1000) NOTE: This automatically redraws the window


setHorizontal

public void setHorizontal(boolean horiz)
set orientation of grid - true = horizontal; false = vertical


setLayerColour

public void setLayerColour(java.lang.String layername,
                           java.awt.Color col)
set orientation of grid - true = horizontal; false = vertical


isHorizontal

public boolean isHorizontal()
get orientation of grid - true = horizontal; false = vertical


setBlobFatness

public void setBlobFatness(int val)
set width of all blobs (or height if horizontal)


getBlobFatness

public int getBlobFatness()
get width of all blobs (or height if horizontal)


setBlobLabel

public void setBlobLabel(boolean val)
set property where we try to show labels on Blobs


showLabels

public boolean showLabels()
return true if Blobs should have labels


setSelected

public void setSelected(TimeBlob tb)

getSelectedBlob

public TimeBlob getSelectedBlob()

getSelectedElements

public java.util.List getSelectedElements()
Specified by:
getSelectedElements in interface NOMElementSelector

addNOMElementSelectionListener

public void addNOMElementSelectionListener(NOMElementSelectionListener l)

removeNOMElementSelectionListener

public void removeNOMElementSelectionListener(NOMElementSelectionListener l)

timeToPixels

public int timeToPixels(int timeinmilliseconds)
translate time in milliseconds to pixels onscreen


drawGrid

public void drawGrid(java.awt.Graphics g)
Draw a grid on the background, representing time.


getDimension

public java.awt.Dimension getDimension(TimeBlob tb)
return dimension of given Blob in screen pixels


getColour

public java.awt.Color getColour(TimeBlob tb)
return Color of given Blob


getHighlighted

public boolean getHighlighted(TimeBlob tb)

getWidth

public int getWidth(net.sourceforge.nite.gui.timelineviewer.TimedComponent tb)
return width of given TimedComponent in screen pixels


getHeight

public int getHeight(net.sourceforge.nite.gui.timelineviewer.TimedComponent tb)
return height of given Blob in screen pixels


getX

public int getX(net.sourceforge.nite.gui.timelineviewer.TimedComponent tb)
get X position of Blob in screen pixels


getY

public int getY(net.sourceforge.nite.gui.timelineviewer.TimedComponent tb)
get Y position of Blob in screen pixels


layerPos

public int layerPos(net.sourceforge.nite.gui.timelineviewer.TimedComponent tb)
calculate pos of layer taking recursive layer into account


registerLayer

public void registerLayer(java.lang.String layername,
                          int maxdepth)
Called when a new layer is added - make sure the layer has a colour and location (and max recursive depth


getMaxTime

public double getMaxTime()
Description copied from interface: TimeHandler
find the largest end time handled by this TimeHandler. This is only really applicable to text areas.

Specified by:
getMaxTime in interface TimeHandler

acceptTimeChange

public void acceptTimeChange(double systemTime)
Description copied from interface: TimeHandler
Accept a new time (generally from another registered TimeHandler). Do what you have to do in this TimeHandler to represent the fact that the global system time is now 'systemTime' (but don't inform the niteclock to pass it on).

Specified by:
acceptTimeChange in interface TimeHandler

setTime

public void setTime(double time)
Description copied from interface: TimeHandler
Broadcast a new time. Implement by sending a setSystemTime call to the current Clock.

Specified by:
setTime in interface TimeHandler

acceptTimeSpanChange

public void acceptTimeSpanChange(double start,
                                 double end)
Description copied from interface: TimeHandler
Accept a new time span from another registered time handler. This may involve changing our on-screen appearance to introduce some new time highlights, or playing a stretch of video, depending on the type of handler.

Specified by:
acceptTimeSpanChange in interface TimeHandler

setTimeSpan

public void setTimeSpan(double start,
                        double end)
Description copied from interface: TimeHandler
Broadcast a new span to all registered TimeHandlers.

Specified by:
setTimeSpan in interface TimeHandler

getClock

public Clock getClock()
Description copied from interface: TimeHandler
Return the Clock that is currently syncronising this TimeHandler

Specified by:
getClock in interface TimeHandler

setClock

public void setClock(Clock clock)
Description copied from interface: TimeHandler
Set the Clock to which this TimeHandler is registered

Specified by:
setClock in interface TimeHandler

setTimeHighlightColor

public void setTimeHighlightColor(java.awt.Color color)
Description copied from interface: TimeHandler
Change the Color used for all registered TimeHandlers to highlight times

Specified by:
setTimeHighlightColor in interface TimeHandler

getTimeHighlightColor

public java.awt.Color getTimeHighlightColor()

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Specified by:
mouseClicked in interface java.awt.event.MouseListener

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Specified by:
mousePressed in interface java.awt.event.MouseListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Specified by:
mouseReleased in interface java.awt.event.MouseListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Specified by:
mouseExited in interface java.awt.event.MouseListener

getSelectedColor

public java.awt.Color getSelectedColor()
Returns:
the selectedColor

setSelectedColor

public void setSelectedColor(java.awt.Color selectedColor)
Parameters:
selectedColor - the selectedColor to set

acceptQueryResult

public void acceptQueryResult(NOMElement result)
Query Result Handling

Specified by:
acceptQueryResult in interface QueryResultHandler

acceptQueryResults

public void acceptQueryResults(java.util.List results)
Description copied from interface: QueryResultHandler
accept a query result as a list of NOMElements

Specified by:
acceptQueryResults in interface QueryResultHandler

isQueryResult

public boolean isQueryResult(TimeBlob tb)

setQueryHighlightColor

public void setQueryHighlightColor(java.awt.Color color)
Description copied from interface: QueryResultHandler
set the colour of the highlighting for queries

Specified by:
setQueryHighlightColor in interface QueryResultHandler

getQueryHighlightColor

public java.awt.Color getQueryHighlightColor()

setElementCreator

public void setElementCreator(TimelineNOMElementCreator elementCreator)
Parameters:
elementCreator - the elementCreator to set

setTimeline

public void setTimeline(NiteTimeline ntl)
Assign a timeline to this timegrid (essential if you want to create blobs using delegates)

Parameters:
ntl - the NiteTimeline to set