org.opensourcephysics.media.core
Class VideoIO

java.lang.Object
  extended by org.opensourcephysics.media.core.VideoIO
Direct Known Subclasses:
TrackerIO

public class VideoIO
extends java.lang.Object

This provides static methods for managing video and text input/output.

Version:
1.0
Author:
Douglas Brown

Nested Class Summary
static class VideoIO.StreamPiper
           
protected static class VideoIO.VideoEnginePanel
          A JPanel for setting a preferred video engine when opening a video.
 
Field Summary
protected static boolean canceled
           
protected static javax.swing.JFileChooser chooser
           
static java.lang.String DEFAULT_PREFERRED_EXPORT_EXTENSION
           
protected static java.lang.String defaultXMLExt
           
static java.lang.String ENGINE_NONE
           
static java.lang.String ENGINE_QUICKTIME
           
static java.lang.String ENGINE_XUGGLE
           
protected static javax.swing.filechooser.FileFilter imageFileFilter
           
protected static java.lang.String preferredExportExtension
           
protected static java.util.Collection<VideoFileFilter> singleVideoTypeFilters
           
static java.lang.String[] VIDEO_EXTENSIONS
           
protected static java.lang.String videoEngine
           
protected static VideoIO.VideoEnginePanel videoEnginePanel
           
protected static java.util.ArrayList<VideoType> videoEngines
           
protected static VideoFileFilter videoFileFilter
           
protected static java.util.ArrayList<VideoType> videoTypes
           
static long XUGGLE_54_FILE_LENGTH
           
 
Constructor Summary
protected VideoIO()
          protected constructor to discourage instantiation
 
Method Summary
static void addVideoEngine(VideoType engine)
          Adds a video engine to the list of available engines
static void addVideoType(VideoType type)
          Adds a video type to the list of available types
static Video clone(Video video)
          Returns a clone of the specified video.
static boolean copyFile(java.io.File inFile, java.io.File outFile)
          Copies a source file to a target file.
static javax.swing.JFileChooser getChooser()
          Gets the file chooser.
static java.io.File[] getChooserFiles(java.lang.String type)
          Displays a file chooser and returns the chosen files.
static java.lang.String getDefaultEngine()
          Gets the name of the default video engine.
static java.lang.String getEngine()
          Gets the name of the current video engine.
static java.lang.String getExtension(java.io.File file)
          Gets the extension of a file.
static java.lang.String getPreferredExportExtension()
          Gets the preferred file extension for video exports.
static java.lang.String getRelativePath(java.lang.String absolutePath)
          Gets the path relative to the user directory.
static Video getVideo(java.lang.String path, VideoType vidType)
          Returns a video from a specified path.
static java.lang.String[] getVideoExtensions()
          Returns the currently supported video file extensions
static VideoType getVideoType(java.lang.String className, java.lang.String extension)
          Returns the first registered video type corresponding to a class name and/or extension.
static VideoType[] getVideoTypes()
          Gets an array of available video types
static VideoType[] getVideoTypesForEngine(java.lang.String engine)
          Gets an array of video types available to a specified video engine.
static VideoType[] getVideoTypesForExtension(java.lang.String ext)
          Gets an array of video types that can open files with a given extension.
static double guessXuggleVersion()
          Returns the best guess Xuggle version as a double based on file size.
static boolean isCanceled()
          Determines if the current operation is canceled.
static boolean isEngineInstalled(java.lang.String engine)
          Determines if a video engine is installed on the current computer.
static java.io.File open(java.io.File file, VideoPanel vidPanel)
          Loads data or a video from a specified file into a VideoPanel.
static java.io.File open(VideoPanel vidPanel)
          Loads the specified video panel from a file selected with a chooser and sets the data file of the panel.
static java.io.File save(java.io.File file, VideoPanel vidPanel)
          Writes VideoPanel data to the specified file.
static java.io.File save(java.io.File file, VideoPanel vidPanel, java.lang.String chooserTitle)
          Writes VideoPanel data to the specified file.
static void setCanceled(boolean cancel)
          Cancels the current operation when true.
static void setDefaultXMLExtension(java.lang.String ext)
          Sets the default xml extension used when saving data.
