com.kirkwarez.wdysdv.system
Class WVControl

java.lang.Object
  extended bycom.kirkwarez.wdysdv.system.WVControl
All Implemented Interfaces:
ActionListener, EventListener

public class WVControl
extends Object
implements ActionListener

This class acts a control class that processes all the user's actions in the main window.

Since:
5.00
Version:
5.00
Author:
Berend "Kirk" Wouda

Field Summary
protected  Batch batch
          The batch.
protected  DisplayControl displaycontrol
          The control class for the extra windows.
protected  WVFrame gui
          The associated GUI.
protected  Processor processor
          Our personal batch processor.
 
Constructor Summary
WVControl(WVFrame gui)
          Constructs a new control class related with the given GUI.
 
Method Summary
 void actionPerformed(ActionEvent event)
          Processes an event created by the GUI because of user interaction.
 void addTask(Task task)
          Adds the given task to the batchlist.
 void addTasks(File infolder, File outfolder)
          Adds the given folder of files to the batchlist by making tasks of each, using the settings in the GUI and adapting the filenames.
protected  File browseInFile()
          Makes the GUI ask the user for an input file and returns that.
protected  File browseOutFile()
          Makes the GUI ask the user for an output file and returns that.
protected  boolean folder()
          Returns whether the input field is a file or a folder.
protected  File[] getFiles(File folder)
          Returns all the files in the given folder that comply with the current settings in the GUI.
protected  Task getNewTask()
          Retrieves data from the GUI and makes a Task out of it.
protected  File getSuggestedOutFile(File in, File folder)
          Sets the suggested output filename in the output filename field.
 void openBatch(Batch batch)
          Opens all the files in the batch in the GUI in new windows.
 void openFile(File file, int type, int mode)
          Opens the given file in the GUI in a new window.
 void openFolder(File folder, int type, int mode)
          Opens all the files in the given folder in the GUI in new windows.
protected  void openWindow(File file, int type, int mode)
          This method opens a new window on the GUI, that contains the contents of the given file for editing.
 void processBatch(Batch batch)
          Processes the given batch.
 void processSingle(Task task)
          Processes a single task.
 void removeTask(int index)
          Removes the Task on the given index from the batch.
 void returnTask(int index)
          Removes the Task on the given index from the batch and put it in the GUI.
 void setInFile(File in)
          Sets the input file field in the GUI to the given file.
protected  void setNewTask(Task task)
          Takes the given Task and puts its data in the GUI.
 void setOutFile(File out)
          Sets the output file field in the GUI to the given file.
protected  boolean single()
          Returns whether the GUI is in single or in batch mode.
protected  void updateBatchList(Batch batch)
          Updates the lsit in the GUI with the given batch.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

batch

protected Batch batch
The batch.


processor

protected Processor processor
Our personal batch processor.


displaycontrol

protected DisplayControl displaycontrol
The control class for the extra windows.


gui

protected WVFrame gui
The associated GUI.

Constructor Detail

WVControl

public WVControl(WVFrame gui)
Constructs a new control class related with the given GUI.

Method Detail

actionPerformed

public void actionPerformed(ActionEvent event)
Processes an event created by the GUI because of user interaction.

Specified by:
actionPerformed in interface ActionListener
See Also:
ActionListener.actionPerformed(java.awt.event.ActionEvent)

setInFile

public void setInFile(File in)
Sets the input file field in the GUI to the given file.

Parameters:
in - The file to set it to.

setOutFile

public void setOutFile(File out)
Sets the output file field in the GUI to the given file.

Parameters:
out - The file to set it to.

addTask

public void addTask(Task task)
Adds the given task to the batchlist.

Parameters:
task - The task to add.

addTasks

public void addTasks(File infolder,
                     File outfolder)
              throws WVException
Adds the given folder of files to the batchlist by making tasks of each, using the settings in the GUI and adapting the filenames.

Throws:
WVException

openFile

public void openFile(File file,
                     int type,
                     int mode)
Opens the given file in the GUI in a new window.

Parameters:
file - The file to open.

openFolder

public void openFolder(File folder,
                       int type,
                       int mode)
Opens all the files in the given folder in the GUI in new windows.

Parameters:
folder - The folder with the files to open.

openBatch

public void openBatch(Batch batch)
Opens all the files in the batch in the GUI in new windows.

Parameters:
batch - The batch with the files to open.

processSingle

public void processSingle(Task task)
                   throws IOException
Processes a single task.

Parameters:
task - The task to process.
Throws:
IOException - When the file stuff barfs.

processBatch

public void processBatch(Batch batch)
                  throws IOException
Processes the given batch.

Parameters:
batch - The batch with tasks to process.
Throws:
IOException - When the file stuff barfs.

removeTask

public void removeTask(int index)
Removes the Task on the given index from the batch.

Parameters:
index - The index of the task.

returnTask

public void returnTask(int index)
Removes the Task on the given index from the batch and put it in the GUI.

Parameters:
index - The index of the task.

single

protected boolean single()
Returns whether the GUI is in single or in batch mode.

Returns:
Whether to perform a given task directly or run the batch instead.

folder

protected boolean folder()
Returns whether the input field is a file or a folder.

Returns:
Whether to use the given file or all the files in te given folder.

browseInFile

protected File browseInFile()
Makes the GUI ask the user for an input file and returns that.

Returns:
The selected input file.

browseOutFile

protected File browseOutFile()
Makes the GUI ask the user for an output file and returns that.

Returns:
The selected output file.

getSuggestedOutFile

protected File getSuggestedOutFile(File in,
                                   File folder)
Sets the suggested output filename in the output filename field.

Parameters:
in - The input filename to construct it from.
folder - The folder to use as output folder.
Returns:
The suggested filename, or null if none could be determined.

getFiles

protected File[] getFiles(File folder)
Returns all the files in the given folder that comply with the current settings in the GUI.

Returns:
That what I just said.
Throws:
NullPointerException - When the given folder is null.

getNewTask

protected Task getNewTask()
                   throws WVException
Retrieves data from the GUI and makes a Task out of it.

Returns:
That Task.
Throws:
WVException - If the user didn't fill in a file field.

setNewTask

protected void setNewTask(Task task)
Takes the given Task and puts its data in the GUI.


updateBatchList

protected void updateBatchList(Batch batch)
Updates the lsit in the GUI with the given batch.

Parameters:
batch - The batch to update with.

openWindow

protected void openWindow(File file,
                          int type,
                          int mode)
                   throws IOException

This method opens a new window on the GUI, that contains the contents of the given file for editing. The contents are decrypted using the given type of encryption depending on the mode.

If the mode is to decrypt, the file will be decrypted before it is shown. However if the mode is to encrypt, the file will be shown as is, because one can assume that is what the user wants to see.

Parameters:
file - The file to show.
type - The type of encryption (Uru ot MYST V).
mode - The mode of encryption (encrypt or decrypt).
Throws:
IOException - When the window can't do its streamstuff without errors.