krut
Class Run_KRUT

java.lang.Object
  extended by krut.Run_KRUT
All Implemented Interfaces:
java.awt.event.ActionListener, java.awt.event.ItemListener, java.util.EventListener

public class Run_KRUT
extends java.lang.Object
implements java.awt.event.ActionListener, java.awt.event.ItemListener

This is the main class of the program. When the main() method is run, the following things will be done:

- Create and show the GUI.
- Start two new threads for the Sampler and the ScreenGrabber.
- Register event and action listeners to all buttons and menus.

When this is done, the main thread is done, and everything that is done after is caused by the event and action listeners.


Field Summary
protected  javax.swing.JButton activeButton
          This button is used to switch between the recording button, the stop button and the timer button.
 java.io.File audioFile
          The initial name of the audio file.
 CapSizeQuery capQuery
          The interface to the user for changing the capture area.
protected  java.awt.Rectangle capRect
          The starting value of the capture size.
 QualitySlider encSlider
          The interface to the user for changing the movie encoding quality.
 FPSQuery fpsQuery
          The interface to the user for changing the fps values for the recorded movie.
 javax.swing.JFrame frame
          The main frame.
 java.io.File imageFile
          The initial name of the snapshot file.
 SnapShot imageUtils
          A class used for showing the snap shot.
 KrutSettings krutSettings
          The settings object, containing the interfaces to the user for changing the properties of the recorded data.
protected  javax.swing.JButton mouseButton
          The mouse pointer button.
 java.io.File movieFile
          The initial name of the movie file.
 ScreenGrabber myGrabber
          The ScreenGrabber is used for all video and screenshot functions.
 EncodingProgressBar myProgressBar
          The EncodingProgressBar is used to show and abort encoding.
 Sampler mySampler
          The Sampler is used for all audio recording.
protected  java.lang.String newline
          Newline String for the OutputWindow.
protected  boolean nextAudio
          Flag used to keep track of if the NEXT recording should record audio.
protected  boolean nextVideo
          Flag used to keep track of if the NEXT recording should record video.
 OutputText outWindow
          The output window for the program.
protected  boolean recAudio
          Flag to keep track of if we should record audio.
protected  javax.swing.JButton recButton
          The recording button.
protected  boolean recording
          A flag used to tell if recording is in progress.
protected  boolean recVideo
          Flag to keep track of if we should record Video.
 SaveFileChooser saveQuery
          The interface to the user for changing the save files.
protected  javax.swing.JButton snapshotButton
          The snapshot button.
protected  javax.swing.JFrame snapShotFrame
          This JFrame is used to show the SnapShots in.
 SoundQuery soundQuery
          The interface to the user for changing the sound recording quality.
protected  javax.swing.JButton stopButton
          The stop button.
protected  boolean stopping
          A flag used to tell if there is already a thread running trying to stop the recording.
 KrutTimer timer
          The timer object.
protected  javax.swing.JButton timerButton
          The button used to indicate that the timer is active.
protected  javax.swing.JButton timerRecButton
          The button used to indicate that the timer is running.
 
Constructor Summary
Run_KRUT()
           
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          If an ActionEvent is fired from one of the buttons or the menu, this is where we'll end up.
protected  void addButtons(javax.swing.JToolBar toolBar)
          Add 3 buttons to a toolbar.
protected static javax.swing.ImageIcon createImageIcon(java.lang.String path)
          Returns an ImageIcon, or null if the path was invalid.
 javax.swing.JMenuBar createMenuBar()
          Create the menu bar, and add the menu to it.
 java.awt.Dimension getActiveButtonSize()
          This method delivers the size that the activeButton parameter should have.
 void init()
          Main init function.
 void itemStateChanged(java.awt.event.ItemEvent e)
          Something has changed in one of the checkboxes.
static void main(java.lang.String[] args)
           
protected  javax.swing.JButton makeNavigationButton(java.lang.String imageName, java.lang.String actionCommand, java.lang.String toolTipText, java.lang.String altText)
          Creates a navigation button of the specified appearance, and returns it.
 void restoreGUI()
          This is where the GUI is restored after encoding of a recorded film.
 void setTimerGUI(boolean recording)
          Change the GUI to display a timer button instead of a recording/stop button.
 void speedTest()
          Runs the speed test.
protected  void switchActiveButton(javax.swing.JButton newButton)
          Switches the activeButton so that the button displayed is now the one in newButton.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

newline

protected java.lang.String newline
Newline String for the OutputWindow.


frame

public javax.swing.JFrame frame
The main frame.


capQuery

