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) {
|
||||
this.model = model;
|
||||
this.view = view;
|
||||
|
||||
|
||||
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};
|
||||
|
@ -42,6 +40,7 @@ public class Presenter {
|
|||
view.log("f(x) = " + p.getX() + "x + " + p.getY());
|
||||
this.model.addLine(p);
|
||||
}
|
||||
|
||||
calcArrangementNodes();
|
||||
//print
|
||||
List<String> heading = new LinkedList<>();
|
||||
|
@ -59,18 +58,6 @@ public class Presenter {
|
|||
view.logSuccess("Berechnung wurde Erfolgreich durchgeführt");
|
||||
}
|
||||
|
||||
public void getDataFromModel() {
|
||||
|
||||
}
|
||||
|
||||
public void setDataByModel() {
|
||||
|
||||
}
|
||||
|
||||
public void getActionsFromView() {
|
||||
|
||||
}
|
||||
|
||||
public void startArrangementVisualization() {
|
||||
view.createArrangement();
|
||||
}
|
||||
|
@ -79,19 +66,15 @@ public class Presenter {
|
|||
view.createPlot();
|
||||
}
|
||||
|
||||
private void extractBounds() {
|
||||
// Coordinates pmax = Collections.max(model.getLines());
|
||||
// Coordinates pmin = Collections.min(model.getLines());
|
||||
//
|
||||
// max = pmax.getX() >= pmax.getY() ? pmax.getX() : pmax.getY();
|
||||
// min = pmin.getX() <= pmin.getY() ? pmin.getX() : pmin.getY();
|
||||
|
||||
|
||||
private void convertCoordinates() {
|
||||
LinkedList<Double> xCoordinates = new LinkedList<>();
|
||||
LinkedList<Double> yCoordinates = new LinkedList<>();
|
||||
|
||||
for (Coordinates point : model.getNodes()) {
|
||||
xCoordinates.add(point.getX());
|
||||
yCoordinates.add(point.getY());
|
||||
System.out.println(point.getX() + ", " + point.getY());
|
||||
}
|
||||
|
||||
Collections.sort(xCoordinates);
|
||||
|
@ -105,22 +88,19 @@ public class Presenter {
|
|||
ymin = yCoordinates.getFirst();
|
||||
ymax = yCoordinates.getLast();
|
||||
|
||||
System.out.println("x: "+xmin+", "+xmax+"\t"+ymin+", "+ymax);
|
||||
|
||||
for (Coordinates p : model.getLines()) {
|
||||
p.setX(scale(p.getX(), xmin, xmax, 0, 100));
|
||||
p.setY(scale(p.getY(), ymin, ymax, 0, 100));
|
||||
view.log(p.getX() + ", "+p.getY());
|
||||
}
|
||||
// for (Coordinates p : model.getNodes()) {
|
||||
// p.setX(scale(p.getX(), xmin, xmax, 0, 700));
|
||||
// p.setY(scale(p.getY(), ymin, ymax, 0, 700));
|
||||
// }
|
||||
}
|
||||
|
||||
public double scale(
|
||||
double x,
|
||||
double old_min, double old_max,
|
||||
double new_min, double new_max) {
|
||||
public double scale(double x, double old_min, double old_max, double new_min, double new_max){
|
||||
double old_range = Math.abs(old_max - old_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) {
|
||||
|
@ -143,17 +123,14 @@ public class Presenter {
|
|||
}
|
||||
|
||||
public void calcArrangementNodes() {
|
||||
Thread thread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (int i = 0; i < getLines().size(); i++) {
|
||||
for (int j = i; j < getLines().size(); j++) {
|
||||
if (i != j)
|
||||
model.addNode(calcIntersection(getLines().get(j), getLines().get(i)));
|
||||
}
|
||||
Thread thread = new Thread(() -> {
|
||||
for (int i = 0; i < getLines().size(); i++) {
|
||||
for (int j = i; j < getLines().size(); j++) {
|
||||
if (i != j)
|
||||
model.addNode(calcIntersection(getLines().get(j), getLines().get(i)));
|
||||
}
|
||||
extractBounds();
|
||||
}
|
||||
convertCoordinates();
|
||||
});
|
||||
thread.start();
|
||||
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
|
||||
***************************************************************************************************************************/
|
||||
|
|
|
@ -1,9 +1,16 @@
|
|||
package View;
|
||||
|
||||
import Model.Coordinates;
|
||||
import sun.awt.image.ImageWatched;
|
||||
import sun.plugin.dom.core.CoreConstants;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import java.awt.*;
|
||||
import java.awt.geom.Line2D;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.util.LinkedList;
|
||||
|
||||
/**
|
||||
|
@ -15,45 +22,73 @@ import java.util.LinkedList;
|
|||
*/
|
||||
public class ArrangementDialog2 extends JPanel {
|
||||
|
||||
private double scale;
|
||||
|
||||
private int min = 0;
|
||||
private int max = 600;
|
||||
private int max = 800;
|
||||
private int zero = max/2;
|
||||
private double scale = 1.0;
|
||||
private int pointThicknes = 5;
|
||||
|
||||
private int low;
|
||||
private int high;
|
||||
|
||||
private Dimension dimension;
|
||||
private LinkedList<Coordinates> lines;
|
||||
private LinkedList<LinkedList<Coordinates>> lines;
|
||||
private LinkedList<Coordinates> points;
|
||||
private LinkedList<Line2D.Double> line2Ds;
|
||||
|
||||
|
||||
public ArrangementDialog2(){
|
||||
super();
|
||||
this.dimension = new Dimension(max,max);
|
||||
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.points = points;
|
||||
|
||||
//scalePoints();
|
||||
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
|
||||
protected void paintComponent(Graphics g){
|
||||
public void paintComponent(Graphics 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) {
|
||||
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 javax.swing.*;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import java.awt.*;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -23,6 +25,7 @@ public class MainFrame extends JFrame {
|
|||
private JButton plotButton;
|
||||
private JButton button3;
|
||||
private JPanel pane;
|
||||
private JSlider slider;
|
||||
private JDialog arrangementDialog;
|
||||
private JDialog plotDialog;
|
||||
private OutputPanel output;
|
||||
|
@ -52,12 +55,13 @@ public class MainFrame extends JFrame {
|
|||
public void createArrangement() {
|
||||
if (arrangement == null) {
|
||||
arrangement = new ArrangementDialog2();
|
||||
arrangement.setPrameters(getPresenter().getLines(), getPresenter().getModel().getNodes());
|
||||
arrangement.setPrameters(getPresenter().calcArrangementLines(), getPresenter().getModel().getNodes());
|
||||
// arrangement.createArrangement();
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
arrangementDialog.add(arrangement);
|
||||
arrangementDialog.add(arrangement, BorderLayout.CENTER);
|
||||
arrangementDialog.add(slider, BorderLayout.SOUTH);
|
||||
arrangementDialog.setVisible(true);
|
||||
}
|
||||
});
|
||||
|
@ -103,13 +107,36 @@ public class MainFrame extends JFrame {
|
|||
|
||||
arrangementDialog = new JDialog();
|
||||
plotDialog = new JDialog();
|
||||
arrangementDialog.setSize(new Dimension(600, 600));
|
||||
arrangementDialog.setSize(new Dimension(800, 800));
|
||||
plotDialog.setSize(new Dimension(700, 470));
|
||||
arrangementDialog.setTitle("Arrangement Dialog");
|
||||
plotDialog.setTitle("Scatter Plot Dialog");
|
||||
arrangementDialog.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();
|
||||
splitpane = new JSplitPane();
|
||||
output.setMinimumSize(new Dimension(400,500));
|
||||
|
|
Loading…
Reference in New Issue