344 lines
8.9 KiB
Java
344 lines
8.9 KiB
Java
package View;
|
|
|
|
|
|
import Presenter.Presenter;
|
|
import View.Panels.LMSPanel;
|
|
import View.Panels.MenuPanel;
|
|
import View.Panels.OutputPanel;
|
|
import View.Panels.RMPanel;
|
|
import java.awt.BorderLayout;
|
|
import java.awt.Dimension;
|
|
import java.awt.FlowLayout;
|
|
import java.awt.event.ActionEvent;
|
|
import java.util.List;
|
|
import javax.swing.JButton;
|
|
import javax.swing.JDialog;
|
|
import javax.swing.JFrame;
|
|
import javax.swing.JPanel;
|
|
import javax.swing.JScrollPane;
|
|
import javax.swing.JSplitPane;
|
|
import javax.swing.JTabbedPane;
|
|
import javax.swing.SwingUtilities;
|
|
|
|
/**
|
|
* Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
|
|
*
|
|
* @Author: Armin Wolf
|
|
* @Email: a_wolf28@uni-muenster.de
|
|
* @Date: 28.05.2017.
|
|
*/
|
|
public class MainFrame extends JFrame {
|
|
|
|
private Presenter presenter;
|
|
private Boolean lmsIsComplete = false;
|
|
private Boolean rmIsComplete = false;
|
|
private Boolean tsIsComplete = false;
|
|
|
|
|
|
//TODO refactoring
|
|
private JButton arrangementButton;
|
|
private JButton button3;
|
|
|
|
private OutputPanel output;
|
|
private MenuPanel menupanel;
|
|
private LMSPanel lmsPanel;
|
|
private RMPanel rmPanel;
|
|
private JPanel pane;
|
|
|
|
private ArrangementDialog arrangement;
|
|
private JDialog arrangementDialog;
|
|
private PlotDialog plotLMS;
|
|
private PlotDialog plotRM;
|
|
private PlotDialog plotTS;
|
|
|
|
|
|
|
|
private JSplitPane splitpane;
|
|
private JScrollPane scrollPane;
|
|
|
|
private JTabbedPane tabbedPane;
|
|
|
|
public MainFrame() {
|
|
initializeComponents();
|
|
setDimensions();
|
|
setLayouts();
|
|
setTitles();
|
|
|
|
addComponents();
|
|
|
|
setCloseOperations();
|
|
setActionListeners();
|
|
|
|
this.setVisible(true);
|
|
}
|
|
|
|
|
|
/*******************************************************************************************************************
|
|
* visualisierungs methoden
|
|
******************************************************************************************************************/
|
|
|
|
public void createArrangement() {
|
|
if (arrangement == null) {
|
|
arrangement = new ArrangementDialog();
|
|
arrangement.setPrameters(getPresenter().calcArrangementLines(),
|
|
getPresenter().getModel().getNodes());
|
|
arrangement.createArrangement();
|
|
SwingUtilities.invokeLater(() -> {
|
|
arrangementDialog.add(arrangement, BorderLayout.CENTER);
|
|
arrangementDialog.setVisible(true);
|
|
});
|
|
} else {
|
|
arrangementDialog.setVisible(true);
|
|
}
|
|
}
|
|
|
|
public void visualizeLMS(double m, double b) {
|
|
plotLMS = new PlotDialog();
|
|
lmsPanel.setPlotDialog(plotLMS);
|
|
createPlot(m,b,plotLMS,lmsPanel);
|
|
}
|
|
|
|
public void visualizeRM(double m, double b) {
|
|
plotRM = new PlotDialog();
|
|
rmPanel.setPlotDialog(plotRM);
|
|
createPlot(m,b,plotRM,rmPanel);
|
|
}
|
|
|
|
public void createPlot(double m, double b, PlotDialog plot, JPanel panel){
|
|
SwingUtilities.invokeLater(() -> {
|
|
plot.clear();
|
|
plot.createPlot(getPresenter().getLines());
|
|
plot.addLineToPlot(m, b);
|
|
panel.revalidate();
|
|
});
|
|
}
|
|
|
|
/*******************************************************************************************************************
|
|
* init GUI
|
|
******************************************************************************************************************/
|
|
private void setTitles() {
|
|
this.setTitle("MainFrame");
|
|
arrangementDialog.setTitle("Dual Representation - Dialog");
|
|
button3.setText("Import");
|
|
arrangementButton.setText("Dualraum");
|
|
}
|
|
|
|
private void setupTabbedPane() {
|
|
tabbedPane.add("Least Median of Squares", lmsPanel);
|
|
tabbedPane.add("Repeated Median", rmPanel);
|
|
tabbedPane.add("Theil-Sen", new JPanel());
|
|
}
|
|
|
|
private void addComponents() {
|
|
pane.add(arrangementButton);
|
|
pane.add(button3);
|
|
|
|
setupSplitPane();
|
|
setupTabbedPane();
|
|
|
|
this.add(pane, BorderLayout.SOUTH);
|
|
this.add(splitpane, BorderLayout.CENTER);
|
|
this.add(menupanel, BorderLayout.NORTH);
|
|
}
|
|
|
|
private void setupSplitPane() {
|
|
splitpane.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
|
|
splitpane.setResizeWeight(.5d);
|
|
splitpane.setContinuousLayout(true);
|
|
splitpane.setLeftComponent(output);
|
|
splitpane.setRightComponent(tabbedPane);
|
|
}
|
|
|
|
private void setCloseOperations() {
|
|
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
arrangementDialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
|
|
}
|
|
|
|
private void setDimensions() {
|
|
this.setMinimumSize(new Dimension(1900,1000));
|
|
this.setExtendedState(JFrame.MAXIMIZED_BOTH);
|
|
lmsPanel.setMinimumSize(new Dimension(400, 500));
|
|
rmPanel.setMinimumSize(new Dimension(400, 500));
|
|
arrangementDialog.setSize(new Dimension(800, 800));
|
|
output.setMinimumSize(new Dimension(400, 500));
|
|
}
|
|
|
|
|
|
private void setLayouts() {
|
|
this.setLayout(new BorderLayout());
|
|
pane.setLayout(new FlowLayout());
|
|
}
|
|
|
|
private void initializeComponents() {
|
|
//Panels
|
|
pane = new JPanel();
|
|
lmsPanel = new LMSPanel();
|
|
rmPanel = new RMPanel();
|
|
menupanel = new MenuPanel();
|
|
|
|
//Dialogs
|
|
arrangementDialog = new JDialog();
|
|
|
|
//Panes
|
|
tabbedPane = new JTabbedPane();
|
|
output = new OutputPanel();
|
|
splitpane = new JSplitPane();
|
|
|
|
//Buttons
|
|
arrangementButton = new JButton();
|
|
button3 = new JButton();
|
|
}
|
|
|
|
private void setActionListeners() {
|
|
arrangementButton.addActionListener((ActionEvent e) -> {
|
|
Thread t = new Thread(() -> getPresenter().startArrangementVisualization());
|
|
t.start();
|
|
});
|
|
|
|
lmsPanel.getStartButton().addActionListener((ActionEvent e) -> {
|
|
Thread t = new Thread(
|
|
() -> this.getPresenter().calculateLMS(lmsPanel.getInput()));
|
|
t.start();
|
|
});
|
|
|
|
rmPanel.getStartButton().addActionListener((ActionEvent e) -> {
|
|
Thread t = new Thread(
|
|
() -> this.getPresenter().calculateRM(rmPanel.getInput()));
|
|
t.start();
|
|
});
|
|
}
|
|
|
|
|
|
/*******************************************************************************************************************
|
|
* log Methode
|
|
******************************************************************************************************************/
|
|
public void log(String s) {
|
|
SwingUtilities.invokeLater(() -> output.appendParagraph(s));
|
|
}
|
|
|
|
public void logError(String s) {
|
|
SwingUtilities.invokeLater(() -> output.appendParagraphRed(s));
|
|
}
|
|
|
|
public void logSuccess(String s) {
|
|
SwingUtilities.invokeLater(() -> output.appendParagraphGreen(s));
|
|
}
|
|
|
|
public void logHeading(String s) {
|
|
SwingUtilities.invokeLater(() -> output.appendParagraphWithHeading(s));
|
|
}
|
|
|
|
public void createTable(List<String> heading, List<List<String>> rows) {
|
|
SwingUtilities.invokeLater(() -> output.logTable(heading, rows));
|
|
}
|
|
|
|
/*******************************************************************************************************************
|
|
* Getter und Setter Methoden
|
|
******************************************************************************************************************/
|
|
|
|
public Boolean getLmsIsComplete() {
|
|
return lmsIsComplete;
|
|
}
|
|
|
|
public void setLmsIsComplete(Boolean lmsIsComplete) {
|
|
this.lmsIsComplete = lmsIsComplete;
|
|
}
|
|
|
|
public Boolean getRmIsComplete() {
|
|
return rmIsComplete;
|
|
}
|
|
|
|
public void setRmIsComplete(Boolean rmIsComplete) {
|
|
this.rmIsComplete = rmIsComplete;
|
|
}
|
|
|
|
public Boolean getTsIsComplete() {
|
|
return tsIsComplete;
|
|
}
|
|
|
|
public void setTsIsComplete(Boolean tsIsComplete) {
|
|
this.tsIsComplete = tsIsComplete;
|
|
}
|
|
|
|
public JButton getArrangementButton() {
|
|
return arrangementButton;
|
|
}
|
|
|
|
public void setArrangementButton(JButton arrangementButton) {
|
|
this.arrangementButton = arrangementButton;
|
|
}
|
|
|
|
public JButton getButton3() {
|
|
return button3;
|
|
}
|
|
|
|
public void setButton3(JButton button3) {
|
|
this.button3 = button3;
|
|
}
|
|
|
|
public JPanel getPane() {
|
|
return pane;
|
|
}
|
|
|
|
public void setPane(JPanel pane) {
|
|
this.pane = pane;
|
|
}
|
|
|
|
public JDialog getArrangementDialog() {
|
|
return arrangementDialog;
|
|
}
|
|
|
|
public void setArrangementDialog(JDialog arrangementDialog) {
|
|
this.arrangementDialog = arrangementDialog;
|
|
}
|
|
|
|
public OutputPanel getOutput() {
|
|
return output;
|
|
}
|
|
|
|
public void setOutput(OutputPanel output) {
|
|
this.output = output;
|
|
}
|
|
|
|
public JPanel getMenupanel() {
|
|
return menupanel;
|
|
}
|
|
|
|
public JPanel getLmsPanel() {
|
|
return lmsPanel;
|
|
}
|
|
|
|
public JSplitPane getSplitpane() {
|
|
return splitpane;
|
|
}
|
|
|
|
public void setSplitpane(JSplitPane splitpane) {
|
|
this.splitpane = splitpane;
|
|
}
|
|
|
|
public JScrollPane getScrollPane() {
|
|
return scrollPane;
|
|
}
|
|
|
|
public void setScrollPane(JScrollPane scrollPane) {
|
|
this.scrollPane = scrollPane;
|
|
}
|
|
|
|
|
|
public PlotDialog getPlotLMS() {
|
|
return plotLMS;
|
|
}
|
|
|
|
public void setPlotLMS(PlotDialog plotLMS) {
|
|
this.plotLMS = plotLMS;
|
|
}
|
|
|
|
public Presenter getPresenter() {
|
|
return presenter;
|
|
}
|
|
|
|
public void setPresenter(Presenter presenter) {
|
|
this.presenter = presenter;
|
|
}
|
|
}
|