Groovy Documentation

com.blogofbug.swing.components
[Java] Class JCarosel

java.lang.Object
  java.awt.Component
      java.awt.Container
          javax.swing.JComponent
              javax.swing.JPanel
                  griffon.coverflow.ui.GradientPanel
                      com.blogofbug.swing.components.JCarosel
All Implemented Interfaces:
MouseListener, MouseWheelListener

public class JCarosel
extends GradientPanel

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.

Authors:
bug


Field Summary
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 String FRONT_COMPONENT_CHANGE

The property that is set when a new component comes to the front.

private static boolean MEASURE_PERFORMANCE

Set to true if the performance should be measured.

protected 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 GradientPanel
GRADIENT_END, GRADIENT_START, gradientEnd, gradientImage, gradientStart
 
Fields inherited from class JPanel
WHEN_FOCUSED, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_IN_FOCUSED_WINDOW, UNDEFINED_CONDITION, TOOL_TIP_TEXT_KEY, TOP_ALIGNMENT, CENTER_ALIGNMENT, BOTTOM_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, WIDTH, HEIGHT, PROPERTIES, SOMEBITS, FRAMEBITS, ALLBITS, ERROR, ABORT
 
Constructor Summary
JCarosel()

Creates a new instance of JCarosel

JCarosel(int contentWidth)

Creates a new Carousel specifying the prefered width up front

 
Method Summary
Component add(Component component)

Adds a component to the carousel

Component add(Image image, String text)

Adds an image to the carousel

Component add(String imageURL, int width, int height)

The image to add and it's width and height

Component add(String imageURL, String text, int width, int height)

Add the image, and it's label to the carousel

Component add(String imageURL)

Adds a new image to the carousel

Component add(String imageURL, String textLabel)

Adds a new image to the carousel

void bringToFront(Component component)

Brings the specified component to the front of the carousel

void finalizeLayoutImmediately()

Moves everything to their final positions

Component getFrontmost()

Which component is at the front

int getSpinStartDelay()

Returns the spin start delay

Component insertAt(int i, String imageURL, int width, int height)

Inserts a new object at a specific location

Component insertAt(int i, String imageURL, String text, int width, int height)

Inserts a new object at a specific location

void insertComponentAt(int i, Component comp)

Inserts a component at the specified index

void mouseClicked(MouseEvent mouseEvent)

Bring the "clicked" component to the front.

void mouseEntered(MouseEvent mouseEvent)

Not interested

void mouseExited(MouseEvent mouseEvent)

Not interested

void mousePressed(MouseEvent mouseEvent)

Not interested

void mouseReleased(MouseEvent mouseEvent)

Not interested

void mouseWheelMoved(MouseWheelEvent mouseWheelEvent)

When event received will spin the carousel to select the next object.

