Package org.opensourcephysics.media.core
Class VideoPanel
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
org.opensourcephysics.display.DrawingPanel
org.opensourcephysics.display.InteractivePanel
org.opensourcephysics.media.core.VideoPanel
- All Implemented Interfaces:
ActionListener
,ImageObserver
,MenuContainer
,PropertyChangeListener
,Serializable
,EventListener
,Accessible
,InteractiveMouseHandler
,OSPRuntime.Disposable
,Renderable
- Direct Known Subclasses:
TrackerPanel
This is an interactive drawing panel with a video player. It can draw videos
and other Trackable objects in either imagespace or worldspace. When drawing
in imagespace, the image reference frame (ie the image itself) is fixed. When
drawing in worldspace, the world reference frame is fixed. The image
reference frame defines positions in pixel units relative to the upper left
corner of a video image--ie, the UL corner of a 320 x 240 video is at (0.0,
0.0) and the LR corner is at (320.0, 240.0). When drawing in imagespace,
non-Trackable objects are not drawn.
- Version:
- 1.0
- Author:
- Douglas Brown
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
A class to save and load data for this object.Nested classes/interfaces inherited from class org.opensourcephysics.display.InteractivePanel
InteractivePanel.IADMouseController
Nested classes/interfaces inherited from class org.opensourcephysics.display.DrawingPanel
DrawingPanel.PopupmenuListener, DrawingPanel.ZoomBox
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
Field Summary
FieldsModifier and TypeFieldDescriptionboolean
set to true when this panel has been changed, false when savedprotected ImageCoordSystem
protected File
default file name used for initial saveAsprotected static final int
protected static final int
protected boolean
map filter names to classesint
protected double
protected double
protected double
protected VideoIO.FinalizableLoader
protected VideoPlayer
protected boolean
protected int
progress and framesLoaded used to keep track of loading processstatic final String
static final String
protected Point2D
protected String
protected Video
protected double
protected double
Fields inherited from class org.opensourcephysics.display.InteractivePanel
containsInteractive, interactive, MOUSE_CLICKED, MOUSE_DRAGGED, MOUSE_ENTERED, MOUSE_EXITED, MOUSE_MOVED, MOUSE_PRESSED, MOUSE_RELEASED, mouseAction, mouseEvent
Fields inherited from class org.opensourcephysics.display.DrawingPanel
adjustableGutter, antialiasShapeOn, antialiasTextOn, autoscaleItem, autoscaleMargin, autoscaleX, autoscaleXMax, autoscaleXMin, autoscaleY, autoscaleYMax, autoscaleYMin, bgColor, BOTTOM_LEFT, BOTTOM_RIGHT, bottomGutter, bottomGutterPreferred, clipAtGutter, coordinateStrBuilder, currentTime, customInspector, decimalFormat, dimensionSetter, displayCoordsOnMouseMoved, drawableList, dxmax, dxmin, dymax, dymin, enableZoom, fixedPixelPerUnit, fixedScale, guiChangeListener, imageRatio, isDisposed, isInteractive, lastHeight, lastWidth, leftGutter, leftGutterPreferred, logScaleX, logScaleY, messages, messagesAsJLabels, mouseController, offscreenImage, optionController, paintDrawables, pixelMatrix, pixelTransform, popupmenu, propertiesItem, RECORD_PAINT_TIMES, refreshDelay, refreshTimer, rightGutter, rightGutterPreferred, scaleItem, scientificFormat, showCoordinates, snapshotItem, squareAspect, TOP_LEFT, TOP_RIGHT, topGutter, topGutterPreferred, vidCap, viewRect, workingImage, xceil, xfloor, xLeftMarginPercentage, xmax, xmaxPreferred, xmin, xminPreferred, xPixPerUnit, xRightMarginPercentage, yBottomMarginPercentage, yceil, yfloor, ymax, ymaxPreferred, ymin, yminPreferred, yPixPerUnit, yTopMarginPercentage, zoomBox, zoomCount, zoomDelay, zoomInItem, zoomOutItem, zoomTimer
Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Fields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Fields inherited from interface org.opensourcephysics.display.OSPRuntime.Disposable
allocated
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a blank VideoPanel with a player.VideoPanel
(Video video) Constructs a VideoPanel with a video and player. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addDrawable
(Drawable drawable) Adds a drawable object to the drawable list.void
Adds a video filter class to the map of available filters.protected void
protected boolean
Overrides DrawingPanel checkImage method so offscreenImage will not include the videoPlayer.void
clear()
Removes all drawable objects except the video.void
Clears all video filter classes from the map of available filters.void
dispose()
Gets the current image coordinate system used for drawing.Gets the file where data is saved.Gets the cloned list of Drawable objects.Must clone if removing TrackableGets the default path for the saveAs method.Gets the map of available video filters.int
Gets the current frame number.double
Gets the image border.double
Gets the image height in image units (1.0 unit/pixel).double
Gets the image width in image units.static XML.ObjectLoader
Returns an XML.ObjectLoader to save and load data for this object.Gets the video player.int
int
Gets the current step number.Gets the time unitgetVideo()
Gets the video.Gets the world coordinates of the last mouse eventGets a XYCoordinateStringBuilder for a TPoint to display its coordinates.void
Hides the mouse boximportData
(Data data, Object source) Imports Data from a source into a DataTrack.boolean
Returns true if this is drawing in image space rather than world space.boolean
Gets the video player visibility.protected void
offerReloadVM
(String ext, String message) protected void
Overrides DrawingPanel paintEverything method.void
Responds to property change events.void
Video loading has failed.void
removeDrawable
(Drawable drawable) Removes a drawable object from the drawable list.void
removeFilter
(Class<?> filterClass) Removes a video filter class from the map of available filters.<T extends Drawable>
voidremoveObjectsOfClass
(Class<T> c) Removes all objects of the specified class.protected void
Overrides DrawingPanel scale method to handle drawing in imagespacevoid
setCoords
(ImageCoordSystem newCoords) Sets the image coordinate system used to convert between image and world spaces.void
setDataFile
(File file) Sets the file in which data is saved.void
setDrawingInImageSpace
(boolean imagespace) Sets the drawing space to imagespace or worldspace.void
setImageBorder
(double borderFraction) Sets the image border.void
setImageHeight
(double h) Sets the image height in image units (1.0 unit/pixel).void
setImageWidth
(double w) Sets the image width in image units.void
setLoader
(VideoIO.FinalizableLoader loader) void
setPlayerVisible
(boolean visible) Shows or hides the video player.void
setProgress
(int p) void
setResourceLoading
(Video video) boolean
setTimeUnit
(String unit) Sets the time unit.void
Sets the video.void
Sets the video.Methods inherited from class org.opensourcephysics.display.InteractivePanel
getCurrentDraggable, getInteractive, getMouseAction, getMouseButton, getMouseClickCount, getMouseIntX, getMouseIntY, getMouseX, getMouseY, handleMouseAction, saveMouseEvent, scaleX, scaleY, setInteractiveMouseHandler, setMouseListeners, setShowCoordinates
Methods inherited from class org.opensourcephysics.display.DrawingPanel
actionPerformed, addDrawableAtIndex, addDrawables, addMessageLabel, addOptionController, buildPopupMenu, checkWorkingImage, computeGutters, displayCoordinates, dref, enableInspector, findViewRect, firePropertyChange, getAspectRatio, getBottomGutter, getCoordinateStringBuilder, getDimensionSetter, getDrawables, getDrawables, getDrawablesExcept, getDrawablesExcept, getFirstDrawable, getGlassPane, getGutters, getHeight, getImageRatio, getLeftGutter, getMaxPixPerUnit, getMeasure, getObjectOfClass, getPixelMatrix, getPixelTransform, getPixelTransform, getPopupMenu, getPreferredXMax, getPreferredXMin, getPreferredYMax, getPreferredYMin, getRightGutter, getScale, getSnapshotItem, getTopGutter, getVideoTool, getViewRect, getWidth, getXMax, getXMin, getXPixPerUnit, getYMax, getYMin, getYPixPerUnit, getZoomBox, hasInspector, hideInspector, invalidateImage, isAdjustableGutter, isAntialiasShapeOn, isAntialiasTextOn, isAutoscaleX, isAutoscaleXMax, isAutoscaleXMin, isAutoscaleY, isAutoscaleYMax, isAutoscaleYMin, isBuffered, isClipAtGutter, isFixedScale, isIconified, isLogScaleX, isLogScaleY, isPointInside, isShowCoordinates, isSquareAspect, isValidImage, isZoom, isZoomEvent, limitAutoscaleX, limitAutoscaleY, measure, paint, paintComponent, paintDrawableList, paintFirst, paintLast, pixToX, pixToY, project, receiveToolReply, recomputeTransform, refreshDecimalSeparators, refreshGUI, removeDrawables, removeOptionController, render, render, repaint, repaint, repaintForZoom, repaintIfNecessary, replaceDrawable, resetGutters, scale, scaleX, scaleY, setAdjustableGutter, setAntialiasShapeOn, setAntialiasTextOn, setAutoscaleMargin, setAutoscaleX, setAutoscaleY, setBounds, setBounds, setBuffered, setClipAtGutter, setCoordinateStringBuilder, setCustomInspector, setFixedScale, setFontFactor, setFontLevel, setGutters, setGutters, setMessage, setMessage, setMouseCursor, setPaintDrawables, setPixelScale, setPixelsPerUnit, setPopupMenu, setPreferredGutters, setPreferredMinMax, setPreferredMinMax, setPreferredMinMaxX, setPreferredMinMaxY, setSquareAspect, setVideoTool, setVisible, setXLeftMarginPercentage, setXMarginPercentage, setXMarginPercentage, setXRightMarginPercentage, setYBottomMarginPercentage, setYMarginPercentage, setYMarginPercentage, setYTopMarginPercentage, setZoom, showInspector, snapshot, transformPath, transformShape, validateImage, xToGraphics, xToPix, yToGraphics, yToPix, zoomIn, zoomOut
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, unregisterKeyboardAction, update
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
defaultWidth
protected static final int defaultWidth- See Also:
-
defaultHeight
protected static final int defaultHeight- See Also:
-
PROPERTY_VIDEOPANEL_DATAFILE
- See Also:
-
PROPERTY_VIDEOPANEL_IMAGESPACE
- See Also:
-
changed
public boolean changedset to true when this panel has been changed, false when saved -
defaultFileName
default file name used for initial saveAs -
progress
protected int progressprogress and framesLoaded used to keep track of loading process -
framesLoaded
public int framesLoaded -
player
-
video
-
playerVisible
protected boolean playerVisible -
drawingInImageSpace
protected boolean drawingInImageSpace -
imageWidth
protected double imageWidth -
imageHeight
protected double imageHeight -
xOffset
protected double xOffset -
yOffset
protected double yOffset -
imageBorder
protected double imageBorder -
coords
-
pt
-
dataFile
-
timeUnit
-
filterClasses
map filter names to classes -
loader
-
-
Constructor Details
-
VideoPanel
public VideoPanel()Constructs a blank VideoPanel with a player. -
VideoPanel
Constructs a VideoPanel with a video and player.- Parameters:
video
- the video to be drawn
-
-
Method Details
-
addVideoPlayer
protected void addVideoPlayer() -
setVideo
Sets the video.- Parameters:
newVideo
- the videoplayAllSteps
- true to play all steps
-
setVideo
Sets the video.- Parameters:
newVideo
- the video
-
getVideo
Gets the video.- Returns:
- the video
-
getImageWidth
public double getImageWidth()Gets the image width in image units.- Returns:
- the width
-
setImageWidth
public void setImageWidth(double w) Sets the image width in image units.- Parameters:
w
- the width
-
getImageHeight
public double getImageHeight()Gets the image height in image units (1.0 unit/pixel).- Returns:
- the height
-
setImageHeight
public void setImageHeight(double h) Sets the image height in image units (1.0 unit/pixel).- Parameters:
h
- the height
-
getImageBorder
public double getImageBorder()Gets the image border.- Returns:
- the border fraction
-
setImageBorder
public void setImageBorder(double borderFraction) Sets the image border.- Parameters:
borderFraction
- the border fraction
-
getTimeUnit
Gets the time unit- Returns:
- unit the desired unit
-
setTimeUnit
Sets the time unit.- Parameters:
unit
- the time unit- Returns:
- true if unit was changed
-
setCoords
Sets the image coordinate system used to convert between image and world spaces.- Parameters:
newCoords
- the image coordinate system
-
getCoords
Gets the current image coordinate system used for drawing.- Returns:
- the current image coordinate system
-
setDataFile
Sets the file in which data is saved.- Parameters:
file
- the data file
-
getDataFile
Gets the file where data is saved.- Returns:
- the data file
-
getFilePath
Gets the default path for the saveAs method.- Returns:
- the relative path to the file
-
setDrawingInImageSpace
public void setDrawingInImageSpace(boolean imagespace) Sets the drawing space to imagespace or worldspace.- Parameters:
imagespace
-true
to draw in imagespace
-
isDrawingInImageSpace
public boolean isDrawingInImageSpace()Returns true if this is drawing in image space rather than world space.- Returns:
true
if drawing in image space
-
getPlayer
Gets the video player.- Returns:
- the video player
-
setPlayerVisible
public void setPlayerVisible(boolean visible) Shows or hides the video player.- Parameters:
visible
-true
to show the player
-
isPlayerVisible
public boolean isPlayerVisible()Gets the video player visibility.- Returns:
true
if the player is visible
-
getStepNumber
public int getStepNumber()Gets the current step number.- Returns:
- the current step number
-
getFrameNumber
public int getFrameNumber()Gets the current frame number.- Returns:
- the frame number
-
getDrawables
Description copied from class:DrawingPanel
Gets the cloned list of Drawable objects. This is a shallow clone. The same objects will be in both the drawable list and the cloned list.- Overrides:
getDrawables
in classDrawingPanel
- Returns:
- cloned list
-
getDrawablesNoClone
Must clone if removing Trackable- Overrides:
getDrawablesNoClone
in classDrawingPanel
-
addDrawable
Adds a drawable object to the drawable list.- Overrides:
addDrawable
in classInteractivePanel
- Parameters:
drawable
- the drawable object
-
removeDrawable
Removes a drawable object from the drawable list.- Overrides:
removeDrawable
in classDrawingPanel
- Parameters:
drawable
- the drawable object
-
removeObjectsOfClass
Removes all objects of the specified class.- Overrides:
removeObjectsOfClass
in classDrawingPanel
- Parameters:
c
- the class to remove- See Also:
-
clear
public void clear()Removes all drawable objects except the video. To remove the video, use setVideo(null);- Overrides:
clear
in classInteractivePanel
-
addFilter
Adds a video filter class to the map of available filters.- Parameters:
filterClass
- the filter class to add
-
removeFilter
Removes a video filter class from the map of available filters.- Parameters:
filterClass
- the filter class to remove
-
clearFilters
public void clearFilters()Clears all video filter classes from the map of available filters. -
getFilters
Gets the map of available video filters.- Returns:
- the map of available video filters
-
hideMouseBox
public void hideMouseBox()Hides the mouse box -
propertyChange
Responds to property change events. VideoPanel listens for the following events: "videoclip" and "stepnumber" from VideoPlayer, "coords" and "image" from Video.- Specified by:
propertyChange
in interfacePropertyChangeListener
- Parameters:
e
- the property change event
-
importData
Imports Data from a source into a DataTrack. This method returns null, but superclass TrackerPanel overrides it and returns a DataTrack track. Source object may be String path, JPanel controlPanel, Tool tool, etc- Parameters:
data
- the Data to importsource
- the data source (may be null)- Returns:
- the DataTrack with the Data (may return null)
-
paintEverything
Overrides DrawingPanel paintEverything method.- Overrides:
paintEverything
in classDrawingPanel
- Parameters:
g
- the graphics context to draw on
-
scale
Overrides DrawingPanel scale method to handle drawing in imagespace- Overrides:
scale
in classDrawingPanel
- Parameters:
drawables
- the list of drawable objects
-
checkImage
protected boolean checkImage()Overrides DrawingPanel checkImage method so offscreenImage will not include the videoPlayer.- Returns:
true
if the image is correctly sized
-
getWorldMousePoint
Gets the world coordinates of the last mouse event- Returns:
- world coordinates of last mouse event
-
getXYCoordinateStringBuilder
Gets a XYCoordinateStringBuilder for a TPoint to display its coordinates. This default implementation returns the static TPoint string builder.- Parameters:
point
- the TPoint- Returns:
- the XYCoordinateStringBuilder
-
getLoader
Returns an XML.ObjectLoader to save and load data for this object.- Returns:
- the object loader
-
setLoader
-
setResourceLoading
-
setProgress
public void setProgress(int p) -
getProgress
public int getProgress() -
releaseResources
public void releaseResources()Video loading has failed. -
offerReloadVM
-
dispose
public void dispose()- Specified by:
dispose
in interfaceOSPRuntime.Disposable
- Overrides:
dispose
in classInteractivePanel
-