From dd18dbd55edcbb607ad89e65bb1e178d0f4e7c8a Mon Sep 17 00:00:00 2001 From: cmerkens Date: Mon, 8 Jul 2024 21:15:24 +0200 Subject: [PATCH] Nix funktioniert --- .idea/workspace.xml | 55 +++++++-- OurApplication/OurAlgorithm.java | 12 +- OurApplication/OurApplication.java | 2 - OurApplication/OurDrawArea.java | 106 ++++++++++++++++-- OurApplication/OurParameterArea.java | 3 + graph/DirectedGraph.java | 5 + graph/Graph.java | 3 + graph/UndirectedGraph.java | 4 + graph/VertexMarking.java | 50 --------- graph/VertexWeightMarking.java | 51 +++++++++ .../ProjektGraph/.idea/workspace.xml | 45 ++++---- .../OurApplication/OurAlgorithm.class | Bin 2490 -> 2768 bytes .../OurApplication/OurApplication.class | Bin 2847 -> 2962 bytes .../OurApplication/OurDrawArea.class | Bin 2108 -> 4646 bytes .../OurApplication/OurParameterArea.class | Bin 5986 -> 5986 bytes .../ProjektGraph/graph/DirectedGraph.class | Bin 13065 -> 13197 bytes .../ProjektGraph/graph/ExampleGraphs.class | Bin 6300 -> 6300 bytes out/production/ProjektGraph/graph/Graph.class | Bin 7961 -> 7992 bytes .../ProjektGraph/graph/UndirectedGraph.class | Bin 11581 -> 11713 bytes .../graph/VertexWeightMarking.class | Bin 519 -> 525 bytes 20 files changed, 237 insertions(+), 99 deletions(-) create mode 100644 graph/VertexWeightMarking.java diff --git a/.idea/workspace.xml b/.idea/workspace.xml index e3ac3ff..645aa03 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,8 +5,25 @@ + - + + + + + + + + + + + + + + + + + - { - "keyToString": { - "Application.Display.executor": "Run", - "Application.OurApplication.executor": "Run", - "Application.OurLegendArea.executor": "Run", - "RunOnceActivity.ShowReadmeOnStart": "true", - "git-widget-placeholder": "main", - "kotlin-language-version-configured": "true", - "last_opened_file_path": "C:/Git/ProjektGraphMain" + +}]]> @@ -180,4 +197,20 @@ + + + + + file://$PROJECT_DIR$/OurApplication/OurDrawArea.java + 51 + + + file://$PROJECT_DIR$/OurApplication/OurAlgorithm.java + 46 + + + + \ No newline at end of file diff --git a/OurApplication/OurAlgorithm.java b/OurApplication/OurAlgorithm.java index 516bd00..bc902db 100644 --- a/OurApplication/OurAlgorithm.java +++ b/OurApplication/OurAlgorithm.java @@ -44,10 +44,10 @@ public class OurAlgorithm extends Algorithm { */ public LogElementList run() { - OurParameterArea currentParameterArea = (OurParameterArea) this.getParameterArea(); - this.setCurrentGraph(currentParameterArea.getSelectedGraph()); + this.setCurrentGraph(((OurParameterArea) this.getParameterArea()).getSelectedGraph()); + /* MarkedVertex start = null; for (MarkedVertex i: this.currentGraph.getAllVertexes()) { if (Objects.equals(i.getName(), "Start")) { @@ -62,16 +62,18 @@ public class OurAlgorithm extends Algorithm { } } - /* + + */ + Random random = new Random(); MarkedVertex start = this.currentGraph.getAllVertexes().get(random.nextInt(this.currentGraph.getAllVertexes().size())); MarkedVertex end = this.currentGraph.getAllVertexes().get(random.nextInt(this.currentGraph.getAllVertexes().size())); System.out.println(start.getName() + " to " + end.getName()); - */ + if(this.methodButtons.getSelectedMethod()){ - this.currentGraph.getShortestPathDijkstra(start, end); + // this.currentGraph.getShortestPathDijkstra(start, end); }else{ this.currentGraph.getShortestPathAStar(start, end); } diff --git a/OurApplication/OurApplication.java b/OurApplication/OurApplication.java index 3ba9a59..6d07c00 100644 --- a/OurApplication/OurApplication.java +++ b/OurApplication/OurApplication.java @@ -56,8 +56,6 @@ public class OurApplication { OurAlgorithm algorithm = new OurAlgorithm(parameterArea, methodButtons); OurLegendArea legendArea = new OurLegendArea(); OurHybridWindow applet = new OurHybridWindow<>(drawArea, textArea, parameterArea, algorithm, logList, legendArea, methodButtons); - - diff --git a/OurApplication/OurDrawArea.java b/OurApplication/OurDrawArea.java index ad63f54..1379bce 100644 --- a/OurApplication/OurDrawArea.java +++ b/OurApplication/OurDrawArea.java @@ -1,12 +1,13 @@ package OurApplication; +import graph.*; import logging.LogElementList; import visualisation.DrawArea; import visualizationElements.Edge; import visualizationElements.Vertex; import javax.swing.*; -import java.awt.Graphics; +import java.awt.*; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; @@ -22,7 +23,7 @@ public class OurDrawArea extends DrawArea{ private static final long serialVersionUID = 1L; - private visualizationElements.Graph currentGraph; + private graph.Graph currentGraph; /** @@ -31,7 +32,8 @@ public class OurDrawArea extends DrawArea{ public OurDrawArea() { super(); } - + + /** * Creates a test draw area and sets the specified log list. * @param logList the draw area's log list test log elements. @@ -39,23 +41,111 @@ public class OurDrawArea extends DrawArea{ */ public OurDrawArea(LogElementList logList, String drawAreaName){ super(logList, drawAreaName); + + this.addMouseListener(new MouseListener() { + + MarkedVertex temp = null; + + @Override + public void mouseClicked(MouseEvent e) { + // Linksklick = Einfügen + if (SwingUtilities.isLeftMouseButton(e)) { + System.out.println("Left Mouse Clicked at (" + e.getX() + ", " + e.getY() + ")" + e.getPoint()); + if (check(e.getPoint()) == null) { + addVertex(e.getPoint()); + } + + // Rechtsklick = Löschen + } else if (SwingUtilities.isRightMouseButton(e)) { + System.out.println("Right Mouse Clicked at (" + e.getX() + ", " + e.getY() + ")"); + if (check(e.getPoint()) != null) { + removeVertex(check(e.getPoint())); + } + } + } + + + @Override + public void mousePressed(MouseEvent e) { + if (check(e.getPoint()) != null) { + temp = check(e.getPoint()); + } + } + + @Override + public void mouseReleased(MouseEvent e) { + if (check(e.getPoint()) != null) { + addEdge(temp, check(e.getPoint())); + } + } + + @Override + public void mouseEntered(MouseEvent e) { + } + + @Override + public void mouseExited(MouseEvent e) { + } + }); } - public void setCurrentGraph(visualizationElements.Graph graph) { + public void setCurrentGraph(graph.Graph graph) { this.currentGraph = graph; } - + + public graph.Graph getCurrentGraph() { + return this.currentGraph; + } + + + // TODO Vertex + private void addVertex(java.awt.Point point) { + this.currentGraph.addVertex(new MarkedVertex<>(point.x, point.y, "name", new VertexWeightMarking(1), Color.BLACK)); + this.currentGraph.createLoglistElement(); + this.drawStep(); + } + + private void removeVertex(MarkedVertex n) { + this.currentGraph.removeVertex(n); + this.currentGraph.createLoglistElement(); + this.drawStep(); + } + + // TODO Edge + private void addEdge(MarkedVertex start, MarkedVertex end) { + this.currentGraph.addEdge(new MarkedEdge<>("", start, end, new EdgeWeightMarking(1))); + this.currentGraph.createLoglistElement(); + this.drawStep(); + } + + + private MarkedVertex check(java.awt.Point point) { + for (MarkedVertex i: this.currentGraph.getAllVertexes()) { + if (isWithinRadius(point.x, point.y, i.getCords()[0], i.getCords()[1], 20)) { + return i; + } + } + return null; + } + + + private static boolean isWithinRadius(int clickX, int clickY, int centerX, int centerY, int radius) { + int deltaX = clickX - centerX; + int deltaY = clickY - centerY; + double distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY); + return distance <= radius; + } + + /** * Draws a visualization element. */ - public void draw(Graphics g) { OurLogElement logElement = (OurLogElement) logList.get(); - this.setCurrentGraph(((OurLogElement) logList.get()).getGraph()); logElement.getGraph().draw(g); - for(Edge screenEdge : currentGraph.getEdges()){ + for(Edge screenEdge : ((OurLogElement) logList.get()).getGraph().getEdges()){ g.drawString(screenEdge.getMarking(), (screenEdge.getSource().getXpos() + screenEdge.getDestination().getXpos())/2, (screenEdge.getSource().getYpos() + screenEdge.getDestination().getYpos())/2); } diff --git a/OurApplication/OurParameterArea.java b/OurApplication/OurParameterArea.java index 8813c8e..7d7ca0b 100644 --- a/OurApplication/OurParameterArea.java +++ b/OurApplication/OurParameterArea.java @@ -86,9 +86,11 @@ public class OurParameterArea extends ParameterArea{ buttonAddGraph.addActionListener(e -> { + String input1 = textField1.getText(); String input2 = textField2.getText(); this.customGraph = createGraph(input1, input2); + }); // Buttons zum Panel hinzufügen @@ -103,6 +105,7 @@ public class OurParameterArea extends ParameterArea{ add(textField2); } + public DirectedGraph getSelectedGraph() { ExampleGraphs temp = new ExampleGraphs(); switch (selectedExample) { diff --git a/graph/DirectedGraph.java b/graph/DirectedGraph.java index 6eb666b..1b5e731 100644 --- a/graph/DirectedGraph.java +++ b/graph/DirectedGraph.java @@ -585,4 +585,9 @@ public class DirectedGraph exten // Gibt Distanz zu gefragtem Knoten zurück return distance.get(n2); } + + + public void createLoglistElement() { + this.logList.add(new OurLogElement(0, "", 0, this.getScreenGraphCopy())); + } } diff --git a/graph/Graph.java b/graph/Graph.java index e76c7e0..00f8fb4 100644 --- a/graph/Graph.java +++ b/graph/Graph.java @@ -413,5 +413,8 @@ public abstract class Graph { * @return Length of the shortest path between the vertices. */ public abstract double getShortestPathAStar(MarkedVertex n1, MarkedVertex n2); + + + public abstract void createLoglistElement(); } diff --git a/graph/UndirectedGraph.java b/graph/UndirectedGraph.java index e76f863..48abc1d 100644 --- a/graph/UndirectedGraph.java +++ b/graph/UndirectedGraph.java @@ -487,4 +487,8 @@ public class UndirectedGraph ext return distance.get(n2); } + public void createLoglistElement() { + this.logList.add(new OurLogElement(0, "", 0, this.getScreenGraphCopy())); + } + } diff --git a/graph/VertexMarking.java b/graph/VertexMarking.java index 13ea5c0..90916e7 100644 --- a/graph/VertexMarking.java +++ b/graph/VertexMarking.java @@ -8,53 +8,3 @@ public abstract class VertexMarking extends Marking { // This class currently does not have any additional attributes or methods. // It extends Marking, inheriting its properties and behaviors. } - - - -/** - * Represents a weight marking associated with a vertex in a graph. - * Extends {@link VertexMarking}. - */ -class VertexWeightMarking extends VertexMarking { - - // ATTRIBUTE - - private int weight; - - - // KONSTRUKTOREN - - /** - * Constructs a vertex weight marking with the specified weight. - * - * @param weight The weight value associated with the vertex. - */ - VertexWeightMarking(int weight) { - this.weight = weight; - } - - - // GET-ER - - /** - * Retrieves the weight associated with this vertex weight marking. - * - * @return The weight of the vertex marking. - */ - public int getWeight() { - return this.weight; - } - - - // SET-ER - - /** - * Sets the weight associated with this vertex weight marking. - * - * @param weight The new weight value to set. - */ - public void setWeight(int weight) { - this.weight = weight; - } - -} diff --git a/graph/VertexWeightMarking.java b/graph/VertexWeightMarking.java new file mode 100644 index 0000000..db1461f --- /dev/null +++ b/graph/VertexWeightMarking.java @@ -0,0 +1,51 @@ +package graph; + + +/** + * Represents a weight marking associated with a vertex in a graph. + * Extends {@link VertexMarking}. + */ +public class VertexWeightMarking extends VertexMarking { + + // ATTRIBUTE + + private int weight; + + + // KONSTRUKTOREN + + /** + * Constructs a vertex weight marking with the specified weight. + * + * @param weight The weight value associated with the vertex. + */ + public VertexWeightMarking(int weight) { + this.weight = weight; + } + + + // GET-ER + + /** + * Retrieves the weight associated with this vertex weight marking. + * + * @return The weight of the vertex marking. + */ + public int getWeight() { + return this.weight; + } + + + // SET-ER + + /** + * Sets the weight associated with this vertex weight marking. + * + * @param weight The new weight value to set. + */ + public void setWeight(int weight) { + this.weight = weight; + } + +} + diff --git a/out/production/ProjektGraph/.idea/workspace.xml b/out/production/ProjektGraph/.idea/workspace.xml index a0be32b..8070b2c 100644 --- a/out/production/ProjektGraph/.idea/workspace.xml +++ b/out/production/ProjektGraph/.idea/workspace.xml @@ -4,22 +4,23 @@ - + - - - - - - - - + + + + +