org.nlogo.app
Class App

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Window
              extended by java.awt.Frame
                  extended by javax.swing.JFrame
                      extended by org.nlogo.app.App
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, RootPaneContainer, WindowConstants, org.nlogo.app.SwitchedTabsEvent.Handler, org.nlogo.event.AboutToQuitEvent.Handler, org.nlogo.event.AppEvent.Handler, org.nlogo.event.BeforeLoadEvent.Handler, org.nlogo.event.CompileAllEvent.Raiser, org.nlogo.event.Event.Handler, org.nlogo.event.EventLinkContainer, org.nlogo.event.IconifiedEvent.Raiser, org.nlogo.event.LoadBeginEvent.Handler, org.nlogo.event.LoadEndEvent.Handler, org.nlogo.event.LoadSectionEvent.Handler, org.nlogo.event.ModelSavedEvent.Handler, org.nlogo.event.ZoomedEvent.Raiser, org.nlogo.swing.MenuBarFactory, org.nlogo.util.ExceptionsHandler, org.nlogo.window.ExternalFileManager, Controllable

public final class App
extends JFrame
implements org.nlogo.swing.MenuBarFactory, org.nlogo.util.ExceptionsHandler, org.nlogo.event.EventLinkContainer, org.nlogo.window.ExternalFileManager, 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.LoadSectionEvent.Handler, org.nlogo.event.LoadEndEvent.Handler, org.nlogo.event.ModelSavedEvent.Handler, org.nlogo.app.SwitchedTabsEvent.Handler, org.nlogo.event.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.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.awt.Component
Component.BaselineResizeBehavior
 
Field Summary
static App app
          Once main() has been called, holds the singleton instance of this class.
 org.nlogo.shapes.editor.ManagerDialog linkShapesManager
           
 org.nlogo.shapes.editor.ManagerDialog turtleShapesManager
           
 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
 JMenu 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 createEditMenu()
           
 JMenu createFileMenu()
           
 JMenu createToolsMenu()
           
 JMenu createZoomMenu()
           
 Object[] getLinkComponents()
          Internal use only.
 String getProcedures()
          Returns the contents of the Procedures tab.
 String getSource(String filename)
           
 void handle(Throwable throwable)
          Internal use only.
 void handleAboutToQuitEvent(org.nlogo.event.AboutToQuitEvent e)
           
 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 handleLoadSectionEvent(org.nlogo.event.LoadSectionEvent e)
           
 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.
 void quit()
          Quits NetLogo by exiting the JVM.
 Object report(String source)
          Runs a NetLogo reporter.
 void requestFocus()
          Internal use only.
 void resizeWorld(int minPxcor, int maxPxcor, int minPycor, int maxPycor)
          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, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, isDefaultLookAndFeelDecorated, remove, repaint, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setIconImage, setJMenuBar, setLayeredPane, setLayout, setTransferHandler, update
 
Methods inherited from class java.awt.Frame
addNotify, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, remove, removeNotify, setCursor, setExtendedState, 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, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOwnedWindows, getOwner, getOwnerlessWindows, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, hide, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isShowing, pack, postEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImages, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, setVisible, 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, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, 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, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, 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, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, 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, requestFocusInWindow, resize, resize, setBackground, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setName, setPreferredSize, 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.


turtleShapesManager

public org.nlogo.shapes.editor.ManagerDialog turtleShapesManager

linkShapesManager

public org.nlogo.shapes.editor.ManagerDialog linkShapesManager
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.util.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.util.UserCancelException

createFileMenu

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

createEditMenu

public JMenu createEditMenu()
Specified by:
createEditMenu in interface org.nlogo.swing.MenuBarFactory

createToolsMenu

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

createZoomMenu

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

addHelpMenu

public JMenu addHelpMenu(JMenuBar menuBar)
Specified by:
addHelpMenu in interface org.nlogo.swing.MenuBarFactory

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

handleAboutToQuitEvent

public void handleAboutToQuitEvent(org.nlogo.event.AboutToQuitEvent e)
Specified by:
handleAboutToQuitEvent in interface org.nlogo.event.AboutToQuitEvent.Handler

requestFocus

public void requestFocus()
Internal use only.

Overrides:
requestFocus in class Component

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.

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

resizeWorld

public void resizeWorld(int minPxcor,
                        int maxPxcor,
                        int minPycor,
                        int maxPycor)
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:
minPxcor - new value for min-pxcor
maxPxcor - new value for max-pxcor
minPycor - new value for min-pycor
maxPycor - new value for max-pycor

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

handleLoadSectionEvent

public void handleLoadSectionEvent(org.nlogo.event.LoadSectionEvent e)
Specified by:
handleLoadSectionEvent in interface org.nlogo.event.LoadSectionEvent.Handler

getSource

public String getSource(String filename)
Specified by:
getSource in interface org.nlogo.window.ExternalFileManager

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