예제 #1
0
 @Override
 protected void paintComponent(Graphics g) {
   super.paintComponent(g);
   if (tempLine != null) {
     tempLine.draw(g);
   }
   graph.draw(g);
 }
예제 #2
0
 public void verticeMouseDragged(MouseEvent e) {
   if (SwingUtilities.isLeftMouseButton(e)) {
     if (currentVertex != null) {
       Point diff = Vector2DHelper.SubstractVector(e.getPoint(), previousPoint);
       currentVertex.setLocation(Vector2DHelper.AddVector(currentVertex.getLocation(), diff));
       previousPoint = e.getPoint();
       repaint();
     }
   } else if (SwingUtilities.isRightMouseButton(e)) {
     if (tempLine != null) {
       tempLine.setPoint2(e.getPoint());
       repaint();
     }
   }
 }
예제 #3
0
  public void verticeMousePressed(MouseEvent e) {
    if (e.getClickCount() == 2) {
      for (Edge edge : graph.getEdges()) {
        if (edge.contains(e.getPoint())) {
          String input = DialogHelpers.showInPutDialog("Input", "Enter cost: ");
          try {
            int number = Integer.parseInt(input);
            edge.setCost(number);
            repaint();
          } catch (NumberFormatException e1) {
            // e1.printStackTrace();
          }
        }
      }
      return;
    }

    if (SwingUtilities.isLeftMouseButton(e)) {
      for (Vertex vertex : graph.getVertices()) {
        if (vertex.contains(e.getPoint())) {
          currentVertex = vertex;
          previousPoint = e.getPoint();
          return;
        }
      }

      for (Edge edge : graph.getEdges()) {
        if (edge.contains(e.getPoint())) {}
      }
    } else if (SwingUtilities.isRightMouseButton(e)) {
      for (Vertex vertex : graph.getVertices()) {
        if (vertex.contains(e.getPoint())) {
          currentVertex = vertex;
          tempLine = new Line();
          tempLine.setPoint1(e.getPoint());
        }
      }
    }
  }