@Override public void invoke(GObject target, Context context) { if (edges.mst != null) { edges.mst = null; if (settings.realtime) { doKruskal(); } } NodeView view = (NodeView) target; Node<String> node = view.getNode(); for (WeightedEdge<String, Double> edge : graph.getEdges()) { if (!(edge.getTail() == node) && !(edge.getHead() == node)) { continue; } Node<String> otherNode = (node == edge.getTail() ? edge.getHead() : edge.getTail()); NodeView otherView = null; for (NodeView couldBeOther : nodes) { if (couldBeOther.getNode().equals(otherNode)) { otherView = couldBeOther; break; } } if (otherView != null) { edge.setWeight(calculateWeightByDistance(view, otherView)); } } }
@Override public void viewShown() { if (settings.useDistanceWeight) { // temporary map Map<Node<String>, NodeView> map = new HashMap<>(); for (NodeView nv : nodes) { map.put(nv.getNode(), nv); } Set<? extends WeightedEdge<String, Double>> edges = graph.getEdges(); for (WeightedEdge<String, Double> edge : edges) { edge.setWeight(calculateWeightByDistance(map.get(edge.getHead()), map.get(edge.getTail()))); } } }