public class SnakePluginList extends Object implements IQuimpSerialize
This class keeps configuration for all plugin slots but for one frame. If you look for global
Configuration check BOAState.snakePluginListSnapshots
. Note
also that each plugin is instanced only once by PluginFactory
so their configuration must
be updated for each frame separately.
Related to GUI, first plugin is at index 0, etc. Keeps also UI settings activating or
deactivating plugins. Produces plugins from their names using provided
PluginFactory
The sPluginList is
serialized
(saved as JSON object). Because serialization does not touch plugins (understood as jars)
directly and moreover they reference the same object among frames, their
configuration and state must be stored locally in Plugin object. This task is
must be
accomplished on any change in plugin configuration, serialisation and deserialisation. Check
afterSerialize()
, beforeSerialize()
BOAState.restore(int)
and BOAState.store(int)
. From plugin side it is enough to
use IQuimpPluginSynchro
interface to store its
current configuration locally.
For the whole stack of images, plugin stack is kept for each frame
(BOAState.snakePluginListSnapshots
) together with updated configuration inside
SnakePluginList.Plugin
. Browsing through frames upload configuration to plugin for each
frame.
This class is serializable and it is part of QuimP config.
The most important use cases are:
During initialization basic structures are created. Note that plugins are stored in
intermediate
class SnakePluginList.Plugin
that holds current state of plugin:
During setInstance the instance of plugin is created and assign to Plugin object
During Serialize plugins are prepared for serialization what means saving current state of plugins like:
During Deletion of plugin the new empty plugin is created in place of old one
During Set Active state, the internal state of plugin is set to active. This is important for
method SnakePluginList.Plugin.isExecutable()
.
BOA_.run(String)
Constructor and Description |
---|
SnakePluginList()
Default constructor.
|
SnakePluginList(int s,
PluginFactory pf,
ViewUpdater vu)
Main constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
afterSerialize()
This method is called after restoring object from JSON but before returning the object.
|
void |
beforeSerialize()
Fills fields in Plugin class related to configuration and version.
|
void |
clear()
Deletes all plugins from list and closes theirs windows.
|
void |
closeAllWindows()
Close all opened plugins windows.
|
void |
deletePlugin(int i)
Deletes plugin from memory.
|
void |
downloadPluginsConfig()
Download configuration from all opened plugins into internal structure.
|
ParamList |
getConfig(int i)
Return i-th plugin configuration.
|
SnakePluginList |
getDeepCopy()
Copy method.
|
IQuimpCorePlugin |
getInstance(int i)
Return i-th instance of plugin.
|
List<com.github.celldynamics.quimp.SnakePluginList.Plugin> |
getList()
Returns unmodifiable list of plugins.
|
String |
getName(int i)
Return i-th plugin name.
|
ArrayList<String> |
getPluginNames(int type)
Return names of plugins of given type registered in PluginFactory associated with this
object.
|
SnakePluginList |
getShallowCopy()
Copy method.
|
String |
getVer(int i)
Return i-th plugin version.
|
boolean |
isActive(int i)
Check if plugin is active.
|
boolean |
isRefListEmpty()
Check if list of references contains all null elements.
|
void |
setActive(int i,
boolean act)
Activate or deactivate plugin.
|
void |
setInstance(int i,
String name,
boolean act)
Sets instance of plugin on slot i.
|
void |
updateRefs(PluginFactory pf,
ViewUpdater vu)
Updates references of external object connected in constructor.
|
void |
uploadPluginsConfig()
Transfer locally stored config to plugins instance for current list of plugin.
|
public SnakePluginList()
Create empty Plugin object that refers to nothing
public SnakePluginList(int s, PluginFactory pf, ViewUpdater vu)
s
- Number of supported pluginspf
- Deliverer of pluginsvu
- ViewUpdater to be connected to pluginpublic SnakePluginList getShallowCopy()
Returns copy of current object with some limitations. It does not copy loaded plugin (ref).
Should be called after SnakePluginList.Plugin.downloadPluginConfig()
to make sure
that config, ver are filled correctly
public SnakePluginList getDeepCopy()
Returns copy of current object.It does copy loaded plugin (ref). It requires that plugins must be correctly instanced. This code copies plugin stack between frames. Note double afterSerialise():
qState.snakePluginList.clear();
// snakePluginListSnapshots keeps only params and name, whereas deepCopy requires real
// instance to download config from it.
SnakePluginList previous = qState.snakePluginListSnapshots.get(frameCopyFrom - 1);
// So create instances on copy first (config will be uploaded here)
previous.afterSerialize();
// and make deep copy downloading config back
qState.snakePluginList = previous.getDeepCopy();
qState.snakePluginList.afterSerialize(); // instance all plugins
qState.store(qState.boap.frame); // copy to current snapshot
recalculatePlugins(); // update screen
All copied plugin will refer to the same jar thus they will share e.g. configuration
parameters. To have independent copies afterSerialize()
should be called on the list.
Refer to this code making full independent copies of plugins from current frame over all
frames:
SnakePluginList tmp = qState.snakePluginList.getDeepCopy();
for (int i = 0; i < qState.snakePluginListSnapshots.size(); i++) {
// make a deep copy
qState.snakePluginListSnapshots.set(i, tmp.getDeepCopy());
// instance separate copy of jar for this plugin
qState.snakePluginListSnapshots.get(i).afterSerialize();
}
int cf = qState.boap.frame;
for (boap.frame = 1; boap.frame <= boap.getFrames(); qState.boap.frame++) {
imageGroup.updateToFrame(boap.frame);
recalculatePlugins();
}
qState.boap.frame = cf;
imageGroup.updateToFrame(qState.boap.frame);
public void updateRefs(PluginFactory pf, ViewUpdater vu)
External references are not copied by getShallowCopy()
thus they should be
reinitialized after that operation
pf
- new PluginFactoryvu
- new ViewUpdaterpublic List<com.github.celldynamics.quimp.SnakePluginList.Plugin> getList()
Particular fields in Plugin may not be valid unless beforeSerialize() is called.
public IQuimpCorePlugin getInstance(int i)
i
- Number of plugin to returnpublic String getName(int i)
i
- Number of plugin to returnpublic String getVer(int i)
i
- Number of plugin to returnpublic ParamList getConfig(int i)
i
- Number of plugin to returnpublic boolean isActive(int i)
i
- Number of plugin to checkpublic void setInstance(int i, String name, boolean act) throws QuimpPluginException
If there is other plugin there, it replaces instance keeping its selection state. Connects also ViewUpdater and data to plugin if necessary.
i
- Slot to be setname
- Name of plugin - must be registered in PluginFactory or ref will be nullact
- true for active plugin, false for inactiveQuimpPluginException
- When instance can not be createdpublic void setActive(int i, boolean act)
i
- Slot to be setact
- true for active plugin, false for inactivepublic void deletePlugin(int i)
i
- Number of slot to deletepublic void clear()
public boolean isRefListEmpty()
public void downloadPluginsConfig()
Configuration is kept locally for serialisation purposes.
beforeSerialize()
public void uploadPluginsConfig()
downloadPluginsConfig()
public void beforeSerialize()
This method should be called directly before saving to have most recent options.
beforeSerialize
in interface IQuimpSerialize
Serializer.save(String)
public void afterSerialize()
IQuimpSerialize
afterSerialize
in interface IQuimpSerialize
Serializer.load(String)
public void closeAllWindows()
public ArrayList<String> getPluginNames(int type)
type
- requested plugin type PluginFactory
PluginFactory.getPluginNames(int)
Copyright © 2002–2019 Department of Computer Science, Warwick University. All rights reserved.