/Users/lyon/j4p/src/gui/run/RunList.java
|
1 package gui.run;
2
3 import gui.ClosableJFrame;
4
5 import javax.swing.JList;
6 import javax.swing.ListModel;
7 import javax.swing.ListSelectionModel;
8 import javax.swing.event.ListSelectionEvent;
9 import javax.swing.event.ListSelectionListener;
10 import java.util.Vector;
11
12
13 public abstract class RunList extends
14 JList
15 implements
16 ListSelectionListener,
17 Runnable {
18 public RunList(Vector v) {
19 super(v);
20 addListSelectionListener(this);
21 }
22
23 public RunList() {
24 addListSelectionListener(this);
25 }
26
27 public RunList(ListModel dataModel) {
28 super(dataModel);
29 addListSelectionListener(this);
30 }
31
32 public RunList(Object[] listData) {
33 super(listData);
34 addListSelectionListener(this);
35 }
36
37 public void valueChanged(ListSelectionEvent e) {
38 // just print once
39 if (!e.getValueIsAdjusting())
40 run();
41 }
42
43 public static void main(String[] args) {
44 testSimpleList();
45 }
46
47 public static void testSimpleList() {
48 ClosableJFrame cf = new ClosableJFrame("RunList");
49 java.awt.Container c = cf.getContentPane();
50 String list[] = {"this", "is", "a",
51 "test"};
52 RunList runList = new RunList(list) {
53 public void run() {
54 Object o[] = getSelectedValues();
55 for (int i = 0; i < o.length; i++)
56 System.out.println(o[i]);
57 }
58 };
59 runList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
60 c.add(runList);
61 c.setLayout(new java.awt.GridLayout(1, 0));
62 cf.setSize(200, 200);
63 cf.setVisible(true);
64 }
65
66 }