Package ptolemy.media
Class Picture
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.JPanel
-
- ptolemy.media.Picture
-
- All Implemented Interfaces:
java.awt.image.ImageObserver
,java.awt.MenuContainer
,java.io.Serializable
,javax.accessibility.Accessible
public class Picture extends javax.swing.JPanel
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$
- Author:
- Edward A. Lee
- See Also:
- Serialized Form
- Pt.AcceptedRating:
- Red (cxh)
- Pt.ProposedRating:
- Red (eal)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
-
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
-
-
Field Summary
-
Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
-
-
Constructor Summary
Constructors Constructor Description Picture(int width, int height)
Create an image with the specified width and height, in pixels.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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(int[] pixels)
Specify the packed ARGB representation of the image.void
setImage(java.awt.Image image)
Specify the java.awt.Image 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 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, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, 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
-
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, 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, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, 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, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
-
-
-
Method Detail
-
getPreferredSize
public java.awt.Dimension getPreferredSize()
Return the preferred size.- Overrides:
getPreferredSize
in classjavax.swing.JComponent
- Returns:
- The size of the image.
-
getMinimumSize
public java.awt.Dimension getMinimumSize()
Return the minimum size.- Overrides:
getMinimumSize
in classjavax.swing.JComponent
- Returns:
- The size of the image.
-
getMaximumSize
public java.awt.Dimension getMaximumSize()
Return the maximum size.- Overrides:
getMaximumSize
in classjavax.swing.JComponent
- 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.- Overrides:
paint
in classjavax.swing.JComponent
- 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.- Overrides:
update
in classjavax.swing.JComponent
- Parameters:
graphics
- The graphics context.
-
-