com.sun.electric.database.hierarchy
Class Library

java.lang.Object
  extended by com.sun.electric.database.variable.ElectricObject
      extended by com.sun.electric.database.hierarchy.Library
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<Library>

public class Library
extends ElectricObject
implements java.lang.Comparable<Library>

A Library represents a collection of Cells. To find of a Library, you use Electric.getLibrary(String name). Use Electric.newLibrary(String name) to create a new library, or Electric.getCurrent() to get the current Library.

Once you have a Library, you can create a new Cell in it, find an existing Cell, get an Enumeration of all Cells, or find the Cell that the user is currently editing.

See Also:
Serialized Form

Field Summary
static Variable.Key FONT_ASSOCIATIONS
          key of Variable holding font associations.
static int HIDDENLIBRARY
          library is "hidden" (clipboard library)
 
Method Summary
 void addVar(Variable var)
          Method to add a Variable on this Library.
 LibraryBackup backup()
           
protected  void check()
          Method to check invariants in this Library.
 int checkAndRepair(boolean repair, ErrorLogger errorLogger)
          Method to check and repair data structure errors in this Library.
 void clearChanged()
          Method to indicate that this Library has not changed.
 void clearFromDisk()
          Method to indicate that this Library did not come from disk.
 void clearHidden()
          Method to indicate that this Library is not hidden.
 int compareTo(Library that)
          Compares two Library objects.
 void delVar(Variable.Key key)
          Method to delete a Variable from this Library.
 void erase()
          Method to remove all contents from this Library.
static Cell findCellInLibraries(java.lang.String cellName, View view, java.lang.String libraryName)
           
static Library findLibrary(java.lang.String libName)
          Method to find a Library with the specified name.
 Cell findNodeProto(java.lang.String name)
          Method to find the Cell with the given name in this Library.
static java.util.Set<Cell> findReferenceInCell(Library elib)
          Get list of cells contained in other libraries that refer to cells contained in this library
 java.util.Iterator<Cell> getCells()
          Method to return an Iterator over all Cells in this Library.
 Cell getCurCell()
          Method to get the current Cell in this Library.
static Library getCurrent()
          Method to return the current Library.
 ImmutableLibrary getD()
          Returns persistent data of this Library.
 EDatabase getDatabase()
          Returns database to which this Library belongs.
 java.util.Set<java.lang.String> getDelibCellFiles()
          Returns DELIB cell files.
 LibId getId()
          Method to return LibId of this Library.
 java.net.URL getLibFile()
          Method to return the URL of this Library.
static java.util.Iterator<Library> getLibraries()
          Method to return an iterator over all libraries.
 java.lang.String getName()
          Method to return the name of this Library.
 int getNumCells()
           
static int getNumLibraries()
          Method to return the number of libraries.
 Pref.Group getPrefs()
          Method to get the Preferences associated with this Library.
 Version getVersion()
          Returns verison of Electric which wrote this library.
static java.util.List<Library> getVisibleLibraries()
          Method to return an iterator over all visible libraries.
static Library inCurrentThread(LibId libId)
          Returns a Library by LibId.
 boolean isChanged()
          Method to return true if this Library has changed.
 boolean isFromDisk()
          Method to return true if this Library came from disk.
 boolean isHidden()
          Method to return true if this Library is hidden.
 boolean isLinked()
          Returns true if this Library is linked into database.
 boolean kill(java.lang.String reason)
          Method to delete this Library.
 int lowLevelGetUserBits()
          Low-level method to get the user bits.
 void lowLevelSetUserBits(int userBits)
          Low-level method to set the user bits.
static Library newInstance(java.lang.String libName, java.net.URL libFile)
          This method is a factory to create new libraries.
 boolean referencesLib(Library lib)
          Returns true if this Library directly references the specified Library 'lib'.
static void repairAllLibraries()
           
static void saveExpandStatus()
          Method to save isExpanded status of NodeInsts in this Library to Preferences.
 void setChanged()
          Method to indicate that this Library has changed.
 void setCurCell(Cell curCell)
          Method to set the current Cell in this Library.
 void setCurrent()
          Method to make this the current Library.
 void setDelibCellFiles(java.util.HashSet<java.lang.String> delibCellFiles)
          Sets DELIB cell files.
 void setFromDisk()
          Method to indicate that this Library came from disk.
 void setHidden()
          Method to indicate that this Library is hidden.
 void setLibFile(java.net.URL libFile)
          Method to set the URL of this Library.
 IdMapper setName(java.lang.String libName)
          Method to set the name of this Library.
 void setVersion(Version version)
          Method to set library version found in header.
 java.lang.String toString()
          Returns a printable version of this Library.
 
