Ejemplo n.º 1
0
 /** Releases the mouse-selected node so that it readjusts in response to other node positions. */
 public void dropSelected() {
   if (!zoomer.isMouseCaptured()) {
     if (selectedNode != null) {
       nodes.get(selectedNode).makeFree();
       selectedNode = null;
     }
   }
 }
Ejemplo n.º 2
0
  /** Allows a node to be selected with the mouse. */
  public void selectNearestWithMouse() {
    if (!zoomer.isMouseCaptured()) {
      float mX = (zoomer.getMouseCoord().x - (width / 2)) / centroid.getZ() + centroid.getX();
      float mY = (zoomer.getMouseCoord().y - (height / 2)) / centroid.getZ() + centroid.getY();

      if (selectedNode == null) {
        float nearestDSq = Float.MAX_VALUE;

        for (Map.Entry<N, Particle> row : nodes.entrySet()) {
          N node = row.getKey();
          Particle p = row.getValue();

          float px = p.position().x();
          float py = p.position().y();
          float dSq = (px - mX) * (px - mX) + (py - mY) * (py - mY);
          if (dSq < nearestDSq) {
            nearestDSq = dSq;
            selectedNode = node;
          }
        }
      }
    }
  }