|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objecthades.manager.DesignManager
DesignManager - the central HADES design manager class. The singleton instance of this class is responsible for loading, saving, and browsing of simulation models, Designs, and their symbols. DesignManager accesses designs and design resources from local files, JAR/Zip-files, URLs, and the Java classpath.
This class currently supports the following use-cases and scenarios:
Nested Class Summary | |
(package private) class |
DesignManager.SwingFileChooser
|
Method Summary | |
static java.lang.String |
changeExtension(java.lang.String source,
java.lang.String newExtension)
change the extension of original filename "source" to the "newExtension". |
java.lang.String |
checkAndAddFilenameExtension(java.lang.String name,
java.lang.String extension)
utility method to "repair" a missing filename extension. |
boolean |
checkExistsMakeBackup(java.lang.String pathname)
this method checks whether the file/URL specified by "pathname" already exists. |
static void |
dbg(java.lang.String msg)
|
static void |
dumpTokens(java.lang.String[] tokens)
|
static java.lang.String |
getAbsoluteFilename(java.lang.String pathname)
|
static java.lang.String |
getAppletBaseDir()
|
static java.lang.String |
getAppletServerName()
|
SimObject |
getCopy(SimObject source,
Editor editor)
|
boolean |
getDebug()
|
Design |
getDesign(Editor editor,
java.lang.String resourcename,
boolean toplevel)
getDesign: try to load a Design from file/URL "resourcename". |
static DesignManager |
getDesignManager()
Return a reference to the Singleton DesignManager. |
static java.lang.String |
getDirectory(java.lang.String pathname)
|
static java.lang.String |
getExtension(java.lang.String pathname)
get the extension (starting with the last "." dot char) of this pathname, or null. |
java.awt.Image |
getImage(java.lang.Object parent,
java.lang.String pathname)
Try to load an Image from the resource called 'pathname'. |
java.io.InputStream |
getInputStream(java.lang.Object parent,
java.lang.String pathname)
getInputStream: this method is the heart of DesignManager. |
java.lang.String[] |
getMatlabPath()
|
static java.lang.String |
getName(java.lang.String pathname)
|
Design |
getNewDesign(Editor editor)
|
java.io.OutputStream |
getOutputStream(java.lang.Object o,
java.lang.String pathname)
|
java.io.InputStream |
getResourceAsStream(java.lang.String resourceName)
try to find and open an InputStream for the given resource name. |
SimObject |
getSimObject(java.lang.String classname)
getSimObject(): given a Java classname like "hades.models.gates.And2", return an instance of that class. |
SimObject |
getSimObject(java.lang.String classname,
long version,
Editor editor)
getSimObject(): locate and return a simulation model of class 'classname' and version 'version' or higher. |
java.awt.Image |
getThumbnail(java.lang.String pathname)
load, create and return an Image object from file/URL pathname. |
java.io.InputStream |
getVirtualFile(java.lang.String key)
|
java.util.Hashtable |
getVirtualFiles()
|
java.io.InputStream |
getZipEntryInputStream(java.lang.String pathname)
given a pathname of the form "zip://hugo.zip?/path/to/file.hds" locate the corresponding zipfile (which should have been registered by calling registerZipFile), and return an InputStream for the specified zip entry. |
void |
msg(java.lang.String msg)
|
java.io.ByteArrayOutputStream |
readStreamIntoBuffer(java.io.InputStream input)
|
java.io.ByteArrayOutputStream |
readStreamIntoBuffer(java.lang.String pathname)
find the specified resource and read its contents into a ByteArrayOutputStream buffer. |
java.lang.String |
readStreamIntoString(java.lang.String pathname)
an utility method to read the specified resource into a (multiline) String for further processing. |
void |
registerZipFile(java.util.zip.ZipFile zipfile)
|
void |
saveAsVirtualFile(java.lang.String key,
java.io.InputStream is)
|
void |
saveAsVirtualFile(java.lang.String key,
java.lang.String data)
|
java.lang.String |
selectFileOrURLName(java.lang.String dialogTitle,
java.lang.String defaultName,
java.lang.Object _extensions,
int mode)
selectFileOrURLName: prompt the user for a file or URL name. |
java.lang.String |
selectURLName(java.lang.String dialogTitle,
java.lang.String defaultName)
|
static void |
setAppletBaseDir(java.lang.String name)
|
static void |
setAppletServerName(java.lang.String servername)
|
void |
setDebug(boolean b)
|
void |
setDialogWindowsParentFrame(java.awt.Frame frame)
set a Frame which is used as a parent window for the FileDialog and SelectURLDialog windows. |
void |
setFileDialogDirectoryAndFilename(java.awt.FileDialog fileDialog,
java.lang.String resourceName)
try to split resourceName (which always uses '/' as a separator char) into directory and filename parts. |
void |
setMatlabPath(java.lang.String s)
|
java.lang.String |
toString()
|
(package private) void |
traceResourceAccess(java.lang.String resourceName)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Method Detail |
public static DesignManager getDesignManager()
public void setMatlabPath(java.lang.String s)
public java.lang.String[] getMatlabPath()
public SimObject getSimObject(java.lang.String classname) throws SimObjectNotFoundException
SimObjectNotFoundException
- if the requested Object is not foundpublic SimObject getSimObject(java.lang.String classname, long version, Editor editor) throws SimObjectNotFoundException, SimObjectVersionNotFoundException
The current preliminary implementation just ignores the requested version number!
SimObjectNotFoundException
- if the Object specified by
classname and version number cannot be found
SimObjectVersionNotFoundException
- if the version of
SimObject cannot be foundpublic SimObject getCopy(SimObject source, Editor editor)
public Design getNewDesign(Editor editor)
public Design getDesign(Editor editor, java.lang.String resourcename, boolean toplevel) throws SimObjectNotFoundException
SimObjectNotFoundException
public boolean checkExistsMakeBackup(java.lang.String pathname)
Note that the current implementation only works for local files, not for remote files or URLs, and not for files in JAR/Zip archives.
At the moment, the backup name is constructed by appending an underscore character and an integer. For example, the backups for Hades design "/examples/cla/adder8.hds" will be called "/examples/cla/adder8.hds_1", "/examples/cla/ader8.hds_2", and so on. We use the trivial algorithm for this, which becomes very slow when the number of existing backup files is large.
public java.io.InputStream getResourceAsStream(java.lang.String resourceName)
void traceResourceAccess(java.lang.String resourceName)
public static java.lang.String getAppletServerName()
public static void setAppletServerName(java.lang.String servername)
public static java.lang.String getAppletBaseDir()
public static void setAppletBaseDir(java.lang.String name)
public void setDialogWindowsParentFrame(java.awt.Frame frame)
public java.lang.String selectFileOrURLName(java.lang.String dialogTitle, java.lang.String defaultName, java.lang.Object _extensions, int mode)
If non-null, dialogTitle is used for dialog window title, defaultName is used as the initial file/URL name, and the extension is used to create a matching hades.utils.EndsWithFilter. The mode argument should be either java.awt.FileDialog.LOAD or java.awt.FileDialog.SAVE.
The current implementation uses AWT-based dialog windows (FileDialog and hades.gui.SelectURLDialog), but this will use the BrowserFrame JTree-based selection soon.
Question: Why does the JDK deadlock or crashes on Windows, when this method is made synchronized?
public java.lang.String selectURLName(java.lang.String dialogTitle, java.lang.String defaultName)
public void setFileDialogDirectoryAndFilename(java.awt.FileDialog fileDialog, java.lang.String resourceName)
public java.lang.String checkAndAddFilenameExtension(java.lang.String name, java.lang.String extension)
This method will first check the current value of the SetupManager "Hades.DesignManager.AutoAddExtension" property. If not true, the method returns the original "name" argument unmodified. When enabled, this method will then check whether the string "name" already has an extension. If yes, it also returns the original string. If not, it will add "extension" to "name".
For example, when called with "c:\tmp\adder" and ".hds" arguments, this method will return "c:\tmp\adder.hds".
This is a dumb method, the check for an extension is made simply by searching for a dot "." in the original "name". This algorithm is not optimal when the user selects a name with multiple dots in it.
public java.io.InputStream getInputStream(java.lang.Object parent, java.lang.String pathname)
file://c:/users/foo/examples/bar.txt zip://c:/temp/foo.zip?/foo/foo2/foobar.hds virtual://hashtable-key.hds hades/models/gates/And2.gif /hades/models/gates/And2.gif resource://hades/models/io/Ipin.sym ./foobar.rom
When searching for a local file, this method will automagically replace any slash chars ('/') in pathname with the platform dependent separator char.
When the first argument is non-null, it will also be used to search for the given resource. For example, when the first argument is a Hades Design, that Design resource name will be used to search for pathname, too.
When matlabPath is non-null, getInputStream() employs a Matlab-style algorithm: every directory on the matlabPath array is searched for the given (relative) path, and the first matching stream is returned.
public static void dumpTokens(java.lang.String[] tokens)
public java.io.OutputStream getOutputStream(java.lang.Object o, java.lang.String pathname)
public java.awt.Image getThumbnail(java.lang.String pathname)
public java.awt.Image getImage(java.lang.Object parent, java.lang.String pathname)
The raw image data is loaded via DesignManager.getInputStream() into a ByteArrayOutputStream, and then converted into an Image via java.awt.Toolkit.createImage().
public java.lang.String readStreamIntoString(java.lang.String pathname)
public java.io.ByteArrayOutputStream readStreamIntoBuffer(java.lang.String pathname)
public java.io.ByteArrayOutputStream readStreamIntoBuffer(java.io.InputStream input)
public java.util.Hashtable getVirtualFiles()
public void saveAsVirtualFile(java.lang.String key, java.io.InputStream is)
public void saveAsVirtualFile(java.lang.String key, java.lang.String data)
public java.io.InputStream getVirtualFile(java.lang.String key)
public void registerZipFile(java.util.zip.ZipFile zipfile)
public java.io.InputStream getZipEntryInputStream(java.lang.String pathname)
public static java.lang.String getAbsoluteFilename(java.lang.String pathname)
public static java.lang.String getDirectory(java.lang.String pathname)
public static java.lang.String getName(java.lang.String pathname)
public static java.lang.String getExtension(java.lang.String pathname)
public static java.lang.String changeExtension(java.lang.String source, java.lang.String newExtension)
For example, calling this method with arguments "/tmp/design/traffic.hds" and ".sym" will create the name "/tmp/design/traffic.sym". This dumb method is not designed to handle illegal or null arguments.
public void setDebug(boolean b)
public boolean getDebug()
public static void dbg(java.lang.String msg)
public void msg(java.lang.String msg)
public java.lang.String toString()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |