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
           
protected static java.lang.String defaultXMLExt
           
protected static javax.swing.filechooser.FileFilter imageFileFilter
           
static boolean loadQTLast
           
protected static java.util.Collection<VideoFileFilter> singleVideoTypeFilters
           
static java.lang.String[] VIDEO_EXTENSIONS
           
protected static VideoIO.VideoEnginePanel videoEnginePanel
           
protected static java.util.ArrayList<VideoType> videoEngines
           
protected static VideoFileFilter videoFileFilter
           
protected static java.util.ArrayList<VideoType> videoTypes
           
 
Constructor Summary
protected VideoIO()
          protected constructor to discourage instantiation
 
Method Summary
static void addVideoEngine(VideoType type)
          Adds a video engine to the list of available types
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 getExtension(java.io.File file)
          Gets the extension of a file.
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[] getVideoTypes(java.lang.String ext)
          Gets an array of video types that can open files with a given extension
static boolean isCanceled()
          Determines if the current operation is canceled.
static boolean isQTPreferred()
          Returns true if QTVideo is present and preferred.
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 setQTLast(boolean last)
          Sets the loadQTLast flag.
static void testExec()
          test executing shell commands
static boolean updateVideoType(java.lang.Class<? extends VideoType> type)
          Updates a VideoType if needed.
 
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

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

loadQTLast

public static boolean loadQTLast

videoEnginePanel

protected static VideoIO.VideoEnginePanel videoEnginePanel

canceled

protected static boolean canceled
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

updateVideoType

public static boolean updateVideoType(java.lang.Class<? extends VideoType> type)
Updates a VideoType if needed.

Parameters:
type - the VideoType class
Returns:
true if the type was 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

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 type)
Adds a video engine to the list of available types

Parameters:
type - the video 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)

getVideoTypes

public static VideoType[] getVideoTypes(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

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

setQTLast

public static void setQTLast(boolean last)
Sets the loadQTLast flag. When true, QTVideo is used only if all others fail to load a video.

Parameters:
last - true to load QTVideo last

isQTPreferred

public static boolean isQTPreferred()
Returns true if QTVideo is present and preferred.

Returns:
true if QTVideo is preferred

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