Line | Hits | Source |
---|---|---|
1 | /* | |
2 | * Copyright (c) 2005, the JUNG Project and the Regents of the University of | |
3 | * California All rights reserved. | |
4 | * | |
5 | * This software is open-source under the BSD license; see either "license.txt" | |
6 | * or http://jung.sourceforge.net/license.txt for a description. | |
7 | * | |
8 | * Created on Jul 7, 2005 | |
9 | */ | |
10 | ||
11 | package edu.uci.ics.jung.visualization.control; | |
12 | ||
13 | import java.awt.Component; | |
14 | import java.awt.event.MouseEvent; | |
15 | import java.awt.event.MouseListener; | |
16 | import java.awt.event.MouseMotionListener; | |
17 | import java.awt.event.MouseWheelEvent; | |
18 | import java.awt.event.MouseWheelListener; | |
19 | import java.util.LinkedHashSet; | |
20 | import java.util.Set; | |
21 | ||
22 | import edu.uci.ics.jung.visualization.VisualizationViewer; | |
23 | ||
24 | /** | |
25 | * a GraphMouse that accepts plugins for various mouse events. | |
26 | * | |
27 | * @author Tom Nelson - RABA Technologies | |
28 | * | |
29 | * | |
30 | */ | |
31 | 0 | public class PluggableGraphMouse implements VisualizationViewer.GraphMouse { |
32 | ||
33 | MouseListener[] mouseListeners; | |
34 | MouseMotionListener[] mouseMotionListeners; | |
35 | MouseWheelListener[] mouseWheelListeners; | |
36 | 0 | Set mousePluginList = new LinkedHashSet(); |
37 | 0 | Set mouseMotionPluginList = new LinkedHashSet(); |
38 | 0 | Set mouseWheelPluginList = new LinkedHashSet(); |
39 | ||
40 | public void add(GraphMousePlugin plugin) { | |
41 | 0 | if(plugin instanceof MouseListener) { |
42 | 0 | mousePluginList.add(plugin); |
43 | 0 | mouseListeners = null; |
44 | } | |
45 | 0 | if(plugin instanceof MouseMotionListener) { |
46 | 0 | mouseMotionPluginList.add(plugin); |
47 | 0 | mouseMotionListeners = null; |
48 | } | |
49 | 0 | if(plugin instanceof MouseWheelListener) { |
50 | 0 | mouseWheelPluginList.add(plugin); |
51 | 0 | mouseWheelListeners = null; |
52 | } | |
53 | 0 | } |
54 | ||
55 | public void remove(GraphMousePlugin plugin) { | |
56 | 0 | if(plugin instanceof MouseListener) { |
57 | 0 | boolean wasThere = mousePluginList.remove(plugin); |
58 | 0 | if(wasThere) mouseListeners = null; |
59 | } | |
60 | 0 | if(plugin instanceof MouseMotionListener) { |
61 | 0 | boolean wasThere = mouseMotionPluginList.remove(plugin); |
62 | 0 | if(wasThere) mouseMotionListeners = null; |
63 | } | |
64 | 0 | if(plugin instanceof MouseWheelListener) { |
65 | 0 | boolean wasThere = mouseWheelPluginList.remove(plugin); |
66 | 0 | if(wasThere) mouseWheelListeners = null; |
67 | } | |
68 | 0 | } |
69 | ||
70 | private void checkMouseListeners() { | |
71 | 0 | if(mouseListeners == null) { |
72 | 0 | mouseListeners = (MouseListener[]) |
73 | mousePluginList.toArray(new MouseListener[mousePluginList.size()]); | |
74 | } | |
75 | 0 | } |
76 | ||
77 | private void checkMouseMotionListeners() { | |
78 | 0 | if(mouseMotionListeners == null){ |
79 | 0 | mouseMotionListeners = (MouseMotionListener[]) |
80 | mouseMotionPluginList.toArray(new MouseMotionListener[mouseMotionPluginList.size()]); | |
81 | } | |
82 | 0 | } |
83 | ||
84 | private void checkMouseWheelListeners() { | |
85 | 0 | if(mouseWheelListeners == null) { |
86 | 0 | mouseWheelListeners = (MouseWheelListener[]) |
87 | mouseWheelPluginList.toArray(new MouseWheelListener[mouseWheelPluginList.size()]); | |
88 | } | |
89 | 0 | } |
90 | ||
91 | public void mouseClicked(MouseEvent e) { | |
92 | 0 | checkMouseListeners(); |
93 | 0 | for(int i=0; i<mouseListeners.length; i++) { |
94 | 0 | mouseListeners[i].mouseClicked(e); |
95 | 0 | if(e.isConsumed()) break; |
96 | } | |
97 | 0 | ((Component) e.getSource()).repaint(); |
98 | 0 | } |
99 | ||
100 | public void mousePressed(MouseEvent e) { | |
101 | 0 | checkMouseListeners(); |
102 | 0 | for(int i=0; i<mouseListeners.length; i++) { |
103 | 0 | mouseListeners[i].mousePressed(e); |
104 | 0 | if(e.isConsumed()) break; |
105 | } | |
106 | 0 | ((Component) e.getSource()).repaint(); |
107 | 0 | } |
108 | ||
109 | public void mouseReleased(MouseEvent e) { | |
110 | 0 | checkMouseListeners(); |
111 | 0 | for(int i=0; i<mouseListeners.length; i++) { |
112 | 0 | mouseListeners[i].mouseReleased(e); |
113 | 0 | if(e.isConsumed()) break; |
114 | } | |
115 | 0 | ((Component) e.getSource()).repaint(); |
116 | 0 | } |
117 | ||
118 | public void mouseEntered(MouseEvent e) { | |
119 | 0 | checkMouseListeners(); |
120 | 0 | for(int i=0; i<mouseListeners.length; i++) { |
121 | 0 | mouseListeners[i].mouseEntered(e); |
122 | 0 | if(e.isConsumed()) break; |
123 | } | |
124 | 0 | ((Component) e.getSource()).repaint(); |
125 | 0 | } |
126 | ||
127 | public void mouseExited(MouseEvent e) { | |
128 | 0 | checkMouseListeners(); |
129 | 0 | for(int i=0; i<mouseListeners.length; i++) { |
130 | 0 | mouseListeners[i].mouseExited(e); |
131 | 0 | if(e.isConsumed()) break; |
132 | } | |
133 | 0 | ((Component) e.getSource()).repaint(); |
134 | 0 | } |
135 | ||
136 | public void mouseDragged(MouseEvent e) { | |
137 | 0 | checkMouseMotionListeners(); |
138 | 0 | for(int i=0; i<mouseMotionListeners.length; i++) { |
139 | 0 | mouseMotionListeners[i].mouseDragged(e); |
140 | 0 | if(e.isConsumed()) break; |
141 | } | |
142 | 0 | ((Component) e.getSource()).repaint(); |
143 | 0 | } |
144 | ||
145 | public void mouseMoved(MouseEvent e) { | |
146 | 0 | checkMouseMotionListeners(); |
147 | 0 | for(int i=0; i<mouseMotionListeners.length; i++) { |
148 | 0 | mouseMotionListeners[i].mouseMoved(e); |
149 | 0 | if(e.isConsumed()) break; |
150 | } | |
151 | 0 | ((Component) e.getSource()).repaint(); |
152 | 0 | } |
153 | ||
154 | public void mouseWheelMoved(MouseWheelEvent e) { | |
155 | 0 | checkMouseWheelListeners(); |
156 | 0 | for(int i=0; i<mouseWheelListeners.length; i++) { |
157 | 0 | mouseWheelListeners[i].mouseWheelMoved(e); |
158 | 0 | if(e.isConsumed()) break; |
159 | } | |
160 | 0 | ((Component) e.getSource()).repaint(); |
161 | 0 | } |
162 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |