Class ScratchVideoRecorder

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

public abstract class ScratchVideoRecorder extends Object implements VideoRecorder
This VideoRecorder records to a scratch file which is then copied as needed.
Version:
1.0
Author:
Douglas Brown
  • Field Details

    • chooser

      protected static JFileChooser chooser
    • chooserField

      protected static JTextComponent chooserField
    • ext

      protected static String ext
    • ignoreChooser

      protected static boolean ignoreChooser
    • tempDirectory

      protected static String tempDirectory
    • tempFilePrefix

      protected static String tempFilePrefix
    • videoType

      protected VideoType videoType
    • dim

      protected Dimension dim
    • frameImage

      protected Image frameImage
    • frameDuration

      protected double frameDuration
    • frameCount

      protected int frameCount
    • scratchName

      protected String scratchName
    • scratchNumber

      protected int scratchNumber
    • scratchFile

      protected File scratchFile
    • canRecord

      protected boolean canRecord
    • hasContent

      protected boolean hasContent
    • isSaved

      protected boolean isSaved
    • saveFile

      protected File saveFile
    • saveChanges

      protected boolean saveChanges
    • tempFileBasePath

      protected String tempFileBasePath
    • tempFileType

      protected String tempFileType
    • tempFiles

      protected ArrayList<File> tempFiles
    • suggestedFileName

      protected String suggestedFileName
    • chosenExtension

      protected String chosenExtension
    • baseDir

      protected String baseDir
  • Constructor Details

    • ScratchVideoRecorder

      public ScratchVideoRecorder(VideoType vidType)
      Constructs a ScratchVideoRecorder for the specified video type.
      Parameters:
      vidType - the video type
  • Method Details

    • createVideo

      public void createVideo() throws IOException
      Creates a new video (scratch file) and sets fileName to null.
      Specified by:
      createVideo in interface VideoRecorder
      Throws:
      IOException
    • createVideo

      public void createVideo(String fileName) throws IOException
      Creates a new video and sets the destination file name. If fileName is null, the user can select a file with a chooser.
      Specified by:
      createVideo in interface VideoRecorder
      Parameters:
      fileName - name of the file to which the video will be written
      Throws:
      IOException
    • createVideo

      public void createVideo(String fileName, String trkPath) throws IOException
      Description copied from interface: VideoRecorder
      Creates a new video with the specified file name.
      Specified by:
      createVideo in interface VideoRecorder
      Parameters:
      fileName - name of the file to which the video will be written
      Throws:
      IOException
    • setSize

      public void setSize(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(Image image) throws 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:
      IOException
    • getVideoType

      public VideoType getVideoType()
      Gets the VideoType.
      Returns:
      the video type
    • getVideo

      public Video getVideo() throws IOException
      Gets the current scratch video.
      Specified by:
      getVideo in interface VideoRecorder
      Returns:
      the video
      Throws:
      IOException
    • saveVideo

      public String saveVideo() throws IOException
      Saves the scratch video to the current file or chooser file.
      Specified by:
      saveVideo in interface VideoRecorder
      Returns:
      the full path to the saved file
      Throws:
      IOException
    • saveVideo

      public String saveVideo(String fileName) throws 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:
      IOException
    • saveVideoAs

      public String saveVideoAs() throws 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:
      IOException
    • getFileName

      public String getFileName()
      Gets the file name of the destination video.
      Specified by:
      getFileName in interface VideoRecorder
      Returns:
      the file name
    • setFileName

      public void setFileName(String path)
      Sets the file name. May be null.
      Specified by:
      setFileName in interface VideoRecorder
      Parameters:
      path - the file name
    • suggestFileName

      public void suggestFileName(String name)
      Suggests a file name. May be null.
      Parameters:
      name - 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
    • setChooserExtension

      public static void setChooserExtension(String extension)
      Sets the extension used in the chooser.
    • createScratch

      protected void createScratch() throws IOException
      Creates the scratch file.
      Throws:
      IOException
    • getScratchExtension

      protected String getScratchExtension()
      Returns the extension to use for the scratch file.
      Returns:
      the extension
    • selectFile

      protected File selectFile()
      Shows a save dialog used to set the output movie file.
      Returns:
      the movie file, or none if canceled by user
    • getFileToBeSaved

      protected File getFileToBeSaved(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
    • finalize

      protected void finalize()
      Called by the garbage collector when this recorder is no longer in use.
      Overrides:
      finalize in class Object
    • deleteTempFiles

      protected void deleteTempFiles()
      Deletes the temporary files.
    • deleteFiles

      protected void deleteFiles(ArrayList<File> files)
      Deletes files.
    • saveScratch

      protected abstract void saveScratch() throws IOException
      Saves the current video to the scratch file.
      Throws:
      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(Image image)
      Appends a frame to the current video.
      Parameters:
      image - the image to append
      Returns:
      true if image successfully appended