2024-07-02 19:13:30 +00:00
|
|
|
|
package OurApplication;
|
2024-06-15 19:55:30 +00:00
|
|
|
|
|
2024-07-07 17:49:31 +00:00
|
|
|
|
import logging.Algorithm;
|
|
|
|
|
import logging.LogElement;
|
2024-06-15 19:55:30 +00:00
|
|
|
|
import logging.LogElementList;
|
2024-07-07 17:49:31 +00:00
|
|
|
|
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;
|
2024-06-15 19:55:30 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This class provides an example for using visualization.HybridWindow.
|
|
|
|
|
* Overwriting the constructor is necessary to run as an applet.
|
|
|
|
|
* For running as an application overwriting the constructor is not necessary
|
2024-07-02 19:13:30 +00:00
|
|
|
|
* @see HybridWindow
|
|
|
|
|
* @see OurApplication
|
|
|
|
|
* @author MSch<EFBFBD>fer
|
2024-06-15 19:55:30 +00:00
|
|
|
|
* DHBW Stuttgart/Campus Horb AI2008<br>
|
|
|
|
|
* <br>
|
|
|
|
|
*/
|
2024-07-07 17:49:31 +00:00
|
|
|
|
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;
|
2024-06-15 19:55:30 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Overwritten standard constructor.
|
|
|
|
|
* Creates a TestUpHybridWindow with
|
|
|
|
|
* TestParameterArea,SumUpLegendArea, TestDrawArea, TestTextArea,
|
|
|
|
|
* TestAlgorithm and a LogElementList of TestLogElements.
|
|
|
|
|
*/
|
2024-07-02 19:13:30 +00:00
|
|
|
|
public OurHybridWindow() {
|
2024-06-15 19:55:30 +00:00
|
|
|
|
super();
|
2024-07-07 17:49:31 +00:00
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-15 19:55:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|