public abstract class AbstractCarousel extends StyledComposite implements Swipeable, AnimationListener
If the carousel is cyclic, when the last element is reached, the next one is the first one, and the other way round.
The carousel also displays a cursor showing the selected item. This cursor can be hidden automatically.
Modifier and Type | Field and Description |
---|---|
protected boolean |
autoHide
Whether the cursor is hidden automatically or not.
|
protected PagingIndicator |
cursor
The cursor.
|
protected boolean |
cyclic
Whether the carousel is cyclic or not.
|
protected boolean |
horizontal
Whether the carousel is horizontal or not.
|
EMPTY_ELEMENT_ARRAY
Constructor and Description |
---|
AbstractCarousel(boolean horizontal,
boolean cyclic)
Creates a carousel without cursor.
|
AbstractCarousel(boolean horizontal,
boolean cyclic,
PagingIndicator cursor,
boolean autoHideCursor)
Creates a carousel with a cursor that can be hidden automatically or not.
|
Modifier and Type | Method and Description |
---|---|
void |
add(ej.mwt.Widget widget) |
int |
getSelectedIndex()
Gets the currently selected widget index.
|
void |
goTo(int index)
Selects a widget from its index.
|
void |
goTo(int index,
long duration)
Animates the selection of a widget from its index.
|
void |
goToNext()
Selects the next widget.
|
void |
goToNext(int duration)
Animates the selection of the next widget.
|
void |
goToPrevious()
Selects the previous widget.
|
void |
goToPrevious(int duration)
Animates the selection of the previous widget.
|
boolean |
handleEvent(int event) |
void |
hideNotify() |
protected int |
moveWidget(ej.mwt.Widget widget,
boolean horizontal,
int totalSize,
boolean cyclic,
int shift)
Moves a widget when scrolling.
|
void |
onStartAnimation()
An animation is started.
|
void |
onStopAnimation()
An animation is stopped.
|
void |
remove(ej.mwt.Widget widget) |
void |
removeAllWidgets() |
protected abstract SwipeEventHandler |
setBoundsChildren(Rectangle bounds,
int widgetsCount)
Sets the bounds of the children.
|
protected void |
setBoundsContent(Rectangle bounds)
Sets the bounds of this widget by taking into account the border, margin and padding specified in the style.
|
protected void |
setSelectedIndex(int selectedIndex)
Sets the currently selected widget index.
|
void |
showNotify() |
protected abstract Rectangle |
validateChildren(int boundsWidth,
int boundsHeight,
boolean horizontal)
Lays out the children.
|
Rectangle |
validateContent(Style style,
Rectangle bounds)
Gets the content size of the renderable without the border, margin and padding specified in the style.
|
addClassSelector, contains, gainFocus, getAttribute, getChild, getChildrenCount, getChildrenElements, getParentElement, getStyle, hasClassSelector, isInState, isTransparent, lostFocus, mergeStyle, removeAllClassSelectors, removeClassSelector, removeInstanceStyle, render, renderContent, setBounds, setClassSelectors, setEnabled, updateStyle, updateStyleOnly, validate
getFocus, getFocusIndex, getNext, getWidget, getWidgetAt, getWidgets, getWidgetsCount, iterator, requestFocus, requestFocus, requestFocusFrom
getAbsoluteX, getAbsoluteX, getAbsoluteY, getAbsoluteY, getEventHandler, getHeight, getPanel, getParent, getPreferredHeight, getPreferredWidth, getRelativeX, getRelativeY, getWidth, getX, getY, hasFocus, invalidate, isEnabled, isShown, isValid, isVisible, repaint, repaint, revalidate, revalidateSubTree, setEventHandler, setLocation, setPreferredSize, setSize, setVisible
protected final boolean horizontal
protected final boolean cyclic
protected final boolean autoHide
@Nullable protected final PagingIndicator cursor
public AbstractCarousel(boolean horizontal, boolean cyclic)
horizontal
- true
if the carousel is horizontal, false
otherwise.cyclic
- true
if the carousel is cyclic, false
otherwise.public AbstractCarousel(boolean horizontal, boolean cyclic, @Nullable PagingIndicator cursor, boolean autoHideCursor)
horizontal
- true
if the carousel is horizontal, false
otherwise.cyclic
- true
if the carousel is cyclic, false
otherwise.cursor
- the cursor that indicate the progress in the carousel.autoHideCursor
- true
if the cursor hides automatically, false
otherwise.public void showNotify()
showNotify
in interface ej.mwt.Renderable
showNotify
in class ej.mwt.Composite
public void hideNotify()
hideNotify
in interface ej.mwt.Renderable
hideNotify
in class ej.mwt.Composite
public void add(ej.mwt.Widget widget) throws java.lang.NullPointerException, java.lang.IllegalArgumentException
StyledComposite
If the given widget is not an Element
, an IllegalArgumentException
is thrown.
add
in class StyledComposite
java.lang.IllegalArgumentException
- if the given widget is not an element.java.lang.NullPointerException
Element
,
StyledWidget
,
StyledComposite
public void remove(ej.mwt.Widget widget) throws java.lang.NullPointerException
remove
in class ej.mwt.Composite
java.lang.NullPointerException
public void removeAllWidgets()
removeAllWidgets
in class ej.mwt.Composite
protected void setSelectedIndex(int selectedIndex)
selectedIndex
- the index to set.public int getSelectedIndex()
public Rectangle validateContent(Style style, Rectangle bounds)
StyledComposite
Lays out the children of this composite.
validateContent
in interface StyledRenderable
validateContent
in class StyledComposite
style
- the style to use.bounds
- the bounds available for the content. A width or a height equals to MWT.NONE
means no
constraint on this dimension.protected abstract Rectangle validateChildren(int boundsWidth, int boundsHeight, boolean horizontal)
boundsWidth
- the width hint.boundsHeight
- the height hint.horizontal
- true
if the carousel is horizontal, false
otherwise.protected void setBoundsContent(Rectangle bounds)
StyledComposite
setBoundsContent
in class StyledComposite
bounds
- the bounds available for the content.protected abstract SwipeEventHandler setBoundsChildren(Rectangle bounds, int widgetsCount)
bounds
- the bounds of this carousel.widgetsCount
- the number of widgets in the carousel.protected int moveWidget(ej.mwt.Widget widget, boolean horizontal, int totalSize, boolean cyclic, int shift)
widget
- the widget to move.horizontal
- true
if the carousel is horizontal, false
otherwise.totalSize
- the cumulated size of the children (width if horizontal, height if vertical).cyclic
- true
if the carousel is cyclic, false
otherwise.shift
- the move shift.public boolean handleEvent(int event)
handleEvent
in interface ej.mwt.Renderable
handleEvent
in class ej.mwt.Composite
public void goToPrevious()
public void goToNext()
public void goToPrevious(int duration)
duration
- the duration of the animation.java.lang.IllegalArgumentException
- if the given duration is less or equal than 0
.public void goToNext(int duration)
duration
- the duration of the animation.java.lang.IllegalArgumentException
- if the given duration is less or equal than 0
.public void goTo(int index)
index
- the widget index.java.lang.IllegalArgumentException
- if the given index is not valid (between 0
and the number of items in the carousel).public void goTo(int index, long duration)
index
- the widget index.duration
- the duration of the animation.java.lang.IllegalArgumentException
- if the given duration is less or equal than 0
.java.lang.IllegalArgumentException
- if the given index is not valid (between 0
and the number of items in the carousel).public void onStartAnimation()
AnimationListener
onStartAnimation
in interface AnimationListener
public void onStopAnimation()
AnimationListener
onStopAnimation
in interface AnimationListener