# Class SwipeableContainer

java.lang.Object
com.codename1.ui.Component
com.codename1.ui.Container
com.codename1.ui.SwipeableContainer

All Implemented Interfaces:
  `Animation, Editable, StyleListener, Iterable<Component>`

public class SwipeableContainer extends Container

`SwipeableContainer` allows us to side swipe a component and expose underlying configuration within it. This is useful for editing, ranking of elements within a set of components e.g. in the sample code below we use a ranking widget and swiping to expose the elements:

    public void showForm() {
      Form hi = new Form("Swipe", new BoxLayout(BoxLayout.Y_AXIS));
      hi.add(createRankWidget("A Game of Thrones", "1996")).
          add(createRankWidget("A Clash Of Kings", "1998")).
          add(createRankWidget("A Storm Of Swords", "2000")).
          add(createRankWidget("A Feast For Crows", "2005")).
          add(createRankWidget("A Dance With Dragons", "2011")).
          add(createRankWidget("The Winds of Winter", "TBD")).
          add(createRankWidget("A Dream of Spring", "TBD"));
      hi.show();
    }

    public SwipeableContainer createRankWidget(String title, String year) {
        MultiButton button = new MultiButton(title);
        button.setTextLine2(year);
        return new SwipeableContainer(FlowLayout.encloseCenterMiddle(createStarRankSlider()),
                button);
    }

    private void initStarRankStyle(Style s, Image star) {
        s.setBackgroundType(Style.BACKGROUND_IMAGE_TILE_BOTH);
        s.setBorder(Border.createEmpty());
        s.setBgImage(star);
        s.setBgTransparency(0);
    }

    private Slider createStarRankSlider() {
        Slider starRank = new Slider();
        starRank.setEditable(true);
        starRank.setMinValue(0);
        starRank.setMaxValue(10);
        Font fnt = Font.createTrueTypeFont("native:MainLight", "native:MainLight").
                derive(Display.getInstance().convertToPixels(5, true), Font.STYLE_PLAIN);
        Style s = new Style(0xffff33, 0, fnt, (byte)0);
        Image fullStar = FontImage.createMaterial(FontImage.MATERIAL_STAR, s).toImage();
        s.setOpacity(100);
        s.setFgColor(0);
        Image emptyStar = FontImage.createMaterial(FontImage.MATERIAL_STAR, s).toImage();
        initStarRankStyle(starRank.getSliderEmptySelectedStyle(), emptyStar);
        initStarRankStyle(starRank.getSliderEmptyUnselectedStyle(), emptyStar);
        initStarRankStyle(starRank.getSliderFullSelectedStyle(), fullStar);
        initStarRankStyle(starRank.getSliderFullUnselectedStyle(), fullStar);
        starRank.setPreferredSize(new Dimension(fullStar.getWidth() * 5, fullStar.getHeight()));
        return starRank;
    }

