did.gui
Class DIDImageCanvas

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JLayeredPane
                          |
                          +--javax.swing.JDesktopPane
                                |
                                +--did.gui.DIDImageCanvas

public class DIDImageCanvas
extends javax.swing.JDesktopPane
implements javax.swing.Scrollable

File:         DIDImageCanvas.java
Version:      1.1
Description:  This component is an implementation of JComponent that is responsible for the
display and manipulation of ground truth data (XML).  This is accomplished through a 
heirarchal series of objects called ROIs (Regions of Interest).  Each ROI has a 
corresponding node in the DIDDefaultDataModel which it communicates with to retrieve and
store its vertex data. Note: For future versions of this software it would be wise to 
investigate turning this class into a viewer in the Swing MVC model.  This would simplify
the messaging routines(through listeners), make the code much more streamlined and easier 
to understand and maintain.  Also it would provide a higher degree of abstraction further
serparating the data form the view and possible allowing other methods for viewing the 
data using the same data model.

Modification Log:
Date          Name    Comment
xx-xx-xxxx    XXX	   xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

See Also:
Serialized Form

Inner classes inherited from class javax.swing.JDesktopPane
javax.swing.JDesktopPane.AccessibleJDesktopPane
 
Inner classes inherited from class javax.swing.JLayeredPane
javax.swing.JLayeredPane.AccessibleJLayeredPane
 
Inner classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Field Summary
protected static DIDRoiIFC activeRoi
          A reference to the DIDRoiIFC interface.
protected  java.awt.geom.AffineTransform at
          JAVA 2D coordinate mapping object necessary to render main image.
protected  DIDCreationHandler cHandler
          Reference to a class used to manage the creation of new ROIs.
static int CREATE
          These Constants define the state of the canvas.
static int EDIT
          These Constants define the state of the canvas.
protected  DIDEditHandler eHandler
          Reference to a class used to manage the editing of a single ROI.
static int IMAGE_ONLY
          These Constants define the state of the canvas.
protected  java.awt.Image img
          JAI implementation of RenderedImage interface used to display image files.
protected  boolean isSetNext
           
protected  int maxUnitIncrement
          An integer representing the maximum unit the component should be scrolled (when necessary).
protected  double myLeftRotationFactor
          A double representing the degree and direction by which an ROI should be rotated.
static int myMode
          This integer holds the current state of the canvas: Creating OR Editing.
protected  DIDDefaultTreeModel myModel
          Reference to the TreeModel for which this class is acting as a viewer.
protected  double myRightRotationFactor
          A double representing the degree and direction by which an ROI should be rotated.
protected static java.util.Vector myRoiChildren
          Vector whose purpose is to hold and track all the DIDRoiIFC object implementations currently being displayed with the exception of the parent node's ROI.
protected static java.util.Vector myROIs
          Vector whose purpose is to hold and track all the DIDRoiIFC object implementations of the current data model.
protected  DIDTree myTree
          Reference to the Tree viewer which is also viewing the data.
static int myView
          This integer determines what set of ROIs the canvas is to display.
protected static DIDRoiIFC parentRoi
          A reference to the DIDRoiIFC interface.
protected  java.awt.Image scaledImg
           
protected  DIDSelectionHandler sHandler
          Reference to a class used to manage the selection of multiple overlapping ROIs.
 
Fields inherited from class javax.swing.JLayeredPane
DEFAULT_LAYER, DRAG_LAYER, FRAME_CONTENT_LAYER, LAYER_PROPERTY, MODAL_LAYER, PALETTE_LAYER, POPUP_LAYER
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, 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
 
Constructor Summary
DIDImageCanvas(java.lang.String fileName, int unit, DIDTree newTree, TrueViz frame)
          Constructor used to initialize the component.
 