static void setEngine(java.lang.String engine)
          Sets the current video engine by name.
static void setPreferredExportExtension(java.lang.String extension)
          Gets the preferred file extension for video exports.
static void testExec()
          test executing shell commands
static boolean updateEngine(java.lang.String engine)
          Updates a video engine by copying files or creating symlinks if needed.
static java.io.File writeImageFile(java.awt.image.BufferedImage image, java.lang.String filePath)
          Writes an image to a file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VIDEO_EXTENSIONS

public static final java.lang.String[] VIDEO_EXTENSIONS

ENGINE_QUICKTIME

public static final java.lang.String ENGINE_QUICKTIME
See Also:
Constant Field Values

ENGINE_XUGGLE

public static final java.lang.String ENGINE_XUGGLE
See Also:
Constant Field Values

ENGINE_NONE

public static final java.lang.String ENGINE_NONE
See Also:
Constant Field Values

DEFAULT_PREFERRED_EXPORT_EXTENSION

public static final java.lang.String DEFAULT_PREFERRED_EXPORT_EXTENSION
See Also:
Constant Field Values

XUGGLE_54_FILE_LENGTH

public static final long XUGGLE_54_FILE_LENGTH
See Also:
Constant Field Values

chooser

protected static javax.swing.JFileChooser chooser

videoFileFilter

protected static VideoFileFilter videoFileFilter

singleVideoTypeFilters

protected static java.util.Collection<VideoFileFilter> singleVideoTypeFilters

imageFileFilter

protected static javax.swing.filechooser.FileFilter imageFileFilter

videoTypes

protected static java.util.ArrayList<VideoType> videoTypes

videoEngines

protected static java.util.ArrayList<VideoType> videoEngines

defaultXMLExt

protected static java.lang.String defaultXMLExt

videoEngine

protected static java.lang.String videoEngine

videoEnginePanel

protected static VideoIO.VideoEnginePanel videoEnginePanel

canceled

protected static boolean canceled

preferredExportExtension

protected static java.lang.String preferredExportExtension
Constructor Detail

VideoIO

protected VideoIO()
protected constructor to discourage instantiation

Method Detail

getExtension

public static java.lang.String getExtension(java.io.File file)
Gets the extension of a file.

Parameters:
file - the file
Returns:
the extension of the file

getChooser

public static javax.swing.JFileChooser getChooser()
Gets the file chooser.

Returns:
the file chooser

setDefaultXMLExtension

public static void setDefaultXMLExtension(java.lang.String ext)
Sets the default xml extension used when saving data.

Parameters:
ext - the default extension

getRelativePath

public static java.lang.String getRelativePath(java.lang.String absolutePath)
Gets the path relative to the user directory.

Parameters:
absolutePath - the absolute path
Returns:
the relative path

isEngineInstalled

public static boolean isEngineInstalled(java.lang.String engine)
Determines if a video engine is installed on the current computer. Note that accessing an installed engine may require switching Java VM.

Parameters:
engine - ENGINE_QUICKTIME, ENGINE_XUGGLE, or ENGINE_NONE
Returns:
true if installed

getEngine

public static java.lang.String getEngine()
Gets the name of the current video engine.

Returns:
ENGINE_QUICKTIME, ENGINE_XUGGLE, or ENGINE_NONE

setEngine

public static void setEngine(java.lang.String engine)
Sets the current video engine by name.

Parameters:
engine - ENGINE_QUICKTIME, ENGINE_XUGGLE, or ENGINE_NONE

getDefaultEngine

public static java.lang.String getDefaultEngine()
Gets the name of the default video engine.

Returns:
ENGINE_QUICKTIME, ENGINE_XUGGLE, or ENGINE_NONE

updateEngine

public static boolean updateEngine(java.lang.String engine)
Updates a video engine by copying files or creating symlinks if needed.

Parameters:
engine - ENGINE_QUICKTIME, ENGINE_XUGGLE, or ENGINE_NONE
Returns:
true if updated

testExec

public static void testExec()
test executing shell commands


copyFile

public static boolean copyFile(java.io.File inFile,
                               java.io.File outFile)
Copies a source file to a target file.

Parameters:
inFile - the source
outFile - the target
Returns:
true if successfully copied

