Compare commits

..

No commits in common. "4b59b88688ffd6d01f6c5d081e4fc726a35406ed" and "0be3b82e7b170dea61a52611c9c5f8165df80c33" have entirely different histories.

19 changed files with 460 additions and 442 deletions

41
.idea/workspace.xml generated
View File

@ -7,17 +7,12 @@
<list default="true" id="70f8ea87-9ffc-471a-8059-ebbfc323adcc" name="Changes" comment="Weighting gefixt"> <list default="true" id="70f8ea87-9ffc-471a-8059-ebbfc323adcc" name="Changes" comment="Weighting gefixt">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/OurApplication/OurAlgorithm.java" beforeDir="false" afterPath="$PROJECT_DIR$/OurApplication/OurAlgorithm.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/OurApplication/OurAlgorithm.java" beforeDir="false" afterPath="$PROJECT_DIR$/OurApplication/OurAlgorithm.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/OurApplication/OurApplication.java" beforeDir="false" afterPath="$PROJECT_DIR$/OurApplication/OurApplication.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/OurApplication/OurDrawArea.java" beforeDir="false" afterPath="$PROJECT_DIR$/OurApplication/OurDrawArea.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/OurApplication/OurDrawArea.java" beforeDir="false" afterPath="$PROJECT_DIR$/OurApplication/OurDrawArea.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/OurApplication/OurHybridWindow.java" beforeDir="false" afterPath="$PROJECT_DIR$/OurApplication/OurHybridWindow.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/OurApplication/OurLegendArea.java" beforeDir="false" afterPath="$PROJECT_DIR$/OurApplication/OurLegendArea.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/OurApplication/OurLogElement.java" beforeDir="false" afterPath="$PROJECT_DIR$/OurApplication/OurLogElement.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/OurApplication/OurMethodButtons.java" beforeDir="false" afterPath="$PROJECT_DIR$/OurApplication/OurMethodButtons.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/OurApplication/OurParameterArea.java" beforeDir="false" afterPath="$PROJECT_DIR$/OurApplication/OurParameterArea.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/OurApplication/OurParameterArea.java" beforeDir="false" afterPath="$PROJECT_DIR$/OurApplication/OurParameterArea.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/OurApplication/OurTextArea.java" beforeDir="false" afterPath="$PROJECT_DIR$/OurApplication/OurTextArea.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/ProjektGraph/OurApplication/OurAlgorithm.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ProjektGraph/OurApplication/OurAlgorithm.class" afterDir="false" /> <change beforePath="$PROJECT_DIR$/out/production/ProjektGraph/OurApplication/OurAlgorithm.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ProjektGraph/OurApplication/OurAlgorithm.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/ProjektGraph/OurApplication/OurApplication.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ProjektGraph/OurApplication/OurApplication.class" afterDir="false" /> <change beforePath="$PROJECT_DIR$/out/production/ProjektGraph/OurApplication/OurApplication.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ProjektGraph/OurApplication/OurApplication.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/ProjektGraph/OurApplication/OurDrawArea.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ProjektGraph/OurApplication/OurDrawArea.class" afterDir="false" /> <change beforePath="$PROJECT_DIR$/out/production/ProjektGraph/OurApplication/OurDrawArea.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ProjektGraph/OurApplication/OurDrawArea.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/ProjektGraph/OurApplication/OurParameterArea.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ProjektGraph/OurApplication/OurParameterArea.class" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -49,17 +44,17 @@
<option name="hideEmptyMiddlePackages" value="true" /> <option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" /> <option name="showLibraryContents" value="true" />
</component> </component>
<component name="PropertiesComponent">{ <component name="PropertiesComponent"><![CDATA[{
&quot;keyToString&quot;: { "keyToString": {
&quot;Application.Display.executor&quot;: &quot;Run&quot;, "Application.Display.executor": "Run",
&quot;Application.OurApplication.executor&quot;: &quot;Run&quot;, "Application.OurApplication.executor": "Run",
&quot;Application.OurLegendArea.executor&quot;: &quot;Run&quot;, "Application.OurLegendArea.executor": "Run",
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;, "RunOnceActivity.ShowReadmeOnStart": "true",
&quot;git-widget-placeholder&quot;: &quot;main&quot;, "git-widget-placeholder": "main",
&quot;kotlin-language-version-configured&quot;: &quot;true&quot;, "kotlin-language-version-configured": "true",
&quot;last_opened_file_path&quot;: &quot;C:/Git/ProjektGraphMain&quot; "last_opened_file_path": "C:/Git/ProjektGraphMain"
} }
}</component> }]]></component>
<component name="RecentsManager"> <component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS"> <key name="CopyFile.RECENT_KEYS">
<recent name="C:\Git\ProjektGraph" /> <recent name="C:\Git\ProjektGraph" />
@ -192,6 +187,20 @@
<option name="LAST_COMMIT_MESSAGE" value="Weighting gefixt" /> <option name="LAST_COMMIT_MESSAGE" value="Weighting gefixt" />
</component> </component>
<component name="XDebuggerManager"> <component name="XDebuggerManager">
<breakpoint-manager>
<breakpoints>
<line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/OurApplication/OurAlgorithm.java</url>
<line>46</line>
<option name="timeStamp" value="6" />
</line-breakpoint>
<line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/OurApplication/OurParameterArea.java</url>
<line>142</line>
<option name="timeStamp" value="7" />
</line-breakpoint>
</breakpoints>
</breakpoint-manager>
<watches-manager> <watches-manager>
<configuration name="Application"> <configuration name="Application">
<watch expression="newGraph.screenGraph" /> <watch expression="newGraph.screenGraph" />

View File

