gui parameter übermitteln an Algorithmus

This commit is contained in:
Armin Wolf 2017-06-16 18:06:28 +02:00
parent 72e7348b42
commit 962960c509
3 changed files with 162 additions and 118 deletions

View File

@ -34,35 +34,42 @@ public class MainFrame extends JFrame{
//TODO refactoring
private JButton arrangementButton;
private JButton plotButton;
private JButton button3;
private OutputPanel output;
private MenuPanel menupanel;
private SidePanel sidepanel;
private JPanel pane;
private ArrangementDialog arrangement;
private JDialog arrangementDialog;
private JDialog plotDialog;
private OutputPanel output;
private JPanel menupanel;
private JPanel sidepanel;
private JSplitPane splitpane;
private JScrollPane scrollPane;
private ArrangementDialog arrangement;
private JTabbedPane tabbedPane;
private PlotDialog plot;
private JSplitPane splitpane;
private JScrollPane scrollPane;
private JTabbedPane tabbedPane;
public MainFrame() {
initGUI();
initializeComponents();
setDimensions();
setLayouts();
setTitles();
addComponents();
setCloseOperations();
setActionListeners();
this.setVisible(true);
}
public Presenter getPresenter() {
return presenter;
}
public void setPresenter(Presenter presenter) {
this.presenter = presenter;
}
/**
* visualisierungs methoden
*/
/*******************************************************************************************************************
* visualisierungs methoden
******************************************************************************************************************/
public void createArrangement() {
if (arrangement == null) {
@ -78,90 +85,112 @@ public class MainFrame extends JFrame{
}
}
public void createPlot(double m, double b) {
plot = new PlotDialog();
SwingUtilities.invokeLater(() -> {
plot.createPlot(getPresenter().getLines());
plot.addLineToPlot(m, b);
plotDialog.add(plot);
plotDialog.setVisible(true);
});
plot = new PlotDialog();
SwingUtilities.invokeLater(() -> {
plot.createPlot(getPresenter().getLines());
plot.addLineToPlot(m, b);
plotDialog.add(plot);
plotDialog.setVisible(true);
});
}
/******************************************************************************************************************/
/**
* init GUI
*/
protected void initGUI() {
/*******************************************************************************************************************
* init GUI
******************************************************************************************************************/
private void setTitles(){
this.setTitle("MainFrame");
this.setSize(1900, 1000);
this.setLayout(new BorderLayout());
pane = new JPanel();
sidepanel = new SidePanel();
sidepanel.setMinimumSize(new Dimension(400,500));
pane.setLayout(new FlowLayout());
menupanel = new MenuPanel();
tabbedPane = new JTabbedPane();
arrangementDialog = new JDialog();
plotDialog = new JDialog();
arrangementDialog.setSize(new Dimension(800, 800));
plotDialog.setSize(new Dimension(700, 470));
arrangementDialog.setTitle("Dual Representation - Dialog");
plotDialog.setTitle("Scatter Plot - Dialog");
arrangementDialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
plotDialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
button3.setText("Import");
arrangementButton.setText("Dualraum");
}
output = new OutputPanel();
splitpane = new JSplitPane();
output.setMinimumSize(new Dimension(400,500));
arrangementButton = new JButton("Arrangement");
plotButton = new JButton("Plot");
button3 = new JButton("Import");
arrangementButton.addActionListener((ActionEvent e) -> {
Thread t = new Thread(() -> getPresenter().startArrangementVisualization());
t.start();
});
plotButton.addActionListener((ActionEvent e) -> {
plotButton.setEnabled(false);
Thread t = new Thread(() -> getPresenter().startScatterPlotVisualization());
t.start();
});
pane.add(arrangementButton);
pane.add(plotButton);
pane.add(button3);
private void setupTabbedPane(){
tabbedPane.add("LMS", sidepanel);
tabbedPane.add("RM", new JPanel());
tabbedPane.add("TS", 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);
this.add(pane, BorderLayout.SOUTH);
this.add(splitpane, BorderLayout.CENTER);
this.add(menupanel, BorderLayout.NORTH);
}
private void setCloseOperations(){
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
arrangementDialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
plotDialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
}
private void setDimensions(){
this.setSize(1900, 1000);
sidepanel.setMinimumSize(new Dimension(400,500));
arrangementDialog.setSize(new Dimension(800, 800));
plotDialog.setSize(new Dimension(700, 470));
output.setMinimumSize(new Dimension(400,500));
}
private void setLayouts(){
this.setLayout(new BorderLayout());
pane.setLayout(new FlowLayout());
}
private void initializeComponents(){
//Panels
pane = new JPanel();
sidepanel = new SidePanel();
menupanel = new MenuPanel();
//Dialogs
arrangementDialog = new JDialog();
plotDialog = 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();
});
/******************************************************************************************************************/
/**
* log Methode
*/
sidepanel.getStartButton().addActionListener((ActionEvent e) -> {
Thread t = new Thread(() -> this.getPresenter().startScatterPlotVisualization(sidepanel.getInput()));
t.start();
});
}
/*******************************************************************************************************************
* log Methode
******************************************************************************************************************/
public void log(String s) {
SwingUtilities.invokeLater(() -> output.appendParagraph(s));
@ -182,11 +211,9 @@ public class MainFrame extends JFrame{
public void createTable(List<String> heading, List<List<String>> rows){
SwingUtilities.invokeLater(() -> output.logTable(heading, rows));
}
/******************************************************************************************************************/
/**
* Getter und Setter Methoden!
*/
/*******************************************************************************************************************
* Getter und Setter Methoden
******************************************************************************************************************/
public Boolean getLmsIsComplete() {
return lmsIsComplete;
@ -220,14 +247,6 @@ public class MainFrame extends JFrame{
this.arrangementButton = arrangementButton;
}
public JButton getPlotButton() {
return plotButton;
}
public void setPlotButton(JButton plotButton) {
this.plotButton = plotButton;
}
public JButton getButton3() {
return button3;
}
@ -272,18 +291,10 @@ public class MainFrame extends JFrame{
return menupanel;
}
public void setMenupanel(JPanel menupanel) {
this.menupanel = menupanel;
}
public JPanel getSidepanel() {
return sidepanel;
}
public void setSidepanel(JPanel sidepanel) {
this.sidepanel = sidepanel;
}
public JSplitPane getSplitpane() {
return splitpane;
}
@ -308,4 +319,12 @@ public class MainFrame extends JFrame{
public void setPlot(PlotDialog plot) {
this.plot = plot;
}
public Presenter getPresenter() {
return presenter;
}
public void setPresenter(Presenter presenter) {
this.presenter = presenter;
}
}

View File

@ -41,6 +41,7 @@ public class PlotDialog extends JPanel {
this.setPreferredSize(new Dimension(800, 500));
this.setMinimumSize(new Dimension(800, 500));
this.setLayout(new BorderLayout());
}
public void createPlot(LinkedList<Line> points) {
@ -95,8 +96,8 @@ public class PlotDialog extends JPanel {
public void addLineToPlot(double m, double b) {
linesA = new XYSeries("linesA");
JOptionPane.showMessageDialog(null, "m: "+m+" b: "+b);
linesA.add(min.intValue(), min.intValue() * (-1) * m + b );
linesA.add(max.intValue(), max.intValue() * (-1) * m + b );
linesA.add(min.intValue(), min.intValue() * m + b );
linesA.add(max.intValue(), max.intValue() * m + b );
datapoints.addSeries(linesA);
}

View File

@ -1,8 +1,6 @@
package View;
import javax.swing.*;
import javax.swing.border.LineBorder;
import javax.swing.border.MatteBorder;
import javax.swing.border.TitledBorder;
import java.awt.*;
@ -17,15 +15,15 @@ public class SidePanel extends JPanel {
private JLabel[] labels;
private JTextField[] text;
private JTextField[] input;
private JButton startButton;
private JPanel continer;
private GridBagConstraints gbc;
public SidePanel(){
this.setBorder(new TitledBorder("Eingabefelder"));
this.labels = new JLabel[10];
this.text = new JTextField[10];
this.input = new JTextField[10];
this.setLayout(new BorderLayout());
this.continer = new JPanel();
continer.setLayout(new GridBagLayout());;
@ -33,19 +31,19 @@ public class SidePanel extends JPanel {
gbc.anchor = GridBagConstraints.NORTH;
gbc.fill = GridBagConstraints.HORIZONTAL;
addTextfieldAndInput(0, "Konstante", 1.0);
addTextfieldAndInput(1, "Fehler", 0.005);
addElement(0, "Konstante");
addElement(1, "Fehler");
addElement(2,"Quantile");
startButton = new JButton("start");
addButton(2, startButton);
this.add(continer, BorderLayout.NORTH);
}
private void addElement(int row, String name){
private void addTextfieldAndInput(int row, String name, Double value){
this.labels[row] = new JLabel(name);
this.text[row] = new JTextField();
this.input[row] = new JTextField();
this.input[row].setText(""+value);
gbc.insets = new Insets(0, 5,0,0);
gbc.gridx = 0;
@ -59,6 +57,32 @@ public class SidePanel extends JPanel {
gbc.weightx = 0.9;
gbc.weighty = 0.05;
gbc.insets = new Insets(0, 0,0,5);
continer.add(this.text[row], gbc);
continer.add(this.input[row], gbc);
}
private void addButton(int row, JButton button){
gbc.insets = new Insets(30, 5,0,0);
gbc.gridx = 0;
gbc.gridy = row;
gbc.weightx = 0.05;
gbc.weighty = 0.05;
continer.add(button, gbc);
}
public JButton getStartButton() {
return startButton;
}
public String[] getInput() {
String[] input = new String[3];
input[0] = this.input[0].getText();
input[1] = this.input[1].getText();
return input;
}
public void setInput(JTextField[] input) {
this.input = input;
}
}