View Javadoc

1   /*
2    * @(#)$Id: ScrollableList.java 689 2009-07-22 00:10:27Z bsigner $
3    *
4    * Author		:	Ueli Kurmann, igesture@uelikurmann.ch
5    *
6    * Purpose		:   Implementation of a scrollable list.
7    *
8    * -----------------------------------------------------------------------
9    *
10   * Revision Information:
11   *
12   * Date				Who			Reason
13   *
14   * Nov 15, 2006     ukurmann    Initial Release
15   * Mar 24, 2007     bsigner     Cleanup
16   *
17   * -----------------------------------------------------------------------
18   *
19   * Copyright 1999-2009 ETH Zurich. All Rights Reserved.
20   *
21   * This software is the proprietary information of ETH Zurich.
22   * Use is subject to license terms.
23   * 
24   */
25  
26  
27  package org.ximtec.igesture.graphics;
28  
29  import java.awt.Color;
30  import java.awt.Dimension;
31  
32  import javax.swing.JList;
33  import javax.swing.JScrollPane;
34  import javax.swing.ListModel;
35  import javax.swing.border.LineBorder;
36  
37  
38  /**
39   * Implementation of a scrollable list.
40   * 
41   * @version 1.0 Nov 2006
42   * @author Ueli Kurmann, igesture@uelikurmann.ch
43   * @author Beat Signer, signer@inf.ethz.ch
44   */
45  public class ScrollableList extends JScrollPane {
46  
47     private JList list;
48  
49  
50     public ScrollableList(ListModel listModel, int width, int height) {
51        super();
52        setPreferredSize(new Dimension(width, height));
53        setAutoscrolls(true);
54  
55        if (listModel == null) {
56           list = new JList();
57        }
58        else {
59           list = new JList(listModel);
60        }
61  
62        list.setVisible(true);
63        list.setBorder(new LineBorder(Color.BLACK));
64        list.setAutoscrolls(true);
65        setViewportView(list);
66     }
67  
68  
69     public JList getList() {
70        return list;
71     } // getList
72  
73  
74     public int getSelectedIndex() {
75        return list.getSelectedIndex();
76     }
77  
78  
79     public Object getSelectedValue() {
80        return list.getSelectedValue();
81     } // getSelectedValue
82  
83  
84     public void setModel(ListModel model) {
85        list.setModel(model);
86     } // setModel
87  }