1 package tim.prune.save;
3 import javax.swing.JButton;
4 import javax.swing.ListSelectionModel;
5 import javax.swing.event.ListSelectionEvent;
6 import javax.swing.event.ListSelectionListener;
10 * Class to enable and disable a pair of up and down buttons
12 public class UpDownToggler implements ListSelectionListener
14 private JButton _upButton = null;
15 private JButton _downButton = null;
16 private int _maxIndex = 0;
19 * Constructor giving buttons and size
20 * @param inUpButton up button
21 * @param inDownButton down button
22 * @param inListSize size of list
24 public UpDownToggler(JButton inUpButton, JButton inDownButton, int inListSize)
26 _upButton = inUpButton;
27 _downButton = inDownButton;
28 _maxIndex = inListSize - 1;
33 * list selection has changed
35 public void valueChanged(ListSelectionEvent e)
37 ListSelectionModel lsm = (ListSelectionModel) e.getSource();
38 if (lsm.isSelectionEmpty())
40 // no rows are selected
41 _upButton.setEnabled(false);
42 _downButton.setEnabled(false);
46 // single row is selected
47 int row = lsm.getMinSelectionIndex();
48 _upButton.setEnabled(row > 0);
49 _downButton.setEnabled(row >= 0 && row < _maxIndex);