getVideoExtensions

public static java.lang.String[] getVideoExtensions()
Returns the currently supported video file extensions

Returns:
an array of extensions

getPreferredExportExtension

public static java.lang.String getPreferredExportExtension()
Gets the preferred file extension for video exports.

Returns:
the preferred extension

setPreferredExportExtension

public static void setPreferredExportExtension(java.lang.String extension)
Gets the preferred file extension for video exports.

Parameters:
extension - the preferred extension

addVideoType

public static void addVideoType(VideoType type)
Adds a video type to the list of available types

Parameters:
type - the video type

addVideoEngine

public static void addVideoEngine(VideoType engine)
Adds a video engine to the list of available engines

Parameters:
engine - the video engine type

getVideoType

public static VideoType getVideoType(java.lang.String className,
                                     java.lang.String extension)
Returns the first registered video type corresponding to a class name and/or extension. Strings are case-insensitive.

Parameters:
className - all or part of the simple class name (may be null)
extension - the extension (may be null)
Returns:
the video type

getVideoTypesForExtension

public static VideoType[] getVideoTypesForExtension(java.lang.String ext)
Gets an array of video types that can open files with a given extension.

Parameters:
ext - the extension
Returns:
the video types

getVideoTypes

public static VideoType[] getVideoTypes()
Gets an array of available video types

Returns:
the video types

getVideoTypesForEngine

public static VideoType[] getVideoTypesForEngine(java.lang.String engine)
Gets an array of video types available to a specified video engine. Always returns image and gif types in addition to the engine types.

Parameters:
engine - ENGINE_QUICKTIME, ENGINE_XUGGLE, or ENGINE_NONE
Returns:
the available video types

setCanceled

public static void setCanceled(boolean cancel)
Cancels the current operation when true.

Parameters:
cancel - true to cancel

isCanceled

public static boolean isCanceled()
Determines if the current operation is canceled.

Returns:
true if canceled

getVideo

public static Video getVideo(java.lang.String path,
                             VideoType vidType)
Returns a video from a specified path. May return null.

Parameters:
path - the path
vidType - a requested video type (may be null)
Returns:
the video

clone

public static Video clone(Video video)
Returns a clone of the specified video.

Parameters:
video - the video to clone
Returns:
the clone

open

public static java.io.File open(VideoPanel vidPanel)
Loads the specified video panel from a file selected with a chooser and sets the data file of the panel.

Parameters:
vidPanel - the video panel
Returns:
an array containing the loaded object and file

getChooserFiles

public static java.io.File[] getChooserFiles(java.lang.String type)
Displays a file chooser and returns the chosen files.

Parameters:
type - may be "open", "open video", "save", "insert image"
Returns:
the files, or null if no files chosen

open

public static java.io.File open(java.io.File file,
                                VideoPanel vidPanel)
Loads data or a video from a specified file into a VideoPanel. If file is null, a file chooser is displayed.

Parameters:
file - the file to be loaded
vidPanel - the video panel
Returns:
the file opened

save

public static java.io.File save(java.io.File file,
                                VideoPanel vidPanel)
Writes VideoPanel data to the specified file. If the file is null it brings up a chooser.

Parameters:
file - the file to write to
vidPanel - the video panel
Returns:
the file written to, or null if not written

save

public static java.io.File save(java.io.File file,
                                VideoPanel vidPanel,
                                java.lang.String chooserTitle)
Writes VideoPanel data to the specified file. If the file is null it displays a filechooser.

Parameters:
file - the file to write to
vidPanel - the video panel
chooserTitle - the title for the filechooser
Returns:
the file written to, or null if not written

writeImageFile

public static java.io.File writeImageFile(java.awt.image.BufferedImage image,
                                          java.lang.String filePath)
Writes an image to a file.

Parameters:
image - the image to write
filePath - the path to write to, including extension (png, jpg, gif)
Returns:
the file written, or null if failed

guessXuggleVersion

public static double guessXuggleVersion()
Returns the best guess Xuggle version as a double based on file size. For an exact version number, use DiagnosticsForXuggle (requires Xuggle to be running).

Returns:
3.4 or 5.4 if xuggle installed, otherwise 0.0