dialog für die dualen geraden ist soweit fertig.
This commit is contained in:
parent
dfcc6a15cb
commit
f3df50d86d
|
@ -28,8 +28,6 @@ public class Presenter {
|
||||||
public Presenter(Arrangement model, MainFrame view) {
|
public Presenter(Arrangement model, MainFrame view) {
|
||||||
this.model = model;
|
this.model = model;
|
||||||
this.view = view;
|
this.view = view;
|
||||||
|
|
||||||
|
|
||||||
Double[] x = {1d, 2d, 3d, 4d, 10d, 12d, 18d};
|
Double[] x = {1d, 2d, 3d, 4d, 10d, 12d, 18d};
|
||||||
Double[] y = {9d, 15d, 19d, 20d, 45d, 55d, 78d};
|
Double[] y = {9d, 15d, 19d, 20d, 45d, 55d, 78d};
|
||||||
// Float[] x = {18f,24f,30f,34f,38f};
|
// Float[] x = {18f,24f,30f,34f,38f};
|
||||||
|
@ -42,6 +40,7 @@ public class Presenter {
|
||||||
view.log("f(x) = " + p.getX() + "x + " + p.getY());
|
view.log("f(x) = " + p.getX() + "x + " + p.getY());
|
||||||
this.model.addLine(p);
|
this.model.addLine(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
calcArrangementNodes();
|
calcArrangementNodes();
|
||||||
//print
|
//print
|
||||||
List<String> heading = new LinkedList<>();
|
List<String> heading = new LinkedList<>();
|
||||||
|
@ -59,18 +58,6 @@ public class Presenter {
|
||||||
view.logSuccess("Berechnung wurde Erfolgreich durchgeführt");
|
view.logSuccess("Berechnung wurde Erfolgreich durchgeführt");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getDataFromModel() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDataByModel() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void getActionsFromView() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void startArrangementVisualization() {
|
public void startArrangementVisualization() {
|
||||||
view.createArrangement();
|
view.createArrangement();
|
||||||
}
|
}
|
||||||
|
@ -79,19 +66,15 @@ public class Presenter {
|
||||||
view.createPlot();
|
view.createPlot();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void extractBounds() {
|
|
||||||
// Coordinates pmax = Collections.max(model.getLines());
|
|
||||||
// Coordinates pmin = Collections.min(model.getLines());
|
private void convertCoordinates() {
|
||||||
//
|
|
||||||
// max = pmax.getX() >= pmax.getY() ? pmax.getX() : pmax.getY();
|
|
||||||
// min = pmin.getX() <= pmin.getY() ? pmin.getX() : pmin.getY();
|
|
||||||
LinkedList<Double> xCoordinates = new LinkedList<>();
|
LinkedList<Double> xCoordinates = new LinkedList<>();
|
||||||
LinkedList<Double> yCoordinates = new LinkedList<>();
|
LinkedList<Double> yCoordinates = new LinkedList<>();
|
||||||
|
|
||||||
for (Coordinates point : model.getNodes()) {
|
for (Coordinates point : model.getNodes()) {
|
||||||
xCoordinates.add(point.getX());
|
xCoordinates.add(point.getX());
|
||||||
yCoordinates.add(point.getY());
|
yCoordinates.add(point.getY());
|
||||||
System.out.println(point.getX() + ", " + point.getY());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Collections.sort(xCoordinates);
|
Collections.sort(xCoordinates);
|
||||||
|
@ -105,22 +88,19 @@ public class Presenter {
|
||||||
ymin = yCoordinates.getFirst();
|
ymin = yCoordinates.getFirst();
|
||||||
ymax = yCoordinates.getLast();
|
ymax = yCoordinates.getLast();
|
||||||
|
|
||||||
System.out.println("x: "+xmin+", "+xmax+"\t"+ymin+", "+ymax);
|
|
||||||
|
|
||||||
for (Coordinates p : model.getLines()) {
|
// for (Coordinates p : model.getNodes()) {
|
||||||
p.setX(scale(p.getX(), xmin, xmax, 0, 100));
|
// p.setX(scale(p.getX(), xmin, xmax, 0, 700));
|
||||||
p.setY(scale(p.getY(), ymin, ymax, 0, 100));
|
// p.setY(scale(p.getY(), ymin, ymax, 0, 700));
|
||||||
view.log(p.getX() + ", "+p.getY());
|
// }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public double scale(
|
public double scale(double x, double old_min, double old_max, double new_min, double new_max){
|
||||||
double x,
|
|
||||||
double old_min, double old_max,
|
|
||||||
double new_min, double new_max) {
|
|
||||||
double old_range = Math.abs(old_max - old_min);
|
double old_range = Math.abs(old_max - old_min);
|
||||||
double new_range = Math.abs(new_max - new_min);
|
double new_range = Math.abs(new_max - new_min);
|
||||||
return (new_min + x - old_min) * (new_range / old_range);
|
double ret = new_min + ((x - old_min) * Math.abs(new_range / old_range));
|
||||||
|
System.out.println("Old Range: "+old_range+"\t New Range: "+new_range+"\t ret: "+ret);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Coordinates calcIntersection(Coordinates a, Coordinates b) {
|
public Coordinates calcIntersection(Coordinates a, Coordinates b) {
|
||||||
|
@ -143,17 +123,14 @@ public class Presenter {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void calcArrangementNodes() {
|
public void calcArrangementNodes() {
|
||||||
Thread thread = new Thread(new Runnable() {
|
Thread thread = new Thread(() -> {
|
||||||
@Override
|
for (int i = 0; i < getLines().size(); i++) {
|
||||||
public void run() {
|
for (int j = i; j < getLines().size(); j++) {
|
||||||
for (int i = 0; i < getLines().size(); i++) {
|
if (i != j)
|
||||||
for (int j = i; j < getLines().size(); j++) {
|
model.addNode(calcIntersection(getLines().get(j), getLines().get(i)));
|
||||||
if (i != j)
|
|
||||||
model.addNode(calcIntersection(getLines().get(j), getLines().get(i)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
extractBounds();
|
|
||||||
}
|
}
|
||||||
|
convertCoordinates();
|
||||||
});
|
});
|
||||||
thread.start();
|
thread.start();
|
||||||
try {
|
try {
|
||||||
|
@ -164,6 +141,23 @@ public class Presenter {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LinkedList<LinkedList<Coordinates>> calcArrangementLines(){
|
||||||
|
LinkedList<LinkedList<Coordinates>> lineCoordinates = new LinkedList<>();
|
||||||
|
double x1 = -1000;
|
||||||
|
double x2 = 1000;
|
||||||
|
|
||||||
|
|
||||||
|
for (Coordinates point : model.getLines()) {
|
||||||
|
LinkedList line = new LinkedList();
|
||||||
|
double y1 = (point.getX() * x1 + point.getY());
|
||||||
|
double y2 = (point.getX() * x2 + point.getY());
|
||||||
|
line.add(new Coordinates(x1,y1));
|
||||||
|
line.add(new Coordinates(x2,y2));
|
||||||
|
lineCoordinates.add(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
return lineCoordinates;
|
||||||
|
}
|
||||||
/***************************************************************************************************************************
|
/***************************************************************************************************************************
|
||||||
* Getter und Setter Methoden
|
* Getter und Setter Methoden
|
||||||
***************************************************************************************************************************/
|
***************************************************************************************************************************/
|
||||||
|
|
|
@ -1,9 +1,16 @@
|
||||||
package View;
|
package View;
|
||||||
|
|
||||||
import Model.Coordinates;
|
import Model.Coordinates;
|
||||||
|
import sun.awt.image.ImageWatched;
|
||||||
|
import sun.plugin.dom.core.CoreConstants;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
import javax.swing.event.ChangeEvent;
|
||||||
|
import javax.swing.event.ChangeListener;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
import java.awt.geom.Line2D;
|
||||||
|
import java.awt.geom.Point2D;
|
||||||
|
import java.awt.geom.Rectangle2D;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -15,45 +22,73 @@ import java.util.LinkedList;
|
||||||
*/
|
*/
|
||||||
public class ArrangementDialog2 extends JPanel {
|
public class ArrangementDialog2 extends JPanel {
|
||||||
|
|
||||||
private double scale;
|
|
||||||
|
|
||||||
private int min = 0;
|
private int min = 0;
|
||||||
private int max = 600;
|
private int max = 800;
|
||||||
private int zero = max/2;
|
private int zero = max/2;
|
||||||
|
private double scale = 1.0;
|
||||||
|
private int pointThicknes = 5;
|
||||||
|
|
||||||
private int low;
|
|
||||||
private int high;
|
|
||||||
|
|
||||||
private Dimension dimension;
|
private Dimension dimension;
|
||||||
private LinkedList<Coordinates> lines;
|
private LinkedList<LinkedList<Coordinates>> lines;
|
||||||
private LinkedList<Coordinates> points;
|
private LinkedList<Coordinates> points;
|
||||||
|
private LinkedList<Line2D.Double> line2Ds;
|
||||||
|
|
||||||
|
|
||||||
public ArrangementDialog2(){
|
public ArrangementDialog2(){
|
||||||
super();
|
super();
|
||||||
this.dimension = new Dimension(max,max);
|
this.dimension = new Dimension(max,max);
|
||||||
this.setPreferredSize(dimension);
|
this.setPreferredSize(dimension);
|
||||||
|
this.setLayout(new BorderLayout());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPrameters(LinkedList<Coordinates> lines, LinkedList<Coordinates> points) {
|
public void setPrameters(LinkedList<LinkedList<Coordinates>> lines, LinkedList<Coordinates> points) {
|
||||||
this.lines = lines;
|
this.lines = lines;
|
||||||
this.points = points;
|
this.points = points;
|
||||||
|
|
||||||
//scalePoints();
|
|
||||||
this.repaint();
|
this.repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void scalePoints(){
|
public double getScale() {
|
||||||
|
return scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setScale(double scale) {
|
||||||
|
this.scale = scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPointThicknes() {
|
||||||
|
return pointThicknes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPointThicknes(int pointThicknes) {
|
||||||
|
this.pointThicknes = pointThicknes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void paintComponent(Graphics g){
|
public void paintComponent(Graphics g){
|
||||||
super.paintComponent(g);
|
super.paintComponent(g);
|
||||||
g.setColor(Color.BLACK);
|
Graphics2D g2 = (Graphics2D) g;
|
||||||
|
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||||
|
line2Ds = new LinkedList<>();
|
||||||
|
g2.translate(zero, zero);
|
||||||
|
g2.scale(scale, scale);
|
||||||
|
g2.translate(-1 * zero, -1 *zero);
|
||||||
|
|
||||||
|
//draw the lines
|
||||||
|
g2.setColor(Color.BLACK);
|
||||||
|
g2.setStroke(new BasicStroke(5f / (float) scale));
|
||||||
|
for (LinkedList<Coordinates> line : lines){
|
||||||
|
line2Ds.add(new Line2D.Double(zero +line.getFirst().getX().intValue(), zero +line.getFirst().getY().intValue(), zero +line.getLast().getX().intValue(), zero +line.getLast().getY().intValue()));
|
||||||
|
}
|
||||||
|
for (Line2D.Double line : line2Ds) {
|
||||||
|
g2.draw(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
//draw intersections of the lines
|
||||||
|
g2.setColor(Color.RED);
|
||||||
for (Coordinates point : points) {
|
for (Coordinates point : points) {
|
||||||
g.drawRect(point.getX().intValue(),point.getY().intValue(), 5, 5);
|
g2.fillOval(zero +point.getX().intValue(),zero +point.getY().intValue(), pointThicknes, pointThicknes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,8 @@ package View;
|
||||||
import Presenter.Presenter;
|
import Presenter.Presenter;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
import javax.swing.event.ChangeEvent;
|
||||||
|
import javax.swing.event.ChangeListener;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -23,6 +25,7 @@ public class MainFrame extends JFrame {
|
||||||
private JButton plotButton;
|
private JButton plotButton;
|
||||||
private JButton button3;
|
private JButton button3;
|
||||||
private JPanel pane;
|
private JPanel pane;
|
||||||
|
private JSlider slider;
|
||||||
private JDialog arrangementDialog;
|
private JDialog arrangementDialog;
|
||||||
private JDialog plotDialog;
|
private JDialog plotDialog;
|
||||||
private OutputPanel output;
|
private OutputPanel output;
|
||||||
|
@ -52,12 +55,13 @@ public class MainFrame extends JFrame {
|
||||||
public void createArrangement() {
|
public void createArrangement() {
|
||||||
if (arrangement == null) {
|
if (arrangement == null) {
|
||||||
arrangement = new ArrangementDialog2();
|
arrangement = new ArrangementDialog2();
|
||||||
arrangement.setPrameters(getPresenter().getLines(), getPresenter().getModel().getNodes());
|
arrangement.setPrameters(getPresenter().calcArrangementLines(), getPresenter().getModel().getNodes());
|
||||||
// arrangement.createArrangement();
|
// arrangement.createArrangement();
|
||||||
SwingUtilities.invokeLater(new Runnable() {
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
arrangementDialog.add(arrangement);
|
arrangementDialog.add(arrangement, BorderLayout.CENTER);
|
||||||
|
arrangementDialog.add(slider, BorderLayout.SOUTH);
|
||||||
arrangementDialog.setVisible(true);
|
arrangementDialog.setVisible(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -103,13 +107,36 @@ public class MainFrame extends JFrame {
|
||||||
|
|
||||||
arrangementDialog = new JDialog();
|
arrangementDialog = new JDialog();
|
||||||
plotDialog = new JDialog();
|
plotDialog = new JDialog();
|
||||||
arrangementDialog.setSize(new Dimension(600, 600));
|
arrangementDialog.setSize(new Dimension(800, 800));
|
||||||
plotDialog.setSize(new Dimension(700, 470));
|
plotDialog.setSize(new Dimension(700, 470));
|
||||||
arrangementDialog.setTitle("Arrangement Dialog");
|
arrangementDialog.setTitle("Arrangement Dialog");
|
||||||
plotDialog.setTitle("Scatter Plot Dialog");
|
plotDialog.setTitle("Scatter Plot Dialog");
|
||||||
arrangementDialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
|
arrangementDialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
|
||||||
plotDialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
|
plotDialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
|
||||||
|
|
||||||
|
this.slider = new JSlider(JSlider.HORIZONTAL, 10, 100, 10);
|
||||||
|
this.slider.addChangeListener(new ChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void stateChanged(ChangeEvent e) {
|
||||||
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
JSlider source = (JSlider) e.getSource();
|
||||||
|
arrangement.setScale((double) source.getValue() / 10);
|
||||||
|
int thicknes = 100 / source.getValue();
|
||||||
|
if (thicknes == 0) {
|
||||||
|
arrangement.setPointThicknes(1);
|
||||||
|
} else {
|
||||||
|
arrangement.setPointThicknes(thicknes);
|
||||||
|
}
|
||||||
|
arrangement.repaint();
|
||||||
|
arrangement.validate();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
output = new OutputPanel();
|
output = new OutputPanel();
|
||||||
splitpane = new JSplitPane();
|
splitpane = new JSplitPane();
|
||||||
output.setMinimumSize(new Dimension(400,500));
|
output.setMinimumSize(new Dimension(400,500));
|
||||||
|
|
Loading…
Reference in New Issue