jcreek.cke
Class MainWindow

java.lang.Object
  extended byjcreek.cke.MainWindow

public class MainWindow
extends java.lang.Object

This class implements the application manager. It is the one class that organizes the rest of the classes in the application. It holds the localized resource bundle and available actions for the program.

This class is a Singleton which means only one instance of this class exists. You use the instanceOf() method to access that instance.


Field Summary
protected  java.util.Hashtable actions
          Table of available actions in our program.
protected static java.lang.String actionSuffix
          Suffix added to command string to retrieve action classes.
protected static MainWindow instance
          Reference to the single instance of this class.
protected  java.util.ResourceBundle resources
          String and object resources for our program.
protected  java.util.Vector windows
          The list of main windows in this application.
 
Constructor Summary
protected MainWindow()
          No-arg constructor for Visualizer class.
 
Method Summary
 void addAction(javax.swing.Action cmd)
          Stores the action in the command table.
 javax.swing.Action getAction(java.lang.String cmd)
          Retrieves the action corresponding to the given command string.
 java.net.URL getResource(java.lang.String key)
          Retrieves an object from the localized resource bundle.
 java.lang.String getResourceString(java.lang.String name)
          Retrieves a string from the localized resource bundle.
static MainWindow instanceOf()
          Returns the reference to the single instance of this class.
 Visualizer newWindow()
          Creates, shows, and returns a new main window.
 void removeWindow(Visualizer win)
          Closes and removes a main window.
static java.lang.String[] tokenize(java.lang.String input)
          Take the given string and chop it up into a series of strings on whitespace boundries.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

instance

protected static MainWindow instance
Reference to the single instance of this class.


windows

protected java.util.Vector windows
The list of main windows in this application.


resources

protected java.util.ResourceBundle resources
String and object resources for our program. Used to get localized strings and objects (such as images) for user interface components.


actions

protected java.util.Hashtable actions
Table of available actions in our program. Other classes can look up actions by their action string using the getAction() method.


actionSuffix

protected static java.lang.String actionSuffix
Suffix added to command string to retrieve action classes.

Constructor Detail

MainWindow

protected MainWindow()
No-arg constructor for Visualizer class. It is protected since this class is a Singleton. To get the single instance of this class use the instanceOf() method.

Method Detail

getResourceString

public java.lang.String getResourceString(java.lang.String name)
Retrieves a string from the localized resource bundle. The resources are located in the appropriate resources/JavaCreek.properties file.

Parameters:
name - key name of the string resource to find
Returns:
string resource or null if not found
See Also:
getResource(java.lang.String)

getResource

public java.net.URL getResource(java.lang.String key)
Retrieves an object from the localized resource bundle. In most cases this is an image. The resources are located in the appropriate resources/JavaCreek.properties file.

Parameters:
key - key name of the resource to find
Returns:
URL pointing to the object resource
See Also:
getResourceString(java.lang.String)

instanceOf

public static MainWindow instanceOf()
Returns the reference to the single instance of this class. If an instance does not exist it will be created.

Returns:
the instance of this class

newWindow

public Visualizer newWindow()
Creates, shows, and returns a new main window. This is added to the list of main windows stored in this object. To remove a window when finished, call removeWindow().

Returns:
new main window

removeWindow

public void removeWindow(Visualizer win)
Closes and removes a main window. In the event that there are no more main windows, the application will exit the JVM.

Parameters:
win - main window to close and remove

tokenize

public static java.lang.String[] tokenize(java.lang.String input)
Take the given string and chop it up into a series of strings on whitespace boundries. This is useful for trying to get an array of strings out of the resource file. If input is null, returns a zero-length array of String.

Parameters:
input - string to be split apart
Returns:
array of strings from input

addAction

public void addAction(javax.swing.Action cmd)
Stores the action in the command table. It can later be retrieved using getAction().

Parameters:
cmd - action to store in command table
See Also:
getAction(java.lang.String)

getAction

public javax.swing.Action getAction(java.lang.String cmd)
Retrieves the action corresponding to the given command string. This will first look in the list of actions registered with Visualizer. If the action is not there, it will try to instantiate the action. If successful, it adds the action to the list of registered actions and returns a reference to the action. Else it does nothing and returns null.

Parameters:
cmd - command string to find action for
Returns:
action matching command string or null if not found
See Also:
addAction(javax.swing.Action)


Created at IDI, NTNU by the Artificial Intelligence and Learning group