krut.KRUT_GUI
Class SnapShot

java.lang.Object
  extended by java.lang.Thread
      extended by krut.KRUT_GUI.SnapShot
All Implemented Interfaces:
java.lang.Runnable

public class SnapShot
extends java.lang.Thread

This class is used to show a snapshot. Originally the snapshot was only used to show a single screenshot; however it was later expanded to include the preview window. The new methods (the preview related ones) use the old methods for initialization. This update was done more like a hack than as a restructuring, and the readability of the code suffered. This should be worked on. The original code for showing just a screenshot is found in the snapshot-related methods in RunKRUT and ScreenGrabber, and the new calls for updating the preview window are made from the run method in the ScreenGrabber class.


Nested Class Summary
 class SnapShot.ShowPic
          This class shows the image.
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
 javax.swing.JFrame previewFrame
          The JFrame used to show the animation of the film as it records.
 int sleepMillis
          This is the amount of milliseconds to sleep between each update of the window.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
SnapShot()
           
 
Method Summary
 void createAndShowGUI(javax.swing.JFrame frame, java.awt.image.BufferedImage image)
          Show a new image in a new SnapShot window.
 void initPreviewWindow(int width, int height)
          Initializes and shows the preview window, displaying a new BufferedImage.
 java.awt.Image loadPic(java.lang.String fileName, java.awt.Component comp)
          Load a picture from file into an Image
 void run()
          As long as the isRunning parameter is true, the present method sleeps an amount of time determined by the sleepMillis parameter.
 void setFps(int fps)
          Changes the update frequency of the preview window.
 void stopPreviewWindow()
          Closes the preview window and free system resources.
 void updatePreviewImage(java.awt.image.BufferedImage nextImage)
          Update the image in the preview window.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

previewFrame

public javax.swing.JFrame previewFrame
The JFrame used to show the animation of the film as it records.


sleepMillis

public int sleepMillis
This is the amount of milliseconds to sleep between each update of the window. The window will only update if updatePreviewImage has been called since the last update.

Constructor Detail

SnapShot

public SnapShot()
Method Detail

run

public void run()
As long as the isRunning parameter is true, the present method sleeps an amount of time determined by the sleepMillis parameter. After sleeping, the updateImage method is called if the imageUpdated parameter is true. Then the present method sleeps again.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

loadPic

public java.awt.Image loadPic(java.lang.String fileName,
                              java.awt.Component comp)
                       throws java.lang.OutOfMemoryError
Load a picture from file into an Image

Parameters:
fileName - The name of the file containing the picture
comp - A component (like the frame where the image should be drawn) to use for the MediaTracker.
Returns:
The Image.
Throws:
java.lang.OutOfMemoryError

initPreviewWindow

public void initPreviewWindow(int width,
                              int height)
Initializes and shows the preview window, displaying a new BufferedImage.

Parameters:
width - The width of the preview window.
height - The height of the preview window.

setFps

public void setFps(int fps)
Changes the update frequency of the preview window.

Parameters:
fps - The update frequency given as updates per second.

stopPreviewWindow

public void stopPreviewWindow()
Closes the preview window and free system resources.


updatePreviewImage

public void updatePreviewImage(java.awt.image.BufferedImage nextImage)
Update the image in the preview window. The actual updating of the image seen in the window is done by the run method.

Parameters:
nextImage - The BufferedImage that should be shown in the preview window at the next update.

createAndShowGUI

public void createAndShowGUI(javax.swing.JFrame frame,
                             java.awt.image.BufferedImage image)
                      throws java.lang.OutOfMemoryError
Show a new image in a new SnapShot window.

Parameters:
frame - The frame to show the image in.
image - The image.
Throws:
java.lang.OutOfMemoryError