@ -3,81 +3,86 @@ package OurApplication;
import graph.*; import graph.*;
import logging.Algorithm; import logging.Algorithm;
import logging.LogElementList; import logging.LogElementList;
import visualizationElements.Vertex;
import java.awt.*;
import java.util.Objects; import java.util.Objects;
import java.util.Random;
import java.util.Vector;
/** /**
* This class provides an example of using logging.Algorithm. * This class provides an example for using logging.Algorithm.
* It implements a summation algorithm that computes the sum of integers starting from 0 up to a specified maximum value from the parameter area. * It sums up integer number starting with 0 up to the maximum value specified in the parameter area.
*
* @see Algorithm * @see Algorithm
* @author MSch<EFBFBD>fer
* DHBW Stuttgart/Campus Horb AI2008<br>
* <br>
*/ */
public class OurAlgorithm extends Algorithm { public class OurAlgorithm extends Algorithm {
private graph.Graph<VertexMarking, EdgeMarking> currentGraph; private graph.Graph<VertexMarking, EdgeMarking> currentGraph;
private OurMethodButtons methodButtons; private OurMethodButtons methodButtons;
/**
* Standard constructor.
* Initializes an instance of OurAlgorithm.
*/
public OurAlgorithm() { public OurAlgorithm() {
super(); super();
} }
/** /**
* Constructs a summation algorithm with parameters from the parameter area. * Creates a sum up algorithm.
* * @param parameterArea the sum up parameter area the algorithm gets its parameters from
* @param parameterArea the parameter area providing the selected graph for the algorithm
* @param methodButtons the method buttons determining the algorithm type (Dijkstra or A-Star)
*/ */
public OurAlgorithm(OurParameterArea parameterArea, OurMethodButtons methodButtons) { public OurAlgorithm(OurParameterArea parameterArea, OurMethodButtons methodButtons){
super(parameterArea, "Thema II: Kürzeste Wege"); super(parameterArea,"Thema II: Kürzeste Wege");
this.methodButtons = methodButtons; this.methodButtons = methodButtons;
} }
/** /**
* Overridden method from the superclass. * Overwritten from super class.
* Executes the summation algorithm. * Runs the algorithm..
* Computes the shortest path in the current graph based on the selected method (Dijkstra or A-Star). * Returns the LogElementList produced by the algorithm processing.
* * Adds integer number starting with 0 up to the maximum value.
* @return a LogElementList containing the single steps of the algorithm processing * @return a LogElementList containing the algorithm processing single steps
*/ */
public LogElementList<OurLogElement> run() { public LogElementList<OurLogElement> run() {
this.setCurrentGraph(((OurParameterArea) this.getParameterArea()).getSelectedGraph()); this.setCurrentGraph(((OurParameterArea) this.getParameterArea()).getSelectedGraph());
MarkedVertex<VertexMarking> start = null; MarkedVertex<VertexMarking> start = null;
for (MarkedVertex<VertexMarking> i : this.currentGraph.getAllVertexes()) { for (MarkedVertex<VertexMarking> i: this.currentGraph.getAllVertexes()) {
if (Objects.equals(i.getName(), "Start")) { if (Objects.equals(i.getName(), "Start")) {
start = i; start = i;
} }
} }
MarkedVertex<VertexMarking> end = null; MarkedVertex<VertexMarking> end = null;
for (MarkedVertex<VertexMarking> i : this.currentGraph.getAllVertexes()) { for (MarkedVertex<VertexMarking> i: this.currentGraph.getAllVertexes()) {
if (Objects.equals(i.getName(), "Ende")) { if (Objects.equals(i.getName(), "Ende")) {
end = i; end = i;
} }
} }
if (this.methodButtons.getSelectedMethod()) {
/*Random random = new Random();
MarkedVertex<VertexMarking> start = this.currentGraph.getAllVertexes().get(random.nextInt(this.currentGraph.getAllVertexes().size()));
MarkedVertex<VertexMarking> 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 { }else{
this.currentGraph.getShortestPathAStar(start, end); this.currentGraph.getShortestPathAStar(start, end);
} }
return this.currentGraph.getLogList(); return this.currentGraph.getLogList();
} }
/**
* Sets the current graph for the algorithm.
*
* @param graph the graph to be set as the current graph
*/
public void setCurrentGraph(graph.Graph<VertexMarking, EdgeMarking> graph) { public void setCurrentGraph(graph.Graph<VertexMarking, EdgeMarking> graph) {
this.currentGraph = graph; this.currentGraph = graph;
} }
} }

View File

@ -2,68 +2,69 @@ package OurApplication;
import graph.*; import graph.*;
import logging.LogElementList; import logging.LogElementList;
import visualisation.HybridWindow;
import visualizationElements.Vertex;
import javax.swing.*; import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Random;
/** /**
* Entry point for the OurApplication, demonstrating logging and visualization integration. * This application provides an example for using logging and visualization packages.
* This application sets up a graphical interface using Swing components to visualize graphs * It uses extended classes from logging and visualization.
* and log algorithmic operations. * @see OurAlgorithm
* * @see OurApplication
* @see OurAlgorithm Provides the algorithmic logic for processing graphs. * @see OurDrawArea
* @see OurDrawArea Displays and interacts with the graph visualization. * @see OurHybridWindow
* @see OurHybridWindow Combines visual components and algorithmic operations. * @see OurLogElement
* @see OurLogElement Represents individual logging elements. * @see OurParameterArea
* @see OurParameterArea Manages parameters for graph operations. * @see OurTextArea
* @see OurTextArea Displays log messages and algorithm progress. * @see OurLegendArea
* @see OurLegendArea Provides legend information for the graphical interface. * @see JPanel
* @see JPanel Swing panel used in the graphical interface. * @author MSch<EFBFBD>fer
* DHBW Stuttgart/Campus Horb AI2008<br>
* <br>
*/ */
public class OurApplication { public class OurApplication {
/** /**
* Default constructor for OurApplication. * Standard constructor.
* Initializes the application components and starts the graphical interface.
*/ */
public OurApplication() { public OurApplication() {
super(); super();
} }
/** /**
* Main method to launch the OurApplication. * The applications main method.
* Initializes necessary components, creates a graphical window, and starts the application. * Creates a HybridWindow with TestParameterArea, TestLegendArea ,TestDrawArea, TestTextArea and TestAlgorithm and starts it.
* * @param args
* @param args command-line arguments (not used)
*/ */
public static void main(String[] args){ public static void main(String[]args){
// Create a directed graph instance
DirectedGraph<VertexMarking, EdgeMarking> myGraph = new DirectedGraph<>(); DirectedGraph<VertexMarking, EdgeMarking> myGraph = new DirectedGraph<>();
System.out.println(myGraph.toString()); System.out.println(myGraph.toString());
// Initialize logging elements
LogElementList<OurLogElement> logList = new LogElementList<>();
// Create UI components
LogElementList<OurLogElement> logList = new LogElementList<>();
OurParameterArea parameterArea = new OurParameterArea(); OurParameterArea parameterArea = new OurParameterArea();
OurMethodButtons methodButtons = new OurMethodButtons(); OurMethodButtons methodButtons = new OurMethodButtons();
OurDrawArea drawArea = new OurDrawArea(logList, "GraphVisualization"); OurDrawArea drawArea = new OurDrawArea(logList,"GraphVisualization");
OurTextArea textArea = new OurTextArea(logList); OurTextArea textArea = new OurTextArea(logList);
OurAlgorithm algorithm = new OurAlgorithm(parameterArea, methodButtons); OurAlgorithm algorithm = new OurAlgorithm(parameterArea, methodButtons);
OurLegendArea legendArea = new OurLegendArea(); OurLegendArea legendArea = new OurLegendArea();
OurHybridWindow<OurDrawArea, OurTextArea, OurParameterArea, OurAlgorithm, OurLogElement, OurLegendArea, OurMethodButtons> applet = new OurHybridWindow<>(drawArea, textArea, parameterArea, algorithm, logList, legendArea, methodButtons);
// Create a HybridWindow instance combining all UI components
OurHybridWindow<OurDrawArea, OurTextArea, OurParameterArea, OurAlgorithm, OurLogElement, OurLegendArea, OurMethodButtons> applet =
new OurHybridWindow<>(drawArea, textArea, parameterArea, algorithm, logList, legendArea, methodButtons);
// Create and configure the main JFrame
JFrame frame = new JFrame("Visualise"); JFrame frame = new JFrame("Visualise");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(applet); frame.getContentPane().add(applet);
frame.pack(); frame.pack();
applet.init(); applet.init();
applet.start(); applet.start();
frame.setSize(1350, 800); frame.setSize(1350,800);
frame.setVisible(true); frame.setVisible(true);
} }
} }

View File

@ -4,58 +4,154 @@ import graph.*;
import logging.LogElementList; import logging.LogElementList;
import visualisation.DrawArea; import visualisation.DrawArea;
import visualizationElements.Edge; import visualizationElements.Edge;
import visualizationElements.Vertex;
import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
/** /**
* This class provides an example for using visualization.DrawArea. * This class provides an example for using visualization.DrawArea.
* It extends DrawArea to visualize a graph based on logging elements. * @see logging.Algorithm
* @author MSch<EFBFBD>fer
* @see DrawArea * DHBW Stuttgart/Campus Horb AI2008<br>
* <br>
*/ */
public class OurDrawArea extends DrawArea { public class OurDrawArea extends DrawArea{
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private graph.Graph<VertexMarking, EdgeMarking> currentGraph; private graph.Graph<VertexMarking, EdgeMarking> currentGraph;
/** /**
* Standard constructor. * Standard constructor.
* Initializes an empty draw area.
*/ */
public OurDrawArea() { public OurDrawArea() {
super(); super();
} }
/** /**
* Extended constructor. * Creates a test draw area and sets the specified log list.
* Creates a draw area with a specified log list and display name. * @param logList the draw area's log list test log elements.
* * @param drawAreaName The display name over the draw area.
* @param logList the draw area's log element list
* @param drawAreaName the display name over the draw area
*/ */
public OurDrawArea(LogElementList<OurLogElement> logList, String drawAreaName) { public OurDrawArea(LogElementList<OurLogElement> logList, String drawAreaName){
super(logList, drawAreaName); super(logList, drawAreaName);
/*
this.addMouseListener(new MouseListener() {
MarkedVertex<VertexMarking> 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(graph.Graph<VertexMarking, EdgeMarking> graph) {
this.currentGraph = graph;
}
public graph.Graph<VertexMarking, EdgeMarking> 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<VertexMarking> n) {
this.currentGraph.removeVertex(n);
this.currentGraph.createLoglistElement();
this.drawStep();
}
// TODO Edge
private void addEdge(MarkedVertex<VertexMarking> start, MarkedVertex<VertexMarking> end) {
this.currentGraph.addEdge(new MarkedEdge<>("", start, end, new EdgeWeightMarking(1)));
this.currentGraph.createLoglistElement();
this.drawStep();
}
private MarkedVertex<graph.VertexMarking> check(java.awt.Point point) {
for (MarkedVertex<graph.VertexMarking> 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 visualization elements on the draw area. * Draws a visualization element.
* @param g the graphics context used for drawing
*/ */
public void draw(Graphics g) { public void draw(Graphics g) {
// Get the current log element from the log list
OurLogElement logElement = (OurLogElement) logList.get(); OurLogElement logElement = (OurLogElement) logList.get();
// Draw the graph associated with the log element
logElement.getGraph().draw(g); logElement.getGraph().draw(g);
for(Edge screenEdge : ((OurLogElement) logList.get()).getGraph().getEdges()){
// Draw markings on edges g.drawString(screenEdge.getMarking(), (screenEdge.getSource().getXpos() + screenEdge.getDestination().getXpos())/2, (screenEdge.getSource().getYpos() + screenEdge.getDestination().getYpos())/2);
for (Edge screenEdge : logElement.getGraph().getEdges()) {
g.drawString(screenEdge.getMarking(),
(screenEdge.getSource().getXpos() + screenEdge.getDestination().getXpos()) / 2,
(screenEdge.getSource().getYpos() + screenEdge.getDestination().getYpos()) / 2);
} }
} }
} }

View File

@ -16,19 +16,14 @@ import java.awt.event.ItemEvent;
import java.awt.event.ItemListener; import java.awt.event.ItemListener;
/** /**
* This class provides an example for using visualization.HybridWindow. * This class provides an example for using visualization.HybridWindow.
* It extends HybridWindow to integrate graphical components with algorithmic operations. * Overwriting the constructor is necessary to run as an applet.
* * For running as an application overwriting the constructor is not necessary
* @param <DRAW> Type of the draw area used in the hybrid window.
* @param <TEXT> Type of the text area used in the hybrid window.
* @param <PARAM> Type of the parameter area used in the hybrid window.
* @param <ALGORITHM> Type of the algorithm used in the hybrid window.
* @param <LOG> Type of logging elements used in the hybrid window.
* @param <LEGEND> Type of legend area used in the hybrid window.
* @param <METHODBUTTONS> Type of method buttons used in the hybrid window.
*
* @see HybridWindow * @see HybridWindow
* @see OurApplication * @see OurApplication
* @author MSch<EFBFBD>fer
* DHBW Stuttgart/Campus Horb AI2008<br>
* <br>
*/ */
public class OurHybridWindow<DRAW extends DrawArea, public class OurHybridWindow<DRAW extends DrawArea,
TEXT extends TextArea, TEXT extends TextArea,
@ -36,7 +31,7 @@ public class OurHybridWindow<DRAW extends DrawArea,
ALGORITHM extends Algorithm, ALGORITHM extends Algorithm,
LOG extends LogElement, LOG extends LogElement,
LEGEND extends LegendArea, LEGEND extends LegendArea,
METHODBUTTONS extends ParameterArea> extends HybridWindow { METHODBUTTONS extends ParameterArea> extends HybridWindow{
protected METHODBUTTONS methodButtons; protected METHODBUTTONS methodButtons;
protected StartListener startListener; protected StartListener startListener;
@ -63,78 +58,69 @@ public class OurHybridWindow<DRAW extends DrawArea,
/** /**
* Overwritten standard constructor. * Overwritten standard constructor.
* Creates a HybridWindow with specified draw area, text area, parameter area, * Creates a TestUpHybridWindow with
* algorithm, log list, legend area, and method buttons. * TestParameterArea,SumUpLegendArea, TestDrawArea, TestTextArea,
* * TestAlgorithm and a LogElementList of TestLogElements.
* @param drawArea the draw area used in the hybrid window
* @param textArea the text area used in the hybrid window
* @param parameterArea the parameter area used in the hybrid window
* @param algorithm the algorithm used in the hybrid window
* @param logList the log element list used in the hybrid window
* @param legendArea the legend area used in the hybrid window
* @param methodButtons the method buttons used in the hybrid window
*/ */
public OurHybridWindow(DRAW drawArea, TEXT textArea, PARAM parameterArea, ALGORITHM algorithm, public OurHybridWindow() {
LogElementList<LOG> logList, LEGEND legendArea, METHODBUTTONS methodButtons) { super();
}
public OurHybridWindow(DRAW drawArea, TEXT textArea, PARAM parameterArea, ALGORITHM algorithm, LogElementList<LOG>logList, LEGEND legendArea, METHODBUTTONS methodButtons) {
super(drawArea, textArea, parameterArea, algorithm, logList, legendArea); super(drawArea, textArea, parameterArea, algorithm, logList, legendArea);
this.methodButtons = methodButtons; this.methodButtons = methodButtons;
} }
public void init(){
startButton=new JButton("start");
stopButton=new JButton("stop");
nextButton=new JButton("next");
prevButton=new JButton("prev");
lastButton=new JButton("last");
firstButton=new JButton("first");
autoButton=new JToggleButton("automatc");
autoSlider=new JSlider(1,100,1);
autoForwardButton=new JRadioButton("forward");
autoBackwardButton=new JRadioButton("backward");
pauseButton=new JButton("pause");
/** ButtonGroup autoDirection=new ButtonGroup();
* Initializes the hybrid window by setting up UI components and event listeners.
*/
public void init() {
startButton = new JButton("start");
stopButton = new JButton("stop");
nextButton = new JButton("next");
prevButton = new JButton("prev");
lastButton = new JButton("last");
firstButton = new JButton("first");
autoButton = new JToggleButton("automatic");
autoSlider = new JSlider(1, 100, 1);
autoForwardButton = new JRadioButton("forward");
autoBackwardButton = new JRadioButton("backward");
pauseButton = new JButton("pause");
ButtonGroup autoDirection = new ButtonGroup();
autoDirection.add(autoForwardButton); autoDirection.add(autoForwardButton);
autoDirection.add(autoBackwardButton); autoDirection.add(autoBackwardButton);
autoForwardButton.setSelected(true); autoForwardButton.setSelected(true);
JPanel panelStartStopControls = new JPanel(); JPanel panelStartStopControls=new JPanel();
panelStartStopControls.setLayout(new GridLayout(4, 1, 5, 5)); panelStartStopControls.setLayout(new GridLayout(4,1,5,5));
panelStartStopControls.add(startButton); panelStartStopControls.add(startButton);
panelStartStopControls.add(stopButton); panelStartStopControls.add(stopButton);
panelStartStopControls.add(pauseButton); panelStartStopControls.add(pauseButton);
panelStartStopControls.add(methodButtons); panelStartStopControls.add(methodButtons);
panelStartStopControls.setBorder(BorderFactory.createTitledBorder("Start / Stop")); panelStartStopControls.setBorder(BorderFactory.createTitledBorder("Start / Stop"));
JPanel panelStepwiseExecutionControls = new JPanel(); JPanel panelStepwiseExecutionControls=new JPanel();
panelStepwiseExecutionControls.setLayout(new GridLayout(4, 1, 5, 5)); panelStepwiseExecutionControls.setLayout(new GridLayout(4,1,5,5));
panelStepwiseExecutionControls.add(firstButton); panelStepwiseExecutionControls.add(firstButton);
panelStepwiseExecutionControls.add(nextButton); panelStepwiseExecutionControls.add(nextButton);
panelStepwiseExecutionControls.add(prevButton); panelStepwiseExecutionControls.add(prevButton);
panelStepwiseExecutionControls.add(lastButton); panelStepwiseExecutionControls.add(lastButton);
panelStepwiseExecutionControls.setBorder(BorderFactory.createTitledBorder("Stepwise execution")); panelStepwiseExecutionControls.setBorder(BorderFactory.createTitledBorder("Stepwise execution"));
JPanel panelAutomaticExecutionControls = new JPanel(); JPanel panelAutomaticExecutionControls=new JPanel();
panelAutomaticExecutionControls.setLayout(new GridLayout(5, 1, 5, 5)); panelAutomaticExecutionControls.setLayout(new GridLayout(5,1,5,5));
panelAutomaticExecutionControls.add(autoButton); panelAutomaticExecutionControls.add(autoButton);
panelAutomaticExecutionControls.add(autoSlider); panelAutomaticExecutionControls.add(autoSlider);
panelAutomaticExecutionControls.add(autoForwardButton); panelAutomaticExecutionControls.add(autoForwardButton);
panelAutomaticExecutionControls.add(autoBackwardButton); panelAutomaticExecutionControls.add(autoBackwardButton);
panelAutomaticExecutionControls.setBorder(BorderFactory.createTitledBorder("Automatic execution")); panelAutomaticExecutionControls.setBorder(BorderFactory.createTitledBorder("Automatic execution"));
JPanel buttonLine = new JPanel(); JPanel buttonLine=new JPanel();
buttonLine.setLayout(new GridLayout(3, 1, 5, 5)); buttonLine.setLayout(new GridLayout(3,1,5,5));
buttonLine.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); buttonLine.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
buttonLine.add(panelStartStopControls); buttonLine.add(panelStartStopControls);
buttonLine.add(panelStepwiseExecutionControls); buttonLine.add(panelStepwiseExecutionControls);
buttonLine.add(panelAutomaticExecutionControls); buttonLine.add(panelAutomaticExecutionControls);
JLabel headline = new JLabel(algorithm.getTitle()); JLabel headline=new JLabel(algorithm.getTitle());
headline.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); headline.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
headline.setFont(new Font("SansSerif", Font.PLAIN, 20)); headline.setFont(new Font("SansSerif",Font.PLAIN,20));
JScrollPane parameterAreaScrollPane = parameterArea.getScrollPane(); JScrollPane parameterAreaScrollPane = parameterArea.getScrollPane();
JScrollPane legendAreaScrollPane = legendArea.getScrollPane(); JScrollPane legendAreaScrollPane = legendArea.getScrollPane();
@ -142,33 +128,33 @@ public class OurHybridWindow<DRAW extends DrawArea,
parameterAreaScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); parameterAreaScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
legendAreaScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); legendAreaScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
JSplitPane hybridWindowSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, parameterAreaScrollPane, legendAreaScrollPane); JSplitPane hybridWindowSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,parameterAreaScrollPane, legendAreaScrollPane);
hybridWindowSplitPane.setOneTouchExpandable(true); hybridWindowSplitPane.setOneTouchExpandable(true);
hybridWindowSplitPane.setResizeWeight(0.465); hybridWindowSplitPane.setResizeWeight(0.465);
tabbedPane.insertTab(drawArea.getDrawAreaName(), null, drawArea.getScrollPane(), drawArea.getDrawAreaName(), 0); tabbedPane.insertTab(drawArea.getDrawAreaName(),null, drawArea.getScrollPane(),drawArea.getDrawAreaName(),0);
tabbedPane.setSelectedIndex(0); tabbedPane.setSelectedIndex(0);
setLayout(new BorderLayout(10, 10)); setLayout(new BorderLayout(10,10));
add(headline, BorderLayout.NORTH); add(headline,BorderLayout.NORTH);
add(hybridWindowSplitPane, BorderLayout.WEST); add(hybridWindowSplitPane,BorderLayout.WEST);
add(tabbedPane, BorderLayout.CENTER); add(tabbedPane,BorderLayout.CENTER);
add(textArea.getScrollPane(), BorderLayout.SOUTH); add(textArea.getScrollPane(),BorderLayout.SOUTH);
add(buttonLine, BorderLayout.EAST); add(buttonLine,BorderLayout.EAST);
setState(PARAMETERSTATE); setState(PARAMETERSTATE);
startListener = new StartListener(); startListener= new StartListener();
stopListener = new StopListener(); stopListener=new StopListener();
prevListener = new PrevListener(); prevListener=new PrevListener();
nextListener = new NextListener(); nextListener=new NextListener();
firstListener = new FirstListener(); firstListener=new FirstListener();
lastListener = new LastListener(); lastListener=new LastListener();
autoButtonListener = new AutoButtonListener(); autoButtonListener=new AutoButtonListener();
autoSliderListener = new AutoSliderListener(); autoSliderListener=new AutoSliderListener();
autoForwardListener = new AutoForwardListener(); autoForwardListener=new AutoForwardListener();
autoBackwardListener = new AutoBackwardListener(); autoBackwardListener=new AutoBackwardListener();
pauseButtonListener = new PauseButtonListener(); pauseButtonListener=new PauseButtonListener();
startButton.addActionListener(startListener); startButton.addActionListener(startListener);
stopButton.addActionListener(stopListener); stopButton.addActionListener(stopListener);
@ -182,33 +168,27 @@ public class OurHybridWindow<DRAW extends DrawArea,
autoBackwardButton.addItemListener(autoBackwardListener); autoBackwardButton.addItemListener(autoBackwardListener);
pauseButton.addActionListener(pauseButtonListener); pauseButton.addActionListener(pauseButtonListener);
autoTimer = new Timer(1, nextListener); autoTimer=new Timer(1,nextListener);
} }
/** class StartListener implements ActionListener{
* ActionListener implementation for starting the algorithm. public void actionPerformed(ActionEvent event){
*/ Component[]bComponents=methodButtons.getComponents();
class StartListener implements ActionListener {
public void actionPerformed(ActionEvent event) {
Component[] bComponents = methodButtons.getComponents();
setState(RUNSTATE); setState(RUNSTATE);
for (Component c : bComponents) { for(Component c:bComponents){
c.setEnabled(false); c.setEnabled(false);
} }
logList = algorithm.run(); logList=algorithm.run();
drawArea.setLogList(logList); drawArea.setLogList(logList);
textArea.setLogList(logList); textArea.setLogList(logList);
} }
} }
/** class StopListener implements ActionListener{
* ActionListener implementation for stopping the algorithm. public void actionPerformed(ActionEvent event){
*/ Component[]bComponents=methodButtons.getComponents();
class StopListener implements ActionListener {
public void actionPerformed(ActionEvent event) {
Component[] bComponents = methodButtons.getComponents();
setState(PARAMETERSTATE); setState(PARAMETERSTATE);
for (Component c : bComponents) { for(Component c:bComponents){
c.setEnabled(true); c.setEnabled(true);
} }
logList.clear(); logList.clear();
@ -217,20 +197,19 @@ public class OurHybridWindow<DRAW extends DrawArea,
} }
} }
/** class PrevListener implements ActionListener{
* ActionListener implementation for moving to the previous step. public void actionPerformed(ActionEvent event){
*/ if(logList.isInitialized()){
class PrevListener implements ActionListener { if(logList.get()==logList.firstElement()){
public void actionPerformed(ActionEvent event) {
if (logList.isInitialized()) {
if (logList.get() == logList.firstElement()) {
autoButton.setSelected(false); autoButton.setSelected(false);
} else { }
else{
logList.prev(); logList.prev();
drawArea.drawStep(); drawArea.drawStep();
textArea.printStep(); textArea.printStep();
} }
} else { }
else{
logList.prev(); logList.prev();
drawArea.drawStep(); drawArea.drawStep();
textArea.printStep(); textArea.printStep();
@ -238,20 +217,19 @@ public class OurHybridWindow<DRAW extends DrawArea,
} }
} }
/** class NextListener implements ActionListener{
* ActionListener implementation for moving to the next step. public void actionPerformed(ActionEvent event){
*/ if(logList.isInitialized()){
class NextListener implements ActionListener { if(logList.get()==logList.lastElement()){
public void actionPerformed(ActionEvent event) {
if (logList.isInitialized()) {
if (logList.get() == logList.lastElement()) {
autoButton.setSelected(false); autoButton.setSelected(false);
} else { }
else{
logList.next(); logList.next();
drawArea.drawStep(); drawArea.drawStep();
textArea.printStep(); textArea.printStep();
} }
} else { }
else{
logList.next(); logList.next();
drawArea.drawStep(); drawArea.drawStep();
textArea.printStep(); textArea.printStep();
@ -259,89 +237,68 @@ public class OurHybridWindow<DRAW extends DrawArea,
} }
} }
/** class FirstListener implements ActionListener{
* ActionListener implementation for moving to the first step. public void actionPerformed(ActionEvent event){
*/
class FirstListener implements ActionListener {
public void actionPerformed(ActionEvent event) {
logList.first(); logList.first();
drawArea.drawStep(); drawArea.drawStep();
textArea.printStep(); textArea.printStep();
} }
} }
/** class LastListener implements ActionListener{
* ActionListener implementation for moving to the last step. public void actionPerformed(ActionEvent event){
*/
class LastListener implements ActionListener {
public void actionPerformed(ActionEvent event) {
logList.last(); logList.last();
drawArea.drawStep(); drawArea.drawStep();
textArea.printStep(); textArea.printStep();
} }
} }
/**
* ItemListener implementation for handling auto button state changes.
*/
class AutoButtonListener implements ItemListener { class AutoButtonListener implements ItemListener {
public void itemStateChanged(ItemEvent event) { public void itemStateChanged(ItemEvent event){
if (event.getStateChange() == ItemEvent.SELECTED) { if(event.getStateChange()==ItemEvent.SELECTED){
setState(AUTOSTATE); setState(AUTOSTATE);
autoTimer.setDelay(10000 / ((int) Math.pow(autoSlider.getValue(), 2))); autoTimer.setDelay(10000/((int)Math.pow(autoSlider.getValue(),2)));
autoTimer.start(); autoTimer.start();
} else { }else{
setState(RUNSTATE); setState(RUNSTATE);
autoTimer.stop(); autoTimer.stop();
} }
} }
} }
/**
* ChangeListener implementation for handling auto slider changes.
*/
class AutoSliderListener implements ChangeListener { class AutoSliderListener implements ChangeListener {
public void stateChanged(ChangeEvent event) { public void stateChanged(ChangeEvent event){
if (autoTimer.isRunning()) { if(autoTimer.isRunning()){
autoTimer.stop(); autoTimer.stop();
autoTimer.setInitialDelay(10000 / ((int) Math.pow(autoSlider.getValue(), 2))); autoTimer.setInitialDelay(10000/((int)Math.pow(autoSlider.getValue(),2)));
autoTimer.setDelay(10000 / ((int) Math.pow(autoSlider.getValue(), 2))); autoTimer.setDelay(10000/((int)Math.pow(autoSlider.getValue(),2)));
autoTimer.start(); autoTimer.start();
autoTimer.setInitialDelay(1); autoTimer.setInitialDelay(1);
} }
} }
} }
/** class AutoForwardListener implements ItemListener{
* ItemListener implementation for handling auto forward button state changes. public void itemStateChanged(ItemEvent event){
*/ if(event.getStateChange()==ItemEvent.SELECTED){
class AutoForwardListener implements ItemListener {
public void itemStateChanged(ItemEvent event) {
if (event.getStateChange() == ItemEvent.SELECTED) {
autoTimer.removeActionListener(prevListener); autoTimer.removeActionListener(prevListener);
autoTimer.addActionListener(nextListener); autoTimer.addActionListener(nextListener);
} }
} }
} }
/** class AutoBackwardListener implements ItemListener{
* ItemListener implementation for handling auto backward button state changes. public void itemStateChanged(ItemEvent event){
*/ if(event.getStateChange()==ItemEvent.SELECTED){
class AutoBackwardListener implements ItemListener {
public void itemStateChanged(ItemEvent event) {
if (event.getStateChange() == ItemEvent.SELECTED) {
autoTimer.removeActionListener(nextListener); autoTimer.removeActionListener(nextListener);
autoTimer.addActionListener(prevListener); autoTimer.addActionListener(prevListener);
} }
} }
} }
/** class PauseButtonListener implements ActionListener{
* ActionListener implementation for handling pause button clicks. public void actionPerformed(ActionEvent event){
*/ if(autoButton.isSelected()){
class PauseButtonListener implements ActionListener {
public void actionPerformed(ActionEvent event) {
if (autoButton.isSelected()) {
setState(RUNSTATE); setState(RUNSTATE);
autoTimer.stop(); autoTimer.stop();
autoButton.setSelected(false); autoButton.setSelected(false);

View File

@ -8,6 +8,9 @@ import java.awt.*;
/** /**
* This class represents a visualization.LegendArea implementation and has been created for demonstration purposes only. * This class represents a visualization.LegendArea implementation and has been created for demonstration purposes only.
* Method initialize(Graphics) is overridden and now implements logic for drawing parameters on the legend area. * Method initialize(Graphics) is overridden and now implements logic for drawing parameters on the legend area.
* @author MSch<EFBFBD>fer
* DHBW Stuttgart/Campus Horb AI2008<br>
* <br>
*/ */
public class OurLegendArea extends LegendArea{ public class OurLegendArea extends LegendArea{
@ -18,7 +21,7 @@ public class OurLegendArea extends LegendArea{
*/ */
public OurLegendArea(){ public OurLegendArea(){
super(); super();
//set the legend area's preferred size manually for best visualization //set the legend area's preferred size manually for best visualization
setPreferredSize(new Dimension(150, 170)); setPreferredSize(new Dimension(150, 170));
} }
@ -33,16 +36,8 @@ public class OurLegendArea extends LegendArea{
// Erstellt einen neuen TitledBorder für den Legendenbereich // Erstellt einen neuen TitledBorder für den Legendenbereich
setBorder(BorderFactory.createTitledBorder("LegendArea")); setBorder(BorderFactory.createTitledBorder("LegendArea"));
// Zeichnet den schwarzen Knoten (Unbesuchter Knoten)
int y = 30; // Startposition für das Zeichnen der Legenden-Elemente
g.setColor(Color.BLACK);
g.fillOval(10, y, 20, 20); // Zeichnet einen kleinen Kreis (Knoten) mit der Farbe des Elements
g.setColor(Color.BLACK);
g.drawOval(10, y, 20, 20); // Zeichnet den Rand des Kreises
g.drawString("Unbesuchter Knoten", 40, y + 15); // Zeichnet die Beschreibung neben dem Kreis
// Zeichnet den roten Knoten (Start/End Knoten) // Zeichnet den roten Knoten (Start/End Knoten)
y += 40; // Startposition für das Zeichnen der Legenden-Elemente int y = 30; // Startposition für das Zeichnen der Legenden-Elemente
g.setColor(Color.RED); g.setColor(Color.RED);
g.fillOval(10, y, 20, 20); // Zeichnet einen kleinen Kreis (Knoten) mit der Farbe des Elements g.fillOval(10, y, 20, 20); // Zeichnet einen kleinen Kreis (Knoten) mit der Farbe des Elements
g.setColor(Color.BLACK); g.setColor(Color.BLACK);
@ -73,5 +68,10 @@ public class OurLegendArea extends LegendArea{
g.drawOval(10, y, 20, 20); // Zeichnet den Rand des Kreises g.drawOval(10, y, 20, 20); // Zeichnet den Rand des Kreises
g.drawString("Fertiger Weg", 40, y + 15); // Zeichnet die Beschreibung neben dem Kreis g.drawString("Fertiger Weg", 40, y + 15); // Zeichnet die Beschreibung neben dem Kreis
// Zeichnet die schwarze Linie (Kanten Markierung)
y += 40; // Nach unten verschieben für das nächste Element
g.setColor(Color.BLACK);
g.drawLine(10, y + 10, 30, y + 10); // Zeichnet eine horizontale Linie
g.drawString("Kanten Markierung", 40, y + 15); // Zeichnet die Beschreibung neben der Linie
} }
} }

View File

@ -8,108 +8,80 @@ import visualizationElements.Edge;
import visualizationElements.Vertex; import visualizationElements.Vertex;
/** /**
* This class extends logging.LogElement to provide additional functionality * This class provides an example for using logging.LogElement.
* for logging various elements related to graph visualization. * The super class has been extended by member value and corresponding get method.
* * The standard constructor has been overwritten and a new one has been introduced.
* @see LogElement * @see LogElement
* @author MSch<EFBFBD>fer
* DHBW Stuttgart/Campus Horb AI2008<br>
* <br>
*/ */
public class OurLogElement extends LogElement { public class OurLogElement extends LogElement{
/** The sum up value associated with this log element. */ /** The log elements sum up value. */
protected long value; protected long value;
protected Vertex vertex; protected Vertex vertex;
protected Edge edge; protected Edge edge;
protected visualizationElements.Graph ourGraph; protected visualizationElements.Graph ourGraph;
/** /**
* Standard constructor. * Standard constructor.
* Initializes the log element with default values. * Calls the constructor of super class and sets value 0.
*/ */
public OurLogElement() { public OurLogElement() {
super(); super();
this.value = 0; this.value = 0;
} }
/** /**
* Extended constructor. * Extended constructor.
* Initializes the log element with specified step number, description, sum up value, and vertex. * Sets specified step number, description and sum up value.
* * @param step the log element's step number
* @param step the step number of the log element * @param description the log element's step description
* @param description the description of the log element * @param value the log element's sum up value
* @param value the sum up value associated with the log element
* @param vertex the vertex associated with the log element
*/ */
public OurLogElement(int step, String description, long value, Vertex vertex) { public OurLogElement(int step, String description, long value, Vertex vertex){
this.step = step; this.step = step;
this.description = description; this.description = description;
this.value = value; this.value = value;
this.vertex = vertex; this.vertex = vertex;
} }
/**
* Extended constructor. public OurLogElement(int step, String description, long value, Edge edge){
* Initializes the log element with specified step number, description, sum up value, and edge.
*
* @param step the step number of the log element
* @param description the description of the log element
* @param value the sum up value associated with the log element
* @param edge the edge associated with the log element
*/
public OurLogElement(int step, String description, long value, Edge edge) {
this.step = step; this.step = step;
this.description = description; this.description = description;
this.value = value; this.value = value;
this.edge = edge; this.edge = edge;
} }
/**
* Extended constructor. public OurLogElement(int step, String description, long value, visualizationElements.Graph ourGraph ){
* Initializes the log element with specified step number, description, sum up value, and graph.
*
* @param step the step number of the log element
* @param description the description of the log element
* @param value the sum up value associated with the log element
* @param ourGraph the graph associated with the log element
*/
public OurLogElement(int step, String description, long value, visualizationElements.Graph ourGraph) {
this.step = step; this.step = step;
this.description = description; this.description = description;
this.value = value; this.value = value;
this.ourGraph = ourGraph; this.ourGraph = ourGraph;
} }
/** /**
* Retrieves the sum up value associated with this log element. * Returns the log element's sum up value.
* * @return the log element's sum up value
* @return the sum up value of the log element
*/ */
public long getValue() { public long getValue(){
return this.value; return this.value;
} }
/**
* Retrieves the edge associated with this log element.
*
* @return the edge associated with the log element
*/
public Edge getEdge() { public Edge getEdge() {
return this.edge; return this.edge;
} }
/**
* Retrieves the vertex associated with this log element.
*
* @return the vertex associated with the log element
*/
public Vertex getVertex() { public Vertex getVertex() {
return this.vertex; return this.vertex;
} }
/**
* Retrieves the graph associated with this log element.
*
* @return the graph associated with the log element
*/
public visualizationElements.Graph getGraph() { public visualizationElements.Graph getGraph() {
return this.ourGraph; return this.ourGraph;
} }

View File

@ -8,12 +8,13 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
/** /**
* This class extends visualisation.ParameterArea to provide a panel for selecting * This class provides an example for using visualization.ParameterArea.
* algorithmic methods such as Djikstra or A-Star.
*
* @see ParameterArea * @see ParameterArea
* @author MSch<EFBFBD>fer
* DHBW Stuttgart/Campus Horb AI2008<br>
* <br>
*/ */
public class OurMethodButtons extends ParameterArea { public class OurMethodButtons extends ParameterArea{
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@ -21,31 +22,32 @@ public class OurMethodButtons extends ParameterArea {
protected JRadioButton button2; protected JRadioButton button2;
private boolean isDjikstra; private boolean isDjikstra;
/** TextField containing maximum sum up value. */
/** TextField containing maximum sum up value. */
protected JTextField maxValue; protected JTextField maxValue;
/** /**
* Standard constructor. * Standard constructor.
* Initializes the method buttons panel with default settings. * Creates SumUpMethodArea with an empty JTextField.
*/ */
public OurMethodButtons() { public OurMethodButtons() {
super(); super();
isDjikstra = true; // Default to Djikstra isDjikstra = true; // Standardmäßig Djikstra
// Set layout manager to arrange buttons vertically // Layout-Manager setzen, um die Buttons vertikal anzuordnen
setLayout(new GridLayout(1, 2, 5, 5)); // 1 row, 2 columns, 5 pixels gap setLayout(new GridLayout(1, 2, 5, 5)); // 1 Zeile, 2 Spalten, 5 Pixel Abstand
// Create radio buttons // Buttons erstellen
button1 = new JRadioButton("Djikstra", true); button1 = new JRadioButton("Djikstra", true);
button2 = new JRadioButton("A-Stern"); button2 = new JRadioButton("A-Stern");
// Create a button group and add buttons to ensure mutual exclusion // ButtonGroup erstellen und Buttons hinzufügen, um die gegenseitige Ausschließung zu gewährleisten
ButtonGroup group = new ButtonGroup(); ButtonGroup group = new ButtonGroup();
group.add(button1); group.add(button1);
group.add(button2); group.add(button2);
// Add action listeners to handle button selections // ActionListener hinzufügen
button1.addActionListener(new ActionListener() { button1.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
@ -60,16 +62,11 @@ public class OurMethodButtons extends ParameterArea {
} }
}); });
// Add buttons to the panel // Buttons zum Panel hinzufügen
this.add(button1); this.add(button1);
this.add(button2); this.add(button2);
} }
/**
* Retrieves the selected algorithmic method.
*
* @return true if Djikstra is selected, false if A-Star is selected
*/
public boolean getSelectedMethod() { public boolean getSelectedMethod() {
return isDjikstra; return isDjikstra;
} }

View File

@ -5,39 +5,38 @@ import visualisation.ParameterArea;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Objects; import java.util.Objects;
/** /**
* This class extends visualisation.ParameterArea and provides an example for using it. * This class provides an example for using visualization.ParameterArea.
* It includes functionality for managing a graph selection and creation based on user input.
*
* @see ParameterArea * @see ParameterArea
* @author MSch<EFBFBD>fer
* DHBW Stuttgart/Campus Horb AI2008<br>
* <br>
*/ */
public class OurParameterArea extends ParameterArea { public class OurParameterArea extends ParameterArea{
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
// Custom graph instance
private DirectedGraph<VertexMarking, EdgeMarking> customGraph; private DirectedGraph<VertexMarking, EdgeMarking> customGraph;
// Radio buttons for selecting examples or custom graph
private JRadioButton button1; private JRadioButton button1;
private JRadioButton button2; private JRadioButton button2;
private JRadioButton button3; private JRadioButton button3;
private JRadioButton button4; private JRadioButton button4;
private JRadioButton button5; private JRadioButton button5;
// Button to add a custom graph
private JButton buttonAddGraph; private JButton buttonAddGraph;
// Text fields for inputting vertex and edge data
private JTextField textField1; private JTextField textField1;
private JTextField textField2; private JTextField textField2;
// Selected example identifier
private int selectedExample; private int selectedExample;
/** TextField containing maximum sum up value. */
/** TextField containing maximum sum up value. */
protected JTextField maxValue; protected JTextField maxValue;
/** /**
@ -46,31 +45,30 @@ public class OurParameterArea extends ParameterArea {
*/ */
public OurParameterArea() { public OurParameterArea() {
super(); super();
selectedExample = 1; // Default to example 1 selectedExample = 1; // Standardmäßig Beispiel 1
this.customGraph = new DirectedGraph<>(); this.customGraph = new DirectedGraph<>();
setBorder(BorderFactory.createTitledBorder("ParameterArea")); setBorder(BorderFactory.createTitledBorder("ParameterArea"));
// Set layout manager to arrange buttons vertically // Layout-Manager setzen, um die Buttons vertikal anzuordnen
setLayout(new GridLayout(4, 1, 5, 5)); // 4 rows, 1 column, 5 pixel gap setLayout(new GridLayout(4, 1, 5, 5)); // 4 Zeilen, 1 Spalte, 5 Pixel Abstand
// Create radio buttons // Buttons erstellen
button1 = new JRadioButton("Beispiel 1", true); button1 = new JRadioButton("Beispiel 1", true);
button2 = new JRadioButton("Beispiel 2"); button2 = new JRadioButton("Beispiel 2");
button3 = new JRadioButton("Beispiel 3"); button3 = new JRadioButton("Beispiel 3");
button4 = new JRadioButton("Beispiel 4"); button4 = new JRadioButton("Beispiel 4");
button5 = new JRadioButton("Eigener Graph"); button5 = new JRadioButton("Eigener Graph");
// Button to add a graph
buttonAddGraph = new JButton("Graph einfügen"); buttonAddGraph = new JButton("Graph einfügen");
// Eingabefelder
// Input text fields
textField1 = new JTextField("A-100-100;Ende-200-200;Start-100-200;D-200-100"); textField1 = new JTextField("A-100-100;Ende-200-200;Start-100-200;D-200-100");
textField2 = new JTextField("A-Ende-15;Start-D-10;D-A-3;A-Ende-15;Start-D-10;D-A-3"); textField2 = new JTextField("A-Ende-15;Start-D-10;D-A-3;A-Ende-15;Start-D-10;D-A-3");
textField1.setPreferredSize(new Dimension(button5.getWidth(), button5.getHeight())); textField1.setPreferredSize(new Dimension(button5.getWidth(), button5.getHeight()));
textField2.setPreferredSize(new Dimension(button5.getWidth(), button5.getHeight())); textField2.setPreferredSize(new Dimension(button5.getWidth(), button5.getHeight()));
// Button group to ensure mutual exclusion of radio buttons
// ButtonGroup erstellen und Buttons hinzufügen, um die gegenseitige Ausschließung zu gewährleisten
ButtonGroup group = new ButtonGroup(); ButtonGroup group = new ButtonGroup();
group.add(button1); group.add(button1);
group.add(button2); group.add(button2);
@ -78,36 +76,39 @@ public class OurParameterArea extends ParameterArea {
group.add(button4); group.add(button4);
group.add(button5); group.add(button5);
// Add action listeners to radio buttons // ActionListener hinzufügen
button1.addActionListener(e -> selectedExample = 1); button1.addActionListener(e -> selectedExample = 1);
button2.addActionListener(e -> selectedExample = 2); button2.addActionListener(e -> selectedExample = 2);
button3.addActionListener(e -> selectedExample = 3); button3.addActionListener(e -> selectedExample = 3);
button4.addActionListener(e -> selectedExample = 4); button4.addActionListener(e -> selectedExample = 4);
button5.addActionListener(e -> selectedExample = 5); button5.addActionListener(e -> selectedExample = 5);
// Add action listener to add graph button
buttonAddGraph.addActionListener(e -> { buttonAddGraph.addActionListener(e -> {
String input1 = textField1.getText(); String input1 = textField1.getText();
String input2 = textField2.getText(); String input2 = textField2.getText();
this.customGraph = createGraph(input1, input2); this.customGraph = createGraph(input1, input2);
}); });
// Add components to panel // Buttons zum Panel hinzufügen
add(button1); add(button1);
add(button2); add(button2);
add(button3); add(button3);
add(button4); add(button4);
add(button5); add(button5);
add(buttonAddGraph);
add(textField1); add(buttonAddGraph);
add(textField2); add(textField1);
add(textField2);
} }
/**
* Retrieves the selected graph based on the user's choice.
*
* @return The selected graph as a DirectedGraph instance.
*/
public DirectedGraph<VertexMarking, EdgeMarking> getSelectedGraph() { public DirectedGraph<VertexMarking, EdgeMarking> getSelectedGraph() {
ExampleGraphs temp = new ExampleGraphs(); ExampleGraphs temp = new ExampleGraphs();
switch (selectedExample) { switch (selectedExample) {
@ -125,41 +126,37 @@ public class OurParameterArea extends ParameterArea {
} }
} }
/**
* Creates a directed graph based on input vertex and edge data.
*
* @param vertices String representation of vertices in the format "Name-X-Y;..."
* @param edges String representation of edges in the format "Source-Target-Weight;..."
* @return DirectedGraph<VertexMarking, EdgeMarking> created from the input data.
*/
public DirectedGraph<VertexMarking, EdgeMarking> createGraph(String vertices, String edges) {
DirectedGraph<VertexMarking, EdgeMarking> newGraph = new DirectedGraph<>();
String[] allVertices = vertices.split(";"); // Vertex Beispiel-Eingabe: A-100-100;Ende-200-200;Start-100-200;D-200-100
String[] allEdges = edges.split(";"); // Edge Beispiel-Eingabe: A-B-15;C-D-10;D-A-3
public DirectedGraph<VertexMarking, EdgeMarking> createGraph(String vertices, String edges) {
DirectedGraph<VertexMarking, EdgeMarking> newGraph = new DirectedGraph<>();
// Create vertices
for (String i: allVertices) {
String[] current = i.split("-");
newGraph.addVertex(new MarkedVertex<>(Integer.parseInt(current[1]), Integer.parseInt(current[2]), current[0], null, Color.BLACK));
}
// Create edges String[] allVertices = vertices.split(";");
MarkedVertex<VertexMarking> start = null; String[] allEdges = edges.split(";");
MarkedVertex<VertexMarking> end = null;
for (String i: allEdges) { for (String i: allVertices) {
String[] current = i.split("-"); String[] current = i.split("-");
for (MarkedVertex<VertexMarking> j: newGraph.getAllVertexes()) { newGraph.addVertex(new MarkedVertex<>(Integer.parseInt(current[1]), Integer.parseInt(current[2]), current[0], null, Color.BLACK));
if (Objects.equals(j.getName(), current[0])) { }
start = j;
} MarkedVertex<VertexMarking> start = null;
MarkedVertex<VertexMarking> end = null;
for (String i: allEdges) {
String[] current = i.split("-");
for (MarkedVertex<VertexMarking> j: newGraph.getAllVertexes()) {
if (Objects.equals(j.getName(), current[0])) {
start = j;
}
if (Objects.equals(j.getName(), current[1])) { if (Objects.equals(j.getName(), current[1])) {
end = j; end = j;
} }
} }
newGraph.addEdge(new MarkedEdge<>(i, start, end, new EdgeWeightMarking(Integer.parseInt(current[2])))); newGraph.addEdge(new MarkedEdge<>(i, start, end, new EdgeWeightMarking(Integer.parseInt(current[2]))));
} }
return newGraph;
}
return newGraph;
}
} }

View File

@ -5,40 +5,39 @@ import logging.LogElementList;
import visualisation.TextArea; import visualisation.TextArea;
/** /**
* This class extends visualisation.TextArea and provides an example of its usage. * This class provides an example for using visualization.TextArea.
* It overrides constructors and the print() method. * Constructors and print() method have been overwritten.
*
* @see TextArea * @see TextArea
* @author MSch<EFBFBD>fer
* DHBW Stuttgart/Campus Horb AI2008<br>
* <br>
*/ */
public class OurTextArea extends TextArea { public class OurTextArea extends TextArea{
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** /**
* Default constructor for creating an instance of OurTextArea. * Standard constructor.
* Initializes with default settings.
*/ */
public OurTextArea() { public OurTextArea() {
super(); super();
} }
/** /**
* Extended constructor for creating an instance of OurTextArea. * Extended constructor.
* Sets the initial LogElementList of OurLogElement as the log list. * Sets LogElementList of TestLogElements as log list.
* * @param logList the text area's log element list.
* @param logList the LogElementList containing OurLogElement objects for the text area's log.
*/ */
public OurTextArea(LogElementList<OurLogElement> logList) { public OurTextArea(LogElementList<OurLogElement>logList){
super(logList); super(logList);
} }
/** /**
* Outputs the description of a log element to the text area. * Textual output of a log element.
* * No output.
* @return true if the operation is successful, false otherwise.
*/ */
public boolean print() { public boolean print(){
LogElement logElement = (LogElement) logList.get(); LogElement logElement=(LogElement)logList.get();
setText(logElement.getDescription()); setText(logElement.getDescription());
return true; return true;
} }

View File

@ -7,6 +7,7 @@
<list default="true" id="70f8ea87-9ffc-471a-8059-ebbfc323adcc" name="Changes" comment="Weighting gefixt"> <list default="true" id="70f8ea87-9ffc-471a-8059-ebbfc323adcc" name="Changes" comment="Weighting gefixt">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/OurApplication/OurAlgorithm.java" beforeDir="false" afterPath="$PROJECT_DIR$/OurApplication/OurAlgorithm.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/OurApplication/OurAlgorithm.java" beforeDir="false" afterPath="$PROJECT_DIR$/OurApplication/OurAlgorithm.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/OurApplication/OurDrawArea.java" beforeDir="false" afterPath="$PROJECT_DIR$/OurApplication/OurDrawArea.java" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -180,20 +181,4 @@
<MESSAGE value="Weighting gefixt" /> <MESSAGE value="Weighting gefixt" />
<option name="LAST_COMMIT_MESSAGE" value="Weighting gefixt" /> <option name="LAST_COMMIT_MESSAGE" value="Weighting gefixt" />
</component> </component>
<component name="XDebuggerManager">
<breakpoint-manager>
<breakpoints>
<line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/OurApplication/OurParameterArea.java</url>
<line>142</line>
<option name="timeStamp" value="7" />
</line-breakpoint>
</breakpoints>
</breakpoint-manager>
<watches-manager>
<configuration name="Application">
<watch expression="newGraph.screenGraph" />
</configuration>
</watches-manager>
</component>
</project> </project>