java.lang.Objectorg.nlogo.workspace.AbstractWorkspace
org.nlogo.headless.HeadlessWorkspace
public class HeadlessWorkspace
The primary class for headless (no GUI) operation of NetLogo.
You may create more than one HeadlessWorkspace object. Multiple instances can operate separately and independently. (Behind the scenes, this is supported by creating a separate thread for each instance.)
When you are done using a HeadlessWorkspace, you should call its dispose() method. This will shut down the thread associated with the workspace and allow resources to be freed.
See the "Controlling" section of the NetLogo User Manual for example code.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class org.nlogo.workspace.AbstractWorkspace |
|---|
AbstractWorkspace.HubNetManagerFactory |
| Nested classes/interfaces inherited from interface org.nlogo.nvm.Workspace |
|---|
Workspace.BehaviorSpaceFormat, Workspace.OutputDestination, Workspace.UpdateMode |
| Field Summary | |
|---|---|
LogoException |
lastLogoException
Internal use only. |
boolean |
modelOpened
Has a model been opened in this workspace? |
StringBuilder |
outputAreaBuffer
|
static String |
TEST_DECLARATIONS
Internal use only. |
| Fields inherited from class org.nlogo.workspace.AbstractWorkspace |
|---|
codeBits, DEFAULT_PREVIEW_COMMANDS, jobManager, previewCommands, world |
| Constructor Summary | |
|---|---|
HeadlessWorkspace(World world,
CompilerInterface compiler,
RendererInterface renderer,
org.nlogo.api.AggregateManagerInterface aggregateManager)
Internal use only. |
|
| Method Summary | ||
|---|---|---|
org.nlogo.api.AggregateManagerInterface |
aggregateManager()
|
|
int |
calculateHeight(int worldHeight,
double patchSize)
|
|
int |
calculateWidth(int worldWidth,
double patchSize)
|
|
void |
changeTopology(boolean wrapX,
boolean wrapY)
|
|
void |
clearDrawing()
|
|
void |
clearLastLogoException()
Internal use only. |
|
void |
clearOutput()
Internal use only. |
|
void |
clearTurtles()
|
|
void |
command(String source)
Runs NetLogo commands and waits for them to complete. |
|
CompilerInterface |
compiler()
|
|
double |
computePatchSize(int width,
int numPatches)
|
|
void |
createPatchesNotify()
Internal use only. |
|
void |
deleteLogFiles()
Internal use only. |
|
boolean |
drawSpotlight()
|
|
void |
exportDrawing(String filename,
String format)
|
|
void |
exportDrawingToCSV(PrintWriter writer)
|
|
void |
exportInterface(String filename)
Not implemented. |
|
void |
exportOutput(String filename)
|
|
void |
exportOutputAreaToCSV(PrintWriter writer)
|
|
BufferedImage |
exportView()
Get a snapshot of the 2D view. |
|
void |
exportView(String filename,
String format)
|
|
int |
fontSize()
|
|
void |
fontSize(int fontSize)
|
|
BufferedImage |
getAndCreateDrawing()
|
|
void |
getGraphics(BufferedImage image)
Get a snapshot of the 2D view, using an existing BufferedImage object. |
|
int |
getHeight()
|
|
int |
getMinimumWidth()
|
|
int |
getWidth()
|
|
void |
halt()
Halts all running NetLogo code in this workspace. |
|
void |
importDrawing(File file)
|
|
void |
initForTesting(int worldSize)
Internal use only. |
|
void |
initForTesting(int minPxcor,
int maxPxcor,
int minPycor,
int maxPycor)
|
|
void |
initForTesting(int minPxcor,
int maxPxcor,
int minPycor,
int maxPycor,
String source)
Internal use only. |
|
void |
initForTesting(int worldSize,
String modelString)
Internal use only. |
|
void |
initForTesting(WorldDimensions d)
Internal use only. |
|
void |
initForTesting(WorldDimensions d,
String source)
Internal use only. |
|
int |
insetWidth()
|
|
void |
inspectAgent(Agent agent,
double radius)
Internal use only. |
|
void |
inspectAgent(Class<? extends Agent> agentClass,
Agent agent,
double radius)
Internal use only. |
|
boolean |
isCompilerTestingMode()
Internal use only. |
|
boolean |
isHeadless()
Internal use only. |
|
LogoException |
lastLogoException()
Internal use only. |
|
void |
magicOpen(String name)
Internal use only. |
|
static HeadlessWorkspace |
newInstance()
Makes a new instance of NetLogo capable of running a model "headless", with no GUI. |
|
static HeadlessWorkspace |
newInstance(Class<? extends HeadlessWorkspace> subclass)
If you derive your own subclass of HeadlessWorkspace, you can use this method to instantiate it. |
|
static org.nlogo.nvm.LabInterface |
newLab()
|
|
void |
open(String path)
Opens a model stored in a file. |
|
void |
openFromSource(String source)
Opens a model stored in a string. |
|
void |
openIndex()
Internal use only. |
|
void |
openNext()
Internal use only. |
|
void |
openPrevious()
Internal use only. |
|
void |
openString(String modelContents)
Opens a model stored in a string |
|
void |
ownerFinished(JobOwner owner)
Internal use only. |
|
void |
paint(Graphics2D g)
Internal use only. |
|
double |
patchSize()
|
|
void |
patchSize(double patchSize)
|
|
void |
perhapsUpdateDisplay()
Internal use only. |
|
void |
periodicUpdate()
Internal use only. |
|
Perspective |
perspective()
|
|
RendererInterface |
renderer()
|
|
boolean |
renderPerspective()
|
|
Object |
report(String source)
Runs a NetLogo reporter. |
|
void |
requestDisplayUpdate(boolean force)
Internal use only. |
|
void |
resizeView()
|
|
void |
runtimeError(JobOwner owner,
Context context,
Instruction instruction,
Exception ex)
Internal use only. |
|
void |
setCompilerTestingMode(boolean testing)
Internal use only. |
|
void |
setDimensions(WorldDimensions d)
Kills all turtles, clears all patch variables, and makes a new patch grid. |
|
void |
setDimensions(WorldDimensions d,
double patchSize)
|
|
void |
setImporterErrorHandler(Importer.ErrorHandler importErrorHandler)
Internal use only. |
|
void |
setSize(int x,
int y)
|
|
boolean |
showTickCounter()
|
|
void |
showTickCounter(boolean visible)
|
|
void |
startLogging(String properties)
Internal use only. |
|
String |
tickCounterLabel()
|
|
void |
tickCounterLabel(String label)
|
|
void |
updateDisplay(boolean haveWorldLockAlready)
Internal use only. |
|
void |
updateMode(Workspace.UpdateMode updateMode)
|
|
double |
viewHeight()
|
|
double |
viewOffsetX()
|
|
double |
viewOffsetY()
|
|
double |
viewWidth()
|
|
void |
waitFor(CommandRunnable runnable)
Internal use only. |
|
void |
waitForQueuedEvents()
Internal use only. |
|
|
waitForResult(ReporterRunnable<T> runnable)
Internal use only. |
|
void |
writeGraphicsData(PrintWriter writer)
|
|
void |
zipLogFiles(String filename)
Internal use only. |
|
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public boolean modelOpened
public final StringBuilder outputAreaBuffer
public static final String TEST_DECLARATIONS
public LogoException lastLogoException
| Constructor Detail |
|---|
public HeadlessWorkspace(World world,
CompilerInterface compiler,
RendererInterface renderer,
org.nlogo.api.AggregateManagerInterface aggregateManager)
| Method Detail |
|---|
public static HeadlessWorkspace newInstance()
public static HeadlessWorkspace newInstance(Class<? extends HeadlessWorkspace> subclass)
public static org.nlogo.nvm.LabInterface newLab()
public org.nlogo.api.AggregateManagerInterface aggregateManager()
aggregateManager in interface Workspacepublic RendererInterface renderer()
public CompilerInterface compiler()
compiler in interface Workspacecompiler in class AbstractWorkspacepublic boolean isHeadless()
isHeadless in interface ViewSettingsisHeadless in interface WorkspaceisHeadless in class AbstractWorkspacepublic void setCompilerTestingMode(boolean testing)
public boolean isCompilerTestingMode()
isCompilerTestingMode in class AbstractWorkspace
public void waitFor(CommandRunnable runnable)
throws LogoException
waitFor in interface WorkspaceLogoException
public <T> T waitForResult(ReporterRunnable<T> runnable)
throws LogoException
waitForResult in interface WorkspaceLogoExceptionpublic void waitForQueuedEvents()
waitForQueuedEvents in interface Workspace
public void initForTesting(int worldSize)
throws CompilerException
CompilerException
public void initForTesting(int worldSize,
String modelString)
throws CompilerException
CompilerException
public void initForTesting(int minPxcor,
int maxPxcor,
int minPycor,
int maxPycor,
String source)
throws CompilerException
CompilerException
public void initForTesting(WorldDimensions d,
String source)
throws CompilerException
CompilerException
public void initForTesting(int minPxcor,
int maxPxcor,
int minPycor,
int maxPycor)
public void initForTesting(WorldDimensions d)
public void setDimensions(WorldDimensions d)
setDimensions in interface WorldResizer
public void setDimensions(WorldDimensions d,
double patchSize)
setDimensions in interface WorldResizersetDimensions in interface WorldLoaderInterfacepublic int getMinimumWidth()
getMinimumWidth in interface WorldLoaderInterfacepublic int insetWidth()
insetWidth in interface WorldLoaderInterface
public double computePatchSize(int width,
int numPatches)
computePatchSize in interface WorldLoaderInterface
public int calculateHeight(int worldHeight,
double patchSize)
calculateHeight in interface WorldLoaderInterface
public int calculateWidth(int worldWidth,
double patchSize)
calculateWidth in interface WorldLoaderInterfacepublic void resizeView()
resizeView in interface WorldResizerpublic void tickCounterLabel(String label)
tickCounterLabel in interface WorldLoaderInterfacepublic String tickCounterLabel()
tickCounterLabel in interface WorldLoaderInterfacepublic void showTickCounter(boolean visible)
showTickCounter in interface WorldLoaderInterfacepublic boolean showTickCounter()
showTickCounter in interface WorldLoaderInterfacepublic int getWidth()
public int getHeight()
public double viewWidth()
viewWidth in interface ViewSettingspublic double viewHeight()
viewHeight in interface ViewSettingspublic void patchSize(double patchSize)
patchSize in interface WorldResizerpatchSize in interface WorldLoaderInterfacepublic double patchSize()
patchSize in interface ViewSettingspatchSize in interface Workspace
public void changeTopology(boolean wrapX,
boolean wrapY)
changeTopology in interface WorkspacechangeTopology in interface WorldLoaderInterfacepublic Perspective perspective()
perspective in interface ViewSettingspublic boolean drawSpotlight()
drawSpotlight in interface ViewSettingspublic boolean renderPerspective()
renderPerspective in interface ViewSettingspublic double viewOffsetX()
viewOffsetX in interface ViewSettingspublic double viewOffsetY()
viewOffsetY in interface ViewSettingspublic void updateMode(Workspace.UpdateMode updateMode)
updateMode in interface WorldLoaderInterfaceupdateMode in class AbstractWorkspacepublic int fontSize()
fontSize in interface ViewSettingspublic void fontSize(int fontSize)
fontSize in interface WorldLoaderInterface
public void setSize(int x,
int y)
setSize in interface WorldLoaderInterfacepublic void clearTurtles()
clearTurtles in interface WorldLoaderInterfacepublic void createPatchesNotify()
public void inspectAgent(Agent agent,
double radius)
inspectAgent in interface Workspace
public void inspectAgent(Class<? extends Agent> agentClass,
Agent agent,
double radius)
inspectAgent in interface Workspacepublic BufferedImage getAndCreateDrawing()
getAndCreateDrawing in interface Workspace
public void importDrawing(File file)
throws IOException
IOExceptionpublic void clearDrawing()
clearDrawing in interface WorkspaceclearDrawing in class AbstractWorkspace
public void exportDrawing(String filename,
String format)
throws IOException
exportDrawing in interface WorkspaceIOExceptionpublic void exportDrawingToCSV(PrintWriter writer)
exportDrawingToCSV in class AbstractWorkspacepublic void exportOutput(String filename)
exportOutput in interface Workspacepublic void exportOutputAreaToCSV(PrintWriter writer)
exportOutputAreaToCSV in class AbstractWorkspacepublic void clearOutput()
clearOutput in interface Workspacepublic void setImporterErrorHandler(Importer.ErrorHandler importErrorHandler)
public BufferedImage exportView()
exportView in interface Workspacepublic void getGraphics(BufferedImage image)
public void paint(Graphics2D g)
public void exportView(String filename,
String format)
throws IOException
exportView in interface WorkspaceIOExceptionpublic void exportInterface(String filename)
exportInterface in interface Workspacepublic void writeGraphicsData(PrintWriter writer)
writeGraphicsData in class AbstractWorkspacepublic void ownerFinished(JobOwner owner)
ownerFinished in interface JobManagerOwnerpublic void updateDisplay(boolean haveWorldLockAlready)
updateDisplay in interface JobManagerOwnerpublic void requestDisplayUpdate(boolean force)
requestDisplayUpdate in interface WorkspacerequestDisplayUpdate in class AbstractWorkspacepublic void perhapsUpdateDisplay()
perhapsUpdateDisplay in interface WorkspaceperhapsUpdateDisplay in class AbstractWorkspacepublic void periodicUpdate()
periodicUpdate in interface JobManagerOwnerpublic void magicOpen(String name)
magicOpen in interface WorkspacemagicOpen in class AbstractWorkspacepublic void openIndex()
openIndex in interface Workspacepublic void openNext()
openNext in interface Workspacepublic void openPrevious()
openPrevious in interface Workspacepublic void startLogging(String properties)
startLogging in interface Workspacepublic void zipLogFiles(String filename)
zipLogFiles in interface Workspacepublic void deleteLogFiles()
deleteLogFiles in interface Workspacepublic LogoException lastLogoException()
lastLogoException in interface WorkspacelastLogoException in class AbstractWorkspacepublic void clearLastLogoException()
clearLastLogoException in interface WorkspaceclearLastLogoException in class AbstractWorkspace
public void runtimeError(JobOwner owner,
Context context,
Instruction instruction,
Exception ex)
runtimeError in interface JobManagerOwner
public void open(String path)
throws IOException,
CompilerException,
LogoException
open in interface Workspaceopen in interface Controllableopen in class AbstractWorkspacepath - the path (absolute or relative) of the NetLogo model to open.
IOException
CompilerException
LogoException
public void openString(String modelContents)
throws CompilerException,
LogoException
openString in interface WorkspaceopenString in class AbstractWorkspacemodelContents -
CompilerException
LogoException
public void openFromSource(String source)
throws CompilerException,
LogoException
source - The complete model, including widgets and so forth,
in the same format as it would be stored in a file.
CompilerException
LogoException
public void command(String source)
throws CompilerException,
LogoException
command in interface Controllablesource - The command or commands to run
CompilerException - if the code fails to compile
LogoException - if the code fails to run
public Object report(String source)
throws CompilerException,
LogoException
report in interface Controllablesource - The reporter to run
LogoList,
Agent, AgentSet, or Nobody
CompilerException - if the code fails to compile
LogoException - if the code fails to runpublic void halt()
halt in class AbstractWorkspace