Methods inherited from class com.sun.electric.database.variable.ElectricObject
addDisplayableVariables, checkChanging, checkExamine, checkUndoing, computeTextPoly, copyTextDescriptorFrom, copyVarsFrom, getArtwork, getCode, getDisplayableVariables, getGeneric, getInfo, getMutableTextDescriptor, getNumVariables, getParameterOrVariable, getParameterOrVariable, getParametersAndVariables, getPolyList, getSchematics, getTech, getTechPool, getTextBounds, getTextDescriptor, getVar, getVar, getVariables, getVarValue, getVarValue, isDatabaseObject, isDeprecatedVariable, isParam, newDisplayVar, newVar, newVar, newVar, newVar, numDisplayableVariables, renameVar, renameVar, setOff, setTextDescriptor, uniqueObjectName, uniqueObjectName, updateVar, updateVarCode, updateVarText, whichCell
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

FONT_ASSOCIATIONS

public static final Variable.Key FONT_ASSOCIATIONS
key of Variable holding font associations.


HIDDENLIBRARY

public static final int HIDDENLIBRARY
library is "hidden" (clipboard library)

See Also:
Constant Field Values
Method Detail

newInstance

public static Library newInstance(java.lang.String libName,
                                  java.net.URL libFile)
This method is a factory to create new libraries. A Library has both a name and a file.

Parameters:
libName - the name of the library (for example, "gates"). Library names must be unique, and they must not contain spaces or colons.
libFile - the URL to the disk file (for example "/home/strubin/gates.elib"). If the Library is being created, the libFile can be null. If the Library file is given and it points to an existing file, then the I/O system can be told to read that file and populate the Library.
Returns:
the Library object.

kill

public boolean kill(java.lang.String reason)
Method to delete this Library.

Parameters:
reason - the reason for deleting this library (replacement or deletion).
Returns:
true if the library was deleted. Returns false on error.

erase

public void erase()
Method to remove all contents from this Library.


referencesLib

public boolean referencesLib(Library lib)
Returns true if this Library directly references the specified Library 'lib'. It does not return true if the library is referenced through another library.

Parameters:
lib - the possible referenced library
Returns:
true if the library is directly referenced by this library, false otherwise

getD

public ImmutableLibrary getD()
Returns persistent data of this Library.

Specified by:
getD in class ElectricObject
Returns:
persistent data of this Library.

addVar

public void addVar(Variable var)
Method to add a Variable on this Library. It may add repaired copy of this Variable in some cases.

Specified by:
addVar in class ElectricObject
Parameters:
var - Variable to add.

delVar

public void delVar(Variable.Key key)
Method to delete a Variable from this Library.

Specified by:
delVar in class ElectricObject
Parameters:
key - the key of the Variable to delete.

getId

public LibId getId()
Method to return LibId of this Library. LibId identifies Library independently of threads.

Returns:
LibId of this Library.

inCurrentThread

public static Library inCurrentThread(LibId libId)
Returns a Library by LibId. Returns null if the Library is not linked to the database.

Parameters:
libId - LibId to find.
Returns:
Library or null.

isLinked

public boolean isLinked()
Returns true if this Library is linked into database.

Specified by:
isLinked in class ElectricObject
Returns:
true if this Library is linked into database.

getDatabase

public EDatabase getDatabase()
Returns database to which this Library belongs.

Specified by:
getDatabase in class ElectricObject
Returns:
database to which this Library belongs.

backup

public LibraryBackup backup()

repairAllLibraries

public static void repairAllLibraries()

checkAndRepair

public int checkAndRepair(boolean repair,
                          ErrorLogger errorLogger)
Method to check and repair data structure errors in this Library.


check

protected void check()
Method to check invariants in this Library.

Overrides:
check in class ElectricObject
Throws:
java.lang.AssertionError - if invariants are not valid

setChanged

public void setChanged()
Method to indicate that this Library has changed.


clearChanged

public void clearChanged()
Method to indicate that this Library has not changed.


isChanged

public boolean isChanged()
Method to return true if this Library has changed.

Returns:
true if this Library has changed.

setFromDisk

public void setFromDisk()
Method to indicate that this Library came from disk. Libraries that come from disk are saved without a file-selection dialog.


clearFromDisk

public void clearFromDisk()
Method to indicate that this Library did not come from disk. Libraries that come from disk are saved without a file-selection dialog.


isFromDisk

public boolean isFromDisk()
Method to return true if this Library came from disk. Libraries that come from disk are saved without a file-selection dialog.

Returns:
true if this Library came from disk.

setHidden

public void setHidden()
Method to indicate that this Library is hidden. Hidden libraries are not seen by the user. For example, the "clipboard" library is hidden because it is only used internally for copying and pasting circuitry.


clearHidden

public void clearHidden()
Method to indicate that this Library is not hidden. Hidden libraries are not seen by the user. For example, the "clipboard" library is hidden because it is only used internally for copying and pasting circuitry.


