CmpSpots
Class DrawHistogram

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 CmpSpots.DrawHistogram
All Implemented Interfaces:
java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible

 class DrawHistogram
extends javax.swing.JPanel
implements java.awt.event.MouseListener, java.awt.event.MouseMotionListener

File: DrawHistogram class is used to draw an image intensity histogram


Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 int activeBin
          active bin idx of SCALED sHist[0:nHist-1] else -1
private  java.awt.Color activeBinColor
          Active bin peak on histogram color
 float activeBinValue
          active bin data value corresponding to activeBinidx of SCALED sHist[0:nHist-1].
 float binScale
          sHist[] Bin width sampling or averaging distance computed as floating (nHist/nShist) to map hist[] to a sHist[] bin.
private  int cHeight
          working canvas height
private static CmpSpots cs
          link to global instance
private static CmpShowImage csi
           
private  int cWidth
          working canvas width
private  java.lang.String dataName
          name of the data used in histogram
private  java.lang.String dataUnits
          data units abbreviation
(package private)  java.awt.Dimension frameSize
          size of frame
private  java.awt.Color histColor
           
private  java.awt.Color histTopColor
           
private  java.awt.Color labelColor
           
private  java.awt.Font largeFont
          medium font used for labeling
 float maxDataValue
          The maximum data value at hist[max index]
 int maxHistFreqValue
          The maximum frequency in hist[]
 int maxShistFreq
          max sHist Frequency in sHist value to be displayed
 int maxShistIdx
          max non-zero bin of sHist to be displayed
 int meanDataGrayValue
          mean non-zero data gray value of sHist to display for Image density
 float meanDataValue
          mean non-zero data value of sHist to be displayed
 int meanShistIdx
          mean non-zero bin of sHist to be displayed
private  java.awt.Color meanValueBinColor
          Mean value bin peak on histogram color
 int medianDataGrayValue
          median non-zero data gray value of sHist to display for Image density
 float medianDataValue
          median non-zero data value of sHist to be displayed
 int medianShistIdx
          median non-zero bin of sHist to be displayed
private  java.awt.Color medianValueBinColor
          Median value bin peak on histogram color
private  java.awt.Font mediumFont
          medium font used for labeling
 float minDataValue
          The minimum data value at hist[0]
 int minHistFreqValue
          The minimum frequency value in hist[]
 int minShistFreq
          min sHist Frequency in sHist value to be displayed
 int minShistIdx
          min non-zero bin of sHist to be displayed
 int modeDataGrayValue
          mode non-zero data gray value of sHist to display for Image density
 float modeDataValue
          mode non-zero data value of sHist to be displayed
 int modeShistIdx
          mode non-zero bin of sHist to be displayed
private  java.awt.Color modeValueBinColor
          Mode value bin peak on histogram color
private  int nShist
          size of input unscaled histogram[] data
private  java.awt.Color optBkgrdColor
           
 int preferredHeight
          preferred size of canvas
 int preferredWidth
          preferred size of canvas
 float scaleFreq
          sHist[] frequency scale factor computed as floating (maxHistFreq/nShist)
(package private) static long serialVersionUID
          frame id
private  int[] sHist
          local SCALED histogram [0:nShist-1]data
private  int[] sHistDisp
          local SCALED histogram [0:nShist-1] scaled to max data value of nShist
private static Util util
          link to global instance
 int xLRHC
          lower Y right hand corner of hist.
private  int[] xPainted
          local SCALED histogram X position
 int xULHC
          upper X left hand corner of hist.
 int yLRHC
          lower Y right hand corner of hist.
 int yULHC
          upper Y left hand corner of hist.
 
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
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
DrawHistogram(CmpShowImage csi, java.awt.Dimension frameSize)
          DrawHistogram() - create a blank histogram canvas
 
Method Summary
private static void drawFilledBox(java.awt.Graphics g, int xC, int yC, int width, java.awt.Color color)
          drawFilledBox() - draw plus sign at the specified color.