- ## Field Summary

  ### Fields inherited from class Component

  `BASELINE, BOTTOM, BRB_CENTER_OFFSET, BRB_CONSTANT_ASCENT, BRB_CONSTANT_DESCENT, BRB_OTHER, CENTER, CROSSHAIR_CURSOR, DEFAULT_CURSOR, DRAG_REGION_IMMEDIATELY_DRAG_X, DRAG_REGION_IMMEDIATELY_DRAG_XY, DRAG_REGION_IMMEDIATELY_DRAG_Y, DRAG_REGION_LIKELY_DRAG_X, DRAG_REGION_LIKELY_DRAG_XY, DRAG_REGION_LIKELY_DRAG_Y, DRAG_REGION_NOT_DRAGGABLE, DRAG_REGION_POSSIBLE_DRAG_X, DRAG_REGION_POSSIBLE_DRAG_XY, DRAG_REGION_POSSIBLE_DRAG_Y, E_RESIZE_CURSOR, HAND_CURSOR, LEFT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NW_RESIZE_CURSOR, RIGHT, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, TOP, W_RESIZE_CURSOR, WAIT_CURSOR`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `SwipeableContainer(Component bottomLeft, Component top)`
  Simple Constructor
  `SwipeableContainer(Component bottomLeft, Component bottomRight, Component top)`
  Simple Constructor

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `addSwipeOpenListener(ActionListener l)`
  Adds a listener to the SwipeableContainer which will cause an event to dispatch once the SwipeableContainer is fully opened
  `boolean`
  `animate()`
  Allows the animation to reduce "repaint" calls when it returns false.
  `void`
  `close()`
  Close the top component if it is currently opened.
  `protected void`
  `deinitialize()`
  Invoked to indicate that the component initialization is being reversed since the component was detached from the container hierarchy.
  `Component`
  `getComponentAt(int x, int y)`
  Returns a Component at coordinate (x, y).
  `SwipeableContainer`
  `getPreviouslyOpened()`
  returns a previously opened SwipeableContainer that should be automatically closed when starting to open this one.
  `protected void`
  `initComponent()`
  Allows subclasses to bind functionality that relies on fully initialized and "ready for action" component state
  `boolean`
  `isOpen()`
  Returns true if the top Component is currently opened
  `boolean`
  `isOpenedToLeft()`
  Returns true if the top Component is opened to the left side
  `boolean`
  `isOpenedToRight()`
  Returns true if the top Component is opened to the right side
  `boolean`
  `isSwipeActivated()`
  Returns true if swipe is activated
  `void`
  `openToLeft()`
  This method will open the top Component to the left if there is a Component to expose on the right.
  `void`
  `openToRight()`
  This method will open the top Component to the right if there is a Component to expose on the left.
  `void`
  `removeSwipeOpenListener(ActionListener l)`
  Removes the given listener from the SwipeableContainer
  `void`
  `setPreviouslyOpened(SwipeableContainer previouslyOpened)`
  set a previously open SwipeableContainer, it will be closed as soon as the user starts swiping this one.
  `void`
  `setSwipeActivated(boolean swipeActivated)`
  disable/enable dragging of the top Component

  ### Methods inherited from class Container

  `add, add, add, add, add, add, addAll, addComponent, addComponent, addComponent, addComponent, animateHierarchy, animateHierarchyAndWait, animateHierarchyFade, animateHierarchyFadeAndWait, animateLayout, animateLayoutAndWait, animateLayoutFade, animateLayoutFadeAndWait, animateUnlayout, animateUnlayoutAndWait, applyRTL, calcPreferredSize, cancelRepaints, clearClientProperties, constrainHeightWhenScrollable, constrainWidthWhenScrollable, contains, createAnimateHierarchy, createAnimateHierarchyFade, createAnimateLayout, createAnimateLayoutFade, createAnimateLayoutFadeAndWait, createAnimateMotion, createAnimateUnlayout, createReplaceTransition, dragInitiated, drop, encloseIn, encloseIn, findDropTargetAt, findFirstFocusable, fireClicked, flushReplace, forceRevalidate, getBottomGap, getChildrenAsList, getClosestComponentTo, getComponentAt, getComponentCount, getComponentIndex, getGridPosX, getGridPosY, getLayout, getLayoutHeight, getLayoutWidth, getLeadComponent, getLeadParent, getResponderAt, getSafeAreaRoot, getScrollIncrement, getSideGap, getUIManager, initLaf, invalidate, isEnabled, isSafeArea, isSafeAreaRoot, isScrollableX, isScrollableY, isSelectableInteraction, isSurface, iterator, iterator, keyPressed, keyReleased, layoutContainer, morph, morphAndWait, paint, paintComponentBackground, paintGlass, paramString, pointerPressed, refreshTheme, removeAll, removeComponent, replace, replace, replaceAndWait, replaceAndWait, replaceAndWait, revalidate, revalidateLater, revalidateWithAnimationSafety, scrollComponentToVisible, setCellRenderer, setEnabled, setLayout, setLeadComponent, setSafeArea, setSafeAreaRoot, setScrollable, setScrollableX, setScrollableY, setScrollIncrement, setShouldCalcPreferredSize, setShouldLayout, setUIManager, updateTabIndices`

  ### Methods inherited from class Component

  `addDragFinishedListener, addDragOverListener, addDropListener, addFocusListener, addLongPressListener, addPointerDraggedListener, addPointerPressedListener, addPointerReleasedListener, addPullToRefresh, addScrollListener, addStateChangeListener, announceForAccessibility, bindProperty, blocksSideSwipe, calcScrollSize, contains, containsOrOwns, createStyleAnimation, deinitializeCustomStyle, dragEnter, dragExit, dragFinished, draggingOver, drawDraggedImage, focusGained, focusLost, getAbsoluteX, getAbsoluteY, getAccessibilityText, getAllStyles, getAnimationManager, getBaseline, getBaselineResizeBehavior, getBindablePropertyNames, getBindablePropertyTypes, getBorder, getBoundPropertyValue, getBounds, getBounds, getClientProperty, getCloudBoundProperty, getCloudDestinationProperty, getComponentForm, getComponentState, getCursor, getDefaultDragTransparency, getDirtyRegion, getDisabledStyle, getDraggedx, getDraggedy, getDragImage, getDragRegionStatus, getDragSpeed, getDragTransparency, getEditingDelegate, getHeight, getInlineAllStyles, getInlineDisabledStyles, getInlinePressedStyles, getInlineSelectedStyles, getInlineStylesTheme, getInlineUnselectedStyles, getInnerHeight, getInnerPreferredH, getInnerPreferredW, getInnerWidth, getInnerX, getInnerY, getLabelForComponent, getName, getNativeOverlay, getNextFocusDown, getNextFocusLeft, getNextFocusRight, getNextFocusUp, getOuterHeight, getOuterPreferredH, getOuterPreferredW, getOuterWidth, getOuterX, getOuterY, getOwner, getParent, getPreferredH, getPreferredSize, getPreferredSizeStr, getPreferredTabIndex, getPreferredW, getPressedStyle, getPropertyNames, getPropertyTypeNames, getPropertyTypes, getPropertyValue, getSameHeight, getSameWidth, getScrollable, getScrollAnimationSpeed, getScrollDimension, getScrollOpacity, getScrollOpacityChangeSpeed, getScrollX, getScrollY, getSelectCommandText, getSelectedRect, getSelectedStyle, getStyle, getTabIndex, getTensileLength, getTextSelectionSupport, getTooltip, getUIID, getUnselectedStyle, getVisibleBounds, getVisibleBounds, getWidth, getX, getY, growShrink, handlesInput, hasFixedPreferredSize, hasFocus, hideNativeOverlay, initCustomStyle, initDisabledStyle, initPressedStyle, initSelectedStyle, initUnselectedStyle, installDefaultPainter, isAlwaysTensile, isBlockLead, isCellRenderer, isChildOf, isDragActivated, isDragAndDropOperation, isDraggable, isDragRegion, isDropTarget, isEditable, isEditing, isFlatten, isFocusable, isGrabsPointerEvents, isHidden, isHidden, isHideInLandscape, isHideInPortrait, isHScrollThumbGrabbed, isHScrollThumbHover, isIgnorePointerEvents, isInClippingRegion, isInitialized, isOpaque, isOwnedBy, isPinchBlocksDragAndDrop, isRippleEffect, isRTL, isScrollable, isScrollVisible, isSetCursorSupported, isSmoothScrolling, isSnapToGrid, isStickyDrag, isTactileTouch, isTactileTouch, isTensileDragEnabled, isTraversable, isVisible, isVScrollThumbGrabbed, isVScrollThumbHover, keyRepeated, laidOut, longKeyPress, longPointerPress, onScrollX, onScrollY, onSetFocusable, paintBackground, paintBackgrounds, paintBorder, paintBorderBackground, paintComponent, paintComponent, paintIntersectingComponentsAbove, paintLock, paintLockRelease, paintRippleOverlay, paintScrollbars, paintScrollbarX, paintScrollbarY, paintShadows, parsePreferredSize, pinch, pinch, pinchReleased, pointerDragged, pointerDragged, pointerHover, pointerHoverPressed, pointerHoverReleased, pointerPressed, pointerReleased, pointerReleased, putClientProperty, refreshTheme, refreshTheme, remove, removeDragFinishedListener, removeDragOverListener, removeDropListener, removeFocusListener, removeLongPressListener, removePointerDraggedListener, removePointerPressedListener, removePointerReleasedListener, removeScrollListener, removeStateChangeListener, repaint, repaint, requestFocus, resetFocusable, respondsToPointerEvents, scrollRectToVisible, scrollRectToVisible, setAccessibilityText, setAlwaysTensile, setBlockLead, setBoundPropertyValue, setCloudBoundProperty, setCloudDestinationProperty, setComponentState, setCursor, setDefaultDragTransparency, setDirtyRegion, setDisabledStyle, setDraggable, setDragTransparency, setDropTarget, setEditingDelegate, setFlatten, setFocus, setFocusable, setGrabsPointerEvents, setHandlesInput, setHeight, setHidden, setHidden, setHideInLandscape, setHideInPortrait, setHorizontalScrollBounds, setIgnorePointerEvents, setInitialized, setInlineAllStyles, setInlineDisabledStyles, setInlinePressedStyles, setInlineSelectedStyles, setInlineStylesTheme, setInlineUnselectedStyles, setIsScrollVisible, setLabelForComponent, setName, setNextFocusDown, setNextFocusLeft, setNextFocusRight, setNextFocusUp, setOpaque, setOwner, setPinchBlocksDragAndDrop, setPreferredH, setPreferredSize, setPreferredSizeStr, setPreferredTabIndex, setPreferredW, setPressedStyle, setPropertyValue, setPullToRefresh, setRippleEffect, setRTL, setSameHeight, setSameSize, setSameWidth, setScrollAnimationSpeed, setScrollOpacityChangeSpeed, setScrollSize, setScrollVisible, setScrollX, setScrollY, setSelectCommandText, setSelectedStyle, setSize, setSmoothScrolling, setSnapToGrid, setTabIndex, setTactileTouch, setTensileDragEnabled, setTensileLength, setTooltip, setTraversable, setUIID, setUIID, setUIIDFinal, setUnselectedStyle, setVerticalScrollBounds, setVisible, setWidth, setX, setY, shouldBlockSideSwipe, shouldBlockSideSwipeLeft, shouldBlockSideSwipeRight, shouldRenderComponentSelection, showNativeOverlay, startEditingAsync, stopEditing, stripMarginAndPadding, styleChanged, toImage, toString, unbindProperty, updateNativeOverlay, visibleBoundsContains`

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

  ### Methods inherited from interface Iterable

  `forEach`

