Groovy Documentation

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

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

public class JCarouselMenu
extends GradientPanel

Shows a carousel offset to the left with a menu of actions on the right.

Authors:
nigel


Nested Class Summary
protected class JCarouselMenu.CarouselListCellRenderer

ListCellRenderer for the Carousel uses an image border to draw a nice border around the menu item when it is selected

class JCarouselMenu.MenuItem

A menu item inside the carousel

private class JCarouselMenu.UpDownButton

This class represents the up and down buttons that allow the scrolling through the menu when it is too big to fit in the avaiable space

 
Field Summary
private JCarosel carousel

The carousel used and drawn on the left.

private JCarouselMenu.UpDownButton downButton

The button shown when you can scroll down

private int lastSelection

The last item selected

private JList menu

A JList with the menu items in

private LinkedList menuItems

Linked list of the items in the menu

private Map menuMap

A hashtable connecting the actions to the components in the carousel

private DefaultListModel menuModel

The model for the action menu

private JScrollPane menuScroll

The scroll pane the menu is in

private JCarouselMenu.UpDownButton upButton

The button that is drawn when it is possible to scroll up

 
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
JCarouselMenu(ImageBorder border)

Creates a new instance of JCarouselMenu

JCarouselMenu()

Creates a new instance

 
Method Summary
Component add(Component component, String label)

Adds a component to the carousel menu that will be brought into view when the user clicks on the associated item

Component add(Image image, String label, int width, int height)

Adds an image to the menu.

Component add(Image image, String label)

Adds an image (with a label) and returns the component created to represent them

Component add(Action action, int width, int height)

Adds an action to the menu

Component add(Action action)

Adds an action to the list, creating a menu item and a carousel entry

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

Adds an image (through a URL) to the menu

Component add(String imageURL, String label)

Adds an image based on the imageURL and a text label, returning the component that is created as a result

JList getList()

Returns the list part of the carousel menu

Dimension getPreferredSize()

Return the preferred size of the component

void keyPressed(KeyEvent keyEvent)

Listen for key events, when we see one that looks like it should wrap, set up the lastSelection variable to trigger a change on release of the key

void keyReleased(KeyEvent keyEvent)

If the wrap-around has detected the need to wrap, sets the selection to the value calculated when the key was first pressed.

void keyTyped(KeyEvent keyEvent)

Don't Care *

void mouseClicked(MouseEvent mouseEvent)

Look to see if an item in the list is double clicked, and launch the action if it is

void mouseEntered(MouseEvent mouseEvent)

Don't Care *

void mouseExited(MouseEvent mouseEvent)

Don't Care *

void mousePressed(MouseEvent mouseEvent)

Don't Care *

void mouseReleased(MouseEvent mouseEvent)

Don't Care *

void mouseWheelMoved(MouseWheelEvent mouseWheelEvent)

Moves the selected menu up or down when the mouse wheel scrolls

protected void processAction()

Launch the action associated with the currently selected list item

void remove(Component component)

Removes a component from the menu

void setCellImageBorder(ImageBorder imageBorder)

Sets the image border used to draw around the items in the menu

void setCellRenderer(ListCellRenderer cellRenderer)

Specifies the list cell renderer used to draw the items in the menu

void setMenuScrollColor(Color color)

Allows the background color to the menu (left side) to be set

void setSelectedIndex(int i)

Sets the selected item in the menu

void setUpDownColor(Color color)

Sets the color the up and down buttons are drawn

void setUpDownIcons(Icon upIcon, Icon downIcon)

Sets icons to use to show the up and down buttons

void stateChanged(ChangeEvent e)

Detect when the list selection changes, and respond by updating the state of the two "arrow" buttons.

void valueChanged(ListSelectionEvent listSelectionEvent)

Detect when the list selection changes, and respond by rotating the carousel to show that item

 
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

carousel

private JCarosel carousel
The carousel used and drawn on the left.


downButton

private JCarouselMenu.UpDownButton downButton
The button shown when you can scroll down


lastSelection

private int lastSelection
The last item selected


menu

private JList menu
A JList with the menu items in


menuItems

private LinkedList menuItems
Linked list of the items in the menu


menuMap

private Map menuMap
A hashtable connecting the actions to the components in the carousel


menuModel

private DefaultListModel menuModel
The model for the action menu


menuScroll

private JScrollPane menuScroll
The scroll pane the menu is in


upButton

private JCarouselMenu.UpDownButton upButton
The button that is drawn when it is possible to scroll up


 
Constructor Detail

JCarouselMenu

public JCarouselMenu(ImageBorder border)
Creates a new instance of JCarouselMenu
Parameters:
border - The border to use to draw items in the menu


JCarouselMenu

public JCarouselMenu()
Creates a new instance


 
Method Detail

