org.nlogo.app
Class App

java.lang.Object
  extended by org.nlogo.app.App
All Implemented Interfaces:
org.nlogo.util.Exceptions.Handler, org.nlogo.window.Event.Handler, org.nlogo.window.Event.LinkChild, org.nlogo.window.Events.AboutToQuitEvent.Handler, org.nlogo.window.Events.AppEvent.Handler, org.nlogo.window.Events.BeforeLoadEvent.Handler, org.nlogo.window.Events.LoadBeginEvent.Handler, org.nlogo.window.Events.LoadEndEvent.Handler, org.nlogo.window.Events.LoadSectionEvent.Handler, org.nlogo.window.Events.ModelSavedEvent.Handler, org.nlogo.window.ExternalFileManager, Controllable

public final class App
extends Object
implements org.nlogo.window.Event.LinkChild, org.nlogo.util.Exceptions.Handler, org.nlogo.window.ExternalFileManager, org.nlogo.window.Events.AppEvent.Handler, org.nlogo.window.Events.BeforeLoadEvent.Handler, org.nlogo.window.Events.LoadBeginEvent.Handler, org.nlogo.window.Events.LoadSectionEvent.Handler, org.nlogo.window.Events.LoadEndEvent.Handler, org.nlogo.window.Events.ModelSavedEvent.Handler, org.nlogo.window.Events.AboutToQuitEvent.Handler, Controllable

The main class for the complete NetLogo application.

All methods in this class, including the constructor, must be called from the AWT event queue thread, unless otherwise specified.

See the "Controlling" section of the NetLogo User Manual for example code.


Nested Class Summary
static class App.AppFrame
           
 
Field Summary
static App app
          Once main() has been called, holds the singleton instance of this class.
 App.AppFrame frame
           
 org.nlogo.window.GUIWorkspace workspace
           
 
Constructor Summary
App()
           
 
Method Summary
 void command(String source)
          Runs NetLogo commands and waits for them to complete.
 void commandLater(String source)
          Runs NetLogo commands in the background.
 void compile()
          Recompiles the model.
 App.AppFrame getLinkParent()
           
 String getProcedures()
          Returns the contents of the Procedures tab.
 String getSource(String filename)
          Internal use only.
 void handle(org.nlogo.window.Events.AboutToQuitEvent e)
          Internal use only.
 void handle(org.nlogo.window.Events.AppEvent e)
          Internal use only.
 void handle(org.nlogo.window.Events.BeforeLoadEvent e)
          Internal use only.
 void handle(org.nlogo.window.Events.LoadBeginEvent e)
          Internal use only.
 void handle(org.nlogo.window.Events.LoadEndEvent e)
          Internal use only.
 void handle(org.nlogo.window.Events.LoadSectionEvent e)
          Internal use only.
 void handle(org.nlogo.window.Events.ModelSavedEvent e)
          Internal use only.
 void handle(org.nlogo.app.Events.SwitchedTabsEvent e)
          Internal use only.
 void handle(Throwable throwable)
          Internal use only.
 org.nlogo.shape.ShapesManagerInterface linkShapesManager()
           
static void main(String[] args)
          Should be called once at startup to create the application and start it running.
 void makeWidget(String text)
          Adds new widget to Interface tab given its specification, in the same (undocumented) format found in a saved model.
 void open(String path)
          Opens a model stored in a file.
 void openFromSource(String name, String source)
          Opens a model stored in a string.
 void pressButton(String name)
          Not currently supported.
 void quit()
          Quits NetLogo by exiting the JVM.
 Object report(String source)
          Runs a NetLogo reporter.
 void selectTab(int number)
          Switches tabs.
 void setProcedures(String source)
          Replaces the contents of the Procedures tab.
 org.nlogo.shape.ShapesManagerInterface turtleShapesManager()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

frame

public App.AppFrame frame

workspace

public final org.nlogo.window.GUIWorkspace workspace

app

public static App app
Once main() has been called, holds the singleton instance of this class.

Constructor Detail

App

public App()
Method Detail

main

public static void main(String[] args)
Should be called once at startup to create the application and start it running. May not be called more than once. Once this method has called, the singleton instance of this class is stored in app.

This method must not be called from the AWT event queue thread.

Parameters:
args - Should be empty. (Passing non-empty arguments is not currently documented.)

quit

public void quit()
          throws org.nlogo.awt.UserCancelException
Quits NetLogo by exiting the JVM. Asks user for confirmation first if they have unsaved changes. If the user confirms, calls System.exit(0).

Throws:
org.nlogo.awt.UserCancelException

handle

public void handle(org.nlogo.window.Events.AppEvent e)
Internal use only.

