public class IlvPaletteManager extends Object
load(URL)
for details.
A palette manager is used when the application must be able to load palettes
dynamically from the file system or from an URL. It must also be used if the
palettes are not static, i.e., if the application modifies the palette at run
time. In order to enable SDM to use the palettes currently contained in the
palette manager, the palette manager must be attached to the diagrammer (see
attach(IlvCSSCompatible)
. When the palette manager is no longer
used, the palette manager should be detached (see detach(ilog.views.util.cssbeans.IlvCSSCompatible)
) in order
to clean up the memory. This is suitable for an application if one of the
following requirements holds:
Saving palettes into jars works like this: The palette is first stored in a
working directory (see setWorkingDirectory(java.io.File)
) and then put into a jar.
Hence, applications that want to save palettes into jars must provide a
working directory.
Here is some example code how to use a palette manager:
IlvPaletteManager paletteManager = new IlvPaletteManager(); paletteManager.attach(diagrammer); paletteManager.setWorkingDirectory(fileOfWorkingDirectory); // load palettes from a jar (the jar might contain many palettes) IlvPalette[] palettes = paletteManager.load(paletteJarURL); ... // save one palette into a jar paletteManager.save(myPalette, paletteJarURL); ... // later, if the palette manager is no longer used: paletteManager.detach();
Constructor and Description |
---|
IlvPaletteManager()
Creates an empty palette manager.
|
IlvPaletteManager(ilog.views.util.cssbeans.IlvCSSCompatible target)
Creates an empty palette manager for the input target.
|
Modifier and Type | Method and Description |
---|---|
void |
add(IlvPalette palette)
Adds a palette.
|
void |
addPaletteManagerListener(PaletteManagerListener l)
Adds a listener that listens to palette manager events.
|
void |
attach(ilog.views.util.cssbeans.IlvCSSCompatible target)
Attaches the palette manager to a diagrammer or an SDM engine.
|
boolean |
contains(IlvPalette palette)
Returns whether the palette is contained in this manager.
|
void |
detach()
Detaches all diagrammers or SDM engines currently attached.
|
void |
detach(ilog.views.util.cssbeans.IlvCSSCompatible target)
Detaches the diagrammer or SDM engine.
|
protected void |
firePaletteAdded(IlvPalette palette)
Fires a event when adding a palette to the palette manager.
|
protected void |
firePaletteRemoved(IlvPalette palette)
Fires a event when removing a palette from the palette manager.
|
ilog.views.util.cssbeans.IlvCSSCompatible[] |
getAttachComponents()
Returns the components the palette manager is attached to.
|
ClassLoader |
getClassLoader()
Returns the class loader used by this palette manager.
|
IlvPalette |
getPalette(int index)
Returns the palette at specified index.
|
IlvPalette |
getPalette(String paletteResourceName)
Returns the palette that has the given palette resource name.
|
int |
getPaletteCount()
Returns the number of palettes.
|
int |
getPaletteIndex(IlvPalette palette)
Returns the index of a palette.
|
ArrayList |
getPalettesToUpdate(String resourceName)
Returns a list of palettes containing symbols referencing the given
resource name as subsymbol
|
IlvPalette |
getPaletteWithSymbol(String symbolFullID,
String symbolCSSResourceName,
String symbolClassName)
Returns the palette that contains a symbol that matches the input
parameters.
|
File |
getWorkingDirectory()
Returns the working directory in which palettes are saved before being
packaged as jar files
|
boolean |
isAttached(ilog.views.util.cssbeans.IlvCSSCompatible target)
Returns true if the input target is attached to this palette manager.
|
boolean |
isPaletteReadOnly(IlvPalette palette)
Indicates if the specified palette is locked in read-only mode.
|
IlvPalette |
load(String palettePackageName)
Loads a palette and adds it to the palette manager.
|
IlvPalette[] |
load(URL paletteJarURL)
This method loads the content of jar file containing one or several palette
definitions.
|
void |
remove(IlvPalette palette)
Removes the palette from the palette manager.
|
void |
removeAll()
Removes all palettes.
|
void |
removePaletteManagerListener(PaletteManagerListener l)
Removes a listener that listens to palette manager events.
|
void |
save(IlvPalette palette,
File jar)
Save the specified palette in the working directory and package it into a
jar file referenced by given URL The palette must belong to this palette
manager.
|
void |
save(IlvPalette palette,
File jar,
boolean cleanBefore,
boolean cleanAfter)
Save the specified palette in the working directory and package it into a
jar file referenced by given URL The palette must belong to this palette
manager.
|
void |
setAndCreateWorkingDirectory(File parent,
String directory)
This method is for convenience.
|
void |
setWorkingDirectory(File workingDirectory)
Sets the working directory in which palettes are saved before being
packaged as jar files.
|
void |
updateSymbolReferences(ArrayList palettesToUpdate,
String resourceName,
String oldName,
String newName)
Update reference to a subsymbol with a new resource name, in a list of
palettes.
|
public IlvPaletteManager()
public IlvPaletteManager(ilog.views.util.cssbeans.IlvCSSCompatible target)
public void attach(ilog.views.util.cssbeans.IlvCSSCompatible target)
It is possible to attach the palette manager to multiple targets at the
same time. When the palette manager is not anymore needed for a specific
target, call detach(IlvCSSCompatible)
. If the palette manager is
not anymore needed for any target, call detach()
. It cleans up the
memory of the palette manager.
If you attach the palette manager to a diagrammer, it is not necessary to attach it as well to the SDM engine contained in the diagrammer, since this is already handled automatically.
target
- Either an IlvDiagrammer
or an
IlvSDMEngine
.detach()
,
getAttachComponents()
public void detach(ilog.views.util.cssbeans.IlvCSSCompatible target)
target
- Either an IlvDiagrammer
or an
IlvSDMEngine
that was previously attached to the
manager.attach(ilog.views.util.cssbeans.IlvCSSCompatible)
public void detach()
public ilog.views.util.cssbeans.IlvCSSCompatible[] getAttachComponents()
IlvDiagrammer
or an
IlvSDMEngine
.attach(ilog.views.util.cssbeans.IlvCSSCompatible)
public boolean isAttached(ilog.views.util.cssbeans.IlvCSSCompatible target)
public ClassLoader getClassLoader()
null
if the allocation of the special class loader for
palettes was not successful. This happens usually only in applets that
don't have the permission to manipulate class loaders.public void add(IlvPalette palette)
PaletteManagerEvent
is fired through the
paletteAdded(PaletteManagerEvent evt)
method of
PaletteListener
class.
If is not possible to add the same IlvPalette
object to two
different palette managers. You must first remove it from one palette
manager before adding it to another palette manager.
palette
- The palette to add.public void remove(IlvPalette palette)
PaletteManagerEvent
is fired through the
paletteRemoved(PaletteManagerEvent evt)
method of
PaletteListener
class.palette
- The palette to remove.public void removeAll()
public IlvPalette getPalette(String paletteResourceName)
paletteResourceName
- The palette resource name to search forIlvPalette.getPaletteResourceName()
public IlvPalette getPalette(int index)
index
- The index of the palette.public int getPaletteCount()
public boolean contains(IlvPalette palette)
true
if the palette has already been added in the
palette manager, otherwise false
public IlvPalette getPaletteWithSymbol(String symbolFullID, String symbolCSSResourceName, String symbolClassName)
null
.symbolFullID
- The full ID of the symbol. Can be null
.symbolCSSResourceName
- The resource access string to the symbol CSS.symbolClassName
- The class name of the symbol.IlvPaletteBaseObject.getFullID()
,
IlvPaletteSymbol.getCSSResourceName()
,
IlvPaletteSymbol.getClassName()
public void addPaletteManagerListener(PaletteManagerListener l)
public void removePaletteManagerListener(PaletteManagerListener l)
protected void firePaletteAdded(IlvPalette palette)
palette
- The palette which has been added.protected void firePaletteRemoved(IlvPalette palette)
palette
- The palette which has been removed.public int getPaletteIndex(IlvPalette palette)
palette
- The palettepublic IlvPalette[] load(URL paletteJarURL) throws IOException
IlvPalette
instance is created and initialized
for each palette definition, and is added in this palette manager.
This method can be used to load palettes dynamically at runtime from jar
files. However, this works in applets only if the applet has the permission
to manipulate files and to allocate class loaders. If you implement an
applet that will not have the appropriate permissions, you should put all
palettes used by the applet into the class path of the applet and load them
by load(String)
instead. If the palette to load has the same jar
URL that one which is already loaded then it will not be loaded again and
only one instance of this palette will be stored in the manager.
paletteJarURL
- The URL of the jar file containing the palette descriptions.SecurityException
- If this method is used in an applet that has not the permissions
to allocate a class loader.IOException
load(String)
public IlvPalette load(String palettePackageName) throws IOException
IlvPalette.setPackageName(java.lang.String)
), for instance
dir1/dir2/.../dirN/
.
This method can only be used if the palette was added to the class path of
the applet or application. The palette is searched on the class path and if
found, it is added to this palette manager and returned as result. If the
palette is not found on the class path, null
is returned.
In order to load palettes from jar files that are not on the class path,
use load(URL)
.
palettePackageName
- The package name of the palette.null
if the palette cannot be
loaded.IOException
load(URL)
public void save(IlvPalette palette, File jar) throws IOException
palette
- The palette to saved.jar
- The jar file.IOException
setWorkingDirectory(java.io.File)
,
save(IlvPalette,File,boolean,boolean)
public void save(IlvPalette palette, File jar, boolean cleanBefore, boolean cleanAfter) throws IOException
cleanBefore
is true, the working
directory is cleaned before saving the palette. This avoids that any old
files of the working directory are contained in the resulting palette. If
the flag cleanAfter
is true, the working directory is cleaned
after saving the palette.palette
- The palette to saved.jar
- The jar file.cleanBefore
- Whether the working directory is cleaned before savingcleanAfter
- Whether the working directory is cleaned after savingIOException
setWorkingDirectory(java.io.File)
public File getWorkingDirectory()
public void setWorkingDirectory(File workingDirectory)
workingDirectory
- the new current working directorypublic void setAndCreateWorkingDirectory(File parent, String directory) throws IOException
null
, it sets the
working directory relative to the current directory (usually the directory
where the application started). If the working directory does not exist, it
tries to create the working directory.parent
- The parent directory.directory
- The path name of the working directory.IOException
public boolean isPaletteReadOnly(IlvPalette palette)
load(String)
are read-only.palette
- The palettepublic void updateSymbolReferences(ArrayList palettesToUpdate, String resourceName, String oldName, String newName)
palettesToUpdate
- List of palettes to updateresourceName
- Resource name to searcholdName
- Name to updatenewName
- New name© Copyright Rogue Wave Software, Inc. 1997, 2018. All Rights Reserved.