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 classA class to save and load data for this object.Nested classes/interfaces inherited from class org.opensourcephysics.display.InteractivePanel
InteractivePanel.IADMouseControllerNested classes/interfaces inherited from class org.opensourcephysics.display.DrawingPanel
DrawingPanel.PopupmenuListener, DrawingPanel.ZoomBoxNested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanelNested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponentNested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsModifier and TypeFieldDescriptionbooleanset to true when this panel has been changed, false when savedprotected ImageCoordSystemprotected Filedefault file name used for initial saveAsprotected static final intprotected static final intprotected booleanmap filter names to classesintprotected doubleprotected doubleprotected doubleprotected VideoIO.FinalizableLoaderprotected VideoPlayerprotected booleanprotected intprogress and framesLoaded used to keep track of loading processstatic final Stringstatic final Stringprotected Point2Dprotected Stringprotected Videoprotected doubleprotected doubleFields inherited from class org.opensourcephysics.display.InteractivePanel
containsInteractive, interactive, MOUSE_CLICKED, MOUSE_DRAGGED, MOUSE_ENTERED, MOUSE_EXITED, MOUSE_MOVED, MOUSE_PRESSED, MOUSE_RELEASED, mouseAction, mouseEventFields 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, zoomTimerFields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTHFields 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 TypeMethodDescriptionvoidaddDrawable(Drawable drawable) Adds a drawable object to the drawable list.voidAdds a video filter class to the map of available filters.protected voidprotected booleanOverrides DrawingPanel checkImage method so offscreenImage will not include the videoPlayer.voidclear()Removes all drawable objects except the video.voidClears all video filter classes from the map of available filters.voiddispose()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.intGets the current frame number.doubleGets the image border.doubleGets the image height in image units (1.0 unit/pixel).doubleGets the image width in image units.static XML.ObjectLoaderReturns an XML.ObjectLoader to save and load data for this object.Gets the video player.intintGets 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.voidHides the mouse boximportData(Data data, Object source) Imports Data from a source into a DataTrack.booleanReturns true if this is drawing in image space rather than world space.booleanGets the video player visibility.protected voidofferReloadVM(String ext, String message) protected voidOverrides DrawingPanel paintEverything method.voidResponds to property change events.voidVideo loading has failed.voidremoveDrawable(Drawable drawable) Removes a drawable object from the drawable list.voidremoveFilter(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 voidOverrides DrawingPanel scale method to handle drawing in imagespacevoidsetCoords(ImageCoordSystem newCoords) Sets the image coordinate system used to convert between image and world spaces.voidsetDataFile(File file) Sets the file in which data is saved.voidsetDrawingInImageSpace(boolean imagespace) Sets the drawing space to imagespace or worldspace.voidsetImageBorder(double borderFraction) Sets the image border.voidsetImageHeight(double h) Sets the image height in image units (1.0 unit/pixel).voidsetImageWidth(double w) Sets the image width in image units.voidsetLoader(VideoIO.FinalizableLoader loader) voidsetPlayerVisible(boolean visible) Shows or hides the video player.voidsetProgress(int p) voidsetResourceLoading(Video video) booleansetTimeUnit(String unit) Sets the time unit.voidSets the video.voidSets 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, setShowCoordinatesMethods 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, zoomOutMethods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUIMethods 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, updateMethods 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, validateTreeMethods 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-trueto draw in imagespace
-
isDrawingInImageSpace
public boolean isDrawingInImageSpace()Returns true if this is drawing in image space rather than world space.- Returns:
trueif 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-trueto show the player
-
isPlayerVisible
public boolean isPlayerVisible()Gets the video player visibility.- Returns:
trueif 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:DrawingPanelGets 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:
getDrawablesin classDrawingPanel- Returns:
- cloned list
-
getDrawablesNoClone
Must clone if removing Trackable- Overrides:
getDrawablesNoClonein classDrawingPanel
-
addDrawable
Adds a drawable object to the drawable list.- Overrides:
addDrawablein classInteractivePanel- Parameters:
drawable- the drawable object
-
removeDrawable
Removes a drawable object from the drawable list.- Overrides:
removeDrawablein classDrawingPanel- Parameters:
drawable- the drawable object
-
removeObjectsOfClass
Removes all objects of the specified class.- Overrides:
removeObjectsOfClassin 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:
clearin 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:
propertyChangein 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:
paintEverythingin classDrawingPanel- Parameters:
g- the graphics context to draw on
-
scale
Overrides DrawingPanel scale method to handle drawing in imagespace- Overrides:
scalein classDrawingPanel- Parameters:
drawables- the list of drawable objects
-
checkImage
protected boolean checkImage()Overrides DrawingPanel checkImage method so offscreenImage will not include the videoPlayer.- Returns:
trueif 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:
disposein interfaceOSPRuntime.Disposable- Overrides:
disposein classInteractivePanel
-