Method Summary
 boolean arrowDisplay()
           
 void changeScale(float newscale)
           
 void deleteNext()
           
 void deleteRoi()
          Method used to remove and ROI and its corresponding data from the display and data file respectively.
 void displayInfopanel()
           
 int getMode()
          Method used to get the Mode of the ImageCanvas.
 java.awt.Dimension getPreferredScrollableViewportSize()
          Part of Scrollable Interface Implementation used to return the preferred display size of the ImageCanvas.
 float getScale()
           
 int getScrollableBlockIncrement(java.awt.Rectangle visibleRect, int orientation, int direction)
          Method used to determine the amount for a block inrecment, which is the height or width of visibleRect, based on orientation.
 boolean getScrollableTracksViewportHeight()
          Returns false to indicate that the height of the viewport does not determine the height of the table, unless the preferred height of the tree is smaller than the viewports height.
 boolean getScrollableTracksViewportWidth()
          Returns false to indicate that the width of the viewport does not determine the width of the table, unless the preferred width of the tree is smaller than the viewports width.
 int getScrollableUnitIncrement(java.awt.Rectangle visibleRect, int orientation, int direction)
          Part of Scrollable Interface Implementation necessary to determine the amount by which to scroll the object in the viewport when necessary.
 int getView()
          Method used to return the current view of this ImageCanvas (Page, Zone, Line, Character).
 void init()
          Method used to initialize this object.
 void newRoi(int type)
          Method used to create new ROIs.
 void paintComponent(java.awt.Graphics g)
          Method used to perform the custom painting necessary to display the appropriate ROIs.
 void reset()
          Method used to clear all the zones from the screen.
 void resetFocus()
          Method used take the focus away from all the ROIs on the screen (mainly to releave formatting issues).
 void rotateLeft()
          Method used rotate the selected ROI to the left.
 void rotateRight()
          Method used rotate the selected ROI to the right.
 void searchFind()
           
 void searchFindDir()
           
 void setArrowDisplay(boolean boolVal)
           
 void setArrowDisplay(int entityType, boolean boolVal)
           
 void setFillColors(boolean fill)
           
 void setImage(java.lang.String fileName)
          This method is responsible for creating an image object from a file reference.
 void setMaxUnitIncrement(int pixels)
          Method used to set the maximum unit (in pixels) by which this object should scroll.
 void setMode(int mode)
          Method used to set the Mode of the ImageCanvas.
 void setMouseCoordinate(int x, int y)
           
 void setNext()
           
 void setNext(DIDRoiIFC nextRoi)
           
 void setScale(float newscale)
           
 boolean setView(int newView)
          Method used to determine which level of ROIs the ImageCanvas should display.
 void showInfopanel()
           
 void zoomIn()
           
 void zoomOut()
           
 
Methods inherited from class javax.swing.JDesktopPane
getAccessibleContext, getAllFrames, getAllFramesInLayer, getDesktopManager, getUI, getUIClassID, isOpaque, paramString, setDesktopManager, setUI, updateUI
 
Methods inherited from class javax.swing.JLayeredPane
addImpl, getComponentCountInLayer, getComponentsInLayer, getComponentToLayer, getIndexOf, getLayer, getLayer, getLayeredPaneAbove, getObjectForLayer, getPosition, highestLayer, insertIndexForLayer, isOptimizedDrawingEnabled, lowestLayer, moveToBack, moveToFront, paint, putLayer, remove, setLayer, setLayer, setPosition
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getAlignmentX, getAlignmentY, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getGraphics, getHeight, getInsets, getInsets, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getVisibleRect, getWidth, getX, getY, grabFocus, hasFocus, isDoubleBuffered, isFocusCycleRoot, isFocusTraversable, isLightweightComponent, isManagingFocus, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, processComponentKeyEvent, processFocusEvent, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDoubleBuffered, setEnabled, setFont, setForeground, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setUI, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getLayout, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, removeAll, removeContainerListener, setCursor, setLayout, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hide, imageUpdate, inside, isDisplayable, isEnabled, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processInputMethodEvent, processMouseEvent, remove, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setDropTarget, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

EDIT

