Class SearchedItemPanel

All Implemented Interfaces:
Styleable, EventTarget

public class SearchedItemPanel extends HBox
The SearchedItemPanel class represents a UI component that displays the details of a single item in the search results.
  • Field Details

    • interactors

      private final List<SearchedItemPanelInteractor> interactors
      List of interactors to handle interactions with the item panel, such as adding the item to the RecentlyViewedQueue when the panel is clicked.
    • dateAddedFormatter

      private static final SimpleDateFormat dateAddedFormatter
      Date formatter for displaying the date added attribute of the item in a user-friendly format. The format used is "MMMM dd, yyyy" (e.g., "January 01, 2020").
    • attributedImage

      private final AttributedItemContainer attributedImage
      The container for the attributed image of the item, displaying the item's image along with any relevant attributes.
    • itemId

      private final String itemId
      The ID of the item being displayed in this panel. Used for checking if the panel is in the recently viewed queue.
    • firstInstanceMade

      public static boolean firstInstanceMade
      Static variable to track if the first instance of SearchedItemPanel has been created, used to assign an ID to the name label of the first instance for clicking on the instance in tests.
  • Constructor Details

    • SearchedItemPanel

      private SearchedItemPanel(Item item)
      Creates a SearchedItemPanel for the given item, displaying its image and details in a structured layout. The panel consists of a left side with the attributed image and a right side with textual details about the item. It also includes styling such as borders and spacing to enhance the visual presentation of the item information.
      Parameters:
      item - The item whose details are being displayed in this panel, used to populate both the attributed image and the other details.
      Preconditions:
      item should contain valid data for all attributes being displayed.
  • Method Details

    • create

      public static SearchedItemPanel create(Item item)
      Factory method to create a SearchedItemPanel instance.
      Parameters:
      item - The item whose details are being displayed in this panel.
      Returns:
      A new instance of SearchedItemPanel.
    • addSearchedItemPanelInteractor

      public void addSearchedItemPanelInteractor(SearchedItemPanelInteractor interactor)
      Sets a SearchedItemPanelInteractor to the panel to allow for interaction with the item panel
      Parameters:
      interactor - The SearchedItemPanelInteractor to set for handling interactions with the item panel.
      Preconditions:
      interactor should be properly implemented to handle interactions with the item panel, and the SearchedItemPanel should be properly initialized to allow for setting the interactor.
      Postconditions:
      The provided interactor is set to the SearchedItemPanel, allowing it to receive interaction events from the item panel. This enables functionality such as adding the item to the RecentlyViewedQueue when the panel is clicked.
    • getItemId

      public String getItemId()
      Getter for the item ID of the item being displayed in this panel, used for checking if the panel is in the RecentlyViewedQueue.
      Returns:
      The ID of the item being displayed in this panel.
    • stopLoadingImage

      public void stopLoadingImage()
      Stops the asynchronous loading of the image in the AttributedItemContainer. This method can be called when the panel 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 the AttributedItemContainer is stopped, preventing any further loading of the image that is not being displayed.
    • makeRightPanel

      public static VBox makeRightPanel(Item item)
      Fills the right panel with some of the data from the item.
      Parameters:
      item - The Item whose data is being displayed in the right panel.
      Returns:
      A VBox containing the labels with the item details, styled and formatted for display in the right panel of the SearchedItemPanel.
      Preconditions:
      item should contain valid data for all the attributes being displayed. rightPanel should be properly initialized to add the labels to.
      Postconditions:
      rightPanel will contain labels displaying the name, publisher, category, price, rating, stock quantity, and date added for the item, with consistent styling and formatting.
    • createLabel

      private static Label createLabel(String text)
      Helper method to create a label with consistent styling for the item details in the right panel. This method sets properties such as wrapping, maximum width, and alignment to ensure that the labels are displayed consistently.
      Parameters:
      text - The text to display in the label.
      Returns:
      A label with the specified text and consistent styling.