コード例 #1
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();
     }
   }
 }
コード例 #2
0
  public void verticeMouseReleased(MouseEvent e) {

    if (tempLine != null) {
      for (Vertex vertex : graph.getVertices()) {
        if (vertex == currentVertex) continue;
        if (vertex.contains(e.getPoint())) {
          Edge edge = new Edge(currentVertex, vertex);
          addEdge(edge);
          break;
        }
      }
      tempLine = null;
      repaint();
    }
    currentVertex = null;
  }
コード例 #3
0
  public synchronized boolean deleteTile(int x, int y) {
    Station tempStation = null;
    for (Station station : allStations) {
      if (station.checkPosition(x, y)) {
        tempStation = station;
        break;
      }
    }
    allStations.remove(tempStation);

    Vertex tempVertex = null;
    for (Vertex vertex : allVertexes) {
      if (vertex.checkPosition(x, y)) {
        tempVertex = vertex;
        break;
      }
    }
    allVertexes.remove(tempVertex);

    return true;
  }
コード例 #4
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());
        }
      }
    }
  }
コード例 #5
0
  void selectTile(int x, int y) {
    selectedVertex = null;
    selectedStation = null;
    for (Vertex vertex : allVertexes) {
      if (vertex.checkPosition(x, y)) {
        selectedVertex = vertex;
        break;
      }
    }

    for (Station station : allStations) {
      if (station.checkPosition(x, y)) {
        selectedStation = station;
        break;
      }
    }

    if (selectedVertex != null) {
      this.mapMakerView.getShowDataPanel().getNewPodcarButton().setEnabled(true);
    } else {
      this.mapMakerView.getShowDataPanel().getNewPodcarButton().setEnabled(false);
    }
  }
コード例 #6
0
  void createVertex(int x, int y) {
    for (Vertex vertex : allVertexes) {
      if (vertex.checkPosition(x, y)) {
        return;
      }
    }

    Vertex newVertex = new Vertex("N" + x + "_" + y, x, y);
    allVertexes.add(newVertex);

    for (Vertex checkVertex : allVertexes) {
      int diffX = Math.abs(checkVertex.getxPosition() - newVertex.getxPosition());
      int diffY = Math.abs(checkVertex.getyPosition() - newVertex.getyPosition());

      if ((diffX == 1) != (diffY == 1)) {
        if ((diffX == 0) != (diffY == 0)) {
          checkVertex.addAdjacentVertex(newVertex);
        }
      }
    }
  }
コード例 #7
0
  synchronized void toggleAdjecent(int x, int y) {

    Vertex tempAdjecentVertex = null;
    for (Vertex adjecentVertex : selectedVertex.getAdjacencyList()) {
      if (adjecentVertex.getxPosition() == x && adjecentVertex.getyPosition() == y) {
        tempAdjecentVertex = adjecentVertex;
        break;
      }
    }

    if (tempAdjecentVertex != null) {
      selectedVertex.getAdjacencyList().remove(tempAdjecentVertex);
      return;
    }

    Vertex tempNewAdjecentVertex = null;
    for (Vertex vertex : allVertexes) {
      if (vertex.checkPosition(x, y)) {
        tempNewAdjecentVertex = vertex;
      }
    }
    selectedVertex.getAdjacencyList().add(tempNewAdjecentVertex);
  }
コード例 #8
0
 public void addVertex(Vertex vertex) {
   graph.addVertex(vertex);
   vertex.setName(String.valueOf(graph.getVerticesCount()));
   repaint();
 }