Class Playback

java.lang.Object
  extended by Playback
All Implemented Interfaces:
java.awt.event.ActionListener, java.util.EventListener, javax.swing.event.ChangeListener

public class Playback
extends java.lang.Object
implements java.awt.event.ActionListener, javax.swing.event.ChangeListener

This class contains all the graphical components for the playback module. It also loads log files and prepares them for playback. It implements functions used to execute moves from the stored moves list. It also uses a thread class PlaybackThread to implement auto-playback.


Field Summary
(package private)  javax.swing.JTextArea arrangementComments
          Arrangement comments for a log file in the summary dialog
(package private)  javax.swing.JButton closeSummaryButton
          Close button for the summary dialog
(package private)  javax.swing.JTextPane descText
          Description for an unused or blank tile in the summary dialog
(package private)  javax.swing.JButton forwardButton
          The forward button (step forward)
(package private)  javax.swing.ImageIcon forwardIcon
          Icon for the forward button
(package private)  java.util.ListIterator mlIterator
          The list iterator for the log moveList
(package private)  java.util.LinkedList moveList
          A linked list of LogEntries
(package private)  javax.swing.JLabel moveNumberLabel
          Label for the move number
(package private)  CLIPFrame parentFrame
          The frame the application runs in
(package private)  PlaybackThread pbThread
          The thread class used for autoplayback
(package private)  javax.swing.JSlider playbackSlider
          The playback slider
(package private)  javax.swing.JComboBox playbackSpeed
          Auto-Playback speed adjustement combo box
(package private)  javax.swing.JButton playButton
          The play button (auto-playback)
(package private)  javax.swing.ImageIcon playIcon
          Icon for the play button
(package private)  javax.swing.JLabel previousMoveTime
          Label for the previous move time
(package private)  javax.swing.JButton rewindButton
          The rewind button (step back)
(package private)  javax.swing.ImageIcon rewindIcon
          Icon for the rewind button
(package private)  javax.swing.JButton skipBeginButton
          The skip to beginning button (skips to first entry)
(package private)  javax.swing.ImageIcon skipBeginIcon
          Icon for the skip to beginning button
(package private)  javax.swing.JButton skipEndButton
          The skip to end button (skips to last entry)
(package private)  javax.swing.ImageIcon skipEndIcon
          Icon for the skip to end button
(package private)  long speed1_2
          Half speed ms delay time
(package private)  java.lang.String speed1_2Label
          Label for Half speed
(package private)  long speed1_4
          One fourth speed ms delay time
(package private)  java.lang.String speed1_4Label
          Label for one fourth speed
(package private)  long speed1_8
          One eighth speed ms delay time
(package private)  java.lang.String speed1_8Label
          Label for one eighth speed
(package private)  long speed2
          Double speed ms delay time
(package private)  java.lang.String speed2Label
          Label for double speed
(package private)  long speed4
          Quadruple speed ms delay time
(package private)  java.lang.String speed4Label
          Label for quadruple speed
(package private)  long speed8
          Eight times speed ms delay time
(package private)  java.lang.String speed8Label
          Label for eight times speed
(package private)  long speedNorm
          Normal speed ms delay time
(package private)  java.lang.String speedNormLabel
          Label for normal speed
(package private)  javax.swing.JLabel statusDisplayLabel
          Label for the move description
(package private)  javax.swing.JButton stopButton
          The stop button (pause)
(package private)  javax.swing.ImageIcon stopIcon
          Icon for the stop button
(package private)  javax.swing.JButton summaryButton
          The comments button (to display unused/blank/arrangement comments)
(package private)  javax.swing.JDialog summaryDialog
          The Dialog containing the summary information
(package private)  int summaryDialogMaxHeight
          Max height of the summary dialog
(package private)  int summaryDialogMaxWidth
          Max width of the summary dialog
(package private)  Grid theGrid
          The grid object
(package private)  TileBin theTileBin
          The tilebin object
(package private)  UserInterface theUserInterface
          The user interface object
(package private)  javax.swing.ImageIcon[] tileSummaryIcons
          Array of Icons for the summary list in the summary dialog
(package private)  javax.swing.JList tileSummaryList
          List to hold summary tile icons in the summary dialog
