Module org.jpo

Class PictureInfo

java.lang.Object
org.jpo.datamodel.PictureInfo
All Implemented Interfaces:
Serializable, GroupOrPicture

public class PictureInfo extends Object implements Serializable, GroupOrPicture
Objects of this type represent a single picture in the collection. Since SortableDefaultMutableTreeNodes allow user objects to be attached to the node this is a convenient place to store all the information that we have about a picture.

The class provides several convenience methods to access the information.

This class must implement the Serializable interface or Drag and Drop will not work.

See Also:
  • Constructor Details

    • PictureInfo

      public PictureInfo()
      Constructor without options. All strings are set to blanks
    • PictureInfo

      public PictureInfo(File imageFile, String description)
      Constructor with just filename as option.
      Parameters:
      imageFile - The file of the image
      description - Description
  • Method Details

    • getFormattedCreationTime

      public static String getFormattedCreationTime(Calendar dateTime)
      Returns the creationTime as a formatted String. If the dateTime is null a polite "Failed to Parse" string is returned
      Parameters:
      dateTime - the Calendar to format
      Returns:
      the creation time as a formatted string
    • getFormattedCreationTimeForTimestamp

      public String getFormattedCreationTimeForTimestamp()
      Returns the creationTime as a formatted String. If parsing doesn't work it returns an empty string
      Returns:
      the creation time as a formatted string
    • toString

      public String toString()
      returns the description of the image in the default toString method.
      Overrides:
      toString in class Object
      Returns:
      description
    • dumpToXml

      public void dumpToXml(BufferedWriter out, Path baseDir) throws IOException
      this method writes all attributes of the picture in the JPO xml data format with the highres and lowres locations passed in as parameters. This became necessary because when the XmlDistiller copies the pictures to a new location we don't want to write the URLs of the original pictures whilst all other attributes are retained.
      Parameters:
      out - The Buffered Writer receiving the xml data
      Throws:
      IOException - If there was an IO error
    • getRelativePath

      public static Path getRelativePath(File imageFile, Path baseDir)
    • getDescription

      public String getDescription()
      Returns the description of the image.
      Returns:
      The description of the image.
      See Also:
    • setDescription

      public void setDescription(String desc)
      Sets the description of the image.
      Parameters:
      desc - New description of the image.
      See Also:
    • appendToDescription

      public void appendToDescription(String s)
      Appends the text fragment to the description.
      Parameters:
      s - The text fragment to append.
    • descriptionContains

      public boolean descriptionContains(String searchString)
      Checks whether the searchString parameter is contained in the description. The search is case-insensitive.
      Parameters:
      searchString - The string to search for.
      Returns:
      true if found. false if not.
    • getImageLocation

      public String getImageLocation()
      Returns the full path to the highres picture. If the PictureInto doesn't have an image location an empty String is returned.
      Returns:
      The highres location
      See Also:
    • setImageLocation

      public void setImageLocation(@NotNull @NotNull File file)
      Sets the image location and sends a sendImageLocationChangedEvent.
      Parameters:
      file - The new file of the picture.
    • getImageFile

      public File getImageFile()
      returns the file handle to the highres picture.
      Returns:
      the highres location or null if there is a failure
    • getImageURIOrNull

      public URI getImageURIOrNull()
      returns the URI handle to the picture.
      Returns:
      The image location
    • appendToImageLocation

      public void appendToImageLocation(String s)
      Appends the text to the field (used by XML parser).
      Parameters:
      s - The text fragment to be added to the image Location
    • appendToImageFile

      public void appendToImageFile(String s, Path baseDir)
      Appends the text to the field (used by XML parser).
      Parameters:
      s - The text fragment to be added to the image Location
    • getSha256

      public String getSha256()
      Returns the SHA-256 of the contents of the file
      Returns:
      the SHA-256 of the image file or null if not calculated
    • calculateSha256

      public static String calculateSha256(File file) throws IOException
      calculates the SHA-256 hash of the picture.
      Returns:
      returns a HashCode object containing the SHA256 of the Image File
      Throws:
      IOException - if the underlying library encounters and IOException
    • setSha256

      public void setSha256()
      calculates the SHA-256 hash of the picture and saves it to the sha256 member variable. If the value changes it sends a PictureInfoChangedEvent
    • setSha256

      public void setSha256(String newSha256)
      calculates the SHA-256 hash of the picture and saves it to the fileHash member variable. If the value changes it sends a PictureInfoChangedEvent
    • appendToSha256

      public void appendToSha256(String s)
      Appends the text fragment to the sha256 field.
      Parameters:
      s - Text fragment
    • appendToFilmReference

      public void appendToFilmReference(String s)
      Appends the string to the filmReference field.
      Parameters:
      s - Fragment to append to Film Reference
    • getFilmReference

      public String getFilmReference()
      Returns the film reference.
      Returns:
      the film reference
    • setFilmReference

      public void setFilmReference(String newFilmReference)
      Sets the film reference.
      Parameters:
      newFilmReference - The new film reference.
    • appendToCreationTime

      public void appendToCreationTime(String textFragment)
      appends the text fragment to the creation time.
      Parameters:
      textFragment - The text fragment to add.
    • getCreationTime

      public String getCreationTime()
      Returns the creation Time.
      Returns:
      the creation Time
    • setCreationTime

      public void setCreationTime(String newCreationTime)
      Sets the creationTime.
      Parameters:
      newCreationTime - The new creation time.
    • getCreationTimeAsDate

      public Calendar getCreationTimeAsDate()
      Returns the creationTime as a Date object or null if the parsing failed.
      Returns:
      the creation time
    • getFormattedCreationTime

      public String getFormattedCreationTime()
      Returns the creationTime as a string after it has been parsed. Essentially this is a utility method to identify what the Date parser is doing.
      Returns:
      the creation time
    • appendToComment

      public void appendToComment(String textFragment)
      Appends the text fragment to the comment.
      Parameters:
      textFragment - the text fragment
    • getComment

      public String getComment()
      Returns the comment.
      Returns:
      The comment.
    • setComment

      public void setComment(String newComment)
      Sets the comment.
      Parameters:
      newComment - The new comment
    • appendToPhotographer

      public void appendToPhotographer(String textFragment)
      Appends the text fragment to the photographer field.
      Parameters:
      textFragment - The photographer.
    • getPhotographer

      public String getPhotographer()
      Returns the photographer.
      Returns:
      The Photographer.
    • setPhotographer

      public void setPhotographer(String newPhotographer)
      Sets the Photographer.
      Parameters:
      newPhotographer - The new Photographer
    • appendToCopyrightHolder

      public void appendToCopyrightHolder(String textFragment)
      appends the text fragment to the copyright holder field.
      Parameters:
      textFragment - The text fragment.
    • getCopyrightHolder

      public String getCopyrightHolder()
      returns the copyright holder.
      Returns:
      The copyright holder
    • setCopyrightHolder

      public void setCopyrightHolder(String newCopyrightHolder)
      Sets the copyright holder.
      Parameters:
      newCopyrightHolder - The copyright holder
    • appendToRotation

      public void appendToRotation(String textFragment)
      Appends the text fragment to the rotation field. does not send a rotationChangedEvent as the rotation has not yet been parsed
      Parameters:
      textFragment - Text fragment
    • parseRotation

      public void parseRotation()
      Converts the temporary rotationString to the rotation double.
    • getRotation

      public double getRotation()
      Returns the rotation.
      Returns:
      The rotation of the image.
    • setRotation

      public void setRotation(double rotation)
      Sets the rotation.
      Parameters:
      rotation - The new rotation for the PictureInfo.
    • setRotation

      public void setRotation(int rotation)
      Sets the rotation.
      Parameters:
      rotation - The new rotation for the PictureInfo.
    • rotate

      public void rotate(double angle)
      Changes the angle by the supplied angle the picture by an angle.
      Parameters:
      angle - the new angle
    • appendToLatLng

      public void appendToLatLng(String textFragment)
      appends the text fragment to the latlng string.
      Parameters:
      textFragment - The text fragment.
    • parseLatLng

      public void parseLatLng()
      Converts the temporary latLngString to a LatLng Point.
    • getLatLng

      public Point2D.Double getLatLng()
      returns the Latitude and Longitude.
      Returns:
      The Latitude and Longitude
    • setLatLng

      public void setLatLng(Point2D.Double newLatLng)
      Sets the Latitude and Longitude.
      Parameters:
      newLatLng - The latitude and longitude holder
    • setLatLng

      public void setLatLng(String newLatLng)
      Sets the Latitude and Longitude.
      Parameters:
      newLatLng - The latitude and longitude in the format of 2 doubles with an x
    • getLatLngString

      public String getLatLngString()
      returns the Latitude and Longitude as a String
      Returns:
      The latitude and longitude in the format of 2 doubles with an x
    • getCategoryAssignments

      public Set<Integer> getCategoryAssignments()
      Returns a Set of categories that have been applied to this picture
      Returns:
      the Set of categories
    • clearCategoryAssignments

      public void clearCategoryAssignments()
      removes all category Assignments
    • appendToCategoryAssignment

      public void appendToCategoryAssignment(String string)
      Appends the text fragment to the categoryAssignmentString field.
      Parameters:
      string - Text fragment
    • addCategoryAssignment

      public void addCategoryAssignment(String string)
      Adds to the index number received as a string to the Set of categories
      Parameters:
      string - Text fragment
    • addCategoryAssignment

      public void addCategoryAssignment(Integer key)
      Adds the supplied Object to the categoryAssignment HashSet. If the Object already existed it doesn't get added a second time.
      Parameters:
      key - the key to add
    • setCategoryAssignment

      public void setCategoryAssignment(@NotNull @NotNull Collection<Integer> ca)
      Sets the supplied Collection as the categories of the picture, clearing out any pre-existing ones.
      Parameters:
      ca - the supplied hash set
    • parseCategoryAssignment

      public void parseCategoryAssignment()
      Converts the temporary categoryAssignmentString to a categoryAssignment and calls addCategoryAssignment
    • containsCategory

      public boolean containsCategory(Integer key)
      Returns whether the category is part of the attributes of the picture
      Parameters:
      key - the key
      Returns:
      true if the key was in the categories
    • removeCategory

      public void removeCategory(Object key)
      Removes the supplied category from the picture if it was there
      Parameters:
      key - the key to search for
    • sendWasSelectedEvent

      public void sendWasSelectedEvent()
      Creates a PictureChangedEvent and sends it to inform listening objects that the node was selected. Strictly speaking this is not a PictureInfo level event but a node level event. However, because I have the PictureInfoChangeEvent structure in place this is a good place to put this notification.
    • sendWasUnselectedEvent

      public void sendWasUnselectedEvent()
      Creates a PictureChangedEvent and sends it to inform listening objects that the node was unselected. Strictly speaking this is not a PictureInfo level event but a node level event. However, because I have the PictureInfoChangeEvent structure in place this is a good place to put this notification.
    • sendWasMailSelectedEvent

      public void sendWasMailSelectedEvent()
      Creates a PictureChangedEvent and sends it to inform listening objects that the node was mailSelected. Strictly speaking this is not a PictureInfo level event but a node level event. However, because I have the PictureInfoChangeEvent structure in place this is a good place to put this notification.
    • sendWasMailUnselectedEvent

      public void sendWasMailUnselectedEvent()
      Creates a PictureChangedEvent and sends it to inform listening objects that the node was mailUnselected. Strictly speaking this is not a PictureInfo level event but a node level event. However, because I have the PictureInfoChangeEvent structure in place this is a good place to put this notification.
    • getClone

      public PictureInfo getClone()
      Returns a new PictureInfo object which is identical to the current one.
      Returns:
      a clone of the current PictureInfo object.
    • addPictureInfoChangeListener

      public void addPictureInfoChangeListener(PictureInfoChangeListener pictureInfoChangeListener)
      Registers a listener for picture info change events
      Parameters:
      pictureInfoChangeListener - The object that will receive notifications.
    • removePictureInfoChangeListener

      public void removePictureInfoChangeListener(PictureInfoChangeListener pictureInfoChangeListener)
      Removes the supplied listener
      Parameters:
      pictureInfoChangeListener - The listener that doesn't want to notifications anymore.
    • anyMatch

      public boolean anyMatch(String searchString)
      Checks whether the searchString parameter is contained in any of the fields. It doesn't check the checksum or rotation. It does check the description, highres name, film reference, creation time, comment and copyright holder
      Parameters:
      searchString - The string to search for.
      Returns:
      true if found. false if not.
    • compareTo

      public int compareTo(@NotNull @NotNull PictureInfo otherPictureInfo, Settings.FieldCodes sortField)
      Defines how PictureInfo objects compare themselves
      Parameters:
      otherPictureInfo - The other GroupInfo object
      sortField - which attribute to use in the comparison
      Returns:
      negative number if this is less than or Zero if same or positive number if other is less than this
    • setOwningNode

      public void setOwningNode(SortableDefaultMutableTreeNode sortableDefaultMutableTreeNode)
      Description copied from interface: GroupOrPicture
      A GroupOrPicture must be able to remember the node that owns it to facilitate traversal
      Specified by:
      setOwningNode in interface GroupOrPicture
      Parameters:
      sortableDefaultMutableTreeNode - The owning node
    • getOwningNode

      public SortableDefaultMutableTreeNode getOwningNode()
      Description copied from interface: GroupOrPicture
      Returns the node that owns this object
      Specified by:
      getOwningNode in interface GroupOrPicture
      Returns:
      the node that owns this object