org.nlogo.workspace
Class AbstractWorkspace

java.lang.Object
  extended by org.nlogo.workspace.AbstractWorkspace
All Implemented Interfaces:
Evaluator, org.nlogo.api.CompilerServices, HubNetWorkspaceInterface, ImporterUser, RandomServices, WorldResizer, JobManagerOwner, Workspace
Direct Known Subclasses:
DummyAbstractWorkspace, HeadlessWorkspace

public abstract class AbstractWorkspace
extends Object
implements Workspace, Evaluator, HubNetWorkspaceInterface


Nested Class Summary
static interface AbstractWorkspace.HubNetManagerFactory
           
 
Nested classes/interfaces inherited from interface org.nlogo.nvm.Workspace
Workspace.BehaviorSpaceFormat, Workspace.OutputDestination, Workspace.UpdateMode
 
Field Summary
 WeakHashMap<String,Procedure> codeBits
           
static String DEFAULT_PREVIEW_COMMANDS
          previewCommands used by make-preview and model test
 JobManagerInterface jobManager
           
 String previewCommands
           
 World world
           
 
Method Summary
 void addJobFromJobThread(Job job)
           
 String attachModelDir(String filePath)
          attaches the current model directory to a relative path, if necessary.
 String autoConvert(String source, boolean subprogram, boolean reporter, String modelVersion)
           
 org.nlogo.util.MersenneTwisterFast auxRNG()
           
 int behaviorSpaceRunNumber()
           
 void behaviorSpaceRunNumber(int n)
           
 void checkCommandSyntax(String source)
           
 void checkReporterSyntax(String source)
           
 void clearAll()
           
abstract  void clearDrawing()
           
 void clearLastLogoException()
           
 Procedure compileCommands(String source)
           
 Procedure compileCommands(String source, Class<? extends Agent> agentClass)
           
 Procedure compileForRun(String source, Context context, boolean reporter)
           
abstract  CompilerInterface compiler()
           
 Procedure compileReporter(String source)
           
 boolean computerHubNetRunning()
           
 void computerHubNetRunning(boolean computerHubNetRunning)
           
 void convertToNormal()
          instantly converts the current model to ModelType.NORMAL.
 void currentPlot(String plot)
           
 void dispose()
          Shuts down the background thread associated with this workspace, allowing resources to be freed.
 void evaluateCommands(String source)
           
 void evaluateCommands(String source, Agent agent, boolean waitForCompletion)
           
 void evaluateCommands(String source, Class<? extends Agent> agentClass, boolean waitForCompletion)
           
 Object evaluateReporter(String source)
           
 Object evaluateReporter(String source, Agent agent)
           
 void exportAllPlots(String filename)
           
 File exportBehaviors(String filename, String experimentName, boolean includeHeader)
           
abstract  void exportDrawingToCSV(PrintWriter writer)
           
abstract  void exportOutputAreaToCSV(PrintWriter writer)
           
 void exportPlot(String plotName, String filename)
           
 void exportWorld(PrintWriter writer)
           
 void exportWorld(String filename)
           
 FileManager fileManager()
           
 Map<String,List<Object>> findProcedurePositions(String source)
           
 boolean forceSaveAs()
          whether the user needs to enter a new filename to save this model.
 ExtensionManager getExtensionManager()
           
 HubNetInterface getHubNetManager()
           
 boolean getIsApplet()
           
 String getModelDir()
          returns the full path to the directory from which the current model was loaded.
 String getModelFileName()
          returns the name of the file from which the current model was loaded.
 String getModelPath()
          returns the full pathname of the currently loaded model, if any.
 ModelType getModelType()
           
 PlotInterface getPlot(String plot)
           
 Map<String,Procedure> getProcedures()
           
 WorldPropertiesInterface getPropertiesInterface()
           
 String getSource(String filename)
           
 org.nlogo.api.Token getTokenAtPosition(String s, int pos)
           
 String guessExportName(String defaultName)
           
 void halt()
           
 HubNetInterface hubnetManager()
           
 void importDrawing(String filename)
           
 void importExtensionData(String name, List<String[]> data, ImportErrorHandler handler)
           
 void importWorld(String filename)
           
 void init()
           