(package private)  javax.swing.JScrollPane tileSummaryListPane
          Scrollpane for the list in the summary dialog
(package private)  javax.swing.JLabel totalTime
          Label for the total elapsed time
 
Constructor Summary
Playback(Grid grid, TileBin tileBin, CLIPFrame frame, UserInterface ui)
          Constructor sets references to the grid, tilebin, frame, and user interface objects.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent ev)
          The action listener attached to the playback controls and handles the execution of click events on those controls.
 void beginPlayback()
          Begins playback mode by setting start values for playback controls and labels.
 javax.swing.JPanel createControlPanel()
          Creates a panel to hold all of the controls and labels needed for playback mode.
private  javax.swing.JPanel createPlaybackSummaryPanel()
          Creates a panel to display the summary information components.
private  void displaySummaryDialog()
          Creates and displays the summary dialog containing info on all unused and blank tiles plus overall tile arrangement comments.
private  void displaySummaryTileInfo()
          Displays summary tile information in the summary dialog for the selected tile in the summary tile list.
private  long getPlaybackSpeed(java.lang.String sp)
          Returns the delay time for the passed in speed String.
private  java.lang.String getPreviousMoveTime(LogEntry cur)
          Takes a log entry and generates a string representing the previous move time.
private  int getReverseMove(int type)
          This returns the opposite log entry type from the one passed in but only works for the four basic move types.
private  java.lang.String getTotalTime(LogEntry cur)
          Takes a log entry and generates a string representing the elapsed time.
 boolean isEndOfLog()
          Returns true if the list iterator is at the end of the move list.
 void loadLogFile(java.lang.String path)
          Loads a log file at the specified path and prepares it for playback.
 LogEntry moveToNextEntry()
          Returns a LogEntry of the next entry in the moveList.
 LogEntry moveToPreviousEntry()
          Returns a LogEntry of the previous entry in the moveList.
private  void playbackMove(int type, int x, int y, int tileID)
          Handles the execution of the four 'move' type log entries.
 void processEntry(LogEntry cur)
          This takes a LogEntry and first checks the type of entry it is followed by performing that entry.
private  void skipToMove(int move)
          Skips to the specified move number.
 void stateChanged(javax.swing.event.ChangeEvent e)
          This method fires whenever the slider on the slider bar changes.
 void stopAutoPlayback()
          Stops the playback thread if it is currently running.
private  void undoEntry(LogEntry cur)
          This takes a LogEntry and first checks the type of entry it is followed by executing the reverse of that entry.
private  void updateStatusLabel(int type)
          This checks the move type passed in and then displays an appropriate message in the move description label.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

theGrid

Grid theGrid
The grid object


theTileBin

TileBin theTileBin
The tilebin object


parentFrame

CLIPFrame parentFrame
The frame the application runs in


theUserInterface

UserInterface theUserInterface
The user interface object


moveList

java.util.LinkedList moveList
A linked list of LogEntries

See Also:
LogEntry

mlIterator

java.util.ListIterator mlIterator
The list iterator for the log moveList


pbThread

PlaybackThread pbThread
The thread class used for autoplayback


rewindButton

javax.swing.JButton rewindButton
The rewind button (step back)


forwardButton

javax.swing.JButton forwardButton
The forward button (step forward)


playButton

javax.swing.JButton playButton
The play button (auto-playback)


stopButton

javax.swing.JButton stopButton
The stop button (pause)


playbackSlider

javax.swing.JSlider playbackSlider
The playback slider


summaryButton

javax.swing.JButton summaryButton
The comments button (to display unused/blank/arrangement comments)


skipEndButton

javax.swing.JButton skipEndButton
The skip to end button (skips to last entry)


skipBeginButton

javax.swing.JButton skipBeginButton
The skip to beginning button (skips to first entry)


playbackSpeed

javax.swing.JComboBox playbackSpeed
Auto-Playback speed adjustement combo box


rewindIcon

javax.swing.ImageIcon rewindIcon
Icon for the rewind button


forwardIcon

javax.swing.ImageIcon forwardIcon
Icon for the forward button


stopIcon

