org.opensourcephysics.media.core
Class ImageVideo

java.lang.Object
  extended by org.opensourcephysics.media.core.VideoAdapter
      extended by org.opensourcephysics.media.core.ImageVideo
All Implemented Interfaces:
java.beans.PropertyChangeListener, java.util.EventListener, Drawable, Interactive, Measurable, DrawableImage, InteractiveImage, Playable, Trackable, Video

public class ImageVideo
extends VideoAdapter

This is a Video assembled from one or more still images.

Version:
1.0
Author:
Douglas Brown

Field Summary
protected  double deltaT
           
protected  java.awt.image.BufferedImage[] images
           
protected  java.awt.Component observer
           
protected  java.lang.String[] paths
           
protected  boolean readOnly
           
 
Fields inherited from class org.opensourcephysics.media.core.VideoAdapter
aspects, bufferedImage, clearRaster, coords, endFrameNumber, filteredImage, filterStack, frameCount, frameNumber, isMeasured, isValidFilteredImage, isValidImage, isValidMeasure, looping, maxX, maxY, minX, minY, mouseEnabled, playing, properties, rate, rawImage, size, startFrameNumber, support, visible, widthDominates
 
Constructor Summary
ImageVideo(java.awt.Image image)
          Creates an ImageVideo from an image.
ImageVideo(java.awt.Image[] images)
          Creates an ImageVideo from an image array.
ImageVideo(java.lang.String imageName)
          Creates an ImageVideo and loads a named image or image sequence.
ImageVideo(java.lang.String imageName, boolean sequence)
          Creates an ImageVideo and loads a named image or image sequence.
ImageVideo(java.lang.String imageName, boolean sequence, boolean fileBased)
          Creates an ImageVideo and loads a named image or image sequence.
 
Method Summary
 void append(java.lang.String imageName)
          Appends the named image or image sequence to the end of this video.
 void append(java.lang.String imageName, boolean sequence)
          Appends the named image or image sequence to the end of this video.
protected  void finalize()
          Called by the garbage collector when this video is no longer in use.
 double getDuration()
          Gets the duration of the video.
 double getEndTime()
          Gets the end time in milliseconds.
 double getFrameTime(int n)
          Gets the start time of the specified frame in milliseconds.
 java.awt.Image[] getImages()
          Gets the image array.
static XML.ObjectLoader getLoader()
          Returns an XML.ObjectLoader to save and load ImageVideo data.
 java.awt.Dimension getSize()
          Gets the size of this video.
 double getStartTime()
          Gets the start time in milliseconds.
 double getTime()
          Gets the current video time in milliseconds.
protected  java.lang.String[] getValidPaths()
          Returns the valid paths (i.e., those that are not "").
protected  java.lang.String[] getValidPathsRelativeTo(java.lang.String base)
          Returns the valid paths (i.e., those that are not "") relative to a bae path.
protected  void insert(java.awt.Image[] newImages, int index, java.lang.String[] imagePaths)
          Inserts images starting at the specified index.
 void insert(java.awt.Image image, int index)
          Inserts an image at the specified index.
 void insert(java.lang.String imageName, int index)
          Inserts the named image or image sequence at the specified index.
 void insert(java.lang.String imageName, int index, boolean sequence)
          Inserts the named image or image sequence at the specified index.
 boolean isEditable()
          Returns true if all images are loaded into memory.
 boolean isFileBased()
          Returns true if all of the images are associated with files.
 java.lang.String remove(int index)
          Removes the image at the specified index.
 boolean saveInvalidImages()
          Allows user to save invalid images, if any.
 void setEditable(boolean edit)
          Sets the editable property.
 void setEndTime(double millis)
          Sets the end time in milliseconds.
 void setFrameDuration(double millis)
          Sets the frame duration in milliseconds.
 void setFrameNumber(int n)
          Overrides VideoAdapter setFrameNumber method.
 void setStartTime(double millis)
          Sets the start time in milliseconds.
 void setTime(double millis)
          Sets the video time in milliseconds.
 