private static void drawFilledRectangle(java.awt.Graphics g, int x1, int x2, int y1, int y2, java.awt.Color color)
          drawFilledRectangle() - draw plus sign at the specified color.
 java.awt.Dimension getPreferredSize()
          getPreferredSize() - getPreferredSize, must be implemented for ScrollPane to be displayed correctly.
 void mouseClicked(java.awt.event.MouseEvent e)
           
 void mouseDragged(java.awt.event.MouseEvent e)
          mouseDragged() - process mouse event
 void mouseEntered(java.awt.event.MouseEvent e)
           
 void mouseExited(java.awt.event.MouseEvent e)
           
 boolean mouseHandler(int x, int y)
          mouseHandler() - search for the active bin if any
 void mouseMoved(java.awt.event.MouseEvent e)
           
 void mousePressed(java.awt.event.MouseEvent e)
           
 void mouseReleased(java.awt.event.MouseEvent e)
          mouseReleased() - process mouse event
 void paintComponent(java.awt.Graphics g)
          paintComponent() - draw histogram of hist[].
 boolean setHistData(java.lang.String title, java.lang.String dataName, java.lang.String dataUnits, java.lang.String horizCaption, java.lang.String vertCaption, int[] hist, float minDataValue, float maxDataValue)
          setHistData() - set the hist data, title, Horiz and Vert captions and then repaint to start drawing it.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, 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, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, 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, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, 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, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, 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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

static final long serialVersionUID
frame id

See Also:
Constant Field Values

csi

private static CmpShowImage csi

cs

private static CmpSpots cs
link to global instance


util

private static Util util
link to global instance


preferredWidth

public int preferredWidth
preferred size of canvas


preferredHeight

public int preferredHeight
preferred size of canvas


mediumFont

private java.awt.Font mediumFont
medium font used for labeling


largeFont

private java.awt.Font largeFont
medium font used for labeling


optBkgrdColor

private java.awt.Color optBkgrdColor

histColor

private java.awt.Color histColor

histTopColor

private java.awt.Color histTopColor

activeBinColor

private java.awt.Color activeBinColor
Active bin peak on histogram color


meanValueBinColor

private java.awt.Color meanValueBinColor
Mean value bin peak on histogram color


modeValueBinColor

private java.awt.Color modeValueBinColor
Mode value bin peak on histogram color


medianValueBinColor

private java.awt.Color medianValueBinColor
Median value bin peak on histogram color


labelColor

private java.awt.Color labelColor

frameSize

java.awt.Dimension frameSize
size of frame


cWidth

private int cWidth
working canvas width


cHeight

private int cHeight
working canvas height


dataName

private java.lang.String dataName
name of the data used in histogram


dataUnits

private java.lang.String dataUnits
data units abbreviation


sHist

private int[] sHist
local SCALED histogram [0:nShist-1]data


nShist

private int nShist
size of input unscaled histogram[] data


sHistDisp

private int[] sHistDisp
local SCALED histogram [0:nShist-1] scaled to max data value of nShist


xPainted

private int[] xPainted
local SCALED histogram X position


activeBin

public int activeBin
active bin idx of SCALED sHist[0:nHist-1] else -1


activeBinValue

public float activeBinValue
active bin data value corresponding to activeBinidx of SCALED sHist[0:nHist-1]. Only valid if activeBin is NEQ -1


xULHC

public int xULHC
upper X left hand corner of hist. graph


yULHC

public int yULHC
upper Y left hand corner of hist. graph


xLRHC

public int xLRHC
lower Y right hand corner of hist. graph


yLRHC

public int yLRHC
lower Y right hand corner of hist. graph


minShistIdx

public int minShistIdx
min non-zero bin of sHist to be displayed


maxShistIdx

public int maxShistIdx
max non-zero bin of sHist to be displayed


meanShistIdx

public int meanShistIdx
mean non-zero bin of sHist to be displayed


medianShistIdx

public int medianShistIdx
median non-zero bin of sHist to be displayed


modeShistIdx

public int modeShistIdx
mode non-zero bin of sHist to be displayed


minShistFreq

public int minShistFreq
min sHist Frequency in sHist value to be displayed


maxShistFreq

public int maxShistFreq
max sHist Frequency in sHist value to be displayed


