java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
org.nlogo.lite.AppletPanel
org.nlogo.lite.InterfaceComponent
public class InterfaceComponent
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.
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 java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public org.nlogo.log.Logger logger
Constructor Detail |
---|
public InterfaceComponent(Frame frame)
Method Detail |
---|
public Object getLinkParent()
getLinkParent
in interface org.nlogo.window.Event.LinkChild
public URL getFileURL(String filename)
getFileURL
in class AppletPanel
public void compile()
setProcedures()
.
AppletPanel.setProcedures(java.lang.String)
public void makeWidget(String text)
text
- the widget specificationpublic void hideWidget(String name)
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.
name
- the display name of the widget to hide.hideWidget(java.lang.String)
public void showWidget(String name)
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.
name
- the display name of the widget to reveal.hideWidget(java.lang.String)
public void open(String path) throws IOException, org.nlogo.window.InvalidVersionException
path
- the path (absolute or relative) of the NetLogo model to open.
IOException
org.nlogo.window.InvalidVersionException
public void startLogging(String properties, String username)
properties
- path to the XML properties file as defined by the log4j dtdusername
- user defined username, this should be a unique identifierpublic void startLogging(Reader reader, String username)
reader
- a reader that contains an XML properties file as defined by the log4j dtdusername
- user defined username, this should be a unique identifierpublic void createLogger(String username)
public void pressButton(String name)
public org.nlogo.window.Widget findWidget(String name, Class<?> type)
public RenderedImage getViewImage()
public void exportWorld(PrintWriter writer)
writer
- to writer the contents of the export world
featurepublic RenderedImage getPlotContentsAsImage(String name)
name
- the display name of the widget to reveal.public void reportAndCallback(String code, InterfaceComponent.InvocationListener handler)
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.