Class CocoAnnotationsHandler

  • All Implemented Interfaces:
    Destroyable, GlobalInfoSupporter, LoggingLevelHandler, LoggingSupporter, OptionHandler, SizeOfHandler, ContentHandler, Serializable

    public class CocoAnnotationsHandler
    extends AbstractContentHandler
    Displays the following image types with an overlay for the objects stored in the COCO JSON files: jpg,tif,tiff,bmp,gif,png,jpeg,wbmp
    Loads all JSON files in either the directory of the image or the alternative location.

    -logging-level <OFF|SEVERE|WARNING|INFO|CONFIG|FINE|FINER|FINEST> (property: loggingLevel)
        The logging level for outputting errors and debugging output.
        default: WARNING
     
    -color <java.awt.Color> (property: color)
        The color to use for the objects.
        default: #ff0000
     
    -use-colors-per-type <boolean> (property: useColorsPerType)
        If enabled, individual colors per type are used.
        default: true
     
    -type-color-provider <adams.gui.visualization.core.ColorProvider> (property: typeColorProvider)
        The color provider to use for the various types.
        default: adams.gui.visualization.core.DefaultColorProvider
     
    -type-regexp <adams.core.base.BaseRegExp> (property: typeRegExp)
        The regular expression that the types must match in order to get drawn (
        eg only plotting a subset).
        default: .*
        more: https://docs.oracle.com/javase/tutorial/essential/regex/
        https://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html
     
    -label-format <java.lang.String> (property: labelFormat)
        The label format string to use for the rectangles; '#' for index, '@' for
        type and '$' for short type (type suffix must be defined for '@' and '$'
        ); for instance: '# @'.
        default: $
     
    -label-font <java.awt.Font> (property: labelFont)
        The font to use for the labels.
        default: Display-PLAIN-14
     
    -finder <adams.data.objectfinder.ObjectFinder> (property: finder)
        The object finder to use.
        default: adams.data.objectfinder.AllFinder
     
    -use-alternative-location <boolean> (property: useAlternativeLocation)
        If enabled, the alternative location is used to locate the associated report
        rather than the directory with the image.
        default: false
     
    -alternative-location <adams.core.io.PlaceholderDirectory> (property: alternativeLocation)
        The alternative location to use look for associated reports.
        default: ${CWD}
     
    Author:
    FracPete (fracpete at waikato dot ac dot nz)
    See Also:
    Serialized Form
    • Field Detail

      • m_Color

        protected Color m_Color
        the color for the objects.
      • m_UseColorsPerType

        protected boolean m_UseColorsPerType
        whether to use colors per type.
      • m_TypeColorProvider

        protected ColorProvider m_TypeColorProvider
        the color provider to use.
      • m_TypeRegExp

        protected BaseRegExp m_TypeRegExp
        the regular expression for the types to draw.
      • m_LabelFormat

        protected String m_LabelFormat
        the label for the rectangles.
      • m_LabelFont

        protected Font m_LabelFont
        the label font.
      • m_Finder

        protected ObjectFinder m_Finder
        the object finder to use.
      • m_UseAlternativeLocation

        protected boolean m_UseAlternativeLocation
        whether to use an alternative location for the reports.
      • m_AlternativeLocation

        protected PlaceholderDirectory m_AlternativeLocation
        the alternative location.
    • Constructor Detail

      • CocoAnnotationsHandler

        public CocoAnnotationsHandler()
    • Method Detail

      • setColor

        public void setColor​(Color value)
        Sets the color to use for the objects.
        Parameters:
        value - the color
      • getColor

        public Color getColor()
        Returns the color to use for the objects.
        Returns:
        the color
      • colorTipText

        public String colorTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setUseColorsPerType

        public void setUseColorsPerType​(boolean value)
        Sets whether to use colors per type.
        Parameters:
        value - true if to use colors per type
      • getUseColorsPerType

        public boolean getUseColorsPerType()
        Returns whether to use colors per type.
        Returns:
        true if to use colors per type
      • useColorsPerTypeTipText

        public String useColorsPerTypeTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setTypeColorProvider

        public void setTypeColorProvider​(ColorProvider value)
        Sets the color provider to use for the types.
        Parameters:
        value - the provider
      • getTypeColorProvider

        public ColorProvider getTypeColorProvider()
        Returns the color provider to use for the types.
        Returns:
        the provider
      • typeColorProviderTipText

        public String typeColorProviderTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setTypeRegExp

        public void setTypeRegExp​(BaseRegExp value)
        Sets the regular expression that the types must match in order to get drawn.
        Parameters:
        value - the expression
      • getTypeRegExp

        public BaseRegExp getTypeRegExp()
        Returns the regular expression that the types must match in order to get drawn.
        Returns:
        the expression
      • typeRegExpTipText

        public String typeRegExpTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setLabelFormat

        public void setLabelFormat​(String value)
        Sets the label format.
        Parameters:
        value - the label format
      • getLabelFormat

        public String getLabelFormat()
        Returns the label format.
        Returns:
        the label format
      • labelFormatTipText

        public String labelFormatTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setLabelFont

        public void setLabelFont​(Font value)
        Sets the label font.
        Parameters:
        value - the label font
      • getLabelFont

        public Font getLabelFont()
        Returns the label font.
        Returns:
        the label font
      • labelFontTipText

        public String labelFontTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setFinder

        public void setFinder​(ObjectFinder value)
        Sets the finder to use for locating the objects.
        Parameters:
        value - the finder
      • getFinder

        public ObjectFinder getFinder()
        Returns the finder to use for locating the objects.
        Returns:
        the finder
      • finderTipText

        public String finderTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setUseAlternativeLocation

        public void setUseAlternativeLocation​(boolean value)
        Sets whether to use an alternative location for the reports.
        Parameters:
        value - true if to use
      • getUseAlternativeLocation

        public boolean getUseAlternativeLocation()
        Returns whether to use an alternative location for the reports.
        Returns:
        true if to use
      • useAlternativeLocationTipText

        public String useAlternativeLocationTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setAlternativeLocation

        public void setAlternativeLocation​(PlaceholderDirectory value)
        Sets the alternative location to use for the reports.
        Parameters:
        value - the location
      • getAlternativeLocation

        public PlaceholderDirectory getAlternativeLocation()
        Returns the alternative location to use for the reports.
        Returns:
        the location
      • alternativeLocationTipText

        public String alternativeLocationTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • getExtensions

        public String[] getExtensions()
        Returns the list of extensions (without dot) that this handler can take care of.
        Returns:
        the list of extensions (no dot)
      • determineBaseFile

        protected File determineBaseFile​(CocoAnnotationsHandler.CombinedPanel panel,
                                         File file)
        Determines the basefile, either current location or alternative one.
        Parameters:
        panel - the context panel
        file - the current image
        Returns:
        the (potentially) update path
      • locateJsonFiles

        protected File[] locateJsonFiles​(CocoAnnotationsHandler.CombinedPanel panel,
                                         File file)
        Locates all JSON files in relation to the file.
        Parameters:
        panel - the context panel
        file - the current image to view
      • refreshReportsIfNecessary

        protected void refreshReportsIfNecessary​(CocoAnnotationsHandler.CombinedPanel panel,
                                                 File file)
        Refreshes the report cache if necessary.
        Parameters:
        panel - the context panel
        file - the current image to view
      • filterReport

        protected Report filterReport​(Report report)
        Filters the objects in the report, if necessary.
        Parameters:
        report - the report to filter
        Returns:
        the filtered report (copy, in case filtering occurred)
      • loadFromJson

        protected Report loadFromJson​(CocoAnnotationsHandler.CombinedPanel panel,
                                      File file)
        Loads the report associated with the image file.
        Parameters:
        panel - the context panel
        file - the image file
        Returns:
        the report, null if not present or failed to load