Added option to chose between methods
This commit is contained in:
parent
e020e34d94
commit
b5730e1b18
@ -20,6 +20,7 @@ import java.util.Vector;
|
||||
public class OurAlgorithm extends Algorithm {
|
||||
|
||||
private graph.Graph<VertexMarking, EdgeMarking> currentGraph;
|
||||
private OurMethodButtons methodButtons;
|
||||
|
||||
public OurAlgorithm() {
|
||||
super();
|
||||
@ -28,8 +29,9 @@ public class OurAlgorithm extends Algorithm {
|
||||
* Creates a sum up algorithm.
|
||||
* @param parameterArea the sum up parameter area the algorithm gets its parameters from
|
||||
*/
|
||||
public OurAlgorithm(OurParameterArea parameterArea){
|
||||
public OurAlgorithm(OurParameterArea parameterArea, OurMethodButtons methodButtons){
|
||||
super(parameterArea,"GraphAlgorithm");
|
||||
this.methodButtons = methodButtons;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -40,6 +42,7 @@ public class OurAlgorithm extends Algorithm {
|
||||
* @return a LogElementList containing the algorithm processing single steps
|
||||
*/
|
||||
public LogElementList<OurLogElement> run() {
|
||||
|
||||
OurParameterArea currentParameterArea = (OurParameterArea) this.getParameterArea();
|
||||
this.setCurrentGraph(currentParameterArea.getSelectedGraph());
|
||||
|
||||
@ -50,7 +53,11 @@ public class OurAlgorithm extends Algorithm {
|
||||
MarkedVertex<VertexMarking> end = this.currentGraph.getAllVertexes().get(random.nextInt(this.currentGraph.getAllVertexes().size()));
|
||||
System.out.println(start.getName() + " to " + end.getName());
|
||||
|
||||
this.currentGraph.getShortestPathDijkstra(start, end);
|
||||
if(this.methodButtons.getSelectedMethod()){
|
||||
this.currentGraph.getShortestPathDijkstra(start, end);
|
||||
}else{
|
||||
this.currentGraph.getShortestPathAStar(start, end);
|
||||
}
|
||||
|
||||
return this.currentGraph.getLogList();
|
||||
}
|
||||
@ -59,6 +66,5 @@ public class OurAlgorithm extends Algorithm {
|
||||
public void setCurrentGraph(graph.Graph<VertexMarking, EdgeMarking> graph) {
|
||||
this.currentGraph = graph;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -52,11 +52,12 @@ public class OurApplication {
|
||||
|
||||
LogElementList<OurLogElement> logList=new LogElementList<OurLogElement>();
|
||||
OurParameterArea parameterArea = new OurParameterArea();
|
||||
OurMethodButtons methodButtons = new OurMethodButtons();
|
||||
OurDrawArea drawArea = new OurDrawArea(logList,"GraphVisualization");
|
||||
OurTextArea textArea = new OurTextArea(logList);
|
||||
OurAlgorithm algorithm = new OurAlgorithm(parameterArea);
|
||||
OurAlgorithm algorithm = new OurAlgorithm(parameterArea, methodButtons);
|
||||
OurLegendArea legendArea = new OurLegendArea();
|
||||
HybridWindow<OurDrawArea, OurTextArea, OurParameterArea, OurAlgorithm, OurLogElement, OurLegendArea> applet = new HybridWindow<OurDrawArea, OurTextArea, OurParameterArea, OurAlgorithm, OurLogElement, OurLegendArea>(drawArea, textArea, parameterArea, algorithm, logList, legendArea);
|
||||
OurHybridWindow<OurDrawArea, OurTextArea, OurParameterArea, OurAlgorithm, OurLogElement, OurLegendArea, OurMethodButtons> applet = new OurHybridWindow<OurDrawArea, OurTextArea, OurParameterArea, OurAlgorithm, OurLogElement, OurLegendArea, OurMethodButtons>(drawArea, textArea, parameterArea, algorithm, logList, legendArea, methodButtons);
|
||||
|
||||
|
||||
|
||||
|
@ -1,7 +1,19 @@
|
||||
package OurApplication;
|
||||
|
||||
import logging.Algorithm;
|
||||
import logging.LogElement;
|
||||
import logging.LogElementList;
|
||||
import visualisation.HybridWindow;
|
||||
import visualisation.*;
|
||||
import visualisation.TextArea;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.awt.event.ItemListener;
|
||||
|
||||
/**
|
||||
* This class provides an example for using visualization.HybridWindow.
|
||||
@ -13,7 +25,36 @@ import visualisation.HybridWindow;
|
||||
* DHBW Stuttgart/Campus Horb AI2008<br>
|
||||
* <br>
|
||||
*/
|
||||
public class OurHybridWindow extends HybridWindow{
|
||||
public class OurHybridWindow<DRAW extends DrawArea,
|
||||
TEXT extends TextArea,
|
||||
PARAM extends ParameterArea,
|
||||
ALGORITHM extends Algorithm,
|
||||
LOG extends LogElement,
|
||||
LEGEND extends LegendArea,
|
||||
METHODBUTTONS extends ParameterArea> extends HybridWindow{
|
||||
|
||||
protected METHODBUTTONS methodButtons;
|
||||
protected StartListener startListener;
|
||||
/** Action listener for stop button. */
|
||||
protected StopListener stopListener;
|
||||
/** Action listener for previous button. */
|
||||
protected PrevListener prevListener;
|
||||
/** Action listener for next button. */
|
||||
protected NextListener nextListener;
|
||||
/** Action listener for first button. */
|
||||
protected FirstListener firstListener;
|
||||
/** Action listener for last button. */
|
||||
protected LastListener lastListener;
|
||||
/** Item listener for auto button. */
|
||||
protected AutoButtonListener autoButtonListener;
|
||||
/** Change listener for auto slider. */
|
||||
protected AutoSliderListener autoSliderListener;
|
||||
/** Item listener for forward button. */
|
||||
protected AutoForwardListener autoForwardListener;
|
||||
/** Item listener for backward button. */
|
||||
protected AutoBackwardListener autoBackwardListener;
|
||||
/** Item listener for pause button. */
|
||||
protected PauseButtonListener pauseButtonListener;
|
||||
|
||||
/**
|
||||
* Overwritten standard constructor.
|
||||
@ -23,11 +64,245 @@ public class OurHybridWindow extends HybridWindow{
|
||||
*/
|
||||
public OurHybridWindow() {
|
||||
super();
|
||||
logList = new LogElementList<OurLogElement>();
|
||||
parameterArea = new OurParameterArea();
|
||||
drawArea = new OurDrawArea(logList,"visualization");
|
||||
textArea = new OurTextArea(logList);
|
||||
legendArea = new OurLegendArea();
|
||||
algorithm = new OurAlgorithm((OurParameterArea) parameterArea);
|
||||
}
|
||||
public OurHybridWindow(DRAW drawArea, TEXT textArea, PARAM parameterArea, ALGORITHM algorithm, LogElementList<LOG>logList, LEGEND legendArea, METHODBUTTONS methodButtons) {
|
||||
super(drawArea, textArea, parameterArea, algorithm, logList, legendArea);
|
||||
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();
|
||||
autoDirection.add(autoForwardButton);
|
||||
autoDirection.add(autoBackwardButton);
|
||||
autoForwardButton.setSelected(true);
|
||||
|
||||
JPanel panelStartStopControls=new JPanel();
|
||||
panelStartStopControls.setLayout(new GridLayout(4,1,5,5));
|
||||
panelStartStopControls.add(startButton);
|
||||
panelStartStopControls.add(stopButton);
|
||||
panelStartStopControls.add(pauseButton);
|
||||
panelStartStopControls.add(methodButtons);
|
||||
panelStartStopControls.setBorder(BorderFactory.createTitledBorder("Start / Stop"));
|
||||
|
||||
JPanel panelStepwiseExecutionControls=new JPanel();
|
||||
panelStepwiseExecutionControls.setLayout(new GridLayout(4,1,5,5));
|
||||
panelStepwiseExecutionControls.add(firstButton);
|
||||
panelStepwiseExecutionControls.add(nextButton);
|
||||
panelStepwiseExecutionControls.add(prevButton);
|
||||
panelStepwiseExecutionControls.add(lastButton);
|
||||
panelStepwiseExecutionControls.setBorder(BorderFactory.createTitledBorder("Stepwise execution"));
|
||||
|
||||
JPanel panelAutomaticExecutionControls=new JPanel();
|
||||
panelAutomaticExecutionControls.setLayout(new GridLayout(5,1,5,5));
|
||||
panelAutomaticExecutionControls.add(autoButton);
|
||||
panelAutomaticExecutionControls.add(autoSlider);
|
||||
panelAutomaticExecutionControls.add(autoForwardButton);
|
||||
panelAutomaticExecutionControls.add(autoBackwardButton);
|
||||
panelAutomaticExecutionControls.setBorder(BorderFactory.createTitledBorder("Automatic execution"));
|
||||
|
||||
JPanel buttonLine=new JPanel();
|
||||
buttonLine.setLayout(new GridLayout(3,1,5,5));
|
||||
buttonLine.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
||||
buttonLine.add(panelStartStopControls);
|
||||
buttonLine.add(panelStepwiseExecutionControls);
|
||||
buttonLine.add(panelAutomaticExecutionControls);
|
||||
|
||||
JLabel headline=new JLabel(algorithm.getTitle());
|
||||
headline.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
||||
headline.setFont(new Font("SansSerif",Font.PLAIN,20));
|
||||
|
||||
JScrollPane parameterAreaScrollPane = parameterArea.getScrollPane();
|
||||
JScrollPane legendAreaScrollPane = legendArea.getScrollPane();
|
||||
|
||||
parameterAreaScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
|
||||
legendAreaScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
|
||||
|
||||
JSplitPane hybridWindowSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,parameterAreaScrollPane, legendAreaScrollPane);
|
||||
hybridWindowSplitPane.setOneTouchExpandable(true);
|
||||
hybridWindowSplitPane.setResizeWeight(0.465);
|
||||
tabbedPane.insertTab(drawArea.getDrawAreaName(),null, drawArea.getScrollPane(),drawArea.getDrawAreaName(),0);
|
||||
tabbedPane.setSelectedIndex(0);
|
||||
|
||||
setLayout(new BorderLayout(10,10));
|
||||
|
||||
add(headline,BorderLayout.NORTH);
|
||||
add(hybridWindowSplitPane,BorderLayout.WEST);
|
||||
add(tabbedPane,BorderLayout.CENTER);
|
||||
add(textArea.getScrollPane(),BorderLayout.SOUTH);
|
||||
add(buttonLine,BorderLayout.EAST);
|
||||
|
||||
setState(PARAMETERSTATE);
|
||||
|
||||
startListener= new StartListener();
|
||||
stopListener=new StopListener();
|
||||
prevListener=new PrevListener();
|
||||
nextListener=new NextListener();
|
||||
firstListener=new FirstListener();
|
||||
lastListener=new LastListener();
|
||||
autoButtonListener=new AutoButtonListener();
|
||||
autoSliderListener=new AutoSliderListener();
|
||||
autoForwardListener=new AutoForwardListener();
|
||||
autoBackwardListener=new AutoBackwardListener();
|
||||
pauseButtonListener=new PauseButtonListener();
|
||||
|
||||
startButton.addActionListener(startListener);
|
||||
stopButton.addActionListener(stopListener);
|
||||
prevButton.addActionListener(prevListener);
|
||||
nextButton.addActionListener(nextListener);
|
||||
firstButton.addActionListener(firstListener);
|
||||
lastButton.addActionListener(lastListener);
|
||||
autoButton.addItemListener(autoButtonListener);
|
||||
autoSlider.addChangeListener(autoSliderListener);
|
||||
autoForwardButton.addItemListener(autoForwardListener);
|
||||
autoBackwardButton.addItemListener(autoBackwardListener);
|
||||
pauseButton.addActionListener(pauseButtonListener);
|
||||
|
||||
autoTimer=new Timer(1,nextListener);
|
||||
}
|
||||
|
||||
class StartListener implements ActionListener{
|
||||
public void actionPerformed(ActionEvent event){
|
||||
Component[]bComponents=methodButtons.getComponents();
|
||||
setState(RUNSTATE);
|
||||
for(Component c:bComponents){
|
||||
c.setEnabled(false);
|
||||
}
|
||||
logList=algorithm.run();
|
||||
drawArea.setLogList(logList);
|
||||
textArea.setLogList(logList);
|
||||
}
|
||||
}
|
||||
|
||||
class StopListener implements ActionListener{
|
||||
public void actionPerformed(ActionEvent event){
|
||||
Component[]bComponents=methodButtons.getComponents();
|
||||
setState(PARAMETERSTATE);
|
||||
for(Component c:bComponents){
|
||||
c.setEnabled(true);
|
||||
}
|
||||
logList.clear();
|
||||
drawArea.clear();
|
||||
textArea.clear();
|
||||
}
|
||||
}
|
||||
|
||||
class PrevListener implements ActionListener{
|
||||
public void actionPerformed(ActionEvent event){
|
||||
if(logList.isInitialized()){
|
||||
if(logList.get()==logList.firstElement()){
|
||||
autoButton.setSelected(false);
|
||||
}
|
||||
else{
|
||||
logList.prev();
|
||||
drawArea.drawStep();
|
||||
textArea.printStep();
|
||||
}
|
||||
}
|
||||
else{
|
||||
logList.prev();
|
||||
drawArea.drawStep();
|
||||
textArea.printStep();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class NextListener implements ActionListener{
|
||||
public void actionPerformed(ActionEvent event){
|
||||
if(logList.isInitialized()){
|
||||
if(logList.get()==logList.lastElement()){
|
||||
autoButton.setSelected(false);
|
||||
}
|
||||
else{
|
||||
logList.next();
|
||||
drawArea.drawStep();
|
||||
textArea.printStep();
|
||||
}
|
||||
}
|
||||
else{
|
||||
logList.next();
|
||||
drawArea.drawStep();
|
||||
textArea.printStep();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class FirstListener implements ActionListener{
|
||||
public void actionPerformed(ActionEvent event){
|
||||
logList.first();
|
||||
drawArea.drawStep();
|
||||
textArea.printStep();
|
||||
}
|
||||
}
|
||||
|
||||
class LastListener implements ActionListener{
|
||||
public void actionPerformed(ActionEvent event){
|
||||
logList.last();
|
||||
drawArea.drawStep();
|
||||
textArea.printStep();
|
||||
}
|
||||
}
|
||||
|
||||
class AutoButtonListener implements ItemListener {
|
||||
public void itemStateChanged(ItemEvent event){
|
||||
if(event.getStateChange()==ItemEvent.SELECTED){
|
||||
setState(AUTOSTATE);
|
||||
autoTimer.setDelay(10000/((int)Math.pow(autoSlider.getValue(),2)));
|
||||
autoTimer.start();
|
||||
}else{
|
||||
setState(RUNSTATE);
|
||||
autoTimer.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class AutoSliderListener implements ChangeListener {
|
||||
public void stateChanged(ChangeEvent event){
|
||||
if(autoTimer.isRunning()){
|
||||
autoTimer.stop();
|
||||
autoTimer.setInitialDelay(10000/((int)Math.pow(autoSlider.getValue(),2)));
|
||||
autoTimer.setDelay(10000/((int)Math.pow(autoSlider.getValue(),2)));
|
||||
autoTimer.start();
|
||||
autoTimer.setInitialDelay(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class AutoForwardListener implements ItemListener{
|
||||
public void itemStateChanged(ItemEvent event){
|
||||
if(event.getStateChange()==ItemEvent.SELECTED){
|
||||
autoTimer.removeActionListener(prevListener);
|
||||
autoTimer.addActionListener(nextListener);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class AutoBackwardListener implements ItemListener{
|
||||
public void itemStateChanged(ItemEvent event){
|
||||
if(event.getStateChange()==ItemEvent.SELECTED){
|
||||
autoTimer.removeActionListener(nextListener);
|
||||
autoTimer.addActionListener(prevListener);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class PauseButtonListener implements ActionListener{
|
||||
public void actionPerformed(ActionEvent event){
|
||||
if(autoButton.isSelected()){
|
||||
setState(RUNSTATE);
|
||||
autoTimer.stop();
|
||||
autoButton.setSelected(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
73
OurApplication/OurMethodButtons.java
Normal file
73
OurApplication/OurMethodButtons.java
Normal file
@ -0,0 +1,73 @@
|
||||
package OurApplication;
|
||||
|
||||
import visualisation.ParameterArea;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
/**
|
||||
* This class provides an example for using visualization.ParameterArea.
|
||||
* @see ParameterArea
|
||||
* @author MSch<EFBFBD>fer
|
||||
* DHBW Stuttgart/Campus Horb AI2008<br>
|
||||
* <br>
|
||||
*/
|
||||
public class OurMethodButtons extends ParameterArea{
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
protected JRadioButton button1;
|
||||
protected JRadioButton button2;
|
||||
private boolean isDjikstra;
|
||||
|
||||
|
||||
/** TextField containing maximum sum up value. */
|
||||
protected JTextField maxValue;
|
||||
|
||||
/**
|
||||
* Standard constructor.
|
||||
* Creates SumUpMethodArea with an empty JTextField.
|
||||
*/
|
||||
public OurMethodButtons() {
|
||||
super();
|
||||
|
||||
isDjikstra = true; // Standardmäßig Djikstra
|
||||
|
||||
// Layout-Manager setzen, um die Buttons vertikal anzuordnen
|
||||
setLayout(new GridLayout(1, 2, 5, 5)); // 1 Zeile, 2 Spalten, 5 Pixel Abstand
|
||||
|
||||
// Buttons erstellen
|
||||
button1 = new JRadioButton("Djikstra", true);
|
||||
button2 = new JRadioButton("A-Stern");
|
||||
|
||||
// ButtonGroup erstellen und Buttons hinzufügen, um die gegenseitige Ausschließung zu gewährleisten
|
||||
ButtonGroup group = new ButtonGroup();
|
||||
group.add(button1);
|
||||
group.add(button2);
|
||||
|
||||
// ActionListener hinzufügen
|
||||
button1.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
isDjikstra = true;
|
||||
}
|
||||
});
|
||||
|
||||
button2.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
isDjikstra = false;
|
||||
}
|
||||
});
|
||||
|
||||
// Buttons zum Panel hinzufügen
|
||||
this.add(button1);
|
||||
this.add(button2);
|
||||
}
|
||||
|
||||
public boolean getSelectedMethod() {
|
||||
return isDjikstra;
|
||||
}
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user