javax.swing.ImageIcon stopIcon
Icon for the stop button


playIcon

javax.swing.ImageIcon playIcon
Icon for the play button


skipEndIcon

javax.swing.ImageIcon skipEndIcon
Icon for the skip to end button


skipBeginIcon

javax.swing.ImageIcon skipBeginIcon
Icon for the skip to beginning button


moveNumberLabel

javax.swing.JLabel moveNumberLabel
Label for the move number


previousMoveTime

javax.swing.JLabel previousMoveTime
Label for the previous move time


totalTime

javax.swing.JLabel totalTime
Label for the total elapsed time


statusDisplayLabel

javax.swing.JLabel statusDisplayLabel
Label for the move description


descText

javax.swing.JTextPane descText
Description for an unused or blank tile in the summary dialog


arrangementComments

javax.swing.JTextArea arrangementComments
Arrangement comments for a log file in the summary dialog


tileSummaryList

javax.swing.JList tileSummaryList
List to hold summary tile icons in the summary dialog


tileSummaryIcons

javax.swing.ImageIcon[] tileSummaryIcons
Array of Icons for the summary list in the summary dialog


tileSummaryListPane

javax.swing.JScrollPane tileSummaryListPane
Scrollpane for the list in the summary dialog


closeSummaryButton

javax.swing.JButton closeSummaryButton
Close button for the summary dialog


summaryDialog

javax.swing.JDialog summaryDialog
The Dialog containing the summary information


summaryDialogMaxWidth

final int summaryDialogMaxWidth
Max width of the summary dialog

See Also:
Constant Field Values

summaryDialogMaxHeight

final int summaryDialogMaxHeight
Max height of the summary dialog

See Also:
Constant Field Values

speed1_8Label

final java.lang.String speed1_8Label
Label for one eighth speed

See Also:
Constant Field Values

speed1_8

final long speed1_8
One eighth speed ms delay time

See Also:
Constant Field Values

speed1_4Label

final java.lang.String speed1_4Label
Label for one fourth speed

See Also:
Constant Field Values

speed1_4

final long speed1_4
One fourth speed ms delay time

See Also:
Constant Field Values

speed1_2Label

final java.lang.String speed1_2Label
Label for Half speed

See Also:
Constant Field Values

speed1_2

final long speed1_2
Half speed ms delay time

See Also:
Constant Field Values

speedNormLabel

final java.lang.String speedNormLabel
Label for normal speed

See Also:
Constant Field Values

speedNorm

final long speedNorm
Normal speed ms delay time

See Also:
Constant Field Values

speed2Label

final java.lang.String speed2Label
Label for double speed

See Also:
Constant Field Values

speed2

final long speed2
Double speed ms delay time

See Also:
Constant Field Values

speed4Label

final java.lang.String speed4Label
Label for quadruple speed

See Also:
Constant Field Values

speed4

final long speed4
Quadruple speed ms delay time

See Also:
Constant Field Values

speed8Label

final java.lang.String speed8Label
Label for eight times speed

See Also:
Constant Field Values

speed8

final long speed8
Eight times speed ms delay time

See Also:
Constant Field Values
Constructor Detail

Playback

public Playback(Grid grid,
                TileBin tileBin,
                CLIPFrame frame,
                UserInterface ui)
Constructor sets references to the grid, tilebin, frame, and user interface objects.

Parameters:
grid - The grid object
tileBin - The tilebin object
frame - The frame the application runs in
ui - The user interface object
Method Detail

createPlaybackSummaryPanel

private javax.swing.JPanel createPlaybackSummaryPanel()
Creates a panel to display the summary information components.

Returns:
A panel containing the summary information components.

createControlPanel

public javax.swing.JPanel createControlPanel()
Creates a panel to hold all of the controls and labels needed for playback mode.

Returns:
A panel containing the playback controls and labels

loadLogFile

public void loadLogFile(java.lang.String path)
Loads a log file at the specified path and prepares it for playback.

Parameters:
path - Path of the log file

displaySummaryDialog

private void displaySummaryDialog()
Creates and displays the summary dialog containing info on all unused and blank tiles plus overall tile arrangement comments.

See Also:
createPlaybackSummaryPanel()

