hades.simulator
Class SimObject

java.lang.Object
  extended byhades.simulator.SimObject
All Implemented Interfaces:
java.lang.Cloneable, ContextToolTip, java.io.Serializable, Simulatable
Direct Known Subclasses:
AbstractIntel4000, ActionButton, Adder, Alu, AsciiDisplay, BitReg6, Constant, Constant, Counter, Dcf77Clock, Dcf77Sender, DelayNode, Design, EdgeTrigger, FastPic16F84, FigObject, FsmWrapper, GenericCGate, GenericFlipflop, GenericGate, GenericMemory, GenericOnebitLogicObject, GenericRtlibObject, Gnd, GraphicsLCD, GraphicsLCDnfb, HazardTrigger, HexSwitch, i4003, IDT6116, IDTR3051, ImageMux21, ImageSource, ImageViewer, ImageWriter, Incr, Iso8859Display, JPWrapper, JythonScriptWrapper, Label, Latch, LED, MidiReceiver, Mux, ParallelTerminal, ParametrizedFilter, Pic16C84, Pic16C84Debug, PowerOnReset, Pullup, RAM_256x8, RAM_64K, Register, Register, RemoteIpin, RemoteOpin, ROM_1Kx8, SerialTerminal, SevenSegment, SevenSegmentMultiplexed, SimpleFilter, SmartPic16F84, SN7400, SN7405, SN74189, SN74219, SN7449, StimuliGenerator, StringDisplay, Swatch, TextLCD, TriBuf, TurboPicCore, ValueTrigger, Vcc

public class SimObject
extends java.lang.Object
implements Simulatable, ContextToolTip, java.lang.Cloneable, java.io.Serializable

SimObject - an example stub class that implements the Simulatable interface and may be subclassed for concrete simulation objects

See Also:
Serialized Form

Field Summary
protected  java.lang.ClassLoader classloader
           
protected  Console console
           
protected static boolean debug
           
protected  Editor editor
           
protected  java.lang.String name
           
protected  SimObject parent
           
protected  Port[] ports
           
protected  PropertySheet propertySheet
           
protected  SimKernel simulator
           
protected  Symbol symbol
           
protected  long versionId
           
protected  boolean visible
           
 
Constructor Summary
SimObject()
          simple default constructor.
 
Method Summary
 void configure()
          create and display a 'ConfigDialog' to set the parameters for a SimObject.
 void constructDynamicSymbol()
           
 SimObject copy()
          copy(): This function is used to create a clone of the current SimObject.
 void elaborate(java.lang.Object arg)
          elaborate(): This method is called by the simulation engine to initialize the simulation object.
 void evaluate(java.lang.Object arg)
          evaluate(): called by the simulation engine on all events that concern this object.
 java.lang.String getBindkey()
          return the bindkey as a String.
 java.lang.ClassLoader getClassLoader()
           
 boolean getDebug()
           
 Editor getEditor()
           
 java.lang.String[] getExternalResources()
          return a String array with all external resources required by the current SimObject.
 java.lang.String getFullName()
          get the full (hierarchical) name of this object
 java.lang.String getName()
          get the name of this object
 SimObject getParent()
          get a reference to the parent of this SimObject, if any
 Port getPort(java.lang.String name)
          get a reference to a port called 'name' if any
 Port[] getPorts()
          get a list of Ports on this SimObject
 java.awt.Component getPropertySheet()
          return a reference to the 'property sheet' or configuration window for this SimObject.
 java.io.InputStream getResourceAsStream(java.lang.String s)
          get an InputStream for the CLASSPATH resource specified by String s.
 SimKernel getSimulator()
          get a reference to the simulator for this SimObject
 Symbol getSymbol()
           
 java.lang.String getSymbolResourceName()
          construct a symbol resource name from the class name of SimObject or its respective derived class: prepend '/', replace '.' by '/', and append ".sym".
 java.lang.String getToolTip(java.awt.Point position, long millis)
          construct a (short) tool tip message for a SimObject.
 long getVersionId()
           
 boolean initialize(java.lang.String s)
          initialize a SimObject from a String.
 boolean isVisible()
           
 void keyPressed(java.awt.event.KeyEvent ke)
          react to a KeyEvent.
 void message(java.lang.String msg)
          message(): print or display an information message.
 void mousePressed(java.awt.event.MouseEvent me)
          react to a MouseEvent.
 boolean needsDynamicSymbol()
           
 boolean needsExternalResources()
          check whether this SimObject needs external resources, e.g.
 void setClassLoader(java.lang.ClassLoader CL)
           
 void setConsole(Console console)
          setConsole(): set a new Console for output messages
 void setDebug(boolean d)
           
 void setEditor(Editor editor)
           
 void setName(java.lang.String s)
          set the name of this SimObject.
 void setParent(SimObject parent)
          set the parent SimObject for this SimObject
 void setPorts(Port[] ports)
           
 void setSimulator(SimKernel sim)
          set a new simulation engine for this SimObject
 void setSymbol(Symbol symbol)
           
 void setVersionId(long _id)
           
 void setVisible(boolean v)
           
 void tearDown()
          tearDown(): called at the end of a simulation to clear up all references held by the SimObject.
 java.lang.String toString()
          toString: generate a text description for this SimObject.
 void write(java.io.PrintWriter ps)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ports

