com.kirkwarez.wdysdv.control
Class WVControl

java.lang.Object
  extended byjava.awt.event.WindowAdapter
      extended bycom.kirkwarez.wdysdv.control.WVControl
All Implemented Interfaces:
ActionListener, EventListener, ItemListener, WindowFocusListener, WindowListener, WindowStateListener

public class WVControl
extends WindowAdapter
implements ActionListener, ItemListener

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  void clearTask()
          Clears the GUI's task settings.
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 itemStateChanged(ItemEvent event)
          Processes a checkbox event.
 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.
 void processBatch(Batch batch)
          Processes the given batch.
 void processTask(Task task)
          Processes a single task.
 void processTasks(File infolder, File outfolder)
          Processes a folder of tasks :^P
 void removeAllTasks()
          Removes all Tasks from the batch.
 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.
 void windowClosing(WindowEvent event)
          Closes the GUI and exists the program.
 
Methods inherited from class java.awt.event.WindowAdapter
windowActivated, windowClosed, windowDeactivated, windowDeiconified, windowGainedFocus, windowIconified, windowLostFocus, windowOpened, windowStateChanged
 
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

windowClosing

public void windowClosing(WindowEvent event)
Closes the GUI and exists the program.

Specified by:
windowClosing in interface WindowListener
Parameters:
event - The event that happened.

itemStateChanged

public void itemStateChanged(ItemEvent event)
Processes a checkbox event.

Specified by:
itemStateChanged in interface ItemListener
Parameters:
event - The event.

actionPerformed

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

Specified by:
actionPerformed in interface ActionListener
Parameters:
event - The event that happened.
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. Now with added smart behaviour (the app will try to set the right settings depending on the filename)!

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.

Parameters:
infolder - The folder of files to batch.
outfolder - The output folder where the batched files go to.
Throws:
WVException - When folders aren't folders.

openFile

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

Parameters:
file - The file to open.
Throws:
IOException - When the window can't do its streamstuff without errors.

openFolder

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

Parameters:
folder - The folder with the files to open.
Throws:
IOException - When the windows can't do their streamstuff without errors.

openBatch

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

Parameters:
batch - The batch with the files to open.
Throws:
IOException - When the windows can't do their streamstuff without errors.

processTask

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

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

processTasks

public void processTasks(File infolder,
                         File outfolder)
                  throws IOException,
                         WVException
Processes a folder of tasks :^P

Parameters:
infolder - The folder of files to batch.
outfolder - The output folder where the batched tasks go to.
Throws:
IOException - When the file stuff barfs.
WVException - When folders aren't folders.

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.

removeAllTasks

public void removeAllTasks()
Removes all Tasks from the batch.


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 the 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.

Parameters:
task - The Task to put up 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.

clearTask

protected void clearTask()
Clears the GUI's task settings.