Specified by:
handle in interface org.nlogo.window.Events.AppEvent.Handler

handle

public void handle(org.nlogo.app.Events.SwitchedTabsEvent e)
Internal use only.


handle

public void handle(org.nlogo.window.Events.ModelSavedEvent e)
Internal use only.

Specified by:
handle in interface org.nlogo.window.Events.ModelSavedEvent.Handler

handle

public void handle(org.nlogo.window.Events.LoadBeginEvent e)
Internal use only.

Specified by:
handle in interface org.nlogo.window.Events.LoadBeginEvent.Handler

handle

public void handle(org.nlogo.window.Events.BeforeLoadEvent e)
Internal use only.

Specified by:
handle in interface org.nlogo.window.Events.BeforeLoadEvent.Handler

turtleShapesManager

public org.nlogo.shape.ShapesManagerInterface turtleShapesManager()

linkShapesManager

public org.nlogo.shape.ShapesManagerInterface linkShapesManager()

handle

public void handle(org.nlogo.window.Events.LoadEndEvent e)
Internal use only.

Specified by:
handle in interface org.nlogo.window.Events.LoadEndEvent.Handler

handle

public void handle(org.nlogo.window.Events.AboutToQuitEvent e)
Internal use only.

Specified by:
handle in interface org.nlogo.window.Events.AboutToQuitEvent.Handler

handle

public void handle(Throwable throwable)
Internal use only.

Specified by:
handle in interface org.nlogo.util.Exceptions.Handler

open

public void open(String path)
          throws IOException
Opens a model stored in a file.

Specified by:
open in interface Controllable
Parameters:
path - the path (absolute or relative) of the NetLogo model to open.
Throws:
IOException

openFromSource

public void openFromSource(String name,
                           String source)
Opens a model stored in a string.

Parameters:
name - Model name (will appear in the main window's title bar)
source - The complete model, including widgets and so forth, in the same format as it would be stored in a file.

command

public void command(String source)
             throws CompilerException
Runs NetLogo commands and waits for them to complete.

This method must not be called from the AWT event queue thread or while that thread is blocked. It is an error to do so.

Specified by:
command in interface Controllable
Parameters:
source - The command or commands to run
Throws:
CompilerException - if the code fails to compile
IllegalStateException - if called from the AWT event queue thread
See Also:
commandLater(java.lang.String)

commandLater

public void commandLater(String source)
                  throws CompilerException
Runs NetLogo commands in the background. Returns immediately, without waiting for the commands to finish.

This method may be called from any thread.

Parameters:
source - The command or commands to run
Throws:
CompilerException - if the code fails to compile
See Also:
command(java.lang.String)

report

public Object report(String source)
              throws CompilerException
Runs a NetLogo reporter.

This method must not be called from the AWT event queue thread or while that thread is blocked. It is an error to do so.

Specified by:
report in interface Controllable
Parameters:
source - The reporter to run
Returns:
the result reported; may be of type java.lang.Integer, java.lang.Double, java.lang.Boolean, java.lang.String, LogoList, Agent, AgentSet, or Nobody
Throws:
CompilerException - if the code fails to compile
IllegalStateException - if called from the AWT event queue thread

getProcedures

public String getProcedures()
Returns the contents of the Procedures tab.

Returns:
contents of Procedures tab

setProcedures

public void setProcedures(String source)
Replaces the contents of the Procedures tab. Does not recompile the model.

Parameters:
source - new contents
See Also:
compile()

compile

public void compile()
Recompiles the model. Useful after calling setProcedures().

See Also:
setProcedures(java.lang.String)

selectTab

public void selectTab(int number)
Switches tabs.

Parameters:
number - which tab to switch to. 0 is the Interface tab, 1 the Information tab, 2 the Procedures tab, 3 the Errors tab.

pressButton

public void pressButton(String name)
Not currently supported. For now, use command or commandLater() instead.

Parameters:
name - the button to press
See Also:
command(java.lang.String), commandLater(java.lang.String)

makeWidget

public void makeWidget(String text)
Adds new widget to Interface tab given its specification, in the same (undocumented) format found in a saved model.

Parameters:
text - the widget specification

handle

public void handle(org.nlogo.window.Events.LoadSectionEvent e)
Internal use only.

Specified by:
handle in interface org.nlogo.window.Events.LoadSectionEvent.Handler

getSource

public String getSource(String filename)
Internal use only.

Specified by:
getSource in interface org.nlogo.window.ExternalFileManager

getLinkParent

public App.AppFrame getLinkParent()
Specified by:
getLinkParent in interface org.nlogo.window.Event.LinkChild