protected Port[] ports

name

protected java.lang.String name

versionId

protected long versionId

parent

protected SimObject parent

simulator

protected SimKernel simulator

editor

protected Editor editor

classloader

protected java.lang.ClassLoader classloader

symbol

protected Symbol symbol

visible

protected boolean visible

console

protected Console console

propertySheet

protected PropertySheet propertySheet

debug

protected static boolean debug
Constructor Detail

SimObject

public SimObject()
simple default constructor.

Method Detail

getClassLoader

public java.lang.ClassLoader getClassLoader()

setClassLoader

public void setClassLoader(java.lang.ClassLoader CL)

getResourceAsStream

public java.io.InputStream getResourceAsStream(java.lang.String s)
get an InputStream for the CLASSPATH resource specified by String s. While this method expects a fully qualified name, e.g. "/hades/models/gates/And2.sym", it includes a workaround to handle and convert incomplete names. For example, when called with the String "And2.sym", the full name is constructed and then used to lookup the resource via DesignManager.getResourceAsStream.


getName

public java.lang.String getName()
get the name of this object


getFullName

public java.lang.String getFullName()
get the full (hierarchical) name of this object


setName

public void setName(java.lang.String s)
set the name of this SimObject. If there is a Symbol for this SimObject, we also try to set the InstanceLabel in the Symbol.

To avoid consistency problems, when the user changes a SimObject's name interactively, we also try to enforce a unique name.


getParent

public SimObject getParent()
get a reference to the parent of this SimObject, if any


setParent

public void setParent(SimObject parent)
set the parent SimObject for this SimObject


getEditor

public Editor getEditor()

setEditor

public void setEditor(Editor editor)

getSimulator

public SimKernel getSimulator()
get a reference to the simulator for this SimObject


setSimulator

public void setSimulator(SimKernel sim)
set a new simulation engine for this SimObject


getPorts

public Port[] getPorts()
get a list of Ports on this SimObject


setPorts

public void setPorts(Port[] ports)

getPort

public Port getPort(java.lang.String name)
get a reference to a port called 'name' if any


needsExternalResources

public boolean needsExternalResources()
check whether this SimObject needs external resources, e.g. to initialize a memory from an external programming file or the Hades design file used for hades.models.Design instances. Base class SimObject has no external resources.


getExternalResources

public java.lang.String[] getExternalResources()
return a String array with all external resources required by the current SimObject. As the base class SimObject does not have any external resources, we return an array of length 0.


getSymbolResourceName

public java.lang.String getSymbolResourceName()
construct a symbol resource name from the class name of SimObject or its respective derived class: prepend '/', replace '.' by '/', and append ".sym". For example, when called on a "hades.models.gates.And2" instance, this method will return "/hades/models/gates/And2.sym"


getSymbol

public Symbol getSymbol()

setSymbol

public void setSymbol(Symbol symbol)

needsDynamicSymbol

public boolean needsDynamicSymbol()

constructDynamicSymbol

public void constructDynamicSymbol()

setVisible

public void setVisible(boolean v)

isVisible

public boolean isVisible()

setDebug

public void setDebug(boolean d)

getDebug

public boolean getDebug()

getVersionId

public long getVersionId()

setVersionId

public void setVersionId(long _id)

initialize

public boolean initialize(java.lang.String s)
initialize a SimObject from a String. The method returns true once all required data has been read. Until then, you should repeatedly call initialize() with additional Strings.


write

public void write(java.io.PrintWriter ps)

elaborate

public void elaborate(java.lang.Object arg)
elaborate(): This method is called by the simulation engine to initialize the simulation object.

Specified by:
elaborate in interface Simulatable
Parameters:
arg - an arbitrary argument

evaluate

public void evaluate(java.lang.Object arg)
evaluate(): called by the simulation engine on all events that concern this object. The object is responsible for updating its internal state and for scheduling all pending output events.

Specified by:
evaluate in interface Simulatable
Parameters:
arg - an arbitrary object argument

tearDown

public void tearDown()
tearDown(): called at the end of a simulation to clear up all references held by the SimObject. Unfortunately, this is required as the garbage collector often fails to clean up the cyclic interdependencies between objects, signals, simulator and GUI fast enough. Note that the SimObject cannot be used after this method has been called. Should be overridden by subclasses as needed.


configure

public void configure()
create and display a 'ConfigDialog' to set the parameters for a SimObject. The default ConfigDialog for the base class (SimObject) itself is empty except for the 'instance name' of the SimObject.


getPropertySheet

public java.awt.Component getPropertySheet()
return a reference to the 'property sheet' or configuration window for this SimObject. We cast the return value to an AWT Component, but typically you can expect either a hades.gui.PropertySheet or an java.awt.Window (Dialog or Frame).


mousePressed

public void mousePressed(java.awt.event.MouseEvent me)
react to a MouseEvent. The base SimObject ignores MouseEvents.

Note that the HADES schematic editor will also deliver jfig.canvas.FigCanvasEvent object, which also include the world-coordinates of the Event.


keyPressed

public void keyPressed(java.awt.event.KeyEvent ke)
react to a KeyEvent. The base SimObject ignores all KeyEvents. this method is currently only used by a few classes in hades.models.io, e.g. IpinWithBindkey.

At the moment this is actually called from KeyHandler.keyTyped(), but this naming mismatch is not considered critical...


getBindkey

public java.lang.String getBindkey()
return the bindkey as a String.

Returns the lowercase bindkey character as a String; this key is used by KeyHandler to check whether this SimObject should be activated (via keyPressed()) in view-mode. We return null here. Should be overridden by SimObject's that want to be notified by and react to global key-events on the main editor canvas.

If you plan to enable a bindkey for your SimObject, please: override getBindkey(), implement setBindkey() - e.g. via NameMangler.getBindkey(), change write() to write the bindkey string, change initialize() to parse the bindkey string, modify getToolTip() to print the bindkey, and change configure() to allow setting the bindkey.


copy

public SimObject copy()
copy(): This function is used to create a clone of the current SimObject.

I am not yet sure about the correct and best semantic for copy(). Currently a new object of the current class is created by calling the default constructor.


message

public void message(java.lang.String msg)
message(): print or display an information message.

Specified by:
message in interface Simulatable

setConsole

public void setConsole(Console console)
setConsole(): set a new Console for output messages


getToolTip

public java.lang.String getToolTip(java.awt.Point position,
                                   long millis)
construct a (short) tool tip message for a SimObject. This method should be overridden as needed.

Specified by:
getToolTip in interface ContextToolTip

toString

public java.lang.String toString()
toString: generate a text description for this SimObject. This method currently combines the class name for the SimObject (or subclass) and its full name in the current Hades Design, e.g. "hades.models.gates.And2: /uut/adder16/adder1/i3".