static boolean isApp()
           
static void isApp(boolean isApp)
           
static boolean isApplet()
           
static void isApplet(boolean isApplet)
           
 boolean isCompilerTestingMode()
          Internal use only.
 boolean isConstant(String string)
           
 boolean isExtensionName(String name)
           
abstract  boolean isHeadless()
           
 boolean isValidIdentifier(String s)
           
 void joinForeverButtons(Agent agent)
           
 LogoException lastLogoException()
           
 WeakHashMap<Job,WeakHashMap<Agent,WeakHashMap<Command,MutableLong>>> lastRunTimes()
           
 void loadWorld(String[] strings, String version, WorldLoaderInterface worldInterface)
           
abstract  void magicOpen(String name)
           
 org.nlogo.util.MersenneTwisterFast mainRNG()
           
 Thunk makeThunk(String source, Agent agent, Object owner)
           
 String modelNameForDisplay()
           
abstract  void open(String path)
           
abstract  void openString(String modelContents)
           
 void outputObject(Object object, Object owner, boolean addNewline, boolean readable, Workspace.OutputDestination destination)
           
abstract  void perhapsUpdateDisplay()
           
 org.nlogo.plot.PlotManager plotManager()
           
 Object readFromString(String string)
           
 Object readNumberFromString(String source)
           
abstract  void requestDisplayUpdate(boolean force)
           
 boolean runCompiledCommands(Procedure procedure)
           
 Object runCompiledReporter(Procedure procedure)
           
 Object runCompiledReporter(Procedure procedure, org.nlogo.util.MersenneTwisterFast rng)
           
 void setModelPath(String modelPath)
           
 void setOutputAreaContents(String text)
           
 void setProcedures(Map<String,Procedure> procedures)
           
 org.nlogo.api.Token[] tokenizeForColorization(String s)
           
 Workspace.UpdateMode updateMode()
           
 void updateMode(Workspace.UpdateMode updateMode)
           
 boolean warningMessage(String message)
          Displays a warning to the user, and determine whether to continue.
 World world()
           
abstract  void writeGraphicsData(PrintWriter writer)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.nlogo.nvm.Workspace
aggregateManager, changeTopology, clearOutput, deleteLogFiles, exportDrawing, exportInterface, exportOutput, exportView, exportView, getAndCreateDrawing, inspectAgent, inspectAgent, openIndex, openNext, openPrevious, patchSize, startLogging, waitFor, waitForQueuedEvents, waitForResult, zipLogFiles
 
Methods inherited from interface org.nlogo.api.WorldResizer
patchSize, resizeView, setDimensions, setDimensions
 
Methods inherited from interface org.nlogo.nvm.JobManagerOwner
ownerFinished, periodicUpdate, runtimeError, updateDisplay
 

Field Detail

world

public final World world

jobManager

public final JobManagerInterface jobManager

DEFAULT_PREVIEW_COMMANDS

public static final String DEFAULT_PREVIEW_COMMANDS
previewCommands used by make-preview and model test

See Also:
Constant Field Values

previewCommands

public String previewCommands

codeBits

public WeakHashMap<String,Procedure> codeBits
Method Detail

world

public World world()
Specified by:
world in interface Workspace

fileManager

public FileManager fileManager()
Specified by:
fileManager in interface Workspace

plotManager

public org.nlogo.plot.PlotManager plotManager()
Specified by:
plotManager in interface Workspace

lastRunTimes

public WeakHashMap<Job,WeakHashMap<Agent,WeakHashMap<Command,MutableLong>>> lastRunTimes()
Specified by:
lastRunTimes in interface Workspace

getExtensionManager

public ExtensionManager getExtensionManager()
Specified by:
getExtensionManager in interface Workspace

isExtensionName

public boolean isExtensionName(String name)
Specified by:
isExtensionName in interface ImporterUser

