plot hinzugefügt
This commit is contained in:
parent
1bc660a3be
commit
4e821a6c8f
|
@ -30,6 +30,18 @@ public class Presenter {
|
||||||
this.model = model;
|
this.model = model;
|
||||||
this.view = view;
|
this.view = view;
|
||||||
this.lines = new LinkedList<>();
|
this.lines = new LinkedList<>();
|
||||||
|
|
||||||
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getDataFromModel() {
|
public void getDataFromModel() {
|
||||||
|
@ -44,23 +56,14 @@ public class Presenter {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setActionByView() {
|
public void startArrangementVisualization() {
|
||||||
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();
|
view.createArrangement();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void startScatterPlotVisualization(){
|
||||||
|
view.createPlot();
|
||||||
|
}
|
||||||
|
|
||||||
private void extractBounds(){
|
private void extractBounds(){
|
||||||
Pair pmax = Collections.max(lines);
|
Pair pmax = Collections.max(lines);
|
||||||
Pair pmin = Collections.min(lines);
|
Pair pmin = Collections.min(lines);
|
||||||
|
@ -69,6 +72,10 @@ public class Presenter {
|
||||||
min = pmin.getX() <= pmin.getY() ? pmin.getX() : pmin.getY();
|
min = pmin.getX() <= pmin.getY() ? pmin.getX() : pmin.getY();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/***************************************************************************************************************************
|
||||||
|
* Getter und Setter Methoden
|
||||||
|
***************************************************************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
public Arrangement getModel() {
|
public Arrangement getModel() {
|
||||||
return model;
|
return model;
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
package View;
|
package View;
|
||||||
|
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.util.LinkedList;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
|
* Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
|
||||||
|
@ -16,11 +16,14 @@ import java.util.LinkedList;
|
||||||
public class MainFrame<T> extends View {
|
public class MainFrame<T> extends View {
|
||||||
|
|
||||||
//TODO refactoring
|
//TODO refactoring
|
||||||
private JButton button1;
|
private JButton arrangementButton;
|
||||||
private JButton button2;
|
private JButton plotButton;
|
||||||
private JButton button3;
|
private JButton button3;
|
||||||
private JDialog dialog;
|
private JPanel pane;
|
||||||
|
private JDialog arrangementDialog;
|
||||||
|
private JDialog plotDialog;
|
||||||
private ArrangementDialog arrangement;
|
private ArrangementDialog arrangement;
|
||||||
|
private PlotDialog plot;
|
||||||
|
|
||||||
public MainFrame(){
|
public MainFrame(){
|
||||||
initGUI();
|
initGUI();
|
||||||
|
@ -30,24 +33,39 @@ public class MainFrame<T> extends View {
|
||||||
protected void initGUI(){
|
protected void initGUI(){
|
||||||
this.setTitle("MainFrame");
|
this.setTitle("MainFrame");
|
||||||
this.setSize(800,800);
|
this.setSize(800,800);
|
||||||
this.setLayout(new FlowLayout());
|
this.setLayout(new BorderLayout());
|
||||||
dialog = new JDialog();
|
pane = new JPanel();
|
||||||
dialog.setSize(new Dimension(700,470));
|
pane.setLayout(new FlowLayout());
|
||||||
dialog.setTitle("Arrangement Dialog");
|
arrangementDialog = new JDialog();
|
||||||
dialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
|
plotDialog = new JDialog();
|
||||||
button1 = new JButton("Button 1");
|
arrangementDialog.setSize(new Dimension(700,470));
|
||||||
button2 = new JButton("Button 2");
|
plotDialog.setSize(new Dimension(700,470));
|
||||||
button3 = new JButton("Button 3");
|
arrangementDialog.setTitle("Arrangement Dialog");
|
||||||
|
plotDialog.setTitle("Scatter Plot Dialog");
|
||||||
|
arrangementDialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
|
||||||
|
plotDialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
|
||||||
|
arrangementButton = new JButton("Arrangement");
|
||||||
|
plotButton = new JButton("Plot");
|
||||||
|
button3 = new JButton("Import");
|
||||||
|
|
||||||
button1.addActionListener(new ActionListener() {
|
arrangementButton.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
getPresenter().setActionByView();
|
getPresenter().startArrangementVisualization();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.add(button1);
|
|
||||||
this.add(button2);
|
plotButton.addActionListener(new ActionListener() {
|
||||||
this.add(button3);
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
getPresenter().startScatterPlotVisualization();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
pane.add(arrangementButton);
|
||||||
|
pane.add(plotButton);
|
||||||
|
pane.add(button3);
|
||||||
|
this.add(pane, BorderLayout.WEST);
|
||||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
this.setVisible(true);
|
this.setVisible(true);
|
||||||
}
|
}
|
||||||
|
@ -61,15 +79,13 @@ public class MainFrame<T> extends View {
|
||||||
SwingUtilities.invokeLater(new Runnable() {
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
dialog.add(arrangement);
|
arrangementDialog.add(arrangement);
|
||||||
dialog.setVisible(true);
|
arrangementDialog.setVisible(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
dialog.setVisible(true);
|
arrangementDialog.setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -79,6 +95,18 @@ public class MainFrame<T> extends View {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createPlot() {
|
public void createPlot() {
|
||||||
//TODO
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,20 @@
|
||||||
package View;
|
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.chart.plot.XYPlot;
|
||||||
|
import org.jfree.chart.renderer.xy.XYItemRenderer;
|
||||||
|
import org.jfree.data.xy.XYSeries;
|
||||||
|
import org.jfree.data.xy.XYSeriesCollection;
|
||||||
|
import org.jfree.util.ShapeUtilities;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
|
* Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
|
||||||
*
|
*
|
||||||
|
@ -7,5 +22,72 @@ package View;
|
||||||
* @Email: a_wolf28@uni-muenster.de
|
* @Email: a_wolf28@uni-muenster.de
|
||||||
* @Date: 29.05.2017.
|
* @Date: 29.05.2017.
|
||||||
*/
|
*/
|
||||||
public class PlotDialog {
|
public class PlotDialog extends JPanel {
|
||||||
|
|
||||||
|
private JFreeChart chart;
|
||||||
|
private ChartPanel panel;
|
||||||
|
private XYSeriesCollection datapoints;
|
||||||
|
private XYSeries series;
|
||||||
|
|
||||||
|
public PlotDialog() {
|
||||||
|
super();
|
||||||
|
this.setPreferredSize(new Dimension(800, 500));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void createPlot(LinkedList<Pair> points) {
|
||||||
|
|
||||||
|
Thread thread = new Thread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
System.out.println("start");
|
||||||
|
|
||||||
|
convertData(points);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
thread.start();
|
||||||
|
try {
|
||||||
|
thread.join();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
chart = ChartFactory.createScatterPlot("",
|
||||||
|
"X", "Y", datapoints, PlotOrientation.VERTICAL, false, true, false);
|
||||||
|
Shape diamond = ShapeUtilities.createDiamond(2f);
|
||||||
|
chart.setBorderVisible(false);
|
||||||
|
chart.setAntiAlias(true);
|
||||||
|
chart.getPlot().setBackgroundPaint(Color.WHITE);
|
||||||
|
|
||||||
|
XYPlot xyPlot = (XYPlot) chart.getPlot();
|
||||||
|
xyPlot.setDomainCrosshairVisible(true);
|
||||||
|
xyPlot.setRangeCrosshairVisible(true);
|
||||||
|
|
||||||
|
XYItemRenderer renderer = xyPlot.getRenderer();
|
||||||
|
renderer.setSeriesPaint(0, Color.blue);
|
||||||
|
renderer.setSeriesShape(0, diamond);
|
||||||
|
|
||||||
|
xyPlot.setDomainCrosshairVisible(true);
|
||||||
|
xyPlot.setRangeCrosshairVisible(true);
|
||||||
|
|
||||||
|
panel = new ChartPanel(chart);
|
||||||
|
this.add(panel);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addLineToPlot() {
|
||||||
|
//TODO Line Estimator
|
||||||
|
}
|
||||||
|
|
||||||
|
private void convertData(LinkedList<Pair> points) {
|
||||||
|
|
||||||
|
datapoints = new XYSeriesCollection();
|
||||||
|
series = new XYSeries("");
|
||||||
|
for (Pair p : points) {
|
||||||
|
series.add(p.getX(), p.getY());
|
||||||
|
}
|
||||||
|
|
||||||
|
datapoints.addSeries(series);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue