97 lines
2.4 KiB
Java
97 lines
2.4 KiB
Java
package View;
|
|
|
|
import Model.Point;
|
|
import java.awt.BasicStroke;
|
|
import java.awt.BorderLayout;
|
|
import java.awt.Color;
|
|
import java.awt.Dimension;
|
|
import java.awt.Graphics;
|
|
import java.awt.Graphics2D;
|
|
import java.awt.RenderingHints;
|
|
import java.awt.geom.Line2D;
|
|
import java.util.LinkedList;
|
|
import javax.swing.JPanel;
|
|
|
|
/**
|
|
* Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
|
|
*
|
|
* @Author: Armin Wolf
|
|
* @Email: a_wolf28@uni-muenster.de
|
|
* @Date: 03.06.2017.
|
|
*/
|
|
public class ArrangementDialog2 extends JPanel {
|
|
|
|
private int min = 0;
|
|
private int max = 800;
|
|
private int zero = max / 2;
|
|
private double scale = 1.0;
|
|
private int pointThicknes = 5;
|
|
|
|
|
|
private Dimension dimension;
|
|
private LinkedList<LinkedList<Point>> lines;
|
|
private LinkedList<Point> 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<LinkedList<Point>> lines, LinkedList<Point> points) {
|
|
this.lines = lines;
|
|
this.points = points;
|
|
this.repaint();
|
|
}
|
|
|
|
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
|
|
public void paintComponent(Graphics g) {
|
|
super.paintComponent(g);
|
|
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<Point> 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 (Point point : points) {
|
|
g2.fillOval(zero + point.getX().intValue(), zero + point.getY().intValue(), pointThicknes,
|
|
pointThicknes);
|
|
}
|
|
}
|
|
}
|