public CapSizeQuery capQuery
The interface to the user for changing the capture area. This used to be a separate object that was initiated by the Run_KRUT object. Now the present object is initiated in KrutSettings, but the Run_KRUT object still needs access so the code will not break.


fpsQuery

public FPSQuery fpsQuery
The interface to the user for changing the fps values for the recorded movie. This used to be a separate object that was initiated by the Run_KRUT object. Now the present object is initiated in KrutSettings, but the Run_KRUT object still needs access so the code will not break.


encSlider

public QualitySlider encSlider
The interface to the user for changing the movie encoding quality. This used to be a separate object that was initiated by the Run_KRUT object. Now the present object is initiated in KrutSettings, but the Run_KRUT object still needs access so the code will not break.


soundQuery

public SoundQuery soundQuery
The interface to the user for changing the sound recording quality. This used to be a separate object that was initiated by the Run_KRUT object. Now the present object is initiated in KrutSettings, but the Run_KRUT object still needs access so the code will not break.


saveQuery

public SaveFileChooser saveQuery
The interface to the user for changing the save files. This used to be a separate object that was initiated by the Run_KRUT object. Now the present object is initiated in KrutSettings, but the Run_KRUT object still needs access so the code will not break.


outWindow

public OutputText outWindow
The output window for the program.


timer

public KrutTimer timer
The timer object.


krutSettings

public KrutSettings krutSettings
The settings object, containing the interfaces to the user for changing the properties of the recorded data.


myGrabber

public ScreenGrabber myGrabber
The ScreenGrabber is used for all video and screenshot functions.


mySampler

public Sampler mySampler
The Sampler is used for all audio recording.


myProgressBar

public EncodingProgressBar myProgressBar
The EncodingProgressBar is used to show and abort encoding.


imageUtils

public SnapShot imageUtils
A class used for showing the snap shot. Used in the snapAction() method.


imageFile

public java.io.File imageFile
The initial name of the snapshot file. This is just passed on to the SaveFileChooser in the activateGUI() method.


movieFile

public java.io.File movieFile
The initial name of the movie file. This is just passed on to the SaveFileChooser in the activateGUI() method.


audioFile

public java.io.File audioFile
The initial name of the audio file. This is just passed on to the SaveFileChooser in the activateGUI() method.


recAudio

protected boolean recAudio
Flag to keep track of if we should record audio. Used in the recordAction() and stopAction(). This flag is updated in the checkInited() method, where it is set to the value of the nextAudio flag. This means that this flag will not change until a new recording is ready to start, so there will be no unwanted interruptions of ongoing recordings.


recVideo

protected boolean recVideo
Flag to keep track of if we should record Video. Used in the recordAction() and stopAction(). This flag is updated in the checkInited() method, where it is set to the value of the nextVideo flag. This means that this flag will not change until a new recording is ready to start, so there will be no unwanted interruptions of ongoing recordings.


nextAudio

protected boolean nextAudio
Flag used to keep track of if the NEXT recording should record audio. This flag is used in the checkInited() method, where its value is copied into recAudio. This flag is changed in the itemStateChanged() method.


nextVideo

protected boolean nextVideo
Flag used to keep track of if the NEXT recording should record video. This flag is used in the checkInited() method, where its value is copied into recVideo. This flag is changed in the itemStateChanged() method.


activeButton

protected javax.swing.JButton activeButton
This button is used to switch between the recording button, the stop button and the timer button. The active button is the button actually showing in the left button position in the main window. The buttons are added in init(), and used in addButtons() and makeNavigationButton and addButtons().


recButton

protected javax.swing.JButton recButton
The recording button. The buttons are added in init(), and used in addButtons() and makeNavigationButton and addButtons().


stopButton

protected javax.swing.JButton stopButton
The stop button. The buttons are added in init(), and used in addButtons() and makeNavigationButton and addButtons().


snapshotButton

protected javax.swing.JButton snapshotButton
The snapshot button. The buttons are added in init(), and used in addButtons() and makeNavigationButton and addButtons().


mouseButton

protected javax.swing.JButton mouseButton
The mouse pointer button. The buttons are added in init(), and used in addButtons() and makeNavigationButton and addButtons().


timerButton

protected javax.swing.JButton timerButton
The button used to indicate that the timer is active. The buttons are added in init(), and used in addButtons() and makeNavigationButton and addButtons().


timerRecButton

protected javax.swing.JButton timerRecButton
The button used to indicate that the timer is running. The buttons are added in init(), and used in addButtons() and makeNavigationButton and addButtons().


capRect

protected java.awt.Rectangle capRect
The starting value of the capture size. This is used in the createScreenGrabber() method. It is also passed on to the KrutSettings constructur from the init() method.


snapShotFrame

