org.nlogo.workspace
Class AbstractWorkspace

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

public abstract class AbstractWorkspace
extends Object
implements Workspace, Evaluator


Nested Class Summary
static interface AbstractWorkspace.HubNetManagerFactory
           
 
Field Summary
 AggregateManagerInterface aggregateManager
           
static String DEFAULT_PREVIEW_COMMANDS
          previewCommands used by make-preview and model test
 JobManager jobManager
           
 String previewCommands
           
static int TYPE_CONVERTED
          type for models auto-converted from StarLogoT.
static int TYPE_LIBRARY
          type for "library" models (i.e., loaded from the Models Library).
static int TYPE_NEW
          type for new models.
static int TYPE_NORMAL
          type for "normal" models (i.e., loaded from File/Open).
 World world
           
 WorldLoader worldLoader
           
 
Fields inherited from interface org.nlogo.nvm.Workspace
CONTINUOUS_UPDATES, OUTPUT_NORMAL, OUTPUT_TO_FILE, OUTPUT_TO_OUTPUT_AREA, TICK_BASED_UPDATES
 
Method Summary
 void addJobFromJobThread(Job job)
           
 String attachModelDir(String filePath)
          attaches the current model directory to a relative path, if necessary.
 void clearAll()
           
abstract  void clearDrawing()
           
 Procedure compileCommands(String source)
           
 Procedure compileForRun(String source, Context context, boolean reporter)
           
 Procedure compileReporter(String source)
           
 boolean computerHubNetRunning()
           
 void computerHubNetRunning(boolean computerHubNetRunning)
           
 void convertToNormal()
          instantly converts the current model to TYPE_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 agentClass, boolean waitForCompletion)
           
 Object evaluateReporter(String source)
           
 Object evaluateReporter(String source, Agent agent)
           
 void exportAllPlots(String filename)
           
 org.nlogo.util.File exportBehaviors(String filename, String experimentName, boolean includeHeader)
           
abstract  void exportDrawingToCSV(PrintWriter writer)
           
abstract  void exportOutputAreaToCSV(PrintWriter writer)
           
 void exportPlot(org.nlogo.plot.Plot plot, String filename)
           
 void exportWorld(PrintWriter writer)
           
 void exportWorld(String filename)
           
 FileManager fileManager()
           
 boolean forceSaveAs()
          whether the user needs to enter a new filename to save this model.
 Shape getDefaultLinkShape()
           
 Shape getDefaultShape()
           
 org.nlogo.compiler.ExtensionManager getExtensionManager()
           
 String getExternalFileSource(String filename)
           
 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.
 int getModelType()
           
 PlotInterface getPlot(String plot)
           
 String guessExportName(String defaultName)
           
 void halt()
           
 HubNetInterface hubnetManager()
           
 void importDrawing(String filename)
           
 void importWorld(String filename)
           
 void init(Program program)
           
 void initForTesting(WorldDimensions d)
          Internal use only.
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)
           
abstract  boolean isHeadless()
           
 void joinForeverButtons(Agent agent)
           
abstract  void magicOpen(String name)
           
 Thunk makeThunk(String source, Agent agent, Object owner)
           
 String modelNameForDisplay()
           
abstract  void open(String path)
           
 void outputObject(Object object, Object owner, boolean addNewline, boolean readable, int destination)
           
abstract  void perhapsUpdateDisplay()
           
 org.nlogo.plot.PlotManager plotManager()
           
 Object readFromString(String string)
           
abstract  void requestDisplayUpdate(boolean force)
           
 void resetTimer()
           
 boolean runCompiledCommands(Procedure procedure)
           
 Object runCompiledReporter(Procedure procedure)
           
 void setOutputAreaContents(String text)
           
abstract  boolean shapesOn()
           
abstract  void shapesOn(boolean shapesOn)
           
 void updateChecksum()
           
 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
changeTopology, clearOutput, deleteLogFiles, exportDrawing, exportGraphics, exportInterface, exportOutput, getAndCreateDrawing, getAutoConverterErrorHandler, getHSB, initModelForChecksumming, inspectAgent, makePreviews, openIndex, openNext, openPrevious, patchSize, startLogging, waitFor, waitForQueuedEvents, waitForResult, zipLogFiles
 
Methods inherited from interface org.nlogo.agent.WorldResizer
patchSize, resizeWorld, setDimensions
 
Methods inherited from interface org.nlogo.nvm.JobManagerOwner
ownerFinished, periodicUpdate, runtimeError, updateDisplay
 

Field Detail

world

public final World world

jobManager

public final JobManager jobManager

aggregateManager

public AggregateManagerInterface aggregateManager

TYPE_NEW

public static final int TYPE_NEW
type for new models.

See Also:
Constant Field Values

TYPE_NORMAL

public static final int TYPE_NORMAL
type for "normal" models (i.e., loaded from File/Open).

See Also:
Constant Field Values

TYPE_LIBRARY

public static final int TYPE_LIBRARY
type for "library" models (i.e., loaded from the Models Library).

See Also:
Constant Field Values

TYPE_CONVERTED

public static final int TYPE_CONVERTED
type for models auto-converted from StarLogoT.

See Also:
Constant Field Values

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

worldLoader

public final WorldLoader worldLoader
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

getExtensionManager

public org.nlogo.compiler.ExtensionManager getExtensionManager()
Specified by:
getExtensionManager in interface Workspace

initForTesting

public void initForTesting(WorldDimensions d)
Internal use only.


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.

Throws:
InterruptedException

getDefaultShape

public Shape getDefaultShape()

getDefaultLinkShape

public Shape getDefaultLinkShape()

isHeadless

public abstract boolean isHeadless()

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)

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 TYPE_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 int 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()

init

public void init(Program program)

clearAll

public void clearAll()
              throws LogoException
Specified by:
clearAll in interface Workspace
Throws:
LogoException

resetTimer

public void resetTimer()
Specified by:
resetTimer 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

open

public abstract void open(String path)
                   throws IOException,
                          CompilerException,
                          LogoException
Throws:
IOException
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,
                         int 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(org.nlogo.plot.Plot plot,
                       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 org.nlogo.util.File exportBehaviors(String filename,
                                           String experimentName,
                                           boolean includeHeader)
                                    throws IOException
Throws:
IOException

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 agentClass,
                             boolean waitForCompletion)
                      throws CompilerException
Specified by:
evaluateCommands in interface Workspace
Throws:
CompilerException

evaluateReporter

public Object evaluateReporter(String source)
                        throws CompilerException
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

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

shapesOn

public abstract boolean shapesOn()

shapesOn

public abstract void shapesOn(boolean shapesOn)

updateChecksum

public void updateChecksum()
                    throws LogoException,
                           CompilerException,
                           IOException
Specified by:
updateChecksum in interface Workspace
Throws:
LogoException
CompilerException
IOException

isConstant

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

readFromString

public Object readFromString(String string)
Specified by:
readFromString in interface Evaluator

getExternalFileSource

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