refactoring, log eingefügt, menupanel

This commit is contained in:
Armin Wolf 2017-05-29 17:08:58 +02:00
parent 4e821a6c8f
commit 7e02f156a1
6 changed files with 140 additions and 88 deletions

View File

@ -1,7 +1,6 @@
import Model.Arrangement;
import Presenter.Presenter;
import View.MainFrame;
import View.View;
import javax.swing.*;
@ -18,7 +17,7 @@ public class App {
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
View view = new MainFrame();
MainFrame view = new MainFrame();
view.setPresenter(new Presenter(new Arrangement(), view));
});

View File

@ -19,14 +19,14 @@ import java.util.LinkedList;
public class Presenter {
private Arrangement model;
private View view;
private MainFrame view;
private LinkedList<Pair> lines;
private Double max;
private Double min;
public Presenter(Arrangement model, View view){
public Presenter(Arrangement model, MainFrame view){
this.model = model;
this.view = view;
this.lines = new LinkedList<>();
@ -37,10 +37,13 @@ public class Presenter {
// Float[] y = {18f,26f,30f,40f,70f};
// Double[] x = {1d,3d,4d,5d,8d};
// Double[] y = {4d,2d,1d,0d,0d};
view.log("Koordinaten der Punkte:");
for (int j=0;j<7;j++){
Pair p = new Pair(x[j], y[j]);
view.log("f(x) = "+p.getX()+"* x + "+p.getY());
lines.add(p);
}
view.log("");
extractBounds();
}
@ -85,11 +88,11 @@ public class Presenter {
this.model = model;
}
public View getView() {
public MainFrame getView() {
return view;
}
public void setView(View view) {
public void setView(MainFrame view) {
this.view = view;
}

View File

@ -1,6 +1,8 @@
package View;
import Presenter.Presenter;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
@ -13,7 +15,9 @@ import java.awt.event.ActionListener;
* @Email: a_wolf28@uni-muenster.de
* @Date: 28.05.2017.
*/
public class MainFrame<T> extends View {
public class MainFrame extends JFrame {
private Presenter presenter;
//TODO refactoring
private JButton arrangementButton;
@ -22,6 +26,9 @@ public class MainFrame<T> extends View {
private JPanel pane;
private JDialog arrangementDialog;
private JDialog plotDialog;
private JTextArea output;
private JPanel menupanel;
private JScrollPane scrollPane;
private ArrangementDialog arrangement;
private PlotDialog plot;
@ -29,13 +36,81 @@ public class MainFrame<T> extends View {
initGUI();
}
public Presenter getPresenter() {
return presenter;
}
public void setPresenter(Presenter presenter) {
this.presenter = presenter;
}
/**
* visualisierungs methoden
*/
public void createArrangement() {
if (arrangement == null){
arrangement = new ArrangementDialog();
arrangement.setPrameters(getPresenter().getMax(), getPresenter().getMin(), getPresenter().getLines());
arrangement.createArrangement();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
arrangementDialog.add(arrangement);
arrangementDialog.setVisible(true);
}
});
} else {
arrangementDialog.setVisible(true);
}
}
public void createLine() {
//TODO
}
public void createPlot() {
if (plot == null){
plot = new PlotDialog();
plot.createPlot(getPresenter().getLines());
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
plotDialog.add(plot);
plotDialog.setVisible(true);
}
});
} else {
plotDialog.setVisible(true);
}
}
/**
* log Methode
*/
public void log(String s){
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
output.append(s + "\n");
}
});
}
/**
* init GUI
*/
protected void initGUI(){
this.setTitle("MainFrame");
this.setSize(800,800);
this.setSize(500,400);
this.setLayout(new BorderLayout());
pane = new JPanel();
pane.setLayout(new FlowLayout());
menupanel = new MenuPanel();
arrangementDialog = new JDialog();
plotDialog = new JDialog();
arrangementDialog.setSize(new Dimension(700,470));
@ -44,6 +119,15 @@ public class MainFrame<T> extends View {
plotDialog.setTitle("Scatter Plot Dialog");
arrangementDialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
plotDialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
output = new JTextArea();
output.setEditable(false);
output.setLineWrap(true);
output.setWrapStyleWord(true);
scrollPane = new JScrollPane(output);
scrollPane.setWheelScrollingEnabled(true);
arrangementButton = new JButton("Arrangement");
plotButton = new JButton("Plot");
button3 = new JButton("Import");
@ -62,51 +146,22 @@ public class MainFrame<T> extends View {
}
});
button3.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
log("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. \n" +
"\n" +
"Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet,");
}
});
pane.add(arrangementButton);
pane.add(plotButton);
pane.add(button3);
this.add(pane, BorderLayout.WEST);
this.add(menupanel, BorderLayout.NORTH);
this.add(pane, BorderLayout.SOUTH);
this.add(scrollPane, BorderLayout.CENTER);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
@Override
public void createArrangement() {
if (arrangement == null){
arrangement = new ArrangementDialog();
arrangement.setPrameters(getPresenter().getMax(), getPresenter().getMin(), getPresenter().getLines());
arrangement.createArrangement();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
arrangementDialog.add(arrangement);
arrangementDialog.setVisible(true);
}
});
} else {
arrangementDialog.setVisible(true);
}
}
@Override
public void createLine() {
//TODO
}
@Override
public void createPlot() {
if (plot == null){
plot = new PlotDialog();
plot.createPlot(getPresenter().getLines());
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
plotDialog.add(plot);
plotDialog.setVisible(true);
}
});
} else {
plotDialog.setVisible(true);
}
}
}

View File

@ -0,0 +1,33 @@
package View;
import org.jfree.ui.action.ActionMenuItem;
import javax.swing.*;
import java.awt.*;
/**
* Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
*
* @Author: Armin Wolf
* @Email: a_wolf28@uni-muenster.de
* @Date: 29.05.2017.
*/
public class MenuPanel extends JPanel{
private JMenuBar menuBar;
private JMenu menu;
private JMenuItem item;
public MenuPanel(){
this.setLayout(new BorderLayout());
this.menuBar = new JMenuBar();
this.menu = new JMenu("File");
this.item = new JMenuItem("Exit");
menu.add(item);
menuBar.add(menu);
this.add(menuBar, BorderLayout.WEST);
this.add(new JSeparator(SwingConstants.HORIZONTAL), BorderLayout.SOUTH);
}
}

View File

@ -39,9 +39,7 @@ public class PlotDialog extends JPanel {
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
System.out.println("start");
convertData(points);
convertData(points);
}
});
thread.start();

View File

@ -1,36 +0,0 @@
package View;
import Model.Pair;
import Presenter.Presenter;
import javax.swing.*;
import java.util.LinkedList;
/**
* Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
*
* @Author: Armin Wolf
* @Email: a_wolf28@uni-muenster.de
* @Date: 28.05.2017.
*/
public abstract class View<T> extends JFrame {
private Presenter presenter;
public View(){
}
public Presenter getPresenter() {
return presenter;
}
public void setPresenter(Presenter presenter) {
this.presenter = presenter;
}
public abstract void createArrangement();
public abstract void createLine();
public abstract void createPlot();
}