protected javax.swing.JFrame snapShotFrame
This JFrame is used to show the SnapShots in. Used in the SnapAction() method. Needs to be initiated before the GUI shows. Is initiated in the createMainFrame() method. (If it is initiated earlier, it will not have the correct LookAndFeel)


stopping

protected boolean stopping
A flag used to tell if there is already a thread running trying to stop the recording. This flag is used to (almost) definitely make sure that two STOP - ActionCommands can not be executed in a row. This flag is changed to true in the the ActionListener and changed back to false in restoreGUI.


recording

protected boolean recording
A flag used to tell if recording is in progress. This is used to tell the timer when it should record and when it should stop. This flag is changed to true in the ActionListener, and changed back to false in restoreGUI.

Constructor Detail

Run_KRUT

public Run_KRUT()
Method Detail

createMenuBar

public javax.swing.JMenuBar createMenuBar()
Create the menu bar, and add the menu to it. Three checkbox items are stored in the global parameters vcbMenuItem, acbMenuItem and mcbMenuItem.

Returns:
a JMenuBar object with the menu attached to it.

createImageIcon

protected static javax.swing.ImageIcon createImageIcon(java.lang.String path)
Returns an ImageIcon, or null if the path was invalid.

Parameters:
The - path to the image.
Returns:
The ImageIcon.

addButtons

protected void addButtons(javax.swing.JToolBar toolBar)
Add 3 buttons to a toolbar. Several buttons are created, and then the toolbar will switch between the recButton, the stopButton, and the timerButton. This is done by adding only the button called activeButton to the toolBar, and then copying the layout on to that button from one of the other two.

Parameters:
toolBar - The JToolBar that should be used in the program.

makeNavigationButton

protected javax.swing.JButton makeNavigationButton(java.lang.String imageName,
                                                   java.lang.String actionCommand,
                                                   java.lang.String toolTipText,
                                                   java.lang.String altText)
Creates a navigation button of the specified appearance, and returns it.

Parameters:
imageName - A String representation of the URL to an image that should be displayed on this button.
actionCommand - The action command for this button. This command is listened for in the actionPerformed(ActionEvent e) method, to determine which button was pressed.
toolTipText - The tooltip text for this button.
altText - The text that should be typed on this button, if any.
Returns:
A JButton according to the specifications given in the parameters.

getActiveButtonSize

public java.awt.Dimension getActiveButtonSize()
This method delivers the size that the activeButton parameter should have. This method is used by the switchActiveButton method. To change the size of the activeButton, this method can be overridden.

Returns:
A Dimension object containing the size of the activeButton.

switchActiveButton

protected void switchActiveButton(javax.swing.JButton newButton)
Switches the activeButton so that the button displayed is now the one in newButton. The size of the new activeButton will be the Dimension value taken from the getActiveButtonSize method.

Parameters:
newButton - The new JButton that should be displayed as the activeButton in the GUI.

setTimerGUI

public void setTimerGUI(boolean recording)
Change the GUI to display a timer button instead of a recording/stop button. There will be one button displaying if the timer is just active and waiting to start a recording, and another button if the timer is recording.

Parameters:
recording - Should be true if the timer is recording, false if it is not.

restoreGUI

public void restoreGUI()
This is where the GUI is restored after encoding of a recorded film. This method is called from the stopAction() method. The GUI should not be restored from anywhere else, since that could mean a potential problem if the stopAction() method is still merging a file in the background, while another StopThread had been started. The GUI was changed in the recordAction() method.


actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
If an ActionEvent is fired from one of the buttons or the menu, this is where we'll end up. Since there is only one ActionListener (the Run_KRUT objet itself) listening to all the different objects, this method will use the getActionCommand() method of the incoming ActionEvent to separate them. It is therefore important that the buttons and menu items are given a proper ActionCommand.

Specified by:
actionPerformed in interface java.awt.event.ActionListener
Parameters:
e - The ActionEvent for this Action.

itemStateChanged

public void itemStateChanged(java.awt.event.ItemEvent e)
Something has changed in one of the checkboxes.

Specified by:
itemStateChanged in interface java.awt.event.ItemListener
Parameters:
e - The ItemEvent that caused the change.

speedTest

public void speedTest()
Runs the speed test. This gives a very rough estimate of the maximum fps that can be used for recording without frame loss. It does not consider hard drive limitations, or delays caused by audio recording.


init

public void init()
          throws java.io.IOException
Main init function. First the ScreenGrabber and the Sampler are created, then all classes for the menu bar functions are properly inited. After that, the main window is created and made visible.

Throws:
java.io.IOException

main

public static void main(java.lang.String[] args)
                 throws java.io.IOException
Throws:
java.io.IOException