- ## Constructor Details

  - ### SwipeableContainer

    public SwipeableContainer(Component bottomLeft, Component top)

    Simple Constructor

    ###### Parameters

    - `bottomLeft`: @param bottomLeft the Component below the top, this Component is exposed when dragging the top to the right

    - `top`: the component on top.

  - ### SwipeableContainer

    public SwipeableContainer(Component bottomLeft, Component bottomRight, Component top)

    Simple Constructor

    ###### Parameters

    - `bottomLeft`: @param bottomLeft the Component below the top, this Component is exposed when dragging the top to the right

    - `bottomRight`: @param bottomRight the Component below the top, this Component is exposed when dragging the top to the Left

    - `top`: the component on top.

- ## Method Details

  - ### deinitialize

    protected void deinitialize()
    Invoked to indicate that the component initialization is being reversed since the component was detached from the container hierarchy. This allows the component to deregister animators and cleanup after itself. This method is the opposite of the initComponent() method.
    Overrides:
      `deinitialize` in class `Component`

  - ### initComponent

    protected void initComponent()
    Allows subclasses to bind functionality that relies on fully initialized and "ready for action" component state
    Overrides:
      `initComponent` in class `Component`

  - ### openToRight

    public void openToRight()
    This method will open the top Component to the right if there is a Component to expose on the left.

  - ### openToLeft

    public void openToLeft()
    This method will open the top Component to the left if there is a Component to expose on the right.

  - ### close

    public void close()
    Close the top component if it is currently opened.

  - ### getComponentAt

    public Component getComponentAt(int x, int y)
    Description copied from class: `Container`

    Returns a Component at coordinate (x, y).

    WARNING: This method may return components that are disabled, or invisible, or that do not respond to pointer events. If you are looking for the top-most component that responds to pointer events, you should use `int)` as it is guaranteed to return a component with `Component#respondsToPointerEvents()` true; or null if none is found at the coordinate.

    ###### Parameters

    - `x`: absolute screen location

    - `y`: absolute screen location

    ###### Returns

    a Component if found, null otherwise

    ###### See also

    - Component#contains

    - #getResponderAt(int, int)

    Overrides:
      `getComponentAt` in class `Container`

  - ### animate

    public boolean animate()
    Description copied from class: `Component`

    Allows the animation to reduce "repaint" calls when it returns false. It is called once for every frame. Frames are defined by the `com.codename1.ui.Display` class.

    ###### Returns

    true if a repaint is desired or false if no repaint is necessary

    Specified by:
      `animate` in interface `Animation`
    Overrides:
      `animate` in class `Component`

  - ### isSwipeActivated

    public boolean isSwipeActivated()
    Returns true if swipe is activated

  - ### setSwipeActivated

    public void setSwipeActivated(boolean swipeActivated)
    disable/enable dragging of the top Component

  - ### isOpen

    public boolean isOpen()
    Returns true if the top Component is currently opened

  - ### isOpenedToRight

    public boolean isOpenedToRight()
    Returns true if the top Component is opened to the right side

  - ### isOpenedToLeft

    public boolean isOpenedToLeft()
    Returns true if the top Component is opened to the left side

  - ### addSwipeOpenListener

    public void addSwipeOpenListener(ActionListener l)

    Adds a listener to the SwipeableContainer which will cause an event to dispatch once the SwipeableContainer is fully opened

    ###### Parameters

    - `l`: implementation of the action listener interface

  - ### removeSwipeOpenListener

    public void removeSwipeOpenListener(ActionListener l)

    Removes the given listener from the SwipeableContainer

    ###### Parameters

    - `l`: implementation of the action listener interface

  - ### getPreviouslyOpened

    public SwipeableContainer getPreviouslyOpened()

    returns a previously opened SwipeableContainer that should be automatically closed when starting to open this one. Called as soon as this Swipeable starts opening. One approach is to override this method to return a previously opened SwipeableContainer Can be overridden to return a SwipeableContainer stored outside this container.

    ###### Returns

    Returns:
      an already open SwipeableContainer that will be closed when opening this one, or null if none

  - ### setPreviouslyOpened

    public void setPreviouslyOpened(SwipeableContainer previouslyOpened)

    set a previously open SwipeableContainer, it will be closed as soon as the user starts swiping this one. Be aware that with a long list of Swipeable containers it may be a better approach to store the previously opened outside the list and simply override getPreviouslyOpened to return it

    ###### Parameters

    - `previouslyOpened`: @param previouslyOpened an already open SwipeableContainer that will be closed if this one is opened