@Override protected void paintComponent(Graphics g) { super.paintComponent(g); if (tempLine != null) { tempLine.draw(g); } graph.draw(g); }
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(); } } }
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()); } } } }