Class FitLayout

  • All Implemented Interfaces:
    LayoutManager
    Direct Known Subclasses:
    VideoLayout

    public class FitLayout
    extends Object
    implements LayoutManager
    Represents a LayoutManager which centers the first Component within its Container and, if the preferred size of the Component is larger than the size of the Container, scales the former within the bounds of the latter while preserving the aspect ratio. FitLayout is appropriate for Containers which display a single image or video Component in its entirety for which preserving the aspect ratio is important.
    Author:
    Lyubomir Marinov
    • Field Detail

      • DEFAULT_HEIGHT_OR_WIDTH

        protected static final int DEFAULT_HEIGHT_OR_WIDTH
        The default height and width to be used by FitLayout and its extenders in order to avoid falling back to zero height and/or width. Introduced to mitigate issues arising from the fact that a Component zero height and/or width.
        See Also:
        Constant Field Values
    • Constructor Detail

      • FitLayout

        public FitLayout()
    • Method Detail

      • addLayoutComponent

        public void addLayoutComponent​(String name,
                                       Component comp)
        Does nothing because this LayoutManager lays out only the first Component of the parent Container and thus doesn't need any String associations.
        Specified by:
        addLayoutComponent in interface LayoutManager
      • getComponent

        protected Component getComponent​(Container parent)
        Gets the first Component of a specific Container if there is such a Component.
        Parameters:
        parent - the Container to retrieve the first Component of
        Returns:
        the first Component of a specific Container if there is such a Component; otherwise, null
      • layoutComponent

        protected void layoutComponent​(Component component,
                                       Rectangle bounds,
                                       float alignmentX,
                                       float alignmentY)
      • layoutContainer

        protected void layoutContainer​(Container parent,
                                       float componentAlignmentX)
      • preferredLayoutSize

        public Dimension preferredLayoutSize​(Container parent)
        Since this LayoutManager lays out only the first Component of the specified parent Container, the preferred size of the Container is the preferred size of the mentioned Component.
        Specified by:
        preferredLayoutSize in interface LayoutManager
      • removeLayoutComponent

        public void removeLayoutComponent​(Component comp)
        Does nothing because this LayoutManager lays out only the first Component of the parent Container and thus doesn't need any String associations.
        Specified by:
        removeLayoutComponent in interface LayoutManager