importExtensionData

public void importExtensionData(String name,
                                List<String[]> data,
                                ImportErrorHandler handler)
                         throws ExtensionException
Specified by:
importExtensionData in interface ImporterUser
Throws:
ExtensionException

isCompilerTestingMode

public boolean isCompilerTestingMode()
Internal use only.


dispose

public void dispose()
             throws InterruptedException
Shuts down the background thread associated with this workspace, allowing resources to be freed.

Specified by:
dispose in interface Workspace
Throws:
InterruptedException

isHeadless

public abstract boolean isHeadless()
Specified by:
isHeadless in interface Workspace

warningMessage

public boolean warningMessage(String message)
Displays a warning to the user, and determine whether to continue. The default (non-GUI) implementation is to print the warning and always continue.


isApp

public static boolean isApp()

isApp

public static void isApp(boolean isApp)

isApplet

public static boolean isApplet()

isApplet

public static void isApplet(boolean isApplet)

getIsApplet

public boolean getIsApplet()
Specified by:
getIsApplet in interface Workspace

getHubNetManager

public HubNetInterface getHubNetManager()
Specified by:
getHubNetManager in interface Workspace

hubnetManager

public HubNetInterface hubnetManager()

computerHubNetRunning

public boolean computerHubNetRunning()

computerHubNetRunning

public void computerHubNetRunning(boolean computerHubNetRunning)
Specified by:
computerHubNetRunning in interface HubNetWorkspaceInterface

getPropertiesInterface

public WorldPropertiesInterface getPropertiesInterface()
Specified by:
getPropertiesInterface in interface HubNetWorkspaceInterface

setModelPath

public void setModelPath(String modelPath)
Specified by:
setModelPath in interface Workspace

attachModelDir

public String attachModelDir(String filePath)
                      throws MalformedURLException
attaches the current model directory to a relative path, if necessary. If filePath is an absolute path, this method simply returns it. If it's a relative path, then the current model directory is prepended to it. If this is a new model, the user's platform-dependent home directory is prepended instead.

Specified by:
attachModelDir in interface Workspace
Throws:
MalformedURLException

convertToNormal

public void convertToNormal()
                     throws IOException
instantly converts the current model to ModelType.NORMAL. This is used by the __edit command to enable quick saving of library models. It probably shouldn't be used anywhere else.

Specified by:
convertToNormal in interface Workspace
Throws:
IOException

getModelPath

public String getModelPath()
returns the full pathname of the currently loaded model, if any. This may return null in some cases, for instance if this is a new model.

Specified by:
getModelPath in interface Workspace

getModelFileName

public String getModelFileName()
returns the name of the file from which the current model was loaded. May be null if, for example, this is a new model.

Specified by:
getModelFileName in interface Workspace

getModelDir

public String getModelDir()
returns the full path to the directory from which the current model was loaded. May be null if, for example, this is a new model.

Specified by:
getModelDir in interface Workspace

getModelType

public ModelType getModelType()

forceSaveAs

public boolean forceSaveAs()
whether the user needs to enter a new filename to save this model. We need to do a "save as" if the model is new, from the models library, or converted. Basically, only normal models can get silently saved.


modelNameForDisplay

public String modelNameForDisplay()
Specified by:
modelNameForDisplay in interface HubNetWorkspaceInterface

getProcedures

public Map<String,Procedure> getProcedures()
Specified by:
getProcedures in interface Workspace

setProcedures

public void setProcedures(Map<String,Procedure> procedures)
Specified by:
setProcedures in interface Workspace

init

public void init()

clearAll

public void clearAll()
Specified by:
clearAll in interface Workspace

joinForeverButtons

public void joinForeverButtons(Agent agent)
Specified by:
joinForeverButtons in interface Workspace

addJobFromJobThread

public void addJobFromJobThread(Job job)
Specified by:
addJobFromJobThread in interface Workspace

magicOpen

public abstract void magicOpen(String name)
Specified by:
magicOpen in interface Workspace

