kawigi.cmd
Class Dispatcher

java.lang.Object
  extended by kawigi.cmd.Dispatcher
All Implemented Interfaces:
java.awt.event.FocusListener, java.util.EventListener

public class Dispatcher
extends java.lang.Object
implements java.awt.event.FocusListener

This class is the switchboard of KawigiEdit's command infrastructure, as of version 2.0. If you need an Action, it will usually come from here. If you want to execute an action, or find an action so you can change properties on it, this is also your class. And if you need global access to several important UI components (like the main CodePane), you can get it from this class. There is a lot of references to "subdispatchers" in the kawigi.cmd package. There is one global dispatcher that holds commands that don't need access to a control on which to act, and it has a set of dispatchers (called subdispatchers that are bound to objects (currently always CodePanes) on which they act.


Field Summary
protected  java.util.Map<ActID,DefaultAction> actionMap
          Map of ActIDs to Actions that have already been instantiated on this dispatcher.
protected  java.awt.Component context
          The object for commands to act on if this is a subdispatcher.
protected static Dispatcher globalDispatcher
          The all-important singleton global dispatcher.
 
Constructor Summary
protected Dispatcher(java.awt.Component context)
          Instantiates a local subdispatcher that acts on context.
 
Method Summary
 Dispatcher createSubDispatcher(java.awt.Component context)
          Creates and returns a local subdispatcher that acts on context.
 void eraseSubDispatcher(Dispatcher disp)
          Deletes subdispatcher from internal structures and forgets it.
 void focusGained(java.awt.event.FocusEvent e)
          Notifies the global dispatcher that a new "context" has gotten focus.
 void focusLost(java.awt.event.FocusEvent e)
          Does nothing - part of the FocusListener interface.
 DefaultAction getAction(ActID actid)
          Gets the Action instance for the given ActID.
 DefaultAction getAction(ActID actid, boolean useGlobal)
          Gets the Action instance for the given ActID.
static CodePane getCodePane()
          Gets the CodePane for the code editor.
static SimpleOutputComponent getCompileComponent()
          Returns the component that displays compile output.
static EditorPanel getEditorPanel()
          Gets the EditorPanel for the code editor.
static javax.swing.JFileChooser getFileChooser()
          Returns a "community JFileChooser instance.
static Dispatcher getGlobalDispatcher()
          Accessor for the global dispatcher.
static EditorPanel getLocalCodeEditorPanel()
          Gets the EditorPanel for the Local Code tab.
static CodePane getLocalCodePane()
          Gets the CodePane for the Local Code tab.
static SimpleOutputComponent getOutputComponent()
          Returns the component that displays stuff printed from test runs.
static ProblemTimer getProblemTimer()
          Returns the problem timer.
static javax.swing.JTabbedPane getTabbedPane()
          Returns the JTabbedPane that all the major stuff is on.
static CodePane getTemplateCodePane()
          Returns the CodePane for the template editor.
static EditorPanel getTemplateEditor()
          Returns the EditorPanel for the template editor.
static CodePane getTestCodePane()
          Gets the CodePane for teh Testing Code editor.
static EditorPanel getTestEditorPanel()
          Gets the EditorPanel for the Testing Code editor.
static javax.swing.JFrame getWindow()
          Gets the main window.
 boolean isGlobal()
          Returns true if this dispatcher is the global dispatcher.
static void reportError(java.lang.Throwable t)
          Brings up a message dialog to notify the user about an error, and also prints the stack trace of the error.
 void runCommand(ActID actid)
          Launches an event on the given actid (i.e. - does what would happen if you clicked on the button or something like that)
static void setCompileComponent(SimpleOutputComponent comp)
          Sets the component that displays compile output.
static void setEditorPanel(EditorPanel panel)
          Sets the EditorPanel for the code editor.
static void setLocalCodeEditorPanel(EditorPanel panel)
          Sets the EditorPanel for the Local Code tab.
static void setOutputComponent(SimpleOutputComponent comp)
          Sets the component that displays stuff printed from test runs.
static void setProblemTimer(ProblemTimer problemTimer)
          Sets the problem timer control that's normally on the left side of the window.
static void setTabbedPane(javax.swing.JTabbedPane tabbedPane)
          Sets the JTabbedPane that all the major stuff is on.
static void setTemplateEditor(EditorPanel editor)
          Sets the EditorPanel for the template editor.
static void setTestEditorPanel(EditorPanel panel)
          Sets the EditorPanel for the Testing Code editor.
static void setWindow(javax.swing.JFrame window)
          Sets the main window KawigiEdit is on.
 void UIRefresh()
          Refreshes the settings of all currently mapped actions on this dispatcher.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

actionMap

protected java.util.Map<ActID,DefaultAction> actionMap
Map of ActIDs to Actions that have already been instantiated on this dispatcher.


globalDispatcher

protected static Dispatcher globalDispatcher
The all-important singleton global dispatcher.


context

protected java.awt.Component context
The object for commands to act on if this is a subdispatcher.

Constructor Detail

Dispatcher

protected Dispatcher(java.awt.Component context)
Instantiates a local subdispatcher that acts on context.

Method Detail

isGlobal

public boolean isGlobal()
Returns true if this dispatcher is the global dispatcher.


getGlobalDispatcher

public static Dispatcher getGlobalDispatcher()
Accessor for the global dispatcher.


createSubDispatcher

public Dispatcher createSubDispatcher(java.awt.Component context)
Creates and returns a local subdispatcher that acts on context.


eraseSubDispatcher

public void eraseSubDispatcher(Dispatcher disp)
Deletes subdispatcher from internal structures and forgets it. Method trusts to caller and doesn't check disp if it's null or if it's really was created with createSubDispatcher.


setWindow

public static void setWindow(javax.swing.JFrame window)
Sets the main window KawigiEdit is on.


getWindow

public static javax.swing.JFrame getWindow()
Gets the main window. If it hasn't been set, it tries to find the top-level window containing the editor.


getEditorPanel

public static EditorPanel getEditorPanel()
Gets the EditorPanel for the code editor.


setEditorPanel

public static void setEditorPanel(EditorPanel panel)
Sets the EditorPanel for the code editor.


getCodePane

public static CodePane getCodePane()
Gets the CodePane for the code editor.


getLocalCodeEditorPanel

public static EditorPanel getLocalCodeEditorPanel()
Gets the EditorPanel for the Local Code tab.


setLocalCodeEditorPanel

public static void setLocalCodeEditorPanel(EditorPanel panel)
Sets the EditorPanel for the Local Code tab.


getLocalCodePane

public static CodePane getLocalCodePane()
Gets the CodePane for the Local Code tab.


getTestEditorPanel

public static EditorPanel getTestEditorPanel()
Gets the EditorPanel for the Testing Code editor.


setTestEditorPanel

public static void setTestEditorPanel(EditorPanel panel)
Sets the EditorPanel for the Testing Code editor.


getTestCodePane

public static CodePane getTestCodePane()
Gets the CodePane for teh Testing Code editor.


getOutputComponent

public static SimpleOutputComponent getOutputComponent()
Returns the component that displays stuff printed from test runs.


setOutputComponent

public static void setOutputComponent(SimpleOutputComponent comp)
Sets the component that displays stuff printed from test runs.


getCompileComponent

public static SimpleOutputComponent getCompileComponent()
Returns the component that displays compile output.


setCompileComponent

public static void setCompileComponent(SimpleOutputComponent comp)
Sets the component that displays compile output.


getTabbedPane

public static javax.swing.JTabbedPane getTabbedPane()
Returns the JTabbedPane that all the major stuff is on.


setTabbedPane

public static void setTabbedPane(javax.swing.JTabbedPane tabbedPane)
Sets the JTabbedPane that all the major stuff is on.


setProblemTimer

public static void setProblemTimer(ProblemTimer problemTimer)
Sets the problem timer control that's normally on the left side of the window.


getProblemTimer

public static ProblemTimer getProblemTimer()
Returns the problem timer.


setTemplateEditor

public static void setTemplateEditor(EditorPanel editor)
Sets the EditorPanel for the template editor.


getTemplateEditor

public static EditorPanel getTemplateEditor()
Returns the EditorPanel for the template editor.


getTemplateCodePane

public static CodePane getTemplateCodePane()
Returns the CodePane for the template editor.


getFileChooser

public static javax.swing.JFileChooser getFileChooser()
Returns a "community JFileChooser instance.


getAction

public DefaultAction getAction(ActID actid)
Gets the Action instance for the given ActID.


getAction

public DefaultAction getAction(ActID actid,
                               boolean useGlobal)
Gets the Action instance for the given ActID. There are a few things that might happen here:
  1. If this is called on the global dispatcher and the ActID represents a global action, then the action will just be created if one hasn't been made for this ActID yet, or it will just be returned if it already exists.
  2. If this is called on a subdispatcher but the actid is global, getAction will be called on the global dispatcher.
  3. If the ActID isn't a global action, but this was called on the global dispatcher, a couple things might happen:
    1. If useGlobal is false, the dispatcher will search for the most relevant subdispatcher that already defines this ActID.
    2. If useGlobal is true, a global version of the action will be created which will similarly route commands as necessary. This is so that things like editor commands could be put on a toolbar over the editor.
  4. If this is a local dispatcher and the actid is a local command, the dispatcher will first see if it already has an action mapped to this ActID, otherwise it will attempt to create one using the ActID and a context object.


runCommand

public void runCommand(ActID actid)
Launches an event on the given actid (i.e. - does what would happen if you clicked on the button or something like that)


reportError

public static void reportError(java.lang.Throwable t)
Brings up a message dialog to notify the user about an error, and also prints the stack trace of the error.


UIRefresh

public void UIRefresh()
Refreshes the settings of all currently mapped actions on this dispatcher. If this is the global dispatcher, also refreshes all subdispatchers.


focusGained

public void focusGained(java.awt.event.FocusEvent e)
Notifies the global dispatcher that a new "context" has gotten focus.

Specified by:
focusGained in interface java.awt.event.FocusListener

focusLost

public void focusLost(java.awt.event.FocusEvent e)
Does nothing - part of the FocusListener interface.

Specified by:
focusLost in interface java.awt.event.FocusListener