org.opensourcephysics.media.core
Class ScratchVideoRecorder

java.lang.Object
  extended by org.opensourcephysics.media.core.ScratchVideoRecorder
All Implemented Interfaces:
VideoRecorder
Direct Known Subclasses:
GifVideoRecorder, ImageVideoRecorder

public abstract class ScratchVideoRecorder
extends java.lang.Object
implements VideoRecorder

This VideoRecorder records to a scratch file which is then copied as needed.

Version:
1.0
Author:
Douglas Brown

Field Summary
protected  boolean canRecord
           
protected static javax.swing.JFileChooser chooser
           
protected static javax.swing.text.JTextComponent chooserField
           
protected  java.awt.Dimension dim
           
protected static java.lang.String ext
           
protected  int frameCount
           
protected  double frameDuration
           
protected  java.awt.Image frameImage
           
protected  boolean hasContent
           
protected static boolean ignoreChooser
           
protected  boolean isSaved
           
protected  boolean saveChanges
           
protected  java.io.File saveFile
           
protected  java.io.File scratchFile
           
protected  java.lang.String scratchName
           
protected  int scratchNumber
           
protected  VideoType videoType
           
 
Constructor Summary
ScratchVideoRecorder(VideoType vidType)
          Constructs a ScratchVideoRecorder for the specified video type.
 
Method Summary
 void addFrame(java.awt.Image image)
          Adds a video frame with the specified image.
protected abstract  boolean append(java.awt.Image image)
          Appends a frame to the current video.
protected  void createScratch()
          Creates the scratch file.
 void createVideo()
          Creates a new video (scratch file) and sets fileName to null.
 void createVideo(java.lang.String fileName)
          Creates a new video and sets the destination file name.
 java.lang.String getFileName()
          Gets the file name of the destination video.
protected  java.io.File getFileToBeSaved(java.io.File file)
          Return the file that will be saved if the specified file is selected.
 Video getVideo()
          Gets the current scratch video.
 void reset()
          Discards the current video and resets the recorder to a ready state.
protected abstract  void saveScratch()
          Saves the current video to the scratch file.
 java.lang.String saveVideo()
          Saves the scratch video to the current file or chooser file.
 java.lang.String saveVideo(java.lang.String fileName)
          Saves the current scratch video to the specified file name.
 java.lang.String saveVideoAs()
          Saves the scratch video to a file picked from a chooser.
protected  java.io.File selectFile()
          Shows a save dialog used to set the output movie file.
 void setFileName(java.lang.String path)
          Sets the file name.
 void setFrameDuration(double millis)
          Sets the time duration per frame.
 void setSize(java.awt.Dimension dimension)
          Sets the size of the video.
protected abstract  boolean startRecording()
          Starts the video recording process using current dimension dim.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

chooser

protected static javax.swing.JFileChooser chooser

chooserField

protected static javax.swing.text.JTextComponent chooserField

ext

protected static java.lang.String ext

ignoreChooser

protected static boolean ignoreChooser

videoType

protected VideoType videoType

dim

protected java.awt.Dimension dim

frameImage

protected java.awt.Image frameImage

frameDuration

protected double frameDuration

frameCount

protected int frameCount

scratchName

protected java.lang.String scratchName

scratchNumber

protected int scratchNumber

scratchFile

protected java.io.File scratchFile

canRecord

protected boolean canRecord

hasContent

protected boolean hasContent

isSaved

protected boolean isSaved

saveFile

protected java.io.File saveFile

saveChanges

protected boolean saveChanges
Constructor Detail

ScratchVideoRecorder

public ScratchVideoRecorder(VideoType vidType)
Constructs a ScratchVideoRecorder for the specified video type.

Parameters:
vidType - the video type
Method Detail

createVideo

public void createVideo()
                 throws java.io.IOException
Creates a new video (scratch file) and sets fileName to null.

Specified by:
createVideo in interface VideoRecorder
Throws:
java.io.IOException

createVideo

public void createVideo(java.lang.String fileName)
                 throws java.io.IOException
Creates a new video and sets the destination file name.

Specified by:
createVideo in interface VideoRecorder
Parameters:
fileName - name of the file to which the video will be written
Throws:
java.io.IOException

setSize

public void setSize(java.awt.Dimension dimension)
Sets the size of the video.

Specified by:
setSize in interface VideoRecorder
Parameters:
dimension - the dimensions of the new video

setFrameDuration

public void setFrameDuration(double millis)
Sets the time duration per frame.

Specified by:
setFrameDuration in interface VideoRecorder
Parameters:
millis - the duration per frame in milliseconds

addFrame

public void addFrame(java.awt.Image image)
              throws java.io.IOException
Adds a video frame with the specified image.

Specified by:
addFrame in interface VideoRecorder
Parameters:
image - the image to be drawn on the video frame.
Throws:
java.io.IOException

getVideo

public Video getVideo()
               throws java.io.IOException
Gets the current scratch video.

Specified by:
getVideo in interface VideoRecorder
Returns:
the video
Throws:
java.io.IOException

saveVideo

public java.lang.String saveVideo()
                           throws java.io.IOException
Saves the scratch video to the current file or chooser file.

Specified by:
saveVideo in interface VideoRecorder
Returns:
the full path of the saved file
Throws:
java.io.IOException

saveVideo

public java.lang.String saveVideo(java.lang.String fileName)
                           throws java.io.IOException
Saves the current scratch video to the specified file name.

Specified by:
saveVideo in interface VideoRecorder
Parameters:
fileName - the file name
Returns:
the full path of the saved file
Throws:
java.io.IOException

saveVideoAs

public java.lang.String saveVideoAs()
                             throws java.io.IOException
Saves the scratch video to a file picked from a chooser.

Specified by:
saveVideoAs in interface VideoRecorder
Returns:
the full path of the saved file
Throws:
java.io.IOException

getFileName

public java.lang.String getFileName()
Gets the file name of the destination video.

Specified by:
getFileName in interface VideoRecorder
Returns:
the file name

setFileName

public void setFileName(java.lang.String path)
Sets the file name. May be null.

Specified by:
setFileName in interface VideoRecorder
Parameters:
path - the file name

reset

public void reset()
Discards the current video and resets the recorder to a ready state.

Specified by:
reset in interface VideoRecorder

createScratch

protected void createScratch()
                      throws java.io.IOException
Creates the scratch file.

Throws:
java.io.IOException

selectFile

protected java.io.File selectFile()
Shows a save dialog used to set the output movie file.

Returns:
the movie file

getFileToBeSaved

protected java.io.File getFileToBeSaved(java.io.File file)
Return the file that will be saved if the specified file is selected. This is needed by ImageVideoRecorder since it strips and/or appends digits to the selected file name. This default implementation returns the file itself.

Parameters:
file - the file selected with the chooser
Returns:
the file (or first file) to be saved

saveScratch

protected abstract void saveScratch()
                             throws java.io.IOException
Saves the current video to the scratch file.

Throws:
java.io.IOException

startRecording

protected abstract boolean startRecording()
Starts the video recording process using current dimension dim.

Returns:
true if video recording successfully started

append

protected abstract boolean append(java.awt.Image image)
Appends a frame to the current video.

Parameters:
image - the image to append
Returns:
true if image successfully appended