add

public Component add(Component component, String label)
Adds a component to the carousel menu that will be brought into view when the user clicks on the associated item
Parameters:
component - The component
label - The text to appear in the menu
Returns:
The created component


add

public Component add(Image image, String label, int width, int height)
Adds an image to the menu.
deprecated:
Use add(Image, String) instead
Parameters:
image - The image
label - The text
width - Prefered width
height - Prefered height
Returns:
The created component


add

public Component add(Image image, String label)
Adds an image (with a label) and returns the component created to represent them
Parameters:
image - The image to display
label - The label to show
Returns:
The component created


add

public Component add(Action action, int width, int height)
Adds an action to the menu
deprecated:
Use add(imageURL) instead
Parameters:
action - The action to add
width - The width
height - The height
Returns:
The created component


add

public Component add(Action action)
Adds an action to the list, creating a menu item and a carousel entry
Parameters:
action - The action to add
Returns:
The resultant component


add

public Component add(String imageURL, String label, int width, int height)
Adds an image (through a URL) to the menu
deprecated:
Use add(imageURL, label) instead
Parameters:
imageURL - URL of the image
label - Text message
width - width
height - height
Returns:
The created component


add

public Component add(String imageURL, String label)
Adds an image based on the imageURL and a text label, returning the component that is created as a result
Parameters:
imageURL - The URL of the image
label - Text label to be shown in the menu
Returns:
The created component


getList

public JList getList()
Returns the list part of the carousel menu
Returns:
The JList object


getPreferredSize

public Dimension getPreferredSize()
Return the preferred size of the component
Returns:
The prefered dimensions of the component


keyPressed

public void keyPressed(KeyEvent keyEvent)
Listen for key events, when we see one that looks like it should wrap, set up the lastSelection variable to trigger a change on release of the key
Parameters:
keyEvent - The key event


keyReleased

public void keyReleased(KeyEvent keyEvent)
If the wrap-around has detected the need to wrap, sets the selection to the value calculated when the key was first pressed.
Parameters:
keyEvent - The key event


keyTyped

public void keyTyped(KeyEvent keyEvent)
Don't Care *
Parameters:
keyEvent - The key event


mouseClicked

public void mouseClicked(MouseEvent mouseEvent)
Look to see if an item in the list is double clicked, and launch the action if it is
Parameters:
mouseEvent - The mouse event


mouseEntered

public void mouseEntered(MouseEvent mouseEvent)
Don't Care *
Parameters:
mouseEvent - The mouse event


mouseExited

public void mouseExited(MouseEvent mouseEvent)
Don't Care *
Parameters:
mouseEvent - The mouse event


mousePressed

public void mousePressed(MouseEvent mouseEvent)
Don't Care *
Parameters:
mouseEvent - The mouse event


mouseReleased

public void mouseReleased(MouseEvent mouseEvent)
Don't Care *
Parameters:
mouseEvent - The mouse event


mouseWheelMoved

public void mouseWheelMoved(MouseWheelEvent mouseWheelEvent)
Moves the selected menu up or down when the mouse wheel scrolls
Parameters:
mouseWheelEvent - The mouse wheel event


processAction

protected void processAction()
Launch the action associated with the currently selected list item


remove

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


setCellImageBorder

public void setCellImageBorder(ImageBorder imageBorder)
Sets the image border used to draw around the items in the menu
Parameters:
imageBorder - The desired image border


setCellRenderer

public void setCellRenderer(ListCellRenderer cellRenderer)
Specifies the list cell renderer used to draw the items in the menu
Parameters:
cellRenderer - The list cell renderer


setMenuScrollColor

public void setMenuScrollColor(Color color)
Allows the background color to the menu (left side) to be set
Parameters:
color - Sets the background color to the menu


setSelectedIndex

public void setSelectedIndex(int i)
Sets the selected item in the menu
Parameters:
i - The index of the item to select


setUpDownColor

public void setUpDownColor(Color color)
Sets the color the up and down buttons are drawn
Parameters:
color - The desired color


setUpDownIcons

public void setUpDownIcons(Icon upIcon, Icon downIcon)
Sets icons to use to show the up and down buttons
Parameters:
upIcon - The icon to use for up
downIcon - The icon to use for down


stateChanged

public void stateChanged(ChangeEvent e)
Detect when the list selection changes, and respond by updating the state of the two "arrow" buttons. Contributed by Sebastian Charpentier.
Parameters:
e - The state changed event
See Also:
ChangeListener.stateChanged


valueChanged

public void valueChanged(ListSelectionEvent listSelectionEvent)
Detect when the list selection changes, and respond by rotating the carousel to show that item
Parameters:
listSelectionEvent - The list selection change event


 

Groovy Documentation