Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/memoire/dnd/DndRequestItem.java


1   /**
2    * @modification $Date: 2002/12/16 18:56:25 $
3    * @statut       unstable
4    * @file         DndRequestItem.java
5    * @version      0.36
6    * @author       Guillaume Desnoix
7    * @email        guillaume@desnoix.com
8    * @license      GNU General Public License 2 (GPL2)
9    * @copyright    1998-2001 Guillaume Desnoix
10   */
11  
12  package com.memoire.dnd;
13  import com.memoire.dnd.*;
14  
15  
16  import java.awt.*;
17  import javax.swing.*;
18  import javax.swing.tree.*;
19  
20  public class DndRequestItem
21      implements DndRequestData
22  {
23      public static final DndRequestItem SINGLETON=
24    new DndRequestItem();
25  
26      protected DndRequestItem() { }
27  
28      public Object[] request(JComponent _component,Point _location)
29      {
30    Object v=null;
31  
32    if(_component instanceof JList)
33    {
34        JList list =(JList)_component;
35        int   index=list.locationToIndex(_location);
36        if(index>=0) v=list.getModel().getElementAt(index);
37        //System.err.println("INDEX="+index);
38    }
39    else
40    if(_component instanceof JTree)
41    {
42        JTree    tree=(JTree)_component;
43        TreePath path=tree.getPathForLocation(_location.x,_location.y);
44        if(path!=null) v=path.getLastPathComponent();
45    }
46  
47    /*
48      System.err.println
49      ("VALUE="+v+
50      (v!=null ? ":"+v.getClass().getName() : ""));
51    */
52  
53    return (v==null ? new Object[0] : new Object[] { v });
54      }
55  }