fi.hu.cs.titokone
Class GUIBrain

java.lang.Object
  extended byfi.hu.cs.titokone.GUIBrain

public class GUIBrain
extends java.lang.Object

This class contains the intellect the GUI class needs to provide services to the Control class. It also hides the GUI and Control from each other, serving as the middle-man for all their communication. It prepares all the data from CompileInfo, LoadInfo and RunInfo objects to GUI, so that it doesn't have to be aware of what's happening behind GUIBrain. Moreover, this class for its part doesn't take any position on how to show the data provided here on the screen. It may, however, tell GUI to disable or enable some elements or objects, such as buttons, menuitems or inputfields.


Field Summary
static int ANIMATED
           
private  Animator animator
           
private  java.util.Hashtable availableLanguages
          This field contains the languages available, with the long, English names like "Finnish" or "English (GB)" as keys and the locales corresponding to the languages as values.
private static short B91_NOT_RUNNING
           
private static short B91_PAUSED
           
private static short B91_RUNNING
           
private static short B91_WAIT_FOR_KBD
           
static int COMMENTED
           
private  Control control
           
private  java.io.File currentlyOpenedFile
           
private  Settings currentSettings
          This field namely stores the current settings and everytime a setting is changed, this is informed about it.
private  short currentState
          Keeps track of the state of this program.
static java.lang.String DEFAULT_STDIN_FILENAME
           
static java.lang.String DEFAULT_STDOUT_FILENAME
           
protected static boolean ENABLE_DATA_AREA_MARKUP
          This variable sets whether the initial data area length (up to sp) should be marked by hiding the symbolic versions of lines down from it.
private  GUI gui
           
private static short INTERRUPTED_WITH_PAUSE
           
private static short INTERRUPTED_WITHOUT_PAUSE
           
private  boolean interruptSent
          This field is set when menuInterrupt is called, and all continuous loops which do many things and wait for input in between should check if this is sent before continuing to their next step.
private static short K91_COMPILING
           
private static short K91_NOT_COMPILING
           
private static short K91_PAUSED
           
static int LINE_BY_LINE
           
private  java.util.logging.Logger logger
          This field contains our logger.
static int MAX_KBD_VALUE
           
static int MIN_KBD_VALUE
           
private static short NONE
          These fields are used to set the current state of program.
private  boolean noPauses
          This field is set true, when continueTaskWithoutPauses is launched.
static int PAUSED
           
private  java.lang.String programPath
           
private  java.io.File settingsFile
           
private  boolean threadRunning
           
 
Constructor Summary
GUIBrain(GUI gui, Animator animator)
          This constructor sets up the GUIBrain instance.
 
Method Summary
 void continueTask()
          Notifies all methods,that have called waitForContinueTask() to continue their operation.
 void continueTaskWithoutPauses()
          Notifies all methods, that have called waitForContinueTask() to continue their operation plus informs them that waitForContinueTask() should no longer be called during current operation.
 boolean enterInput(java.lang.String input)
           
private  void findAvailableLanguages()
          This method determines the available languages.
 java.lang.String[] getAvailableLanguages()
          Returns all available languages.
private  java.io.File getCurrentDefaultStdinFile()
          This method returns the default stdin file, which is the one declared in currentSettings.
private  java.io.File getCurrentDefaultStdoutFile()
          This method returns the default stdout file, which is the one declared in currentSettings.
private  void getCurrentSettings()
          Makes sure that currentSettings contains at least the default values for each key, if they cannot be obtained from settingsFile.
static java.lang.String getExtension(java.io.File f)
           
private  void interruptCurrentTasks(boolean immediate)
          Notifies all currents tasks to be interrupted once they are able to read the new value of interruptSent.
private  LoadInfo load()
          This just loads the opened b91-program into Titokone's memory without updating GUI anyway.
private  void loadAndUpdateGUI()
          Load the program into Titokone's memory and update's GUI to show the new memory contents and register values and such.
 void menuAbout()
           
 void menuCompile()
          This method corresponds to the menu option File -> Compile.
 void menuEraseMemory()
          This method corresponds to the menu option File -> Erase memory.
 void menuExit()
          This method corresponds to the menu option File -> Exit.
 void menuInterrupt(boolean immediate)
          This method corresponds to a request to interrupt whatever we were doing once it becomes possible.
 void menuManual()
           
 void menuOpenFile(java.io.File openedFile)
          This method corresponds to the menu option File -> Open...
 void menuRun()
          This method corresponds to the menu option File -> Run.
 void menuSetCompilingOption(int option, boolean b)
          This method
 void menuSetLanguage(java.io.File languageFile)
          This method correspods as well to the menu option Option -> Set language.
 void menuSetLanguage(java.lang.String language)
          This method corresponds to the menu option Option -> Set language.
 void menuSetMemorySize(int newSize)
          This method corresponds to the menu option Option -> Set Memory Size.
 void menuSetRunningOption(int option, boolean b)
           
 void menuSetStdin(java.io.File stdinFile)
          This method corresponds to the menu option Option -> Set Default Stdin File.
 void menuSetStdout(java.io.File stdoutFile, boolean append)
          This method corresponds to the menu option Option -> Set Default Stdout File.
 void refreshCompilingOptions()
          This methods refreshes GUI so that it shows compiling options as they are declared currently.
 void refreshRunningOptions()
          This methods refreshes GUI so that it shows running options as they are declared currently.
