Skip to content
This repository was archived by the owner on Aug 30, 2025. It is now read-only.

Commit 00dc928

Browse files
committed
Handle neighbours case in graph selection
1 parent 240cc79 commit 00dc928

File tree

3 files changed

+44
-35
lines changed

3 files changed

+44
-35
lines changed

modules/engine-core/src/main/java/org/gephi/viz/engine/status/GraphSelection.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,17 @@ enum GraphSelectionMode {
2121

2222
boolean isNodeSelected(Node node);
2323

24-
int getSelectedNodesCount();
25-
2624
Set<Node> getSelectedNodes();
2725

28-
void setSelectedNodes(Collection<Node> nodes);
29-
30-
void addSelectedNodes(Collection<Node> nodes);
26+
Set<Node> getSelectedNodesWithNeighbours();
3127

32-
void removeSelectedNodes(Collection<Node> nodes);
28+
void setSelectedNodes(Collection<Node> nodes, Collection<Node> neighbours);
3329

34-
void setSelectedNode(Node node);
30+
void addSelectedNodes(Collection<Node> nodes, Collection<Node> neighbours);
3531

36-
void addSelectedNode(Node node);
32+
void setSelectedNode(Node node, Collection<Node> neighbours);
3733

38-
void removeSelectedNode(Node node);
34+
void addSelectedNode(Node node, Collection<Node> neighbours);
3935

4036
void clearSelectedNodes();
4137

modules/engine-core/src/main/java/org/gephi/viz/engine/status/GraphSelectionImpl.java

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
public class GraphSelectionImpl implements GraphSelection {
1414

1515
private final Set<Node> nodes = new HashSet<>();
16+
private final Set<Node> nodesWithNeighbours = new HashSet<>();
1617
private final Set<Edge> edges = new HashSet<>();
1718
private GraphSelection.GraphSelectionMode selectionMode;
1819

@@ -27,12 +28,7 @@ public boolean someNodesOrEdgesSelection() {
2728

2829
@Override
2930
public boolean isNodeSelected(Node node) {
30-
return nodes.contains(node);
31-
}
32-
33-
@Override
34-
public int getSelectedNodesCount() {
35-
return nodes.size();
31+
return nodesWithNeighbours.contains(node);
3632
}
3733

3834
@Override
@@ -41,48 +37,57 @@ public Set<Node> getSelectedNodes() {
4137
}
4238

4339
@Override
44-
public void setSelectedNodes(Collection<Node> nodes) {
45-
this.nodes.clear();
46-
if (nodes != null) {
47-
this.nodes.addAll(nodes);
48-
}
40+
public Set<Node> getSelectedNodesWithNeighbours() {
41+
return Collections.unmodifiableSet(nodesWithNeighbours);
4942
}
5043

5144
@Override
52-
public void addSelectedNodes(Collection<Node> nodes) {
45+
public void setSelectedNodes(Collection<Node> nodes, Collection<Node> neighbours) {
46+
this.nodes.clear();
47+
this.nodesWithNeighbours.clear();
5348
if (nodes != null) {
5449
this.nodes.addAll(nodes);
50+
this.nodesWithNeighbours.addAll(nodes);
51+
if (neighbours != null) {
52+
this.nodesWithNeighbours.addAll(neighbours);
53+
}
5554
}
5655
}
5756

5857
@Override
59-
public void removeSelectedNodes(Collection<Node> nodes) {
58+
public void addSelectedNodes(Collection<Node> nodes, Collection<Node> neighbours) {
6059
if (nodes != null) {
61-
this.nodes.removeAll(nodes);
60+
this.nodes.addAll(nodes);
61+
this.nodesWithNeighbours.addAll(nodes);
62+
if (neighbours != null) {
63+
this.nodesWithNeighbours.addAll(neighbours);
64+
}
6265
}
6366
}
6467

6568
@Override
66-
public void setSelectedNode(Node node) {
69+
public void setSelectedNode(Node node, Collection<Node> neighbours) {
6770
if (node == null) {
6871
this.clearSelectedNodes();
6972
} else {
7073
this.nodes.clear();
7174
this.nodes.add(node);
75+
this.nodesWithNeighbours.clear();
76+
this.nodesWithNeighbours.add(node);
77+
if (neighbours != null) {
78+
this.nodesWithNeighbours.addAll(neighbours);
79+
}
7280
}
7381
}
7482

7583
@Override
76-
public void addSelectedNode(Node node) {
84+
public void addSelectedNode(Node node, Collection<Node> neighbours) {
7785
if (node != null) {
7886
this.nodes.add(node);
79-
}
80-
}
81-
82-
@Override
83-
public void removeSelectedNode(Node node) {
84-
if (node != null) {
85-
this.nodes.remove(node);
87+
this.nodesWithNeighbours.add(node);
88+
if (neighbours != null) {
89+
this.nodesWithNeighbours.addAll(neighbours);
90+
}
8691
}
8792
}
8893

modules/opengl-commons/src/main/java/org/gephi/viz/engine/util/actions/InputActionsProcessor.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.gephi.viz.engine.util.actions;
22

3+
import java.util.Collection;
34
import java.util.HashSet;
45
import java.util.Iterator;
56
import java.util.Set;
@@ -53,6 +54,7 @@ public void selectNodes(final NodeIterable nodesIterable) {
5354

5455
final Iterator<Node> iterator = nodesIterable.iterator();
5556
final Set<Node> selectionNodes = new HashSet<>();
57+
final Set<Node> selectionNeighbours = new HashSet<>();
5658
final Set<Edge> selectionEdges = new HashSet<>();
5759

5860
final boolean selectNeighbours = renderingOptions.isAutoSelectNeighbours();
@@ -61,13 +63,19 @@ public void selectNodes(final NodeIterable nodesIterable) {
6163
final Node node = iterator.next();
6264

6365
selectionNodes.add(node);
64-
selectionEdges.addAll(graph.getEdges(node).toCollection());
66+
Collection<Edge> edges = graph.getEdges(node).toCollection();
67+
selectionEdges.addAll(edges);
6568
if (selectNeighbours) {
66-
selectionNodes.addAll(graph.getNeighbors(node).toCollection());
69+
for (Edge edge : edges) {
70+
Node oppositeNode = graph.getOpposite(node, edge);
71+
if (oppositeNode != null && oppositeNode != node) {
72+
selectionNeighbours.add(oppositeNode);
73+
}
74+
}
6775
}
6876
}
6977

70-
selection.setSelectedNodes(selectionNodes);
78+
selection.setSelectedNodes(selectionNodes, selectionNeighbours);
7179
selection.setSelectedEdges(selectionEdges);
7280
} finally {
7381
if (iterator.hasNext()) {

0 commit comments

Comments
 (0)