Class MetadataSource
- java.lang.Object
-
- ca.cgjennings.apps.arkham.project.MetadataSource
-
- Direct Known Subclasses:
MetadataSource.ThreadedMetadataSource
public class MetadataSource extends java.lang.Object
An object that can determine metadata for one or more file types. Note that ifappliesTo(ca.cgjennings.apps.arkham.project.Member)
returnsfalse
for a given member, then the result of passing that member to any other method is undefined.A typical metadata source is shared between many different members, and may even represent more than one type of file. For this reason, methods that query metadata require you to pass in the specific member for which the data is desired.
- Since:
- 2.1
- Author:
- Chris Jennings
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
MetadataSource.PropertyConsumer
This interface is implemented by objects that want to access textual metadata.static class
MetadataSource.ThreadedMetadataSource
An abstract helper class for creating metadata sources that fill in some of their data from a background thread.
-
Field Summary
Fields Modifier and Type Field Description static javax.swing.Icon
ICON_AUTOMATION_SCRIPT
static javax.swing.Icon
ICON_BLANK
static javax.swing.Icon
ICON_CARD_LAYOUT
static javax.swing.Icon
ICON_CLASS
static javax.swing.Icon
ICON_CLASS_MAP
static javax.swing.Icon
ICON_COLLECTION
static javax.swing.Icon
ICON_CONVERSION_MAP
static javax.swing.Icon
ICON_COPIES_LIST
static javax.swing.Icon
ICON_DICT_CPL
static javax.swing.Icon
ICON_DICT_TST
static javax.swing.Icon
ICON_DOCUMENT
static javax.swing.Icon
ICON_EON_DEFAULT
static javax.swing.Icon
ICON_EON_EXTENSION
static javax.swing.Icon
ICON_EON_LIBRARY
static javax.swing.Icon
ICON_EON_PLUGIN
static javax.swing.Icon
ICON_EON_THEME
static javax.swing.Icon
ICON_FILE
static javax.swing.Icon
ICON_FOLDER
static javax.swing.Icon
ICON_FONT
static javax.swing.Icon
ICON_HTML
static javax.swing.Icon
ICON_IMAGE
static javax.swing.Icon
ICON_JAVA
static javax.swing.Icon
ICON_MARKDOWN
static javax.swing.Icon
ICON_PACKED_BUNDLE
static javax.swing.Icon
ICON_PLUGIN_ROOT
static javax.swing.Icon
ICON_PROJECT
static javax.swing.Icon
ICON_PROPERTIES
static javax.swing.Icon
ICON_SCRIPT
static javax.swing.Icon
ICON_SETTINGS
static javax.swing.Icon
ICON_SILHOUETTES
static javax.swing.Icon
ICON_STYLE_SHEET
static javax.swing.Icon
ICON_TABLE
static javax.swing.Icon
ICON_TASK
static javax.swing.Icon
ICON_TASK_CASEBOOK
static javax.swing.Icon
ICON_TASK_DECK
static javax.swing.Icon
ICON_TASK_DOCUMENTATION
static javax.swing.Icon
ICON_TASK_EXPBOARD
static javax.swing.Icon
ICON_TASK_FACTORY
static javax.swing.Icon
ICON_TASK_GROUP
static javax.swing.Icon
ICON_TASK_PLUGIN
static javax.swing.Icon
ICON_TEXT_INDEX
static javax.swing.Icon
ICON_TILE_SET
static javax.swing.Icon
ICON_TYPESCRIPT
static javax.swing.Icon
ICON_VECTOR_IMAGE
-
Constructor Summary
Constructors Constructor Description MetadataSource()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected static void
add(MetadataSource.PropertyConsumer pc, Member m, java.lang.String key, boolean value)
Adds a new, localized boolean property to a consumer.protected static void
add(MetadataSource.PropertyConsumer pc, Member m, java.lang.String key, java.awt.image.BufferedImage image)
Adds a new, localized thumbnail image to a consumer.protected static void
add(MetadataSource.PropertyConsumer pc, Member m, java.lang.String key, java.lang.String value)
Adds a new, localized property to a consumer.protected static void
add(MetadataSource.PropertyConsumer pc, Member m, java.lang.String key, javax.swing.Icon image)
Adds a new, localized thumbnail image to a consumer.boolean
appliesTo(Member m)
Returnstrue
if this source is intended to provide metadata for a given project member.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.java.nio.charset.Charset
getDefaultCharset(Member m)
Returns a character set encoding for the specified member if it represents a character-based file.java.lang.String
getDescription(Member m)
Returns a short description of the type of file represented by the specified member.ThemedIcon
getIcon(Member m)
Return an icon that is appropriate for a particular member.java.util.Map<java.lang.String,java.lang.Object>
getMetadata(Member m)
Returns the metadata that would be generated byfillInMetadata(ca.cgjennings.apps.arkham.project.Member, ca.cgjennings.apps.arkham.project.MetadataSource.PropertyConsumer)
as aMap
.MetadataSource
getSpecificInstanceFor(Member m)
After locating the correct source for a given member, a specific instance is requested by calling this method.protected static javax.swing.ImageIcon
thumbnail(java.awt.image.BufferedImage image)
Creates a thumbnail version of an image.
-
-
-
Field Detail
-
ICON_PROJECT
public static final javax.swing.Icon ICON_PROJECT
-
ICON_FOLDER
public static final javax.swing.Icon ICON_FOLDER
-
ICON_FILE
public static final javax.swing.Icon ICON_FILE
-
ICON_IMAGE
public static final javax.swing.Icon ICON_IMAGE
-
ICON_VECTOR_IMAGE
public static final javax.swing.Icon ICON_VECTOR_IMAGE
-
ICON_JAVA
public static final javax.swing.Icon ICON_JAVA
-
ICON_SCRIPT
public static final javax.swing.Icon ICON_SCRIPT
-
ICON_AUTOMATION_SCRIPT
public static final javax.swing.Icon ICON_AUTOMATION_SCRIPT
-
ICON_TYPESCRIPT
public static final javax.swing.Icon ICON_TYPESCRIPT
-
ICON_SETTINGS
public static final javax.swing.Icon ICON_SETTINGS
-
ICON_PROPERTIES
public static final javax.swing.Icon ICON_PROPERTIES
-
ICON_COLLECTION
public static final javax.swing.Icon ICON_COLLECTION
-
ICON_TABLE
public static final javax.swing.Icon ICON_TABLE
-
ICON_HTML
public static final javax.swing.Icon ICON_HTML
-
ICON_MARKDOWN
public static final javax.swing.Icon ICON_MARKDOWN
-
ICON_STYLE_SHEET
public static final javax.swing.Icon ICON_STYLE_SHEET
-
ICON_PLUGIN_ROOT
public static final javax.swing.Icon ICON_PLUGIN_ROOT
-
ICON_CLASS
public static final javax.swing.Icon ICON_CLASS
-
ICON_BLANK
public static final javax.swing.Icon ICON_BLANK
-
ICON_COPIES_LIST
public static final javax.swing.Icon ICON_COPIES_LIST
-
ICON_DOCUMENT
public static final javax.swing.Icon ICON_DOCUMENT
-
ICON_FONT
public static final javax.swing.Icon ICON_FONT
-
ICON_EON_DEFAULT
public static final javax.swing.Icon ICON_EON_DEFAULT
-
ICON_EON_PLUGIN
public static final javax.swing.Icon ICON_EON_PLUGIN
-
ICON_EON_EXTENSION
public static final javax.swing.Icon ICON_EON_EXTENSION
-
ICON_EON_THEME
public static final javax.swing.Icon ICON_EON_THEME
-
ICON_EON_LIBRARY
public static final javax.swing.Icon ICON_EON_LIBRARY
-
ICON_PACKED_BUNDLE
public static final javax.swing.Icon ICON_PACKED_BUNDLE
-
ICON_CLASS_MAP
public static final javax.swing.Icon ICON_CLASS_MAP
-
ICON_CONVERSION_MAP
public static final javax.swing.Icon ICON_CONVERSION_MAP
-
ICON_SILHOUETTES
public static final javax.swing.Icon ICON_SILHOUETTES
-
ICON_TILE_SET
public static final javax.swing.Icon ICON_TILE_SET
-
ICON_CARD_LAYOUT
public static final javax.swing.Icon ICON_CARD_LAYOUT
-
ICON_DICT_CPL
public static final javax.swing.Icon ICON_DICT_CPL
-
ICON_DICT_TST
public static final javax.swing.Icon ICON_DICT_TST
-
ICON_TEXT_INDEX
public static final javax.swing.Icon ICON_TEXT_INDEX
-
ICON_TASK
public static final javax.swing.Icon ICON_TASK
-
ICON_TASK_PLUGIN
public static final javax.swing.Icon ICON_TASK_PLUGIN
-
ICON_TASK_FACTORY
public static final javax.swing.Icon ICON_TASK_FACTORY
-
ICON_TASK_EXPBOARD
public static final javax.swing.Icon ICON_TASK_EXPBOARD
-
ICON_TASK_CASEBOOK
public static final javax.swing.Icon ICON_TASK_CASEBOOK
-
ICON_TASK_DECK
public static final javax.swing.Icon ICON_TASK_DECK
-
ICON_TASK_DOCUMENTATION
public static final javax.swing.Icon ICON_TASK_DOCUMENTATION
-
ICON_TASK_GROUP
public static final javax.swing.Icon ICON_TASK_GROUP
-
-
Method Detail
-
appliesTo
public boolean appliesTo(Member m)
Returnstrue
if this source is intended to provide metadata for a given project member. The base class returnstrue
for anything, as it provides the fallback implementation for unspecialized file types.- Parameters:
m
- the member to check for applicability- Returns:
true
if this source can provide metadata about the specified member, otherwisefalse
-
getSpecificInstanceFor
public MetadataSource getSpecificInstanceFor(Member m)
After locating the correct source for a given member, a specific instance is requested by calling this method. The base class simply returnsthis
, which shares the source with all members that it applies to. Subclasses may return an instance that is unique to a particular member. For example, they might supply a unique icon that is a thumbnail version of the member.- Parameters:
m
- the member to request a more specific source for- Returns:
- a source that provides the most specific available data for
m
, possiblythis
- Throws:
java.lang.IllegalArgumentException
- if this source does not apply tom
-
getDescription
public java.lang.String getDescription(Member m)
Returns a short description of the type of file represented by the specified member.- Parameters:
m
- the member to fetch a description of- Returns:
- a short description of
m
, typically 2-3 words
-
getIcon
public ThemedIcon getIcon(Member m)
Return an icon that is appropriate for a particular member. Override this to provide a suitable icon for the file type.The base implementation provides built-in icons for certain common file types, and otherwise attempts to fetch the system icon for the file type.
- Parameters:
m
- the member to locate an icon for- Returns:
- an icon appropriate for
m
-
fillInMetadata
public void fillInMetadata(Member m, MetadataSource.PropertyConsumer pc)
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
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.- Parameters:
pc
- the entity that should receive property data
-
fillInMetadataImpl
protected void fillInMetadataImpl(Member m, MetadataSource.PropertyConsumer pc)
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.- Parameters:
m
- the member to publish metadata aboutpc
- the consumer to publish metadata to
-
add
protected static void add(MetadataSource.PropertyConsumer pc, Member m, java.lang.String key, java.lang.String value)
Adds a new, localized property to a consumer. A convenience method to help subclasses writefillInMetadataImpl(ca.cgjennings.apps.arkham.project.Member, ca.cgjennings.apps.arkham.project.MetadataSource.PropertyConsumer)
implementations.- Parameters:
pc
- the consumer to write tom
- the member that the metadata applies tokey
- the interface string key for the metadata labelvalue
- the metadata value
-
add
protected static void add(MetadataSource.PropertyConsumer pc, Member m, java.lang.String key, boolean value)
Adds a new, localized boolean property to a consumer. A convenience method to help subclasses writefillInMetadataImpl(ca.cgjennings.apps.arkham.project.Member, ca.cgjennings.apps.arkham.project.MetadataSource.PropertyConsumer)
implementations.- Parameters:
pc
- the consumer to write tom
- the member that the metadata applies tokey
- the interface string key for the metadata labelvalue
- the metadata value
-
add
protected static void add(MetadataSource.PropertyConsumer pc, Member m, java.lang.String key, java.awt.image.BufferedImage image)
Adds a new, localized thumbnail image to a consumer. The thumbnail is created on the fly. A convenience method to help subclasses writefillInMetadataImpl(ca.cgjennings.apps.arkham.project.Member, ca.cgjennings.apps.arkham.project.MetadataSource.PropertyConsumer)
implementations.- Parameters:
pc
- the consumer to write tom
- the member that the metadata applies tokey
- the interface string key for the metadata labelimage
- the metadata value
-
add
protected static void add(MetadataSource.PropertyConsumer pc, Member m, java.lang.String key, javax.swing.Icon image)
Adds a new, localized thumbnail image to a consumer. The thumbnail has already been generated usingthumbnail(java.awt.image.BufferedImage)
. A convenience method to help subclasses writefillInMetadataImpl(ca.cgjennings.apps.arkham.project.Member, ca.cgjennings.apps.arkham.project.MetadataSource.PropertyConsumer)
implementations.- Parameters:
pc
- the consumer to write tom
- the member that the metadata applies tokey
- the interface string key for the metadata labelimage
- the metadata value
-
thumbnail
protected static javax.swing.ImageIcon thumbnail(java.awt.image.BufferedImage image)
Creates a thumbnail version of an image.- Parameters:
image
- the source image to convert to a thumbnail- Returns:
- if the source image is small, the source image; otherwise a smaller thumbnail version of the source image
-
getMetadata
public final java.util.Map<java.lang.String,java.lang.Object> getMetadata(Member m)
Returns the metadata that would be generated byfillInMetadata(ca.cgjennings.apps.arkham.project.Member, ca.cgjennings.apps.arkham.project.MetadataSource.PropertyConsumer)
as aMap
. UnlikefillInMetadata(ca.cgjennings.apps.arkham.project.Member, ca.cgjennings.apps.arkham.project.MetadataSource.PropertyConsumer)
, this method will block: the returned map will include all available metadata. The map's iterator is guaranteed to return keys in the same order as they would have been added in byfillInMetadata
. Be aware that the keys in this map are the names of the metadata entries, and that these are typically localized. Therefore, the key names will vary depending on the interface locale.- Returns:
- a map of the metadata associated with the member
- See Also:
MetadataSource.PropertyConsumer
,Language
-
getDefaultCharset
public java.nio.charset.Charset getDefaultCharset(Member m)
Returns a character set encoding for the specified member if it represents a character-based file. If it is not, then this method returnsnull
.- Parameters:
m
- a member to obtain a character set for- Returns:
- the character set to use when reading the member as a character
stream, or
null
if the member is not a kind of text file known to this source
-
-