use of org.gephi.visualization.model.node.NodeModel in project gephi by gephi.
the class CompatibilityEngine method mouseClick.
@Override
public void mouseClick() {
if (vizConfig.isSelectionEnable() && rectangleSelection && !customSelection) {
Rectangle rectangle = (Rectangle) currentSelectionArea;
//rectangle.setBlocking(false);
resetEdgesSelection();
//Select with click
boolean someSelection = false;
for (Iterator<NodeModel> itr = octree.getSelectableNodeIterator(); itr.hasNext(); ) {
NodeModel obj = (NodeModel) itr.next();
if (isUnderMouse(obj)) {
if (!obj.isSelected()) {
//New selected
obj.setSelected(true);
}
someSelection = true;
} else if (obj.isSelected()) {
someSelection = true;
}
}
if (!(rectangle.isCtrl() && someSelection)) {
for (NodeModel nm : getSelectedNodes()) {
nm.setSelected(false);
}
someSelection = false;
}
rectangle.setBlocking(someSelection);
if (vizController.getVizModel().isLightenNonSelectedAuto()) {
if (vizConfig.isLightenNonSelectedAnimation()) {
if (!anySelected && someSelection) {
//Start animation
lightenAnimationDelta = 0.07f;
} else if (anySelected && !someSelection) {
//Stop animation
lightenAnimationDelta = -0.07f;
}
vizConfig.setLightenNonSelected(someSelection || lightenAnimationDelta != 0);
} else {
vizConfig.setLightenNonSelected(someSelection);
}
}
anySelected = someSelection;
scheduler.requireUpdateSelection();
}
}
use of org.gephi.visualization.model.node.NodeModel in project gephi by gephi.
the class Octant method trimNodes.
private void trimNodes() {
if (nodesLength >= TRIM_THRESHOLD && ((float) nodeCount) / nodesLength < TRIM_RATIO) {
NodeModel[] t = new NodeModel[nodeCount];
if (nodeCount > 0) {
int c = 0;
for (int i = 0; i < nodes.length; i++) {
NodeModel n = nodes[i];
if (n != null) {
n.setOctantId(c);
t[c++] = n;
}
}
}
nodesLength = t.length;
nodes = t;
nodesGarbage = null;
nodesGarbageLength = 0;
}
}
use of org.gephi.visualization.model.node.NodeModel in project gephi by gephi.
the class Octree method repositionNodes.
public boolean repositionNodes() {
List<NodeModel> movedNodes = new ArrayList<>();
for (int i = 0; i < length; i++) {
Octant leaf = leaves[i];
if (leaf != null) {
int l = leaf.nodesLength;
NodeModel[] nodes = leaf.nodes;
for (int j = 0; j < l; j++) {
NodeModel node = nodes[j];
if (node != null) {
if (!node.isInOctreeLeaf(leaf)) {
removeNode(node);
movedNodes.add(node);
}
}
}
}
}
if (!movedNodes.isEmpty()) {
for (NodeModel node : movedNodes) {
addNode(node);
}
return true;
}
return false;
}
use of org.gephi.visualization.model.node.NodeModel in project gephi by gephi.
the class GraphContextMenu method getMenu.
public JPopupMenu getMenu() {
GraphContextMenuItem[] items = getGraphContextMenuItems();
final List<NodeModel> selectedNodeModels = engine.getSelectedNodes();
Node[] selectedNodes = new Node[selectedNodeModels.size()];
int i = 0;
for (NodeModel nm : selectedNodeModels) {
selectedNodes[i++] = nm.getNode();
}
final Graph graph = dataBridge.getGraph();
JPopupMenu contextMenu = new JPopupMenu();
//Add items ordered:
Integer lastItemType = null;
for (GraphContextMenuItem item : items) {
item.setup(graph, selectedNodes);
if (lastItemType == null) {
lastItemType = item.getType();
}
if (lastItemType != item.getType()) {
contextMenu.addSeparator();
}
lastItemType = item.getType();
if (item.isAvailable()) {
contextMenu.add(createMenuItemFromGraphContextMenuItem(item, graph, selectedNodes));
}
}
return contextMenu;
}
use of org.gephi.visualization.model.node.NodeModel in project gephi by gephi.
the class DataBridge method updateWorld.
public synchronized boolean updateWorld() {
boolean force = false;
if (graphModel != null) {
graphModel.getGraph().writeLock();
}
try {
if ((observer != null && observer.isDestroyed()) || (graphModel != null && graph.getView() != graphModel.getVisibleView())) {
if (observer != null && !observer.isDestroyed()) {
observer.destroy();
}
observer = null;
if (graphModel != null) {
graph = graphModel.getGraphVisible();
observer = graphModel.createGraphObserver(graph, false);
force = true;
}
}
} finally {
if (graphModel != null) {
graphModel.getGraph().readUnlockAll();
graphModel.getGraph().writeUnlock();
}
}
if (force || (observer != null && (observer.isNew() || observer.hasGraphChanged())) || hasColumnsChanged()) {
if (observer.isNew()) {
observer.hasGraphChanged();
}
NodeModeler nodeModeler = engine.getNodeModeler();
EdgeModeler edgeModeler = engine.getEdgeModeler();
Octree octree = engine.getOctree();
//Stats
int removedNodes = 0;
int addedNodes = 0;
int removedEdges = 0;
int addedEdges = 0;
graph.readLock();
try {
boolean isView = !graph.getView().isMainView();
for (int i = 0; i < nodes.length; i++) {
NodeModel node = nodes[i];
if (node != null && (node.getNode().getStoreId() == -1 || (isView && !graph.contains(node.getNode())))) {
//Removed
octree.removeNode(node);
nodes[i] = null;
removedNodes++;
}
}
for (Node node : graph.getNodes()) {
int id = node.getStoreId();
NodeModel model;
if (id >= nodes.length || nodes[id] == null) {
growNodes(id);
model = nodeModeler.initModel(node);
octree.addNode(model);
nodes[id] = model;
addedNodes++;
} else {
model = nodes[id];
}
textManager.refreshNode(graph, model, textModel);
}
for (int i = 0; i < edges.length; i++) {
EdgeModel edge = edges[i];
if (edge != null && (edge.getEdge().getStoreId() == -1 || (isView && !graph.contains(edge.getEdge())))) {
//Removed
int sourceId = edge.getEdge().getSource().getStoreId();
int targetId = edge.getEdge().getTarget().getStoreId();
NodeModel sourceModel = sourceId == -1 ? null : nodes[sourceId];
NodeModel targetModel = targetId == -1 ? null : nodes[targetId];
if (sourceModel != null) {
sourceModel.removeEdge(edge);
}
if (targetModel != null && sourceModel != targetModel) {
targetModel.removeEdge(edge);
}
edges[i] = null;
removedEdges++;
}
}
float minWeight = Float.MAX_VALUE;
float maxWeight = Float.MIN_VALUE;
for (Edge edge : graph.getEdges()) {
int id = edge.getStoreId();
EdgeModel model;
if (id >= edges.length || edges[id] == null) {
growEdges(id);
NodeModel sourceModel = nodes[edge.getSource().getStoreId()];
NodeModel targetModel = nodes[edge.getTarget().getStoreId()];
model = edgeModeler.initModel(edge, sourceModel, targetModel);
sourceModel.addEdge(model);
if (targetModel != sourceModel) {
targetModel.addEdge(model);
}
edges[id] = model;
addedEdges++;
} else {
model = edges[id];
}
float w = (float) edge.getWeight(graph.getView());
model.setWeight(w);
minWeight = Math.min(w, minWeight);
maxWeight = Math.max(w, maxWeight);
textManager.refreshEdge(graph, model, textModel);
}
if (!isView) {
limits.setMaxWeight(maxWeight);
limits.setMinWeight(minWeight);
}
} finally {
graph.readUnlockAll();
}
return true;
} else if (observer == null) {
Octree octree = engine.getOctree();
if (!octree.isEmpty()) {
octree.clear();
}
}
return false;
}
Aggregations