ProgramixGenericLib v5.0.1

com.programix.gui.image
Class Picture

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by com.programix.gui.image.Picture
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable

public class Picture
extends JComponent
implements Serializable

A Swing component that can be used to simple show an image (picture) on a component. Instances are Serializable as only the bytes needed to re-created the image are transmitted. The internal BufferedImage is declared to be (transient) and is left behind. If the image was originally created from a a byte[], these bytes are retained for transmission. If an image was used to create the Picture, then a byte[] is created only on-demand (in the lossless, compressed PNG format).

If you don't need a JComponent but just need a BufferedImage, then you can use ImageTools.

Author:
Paul Hyde
See Also:
Serialized Form

Nested Class Summary
 
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.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
Picture()
          Creates a Picture with no initial image.
Picture(BufferedImage bufferedImage)
          The BufferedImage to be drawn on this JComponent.
Picture(byte[] imageBytes)
          Creates a Picture by storing the specified bytes until there is a demand for the BufferedImage.
Picture(File source)
          Reads all the bytes from source and passes them to the constructor that takes a byte[].
Picture(Image image)
          Creates a BufferedImage from the Image specified and calls the constructor that takes a BufferedImage parameter.
Picture(InputStream source)
          Reads all the bytes from source and passes them to the constructor that takes a byte[].
Picture(String resourceName)
          Reads all the bytes from the resource specified by resourceName and passes them to the constructor that takes a byte[].
Picture(URL source)
          Reads all the bytes from source and passes them to the constructor that takes a byte[].
 
Method Summary
 void clearImage()
          Clears out any current image (blanks out the picture).
 BufferedImage getImage()
           
 byte[] getImageBytes()
           
 int getImageHeight()
           
 int getImageWidth()
           
 Dimension getPreferredSize()
           
protected  void paintComponent(Graphics g)
           
 void setImage(BufferedImage bufferedImage)
           
 void setImage(Image image)
          Creates a BufferedImage from the Image specified and calls the setImage method that takes a BufferedImage parameter.
 void setImageBytes(byte[] imageBytes)
           
 
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, 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, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, 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

Picture

public Picture(BufferedImage bufferedImage)
The BufferedImage to be drawn on this JComponent. The byte[] representation of the image is not created during construction@mdash;only on demand.

Parameters:
bufferedImage - the image to draw on this component.

Picture

public Picture(Image image)
Creates a BufferedImage from the Image specified and calls the constructor that takes a BufferedImage parameter. If the Image reference passed in is actually pointing to a BufferedImage, then this constructor is very efficient and simply does an explicit cast and calls the other constructor.

Parameters:
image - the Image to convert to a BufferedImage.

Picture

public Picture(byte[] imageBytes)
Creates a Picture by storing the specified bytes until there is a demand for the BufferedImage. Typically, the BufferedImage is created the first time that JComponent.paint(Graphics) is called. For help is getting a byte[] to use to create a

Parameters:
imageBytes - the formatted bytes that can be decoded into an image.

Picture

public Picture(InputStream source)
        throws IOException
Reads all the bytes from source and passes them to the constructor that takes a byte[].

Throws:
IOException

Picture

public Picture(File source)
        throws IOException
Reads all the bytes from source and passes them to the constructor that takes a byte[].

Throws:
IOException

Picture

public Picture(URL source)
        throws IOException
Reads all the bytes from source and passes them to the constructor that takes a byte[].

Throws:
IOException

Picture

public Picture(String resourceName)
        throws IOException
Reads all the bytes from the resource specified by resourceName and passes them to the constructor that takes a byte[].

Throws:
IOException

Picture

public Picture()
Creates a Picture with no initial image.

Method Detail

clearImage

public void clearImage()
Clears out any current image (blanks out the picture).


getImage

public BufferedImage getImage()

setImage

public void setImage(BufferedImage bufferedImage)

setImage

public void setImage(Image image)
Creates a BufferedImage from the Image specified and calls the setImage method that takes a BufferedImage parameter. If the Image reference passed in is actually pointing to a BufferedImage, then this method is very efficient and simply does an explicit cast and calls the other method.

Parameters:
image - the Image to convert to a BufferedImage.

getImageBytes

public byte[] getImageBytes()
                     throws ImageTools.ImageException
Throws:
ImageTools.ImageException

setImageBytes

public void setImageBytes(byte[] imageBytes)

getImageWidth

public int getImageWidth()

getImageHeight

public int getImageHeight()

getPreferredSize

public Dimension getPreferredSize()
Overrides:
getPreferredSize in class JComponent

paintComponent

protected void paintComponent(Graphics g)
Overrides:
paintComponent in class JComponent

ProgramixGenericLib v5.0.1

Copyright © 2001-2009 Programix Incorporated. All rights reserved. ProgramixGenericLib is free and is OSI Certified Open Source Software under the BSD license.