Rakesh API

org.rakeshv.gui
Class SlideShow

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by org.rakeshv.gui.SlideShow
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public class SlideShow
extends javax.swing.JComponent

Modified version of SlideShow presented in Java Thread Programming by Paul Hyde published by SAMS.

Load all the images found under the specified directory tree and display using a BufferedImage object. The images are loaded one at a time using File to traverse the specified directory. Each image will be displayed for approximately delayInterval milliseconds. The default value is 100ms for delayInterval. This value can be specified by implementing applications. Implementing applications can also specify that only images in the specified directory be displayed, without traversing sub-directories.

Copyright 2002, Rakesh Vidyadharan

Author:
Rakesh Vidyadharan 18th July 2002 $Id: SlideShow.java,v 1.2 2004/05/26 11:42:37 rakesh Exp $
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
static boolean CONTINUE_PLAYBACK
          Flag that should be used to re-activate the play-back of images.
private  int delayInterval
          The variable that controls the delay between successive image loading.
private  java.awt.image.BufferedImage image
          The current image object that is being displayed.
private  java.lang.Thread internalThread
          The Thread that is used to load the images one at a time.
static boolean SPECIFIED_DIRECTORY_ONLY
          Flag that indicates that the specified directory should not be traversed recursively, and only image files found under the specified directory be played.
static boolean STOP_PLAYBACK
          Flag that should be used to stop the play-back of the images.
private  boolean stopRequested
          A flag that is used to indicate whether the user requested the loading of images to stop.
static boolean TRAVERSE_SUBDIRECTORIES
          Flag that indicates that the specified directory should be traversed recursively, and all image files found played.
 
Fields inherited from class javax.swing.JComponent
accessibleContext, 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
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
 
Constructor Summary
SlideShow(java.io.File directory)
          Create a new JComponent that will load all the image files under the directory.
SlideShow(java.io.File directory, boolean traverseDirectory)
          Create a new JComponent.
 
Method Summary
 int getDelayInterval()
          Return the current value for delayInterval.
 boolean getStopRequested()
          Get the current value of the stopRequested flag.
 void paint(java.awt.Graphics g)
          Draws the current image onto this component.
 void setDelayInterval(int interval)
          Set the desired delayInterval.
 void setStopRequested(boolean flag)
          Set the stopRequested flag to the specified value.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, 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, setVisible, unregisterKeyboardAction, update, updateUI
 
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, transferFocusBackward, 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, 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, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, 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, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TRAVERSE_SUBDIRECTORIES

public static final boolean TRAVERSE_SUBDIRECTORIES
Flag that indicates that the specified directory should be traversed recursively, and all image files found played.

See Also:
Constant Field Values

SPECIFIED_DIRECTORY_ONLY

public static final boolean SPECIFIED_DIRECTORY_ONLY
Flag that indicates that the specified directory should not be traversed recursively, and only image files found under the specified directory be played.

See Also:
Constant Field Values

CONTINUE_PLAYBACK

public static final boolean CONTINUE_PLAYBACK
Flag that should be used to re-activate the play-back of images.

See Also:
Constant Field Values

STOP_PLAYBACK

public static final boolean STOP_PLAYBACK
Flag that should be used to stop the play-back of the images.

See Also:
Constant Field Values

delayInterval

private int delayInterval
The variable that controls the delay between successive image loading. This value is represented in milliseconds. The default value is set to 500ms.


image

private java.awt.image.BufferedImage image
The current image object that is being displayed.


internalThread

private java.lang.Thread internalThread
The Thread that is used to load the images one at a time.


stopRequested

private volatile boolean stopRequested
A flag that is used to indicate whether the user requested the loading of images to stop. By default this is set to false, so that images will be loaded until the user sends a stop request. Since this value will be changed in another thread, this field is made volatile to ensure that the internalThread picks up the latest value.

Constructor Detail

SlideShow

public SlideShow(java.io.File directory)
Create a new JComponent that will load all the image files under the directory. This component may be embedded in any Swing container that wishes to display a slide show of images. This constructor just invokes SlideShow( File, boolean ) with TRAVERSE_SUBDIRECTORIES.

Parameters:
directory - - The directory tree from which the images are to be played.

SlideShow

public SlideShow(java.io.File directory,
                 boolean traverseDirectory)
Create a new JComponent. Depending upon the boolean value passed in sub-directories will be traversed.

Parameters:
directory - - The directory tree from which the images are to be played.
traverseDirectory - - Flag that indicates whether image files under sub-directories should be played. Use TRAVERSE_SUBDIRECTORIES or SPECIFIED_DIRECTORY_ONLY to specify preference.
Method Detail

paint

public void paint(java.awt.Graphics g)
Draws the current image onto this component.

Overrides:
paint in class javax.swing.JComponent

getDelayInterval

public final int getDelayInterval()
Return the current value for delayInterval.

Returns:
int - The current value for delayInterval.

setDelayInterval

public final void setDelayInterval(int interval)
Set the desired delayInterval.

Parameters:
interval - - The desired interval to set.

getStopRequested

public final boolean getStopRequested()
Get the current value of the stopRequested flag.

Returns:
boolean - The value of stopRequested

setStopRequested

public final void setStopRequested(boolean flag)
Set the stopRequested flag to the specified value. After setting the specified flag, send an interrupt to the internalThread. It is recommended that you use the CONTINUE_PLAYBACK or STOP_PLAYBACK flags to set the value.

Parameters:
flag - - The value to set.

Rakesh API

Copyright © 2002-2005 - Rakesh Vidyadharan