displaySummaryTileInfo

private void displaySummaryTileInfo()
Displays summary tile information in the summary dialog for the selected tile in the summary tile list. This function should be called whenever the selected index of the summary tile list has changed.


beginPlayback

public void beginPlayback()
Begins playback mode by setting start values for playback controls and labels.


moveToNextEntry

public LogEntry moveToNextEntry()
Returns a LogEntry of the next entry in the moveList. If no entry is obtained (end of list) then this function returns null.

Returns:
The next LogEntry in the move list; null if its at the end of the list.
See Also:
LogEntry

moveToPreviousEntry

public LogEntry moveToPreviousEntry()
Returns a LogEntry of the previous entry in the moveList. If no entry is obtained (beginning of list) then this function returns null.

Returns:
The previous LogEntry in the move list; null if its at the beginning of the list.
See Also:
LogEntry

playbackMove

private void playbackMove(int type,
                          int x,
                          int y,
                          int tileID)
Handles the execution of the four 'move' type log entries. The move types are grid to grid, grid to tilebin, tilebin to grid, and tilebin to tilebin.

Parameters:
type - Type of move to execute
x - Target X location to move the tile to
y - Targer Y location to move the tile to
tileID - ID of the tile to move
See Also:
LogEntry

skipToMove

private void skipToMove(int move)
Skips to the specified move number. Each move is processed in the system as if the user clicked on the step forward or step back button until they reach thier target move number.

Parameters:
move - The move number to skip to
See Also:
LogEntry

processEntry

public void processEntry(LogEntry cur)
This takes a LogEntry and first checks the type of entry it is followed by performing that entry.

Parameters:
cur - A LogEntry to execute
See Also:
LogEntry

undoEntry

private void undoEntry(LogEntry cur)
This takes a LogEntry and first checks the type of entry it is followed by executing the reverse of that entry.

Parameters:
cur - A LogEntry to undo
See Also:
LogEntry

getPreviousMoveTime

private java.lang.String getPreviousMoveTime(LogEntry cur)
Takes a log entry and generates a string representing the previous move time.

Parameters:
cur - LogEntry to get the previous move time from
Returns:
A String representing previous move time in the form of "hours:minutes:seconds"
See Also:
LogEntry

getTotalTime

private java.lang.String getTotalTime(LogEntry cur)
Takes a log entry and generates a string representing the elapsed time.

Parameters:
cur - LogEntry to get the elapsed time from
Returns:
A String representing elapsed time in the form of "hours:minutes:seconds"
See Also:
LogEntry

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent ev)
The action listener attached to the playback controls and handles the execution of click events on those controls.

Specified by:
actionPerformed in interface java.awt.event.ActionListener
Parameters:
ev - The action event that fired this method

stateChanged

public void stateChanged(javax.swing.event.ChangeEvent e)
This method fires whenever the slider on the slider bar changes. It sets the move number label to the new value and skips to that move.

Specified by:
stateChanged in interface javax.swing.event.ChangeListener
Parameters:
e - The ChangeEvent that fired this method

updateStatusLabel

private void updateStatusLabel(int type)
This checks the move type passed in and then displays an appropriate message in the move description label.

Parameters:
type - Type of move to update the move description label with
See Also:
LogEntry, statusDisplayLabel

getReverseMove

private int getReverseMove(int type)
This returns the opposite log entry type from the one passed in but only works for the four basic move types. The four move types being grid to grid, grid to tilebin, tilebin to grid, and tilebin to tilebin.

Parameters:
type - Type of move to get the opposite of
Returns:
Opposite move type from the one passed in
See Also:
LogEntry

stopAutoPlayback

public void stopAutoPlayback()
Stops the playback thread if it is currently running.

See Also:
PlaybackThread

isEndOfLog

public boolean isEndOfLog()
Returns true if the list iterator is at the end of the move list.

Returns:
true if the list iterator is at the end of the move list; false otherwise.
See Also:
mlIterator

getPlaybackSpeed

private long getPlaybackSpeed(java.lang.String sp)
Returns the delay time for the passed in speed String.

Parameters:
sp - String to get the speed delay time for
Returns:
The delay time for the speed string