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.graphelements;
51
52 import com.touchgraph.graphlayout.*;
53
54
55 /*** VisibleLocality: Extends Locality to spefically handle the
56 * Nodes + Edges that are visible on screen. The visible attribute
57 * of the nodes + edges is set to true when they appear on screen, and
58 * false when they are removed from screen.
59 *
60 * Locality is used in conjunction with LocalityUtils, which handle
61 * locality shift animations.
62 *
63 *
64 * @author Alexander Shapiro
65 * @version 1.21 $Id: VisibleLocality.java,v 1.1.1.1 2004/02/06 08:44:07 keesj Exp $
66 */
67 public class VisibleLocality extends Locality {
68
69 public VisibleLocality(GraphEltSet ges) {
70 super(ges);
71 }
72
73 public void addNode( Node node ) throws TGException {
74 super.addNode(node);
75 node.setVisible(true);
76 }
77
78 public void addEdge( Edge edge ) {
79 if(!contains(edge)) {
80 super.addEdge(edge);
81 edge.from.visibleEdgeCnt++;
82 edge.to.visibleEdgeCnt++;
83 }
84 }
85
86 public boolean removeEdge( Edge edge ) {
87 boolean removed = super.removeEdge(edge);
88 if (removed) {
89 edge.setVisible(false);
90 edge.from.visibleEdgeCnt--;
91 edge.to.visibleEdgeCnt--;
92 }
93 return removed;
94 }
95
96 public boolean removeNode( Node node ) {
97 boolean removed = super.removeNode(node);
98 if (removed) {
99 node.setVisible(false);
100 }
101 return removed;
102 }
103
104 public synchronized void removeAll() {
105 for (int i = 0 ; i < nodeCount(); i++) {
106 nodeAt(i).setVisible(false);
107 }
108 for (int i = 0 ; i < edgeCount(); i++) {
109 edgeAt(i).setVisible(false);
110 }
111 super.removeAll();
112 }
113
114 public void updateLocalityFromVisibility() throws TGException {
115
116
117 TGForEachNode fen = new TGForEachNode() {
118 public void forEachNode( Node node ) {
119 try {
120 if (node.isVisible() && !contains(node))
121 addNode(node);
122 else if (!node.isVisible() && contains(node))
123 removeNode(node);
124 }
125 catch (TGException ex) { ex.printStackTrace(); }
126 }
127 };
128 completeEltSet.forAllNodes(fen);
129
130
131
132 TGForEachEdge fee = new TGForEachEdge() {
133 public void forEachEdge( Edge edge ) {
134 if (edge.isVisible() && !contains(edge))
135 addEdge(edge);
136 else if (!edge.isVisible() && contains(edge))
137 removeEdge(edge);
138 }
139 };
140 completeEltSet.forAllEdges(fee);
141 }
142 }