net.grelf.grip
Class Histogram

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by net.grelf.grip.Histogram
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.awt.print.Printable, java.io.Serializable

public class Histogram
extends javax.swing.JComponent
implements java.awt.print.Printable

A histogram of an image with any number of bands.

See Also:
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.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 
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.print.Printable
NO_SUCH_PAGE, PAGE_EXISTS
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
Histogram(java.awt.image.BufferedImage bim)
          Creates the frequency arrays and fills them from the given image.
Histogram(java.awt.image.BufferedImage bim, PointList ps, DrawingMode mode)
          Creates the frequency arrays and fills them for all points in the given PointList over the given image area.
Histogram(java.awt.image.BufferedImage bim, PointList ps, DrawingMode mode, RangeInt range)
          In this version of the constructor (called by the others) a RangeInt determines the x-axis labels (only - need not be consistent with range of elevels in image).
 
Method Summary
protected  void draw(java.awt.Graphics2D g2, int xOffset, int yOffset)
          Draw a graph of the histogram in the given graphics context (screen or printer) at the given offset position.
 int[] getMaxValues()
          Get array of maximum values for each channel (red, green and blue in the 3-channel case).
 int[] getMinValues()
          Get array of minimum values for each channel (red, green and blue in the 3-channel case).
 int[] getModes()
          Get array of modal values for each channel (red, green and blue in the 3-channel case).
 int[] getModes(int start, int end)
          Get array of modal values, using only levels from start to end inclusive.
 Statistics[] getStatistics()
          Calculate all statistics, returning as an array index by channel (band).
 Statistics[] getStatistics(int start, int end)
          Calculate all statistics, returning as an array index by channel (band).
 void paintComponent(java.awt.Graphics g)
           
 int print(java.awt.Graphics g, java.awt.print.PageFormat pf, int pageNo)
          Print the histogram.
 void saveCSV()
          Save the histogram as a comma-separated-value file, suitable for loading into spreadsheets.
 void saveXML()
          Save the histogram as an XML file.
 javax.swing.JFrame showInJFrame(java.lang.String title)
          Display the histogram in a JFrame (persistent, unlike display in a message dialogue which is usually done in GRIP).
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, 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, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, 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, updateUI
 
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
 

Constructor Detail

Histogram

public Histogram(java.awt.image.BufferedImage bim)
Creates the frequency arrays and fills them from the given image.


Histogram

public Histogram(java.awt.image.BufferedImage bim,
                 PointList ps,
                 DrawingMode mode)
Creates the frequency arrays and fills them for all points in the given PointList over the given image area. Only these drawing modes are recognised: CLOSED_CURVE, RECTANGLE, WHOLE.


Histogram

public Histogram(java.awt.image.BufferedImage bim,
                 PointList ps,
                 DrawingMode mode,
                 RangeInt range)
In this version of the constructor (called by the others) a RangeInt determines the x-axis labels (only - need not be consistent with range of elevels in image).

Method Detail

getMaxValues

public int[] getMaxValues()
Get array of maximum values for each channel (red, green and blue in the 3-channel case).


getMinValues

public int[] getMinValues()
Get array of minimum values for each channel (red, green and blue in the 3-channel case).


getModes

public int[] getModes()
Get array of modal values for each channel (red, green and blue in the 3-channel case).


getModes

public int[] getModes(int start,
                      int end)
Get array of modal values, using only levels from start to end inclusive.


getStatistics

public Statistics[] getStatistics(int start,
                                  int end)
Calculate all statistics, returning as an array index by channel (band). Only consider grey levels from start to end in every channel.


getStatistics

public Statistics[] getStatistics()
Calculate all statistics, returning as an array index by channel (band).


draw

protected void draw(java.awt.Graphics2D g2,
                    int xOffset,
                    int yOffset)
Draw a graph of the histogram in the given graphics context (screen or printer) at the given offset position.


paintComponent

public void paintComponent(java.awt.Graphics g)
Overrides:
paintComponent in class javax.swing.JComponent

print

public int print(java.awt.Graphics g,
                 java.awt.print.PageFormat pf,
                 int pageNo)
          throws java.awt.print.PrinterException
Print the histogram.

Specified by:
print in interface java.awt.print.Printable
Throws:
java.awt.print.PrinterException

showInJFrame

public javax.swing.JFrame showInJFrame(java.lang.String title)
Display the histogram in a JFrame (persistent, unlike display in a message dialogue which is usually done in GRIP).

Returns:
reference to the JFrame, so the caller can dispose of it if required.

saveCSV

public void saveCSV()
Save the histogram as a comma-separated-value file, suitable for loading into spreadsheets.


saveXML

public void saveXML()
Save the histogram as an XML file.