org.nlogo.lite
Class InterfaceComponent

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by org.nlogo.lite.AppletPanel
                      extended by org.nlogo.lite.InterfaceComponent
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, org.nlogo.util.Exceptions.Handler, org.nlogo.window.Event.LinkChild, org.nlogo.window.Event.LinkParent

public class InterfaceComponent
extends AppletPanel
implements org.nlogo.window.Event.LinkChild

This component is a wrapper around the contents of the interface panel that can be embedded in another application. Once created, an InterfaceComponent can't be garbage collected, so you should open successive models in the same InterfaceComponent, rather than making new instances.

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

See Also:
Serialized Form

Nested Class Summary
static interface InterfaceComponent.InvocationListener
          Callback interface used by reportAndCallback().
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Component
Component.BaselineResizeBehavior
 
Field Summary
 org.nlogo.log.Logger logger
           
 
Fields inherited from class org.nlogo.lite.AppletPanel
aggregateManager, iP, linkComponents, listenerManager, panel, procedures, workspace
 
Fields inherited from class javax.swing.JComponent
TOOL_TIP_TEXT_KEY, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
InterfaceComponent(Frame frame)
           
 
Method Summary
 void compile()
          Recompiles the model.
 void createLogger(String username)
           
 void exportWorld(PrintWriter writer)
           
 org.nlogo.window.Widget findWidget(String name, Class<?> type)
           
 URL getFileURL(String filename)
          internal use only
 Object getLinkParent()
          internal use only
 RenderedImage getPlotContentsAsImage(String name)
          returns a graphical image of the current contents of the plot with the given name.
 RenderedImage getViewImage()
          returns the current contents of the NetLogo Graphics Window.
 void hideWidget(String name)
          hides a particular widget.
 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 pressButton(String name)
          Simulates a button press in the current model, exactly as if the user had pressed the button.
 void reportAndCallback(String code, InterfaceComponent.InvocationListener handler)
          evaluates a reporter and return the value to continuation object.
 void showWidget(String name)
          reveals a particular widget.
 void startLogging(Reader reader, String username)
          Starts NetLogo logging using the given file and username
 void startLogging(String properties, String username)
          Starts NetLogo logging using the given file and username
 
Methods inherited from class org.nlogo.lite.AppletPanel
addLinkComponent, command, commandLater, getLinkChildren, getProcedures, handle, main, openFromSource, report, requestFocus, setAdVisible, setPrefix, setProcedures, toURL
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, 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, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

logger

public org.nlogo.log.Logger logger
Constructor Detail

InterfaceComponent

public InterfaceComponent(Frame frame)
Method Detail

getLinkParent

public Object getLinkParent()
internal use only

Specified by:
getLinkParent in interface org.nlogo.window.Event.LinkChild

getFileURL

public URL getFileURL(String filename)
internal use only

Specified by:
getFileURL in class AppletPanel

compile

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

See Also:
AppletPanel.setProcedures(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

hideWidget

public void hideWidget(String name)
hides a particular widget. This method makes the specified widget invisible in the NetLogo interface panel. It does not completely remove the widget, which can later be brought back with showWidget(). This method uses the "display name" to identify the widget. Display names are not necessarily unique within a particular model. It is only safe to use this method on widgets with unique display names. Otherwise the behavior is unspecified.

Parameters:
name - the display name of the widget to hide.
See Also:
hideWidget(java.lang.String)

showWidget

public void showWidget(String name)
reveals a particular widget. This method makes the specified widget visible in the NetLogo interface panel, if it has previously been hidden by a call to hideWidget(). This method uses the "display name" to identify the widget. Display names are not necessarily unique within a particular model. It is only safe to use this method on widgets with unique display names. Otherwise the behavior is unspecified.

Parameters:
name - the display name of the widget to reveal.
See Also:
hideWidget(java.lang.String)

open

public void open(String path)
          throws IOException,
                 org.nlogo.window.InvalidVersionException
Opens a model stored in a file.

Parameters:
path - the path (absolute or relative) of the NetLogo model to open.
Throws:
IOException
org.nlogo.window.InvalidVersionException

startLogging

public void startLogging(String properties,
                         String username)
Starts NetLogo logging using the given file and username

Parameters:
properties - path to the XML properties file as defined by the log4j dtd
username - user defined username, this should be a unique identifier

startLogging

public void startLogging(Reader reader,
                         String username)
Starts NetLogo logging using the given file and username

Parameters:
reader - a reader that contains an XML properties file as defined by the log4j dtd
username - user defined username, this should be a unique identifier

createLogger

public void createLogger(String username)

pressButton

public void pressButton(String name)
Simulates a button press in the current model, exactly as if the user had pressed the button. If the button is a "once" button, this method does not return until the button has popped back up. (For "forever" buttons, it returns immediately.)


findWidget

public org.nlogo.window.Widget findWidget(String name,
                                          Class<?> type)

getViewImage

public RenderedImage getViewImage()
returns the current contents of the NetLogo Graphics Window. This image can be saved to disk, displayed to the user later, etc.


exportWorld

public void exportWorld(PrintWriter writer)
Parameters:
writer - to writer the contents of the export world feature

getPlotContentsAsImage

public RenderedImage getPlotContentsAsImage(String name)
returns a graphical image of the current contents of the plot with the given name. This image can be saved to disk, displayed to the user later, etc.

Parameters:
name - the display name of the widget to reveal.

reportAndCallback

public void reportAndCallback(String code,
                              InterfaceComponent.InvocationListener handler)
evaluates a reporter and return the value to continuation object. This is a convenience method for evaluating reporters on the event thread. Since it is an error to call report() from the event thread, this method creates a new thread to call report() and then passes the result to the given InvocationListener.

This method may be called from any thread, including the AWT Event Thread.