public static final int EDIT
These Constants define the state of the canvas. The component is usually in the EDIT state unless a new ROI needs to be created in which case it enters the CREATE state. These could be elminated in future versions of the code.

CREATE

public static final int CREATE
These Constants define the state of the canvas. The component is usually in the EDIT state unless a new ROI needs to be created in which case it enters the CREATE state. These could be elminated in future versions of the code.

IMAGE_ONLY

public static final int IMAGE_ONLY
These Constants define the state of the canvas. The component is usually in the EDIT state unless a new ROI needs to be created in which case it enters the CREATE state. These could be elminated in future versions of the code.

myMode

public static int myMode
This integer holds the current state of the canvas: Creating OR Editing.

myView

public static int myView
This integer determines what set of ROIs the canvas is to display. Valid values are contained in the DIDRoiIFC interface (PAGE, ZONE, LINE, CHARACTER).

myRoiChildren

protected static java.util.Vector myRoiChildren
Vector whose purpose is to hold and track all the DIDRoiIFC object implementations currently being displayed with the exception of the parent node's ROI. The ROIs to be displayed are dependent on the view setting.

myROIs

protected static java.util.Vector myROIs
Vector whose purpose is to hold and track all the DIDRoiIFC object implementations of the current data model.

activeRoi

protected static DIDRoiIFC activeRoi
A reference to the DIDRoiIFC interface. This reference is used to point to the ROI that is being manipulated by the user.

parentRoi

protected static DIDRoiIFC parentRoi
A reference to the DIDRoiIFC interface. This reference is used to point to the parent ROI of current view. For example if the view is Page or Zone then the ROI is null but if the view is Line then this attribute holds the ROI of the Zone those lines belong to.

maxUnitIncrement

protected int maxUnitIncrement
An integer representing the maximum unit the component should be scrolled (when necessary).

myLeftRotationFactor

protected double myLeftRotationFactor
A double representing the degree and direction by which an ROI should be rotated. (Counter-Clockwise)

myRightRotationFactor

protected double myRightRotationFactor
A double representing the degree and direction by which an ROI should be rotated. (Clockwise)

at

protected java.awt.geom.AffineTransform at
JAVA 2D coordinate mapping object necessary to render main image. Contains any transforms that should be applied to the graphics object prior to rendering.

img

protected java.awt.Image img
JAI implementation of RenderedImage interface used to display image files. This class is used becuase the JAI provides support for most TIFF formats (except LZW) and can, via the JAI class, construct a PlanarImage from a file. The PlanarImage can then be used by Java2D's Graphics2D.drawRenderImage() method.

scaledImg

protected java.awt.Image scaledImg

isSetNext

protected boolean isSetNext

sHandler

protected DIDSelectionHandler sHandler
Reference to a class used to manage the selection of multiple overlapping ROIs.

eHandler

protected DIDEditHandler eHandler
Reference to a class used to manage the editing of a single ROI.

cHandler

protected DIDCreationHandler cHandler
Reference to a class used to manage the creation of new ROIs.

myModel

protected DIDDefaultTreeModel myModel
Reference to the TreeModel for which this class is acting as a viewer.

myTree

protected DIDTree myTree
Reference to the Tree viewer which is also viewing the data. The purpose of this attribute is to expose this object to the various handlers so they can manipulate the Tree based on their own set of circumstances.
Constructor Detail

DIDImageCanvas

public DIDImageCanvas(java.lang.String fileName,
                      int unit,
                      DIDTree newTree,
                      TrueViz frame)
Constructor used to initialize the component. Sets up listeners, reference to background image, reference to data model and component state.
Parameters:
fileName - A string representing the absolute path to the image file that this class is to display.
unit - The maximum amount to move the ImageCanvas when scrolling is necessary.
newTree - Reference to DIDTree that is also visualing data (XML).
See Also:
init(), setImage(java.lang.String)
Method Detail

init