minHistFreqValue

public int minHistFreqValue
The minimum frequency value in hist[]


maxHistFreqValue

public int maxHistFreqValue
The maximum frequency in hist[]


meanDataValue

public float meanDataValue
mean non-zero data value of sHist to be displayed


medianDataValue

public float medianDataValue
median non-zero data value of sHist to be displayed


modeDataValue

public float modeDataValue
mode non-zero data value of sHist to be displayed


meanDataGrayValue

public int meanDataGrayValue
mean non-zero data gray value of sHist to display for Image density


medianDataGrayValue

public int medianDataGrayValue
median non-zero data gray value of sHist to display for Image density


modeDataGrayValue

public int modeDataGrayValue
mode non-zero data gray value of sHist to display for Image density


minDataValue

public float minDataValue
The minimum data value at hist[0]


maxDataValue

public float maxDataValue
The maximum data value at hist[max index]


binScale

public float binScale
sHist[] Bin width sampling or averaging distance computed as floating (nHist/nShist) to map hist[] to a sHist[] bin.


scaleFreq

public float scaleFreq
sHist[] frequency scale factor computed as floating (maxHistFreq/nShist)

Constructor Detail

DrawHistogram

public DrawHistogram(CmpShowImage csi,
                     java.awt.Dimension frameSize)
DrawHistogram() - create a blank histogram canvas

Parameters:
csi - is CmpShowImage
frameSize - is size of canvas
Method Detail

getPreferredSize

public java.awt.Dimension getPreferredSize()
getPreferredSize() - getPreferredSize, must be implemented for ScrollPane to be displayed correctly.

Overrides:
getPreferredSize in class javax.swing.JComponent

setHistData

public boolean setHistData(java.lang.String title,
                           java.lang.String dataName,
                           java.lang.String dataUnits,
                           java.lang.String horizCaption,
                           java.lang.String vertCaption,
                           int[] hist,
                           float minDataValue,
                           float maxDataValue)
setHistData() - set the hist data, title, Horiz and Vert captions and then repaint to start drawing it. Rescale the hist[] to sHist[0:255].

Parameters:
title - title of histogram
dataName - of the type of data used
dataUnits - of the type of data used
horizCaption - horizontal caption
vertCaption - vertical caption
hist - is the histogram array of any size
minDataValue - is the value the data at hist[0]
maxDataValue - is the value the data at hist[max index]
Returns:
true if succeed, false if there is a problem. i.e. no data

drawFilledBox

private static final void drawFilledBox(java.awt.Graphics g,
                                        int xC,
                                        int yC,
                                        int width,
                                        java.awt.Color color)
drawFilledBox() - draw plus sign at the specified color.

Parameters:
g - is graphics context
x - is center of object
y - is center of object
width - is width of object
color - is color to draw

drawFilledRectangle

private static final void drawFilledRectangle(java.awt.Graphics g,
                                              int x1,
                                              int x2,
                                              int y1,
                                              int y2,
                                              java.awt.Color color)
drawFilledRectangle() - draw plus sign at the specified color.

Parameters:
g - is graphics context
x1 - is Left edge
x1 - is Left edge
y1 - is top edge
color - is color to draw

paintComponent

public void paintComponent(java.awt.Graphics g)
paintComponent() - draw histogram of hist[]. NOTE: size is (csi.HIST_WIDTH x csi.HIST_HEIGHT)

Overrides:
paintComponent in class javax.swing.JComponent
Parameters:
g - is graphics context

mouseHandler

public boolean mouseHandler(int x,
                            int y)
mouseHandler() - search for the active bin if any

Parameters:
x - mouse position
y - mouse position
Returns:
true if found it in the xPainted[] list and set activeBin to the index i in [0:255] else set activeBin to -1.

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
mouseDragged() - process mouse event

Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener
Parameters:
e - is mouse pressed event

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
mouseReleased() - process mouse event

Specified by:
mouseReleased in interface java.awt.event.MouseListener
Parameters:
e - is mouse pressed event

mousePressed

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

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Specified by:
mouseClicked 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

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)
Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener