Class Viewport

  • All Implemented Interfaces:
    java.lang.Iterable<Component>, Sequence<Component>, ConstrainedVisual, Visual
    Direct Known Subclasses:
    Panorama, ScrollPane

    @DefaultProperty("view")
    public abstract class Viewport
    extends Container
    Abstract base class for viewport components. Viewports provide a windowed view on a component (called the "view") that is too large to fit within a given area. They are generally scrollable.

    Even though this class is a Container, no components should be added to it via the add() method. The component that gets the windowed (or scrollable) view should be added via the setView() method (or the "view" property).

    • Constructor Detail

      • Viewport

        public Viewport()
    • Method Detail

      • setSkin

        protected void setSkin​(Skin skin)
        Description copied from class: Component
        Sets the skin, replacing any previous skin.
        Overrides:
        setSkin in class Component
        Parameters:
        skin - The new skin.
      • getScrollTop

        public int getScrollTop()
        Returns:
        The current top scroll offset.
      • setScrollTop

        public void setScrollTop​(int newScrollTop)
        Set the new top scroll offset.
        Parameters:
        newScrollTop - The new top offset.
      • getScrollLeft

        public int getScrollLeft()
        Returns:
        The current left scroll offset.
      • setScrollLeft

        public void setScrollLeft​(int newScrollLeft)
        Set the new left scroll offset.
        Parameters:
        newScrollLeft - The new left offset.
      • getView

        public Component getView()
        Returns:
        The (single) component (typically a Container) that we are providing a windowed (or scrollable) view of.
      • setView

        public void setView​(Component newView)
        Set the single component (typically a Container) that we will provide a windowed (or scrollable) view of.
        Parameters:
        newView - The new component (container) we are viewing.
      • isConsumeRepaint

        public boolean isConsumeRepaint()
        Returns the consumeRepaint flag, which controls whether the viewport will propagate repaints to its parent or consume them. This flag enables skins to optimize viewport scrolling by blitting the display to reduce the required repaint area.
        Returns:
        true if this viewport will consume repaints that bubble up through it; false if it will propagate them up like normal.
      • setConsumeRepaint

        public void setConsumeRepaint​(boolean newConsumeRepaint)
        Sets the consumeRepaint flag, which controls whether the viewport will propagate repaints to its parent or consume them. This flag enables skins to optimize viewport scrolling by blitting the display to reduce the required repaint area.
        Parameters:
        newConsumeRepaint - true to consume repaints that bubble up through this viewport; false to propagate them up like normal.
      • getViewportBounds

        public Bounds getViewportBounds()
        Returns:
        The bounds of the Viewport within the container, for example, in ScrollPaneSkin, this excludes the scrollbars.
      • repaint

        public void repaint​(int x,
                            int y,
                            int width,
                            int height,
                            boolean immediate)
        Description copied from class: Component
        Flags an area as needing to be repainted.
        Overrides:
        repaint in class Container
        Parameters:
        x - Starting x-coordinate of area to repaint.
        y - Starting y-coordinate.
        width - Width of area to repaint.
        height - Height of area.
        immediate - Whether repaint should be done immediately.
      • remove

        public Sequence<Component> remove​(int index,
                                          int count)
        This method should not be called to remove child components from the Viewport because the viewable child(ren) are set by the setView(org.apache.pivot.wtk.Component) method instead. Any attempt to remove the "view" component with this method will result in an exception.
        Specified by:
        remove in interface Sequence<Component>
        Overrides:
        remove in class Container
        Parameters:
        index - The starting index to remove.
        count - The number of items to remove, beginning with index.
        Returns:
        A sequence containing the items that were removed.
      • getViewportListeners

        public ListenerList<ViewportListener> getViewportListeners()
        Returns:
        The current list of listeners for events on this viewport.
      • isRepaintAllViewport

        public boolean isRepaintAllViewport()
        Tell if the viewport painting mode is optimized (repaint only needed area, default), or repaint all.

        This is implemented as a workaround for various painting issues on some platforms. So, if you experience problems with the scrolled-in area not being painted properly by default, consider setting this property true using the setRepaintAllViewport method.

        Returns:
        false if optimized, otherwise true (repaint entire viewport)
      • setRepaintAllViewport

        public void setRepaintAllViewport​(boolean newRepaintAllViewport)
        Set the viewport painting mode.

        This is implemented as a workaround for various painting issues on some platforms. So, if you experience problems with the scrolled-in area not being painted properly by default, consider setting this property true (default is false).

        Parameters:
        newRepaintAllViewport - false means optimized (repaint only needed area, default), while true means repaint all