erste schritte in richtung visualisierung... :D
This commit is contained in:
parent
8e8bd52fd1
commit
1bc660a3be
20
pom.xml
20
pom.xml
|
@ -7,6 +7,26 @@
|
||||||
<groupId>wwu</groupId>
|
<groupId>wwu</groupId>
|
||||||
<artifactId>masterarbeit</artifactId>
|
<artifactId>masterarbeit</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<source>1.8</source>
|
||||||
|
<target>1.8</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- https://mvnrepository.com/artifact/org.jfree/jfreechart -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jfree</groupId>
|
||||||
|
<artifactId>jfreechart</artifactId>
|
||||||
|
<version>1.0.14</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
</project>
|
</project>
|
|
@ -0,0 +1,27 @@
|
||||||
|
import Model.Arrangement;
|
||||||
|
import Presenter.Presenter;
|
||||||
|
import View.MainFrame;
|
||||||
|
import View.View;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
|
||||||
|
*
|
||||||
|
* @Author: Armin Wolf
|
||||||
|
* @Email: a_wolf28@uni-muenster.de
|
||||||
|
* @Date: 28.05.2017.
|
||||||
|
*/
|
||||||
|
public class App {
|
||||||
|
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
View view = new MainFrame();
|
||||||
|
view.setPresenter(new Presenter(new Arrangement(), view));
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,61 @@
|
||||||
|
package Model;
|
||||||
|
|
||||||
|
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 class Arrangement {
|
||||||
|
|
||||||
|
private LinkedList<Pair> nodes;
|
||||||
|
private LinkedList<Pair> lines;
|
||||||
|
|
||||||
|
public Arrangement(){
|
||||||
|
nodes = new LinkedList<>();
|
||||||
|
lines = new LinkedList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addNode(Pair node){
|
||||||
|
this.nodes.add(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeNode(int index){
|
||||||
|
this.nodes.remove(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeNode(Pair node){
|
||||||
|
this.nodes.remove(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addLine(Pair line){
|
||||||
|
this.lines.add(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeLine(int index){
|
||||||
|
this.lines.remove(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeLine(Pair line){
|
||||||
|
this.lines.remove(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LinkedList<Pair> getNodes() {
|
||||||
|
return nodes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNodes(LinkedList<Pair> nodes) {
|
||||||
|
this.nodes = nodes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LinkedList<Pair> getLines() {
|
||||||
|
return lines;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLines(LinkedList<Pair> lines) {
|
||||||
|
this.lines = lines;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,50 @@
|
||||||
|
package Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
|
||||||
|
*
|
||||||
|
* @Author: Armin Wolf
|
||||||
|
* @Email: a_wolf28@uni-muenster.de
|
||||||
|
* @Date: 28.05.2017.
|
||||||
|
*/
|
||||||
|
public class Pair implements Comparable<Pair> {
|
||||||
|
|
||||||
|
private Double x;
|
||||||
|
private Double y;
|
||||||
|
|
||||||
|
public Pair(Double x, Double y) {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getX() {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setX(Double x) {
|
||||||
|
this.x = x;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getY() {
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setY(Double y) {
|
||||||
|
this.y = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(Pair o) {
|
||||||
|
if(this.getX() == o.getX()){
|
||||||
|
if (this.getY() <= o.getY()){
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
} else if (this.getX() < o.getX()){
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,27 +0,0 @@
|
||||||
package Presenter;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
|
|
||||||
*
|
|
||||||
* @Author: Armin Wolf
|
|
||||||
* @Email: a_wolf28@uni-muenster.de
|
|
||||||
* @Date: 28.05.2017.
|
|
||||||
*/
|
|
||||||
public class Coordinator implements Presenter {
|
|
||||||
|
|
||||||
public void getDataFromModel() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDataByModel() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void getActionsFromView() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setActionByView() {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,5 +1,14 @@
|
||||||
package Presenter;
|
package Presenter;
|
||||||
|
|
||||||
|
import Model.Arrangement;
|
||||||
|
import Model.Pair;
|
||||||
|
import View.*;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
|
* Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
|
||||||
*
|
*
|
||||||
|
@ -7,14 +16,97 @@ package Presenter;
|
||||||
* @Email: a_wolf28@uni-muenster.de
|
* @Email: a_wolf28@uni-muenster.de
|
||||||
* @Date: 28.05.2017.
|
* @Date: 28.05.2017.
|
||||||
*/
|
*/
|
||||||
public interface Presenter {
|
public class Presenter {
|
||||||
|
|
||||||
public void getDataFromModel();
|
private Arrangement model;
|
||||||
|
private View view;
|
||||||
|
|
||||||
public void setDataByModel();
|
|
||||||
|
|
||||||
public void getActionsFromView();
|
private LinkedList<Pair> lines;
|
||||||
|
private Double max;
|
||||||
|
private Double min;
|
||||||
|
|
||||||
public void setActionByView();
|
public Presenter(Arrangement model, View view){
|
||||||
|
this.model = model;
|
||||||
|
this.view = view;
|
||||||
|
this.lines = new LinkedList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getDataFromModel() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDataByModel() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getActionsFromView() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setActionByView() {
|
||||||
|
Double[] x = {1d,2d,3d,4d,10d,12d,18d};
|
||||||
|
Double[] y = {9d,15d,19d,20d,45d,55d,78d};
|
||||||
|
// Float[] x = {18f,24f,30f,34f,38f};
|
||||||
|
// Float[] y = {18f,26f,30f,40f,70f};
|
||||||
|
// Double[] x = {1d,3d,4d,5d,8d};
|
||||||
|
// Double[] y = {4d,2d,1d,0d,0d};
|
||||||
|
|
||||||
|
|
||||||
|
for (int j=0;j<7;j++){
|
||||||
|
Pair p = new Pair(x[j], y[j]);
|
||||||
|
lines.add(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
extractBounds();
|
||||||
|
view.createArrangement();
|
||||||
|
}
|
||||||
|
private void extractBounds(){
|
||||||
|
Pair pmax = Collections.max(lines);
|
||||||
|
Pair pmin = Collections.min(lines);
|
||||||
|
|
||||||
|
max = pmax.getX() >= pmax.getY() ? pmax.getX() : pmax.getY();
|
||||||
|
min = pmin.getX() <= pmin.getY() ? pmin.getX() : pmin.getY();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Arrangement getModel() {
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setModel(Arrangement model) {
|
||||||
|
this.model = model;
|
||||||
|
}
|
||||||
|
|
||||||
|
public View getView() {
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setView(View view) {
|
||||||
|
this.view = view;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LinkedList<Pair> getLines() {
|
||||||
|
return lines;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLines(LinkedList<Pair> lines) {
|
||||||
|
this.lines = lines;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getMax() {
|
||||||
|
return max;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMax(Double max) {
|
||||||
|
this.max = max;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getMin() {
|
||||||
|
return min;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMin(Double min) {
|
||||||
|
this.min = min;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
package View;
|
||||||
|
|
||||||
|
import Model.Pair;
|
||||||
|
import org.jfree.chart.ChartFactory;
|
||||||
|
import org.jfree.chart.ChartPanel;
|
||||||
|
import org.jfree.chart.JFreeChart;
|
||||||
|
import org.jfree.chart.plot.PlotOrientation;
|
||||||
|
import org.jfree.data.xy.XYSeries;
|
||||||
|
import org.jfree.data.xy.XYSeriesCollection;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
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 class ArrangementDialog extends JPanel {
|
||||||
|
|
||||||
|
private LinkedList<Pair> lines;
|
||||||
|
private double max;
|
||||||
|
private double min;
|
||||||
|
private JFreeChart chart;
|
||||||
|
private ChartPanel panel;
|
||||||
|
|
||||||
|
public ArrangementDialog(){
|
||||||
|
super();
|
||||||
|
this.setPreferredSize(new Dimension(800,500));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrameters(Double pmax, Double pmin, LinkedList<Pair> lines){
|
||||||
|
this.max = pmax;
|
||||||
|
this.min = pmin;
|
||||||
|
this.lines = lines;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void createArrangement(){
|
||||||
|
XYSeriesCollection dataset = new XYSeriesCollection();
|
||||||
|
|
||||||
|
for (Pair p : lines) {
|
||||||
|
XYSeries series = new XYSeries(p.getX()+p.getY());
|
||||||
|
series.add((-1 * this.max), ((-1 * this.max) * p.getX() + p.getY()));
|
||||||
|
series.add(this.max, (this.max * p.getX() + p.getY()));
|
||||||
|
dataset.addSeries(series);
|
||||||
|
}
|
||||||
|
|
||||||
|
chart = ChartFactory.createXYLineChart(
|
||||||
|
null, null, null, dataset,
|
||||||
|
PlotOrientation.HORIZONTAL, false, false, false );
|
||||||
|
chart.getPlot().setBackgroundPaint(Color.WHITE);
|
||||||
|
panel = new ChartPanel(chart);
|
||||||
|
this.add(panel);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,84 @@
|
||||||
|
package View;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
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 class MainFrame<T> extends View {
|
||||||
|
|
||||||
|
//TODO refactoring
|
||||||
|
private JButton button1;
|
||||||
|
private JButton button2;
|
||||||
|
private JButton button3;
|
||||||
|
private JDialog dialog;
|
||||||
|
private ArrangementDialog arrangement;
|
||||||
|
|
||||||
|
public MainFrame(){
|
||||||
|
initGUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected void initGUI(){
|
||||||
|
this.setTitle("MainFrame");
|
||||||
|
this.setSize(800,800);
|
||||||
|
this.setLayout(new FlowLayout());
|
||||||
|
dialog = new JDialog();
|
||||||
|
dialog.setSize(new Dimension(700,470));
|
||||||
|
dialog.setTitle("Arrangement Dialog");
|
||||||
|
dialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
|
||||||
|
button1 = new JButton("Button 1");
|
||||||
|
button2 = new JButton("Button 2");
|
||||||
|
button3 = new JButton("Button 3");
|
||||||
|
|
||||||
|
button1.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
getPresenter().setActionByView();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.add(button1);
|
||||||
|
this.add(button2);
|
||||||
|
this.add(button3);
|
||||||
|
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() {
|
||||||
|
dialog.add(arrangement);
|
||||||
|
dialog.setVisible(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
dialog.setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void createLine() {
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void createPlot() {
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package View;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
|
||||||
|
*
|
||||||
|
* @Author: Armin Wolf
|
||||||
|
* @Email: a_wolf28@uni-muenster.de
|
||||||
|
* @Date: 29.05.2017.
|
||||||
|
*/
|
||||||
|
public class PlotDialog {
|
||||||
|
}
|
|
@ -1,5 +1,11 @@
|
||||||
package View;
|
package View;
|
||||||
|
|
||||||
|
import Model.Pair;
|
||||||
|
import Presenter.Presenter;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
|
* Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
|
||||||
*
|
*
|
||||||
|
@ -7,5 +13,24 @@ package View;
|
||||||
* @Email: a_wolf28@uni-muenster.de
|
* @Email: a_wolf28@uni-muenster.de
|
||||||
* @Date: 28.05.2017.
|
* @Date: 28.05.2017.
|
||||||
*/
|
*/
|
||||||
public interface View {
|
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();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue