Class MetadataSource.ThreadedMetadataSource
- java.lang.Object
-
- ca.cgjennings.apps.arkham.project.MetadataSource
-
- ca.cgjennings.apps.arkham.project.MetadataSource.ThreadedMetadataSource
-
- Enclosing class:
- MetadataSource
public abstract static class MetadataSource.ThreadedMetadataSource extends MetadataSource
An abstract helper class for creating metadata sources that fill in some of their data from a background thread. This prevents blocking the user interface to complete potentially complex or time-consuming operations, such as generating a preview thumbnail. Be careful to observe Swing threading restrictions.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ca.cgjennings.apps.arkham.project.MetadataSource
MetadataSource.PropertyConsumer, MetadataSource.ThreadedMetadataSource
-
-
Field Summary
-
Fields inherited from class ca.cgjennings.apps.arkham.project.MetadataSource
ICON_AUTOMATION_SCRIPT, ICON_BLANK, ICON_CARD_LAYOUT, ICON_CLASS, ICON_CLASS_MAP, ICON_COLLECTION, ICON_CONVERSION_MAP, ICON_COPIES_LIST, ICON_DICT_CPL, ICON_DICT_TST, ICON_DOCUMENT, ICON_EON_DEFAULT, ICON_EON_EXTENSION, ICON_EON_LIBRARY, ICON_EON_PLUGIN, ICON_EON_THEME, ICON_FILE, ICON_FOLDER, ICON_FONT, ICON_HTML, ICON_IMAGE, ICON_JAVA, ICON_MARKDOWN, ICON_PACKED_BUNDLE, ICON_PLUGIN_ROOT, ICON_PROJECT, ICON_PROPERTIES, ICON_SCRIPT, ICON_SETTINGS, ICON_SILHOUETTES, ICON_STYLE_SHEET, ICON_TABLE, ICON_TASK, ICON_TASK_CASEBOOK, ICON_TASK_DECK, ICON_TASK_DOCUMENTATION, ICON_TASK_EXPBOARD, ICON_TASK_FACTORY, ICON_TASK_GROUP, ICON_TASK_PLUGIN, ICON_TEXT_INDEX, ICON_TILE_SET, ICON_TYPESCRIPT, ICON_VECTOR_IMAGE
-
-
Constructor Summary
Constructors Constructor Description ThreadedMetadataSource()
ThreadedMetadataSource(boolean autopause)
Ifautopause
istrue
, thenpause()
will be called before callingfillInThreadedMetadataImpl
.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
fillInMetadata(Member m, MetadataSource.PropertyConsumer pc)
Publishes metadata to aMetadataSource.PropertyConsumer
.protected void
fillInMetadataImpl(Member m, MetadataSource.PropertyConsumer pc)
Called to publish metadata to a consumer.protected abstract void
fillInThreadedMetadataImpl(Member m, MetadataSource.PropertyConsumer pc)
This method is called from a background thread to allow the source to fill in additional metadata that may be expensive to generate.protected boolean
pause(MetadataSource.PropertyConsumer pc)
Briefly pauses the current thread, then returnsfalse
if the property consumer is no longer valid or the thread was interrupted.-
Methods inherited from class ca.cgjennings.apps.arkham.project.MetadataSource
add, add, add, add, appliesTo, getDefaultCharset, getDescription, getIcon, getMetadata, getSpecificInstanceFor, thumbnail
-
-
-
-
Constructor Detail
-
ThreadedMetadataSource
public ThreadedMetadataSource()
-
ThreadedMetadataSource
public ThreadedMetadataSource(boolean autopause)
Ifautopause
istrue
, thenpause()
will be called before callingfillInThreadedMetadataImpl
. If the property consumer becomes invalid during the pause, then the threaded metadata will not be requested.- Parameters:
autopause
-
-
-
Method Detail
-
fillInMetadata
public void fillInMetadata(Member m, MetadataSource.PropertyConsumer pc)
Description copied from class:MetadataSource
Publishes metadata to aMetadataSource.PropertyConsumer
. This method may return before all available data has been published and continue to add new data as it becomes available. Once all of the available data has been published, if the consumer is still valid, itsMetadataSource.PropertyConsumer.doneAddingProperties()
method will be called.The base class implementation calls
MetadataSource.fillInMetadataImpl(ca.cgjennings.apps.arkham.project.Member, ca.cgjennings.apps.arkham.project.MetadataSource.PropertyConsumer)
and then calls the consumer'sMetadataSource.PropertyConsumer.doneAddingProperties()
method. This will fill in the member's file type description and basic file-based metadata.Note: If you want to create a metadata source that adds some properties from another thread (because they take time to provide), use
MetadataSource.ThreadedMetadataSource
as your base class.- Overrides:
fillInMetadata
in classMetadataSource
pc
- the entity that should receive property data
-
fillInMetadataImpl
protected void fillInMetadataImpl(Member m, MetadataSource.PropertyConsumer pc)
Description copied from class:MetadataSource
Called to publish metadata to a consumer. The base class will publish basic metadata including the file type description. Classes that override the default implementation should call the super implementation first to fill in this basic information.- Overrides:
fillInMetadataImpl
in classMetadataSource
- Parameters:
m
- the member to publish metadata aboutpc
- the consumer to publish metadata to
-
pause
protected boolean pause(MetadataSource.PropertyConsumer pc)
Briefly pauses the current thread, then returnsfalse
if the property consumer is no longer valid or the thread was interrupted. This is called at the start of the background thread if the autopause option is enabled. It prevents the generation of expensive metadata when the user is quickly moving through the project members, such as when navigating the tree with the keyboard.- Returns:
true
if the thread should proceed with generating metadata
-
fillInThreadedMetadataImpl
protected abstract void fillInThreadedMetadataImpl(Member m, MetadataSource.PropertyConsumer pc)
This method is called from a background thread to allow the source to fill in additional metadata that may be expensive to generate.- Parameters:
m
- the member to fill in data forpc
- the consumer that will accept the data being produced
-
-