Class StarRating

  • All Implemented Interfaces:
    org.eclipse.swt.graphics.Drawable

    public class StarRating
    extends org.eclipse.swt.widgets.Canvas
    Instances of this class provide a rating element.

    Styles:
    HORIZONTAL
    VERTICAL
    *
    Events:
    Selection

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  StarRating.SIZE  
    • Constructor Summary

      Constructors 
      Constructor Description
      StarRating​(org.eclipse.swt.widgets.Composite parent, int style)
      Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addSelectionListener​(org.eclipse.swt.events.SelectionListener listener)
      Adds the listener to the collection of listeners who will be notified when the control is selected by the user, by sending it one of the messages defined in the SelectionListener interface.
      private static int checkStyle​(int style)  
      org.eclipse.swt.graphics.Point computeSize​(int wHint, int hHint, boolean changed)  
      private org.eclipse.swt.graphics.Point computeSizeHorizontal()  
      private org.eclipse.swt.graphics.Point computeSizeVertical()  
      private void fireSelectionEvent()  
      int getCurrentNumberOfStars()  
      int getMaxNumberOfStars()  
      int getOrientation()  
      StarRating.SIZE getSizeOfStars()  
      private void initListeners()  
      private void onDispose​(org.eclipse.swt.widgets.Event event)  
      private void onMouseEnterOrMove​(org.eclipse.swt.widgets.Event event)  
      private void onMouseExit​(org.eclipse.swt.widgets.Event event)  
      private void onMousePaint​(org.eclipse.swt.widgets.Event event)  
      private void onMouseUp​(org.eclipse.swt.widgets.Event event)  
      private void reinitStars()  
      void removeSelectionListener​(org.eclipse.swt.events.SelectionListener listener)
      Removes the listener from the collection of listeners who will be notified when the control is selected by the user.
      void setCurrentNumberOfStars​(int currentNumberOfStars)
      Set the current number of stars
      void setMaxNumberOfStars​(int maxNumberOfStars)
      Set the maximum number of stars
      void setSizeOfStars​(StarRating.SIZE sizeOfStars)
      Set the current size of stars
      • Methods inherited from class org.eclipse.swt.widgets.Canvas

        drawBackground, getCaret, getIME, scroll, setCaret, setFont, setIME
      • Methods inherited from class org.eclipse.swt.widgets.Composite

        changed, checkSubclass, drawBackground, getBackgroundMode, getChildren, getLayout, getLayoutDeferred, getTabList, isLayoutDeferred, layout, layout, layout, layout, layout, setBackgroundMode, setFocus, setLayout, setLayoutDeferred, setTabList
      • Methods inherited from class org.eclipse.swt.widgets.Scrollable

        computeTrim, getClientArea, getHorizontalBar, getScrollbarsMode, getVerticalBar
      • Methods inherited from class org.eclipse.swt.widgets.Control

        addControlListener, addDragDetectListener, addFocusListener, addGestureListener, addHelpListener, addKeyListener, addMenuDetectListener, addMouseListener, addMouseMoveListener, addMouseTrackListener, addMouseWheelListener, addPaintListener, addTouchListener, addTraverseListener, computeSize, dragDetect, dragDetect, forceFocus, getAccessible, getBackground, getBackgroundImage, getBorderWidth, getBounds, getCursor, getDragDetect, getEnabled, getFont, getForeground, getLayoutData, getLocation, getMenu, getMonitor, getParent, getRegion, getShell, getSize, getTextDirection, getToolTipText, getTouchEnabled, getVisible, internal_dispose_GC, internal_new_GC, isAutoScalable, isEnabled, isFocusControl, isReparentable, isVisible, moveAbove, moveBelow, pack, pack, print, redraw, redraw, removeControlListener, removeDragDetectListener, removeFocusListener, removeGestureListener, removeHelpListener, removeKeyListener, removeMenuDetectListener, removeMouseListener, removeMouseMoveListener, removeMouseTrackListener, removeMouseWheelListener, removePaintListener, removeTouchListener, removeTraverseListener, requestLayout, setBackground, setBackgroundImage, setBounds, setBounds, setCapture, setCursor, setDragDetect, setEnabled, setForeground, setLayoutData, setLocation, setLocation, setMenu, setOrientation, setParent, setRedraw, setRegion, setSize, setSize, setTextDirection, setToolTipText, setTouchEnabled, setVisible, toControl, toControl, toDisplay, toDisplay, traverse, traverse, traverse, update
      • Methods inherited from class org.eclipse.swt.widgets.Widget

        addDisposeListener, addListener, checkWidget, dispose, getData, getData, getDisplay, getListeners, getStyle, isAutoDirection, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, removeListener, reskin, setData, setData, toString
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • maxNumberOfStars

        private int maxNumberOfStars
      • currentNumberOfStars

        private int currentNumberOfStars
      • DEFAULT_MAX_NUMBERS_OF_STARS

        private static final int DEFAULT_MAX_NUMBERS_OF_STARS
        See Also:
        Constant Field Values
      • stars

        private final java.util.List<Star> stars
      • orientation

        private int orientation
      • selectionListeners

        private final java.util.List<org.eclipse.swt.events.SelectionListener> selectionListeners
    • Constructor Detail

      • StarRating

        public StarRating​(org.eclipse.swt.widgets.Composite parent,
                          int style)
        Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.

        The style value is either one of the style constants defined in class SWT which is applicable to instances of this class, or must be built by bitwise OR'ing together (that is, using the int "|" operator) two or more of those SWT style constants. The class description lists the style constants that are applicable to the class. Style bits are also inherited from superclasses.

        Parameters:
        parent - a composite control which will be the parent of the new instance (cannot be null)
        style - the style of control to construct
        Throws:
        java.lang.IllegalArgumentException -
        • ERROR_NULL_ARGUMENT - if the parent is null
        org.eclipse.swt.SWTException -
        • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
    • Method Detail

      • checkStyle

        private static int checkStyle​(int style)
      • initListeners

        private void initListeners()
      • onMouseEnterOrMove

        private void onMouseEnterOrMove​(org.eclipse.swt.widgets.Event event)
      • onMouseExit

        private void onMouseExit​(org.eclipse.swt.widgets.Event event)
      • onMouseUp

        private void onMouseUp​(org.eclipse.swt.widgets.Event event)
      • fireSelectionEvent

        private void fireSelectionEvent()
      • onMousePaint

        private void onMousePaint​(org.eclipse.swt.widgets.Event event)
      • onDispose

        private void onDispose​(org.eclipse.swt.widgets.Event event)
      • addSelectionListener

        public void addSelectionListener​(org.eclipse.swt.events.SelectionListener listener)
        Adds the listener to the collection of listeners who will be notified when the control is selected by the user, by sending it one of the messages defined in the SelectionListener interface.

        widgetDefaultSelected is not called.

        Parameters:
        listener - the listener which should be notified when the control is selected by the user,
        Throws:
        java.lang.IllegalArgumentException -
        • ERROR_NULL_ARGUMENT - if the listener is null
        org.eclipse.swt.SWTException -
        • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
        • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
        See Also:
        SelectionListener, removeSelectionListener(org.eclipse.swt.events.SelectionListener), SelectionEvent
      • computeSize

        public org.eclipse.swt.graphics.Point computeSize​(int wHint,
                                                          int hHint,
                                                          boolean changed)
        Overrides:
        computeSize in class org.eclipse.swt.widgets.Control
        See Also:
        Control.computeSize(int, int, boolean)
      • computeSizeVertical

        private org.eclipse.swt.graphics.Point computeSizeVertical()
      • computeSizeHorizontal

        private org.eclipse.swt.graphics.Point computeSizeHorizontal()
      • getCurrentNumberOfStars

        public int getCurrentNumberOfStars()
        Returns:
        the number of selected stars
        Throws:
        org.eclipse.swt.SWTException -
        • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
        • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      • getMaxNumberOfStars

        public int getMaxNumberOfStars()
        Returns:
        the maximum number of stars that is displayed by this component
        Throws:
        org.eclipse.swt.SWTException -
        • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
        • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      • getOrientation

        public int getOrientation()
        Overrides:
        getOrientation in class org.eclipse.swt.widgets.Control
        Returns:
        the orientation of this widget (SWT.VERTICAL or SWT.HORIZONTAL)
        Throws:
        org.eclipse.swt.SWTException -
        • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
        • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      • getSizeOfStars

        public StarRating.SIZE getSizeOfStars()
        Returns:
        the size of stars
        Throws:
        org.eclipse.swt.SWTException -
        • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
        • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      • removeSelectionListener

        public void removeSelectionListener​(org.eclipse.swt.events.SelectionListener listener)
        Removes the listener from the collection of listeners who will be notified when the control is selected by the user.
        Parameters:
        listener - the listener which should no longer be notified
        Throws:
        java.lang.IllegalArgumentException -
        • ERROR_NULL_ARGUMENT - if the listener is null
        org.eclipse.swt.SWTException -
        • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
        • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
        See Also:
        SelectionListener, addSelectionListener(org.eclipse.swt.events.SelectionListener)
      • setCurrentNumberOfStars

        public void setCurrentNumberOfStars​(int currentNumberOfStars)
        Set the current number of stars
        Parameters:
        currentNumberOfStars - current number of stars
        Throws:
        java.lang.IllegalArgumentException -
        • ERROR_INVALID_ARGUMENT - if the number of star is negative or greater than the maximum number of stars
        org.eclipse.swt.SWTException -
        • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
        • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      • setMaxNumberOfStars

        public void setMaxNumberOfStars​(int maxNumberOfStars)
        Set the maximum number of stars
        Parameters:
        currentNumberOfStars - current number of stars
        Throws:
        org.eclipse.swt.SWTException -
        • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
        • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      • reinitStars

        private void reinitStars()
      • setSizeOfStars

        public void setSizeOfStars​(StarRating.SIZE sizeOfStars)
        Set the current size of stars
        Parameters:
        sizeOfStars - current number of stars
        Throws:
        java.lang.IllegalArgumentException -
        • ERROR_INVALID_ARGUMENT - if the number of star is negative or greater than the maximum number of stars
        org.eclipse.swt.SWTException -
        • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
        • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver