001 package net.sourceforge.bee;
002
003 import java.util.*;
004 import javax.swing.*;
005 import javax.swing.table.*;
006 import javax.swing.event.*;
007
008 /**
009 * I was suprised to see that you can't add ListSelectionListeners to JTables.
010 * This class lets you. ListSelectionEvents are fired when a user selects
011 * rows in the table.
012 *
013 * @author <a href="mailto:"></a>
014 * @version 1.0
015 */
016 public class ListSelectionJTable
017 extends JTable
018 {
019 private Vector<ListSelectionListener> v
020 = new Vector<ListSelectionListener>();
021
022
023 /**
024 * Creates a new <code>ListSelectionJTable</code> instance given a
025 * TableModel.
026 *
027 * @param t a <code>TableModel</code> value
028 * @deprecated
029 * FIXME: this just calls super(t)
030 */
031 @Deprecated public ListSelectionJTable(TableModel t)
032 {
033 super(t);
034 }
035
036 /**
037 * Registers the listener.
038 *
039 * @param x a <code>ListSelectionListener</code> value
040 */
041 public void addListSelectionListener(ListSelectionListener x)
042 {
043 v.add(x);
044 }
045
046 /**
047 * Notifies listeners of ListSelectionEvent.
048 *
049 * @param e a <code>ListSelectionEvent</code> value
050 */
051 public void notifyListeners(ListSelectionEvent e)
052 {
053 //super.notifyListeners(e);
054 if(v==null) return;
055 for(ListSelectionListener y : v) {
056 y.valueChanged(e);
057 }
058
059 }
060
061
062 /**
063 * Called when the selected row(s) have changed. Calls notifyListeners.
064 *
065 * @param e a <code>ListSelectionEvent</code> value
066 */
067 public void valueChanged(ListSelectionEvent e)
068 {
069 super.valueChanged(e);
070 notifyListeners(e);
071 }
072
073
074
075
076 }