us.zuercher.gpx2map.gui
Class GuiProgressMeter

java.lang.Object
  extended by us.zuercher.gpx2map.util.MessageSink
      extended by us.zuercher.gpx2map.gui.GuiProgressMeter
All Implemented Interfaces:
ProgressMeter

public class GuiProgressMeter
extends MessageSink
implements ProgressMeter

GuiProgressMeter is a combination ProgressMeter and MessageSink. It displays a dialog that contains a JProgressBar representing the ProgessMeter as well as a JTextArea representing the MessageSink.

Author:
Stephan Zuercher

Field Summary
 JButton closeButton
          The close button.
 Action closeButtonAction
          The close button action is executed when the close button is clicked.
private  int count
          Task completion point.
private  JDialog dialog
          Dialog object that is created and displayed by this class.
private static String NL
          System new-line character.
 JProgressBar progressBar
          The progress bar.
 JLabel progressBarLabel
          Label for progressBar.
private  String taskName
          The current task name.
 JTextArea textArea
          The MessageSink output.
private  WindowListener windowListener
          Listens for window closing events and handles graceful exits.
 
Constructor Summary
GuiProgressMeter(JFrame root, String dialogName)
          Constructs a new GuiProgressMeter.
 
Method Summary
(package private)  void close()
          Closing the GuiProgressMeter simply enables the closeButton.
private  void closeDialog()
          Actually closes and disposes of the dialog.
 void newLine()
          Write a new line to the text area.
 void reset()
          Reset the progress bar.
 void setCount(int count)
          Set the count for the current progress bar task.
(package private)  void setDialogName(String dialogName)
          Update the dialog's name.
 void setTaskName(String taskName)
          Set the current task name.
 void updateProgress(int count)
          Update the progress bar to the given completion count.
 void write(String message)
          Write a message to the text area.
 
Methods inherited from class us.zuercher.gpx2map.util.MessageSink
write, write, write, write, write, writeLine, writeLine, writeLine, writeLine, writeLine, writeLine, writeLine
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NL

private static final String NL
System new-line character.


dialog

private final JDialog dialog
Dialog object that is created and displayed by this class.


taskName

private String taskName
The current task name. If null, task name is not used.


count

private int count
Task completion point.


progressBarLabel

public JLabel progressBarLabel
Label for progressBar. Updated to reflect the current progress meter name.


progressBar

public JProgressBar progressBar
The progress bar. Updates to have the current taskName or items completed out of total items information.


textArea

public JTextArea textArea
The MessageSink output.


closeButton

public JButton closeButton
The close button. Enabled once execution is complete.


closeButtonAction

public Action closeButtonAction
The close button action is executed when the close button is clicked.


windowListener

private WindowListener windowListener
Listens for window closing events and handles graceful exits.

Constructor Detail

GuiProgressMeter

GuiProgressMeter(JFrame root,
                 String dialogName)
Constructs a new GuiProgressMeter.

Parameters:
root - application root frame
dialogName - dialog's initial name
Method Detail

close

void close()
Closing the GuiProgressMeter simply enables the closeButton. The closeDialog() method actually closes the dialog, and is called by closeButtonAction and windowListener.


closeDialog

private void closeDialog()
Actually closes and disposes of the dialog.


setDialogName

void setDialogName(String dialogName)
Update the dialog's name.

Parameters:
dialogName - new dialog name.

setTaskName

public void setTaskName(String taskName)
Set the current task name.

Specified by:
setTaskName in interface ProgressMeter
Parameters:
taskName - the new task name

reset

public void reset()
Reset the progress bar. Sets the current progress to 0 and clears the progress bar string.

Specified by:
reset in interface ProgressMeter

setCount

public void setCount(int count)
Set the count for the current progress bar task.

Specified by:
setCount in interface ProgressMeter
Parameters:
count - the number of items in the current task.
Throws:
IllegalStateException - if the count was already set

updateProgress

public void updateProgress(int count)
Update the progress bar to the given completion count. If the current taskName is null, updates the progress bar string to reflect the number of items completed.

Specified by:
updateProgress in interface ProgressMeter
Parameters:
count - the number of items completed

write

public void write(String message)
Write a message to the text area.

Specified by:
write in class MessageSink
Parameters:
message - message to write

newLine

public void newLine()
Write a new line to the text area. Updates the current text area caret to keep the last line of output in view.

Specified by:
newLine in class MessageSink