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 Workspace
public RendererInterface renderer()
public CompilerInterface compiler()
compiler
in interface Workspace
compiler
in class AbstractWorkspace
public boolean isHeadless()
isHeadless
in interface ViewSettings
isHeadless
in interface Workspace
isHeadless
in class AbstractWorkspace
public void setCompilerTestingMode(boolean testing)
public boolean isCompilerTestingMode()
isCompilerTestingMode
in class AbstractWorkspace
public void waitFor(CommandRunnable runnable) throws LogoException
waitFor
in interface Workspace
LogoException
public <T> T waitForResult(ReporterRunnable<T> runnable) throws LogoException
waitForResult
in interface Workspace
LogoException
public 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 WorldResizer
setDimensions
in interface WorldLoaderInterface
public int getMinimumWidth()
getMinimumWidth
in interface WorldLoaderInterface
public 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 WorldLoaderInterface
public void resizeView()
resizeView
in interface WorldResizer
public void tickCounterLabel(String label)
tickCounterLabel
in interface WorldLoaderInterface
public String tickCounterLabel()
tickCounterLabel
in interface WorldLoaderInterface
public void showTickCounter(boolean visible)
showTickCounter
in interface WorldLoaderInterface
public boolean showTickCounter()
showTickCounter
in interface WorldLoaderInterface
public int getWidth()
public int getHeight()
public double viewWidth()
viewWidth
in interface ViewSettings
public double viewHeight()
viewHeight
in interface ViewSettings
public void patchSize(double patchSize)
patchSize
in interface WorldResizer
patchSize
in interface WorldLoaderInterface
public double patchSize()
patchSize
in interface ViewSettings
patchSize
in interface Workspace
public void changeTopology(boolean wrapX, boolean wrapY)
changeTopology
in interface Workspace
changeTopology
in interface WorldLoaderInterface
public Perspective perspective()
perspective
in interface ViewSettings
public boolean drawSpotlight()
drawSpotlight
in interface ViewSettings
public boolean renderPerspective()
renderPerspective
in interface ViewSettings
public double viewOffsetX()
viewOffsetX
in interface ViewSettings
public double viewOffsetY()
viewOffsetY
in interface ViewSettings
public void updateMode(Workspace.UpdateMode updateMode)
updateMode
in interface WorldLoaderInterface
updateMode
in class AbstractWorkspace
public int fontSize()
fontSize
in interface ViewSettings
public void fontSize(int fontSize)
fontSize
in interface WorldLoaderInterface
public void setSize(int x, int y)
setSize
in interface WorldLoaderInterface
public void clearTurtles()
clearTurtles
in interface WorldLoaderInterface
public 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 Workspace
public BufferedImage getAndCreateDrawing()
getAndCreateDrawing
in interface Workspace
public void importDrawing(File file) throws IOException
IOException
public void clearDrawing()
clearDrawing
in interface Workspace
clearDrawing
in class AbstractWorkspace
public void exportDrawing(String filename, String format) throws IOException
exportDrawing
in interface Workspace
IOException
public void exportDrawingToCSV(PrintWriter writer)
exportDrawingToCSV
in class AbstractWorkspace
public void exportOutput(String filename)
exportOutput
in interface Workspace
public void exportOutputAreaToCSV(PrintWriter writer)
exportOutputAreaToCSV
in class AbstractWorkspace
public void clearOutput()
clearOutput
in interface Workspace
public void setImporterErrorHandler(Importer.ErrorHandler importErrorHandler)
public BufferedImage exportView()
exportView
in interface Workspace
public void getGraphics(BufferedImage image)
public void paint(Graphics2D g)
public void exportView(String filename, String format) throws IOException
exportView
in interface Workspace
IOException
public void exportInterface(String filename)
exportInterface
in interface Workspace
public void writeGraphicsData(PrintWriter writer)
writeGraphicsData
in class AbstractWorkspace
public void ownerFinished(JobOwner owner)
ownerFinished
in interface JobManagerOwner
public void updateDisplay(boolean haveWorldLockAlready)
updateDisplay
in interface JobManagerOwner
public void requestDisplayUpdate(boolean force)
requestDisplayUpdate
in interface Workspace
requestDisplayUpdate
in class AbstractWorkspace
public void perhapsUpdateDisplay()
perhapsUpdateDisplay
in interface Workspace
perhapsUpdateDisplay
in class AbstractWorkspace
public void periodicUpdate()
periodicUpdate
in interface JobManagerOwner
public void magicOpen(String name)
magicOpen
in interface Workspace
magicOpen
in class AbstractWorkspace
public void openIndex()
openIndex
in interface Workspace
public void openNext()
openNext
in interface Workspace
public void openPrevious()
openPrevious
in interface Workspace
public void startLogging(String properties)
startLogging
in interface Workspace
public void zipLogFiles(String filename)
zipLogFiles
in interface Workspace
public void deleteLogFiles()
deleteLogFiles
in interface Workspace
public LogoException lastLogoException()
lastLogoException
in interface Workspace
lastLogoException
in class AbstractWorkspace
public void clearLastLogoException()
clearLastLogoException
in interface Workspace
clearLastLogoException
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 Workspace
open
in interface Controllable
open
in class AbstractWorkspace
path
- 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 Workspace
openString
in class AbstractWorkspace
modelContents
-
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 Controllable
source
- The command or commands to run
CompilerException
- if the code fails to compile
LogoException
- if the code fails to runpublic Object report(String source) throws CompilerException, LogoException
report
in interface Controllable
source
- 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