NetLogo API
version 3.0.2

org.nlogo.app
Class App

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjava.awt.Window
              extended byjava.awt.Frame
                  extended byjavax.swing.JFrame
                      extended byorg.nlogo.app.App
All Implemented Interfaces:
Accessible, org.nlogo.event.AppEvent.Handler, org.nlogo.event.BeforeLoadEvent.Handler, org.nlogo.event.CompileAllEvent.Raiser, org.nlogo.workspace.Controllable, org.nlogo.event.Event.Handler, org.nlogo.event.EventLinkContainer, org.nlogo.util.ExceptionsHandler, org.nlogo.event.IconifiedEvent.Raiser, ImageObserver, org.nlogo.swing.JMenuBarFactory, org.nlogo.event.LoadBeginEvent.Handler, org.nlogo.event.LoadEndEvent.Handler, MenuContainer, org.nlogo.event.ModelSavedEvent.Handler, RootPaneContainer, Serializable, org.nlogo.app.SwitchedTabsEvent.Handler, WindowConstants, org.nlogo.event.ZoomedEvent.Raiser

public final class App
extends JFrame
implements org.nlogo.swing.JMenuBarFactory, org.nlogo.util.ExceptionsHandler, org.nlogo.event.EventLinkContainer, org.nlogo.event.ZoomedEvent.Raiser, org.nlogo.event.IconifiedEvent.Raiser, org.nlogo.event.CompileAllEvent.Raiser, org.nlogo.event.AppEvent.Handler, org.nlogo.event.BeforeLoadEvent.Handler, org.nlogo.event.LoadBeginEvent.Handler, org.nlogo.event.LoadEndEvent.Handler, org.nlogo.event.ModelSavedEvent.Handler, org.nlogo.app.SwitchedTabsEvent.Handler, org.nlogo.workspace.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.

See Also:
Serialized Form

Field Summary
static App app
          Once main() has been called, holds the singleton instance of this class.
 org.nlogo.window.GUIWorkspace workspace
           
 
Fields inherited from class javax.swing.JFrame
EXIT_ON_CLOSE
 
Fields inherited from class java.awt.Frame
CROSSHAIR_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, ICONIFIED, MAXIMIZED_BOTH, MAXIMIZED_HORIZ, MAXIMIZED_VERT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NORMAL, NW_RESIZE_CURSOR, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, W_RESIZE_CURSOR, WAIT_CURSOR
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface javax.swing.WindowConstants
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Method Summary
 void addHelpMenu(JMenuBar menuBar)
           
 void addLinkComponent(Object c)
          Internal use only.
 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.
 JMenu createFileMenu()
           
 JMenu createToolsMenu()
           
 JMenu createZoomMenu()
           
 Object[] getLinkComponents()
          Internal use only.
 String getProcedures()
          Returns the contents of the Procedures tab.
 void handle(Throwable throwable)
          Internal use only.
 void handleAppEvent(org.nlogo.event.AppEvent e)
          Internal use only.
 void handleBeforeLoadEvent(org.nlogo.event.BeforeLoadEvent e)
          Internal use only.
 void handleLoadBeginEvent(org.nlogo.event.LoadBeginEvent e)
          Internal use only.
 void handleLoadEndEvent(org.nlogo.event.LoadEndEvent e)
          Internal use only.
 void handleModelSavedEvent(org.nlogo.event.ModelSavedEvent e)
          Internal use only.
 void handleSwitchedTabsEvent(org.nlogo.app.SwitchedTabsEvent e)
          Internal use only.
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.
 Object report(String source)
          Runs a NetLogo reporter.
 void requestFocus()
          Internal use only.
 void resizeWorld(int screenEdgeX, int screenEdgeY)
          Kills all turtles, clears all patch variables, and makes a new patch grid.
 void selectTab(int number)
          Switches tabs.
 void setProcedures(String source)
          Replaces the contents of the Procedures tab.
 
