Class AttributedItemContainer

All Implemented Interfaces:
Styleable, EventTarget

public class AttributedItemContainer extends VBox
The AttributedItemContainer class represents a UI component that displays an item's image along with its attribution information.
  • Field Details

    • imageView

      private final ImageView imageView
      The ImageView for displaying the item's image.
    • loadImageTask

      private Task<Image> loadImageTask
      The task used to load the image asynchronously.
    • desktop

      private static Desktop desktop
      The Desktop instance used to open URLs in the default browser. Used in testing to allow for mocking to disable actual browser opening.
  • Constructor Details

    • AttributedItemContainer

      public AttributedItemContainer(Item item)
      Creates an AttributedItemContainer for the given item, initializing the image view and attribution flow.
      Parameters:
      item - The item whose image and attribution information are being displayed in this container.
      Preconditions:
      item should contain valid data for the image URL and attribution information. The AttributedItemContainer should be properly initialized to display the item's image and attribution information. The loadImageTask should be not initialized, it will be set up to load the image asynchronously within this constructor.
      Postconditions:
      The variable passed into loadImageTask will be initialized to a Task that loads the image from the item's image URL asynchronously.
  • Method Details

    • stopLoadingImage

      @Generated public void stopLoadingImage()
      Stops the asynchronous loading of the image in this AttributedItemContainer. This method can be called when the container is no longer visible or needed, to free up resources and prevent unnecessary loading of images that are not being displayed.
      Postconditions:
      The asynchronous image loading task for this AttributedItemContainer is stopped, preventing any further loading of the image that is not being displayed.
    • makeAttributionFlow

      private final TextFlow makeAttributionFlow(Item item)
      Creates a TextFlow for the attribution text with clickable links for the author and source.
      Parameters:
      item - The item whose data is being used to create the attribution flow, specifically the photo author and their URL.
      Returns:
      A TextFlow containing the attribution text with clickable links for the author and source.
      Preconditions:
      item should contain valid data for the photo author and their URL, as well as the source URL for Unsplash.
    • getImageView

      public ImageView getImageView()
      Getter for the ImageView in the AttributedItemContainer, which displays the item's image.
      Returns:
      The ImageView displaying the item's image in the AttributedItemContainer.
    • loadImageAsync

      private Task<Image> loadImageAsync(String imageUrl)
      Loads an image from a URL asynchronously to avoid blocking the UI thread, and sets it to the imageView once loaded.
      Parameters:
      imageUrl - The URL of the image to be loaded.
      Returns:
      A Task that loads the image from the specified URL and updates the imageView upon completion.
      Postconditions:
      The image from the specified URL will be loaded and displayed in the imageView of the AttributedItemContainer.