ptolemy.media
Class Picture

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Canvas
          extended byptolemy.media.Picture
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public class Picture
extends java.awt.Canvas

A component that displays an image. The image can be updated in real time to create videos. It can be monochrome or color. To use it, simply create it, populate it with pixels using one or more of the set methods, and call displayImage().

Since:
Ptolemy II 0.2
Version:
$Id: Picture.java,v 1.24 2004/04/13 03:46:06 cxh Exp $
Author:
Edward A. Lee
See Also:
Serialized Form
Accepted Rating:
Red (cxh)
Proposed Rating:
Red (eal)

Nested Class Summary
 
Nested classes inherited from class java.awt.Canvas
java.awt.Canvas.AccessibleAWTCanvas
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 
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(int width, int height)
          Create an image with the specified width and height, in pixels.
 
Method Summary
 void displayImage()
          Notify this picture that its image has been changed and that it is now OK to display the new image.
 java.awt.Dimension getMaximumSize()
          Return the maximum size.
 java.awt.Dimension getMinimumSize()
          Return the minimum size.
 java.awt.Dimension getPreferredSize()
          Return the preferred size.
 void paint(java.awt.Graphics graphics)
          Paint this component.
 void setImage(java.awt.Image image)
          Specify the java.awt.Image representation of the image.
 void setImage(int[] pixels)
          Specify the packed ARGB representation of the image.
 void setPixel(int row, int col, int intensity)
          Set the specified pixel to the given monochrome value, which should be in the range from zero (black) to 255 (white).
 void setPixel(int row, int col, int red, int green, int blue)
          Set the specified pixel to the given color value, where each color argument should be in the range from zero (absent) to 255 (fully saturated).
 void update(java.awt.Graphics graphics)
          Override the base class to prevent blanking, which causes flashing of the display.
 
Methods inherited from class java.awt.Canvas
addNotify, createBufferStrategy, createBufferStrategy, getAccessibleContext, getBufferStrategy
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Picture

public Picture(int width,
               int height)
Create an image with the specified width and height, in pixels.

Parameters:
width - The width in pixels.
height - The height in pixels.
Method Detail

getPreferredSize

public java.awt.Dimension getPreferredSize()
Return the preferred size.

Returns:
The size of the image.

getMinimumSize

public java.awt.Dimension getMinimumSize()
Return the minimum size.

Returns:
The size of the image.

getMaximumSize

public java.awt.Dimension getMaximumSize()
Return the maximum size.

Returns:
The size of the image.

displayImage

public void displayImage()
Notify this picture that its image has been changed and that it is now OK to display the new image.


paint

public void paint(java.awt.Graphics graphics)
Paint this component. If no pixels have been set, do nothing.

Parameters:
graphics - The graphics context.

setImage

public void setImage(java.awt.Image image)
              throws java.lang.IllegalArgumentException
Specify the java.awt.Image representation of the image.

Parameters:
image - A java.awt.Image object
Throws:
java.lang.IllegalArgumentException - If the image size does not

setImage

public void setImage(int[] pixels)
              throws java.lang.IllegalArgumentException
Specify the packed ARGB representation of the image. Each pixel is a 32-bit integer where the top 8 bits give alpha (the transparency), then next 8 bits give the red value, the next 8 bits the green value, and the bottom 8 bits give the blue value. The pixels are assembled into a single one-dimensional array that contains the first row followed by the second row, etc. So the size of the array is the product of the width and the height of the image. An element in the array might be set using a statement like:
    pix[row*col] = (alpha << 24) | (red << 16) | (green << 8) | blue;
  

Parameters:
pixels - The packed ARGB representation of the image.
Throws:
java.lang.IllegalArgumentException - If the image size does not match.

setPixel

public void setPixel(int row,
                     int col,
                     int intensity)
Set the specified pixel to the given monochrome value, which should be in the range from zero (black) to 255 (white). If the argument is outside this range, then either white or black will be displayed, depending on the sign of the argument. If the row and column are out of bounds, then the command is ignored.

Parameters:
row - The index of the row for the pixel.
col - The index of the column for the pixel.
intensity - The value of the pixel.

setPixel

public void setPixel(int row,
                     int col,
                     int red,
                     int green,
                     int blue)
Set the specified pixel to the given color value, where each color argument should be in the range from zero (absent) to 255 (fully saturated). If an argument is outside this range, then the nearest extreme of the range will be displayed. If the row and column are out of bounds, then the command is ignored.

Parameters:
row - The index of the row for the pixel.
col - The index of the column for the pixel.
red - The red value of the pixel.
green - The green value of the pixel.
blue - The blue value of the pixel.

update

public void update(java.awt.Graphics graphics)
Override the base class to prevent blanking, which causes flashing of the display.

Parameters:
graphics - The graphics context.