Package ptolemy.media

Class 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
      • Nested classes/interfaces inherited from class java.awt.Container

        java.awt.Container.AccessibleAWTContainer
      • Nested classes/interfaces inherited from class java.awt.Component

        java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
    • 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
      • Fields inherited from class java.awt.Component

        accessibleContext, 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

      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
      • 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.
        Overrides:
        getPreferredSize in class javax.swing.JComponent
        Returns:
        The size of the image.
      • getMinimumSize

        public java.awt.Dimension getMinimumSize()
        Return the minimum size.
        Overrides:
        getMinimumSize in class javax.swing.JComponent
        Returns:
        The size of the image.
      • getMaximumSize

        public java.awt.Dimension getMaximumSize()
        Return the maximum size.
        Overrides:
        getMaximumSize in class javax.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 class javax.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 class javax.swing.JComponent
        Parameters:
        graphics - The graphics context.