public void init()
Method used to initialize this object. In this implementation this method adds the appropriate Mouse Listeners (one for Editing, Creating and Selecting ROIs) as well as initializing the view to the PAGE level and the mode to allow the user to edit. (Note: The order in which these listeners are added is the order in which they recieve event notification.)

paintComponent

public void paintComponent(java.awt.Graphics g)
Method used to perform the custom painting necessary to display the appropriate ROIs. The painting is performed in a layered approach. First the image being Ground Truthed is painted. Then based on the ImageCanvas's mode the appropriate ROIs are painted. For the create mode the parent Roi is painted first then all the children except for the activeRoi which is painted last to ensure it's on top. For the edit mode if the view is set to page then all the ROIs are displayed. If the view is in any other state then only that set of ROIs is painted along with that sets parent (if applicable).
Overrides:
paintComponent in class javax.swing.JComponent
Parameters:
g - A Graphics object that represents all the visual data contained in this object's Graphics window.

showInfopanel

public void showInfopanel()

displayInfopanel

public void displayInfopanel()

setImage

public void setImage(java.lang.String fileName)
This method is responsible for creating an image object from a file reference. The image object is basically a background on top of which all ROIs are drawn. The image object is created using a call to the JAI class's create method. This method reads the filename passed to it and returns a PlanarImage which is an implementation of the RenderedImage interface. The PalnarImage can then be painted on this object using the drawRenderedImage() method of the Graphics2D object in the paintComponent() method.
Parameters:
e - String reprsenting the filename from which an image object should be created.
See Also:
paintComponent(java.awt.Graphics)

setScale

public void setScale(float newscale)

getScale

public float getScale()

zoomIn

public void zoomIn()

zoomOut

public void zoomOut()

changeScale

public void changeScale(float newscale)

newRoi

public void newRoi(int type)
Method used to create new ROIs. Based on the parameter passed to this method, the appropriate type of RIO is created. This method also sets the showCoordinates attribute for the ROI being created based on the current view and the corresponding setting the trueviz.properties file.
Parameters:
type - An integer representing the type of ROI to create. This integer comes from the DIDRoiIFC interface constants used to define the type of ROI.

deleteRoi

public void deleteRoi()
Method used to remove and ROI and its corresponding data from the display and data file respectively. This process involves deleting the NOTE: Explore using myModel.removeNodeFromParent(childNode) instead of reload to delete. The problem with using reload is that even though it does meassage all TreeModelListners registered on this model is does not fire the NodesRemoved method. Instead it fires the TreeStructureChanged (which makes sense because you could be deleting a large protion of the tree).

setMode

public void setMode(int mode)
Method used to set the Mode of the ImageCanvas. The mode is used to dertermine what this object should paint. If the user is creating ROIs then it should follow one painting path and if the user is editing ROIs then it should follow another path. This methodology was usefull in early versions of the code but now is somewhat antiquated and could be eliminated in future versions.
Parameters:
An - integer used to determine the mode of the object.
See Also:
paintComponent(java.awt.Graphics)

getMode

public int getMode()
Method used to get the Mode of the ImageCanvas. This method is also somewhat antiquated and could be eliminated in future verions.
Returns:
An integer representing the mode of the ImageCanvas (Create, Edit).

setView

public boolean setView(int newView)
Method used to determine which level of ROIs the ImageCanvas should display. There are currently four level: Page, Zone, Line, and Character. To pass from one level to another there a series of checks to ensure that there is an ROI selected (else how do you know what sub-level ROIs to display) and the proper progression of level is being used. This method also sets the parentRoi based on the level and constructs the myRoiChildren.
Parameters:
newView - An interger constant from the DIDRoiIFC class that represent the level of ROIs to display.
Returns:
True if the view changed to the setting passed in as a parameter, false if it did not change.

getView

public int getView()
Method used to return the current view of this ImageCanvas (Page, Zone, Line, Character).
Returns:
An integer representing the current view the

reset

public void reset()
Method used to clear all the zones from the screen. Clears the vector that holds all ROI objects, the vector that holds ROI children and reset the Mulit-select mechanism.