Methods inherited from class javax.swing.JFrame
getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getJMenuBar, getLayeredPane, getRootPane, isDefaultLookAndFeelDecorated, remove, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setJMenuBar, setLayeredPane, setLayout, update
 
Methods inherited from class java.awt.Frame
addNotify, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, remove, removeNotify, setCursor, setExtendedState, setIconImage, setMaximizedBounds, setMenuBar, setResizable, setState, setTitle, setUndecorated
 
Methods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getGraphicsConfiguration, getInputContext, getListeners, getLocale, getMostRecentFocusOwner, getOwnedWindows, getOwner, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindowStateListeners, hide, isActive, isFocusableWindow, isFocusCycleRoot, isFocused, isShowing, pack, postEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, setCursor, setFocusableWindowState, setFocusCycleRoot, setLocationRelativeTo, show, toBack, toFront
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, remove, removeAll, removeContainerListener, setFocusTraversalKeys, setFocusTraversalPolicy, setFont, transferFocusBackward, transferFocusDownCycle, validate
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, dispatchEvent, enable, enable, enableInputMethods, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.awt.MenuContainer
getFont, postEvent
 

Field Detail

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.

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.

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

createFileMenu

public JMenu createFileMenu()
Specified by:
createFileMenu in interface org.nlogo.swing.JMenuBarFactory

createToolsMenu

public JMenu createToolsMenu()
Specified by:
createToolsMenu in interface org.nlogo.swing.JMenuBarFactory

createZoomMenu

public JMenu createZoomMenu()
Specified by:
createZoomMenu in interface org.nlogo.swing.JMenuBarFactory

addHelpMenu

public void addHelpMenu(JMenuBar menuBar)
Specified by:
addHelpMenu in interface org.nlogo.swing.JMenuBarFactory

handleAppEvent

public void handleAppEvent(org.nlogo.event.AppEvent e)
Internal use only.

Specified by:
handleAppEvent in interface org.nlogo.event.AppEvent.Handler

handleSwitchedTabsEvent

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

Specified by:
handleSwitchedTabsEvent in interface org.nlogo.app.SwitchedTabsEvent.Handler

handleModelSavedEvent

public void handleModelSavedEvent(org.nlogo.event.ModelSavedEvent e)
Internal use only.

Specified by:
handleModelSavedEvent in interface org.nlogo.event.ModelSavedEvent.Handler

handleLoadBeginEvent

public void handleLoadBeginEvent(org.nlogo.event.LoadBeginEvent e)
Internal use only.

Specified by:
handleLoadBeginEvent in interface org.nlogo.event.LoadBeginEvent.Handler

handleBeforeLoadEvent

public void handleBeforeLoadEvent(org.nlogo.event.BeforeLoadEvent e)
Internal use only.

Specified by:
handleBeforeLoadEvent in interface org.nlogo.event.BeforeLoadEvent.Handler

handleLoadEndEvent

public void handleLoadEndEvent(org.nlogo.event.LoadEndEvent e)
Internal use only.

Specified by:
handleLoadEndEvent in interface org.nlogo.event.LoadEndEvent.Handler

requestFocus

public void requestFocus()
Internal use only.


handle

public void handle(Throwable throwable)
Internal use only.

Specified by:
handle in interface org.nlogo.util.ExceptionsHandler

open

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

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 org.nlogo.workspace.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 org.nlogo.workspace.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

resizeWorld

public void resizeWorld(int screenEdgeX,
                        int screenEdgeY)
Kills all turtles, clears all patch variables, and makes a new patch grid. Note that the dimensions given are screen "edges", not screen "sizes", so for example calling resizeWorld(10,10) will result in a 21x21 grid.

Parameters:
screenEdgeX - new value for screen-edge-x
screenEdgeY - new value for screen-edge-y

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

addLinkComponent

public void addLinkComponent(Object c)
Internal use only.


getLinkComponents

public Object[] getLinkComponents()
Internal use only.

Specified by:
getLinkComponents in interface org.nlogo.event.EventLinkContainer

NetLogo API
version 3.0.2