1
2
3
4
5 package spellcast.ui;
6
7 import java.awt.*;
8 import javax.swing.*;
9 import spellcast.gestures.*;
10
11 /***
12 * The GestureHistoryCellRender is a Cell Renderer for the JList class
13 * that renders the gesture history list model. It renders the icon
14 * associated with each gesture into the list.
15 *
16 * @author Barrie Treloar
17 */
18 public class GestureHistoryCellRenderer extends JLabel
19 implements ListCellRenderer
20 {
21 int hand;
22
23 /***
24 * Create a cell renderer with the specified handedness.
25 *
26 * @param hand either <code>GestureIcon.LEFT_HANDED</code> or
27 * <code>GestureIcon.RIGHT_HANDED</code>
28 */
29 public GestureHistoryCellRenderer( int hand )
30 {
31 this.hand = hand;
32 setBorder( BorderFactory.createEmptyBorder( 0, 0, 1, 1 ) );
33 }
34
35 /***
36 * Return a component with the list cell rendered in it.
37 */
38 public Component getListCellRendererComponent( JList list,
39 Object value,
40 int index,
41 boolean isSelected,
42 boolean cellHasFocus )
43 {
44 if ( ! ( value instanceof Gesture ) )
45 {
46 throw new RuntimeException( "GestureHistoryCellRender can only render Gestures. " +
47 "Instead received: " + value.getClass().getName() );
48 }
49 Gesture g = (Gesture)value;
50 setIcon( GestureIcon.getIconForGesture( g, hand ) );
51 return this;
52 }
53 }