Class JCarosel

  • All Implemented Interfaces:
    java.awt.event.ComponentListener, java.awt.event.MouseListener, java.awt.event.MouseWheelListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible

    public class JCarosel
    extends GradientPanel
    implements java.awt.event.MouseListener, java.awt.event.MouseWheelListener
    A carousel component which lays out components around a carousel, moving each to the front as it is clicked on. Double clicking will fire the action associated with the compnent if it has one, or give it the focus if it does not. Note this will be changed to only allow RichComponents in the future.
    See Also:
    Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from class javax.swing.JPanel

        javax.swing.JPanel.AccessibleJPanel
      • Nested classes/interfaces inherited from class javax.swing.JComponent

        javax.swing.JComponent.AccessibleJComponent
      • Nested classes/interfaces inherited from class java.awt.Container

        java.awt.Container.AccessibleAWTContainer
      • Nested classes/interfaces inherited from class java.awt.Component

        java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected int DEFAULT_CONTENT_WIDTH
      The prefered width of the components in the container, everything will be scaled to this width for neutral scaling (1.0)
      static java.lang.String FRONT_COMPONENT_CHANGE
      The property that is set when a new component comes to the front.
      protected java.awt.Component lastWheeledTo
      The last component the wheel selected.
      protected CaroselLayout layout
      The layout being used for the carousel
      protected int spinStartDelay
      Delay in milliseconds from the first click to the start of the spin, this gives implementors using a double click anywhere to fire an event a chance for their users to get the double click message before the component spins around.
      • Fields inherited from class org.pushingpixels.radiance.theming.extras.internal.contrib.blogofbug.swing.components.GradientPanel

        cache, end, gp, start
      • Fields inherited from class javax.swing.JComponent

        listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
      • Fields inherited from class java.awt.Component

        accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
      • Fields inherited from interface java.awt.image.ImageObserver

        ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
    • Constructor Summary

      Constructors 
      Constructor Description
      JCarosel()
      Creates a new instance of JCarosel
      JCarosel​(int contentWidth)
      Creates a new Carousel specifying the prefered width up front
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      java.awt.Component add​(java.awt.Component component)
      Adds a component to the carousel
      java.awt.Component add​(java.awt.Image image, java.lang.String text)
      Adds an image to the carousel
      java.awt.Component add​(java.lang.String imageURL)
      Adds a new image to the carousel
      java.awt.Component add​(java.lang.String imageURL, int width, int height)
      Deprecated.
      This function will be removed, use add(String imageURL) instead.
      java.awt.Component add​(java.lang.String imageURL, java.lang.String textLabel)
      Adds a new image to the carousel
      java.awt.Component add​(java.lang.String imageURL, java.lang.String text, int width, int height)
      Deprecated.
      This function will be removed, use setNeutralWidth() on JCarousel instead.
      void bringToFront​(java.awt.Component component)
      Brings the specified component to the front of the carousel
      void finalizeLayoutImmediately()
      Moves everything to their final positions
      java.awt.Component getFrontmost()
      Which component is at the front
      int getSpinStartDelay()
      Returns the spin start delay
      java.awt.Component insertAt​(int i, java.lang.String imageURL, int width, int height)
      Inserts a new object at a specific location
      java.awt.Component insertAt​(int i, java.lang.String imageURL, java.lang.String text, int width, int height)
      Inserts a new object at a specific location
      void insertComponentAt​(int i, java.awt.Component comp)
      Inserts a component at the specified index
      void mouseClicked​(java.awt.event.MouseEvent mouseEvent)
      Bring the "clicked" component to the front.
      void mouseEntered​(java.awt.event.MouseEvent mouseEvent)
      Not interested
      void mouseExited​(java.awt.event.MouseEvent mouseEvent)
      Not interested
      void mousePressed​(java.awt.event.MouseEvent mouseEvent)
      Not interested
      void mouseReleased​(java.awt.event.MouseEvent mouseEvent)
      Not interested
      void mouseWheelMoved​(java.awt.event.MouseWheelEvent mouseWheelEvent)
      When event received will spin the carousel to select the next object.
      void remove​(java.awt.Component component)
      Removes the component from the carousel
      void setContentWidth​(int contentWidth)
      Sets the prefered width of the components inside the carousel, this is the neutral width that will change as the component is scaled, but at 9 and 6 o'clock where the scale is one they will be this width.
      void setDepthBasedAlpha​(boolean useDepthBased)
      If set to true the carousel will fade out components as they move away from the front of the carousel (6 o'clock)
      void setLayout​(CaroselLayout layout)
      Specifies which type of CarouselLayout to be used to lay the component out around the carousel Any looping layout can be used.
      void setSpinStartDelay​(int spinStartDelay)
      Sets the delay between clicking on a component in the carousel, and the spin starting to move that component to the front.
      • Methods inherited from class javax.swing.JPanel

        getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
      • Methods inherited from class javax.swing.JComponent

        addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
      • Methods inherited from class java.awt.Container

        add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
      • Methods inherited from class java.awt.Component

        action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
      • Methods inherited from class java.lang.Object

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

      • FRONT_COMPONENT_CHANGE

        public static final java.lang.String FRONT_COMPONENT_CHANGE
        The property that is set when a new component comes to the front. To use it add a property change listener for it, useful for keeping animations synchronized.
        See Also:
        Constant Field Values
      • layout

        protected CaroselLayout layout
        The layout being used for the carousel
      • lastWheeledTo

        protected java.awt.Component lastWheeledTo
        The last component the wheel selected. Used to ensure we don't move too far around why they are wheeling and they turn back on themselves creating a nasty oscilation in the animation (everything works fine, it's just not purty)
      • DEFAULT_CONTENT_WIDTH

        protected int DEFAULT_CONTENT_WIDTH
        The prefered width of the components in the container, everything will be scaled to this width for neutral scaling (1.0)
      • spinStartDelay

        protected int spinStartDelay
        Delay in milliseconds from the first click to the start of the spin, this gives implementors using a double click anywhere to fire an event a chance for their users to get the double click message before the component spins around.
    • Constructor Detail

      • JCarosel

        public JCarosel()
        Creates a new instance of JCarosel
      • JCarosel

        public JCarosel​(int contentWidth)
        Creates a new Carousel specifying the prefered width up front
        Parameters:
        contentWidth - The prefered width of component at neutral scale (3 or 9 o'clock)
    • Method Detail

      • setContentWidth

        public void setContentWidth​(int contentWidth)
        Sets the prefered width of the components inside the carousel, this is the neutral width that will change as the component is scaled, but at 9 and 6 o'clock where the scale is one they will be this width.
        Parameters:
        contentWidth - The prefered width.
      • setDepthBasedAlpha

        public void setDepthBasedAlpha​(boolean useDepthBased)
        If set to true the carousel will fade out components as they move away from the front of the carousel (6 o'clock)
        Parameters:
        useDepthBased - True to fade components as they move to the back, false to not do it
      • setLayout

        public void setLayout​(CaroselLayout layout)
        Specifies which type of CarouselLayout to be used to lay the component out around the carousel Any looping layout can be used. Mobius strip layout anyone?
        Parameters:
        layout - The carousel layout to use
      • add

        public java.awt.Component add​(java.awt.Component component)
        Adds a component to the carousel
        Overrides:
        add in class java.awt.Container
        Parameters:
        component - The component to add to the carousel
        Returns:
        The component
      • add

        public java.awt.Component add​(java.awt.Image image,
                                      java.lang.String text)
        Adds an image to the carousel
        Parameters:
        image - The image to add
        text - The text label
        Returns:
        The component created, normally a reflected image label
      • remove

        public void remove​(java.awt.Component component)
        Removes the component from the carousel
        Overrides:
        remove in class java.awt.Container
        Parameters:
        component - The component to remove
      • add

        @Deprecated
        public java.awt.Component add​(java.lang.String imageURL,
                                      int width,
                                      int height)
        Deprecated.
        This function will be removed, use add(String imageURL) instead.
        The image to add and it's width and height
        Parameters:
        imageURL - The URL
        width - The desired rendering width
        height - The desired rendering height
        Returns:
        The component created
      • add

        @Deprecated
        public java.awt.Component add​(java.lang.String imageURL,
                                      java.lang.String text,
                                      int width,
                                      int height)
        Deprecated.
        This function will be removed, use setNeutralWidth() on JCarousel instead.
        Add the image, and it's label to the carousel
        Parameters:
        imageURL - The image URL
        text - The text label
        width - The width
        height - The height
        Returns:
        The component created to hold the image
      • bringToFront

        public void bringToFront​(java.awt.Component component)
        Brings the specified component to the front of the carousel
        Parameters:
        component - The component to bring to the front
      • getFrontmost

        public java.awt.Component getFrontmost()
        Which component is at the front
        Returns:
        The component at the front (by default 6 o'clock)
      • mouseClicked

        public void mouseClicked​(java.awt.event.MouseEvent mouseEvent)
        Bring the "clicked" component to the front. Delays by 200ms to allow for a double click
        Specified by:
        mouseClicked in interface java.awt.event.MouseListener
        Parameters:
        mouseEvent - Brings the component clicked on by the mouse to the front
      • setSpinStartDelay

        public void setSpinStartDelay​(int spinStartDelay)
        Sets the delay between clicking on a component in the carousel, and the spin starting to move that component to the front. The longer it is, the easier it is to double click on a non-front component
        Parameters:
        spinStartDelay - Spin start delay.
      • getSpinStartDelay

        public int getSpinStartDelay()
        Returns the spin start delay
        Returns:
        The delay in ms between the click and the spin
      • insertComponentAt

        public void insertComponentAt​(int i,
                                      java.awt.Component comp)
        Inserts a component at the specified index
        Parameters:
        i - The index
        comp - The component
      • insertAt

        public java.awt.Component insertAt​(int i,
                                           java.lang.String imageURL,
                                           int width,
                                           int height)
        Inserts a new object at a specific location
        Parameters:
        i - The position on the carousel
        imageURL - The URL of the image
        width - The width of the image
        height - The height of the image
        Returns:
        The component created to show the image (usually a ReflectedImageLabel but this may change)
      • insertAt

        public java.awt.Component insertAt​(int i,
                                           java.lang.String imageURL,
                                           java.lang.String text,
                                           int width,
                                           int height)
        Inserts a new object at a specific location
        Parameters:
        i - The position on the carousel
        imageURL - The URL of the image
        text - The text label
        width - The prefered width of the image
        height - The prefered height of the image
        Returns:
        The component created to represent the image, currently reflected image label but may change
      • finalizeLayoutImmediately

        public void finalizeLayoutImmediately()
        Moves everything to their final positions
      • mousePressed

        public void mousePressed​(java.awt.event.MouseEvent mouseEvent)
        Not interested
        Specified by:
        mousePressed in interface java.awt.event.MouseListener
        Parameters:
        mouseEvent - Ignored
      • mouseReleased

        public void mouseReleased​(java.awt.event.MouseEvent mouseEvent)
        Not interested
        Specified by:
        mouseReleased in interface java.awt.event.MouseListener
        Parameters:
        mouseEvent - Ignored
      • mouseEntered

        public void mouseEntered​(java.awt.event.MouseEvent mouseEvent)
        Not interested
        Specified by:
        mouseEntered in interface java.awt.event.MouseListener
        Parameters:
        mouseEvent - Ignored
      • mouseExited

        public void mouseExited​(java.awt.event.MouseEvent mouseEvent)
        Not interested
        Specified by:
        mouseExited in interface java.awt.event.MouseListener
        Parameters:
        mouseEvent - Ignored
      • mouseWheelMoved

        public void mouseWheelMoved​(java.awt.event.MouseWheelEvent mouseWheelEvent)
        When event received will spin the carousel to select the next object. Because the wheel can be spun quicker than the carousel animates it keeps track of the target (so the user may have selected something three components away, althought the animation has not yet finished moving past the first comopnent)
        Specified by:
        mouseWheelMoved in interface java.awt.event.MouseWheelListener
        Parameters:
        mouseWheelEvent - The event object
      • add

        public java.awt.Component add​(java.lang.String imageURL)
        Adds a new image to the carousel
        Parameters:
        imageURL - The image
        Returns:
        The component created
      • add

        public java.awt.Component add​(java.lang.String imageURL,
                                      java.lang.String textLabel)
        Adds a new image to the carousel
        Parameters:
        imageURL - The image
        textLabel - The label
        Returns:
        The component created