public class MaterialRating extends gwt.material.design.client.base.MaterialWidget implements com.google.gwt.user.client.ui.HasValue<Integer>
MaterialRating is the component used by the 5-star rating system, for example, allowing users to easily express their opinion about a product, review, video and so on.
By default, it uses the IconType.STAR
to represent the selected
rating, but other icons can be set using the
setSelectedRatingIcon(IconType)
method.
xmlns:ma='urn:import:gwt.material.design.addins.client'
<ma:rating.MaterialRating ui:field="rating" />
To use different icons, for instance, hearts, you can set:
<ma:rating.MaterialRating ui:field="rating" selectedRatingIcon="FAVORITE" unselectedRatingIcon="FAVORITE_BORDER" textColor="red" />
You can also set the maximum rating (the default is 5):
<ma:rating.MaterialRating ui:field="rating" maxRating="7" />
MaterialRating rating = ... //create using new or using UiBinder
rating.addValueChangeHandler(...); // MaterialRating implements HasValue<Integer>
rating.setEditable(false); // disables user interaction
rating.setValue(2); // directly sets the desired rating
int selectedValue = rating.getValue(); // retrieves the selected rating
You use change the MaterialRating style by using the
material-rating
CSS class. Selected rating icons have the
material-rating-selected
CSS class, and unselected the
material-rating-unselected
CSS class.
gwt.material.design.client.base.MaterialWidget.Feature
com.google.gwt.user.client.ui.UIObject.DebugIdImpl, com.google.gwt.user.client.ui.UIObject.DebugIdImplEnabled
Constructor and Description |
---|
MaterialRating()
Default constructor.
|
MaterialRating(gwt.material.design.client.constants.IconType selectedRatingIcon,
gwt.material.design.client.constants.IconType unselectedRatingIcon,
gwt.material.design.client.constants.Color textColor) |
MaterialRating(gwt.material.design.client.constants.IconType selectedRatingIcon,
gwt.material.design.client.constants.IconType unselectedRatingIcon,
gwt.material.design.client.constants.Color textColor,
Integer value) |
MaterialRating(gwt.material.design.client.constants.IconType selectedRatingIcon,
gwt.material.design.client.constants.IconType unselectedRatingIcon,
gwt.material.design.client.constants.Color textColor,
Integer value,
Integer maxRating) |
Modifier and Type | Method and Description |
---|---|
com.google.gwt.event.shared.HandlerRegistration |
addValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler<Integer> handler) |
void |
clear() |
int |
getMaxRating()
Returns the maximum selectable rating in this component.
|
gwt.material.design.client.constants.IconType |
getSelectedRatingIcon()
Returns the
IconType used to represent the selected ratings. |
gwt.material.design.client.constants.IconType |
getUnselectedRatingIcon()
Returns the
IconType used to represent the not selected ratings. |
Integer |
getValue() |
boolean |
isEditable()
Returns whether the component is editable by the user.
|
protected void |
onLoad() |
protected void |
revalidateLayout()
Method called internally by the component to re-validate the number of
icons when the maximum rating is changed.
|
protected void |
revalidateSelection(int rating)
Method called internally by the component to revalidade selections by the
user, switching the icons accordingly.
|
void |
setEditable(boolean editable)
Sets whether the user can interact with the component or not.
|
void |
setMaxRating(int maxRating)
Sets the maximum number of icons to show - which represents the maximum
selectable rating.
|
void |
setSelectedRatingIcon(gwt.material.design.client.constants.IconType selectedRatingIcon)
Sets the
IconType to be used to represent the selected ratings. |
void |
setUnselectedRatingIcon(gwt.material.design.client.constants.IconType unselectedRatingIcon)
Sets the
IconType to be used to represent the not selected
ratings. |
void |
setValue(Integer value) |
void |
setValue(Integer value,
boolean fireEvents) |
$this, add, add, addAttachHandler, addBlurHandler, addClickHandler, addDoubleClickHandler, addDragEndHandler, addDragEnterHandler, addDragLeaveHandler, addDragMoveHandler, addDragOverHandler, addDragStartHandler, addDropActivateHandler, addDropDeactivateHandler, addDropHandler, addFocusHandler, addGestureChangeHandler, addGestureEndHandler, addGestureStartHandler, addKeyDownHandler, addKeyPressHandler, addKeyUpHandler, addMouseDownHandler, addMouseMoveHandler, addMouseOutHandler, addMouseOverHandler, addMouseUpHandler, addMouseWheelHandler, addOrientationChangeHandler, addTouchCancelHandler, addTouchEndHandler, addTouchMoveHandler, addTouchStartHandler, body, clearActiveClass, enableFeature, getBackfaceVisibility, getBackgroundColor, getBorder, getBorderBottom, getBorderLeft, getBorderMixin, getBorderRadius, getBorderRight, getBorderTop, getCenterOn, getCenterOnMixin, getChildren, getChildrenList, getCircleMixin, getColorsMixin, getDataAttribute, getDepth, getDimensionMixin, getEnabledMixin, getFlexboxMixin, getFloat, getFloatMixin, getFocusableMixin, getFontSize, getFontSizeMixin, getFontWeight, getFontWeightMixin, getGridMixin, getHandlerRegistry, getHideOn, getHideOnMixin, getHoverableMixin, getId, getIdMixin, getInitialClasses, getLayoutPosition, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getOpacity, getOrientation, getOrientationMixin, getPerspective, getPerspectiveOrigin, getScrollspy, getScrollspyMixin, getSeparatorMixin, getShadow, getShadowMixin, getShowOn, getShowOnMixin, getTabIndex, getTextAlign, getTextAlignMixin, getTextColor, getTooltip, getTooltipDelayMs, getTooltipHTML, getTooltipMixin, getTooltipPosition, getTransform, getTransformMixin, getTransformOrigin, getTransformStyle, getTruncateMixin, getVerticalAlign, getVerticalAlignMixin, getWaves, getWavesMixin, getWidth, insert, insert, isCircle, isDetectOrientation, isEnabled, isFeatureEnabled, isHoverable, isSeparator, isTruncate, onUnload, registerHandler, removeHandler, setAccessKey, setBackfaceVisibility, setBackgroundColor, setBorder, setBorderBottom, setBorderLeft, setBorderRadius, setBorderRight, setBorderTop, setBottom, setCenterOn, setCircle, setClass, setDataAttribute, setDepth, setDetectOrientation, setDisplay, setEnabled, setFlex, setFlexAlignContent, setFlexAlignItems, setFlexAlignSelf, setFlexBasis, setFlexDirection, setFlexGrow, setFlexJustifyContent, setFlexOrder, setFlexShrink, setFlexWrap, setFloat, setFocus, setFontSize, setFontSize, setFontWeight, setGrid, setGwtDisplay, setHideOn, setHoverable, setId, setInitialClasses, setLayoutPosition, setLeft, setLineHeight, setMargin, setMarginBottom, setMarginLeft, setMarginRight, setMarginTop, setMaxHeight, setMaxWidth, setMinHeight, setMinWidth, setOffset, setOpacity, setOrientation, setOverflow, setPadding, setPaddingBottom, setPaddingLeft, setPaddingRight, setPaddingTop, setPerspective, setPerspectiveOrigin, setRight, setScrollspy, setSeparator, setShadow, setShowOn, setStyle, setTabIndex, setTextAlign, setTextColor, setTooltip, setTooltipDelayMs, setTooltipHTML, setTooltipPosition, setTop, setTransform, setTransformOrigin, setTransformStyle, setTransition, setTruncate, setVerticalAlign, setVisibility, setWaves, stopTouchStartEvent, validate, window
add, adjustIndex, checkIndexBoundsForAccess, checkIndexBoundsForInsertion, getWidget, getWidgetCount, getWidgetIndex, getWidgetIndex, insert, iterator, remove, remove
add, adopt, doAttachChildren, doDetachChildren, orphan, remove
addAttachHandler, addBitlessDomHandler, addDomHandler, addHandler, asWidget, asWidgetOrNull, createHandlerManager, delegateEvent, fireEvent, getHandlerCount, getLayoutData, getParent, isAttached, isOrWasAttached, onAttach, onBrowserEvent, onDetach, removeFromParent, setLayoutData, sinkEvents, unsinkEvents
addStyleDependentName, addStyleName, ensureDebugId, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleElement, getStyleName, getStyleName, getStylePrimaryName, getStylePrimaryName, getTitle, isVisible, isVisible, onEnsureDebugId, removeStyleDependentName, removeStyleName, resolvePotentialElement, setElement, setElement, setHeight, setPixelSize, setSize, setStyleDependentName, setStyleName, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, sinkBitlessEvent, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
forEach, spliterator
public MaterialRating()
public MaterialRating(gwt.material.design.client.constants.IconType selectedRatingIcon, gwt.material.design.client.constants.IconType unselectedRatingIcon, gwt.material.design.client.constants.Color textColor)
public MaterialRating(gwt.material.design.client.constants.IconType selectedRatingIcon, gwt.material.design.client.constants.IconType unselectedRatingIcon, gwt.material.design.client.constants.Color textColor, Integer value)
public MaterialRating(gwt.material.design.client.constants.IconType selectedRatingIcon, gwt.material.design.client.constants.IconType unselectedRatingIcon, gwt.material.design.client.constants.Color textColor, Integer value, Integer maxRating)
protected void onLoad()
onLoad
in class gwt.material.design.client.base.MaterialWidget
public void setMaxRating(int maxRating)
maxRating
- The maximum selectable rating for this componentpublic int getMaxRating()
public void setSelectedRatingIcon(gwt.material.design.client.constants.IconType selectedRatingIcon)
IconType
to be used to represent the selected ratings.
The default is IconType.STAR
.selectedRatingIcon
- The icon of the selected ratingspublic gwt.material.design.client.constants.IconType getSelectedRatingIcon()
IconType
used to represent the selected ratings. The
default is IconType.STAR
.public void setUnselectedRatingIcon(gwt.material.design.client.constants.IconType unselectedRatingIcon)
IconType
to be used to represent the not selected
ratings. The default is IconType.STAR_BORDER
.unselectedRatingIcon
- The icon of the unselected ratingspublic gwt.material.design.client.constants.IconType getUnselectedRatingIcon()
IconType
used to represent the not selected ratings.
The default is IconType.STAR_BORDER
.public void clear()
clear
in interface com.google.gwt.user.client.ui.HasWidgets
clear
in class com.google.gwt.user.client.ui.Panel
protected void revalidateLayout()
protected void revalidateSelection(int rating)
public void setValue(Integer value, boolean fireEvents)
setValue
in interface com.google.gwt.user.client.ui.HasValue<Integer>
public void setEditable(boolean editable)
true
(editable).editable
- true
to allow the user change the state of the component,
false
otherwise.public boolean isEditable()
true
(editable).true
if the component is editable by the user,
false
otherwise'public com.google.gwt.event.shared.HandlerRegistration addValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler<Integer> handler)
addValueChangeHandler
in interface com.google.gwt.event.logical.shared.HasValueChangeHandlers<Integer>
Copyright © 2018. All rights reserved.