1
2
3
4
5
6
7
8
9
10 package nl.tudelft.simulation.dsol.gui.statistics;
11
12 import java.awt.dnd.DnDConstants;
13 import java.awt.dnd.DragGestureEvent;
14 import java.awt.dnd.DragGestureListener;
15 import java.awt.dnd.DragSource;
16
17 import javax.naming.NamingException;
18 import javax.swing.JTree;
19 import javax.swing.tree.DefaultMutableTreeNode;
20 import javax.swing.tree.TreePath;
21
22 import nl.tudelft.simulation.event.EventInterface;
23 import nl.tudelft.simulation.event.EventListenerInterface;
24 import nl.tudelft.simulation.jstats.Swingable;
25 import nl.tudelft.simulation.naming.InitialEventContext;
26 import nl.tudelft.simulation.naming.context.ContextTransferable;
27 import nl.tudelft.simulation.naming.context.ContextTreeModel;
28 import nl.tudelft.simulation.naming.context.SimpleDragSourceListener;
29
30 /***
31 * The StatisticsTree extends a Tree and drags an object <br>
32 * (c) copyright 2003 <a href="http://www.simulation.tudelft.nl">Delft
33 * University of Technology </a>, the Netherlands. <br>
34 * See for project information <a
35 * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
36 * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
37 * License (GPL) </a>, no warranty <br>
38 *
39 * @version 1.0 18.10.2003 <br>
40 * @author <a href="http://www.simulation.tudelft.nl/people/jacobs.html">Peter
41 * Jacobs </a>
42 */
43 public class StatisticsTree extends JTree implements DragGestureListener,
44 EventListenerInterface
45 {
46
47 /***
48 * constructs a new StatisticsTree
49 *
50 * @throws NamingException on failure
51 */
52 public StatisticsTree() throws NamingException
53 {
54 super(new ContextTreeModel(new InitialEventContext(),
55 new Class[]{Swingable.class}, false));
56 DragSource dragSource = DragSource.getDefaultDragSource();
57 dragSource.createDefaultDragGestureRecognizer(this,
58 DnDConstants.ACTION_COPY_OR_MOVE, this);
59 }
60
61 /***
62 * @see java.awt.dnd.DragGestureListener
63 * #dragGestureRecognized(java.awt.dnd.DragGestureEvent)
64 */
65 public void dragGestureRecognized(final DragGestureEvent dge)
66 {
67 try
68 {
69 TreePath path = getLeadSelectionPath();
70 DefaultMutableTreeNode node = (DefaultMutableTreeNode) path
71 .getLastPathComponent();
72 dge.startDrag(DragSource.DefaultCopyDrop, new ContextTransferable(
73 node.getUserObject()), new SimpleDragSourceListener());
74 } catch (Exception nullPointerException)
75 {
76
77 return;
78 }
79 }
80
81 /***
82 * @see nl.tudelft.simulation.event.EventListenerInterface
83 * #notify(nl.tudelft.simulation.event.EventInterface)
84 */
85 public void notify(final EventInterface event)
86 {
87 this.validate();
88 this.repaint();
89 }
90 }