Class ImagePanel

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JPanel
                          |
                          +--ImagePanel
All Implemented Interfaces:
Accessible, ImageObserver, MenuContainer, Serializable

public class ImagePanel
extends JPanel

A JPanel that displays, loads, saves and modifies images. The refreshImage method displays an image based on the contents of an image file. The saveImage method saves the displayed image to file. The rotate method rotates the displayed image. The removeHorizontalLines method removes horizontal lines in the displayed image based on user set thresholds concerning colour and vertical run length. The showSelectedPixels method highlights certain pixels that meet certain user set thresholds concerning colour and vertical run length, and is useful for debugging. The paintComponent method is needed in order to display images and changes to them.

See Also:
Serialized Form
Author:
Cory McKay

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.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
ImagePanel(String file_path, MainFrame parent_window)
          Basic constructor.
 
Method Summary
 void paintComponent(Graphics g)
          Allow the image and changes to the image to be displayed.
 void refreshImage(String file_path)
          Loads the image file with the specified path, stores it in this object's image field and displays it.
 void removeHorizontalLines(HorizontalLineRemovalSettingsDialogBox horizontal_line_removal_dialog_box)
          Removes horizontal lines from the image held in this object's field.
 void rotate(RotateDialogBox rotate_dialog_box)
          Rotates the image that is currently held in this object's field by the amount specified by the getRotationAmount method of the rotate_dialog_box paramater.
 void saveImage(File file_to_save_to)
          Saves the image that is currently held in this object's field to the specified file.
 void showSelectedPixels(HorizontalLineRemovalSettingsDialogBox horizontal_line_removal_dialog_box)
          Highlights pixels in the image held in this object's field that pass the succesive filter requirements of the filters selected and there related thresholds in the given horizontal_line_removal_dialog_box parameter.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, 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, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, 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, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, 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, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, 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

ImagePanel

public ImagePanel(String file_path,
                  MainFrame parent_window)
Basic constructor. Loads the image file with the given path into this object's image field and displays it.

Parameters:
file_path - The path of the file to be loaded.
parent_window - The window that instantiated this panel.
Method Detail

refreshImage

public void refreshImage(String file_path)
Loads the image file with the specified path, stores it in this object's image field and displays it. Automatically displays an error message and opens a file called example.jpg if no valid image file exists that matches the specified file path. Displays an error message and quits the program if this file cannot be loaded.

The width and height of the image are stored in this classes fields.

Parameters:
file_path - The path of the file to be loaded.

saveImage

public void saveImage(File file_to_save_to)
               throws Exception
Saves the image that is currently held in this object's field to the specified file. It is assumed that the calling method has ensured that this file can be written to. The image is saved in jpeg format.

Parameters:
file_to_save_to - The file to save the image to.
Throws:
Exception - Throws an exception if there is a problem saving the file.

rotate

public void rotate(RotateDialogBox rotate_dialog_box)
Rotates the image that is currently held in this object's field by the amount specified by the getRotationAmount method of the rotate_dialog_box paramater.

Parameters:
rotate_dialog_box - Contains the angle by which to rotate the image.

removeHorizontalLines

public void removeHorizontalLines(HorizontalLineRemovalSettingsDialogBox horizontal_line_removal_dialog_box)
Removes horizontal lines from the image held in this object's field. The pixels that are removed must fall within certain colour and/or run length thresholds. These thresholds are specified in the horizontal_line_removal_dialog_box parameter.

Pixels that are selected through the above method as belonging to a horizontal line are altered by applying a blur filter that averages their new colour to that of the immediately surrounding pixels that are not selected.

Displays an error message if a problem occurs.

Parameters:
horizontal_line_removal_dialog_box - Specifies parameters needed to determine which pixels belong to horizontal lines.

showSelectedPixels

public void showSelectedPixels(HorizontalLineRemovalSettingsDialogBox horizontal_line_removal_dialog_box)
Highlights pixels in the image held in this object's field that pass the succesive filter requirements of the filters selected and there related thresholds in the given horizontal_line_removal_dialog_box parameter.

Only the results of the last n filter layers, as set by the Max Layers To Display text area of the horizontal_line_removal_dialog_box are displayed. The pixels surviving the last stage of filtering are set to bright green, those surviving the second to last stage are set to bright orange, those surviving the third to last stage are set to blue, those survivng the fouth to last stage are set to magenta, and those survivng the first stage are set to cyan.

Displays an error message if a problem occurs.

Parameters:
horizontal_line_removal_dialog_box - Specifies parameters needed to determine which pixels belong to horizontal lines.

paintComponent

public void paintComponent(Graphics g)
Allow the image and changes to the image to be displayed. Not used directly by this software.

Overrides:
paintComponent in class JComponent