compileForRun

public Procedure compileForRun(String source,
                               Context context,
                               boolean reporter)
                        throws CompilerException
Specified by:
compileForRun in interface Workspace
Throws:
CompilerException

updateMode

public Workspace.UpdateMode updateMode()

updateMode

public void updateMode(Workspace.UpdateMode updateMode)

open

public abstract void open(String path)
                   throws IOException,
                          CompilerException,
                          LogoException
Specified by:
open in interface Workspace
Throws:
IOException
CompilerException
LogoException

openString

public abstract void openString(String modelContents)
                         throws CompilerException,
                                LogoException
Specified by:
openString in interface Workspace
Throws:
CompilerException
LogoException

halt

public void halt()

requestDisplayUpdate

public abstract void requestDisplayUpdate(boolean force)
Specified by:
requestDisplayUpdate in interface Workspace

perhapsUpdateDisplay

public abstract void perhapsUpdateDisplay()
Specified by:
perhapsUpdateDisplay in interface Workspace

outputObject

public void outputObject(Object object,
                         Object owner,
                         boolean addNewline,
                         boolean readable,
                         Workspace.OutputDestination destination)
                  throws LogoException
Specified by:
outputObject in interface Workspace
Throws:
LogoException

setOutputAreaContents

public void setOutputAreaContents(String text)
Specified by:
setOutputAreaContents in interface ImporterUser

clearDrawing

public abstract void clearDrawing()
Specified by:
clearDrawing in interface Workspace

exportPlot

public void exportPlot(String plotName,
                       String filename)
                throws IOException
Specified by:
exportPlot in interface Workspace
Throws:
IOException

exportAllPlots

public void exportAllPlots(String filename)
                    throws IOException
Specified by:
exportAllPlots in interface Workspace
Throws:
IOException

exportWorld

public void exportWorld(String filename)
                 throws IOException
Specified by:
exportWorld in interface Workspace
Throws:
IOException

exportWorld

public void exportWorld(PrintWriter writer)

exportDrawingToCSV

public abstract void exportDrawingToCSV(PrintWriter writer)

exportOutputAreaToCSV

public abstract void exportOutputAreaToCSV(PrintWriter writer)

writeGraphicsData

public abstract void writeGraphicsData(PrintWriter writer)

importWorld

public void importWorld(String filename)
                 throws IOException
Specified by:
importWorld in interface Workspace
Throws:
IOException

importDrawing

public void importDrawing(String filename)
                   throws IOException
Specified by:
importDrawing in interface Workspace
Throws:
IOException

currentPlot

public void currentPlot(String plot)
Specified by:
currentPlot in interface ImporterUser

getPlot

public PlotInterface getPlot(String plot)
Specified by:
getPlot in interface ImporterUser

guessExportName

public String guessExportName(String defaultName)

exportBehaviors

public File exportBehaviors(String filename,
                            String experimentName,
                            boolean includeHeader)
                     throws IOException
Throws:
IOException

behaviorSpaceRunNumber

public int behaviorSpaceRunNumber()
Specified by:
behaviorSpaceRunNumber in interface Workspace

behaviorSpaceRunNumber

public void behaviorSpaceRunNumber(int n)
Specified by:
behaviorSpaceRunNumber in interface Workspace

makeThunk

public Thunk makeThunk(String source,
                       Agent agent,
                       Object owner)
                throws CompilerException
Specified by:
makeThunk in interface Evaluator
Throws:
CompilerException

evaluateCommands

public void evaluateCommands(String source)
                      throws CompilerException
Specified by:
evaluateCommands in interface Workspace
Throws:
CompilerException

evaluateCommands

public void evaluateCommands(String source,
                             Agent agent,
                             boolean waitForCompletion)
                      throws CompilerException
Specified by:
evaluateCommands in interface Workspace
Throws:
CompilerException

evaluateCommands

public void evaluateCommands(String source,
                             Class<? extends Agent> agentClass,
                             boolean waitForCompletion)
                      throws CompilerException
