Class PictureEdit

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 PictureEdit
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class PictureEdit
extends JPanel

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, 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.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
PictureEdit()
          Constructor will use the JFileChooser to open a file
PictureEdit(File file)
          Constructor will use the JFileChooser to open a file
PictureEdit(String fileName)
          Constructor will use the JFileChooser to open a file
 
Method Summary
 void displayImage()
          Displays the current image in a new JFrame.
 void displayImage(String title)
          Displays the current image in a new JFrame.
 Color getColor(int x, int y)
          Returns a Color object of the color at a given point.
 int getHeight()
          Returns the height of the image file
 Image getImage()
          Returns the image file as an Image object.
 int getRGBColor(int x, int y)
          Returns the integer value of the color at a given point.
 int getWidth()
          Returns the width of the image file
 boolean open()
          Opens a file by opening a JFileChooser which allows the user to select the file they would like to open.
 boolean open(File file)
          Opens an image file given a File object.
 boolean open(String fileName)
          Opens an image file based on the file name in String format
 void revert()
          Reverts to the original file, all unsaved changes are lost.
 boolean saveAs()
          Saves a file by opening a JFileChooser which allows the user to select the file they would like to save over or create a new file to save onto.
 boolean saveAs(String fileName)
          Saves a file by writing a new file with the given fileName String.
 boolean setColor(int x, int y, Color color)
          Sets the color at a given x,y coordinate.
 boolean setColor(int x, int y, int color)
          Sets the color at a given x,y coordinate.
 
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, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, 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
 

Constructor Detail

PictureEdit

public PictureEdit()
Constructor will use the JFileChooser to open a file


PictureEdit

public PictureEdit(String fileName)
Constructor will use the JFileChooser to open a file

Parameters:
fileName - is the String file name including the directory path

PictureEdit

public PictureEdit(File file)
Constructor will use the JFileChooser to open a file

Parameters:
file - is the File object of the picture that will be opened.
Method Detail

open

public boolean open()
Opens a file by opening a JFileChooser which allows the user to select the file they would like to open.

Returns:
true if the file successfully opened, false otherwise.

open

public boolean open(String fileName)
Opens an image file based on the file name in String format

Parameters:
fileName - the name of the file including file path.
Returns:
true if the file is successfully opened, false otherwise.

open

public boolean open(File file)
Opens an image file given a File object.

Parameters:
file - the File object of the image file.
Returns:
true if the file is successfully opened, false otherwise.

revert

public void revert()
Reverts to the original file, all unsaved changes are lost.


saveAs

public boolean saveAs()
Saves a file by opening a JFileChooser which allows the user to select the file they would like to save over or create a new file to save onto.

Returns:
true if the file successfully opened, false otherwise.

saveAs

public boolean saveAs(String fileName)
Saves a file by writing a new file with the given fileName String. CAUTION: This will overwrite any file with the name provided. No confirmation dialog.

Parameters:
fileName - is a String with the file name and path directory.
Returns:
true if the file successfully opened, false otherwise.

getWidth

public int getWidth()
Returns the width of the image file

Overrides:
getWidth in class JComponent
Returns:
integer value of the width. Will return 0 if there is no file currently open.

getHeight

public int getHeight()
Returns the height of the image file

Overrides:
getHeight in class JComponent
Returns:
integer value of the height. Will return 0 if there is no file currently open.

getImage

public Image getImage()
Returns the image file as an Image object. This might be used to easily display the open image.

Returns:
Image object of the currently open image.

displayImage

public void displayImage()
Displays the current image in a new JFrame. The title of the JFrame will be the timestamp of when it was displayed. The timestamp allows the user to see multiple revisions and know which came first.


displayImage

public void displayImage(String title)
Displays the current image in a new JFrame. The title of the window is given as a paramater.

Parameters:
title - Title of the window.

getRGBColor

public int getRGBColor(int x,
                       int y)
Returns the integer value of the color at a given point. Will return a -1 if the coordinate is outside the width/height of the open image.

Parameters:
x - x-coordinate of the selected pixel
y - y-coordinate of the selected pixel
Returns:
integer value of the color at (x,y) coordinate.

getColor

public Color getColor(int x,
                      int y)
Returns a Color object of the color at a given point. Will return null if the coordinate is outside the width/height of the open image.

Parameters:
x - x-coordinate of the selected pixel
y - y-coordinate of the selected pixel
Returns:
Color object of the color at (x,y) coordinate.

setColor

public boolean setColor(int x,
                        int y,
                        int color)
Sets the color at a given x,y coordinate. The color is given in an integer RGB model. If the x,y is outside the image, the method returns false, true otherwise.

Parameters:
x - x-coordinate of the selected pixel
y - y-coordinate of the selected pixel
color - the color in integer RGB form
Returns:
Color object of the color at (x,y) coordinate.

setColor

public boolean setColor(int x,
                        int y,
                        Color color)
Sets the color at a given x,y coordinate. The color is given as a Color object. If the x,y is outside the image, the method returns false, true otherwise.

Parameters:
x - x-coordinate of the selected pixel
y - y-coordinate of the selected pixel
color - Color object of the color to change to
Returns:
Color object of the color at (x,y) coordinate.