private  void saveSettings()
          Saves currentSettings to settingsFile.
 void saveSource()
          This method is used to save the source after it has been modified in the code window.
private  void setGUICommandsForCurrentState()
          Sets GUI to correspond the current state of program, which means that some buttons should be enables while others not.
 void waitForContinueTask()
          A method can call this, if it wants enter into pause mode and wait for someone to call continueTask() or continueTaskWithoutPauses() methods.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

availableLanguages

private java.util.Hashtable availableLanguages
This field contains the languages available, with the long, English names like "Finnish" or "English (GB)" as keys and the locales corresponding to the languages as values.


control

private Control control

currentSettings

private Settings currentSettings
This field namely stores the current settings and everytime a setting is changed, this is informed about it. When a GUIBrain object is created, it asks for Control to get settings from settings file (which is as well stored in this class, to settingsFile field) and GUIBrain saves those settings (if there's any) in this field.


animator

private Animator animator

gui

private GUI gui

programPath

private java.lang.String programPath

settingsFile

private java.io.File settingsFile

currentlyOpenedFile

private java.io.File currentlyOpenedFile

COMMENTED

public static final int COMMENTED
See Also:
Constant Field Values

LINE_BY_LINE

public static final int LINE_BY_LINE
See Also:
Constant Field Values

PAUSED

public static final int PAUSED
See Also:
Constant Field Values

ANIMATED

public static final int ANIMATED
See Also:
Constant Field Values

interruptSent

private boolean interruptSent
This field is set when menuInterrupt is called, and all continuous loops which do many things and wait for input in between should check if this is sent before continuing to their next step. An interrupt sent means they should stop doing whatever they were doing as soon as is reasonable. (Usually when it would be the time to wait for input from the user.


noPauses

private boolean noPauses
This field is set true, when continueTaskWithoutPauses is launched. Methods menuRun() and menuCompile() check this to see if they want to override the setting in currentSettings.


threadRunning

private boolean threadRunning

currentState

private short currentState
Keeps track of the state of this program. It can be NONE, B91_NOT_RUNNING, B91_RUNNING, B91_PAUSED, B91_WAIT_FOR_KBD, K91_NOT_COMPILING, K91_COMPILING or K91_PAUSED.


NONE

private static final short NONE
These fields are used to set the current state of program. It's stored into currentState field.

See Also:
Constant Field Values

B91_NOT_RUNNING

private static final short B91_NOT_RUNNING
See Also:
Constant Field Values

B91_RUNNING

private static final short B91_RUNNING
See Also:
Constant Field Values

B91_PAUSED

private static final short B91_PAUSED
See Also:
Constant Field Values

B91_WAIT_FOR_KBD

private static final short B91_WAIT_FOR_KBD
See Also:
Constant Field Values

K91_NOT_COMPILING

private static final short K91_NOT_COMPILING
See Also:
Constant Field Values

K91_COMPILING

private static final short K91_COMPILING
See Also:
Constant Field Values

K91_PAUSED

private static final short K91_PAUSED
See Also:
Constant Field Values

INTERRUPTED_WITHOUT_PAUSE

private static final short INTERRUPTED_WITHOUT_PAUSE
See Also:
Constant Field Values

INTERRUPTED_WITH_PAUSE

private static final short INTERRUPTED_WITH_PAUSE
See Also:
Constant Field Values

logger

private java.util.logging.Logger logger
This field contains our logger.


DEFAULT_STDIN_FILENAME

public static java.lang.String DEFAULT_STDIN_FILENAME

DEFAULT_STDOUT_FILENAME

public static java.lang.String DEFAULT_STDOUT_FILENAME

ENABLE_DATA_AREA_MARKUP

protected static boolean ENABLE_DATA_AREA_MARKUP
This variable sets whether the initial data area length (up to sp) should be marked by hiding the symbolic versions of lines down from it.


MIN_KBD_VALUE

public static final int MIN_KBD_VALUE
See Also:
Constant Field Values

MAX_KBD_VALUE

public static final int MAX_KBD_VALUE
See Also:
Constant Field Values
Constructor Detail

GUIBrain

public GUIBrain(GUI gui,
                Animator animator)
This constructor sets up the GUIBrain instance. It calls private initialization functions, including findAvailableLanguages().

Method Detail

menuOpenFile

public void menuOpenFile(java.io.File openedFile)
This method corresponds to the menu option File -> Open... It calls either openBinaryFile or openSourceFile correspondingly.


enterInput

public boolean enterInput(java.lang.String input)

menuRun

public void menuRun()
This method corresponds to the menu option File -> Run. It does its work by calling runInstruction().


saveSource

public void saveSource()
This method is used to save the source after it has been modified in the code window.


menuCompile

public void menuCompile()
This method corresponds to the menu option File -> Compile. It does its work by calling compileLine().


menuEraseMemory

public void menuEraseMemory()
This method corresponds to the menu option File -> Erase memory.


menuExit

public void menuExit()
This method corresponds to the menu option File -> Exit.


menuSetLanguage

public void menuSetLanguage(java.lang.String language)
This method corresponds to the menu option Option -> Set language. If the chosen language is one in the list, then this version is called.

Parameters:
language - Name of the language. This should be one of those get from getAvailableLanguages() method.

menuSetLanguage

public void menuSetLanguage(java.io.File languageFile)
This method correspods as well to the menu option Option -> Set language. This version is called, if user has chosen an external language file.

Parameters:
languageFile - The language file. This must be class-file that extends ListResourceBundle.

menuSetStdin

public void menuSetStdin(java.io.File stdinFile)
This method corresponds to the menu option Option -> Set Default Stdin File. It informs Control about the new default stdin file and saves it to settingsFile.


menuSetStdout

public void menuSetStdout(java.io.File stdoutFile,
                          boolean append)
This method corresponds to the menu option Option -> Set Default Stdout File. It informs Control about the new default stdout file and saves it to settingsFile.


menuSetMemorySize

public void menuSetMemorySize(int newSize)
This method corresponds to the menu option Option -> Set Memory Size.


refreshRunningOptions

public void refreshRunningOptions()
This methods refreshes GUI so that it shows running options as they are declared currently.


menuSetRunningOption

public void menuSetRunningOption(int option,
                                 boolean b)

refreshCompilingOptions

public void refreshCompilingOptions()
This methods refreshes GUI so that it shows compiling options as they are declared currently.


menuSetCompilingOption

public void menuSetCompilingOption(int option,
                                   boolean b)
This method


menuAbout

public void menuAbout()

menuManual

public void menuManual()

menuInterrupt

public void menuInterrupt(boolean immediate)
This method corresponds to a request to interrupt whatever we were doing once it becomes possible.

Parameters:
immediate - If this is true, then continueTask is being waited before the previous job ends. If this is false, then it stops immediately and next job can start right after calling this.

interruptCurrentTasks

private void interruptCurrentTasks(boolean immediate)
Notifies all currents tasks to be interrupted once they are able to read the new value of interruptSent. Immediate interruption means that all tasks should end without any further activities, while non-immediate interruption means that some tasks may pause to wait for continueTask() to notify them before ending completely.

Parameters:
immediate - If this is true, then continueTask is being waited before the previous job ends. If this is false, then it stops immediately and next job can start right after calling this.

continueTask

public void continueTask()
Notifies all methods,that have called waitForContinueTask() to continue their operation.


continueTaskWithoutPauses

public void continueTaskWithoutPauses()
Notifies all methods, that have called waitForContinueTask() to continue their operation plus informs them that waitForContinueTask() should no longer be called during current operation.


waitForContinueTask

public void waitForContinueTask()
A method can call this, if it wants enter into pause mode and wait for someone to call continueTask() or continueTaskWithoutPauses() methods. This method cannot however be used, unless the method which is calling this hasn't been set to run in a thread of its own. eg. by calling new GUIThreader()


getAvailableLanguages

public java.lang.String[] getAvailableLanguages()
Returns all available languages. These (and only these) can be used as parameter for setLanguge(String) method.


getCurrentSettings

private void getCurrentSettings()
                         throws java.io.IOException
Makes sure that currentSettings contains at least the default values for each key, if they cannot be obtained from settingsFile.

Throws:
java.io.IOException

load

private LoadInfo load()
This just loads the opened b91-program into Titokone's memory without updating GUI anyway. However, GUI is told to show an error message, if the loaded program is too large and thus Titokone is out of memory.

Returns:
LoadInfo object, which contains information about the loading process.

loadAndUpdateGUI

private void loadAndUpdateGUI()
Load the program into Titokone's memory and update's GUI to show the new memory contents and register values and such.


saveSettings

private void saveSettings()
Saves currentSettings to settingsFile.


getCurrentDefaultStdoutFile

private java.io.File getCurrentDefaultStdoutFile()
This method returns the default stdout file, which is the one declared in currentSettings.


getCurrentDefaultStdinFile

private java.io.File getCurrentDefaultStdinFile()
This method returns the default stdin file, which is the one declared in currentSettings.


findAvailableLanguages

private void findAvailableLanguages()
This method determines the available languages. It reads them from a setup file languages.cfg, which contains lineseparator-delimited sets of language-name, language-id, (country), eg. "Finnish, fi", or "English (GB), en, GB".


getExtension

public static java.lang.String getExtension(java.io.File f)

setGUICommandsForCurrentState

private void setGUICommandsForCurrentState()
Sets GUI to correspond the current state of program, which means that some buttons should be enables while others not.