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(Widget widget)
Adds the specified widget to the end of the list of children of this composite.
|
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)
Called by the system if a child of this composite is the owner of the focus of the active panel (recursively) and
have not consumed the specified event.
|
void |
hideNotify()
This method is called as soon as the renderable is hidden.
|
protected int |
moveWidget(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(Widget widget)
Removes the specified widget from the list of children of this composite.
|
void |
removeAllWidgets()
Removes all the widgets from the list of children of this composite.
|
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()
This method is called as soon as the renderable is visible.
|
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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getEventHandler, getHeight, getWidth, getX, getY, isShown, repaint, repaint, setEventHandler
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()
Composite
Notifies its children widgets that they are shown.
showNotify
in interface Renderable
showNotify
in class Composite
public void hideNotify()
Composite
Notifies its children widgets that they are hidden.
hideNotify
in interface Renderable
hideNotify
in class Composite
public void add(Widget widget) throws java.lang.NullPointerException, java.lang.IllegalArgumentException
StyledComposite
If the composite is on a panel hierarchy, it is invalidated.
If the given widget is not an Element
, an IllegalArgumentException
is thrown.
add
in class StyledComposite
widget
- the widget to add.java.lang.NullPointerException
- if the specified widget is null
.java.lang.IllegalArgumentException
- if the given widget is not an element.Element
,
StyledWidget
,
StyledComposite
public void remove(Widget widget) throws java.lang.NullPointerException
Composite
If the composite is on a panel hierarchy, it is invalidated.
If the widget is not in the list of children of the composite, nothing is done.
remove
in class Composite
widget
- the widget to removejava.lang.NullPointerException
- if the specified widget is nullWidget.invalidate()
public void removeAllWidgets()
Composite
If the composite is on a panel hierarchy, it is invalidated.
removeAllWidgets
in class Composite
Widget.invalidate()
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(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)
Composite
Command#UP
, Command#DOWN
,
Command#LEFT
, and Command#RIGHT
commands to manage navigation in its children.handleEvent
in interface Renderable
handleEvent
in class Composite
event
- the event to handletrue
if the composite consume the event, false
otherwiseWidget.setEventHandler(EventHandler)
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