Source code: org/altara/util/ListContextMenuSupport.java
1 /* Altara Utility Classes
2 Copyright (C) 2001,2002 Brian H. Trammell
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, it is available at
16 http://www.gnu.org/copyleft/lesser.html, or by writing to the
17 Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18 Boston, MA 02111-1307 USA
19 */
20
21 package org.altara.util;
22
23 import java.util.*;
24 import java.awt.*;
25 import java.awt.event.*;
26 import javax.swing.*;
27 import javax.swing.event.*;
28
29 public class ListContextMenuSupport extends ContextMenuSupport {
30
31 private JList list;
32
33 public ListContextMenuSupport(JList list) {
34 super(list);
35 this.list = list;
36 }
37
38 protected Object findInvoked(MouseEvent me) {
39 Point pt = new Point(me.getX(),me.getY());
40 int index = list.locationToIndex(pt);
41 if (index < 0) return null;
42 return list.getModel().getElementAt(index);
43 }
44 }