Specified by:
evaluateCommands in interface Workspace
Throws:
CompilerException

evaluateReporter

public Object evaluateReporter(String source)
                        throws CompilerException
Specified by:
evaluateReporter in interface Workspace
Throws:
CompilerException

evaluateReporter

public Object evaluateReporter(String source,
                               Agent agent)
                        throws CompilerException
Specified by:
evaluateReporter in interface Workspace
Throws:
CompilerException

compileCommands

public Procedure compileCommands(String source)
                          throws CompilerException
Specified by:
compileCommands in interface Workspace
Throws:
CompilerException

compileCommands

public Procedure compileCommands(String source,
                                 Class<? extends Agent> agentClass)
                          throws CompilerException
Specified by:
compileCommands in interface Workspace
Throws:
CompilerException

compileReporter

public Procedure compileReporter(String source)
                          throws CompilerException
Specified by:
compileReporter in interface Workspace
Throws:
CompilerException

runCompiledCommands

public boolean runCompiledCommands(Procedure procedure)
Specified by:
runCompiledCommands in interface Workspace

runCompiledReporter

public Object runCompiledReporter(Procedure procedure)
Specified by:
runCompiledReporter in interface Workspace

runCompiledReporter

public Object runCompiledReporter(Procedure procedure,
                                  org.nlogo.util.MersenneTwisterFast rng)
Specified by:
runCompiledReporter in interface Workspace

isConstant

public boolean isConstant(String string)
Specified by:
isConstant in interface Evaluator

readFromString

public Object readFromString(String string)
                      throws CompilerException
Specified by:
readFromString in interface Evaluator
Specified by:
readFromString in interface org.nlogo.api.CompilerServices
Throws:
CompilerException

getSource

public String getSource(String filename)
                 throws IOException
Throws:
IOException

autoConvert

public String autoConvert(String source,
                          boolean subprogram,
                          boolean reporter,
                          String modelVersion)
Specified by:
autoConvert in interface org.nlogo.api.CompilerServices

loadWorld

public void loadWorld(String[] strings,
                      String version,
                      WorldLoaderInterface worldInterface)

auxRNG

public org.nlogo.util.MersenneTwisterFast auxRNG()
Specified by:
auxRNG in interface RandomServices

mainRNG

public org.nlogo.util.MersenneTwisterFast mainRNG()
Specified by:
mainRNG in interface RandomServices

readNumberFromString

public Object readNumberFromString(String source)
                            throws CompilerException
Specified by:
readNumberFromString in interface org.nlogo.api.CompilerServices
Throws:
CompilerException

checkReporterSyntax

public void checkReporterSyntax(String source)
                         throws CompilerException
Specified by:
checkReporterSyntax in interface org.nlogo.api.CompilerServices
Throws:
CompilerException

checkCommandSyntax

public void checkCommandSyntax(String source)
                        throws CompilerException
Specified by:
checkCommandSyntax in interface org.nlogo.api.CompilerServices
Throws:
CompilerException

isValidIdentifier

public boolean isValidIdentifier(String s)
Specified by:
isValidIdentifier in interface org.nlogo.api.CompilerServices

tokenizeForColorization

public org.nlogo.api.Token[] tokenizeForColorization(String s)
Specified by:
tokenizeForColorization in interface org.nlogo.api.CompilerServices

getTokenAtPosition

public org.nlogo.api.Token getTokenAtPosition(String s,
                                              int pos)
Specified by:
getTokenAtPosition in interface org.nlogo.api.CompilerServices

findProcedurePositions

public Map<String,List<Object>> findProcedurePositions(String source)
Specified by:
findProcedurePositions in interface org.nlogo.api.CompilerServices

compiler

public abstract CompilerInterface compiler()
Specified by:
compiler in interface Workspace

lastLogoException

public LogoException lastLogoException()
Specified by:
lastLogoException in interface Workspace

clearLastLogoException

public void clearLastLogoException()
Specified by:
clearLastLogoException in interface Workspace