resetFocus

public void resetFocus()
Method used take the focus away from all the ROIs on the screen (mainly to releave formatting issues).

rotateLeft

public void rotateLeft()
Method used rotate the selected ROI to the left. This method does so by setting the rotation factor of the selected ROI and then repainting the entire canvas. NOTE: The rotation is performed around the active vertex. To finalize the rotation the user must click on the ROI after rotation is complete.

rotateRight

public void rotateRight()
Method used rotate the selected ROI to the right. This method does so by setting the rotation factor of the selected ROI and then repainting the entire canvas. NOTE: The rotation is performed around the active vertex. To finalize the rotation the user must click on the ROI after rotation is complete.

getPreferredScrollableViewportSize

public java.awt.Dimension getPreferredScrollableViewportSize()
Part of Scrollable Interface Implementation used to return the preferred display size of the ImageCanvas.
Specified by:
getPreferredScrollableViewportSize in interface javax.swing.Scrollable
Returns:
Dimension This method returns a Dimension object represention the perferred size of the this object.

getScrollableUnitIncrement

public int getScrollableUnitIncrement(java.awt.Rectangle visibleRect,
                                      int orientation,
                                      int direction)
Part of Scrollable Interface Implementation necessary to determine the amount by which to scroll the object in the viewport when necessary.
Specified by:
getScrollableUnitIncrement in interface javax.swing.Scrollable
Parameters:
visibleRect - A Rectangle object representing the visible portion of the component.
orientation - Either SwingConstants.VERTICAL or SwingConstants.HORIZONTAL
direction - Less than zero to scroll up/left, greater than zero for down/right.
Returns:
This method returns an integer represeting the number of pixels to scroll.

getScrollableBlockIncrement

public int getScrollableBlockIncrement(java.awt.Rectangle visibleRect,
                                       int orientation,
                                       int direction)
Method used to determine the amount for a block inrecment, which is the height or width of visibleRect, based on orientation.
Specified by:
getScrollableBlockIncrement in interface javax.swing.Scrollable
Parameters:
visibleRect - The view area visible within the viewport
orientation - Either SwingConstants.VERTICAL or SwingConstants.HORIZONTAL
direction - Less than zero to scroll up/left, greater than zero for down/right.
Returns:
Returns the amount for a block inrecment, which is the height or width of visibleRect, based on orientation

getScrollableTracksViewportHeight

public boolean getScrollableTracksViewportHeight()
Returns false to indicate that the height of the viewport does not determine the height of the table, unless the preferred height of the tree is smaller than the viewports height. In other words: ensure that the tree is never smaller than its viewport.
Specified by:
getScrollableTracksViewportHeight in interface javax.swing.Scrollable
Returns:
false

getScrollableTracksViewportWidth

public boolean getScrollableTracksViewportWidth()
Returns false to indicate that the width of the viewport does not determine the width of the table, unless the preferred width of the tree is smaller than the viewports width. In other words: ensure that the tree is never smaller than its viewport.
Specified by:
getScrollableTracksViewportWidth in interface javax.swing.Scrollable
Returns:
false

setMaxUnitIncrement

public void setMaxUnitIncrement(int pixels)
Method used to set the maximum unit (in pixels) by which this object should scroll.
Parameters:
pixels - An integer representing the number of pixels to scroll by when scrolling is called necessary.

setMouseCoordinate

public void setMouseCoordinate(int x,
                               int y)

searchFind

public void searchFind()

searchFindDir

public void searchFindDir()

arrowDisplay

public boolean arrowDisplay()

setArrowDisplay

public void setArrowDisplay(boolean boolVal)

setArrowDisplay

public void setArrowDisplay(int entityType,
                            boolean boolVal)

setFillColors

public void setFillColors(boolean fill)

setNext

public void setNext()

setNext

public void setNext(DIDRoiIFC nextRoi)

deleteNext

public void deleteNext()