1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50 package com.touchgraph.graphlayout.interaction;
51
52 import java.awt.event.*;
53
54 import javax.swing.*;
55 import javax.swing.event.*;
56
57 import com.touchgraph.graphlayout.*;
58
59 /*** GLNavigateUI. User interface for moving around the graph, as opposed
60 * to editing.
61 *
62 * @author Alexander Shapiro
63 * @author Murray Altheim (abstracted GLPanel to TGScrollPane interface)
64 * @version 1.21 $Id: GLNavigateUI.java,v 1.1.1.1 2004/02/06 08:44:07 keesj Exp $
65 */
66 public class GLNavigateUI extends TGUserInterface {
67
68 GLPanel glPanel;
69 TGPanel tgPanel;
70
71 GLNavigateMouseListener ml;
72
73 TGAbstractDragUI hvDragUI;
74 TGAbstractDragUI rotateDragUI;
75
76
77 TGAbstractClickUI hvScrollToCenterUI;
78 DragNodeUI dragNodeUI;
79 LocalityScroll localityScroll;
80 JPopupMenu nodePopup;
81 JPopupMenu edgePopup;
82 Node popupNode;
83 Edge popupEdge;
84
85 public GLNavigateUI( GLPanel glp ) {
86 glPanel = glp;
87 tgPanel = glPanel.getTGPanel();
88
89 localityScroll = glPanel.getLocalityScroll();
90 hvDragUI = glPanel.getHVScroll().getHVDragUI();
91 rotateDragUI = glPanel.getRotateScroll().getRotateDragUI();
92
93
94 hvScrollToCenterUI = glPanel.getHVScroll().getHVScrollToCenterUI();
95 dragNodeUI = new DragNodeUI(tgPanel);
96
97 ml = new GLNavigateMouseListener();
98 setUpNodePopup();
99 setUpEdgePopup();
100 }
101
102 public void activate() {
103 tgPanel.addMouseListener(ml);
104 }
105
106 public void deactivate() {
107 tgPanel.removeMouseListener(ml);
108 }
109
110 class GLNavigateMouseListener extends MouseAdapter {
111
112 public void mousePressed(MouseEvent e) {
113 if (e.isPopupTrigger()) {
114 triggerPopup(e);
115 }
116 else {
117 Node mouseOverN = tgPanel.getMouseOverN();
118 if (e.getModifiers() == MouseEvent.BUTTON1_MASK) {
119 if (mouseOverN == null)
120 hvDragUI.activate(e);
121 else
122 dragNodeUI.activate(e);
123 }
124 }
125 }
126
127 public void mouseClicked(MouseEvent e) {
128 Node mouseOverN = tgPanel.getMouseOverN();
129 if (e.getModifiers() == MouseEvent.BUTTON1_MASK) {
130 if ( mouseOverN != null) {
131 tgPanel.setSelect(mouseOverN);
132 try {
133 tgPanel.setLocale(mouseOverN, localityScroll.getLocalityRadius());
134 }
135 catch (TGException ex) {
136 System.out.println("Error setting locale");
137 ex.printStackTrace();
138 }
139
140 }
141 }
142 }
143
144 public void mouseReleased(MouseEvent e) {
145 if (e.isPopupTrigger()) {
146 triggerPopup(e);
147 }
148 }
149
150 private void triggerPopup(MouseEvent e) {
151 popupNode = tgPanel.getMouseOverN();
152 popupEdge = tgPanel.getMouseOverE();
153 if (popupNode!=null) {
154 tgPanel.setMaintainMouseOver(true);
155 nodePopup.show(e.getComponent(), e.getX(), e.getY());
156 }
157 else if (popupEdge!=null) {
158 tgPanel.setMaintainMouseOver(true);
159 edgePopup.show(e.getComponent(), e.getX(), e.getY());
160 }
161 else {
162 glPanel.glPopup.show(e.getComponent(), e.getX(), e.getY());
163 }
164 }
165 }
166
167
168 private void setUpNodePopup() {
169 nodePopup = new JPopupMenu();
170 JMenuItem menuItem;
171
172 menuItem = new JMenuItem("Expand Node");
173 ActionListener expandAction = new ActionListener() {
174 public void actionPerformed(ActionEvent e) {
175 if(popupNode!=null) {
176 tgPanel.expandNode(popupNode);
177 }
178 }
179 };
180
181 menuItem.addActionListener(expandAction);
182 nodePopup.add(menuItem);
183
184 menuItem = new JMenuItem("Collapse Node");
185 ActionListener collapseAction = new ActionListener() {
186 public void actionPerformed(ActionEvent e) {
187 if(popupNode!=null) {
188 tgPanel.collapseNode(popupNode );
189 }
190 }
191 };
192
193 menuItem.addActionListener(collapseAction);
194 nodePopup.add(menuItem);
195
196 menuItem = new JMenuItem("Hide Node");
197 ActionListener hideAction = new ActionListener() {
198 public void actionPerformed(ActionEvent e) {
199 if(popupNode!=null) {
200 tgPanel.hideNode(popupNode );
201 }
202 }
203 };
204
205 menuItem.addActionListener(hideAction);
206 nodePopup.add(menuItem);
207
208 nodePopup.addPopupMenuListener(new PopupMenuListener() {
209 public void popupMenuCanceled(PopupMenuEvent e) {}
210 public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
211 tgPanel.setMaintainMouseOver(false);
212 tgPanel.setMouseOverN(null);
213 tgPanel.repaint();
214 }
215 public void popupMenuWillBecomeVisible(PopupMenuEvent e) {}
216 });
217
218 }
219
220 private void setUpEdgePopup() {
221 edgePopup = new JPopupMenu();
222 JMenuItem menuItem;
223
224 menuItem = new JMenuItem("Hide Edge");
225 ActionListener hideAction = new ActionListener() {
226 public void actionPerformed(ActionEvent e) {
227 if(popupEdge!=null) {
228 tgPanel.hideEdge(popupEdge);
229 }
230 }
231 };
232
233 menuItem.addActionListener(hideAction);
234 edgePopup.add(menuItem);
235
236 edgePopup.addPopupMenuListener(new PopupMenuListener() {
237 public void popupMenuCanceled(PopupMenuEvent e) {}
238 public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
239 tgPanel.setMaintainMouseOver(false);
240 tgPanel.setMouseOverE(null);
241 tgPanel.repaint();
242 }
243 public void popupMenuWillBecomeVisible(PopupMenuEvent e) {}
244 });
245 }
246
247 }