void remove(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 GradientPanel
createImageCache, disposeImageCache, getGradientEnd, getGradientStart, paintComponent, setGradientEnd, setGradientStart
 
Methods inherited from class JPanel
getAccessibleContext, setUI, updateUI, getUIClassID, getUI, contains, getLocation, print, getSize, isOpaque, enable, disable, update, getY, getX, getInsets, getInsets, setFont, getPreferredSize, getMinimumSize, getMaximumSize, getAlignmentX, getAlignmentY, paint, getListeners, addNotify, removeNotify, setFocusTraversalKeys, requestFocus, requestFocus, firePropertyChange, firePropertyChange, firePropertyChange, setEnabled, isDoubleBuffered, setVisible, setForeground, setBackground, getBounds, reshape, getWidth, getHeight, setPreferredSize, setMinimumSize, setMaximumSize, getBaseline, getBaselineResizeBehavior, getGraphics, getFontMetrics, repaint, repaint, printAll, requestFocusInWindow, addAncestorListener, setInheritsPopupMenu, getInheritsPopupMenu, setComponentPopupMenu, getComponentPopupMenu, isPaintingTile, isPaintingForPrint, isManagingFocus, setNextFocusableComponent, getNextFocusableComponent, setRequestFocusEnabled, isRequestFocusEnabled, grabFocus, setVerifyInputWhenFocusTarget, getVerifyInputWhenFocusTarget, setBorder, getBorder, setAlignmentY, setAlignmentX, setInputVerifier, getInputVerifier, setDebugGraphicsOptions, getDebugGraphicsOptions, registerKeyboardAction, registerKeyboardAction, unregisterKeyboardAction, getRegisteredKeyStrokes, getConditionForKeyStroke, getActionForKeyStroke, resetKeyboardActions, setInputMap, getInputMap, getInputMap, setActionMap, getActionMap, requestDefaultFocus, getDefaultLocale, setDefaultLocale, setToolTipText, getToolTipText, getToolTipText, getToolTipLocation, getPopupLocation, createToolTip, scrollRectToVisible, setAutoscrolls, getAutoscrolls, setTransferHandler, getTransferHandler, getClientProperty, putClientProperty, isLightweightComponent, setOpaque, computeVisibleRect, getVisibleRect, addVetoableChangeListener, removeVetoableChangeListener, getVetoableChangeListeners, getTopLevelAncestor, removeAncestorListener, getAncestorListeners, revalidate, isValidateRoot, isOptimizedDrawingEnabled, paintImmediately, paintImmediately, setDoubleBuffered, getRootPane, add, add, add, add, add, remove, remove, list, list, removeAll, getComponent, invalidate, validate, getComponentCount, countComponents, getComponents, insets, setComponentZOrder, getComponentZOrder, getLayout, setLayout, doLayout, layout, preferredSize, minimumSize, paintComponents, printComponents, addContainerListener, removeContainerListener, getContainerListeners, deliverEvent, getComponentAt, getComponentAt, locate, getMousePosition, findComponentAt, findComponentAt, isAncestorOf, getFocusTraversalKeys, areFocusTraversalKeysSet, isFocusCycleRoot, isFocusCycleRoot, transferFocusBackward, setFocusTraversalPolicy, getFocusTraversalPolicy, isFocusTraversalPolicySet, setFocusCycleRoot, setFocusTraversalPolicyProvider, isFocusTraversalPolicyProvider, transferFocusDownCycle, applyComponentOrientation, addPropertyChangeListener, addPropertyChangeListener, add, toString, getName, contains, size, getParent, getLocation, remove, setName, list, list, list, getSize, resize, resize, setSize, setSize, enable, location, isValid, setLocale, action, getMousePosition, getGraphicsConfiguration, dispatchEvent, isVisible, isEnabled, isDisplayable, isFocusable, getTreeLock, isLightweight, getPeer, isFocusOwner, transferFocus, getFont, isPreferredSizeSet, isMinimumSizeSet, isMaximumSizeSet, isShowing, handleEvent, postEvent, getFocusCycleRootAncestor, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, setDropTarget, getDropTarget, getToolkit, enableInputMethods, show, show, hide, getForeground, isForegroundSet, getBackground, isBackgroundSet, isFontSet, getLocale, getColorModel, getLocationOnScreen, setLocation, setLocation, move, getBounds, bounds, setBounds, setBounds, setCursor, getCursor, isCursorSet, paintAll, repaint, repaint, repaint, imageUpdate, createImage, createImage, createVolatileImage, createVolatileImage, prepareImage, prepareImage, checkImage, checkImage, setIgnoreRepaint, getIgnoreRepaint, inside, addComponentListener, removeComponentListener, getComponentListeners, addFocusListener, removeFocusListener, getFocusListeners, addHierarchyListener, removeHierarchyListener, getHierarchyListeners, addHierarchyBoundsListener, removeHierarchyBoundsListener, getHierarchyBoundsListeners, addKeyListener, removeKeyListener, getKeyListeners, addMouseListener, removeMouseListener, getMouseListeners, addMouseMotionListener, removeMouseMotionListener, getMouseMotionListeners, addMouseWheelListener, removeMouseWheelListener, getMouseWheelListeners, addInputMethodListener, removeInputMethodListener, getInputMethodListeners, getInputMethodRequests, getInputContext, mouseDown, mouseDrag, mouseUp, mouseMove, mouseEnter, mouseExit, keyDown, keyUp, gotFocus, lostFocus, isFocusTraversable, setFocusable, setFocusTraversalKeysEnabled, getFocusTraversalKeysEnabled, nextFocus, transferFocusUpCycle, hasFocus, removePropertyChangeListener, removePropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, setComponentOrientation, getComponentOrientation, wait, wait, wait, equals, hashCode, getClass, notify, notifyAll
 

Field Detail

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)


FRONT_COMPONENT_CHANGE

public static final 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.


MEASURE_PERFORMANCE

private static final boolean MEASURE_PERFORMANCE
Set to true if the performance should be measured. Debugging purposes only


lastWheeledTo

protected 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)


layout

protected CaroselLayout layout
The layout being used for the carousel


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

add

public Component add(Component component)
Adds a component to the carousel
Parameters:
component - The component to add to the carousel
Returns:
The component


add

public Component add(Image image, 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


add

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


add

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


add

public Component add(String imageURL)
Adds a new image to the carousel
Parameters:
imageURL - The image
Returns:
The component created


add

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


bringToFront

public void bringToFront(Component component)
Brings the specified component to the front of the carousel
Parameters:
component - The component to bring to the front


finalizeLayoutImmediately

public void finalizeLayoutImmediately()
Moves everything to their final positions


getFrontmost

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


getSpinStartDelay

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


insertAt

public Component insertAt(int i, 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 Component insertAt(int i, String imageURL, 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


insertComponentAt

public void insertComponentAt(int i, Component comp)
Inserts a component at the specified index
Parameters:
i - The index
comp - The component


mouseClicked

public void mouseClicked(MouseEvent mouseEvent)
Bring the "clicked" component to the front. Delays by 200ms to allow for a double click
Parameters:
mouseEvent - Brings the component clicked on by the mouse to the front


mouseEntered

public void mouseEntered(MouseEvent mouseEvent)
Not interested
Parameters:
mouseEvent - Ignored


mouseExited

public void mouseExited(MouseEvent mouseEvent)
Not interested
Parameters:
mouseEvent - Ignored


mousePressed

public void mousePressed(MouseEvent mouseEvent)
Not interested
Parameters:
mouseEvent - Ignored


mouseReleased

public void mouseReleased(MouseEvent mouseEvent)
Not interested
Parameters:
mouseEvent - Ignored


mouseWheelMoved

public void mouseWheelMoved(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)
Parameters:
mouseWheelEvent - The event object


remove

public void remove(Component component)
Removes the component from the carousel
Parameters:
component - The component to remove


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


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


 

Groovy Documentation