isHidden

public boolean isHidden()
Method to return true if this Library is hidden. Hidden libraries are not seen by the user. For example, the "clipboard" library is hidden because it is only used internally for copying and pasting circuitry.

Returns:
true if this Library is hidden.

getCurrent

public static Library getCurrent()
Method to return the current Library.

Returns:
the current Library.

setCurrent

public void setCurrent()
Method to make this the current Library.


getPrefs

public Pref.Group getPrefs()
Method to get the Preferences associated with this Library.

Returns:
the Preferences associated with this Library.

lowLevelGetUserBits

public int lowLevelGetUserBits()
Low-level method to get the user bits. The "user bits" are a collection of flags that are more sensibly accessed through special methods. This general access to the bits is required because the ELIB file format stores it as a full integer. This should not normally be called by any other part of the system.

Returns:
the "user bits".

lowLevelSetUserBits

public void lowLevelSetUserBits(int userBits)
Low-level method to set the user bits. The "user bits" are a collection of flags that are more sensibly accessed through special methods. This general access to the bits is required because the ELIB file format stores it as a full integer. This should not normally be called by any other part of the system.

Parameters:
userBits - the new "user bits".

findReferenceInCell

public static java.util.Set<Cell> findReferenceInCell(Library elib)
Get list of cells contained in other libraries that refer to cells contained in this library

Parameters:
elib - to search for
Returns:
list of cells refering to elements in this library

findLibrary

public static Library findLibrary(java.lang.String libName)
Method to find a Library with the specified name.

Parameters:
libName - the name of the Library. Note that this is the Library name, and not the Library file.
Returns:
the Library, or null if there is no known Library by that name.

getLibraries

public static java.util.Iterator<Library> getLibraries()
Method to return an iterator over all libraries.

Returns:
an iterator over all libraries.

getNumLibraries

public static int getNumLibraries()
Method to return the number of libraries.

Returns:
the number of libraries.

getVisibleLibraries

public static java.util.List<Library> getVisibleLibraries()
Method to return an iterator over all visible libraries.

Returns:
an iterator over all visible libraries.

getName

public java.lang.String getName()
Method to return the name of this Library.

Returns:
the name of this Library.

setName

public IdMapper setName(java.lang.String libName)
Method to set the name of this Library.

Parameters:
libName - the new name of this Library.
Returns:
mapping of Library/Cell/Export ids, null if the library was renamed.

getLibFile

public java.net.URL getLibFile()
Method to return the URL of this Library.

Returns:
the URL of this Library.

setLibFile

public void setLibFile(java.net.URL libFile)
Method to set the URL of this Library.

Parameters:
libFile - the new URL of this Library.

compareTo

public int compareTo(Library that)
Compares two Library objects.

Specified by:
compareTo in interface java.lang.Comparable<Library>
Parameters:
that - the Library to be compared.
Returns:
the result of comparison.

toString

public java.lang.String toString()
Returns a printable version of this Library.

Overrides:
toString in class ElectricObject
Returns:
a printable version of this Library.

getCurCell

public Cell getCurCell()
Method to get the current Cell in this Library.

Returns:
the current Cell in this Library. Returns NULL if there is no current Cell.

setCurCell

public void setCurCell(Cell curCell)
Method to set the current Cell in this Library.

Parameters:
curCell - the new current Cell in this Library.

saveExpandStatus

public static void saveExpandStatus()
                             throws java.util.prefs.BackingStoreException
Method to save isExpanded status of NodeInsts in this Library to Preferences.

Throws:
java.util.prefs.BackingStoreException

findCellInLibraries

public static Cell findCellInLibraries(java.lang.String cellName,
                                       View view,
                                       java.lang.String libraryName)

findNodeProto

public Cell findNodeProto(java.lang.String name)
Method to find the Cell with the given name in this Library.

Parameters:
name - the name of the desired Cell.
Returns:
the Cell with the given name in this Library.

getNumCells

public int getNumCells()

getCells

public java.util.Iterator<Cell> getCells()
Method to return an Iterator over all Cells in this Library.

Returns:
an Iterator over all Cells in this Library.

getVersion

public Version getVersion()
Returns verison of Electric which wrote this library. Returns null for ReadableDumps, for new libraries and for dummy libraries.

Returns:
version

setVersion

public void setVersion(Version version)
Method to set library version found in header.

Parameters:
version -

getDelibCellFiles

public java.util.Set<java.lang.String> getDelibCellFiles()
Returns DELIB cell files.

Returns:
DELIB cell files.

setDelibCellFiles

public void setDelibCellFiles(java.util.HashSet<java.lang.String> delibCellFiles)
Sets DELIB cell files.

Parameters:
delibCellFiles - DELIB cell files.