Methods inherited from class org.opensourcephysics.media.core.VideoAdapter
addPropertyChangeListener, addPropertyChangeListener, back, dispose, draw, findInteractive, findMinMaxValues, firePropertyChange, getAngle, getCoords, getEndFrameNumber, getFilterStack, getFrameCount, getFrameDuration, getFrameNumber, getHeight, getImage, getProperty, getPropertyNames, getRate, getRelativeAspect, getStartFrameNumber, getWidth, getX, getXMax, getXMin, getY, getYMax, getYMin, goToEnd, goToStart, initialize, isEnabled, isLooping, isMeasured, isPlaying, isVisible, play, propertyChange, refreshBufferedImage, removePropertyChangeListener, removePropertyChangeListener, reset, setAngle, setCoords, setEnabled, setEndFrameNumber, setFilterStack, setFrameAngle, setFrameHeight, setFrameRelativeAspect, setFrameWidth, setFrameX, setFrameXY, setFrameY, setHeight, setLooping, setPlaying, setProperty, setRate, setRelativeAspect, setStartFrameNumber, setVisible, setWidth, setX, setXY, setY, step, stop
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

observer

protected java.awt.Component observer

images

protected java.awt.image.BufferedImage[] images

paths

protected java.lang.String[] paths

readOnly

protected boolean readOnly

deltaT

protected double deltaT
Constructor Detail

ImageVideo

public ImageVideo(java.lang.String imageName)
           throws java.io.IOException
Creates an ImageVideo and loads a named image or image sequence.

Parameters:
imageName - the name of the image file
Throws:
java.io.IOException

ImageVideo

public ImageVideo(java.lang.String imageName,
                  boolean sequence)
           throws java.io.IOException
Creates an ImageVideo and loads a named image or image sequence.

Parameters:
imageName - the name of the image file
sequence - true to automatically load image sequence, if any
Throws:
java.io.IOException

ImageVideo

public ImageVideo(java.lang.String imageName,
                  boolean sequence,
                  boolean fileBased)
           throws java.io.IOException
Creates an ImageVideo and loads a named image or image sequence.

Parameters:
imageName - the name of the image file
sequence - true to automatically load image sequence, if any
fileBased - true if images will be loaded from files only as needed
Throws:
java.io.IOException

ImageVideo

public ImageVideo(java.awt.Image image)
Creates an ImageVideo from an image.

Parameters:
image - the image

ImageVideo

public ImageVideo(java.awt.Image[] images)
Creates an ImageVideo from an image array.

Parameters:
images - the image array
Method Detail

setFrameNumber

public void setFrameNumber(int n)
Overrides VideoAdapter setFrameNumber method.

Specified by:
setFrameNumber in interface Video
Overrides:
setFrameNumber in class VideoAdapter
Parameters:
n - the desired frame number
See Also:
Video.getStartFrameNumber(), Video.getEndFrameNumber()

getTime

public double getTime()
Gets the current video time in milliseconds.

Specified by:
getTime in interface Playable
Overrides:
getTime in class VideoAdapter
Returns:
the current time in milliseconds, or -1 if not known

setFrameDuration

public void setFrameDuration(double millis)
Sets the frame duration in milliseconds.

Parameters:
millis - the desired frame duration in milliseconds

setTime

public void setTime(double millis)
Sets the video time in milliseconds.

Specified by:
setTime in interface Playable
Overrides:
setTime in class VideoAdapter
Parameters:
millis - the desired time in milliseconds

getStartTime

public double getStartTime()
Gets the start time in milliseconds.

Specified by:
getStartTime in interface Playable
Overrides:
getStartTime in class VideoAdapter
Returns:
the start time in milliseconds, or -1 if not known

setStartTime

public void setStartTime(double millis)
Sets the start time in milliseconds. NOTE: the actual start time is normally set to the beginning of a frame.

Specified by:
setStartTime in interface Playable
Overrides:
setStartTime in class VideoAdapter
Parameters:
millis - the desired start time in milliseconds

getEndTime

public double getEndTime()
Gets the end time in milliseconds.

Specified by:
getEndTime in interface Playable
Overrides:
getEndTime in class VideoAdapter
Returns:
the end time in milliseconds, or -1 if not known

setEndTime

public void setEndTime(double millis)
Sets the end time in milliseconds. NOTE: the actual end time is set to the end of a frame.

Specified by:
setEndTime in interface Playable
Overrides:
setEndTime in class VideoAdapter
Parameters:
millis - the desired end time in milliseconds

getDuration

public double getDuration()
Gets the duration of the video.

Specified by:
getDuration in interface Playable
Overrides:
getDuration in class VideoAdapter
Returns:
the duration of the video in milliseconds, or -1 if not known

getFrameTime

public double getFrameTime(int n)
Gets the start time of the specified frame in milliseconds.

Specified by:
getFrameTime in interface Video
Overrides:
getFrameTime in class VideoAdapter
Parameters:
n - the frame number
Returns:
the start time of the frame in milliseconds, or -1 if not known

getImages

public java.awt.Image[] getImages()
Gets the image array.

Returns:
the image array

append

public void append(java.lang.String imageName)
            throws java.io.IOException
Appends the named image or image sequence to the end of this video. This method will ask user whether to load sequences, if any.

Parameters:
imageName - the image name
Throws:
java.io.IOException

append

public void append(java.lang.String imageName,
                   boolean sequence)
            throws java.io.IOException
Appends the named image or image sequence to the end of this video.

Parameters:
imageName - the image name
sequence - true to automatically load image sequence, if any
Throws:
java.io.IOException

insert

public void insert(java.lang.String imageName,
                   int index)
            throws java.io.IOException
Inserts the named image or image sequence at the specified index. This method will ask user whether to load sequences, if any.

Parameters:
imageName - the image name
index - the index
Throws:
java.io.IOException

insert

public void insert(java.lang.String imageName,
                   int index,
                   boolean sequence)
            throws java.io.IOException
Inserts the named image or image sequence at the specified index.

Parameters:
imageName - the image name
index - the index
sequence - true to automatically load image sequence, if any
Throws:
java.io.IOException

insert

public void insert(java.awt.Image image,
                   int index)
Inserts an image at the specified index.

Parameters:
image - the image
index - the index

remove

public java.lang.String remove(int index)
Removes the image at the specified index.

Parameters:
index - the index
Returns:
the path of the image, or null if none removed

getSize

public java.awt.Dimension getSize()
Gets the size of this video.

Returns:
the maximum size of the images

isFileBased

public boolean isFileBased()
Returns true if all of the images are associated with files.

Returns:
true if all images are file-based

isEditable

public boolean isEditable()
Returns true if all images are loaded into memory.

Returns:
true if editable

setEditable

public void setEditable(boolean edit)
                 throws java.io.IOException
Sets the editable property.

Parameters:
edit - true to edit
Throws:
java.io.IOException

saveInvalidImages

public boolean saveInvalidImages()
Allows user to save invalid images, if any.

Returns:
true if saved

finalize

protected void finalize()
Called by the garbage collector when this video is no longer in use.

Overrides:
finalize in class VideoAdapter

getValidPaths

protected java.lang.String[] getValidPaths()
Returns the valid paths (i.e., those that are not ""). Invalid paths are associated with pasted images rather than files.

Returns:
the valid paths

getValidPathsRelativeTo

protected java.lang.String[] getValidPathsRelativeTo(java.lang.String base)
Returns the valid paths (i.e., those that are not "") relative to a bae path. Invalid paths are associated with pasted images rather than files.

Parameters:
base - a base path
Returns:
the valid relative paths

insert

protected void insert(java.awt.Image[] newImages,
                      int index,
                      java.lang.String[] imagePaths)
Inserts images starting at the specified index.

Parameters:
newImages - an array of images
index - the insertion index
imagePaths - array of image file paths.

getLoader

public static XML.ObjectLoader getLoader()
Returns an XML.ObjectLoader to save and load ImageVideo data.

Returns:
the object loader