paar anpassungen u.a. RM Estimator
This commit is contained in:
parent
484bd3a2c9
commit
a1c3d2c933
7
pom.xml
7
pom.xml
|
@ -35,5 +35,12 @@
|
|||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
</dependency>
|
||||
|
||||
<!-- OpenCSV-->
|
||||
<dependency>
|
||||
<groupId>com.opencsv</groupId>
|
||||
<artifactId>opencsv</artifactId>
|
||||
<version>3.9</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -139,8 +139,7 @@ public class LeastMedianOfSquaresEstimator extends Observable implements Algorit
|
|||
setChanged();
|
||||
double m = (getSigmaMin().getX2() + getSigmaMin().getX1()) * -0.5;
|
||||
double b = (getSigmaMin().getY2() + getSigmaMin().getY1()) * 0.5;
|
||||
Line result = new Line(m, b);
|
||||
result.setId("lms");
|
||||
String[] result = {"lms", m+"", b+""};
|
||||
notifyObservers(result);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import java.util.Collections;
|
|||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Observable;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
/**
|
||||
|
@ -77,6 +78,7 @@ public class RepeatedMedianEstimator extends Observable implements Algorithm {
|
|||
public void run() {
|
||||
|
||||
while (linesInCenterSlab.size() != 1) {
|
||||
n = linesInCenterSlab.size();
|
||||
r = Math.ceil(Math.pow(n, beta));
|
||||
ArrayList<Line> lines = sampleLines(linesInCenterSlab, r);
|
||||
|
||||
|
@ -92,16 +94,18 @@ public class RepeatedMedianEstimator extends Observable implements Algorithm {
|
|||
}
|
||||
|
||||
//rank of the repeated median in C
|
||||
k = (Math.floor(n * 0.5) - linesInLeftSlab.size());
|
||||
k = Math.max(1,Math.min(set.size(),(Math.ceil(n * 0.5) - linesInLeftSlab.size())));
|
||||
|
||||
//compute k_lo and k_hi
|
||||
computeSlabBorders();
|
||||
|
||||
|
||||
if (medianIntersectionAbscissas.size() < kLow || medianIntersectionAbscissas.size()<kHigh || kLow < 0 || kHigh<0 )
|
||||
System.err.print("#medianIntersectionAbscissa: "+medianIntersectionAbscissas.size()+"\t\t klow: "+kLow+" kHigh: "+kHigh+"\n\n");
|
||||
|
||||
//Employ fast selection algorithm to determine the Elements Theta_lo and Theta_hi
|
||||
thetaLow = randomizedSelect(medianIntersectionAbscissas, 0,
|
||||
medianIntersectionAbscissas.size() - 1, kLow);
|
||||
thetaHigh = randomizedSelect(medianIntersectionAbscissas, 0,
|
||||
medianIntersectionAbscissas.size() - 1, kHigh);
|
||||
thetaLow = randomizedSelect(medianIntersectionAbscissas, kLow);
|
||||
thetaHigh = randomizedSelect(medianIntersectionAbscissas, kHigh);
|
||||
|
||||
//For each dual Line in C count the number of intersection abscissas that lie
|
||||
//in each of the intervals.
|
||||
|
@ -119,8 +123,7 @@ public class RepeatedMedianEstimator extends Observable implements Algorithm {
|
|||
double b = (
|
||||
(linesInCenterSlab.get(0).getM() * (thetaLow)) + linesInCenterSlab.get(0)
|
||||
.getB());
|
||||
Line result = new Line(m, b);
|
||||
result.setId("rm");
|
||||
String[] result = {"rm", m+"", b+""};
|
||||
notifyObservers(result);
|
||||
}
|
||||
}
|
||||
|
@ -187,32 +190,50 @@ public class RepeatedMedianEstimator extends Observable implements Algorithm {
|
|||
*/
|
||||
public void computeSlabBorders() {
|
||||
kLow = Math
|
||||
.max(1, Math.floor(((r * k) / (linesInCenterSlab.size())) - ((3 * Math.sqrt(r)) / (2))));
|
||||
.max(1, Math.floor(
|
||||
( (r * k) / (linesInCenterSlab.size()))
|
||||
- ( (3 * Math.sqrt(r)) / (2))
|
||||
)
|
||||
);
|
||||
kHigh = Math
|
||||
.min(r, Math.floor(((r * k) / (linesInCenterSlab.size())) + ((3 * Math.sqrt(r)) / (2))));
|
||||
.min(r, Math.floor(
|
||||
((r * k) / (linesInCenterSlab.size()))
|
||||
+ ((3 * Math.sqrt(r)) / (2))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param a
|
||||
* @param start
|
||||
* @param end
|
||||
* @param i
|
||||
* @return
|
||||
*/
|
||||
public Double randomizedSelect(ArrayList<Double> a, int start, int end, double i) {
|
||||
if (start == end) {
|
||||
return a.get(start);
|
||||
public Double randomizedSelect(ArrayList<Double> a, double i) {
|
||||
int start = 0;
|
||||
int end = a.size()-1;
|
||||
if (i >= end+1){
|
||||
return a.get(end);
|
||||
}
|
||||
int q = randomizedPartition(a, start, end);
|
||||
int tmpPivot = q - start + 1;
|
||||
|
||||
if (i == tmpPivot) {
|
||||
return a.get(q);
|
||||
} else if (i < tmpPivot) {
|
||||
return randomizedSelect(a, start, q - 1, i);
|
||||
} else {
|
||||
return randomizedSelect(a, q + 1, end, i - tmpPivot);
|
||||
while(true){
|
||||
if(start == end){
|
||||
return a.get(start);
|
||||
}
|
||||
int q = randomizedPartition(a, start, end);
|
||||
int k = q-start+1;
|
||||
|
||||
if(i == k){
|
||||
return a.get(q);
|
||||
}
|
||||
else{
|
||||
if(i <k){
|
||||
end = q -1;
|
||||
}else{
|
||||
i = i - k;
|
||||
start = q + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -224,8 +245,16 @@ public class RepeatedMedianEstimator extends Observable implements Algorithm {
|
|||
* @return
|
||||
*/
|
||||
public int randomizedPartition(ArrayList<Double> a, int start, int end) {
|
||||
int delta = Math.abs(end - start);
|
||||
int i = start + ThreadLocalRandom.current().nextInt(0, delta);
|
||||
int i = 0;
|
||||
Random random = new Random(System.currentTimeMillis());
|
||||
|
||||
//alternative: ThreadLocalRandom.current()
|
||||
if(start < end){
|
||||
i = start + random.nextInt(end-start);
|
||||
}else{
|
||||
i = end + random.nextInt(start-end);
|
||||
}
|
||||
|
||||
Collections.swap(a, end, i);
|
||||
return partition(a, start, end);
|
||||
}
|
||||
|
@ -240,14 +269,14 @@ public class RepeatedMedianEstimator extends Observable implements Algorithm {
|
|||
public int partition(ArrayList<Double> a, int start, int end) {
|
||||
Double x = a.get(end);
|
||||
int i = start - 1;
|
||||
for (int j = start; j < end; j++) {
|
||||
for (int j = start; j <= end-1; j++) {
|
||||
if (a.get(j) <= x) {
|
||||
i++;
|
||||
Collections.swap(a, i, j);
|
||||
}
|
||||
}
|
||||
Collections.swap(a, i + 1, end);
|
||||
return i + 1;
|
||||
Collections.swap(a, i+1, end);
|
||||
return i+1;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -284,8 +313,6 @@ public class RepeatedMedianEstimator extends Observable implements Algorithm {
|
|||
*
|
||||
*/
|
||||
public void contractIntervals() {
|
||||
//if (linesInLeftSlab.size() < Math.floor(n / 2) && Math.floor(n / 2) <= (linesInLeftSlab.size()
|
||||
// + linesInCenterSlab.size())) {
|
||||
for (int i = 0; i < linesInCenterSlab.size(); i++) {
|
||||
|
||||
int left = countLeftSlab.get(i);
|
||||
|
|
|
@ -1,15 +1,18 @@
|
|||
package Presenter.Import;
|
||||
|
||||
import Model.Arrangement;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileInputStream;
|
||||
import Model.Line;
|
||||
import com.opencsv.CSVReader;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.List;
|
||||
import java.util.Observable;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
|
||||
/**
|
||||
* Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
|
||||
*
|
||||
|
@ -17,72 +20,49 @@ import javax.swing.JOptionPane;
|
|||
* @Email: a_wolf28@uni-muenster.de
|
||||
* @Date: 21.06.2017.
|
||||
*/
|
||||
public class DataImporter {
|
||||
public class DataImporter extends Observable{
|
||||
|
||||
private String path;
|
||||
private InputStream inputStream;
|
||||
private File file;
|
||||
private CSVReader reader;
|
||||
private Arrangement model;
|
||||
final String separator = " ";
|
||||
|
||||
public DataImporter(String path, Arrangement model) {
|
||||
this.path = path;
|
||||
public DataImporter(File file, Arrangement model) {
|
||||
this.model = model;
|
||||
this.file = file;
|
||||
try {
|
||||
inputStream = new FileInputStream(path);
|
||||
|
||||
this.reader = new CSVReader(new FileReader(file));
|
||||
} catch (FileNotFoundException e) {
|
||||
JOptionPane.showMessageDialog(null, e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try (BufferedReader br = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"))) {
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
// process the line.
|
||||
public void run(){
|
||||
|
||||
try {
|
||||
List<String[]> lines = reader.readAll();
|
||||
int counter = 0;
|
||||
String[] result = {"import", lines.size()+"", ""};
|
||||
//System.out.println("+-------------------------------------------------------------------------------+");
|
||||
for(String[] nextLine : lines) {
|
||||
counter++;
|
||||
// nextLine[] is an array of values from the line
|
||||
int id = Integer.parseInt(nextLine[0]);
|
||||
Double x = Double.parseDouble(nextLine[1]);
|
||||
Double y = Double.parseDouble(nextLine[2]);
|
||||
Line line = new Line(x,y);
|
||||
line.setId(id+"");
|
||||
model.addLine(line);
|
||||
//System.out.format("|\t\t\t\t\t %-11d \t|\t\t\t\t\t %-11f \t|\t\t\t\t\t %-11f \t\t\t\t\t|\n", id,x,y);
|
||||
setChanged();
|
||||
result[2] = counter + "";
|
||||
notifyObservers(result);
|
||||
}
|
||||
br.close();
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
//System.out.println("+-------------------------------------------------------------------------------+");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void parseLine(String line) {
|
||||
if (line.substring(0, 1) == "#") {
|
||||
return;
|
||||
} else if (isNumeric(line.substring(line.lastIndexOf(separator), line.length() - 1))) {
|
||||
String id = line.substring(0, line.indexOf(separator));
|
||||
Double x = Double.parseDouble(line.substring(line.indexOf(separator), line.lastIndexOf(separator)));
|
||||
Double y = Double.parseDouble(line.substring(line.lastIndexOf(separator), line.length()-1));
|
||||
System.out.println("ID: "+id+" x: "+x+"\t y: "+y);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isNumeric(String str) {
|
||||
try {
|
||||
double d = Double.parseDouble(str);
|
||||
} catch (NumberFormatException nfe) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
public void setPath(String path) {
|
||||
path = path;
|
||||
}
|
||||
|
||||
public InputStream getInputStream() {
|
||||
return inputStream;
|
||||
}
|
||||
|
||||
public void setInputStream(InputStream inputStream) {
|
||||
this.inputStream = inputStream;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,11 +5,14 @@ import Model.Line;
|
|||
import Model.Point;
|
||||
import Presenter.Algorithms.LeastMedianOfSquaresEstimator;
|
||||
import Presenter.Algorithms.RepeatedMedianEstimator;
|
||||
import Presenter.Import.DataImporter;
|
||||
import View.MainFrame;
|
||||
import java.io.File;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Observable;
|
||||
import java.util.Observer;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
|
||||
|
@ -33,68 +36,92 @@ public class Presenter implements Observer {
|
|||
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};
|
||||
Double[] x = {18d, 24d, 30d, 34d, 38d};
|
||||
Double[] y = {18d, 26d, 30d, 40d, 70d};
|
||||
// Double[] x = {1d,3d,4d,5d,8d};
|
||||
// Double[] y = {4d,2d,1d,0d,0d};
|
||||
view.logHeading("Duale Darstellung der Punkte als Geraden:");
|
||||
for (int j = 0; j < x.length; j++) {
|
||||
Line p = new Line(x[j], y[j]);
|
||||
p.setId(j+"");
|
||||
view.log("f(x) = " + p.getM() + "x + " + p.getB());
|
||||
this.model.addLine(p);
|
||||
}
|
||||
|
||||
calcArrangementNodes();
|
||||
//print
|
||||
List<String> heading = new LinkedList<>();
|
||||
List<List<String>> rows = new LinkedList<>();
|
||||
heading.add("X - Koordinate");
|
||||
heading.add("Y - Koordinate");
|
||||
for (Point p : model.getNodes()) {
|
||||
LinkedList<String> rowEntry = new LinkedList<>();
|
||||
rowEntry.add(p.getX().toString());
|
||||
rowEntry.add(p.getY().toString());
|
||||
rows.add(rowEntry);
|
||||
}
|
||||
view.logHeading("Schnittpunkte der Dualen Geraden:");
|
||||
view.createTable(heading, rows);
|
||||
// Double[] x = {1d, 2d, 3d, 4d, 10d, 12d, 18d};
|
||||
// Double[] y = {9d, 15d, 19d, 20d, 45d, 55d, 78d};
|
||||
// Double[] x = {18d, 24d, 30d, 34d, 38d};
|
||||
// Double[] y = {18d, 26d, 30d, 40d, 70d};
|
||||
// Double[] x = {1d,3d,4d,5d,8d};
|
||||
// Double[] y = {4d,2d,1d,0d,0d};
|
||||
// view.logHeading("Duale Darstellung der Punkte als Geraden:");
|
||||
// for (int j = 0; j < x.length; j++) {
|
||||
// Line p = new Line(x[j], y[j]);
|
||||
// p.setId(j+"");
|
||||
// view.log("f(x) = " + p.getM() + "x + " + p.getB());
|
||||
// this.model.addLine(p);
|
||||
// }
|
||||
//
|
||||
// calcArrangementNodes();
|
||||
// //print
|
||||
// List<String> heading = new LinkedList<>();
|
||||
// List<List<String>> rows = new LinkedList<>();
|
||||
// heading.add("X - Koordinate");
|
||||
// heading.add("Y - Koordinate");
|
||||
// for (Point p : model.getNodes()) {
|
||||
// LinkedList<String> rowEntry = new LinkedList<>();
|
||||
// rowEntry.add(p.getX().toString());
|
||||
// rowEntry.add(p.getY().toString());
|
||||
// rows.add(rowEntry);
|
||||
// }
|
||||
// view.logHeading("Schnittpunkte der Dualen Geraden:");
|
||||
// view.createTable(heading, rows);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void update(Observable o, Object arg) {
|
||||
Line result = ((Line) arg);
|
||||
if (result.getId() == "lms"){
|
||||
String[] result = ((String[]) arg);
|
||||
if (result[0] == "lms"){
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
getView().visualizeLMS(result.getM(), result.getB());
|
||||
getView().visualizeLMS(Double.parseDouble(result[1]), Double.parseDouble(result[2]));
|
||||
//getView().setLmsIsComplete(true);
|
||||
getView().logHeading("Least Median of Squares");
|
||||
getView().log("<b>m:</b> " + result.getM());
|
||||
getView().log("<b>b:</b> " + result.getB());
|
||||
getView().log("<b>m:</b> " + result[1]);
|
||||
getView().log("<b>b:</b> " + result[2]);
|
||||
getView().logSuccess("Berechnung wurde Erfolgreich durchgeführt");
|
||||
});
|
||||
}
|
||||
|
||||
if (result.getId() == "rm"){
|
||||
if (result[0] == "rm"){
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
getView().visualizeRM(result.getM(), result.getB());
|
||||
getView().visualizeRM(Double.parseDouble(result[1]), Double.parseDouble(result[2]));
|
||||
getView().logHeading("Repeated Median Estimator");
|
||||
getView().log("<b>m:</b> " + result.getM());
|
||||
getView().log("<b>b:</b> " + result.getB());
|
||||
getView().log("<b>m:</b> " + result[1]);
|
||||
getView().log("<b>b:</b> " + result[2]);
|
||||
getView().logSuccess("Berechnung wurde Erfolgreich durchgeführt");
|
||||
});
|
||||
}
|
||||
|
||||
if (result[0] == "import"){
|
||||
Double max = Double.parseDouble(result[1]);
|
||||
Double current = Double.parseDouble(result[2]);
|
||||
Integer progress = (int) (100 * (current/max));
|
||||
//100% erreicht
|
||||
if (progress == 100){
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
getView().showImportProgress(progress);
|
||||
getView().enableFunctionality();
|
||||
getView().getProgressDialog().dispose();
|
||||
});
|
||||
setup();
|
||||
} else {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
getView().showImportProgress(progress);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void startArrangementVisualization() {
|
||||
public void visualizeDualLines() {
|
||||
view.createArrangement();
|
||||
}
|
||||
|
||||
/***************************************************************************************************************************
|
||||
* Ausführung der Algorithmen
|
||||
***************************************************************************************************************************/
|
||||
public void calculateLMS(String[] input) {
|
||||
Double constant = Double.parseDouble(input[0]);
|
||||
Double error = Double.parseDouble(input[1]);
|
||||
|
@ -112,6 +139,33 @@ public class Presenter implements Observer {
|
|||
rm.run();
|
||||
}
|
||||
|
||||
/***************************************************************************************************************************
|
||||
* Hilfsmethoden
|
||||
***************************************************************************************************************************/
|
||||
public void setup(){
|
||||
getView().logHeading("Duale Darstellung der Punkte als Geraden:");
|
||||
|
||||
for (int j = 0; j < getModel().getLines().size(); j++) {
|
||||
Line p = getModel().getLines().get(j);
|
||||
p.setId(j+"");
|
||||
getView().log("f(x) = " + p.getM() + "x + " + p.getB());
|
||||
}
|
||||
calcArrangementNodes();
|
||||
|
||||
//Darstellung der Schnittpunkte in einer Tabelle
|
||||
// List<String> heading = new LinkedList<>();
|
||||
// List<List<String>> rows = new LinkedList<>();
|
||||
// heading.add("X - Koordinate");
|
||||
// heading.add("Y - Koordinate");
|
||||
// for (Point p : getModel().getNodes()) {
|
||||
// LinkedList<String> rowEntry = new LinkedList<>();
|
||||
// rowEntry.add(p.getX().toString());
|
||||
// rowEntry.add(p.getY().toString());
|
||||
// rows.add(rowEntry);
|
||||
// }
|
||||
// getView().logHeading("Schnittpunkte der Dualen Geraden:");
|
||||
// getView().createTable(heading, rows);
|
||||
}
|
||||
|
||||
public Point calcIntersection(Line a, Line b) {
|
||||
Line p1 = a;
|
||||
|
@ -142,23 +196,28 @@ public class Presenter implements Observer {
|
|||
|
||||
}
|
||||
|
||||
public LinkedList<LinkedList<Point>> calcArrangementLines() {
|
||||
LinkedList<LinkedList<Point>> lineCoordinates = new LinkedList<>();
|
||||
public LinkedList<Line> calcArrangementLines() {
|
||||
LinkedList<Line> lineCoordinates = new LinkedList<>();
|
||||
double x1 = -1000;
|
||||
double x2 = 1000;
|
||||
|
||||
for (Line point : model.getLines()) {
|
||||
LinkedList line = new LinkedList();
|
||||
double y1 = (point.getM() * x1 + point.getB());
|
||||
double y2 = (point.getM() * x2 + point.getB());
|
||||
line.add(new Point(x1, y1));
|
||||
line.add(new Point(x2, y2));
|
||||
Line line = new Line(x1, x2, y1, y2);
|
||||
line.setId(point.getId());
|
||||
lineCoordinates.add(line);
|
||||
}
|
||||
|
||||
return lineCoordinates;
|
||||
}
|
||||
|
||||
public void startImport(File file){
|
||||
DataImporter importer = new DataImporter(file, getModel());
|
||||
importer.addObserver(this);
|
||||
importer.run();
|
||||
}
|
||||
|
||||
/***************************************************************************************************************************
|
||||
* Getter und Setter Methoden
|
||||
***************************************************************************************************************************/
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package View;
|
||||
|
||||
import Model.Line;
|
||||
import Model.Point;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
|
@ -30,7 +31,7 @@ import org.jfree.util.ShapeUtilities;
|
|||
*/
|
||||
public class ArrangementDialog extends JPanel {
|
||||
|
||||
private LinkedList<LinkedList<Point>> lines;
|
||||
private LinkedList<Line> lines;
|
||||
private LinkedList<Point> points;
|
||||
private double max;
|
||||
private double min;
|
||||
|
@ -52,7 +53,7 @@ public class ArrangementDialog extends JPanel {
|
|||
this.hslider = new JSlider(SwingConstants.HORIZONTAL, 10, 1000, 500);
|
||||
}
|
||||
|
||||
public void setPrameters(LinkedList<LinkedList<Point>> lines, LinkedList<Point> points) {
|
||||
public void setPrameters(LinkedList<Line> lines, LinkedList<Point> points) {
|
||||
this.lines = lines;
|
||||
this.points = points;
|
||||
this.domainMin = Double.MAX_VALUE;
|
||||
|
@ -64,10 +65,10 @@ public class ArrangementDialog extends JPanel {
|
|||
public void createArrangement() {
|
||||
XYSeriesCollection dataset = new XYSeriesCollection();
|
||||
|
||||
for (LinkedList<Point> p : lines) {
|
||||
XYSeries series = new XYSeries(p.get(0).getX() + p.get(0).getY());
|
||||
series.add(p.get(0).getX(), p.get(0).getY());
|
||||
series.add(p.get(1).getX(), p.get(1).getY());
|
||||
for (Line p : lines) {
|
||||
XYSeries series = new XYSeries(p.getId());
|
||||
series.add(p.getX1(), p.getY1());
|
||||
series.add(p.getX2(), p.getY2());
|
||||
dataset.addSeries(series);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,18 +7,26 @@ import View.Panels.MenuPanel;
|
|||
import View.Panels.OutputPanel;
|
||||
import View.Panels.RMPanel;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Container;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JProgressBar;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JSplitPane;
|
||||
import javax.swing.JTabbedPane;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.border.Border;
|
||||
import javax.swing.filechooser.FileFilter;
|
||||
import javax.swing.filechooser.FileNameExtensionFilter;
|
||||
|
||||
/**
|
||||
* Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
|
||||
|
@ -34,10 +42,8 @@ public class MainFrame extends JFrame {
|
|||
private Boolean rmIsComplete = false;
|
||||
private Boolean tsIsComplete = false;
|
||||
|
||||
|
||||
//TODO refactoring
|
||||
private JButton arrangementButton;
|
||||
private JButton button3;
|
||||
private JButton importButton;
|
||||
|
||||
private OutputPanel output;
|
||||
private MenuPanel menupanel;
|
||||
|
@ -50,12 +56,14 @@ public class MainFrame extends JFrame {
|
|||
private PlotDialog plotLMS;
|
||||
private PlotDialog plotRM;
|
||||
private PlotDialog plotTS;
|
||||
private JDialog progressDialog;
|
||||
private Container progressContent;
|
||||
private JProgressBar progressBar;
|
||||
|
||||
|
||||
|
||||
private JSplitPane splitpane;
|
||||
private JScrollPane scrollPane;
|
||||
|
||||
private JTabbedPane tabbedPane;
|
||||
|
||||
public MainFrame() {
|
||||
|
@ -69,6 +77,7 @@ public class MainFrame extends JFrame {
|
|||
setCloseOperations();
|
||||
setActionListeners();
|
||||
|
||||
disableFunctionality();
|
||||
this.setVisible(true);
|
||||
}
|
||||
|
||||
|
@ -113,13 +122,19 @@ public class MainFrame extends JFrame {
|
|||
});
|
||||
}
|
||||
|
||||
public void showImportProgress(Integer progress){
|
||||
progressBar.setValue(progress);
|
||||
progressBar.setStringPainted(true);
|
||||
progressDialog.setVisible(true);
|
||||
}
|
||||
|
||||
/*******************************************************************************************************************
|
||||
* init GUI
|
||||
******************************************************************************************************************/
|
||||
private void setTitles() {
|
||||
this.setTitle("MainFrame");
|
||||
arrangementDialog.setTitle("Dual Representation - Dialog");
|
||||
button3.setText("Import");
|
||||
importButton.setText("Import");
|
||||
arrangementButton.setText("Dualraum");
|
||||
}
|
||||
|
||||
|
@ -131,11 +146,14 @@ public class MainFrame extends JFrame {
|
|||
|
||||
private void addComponents() {
|
||||
pane.add(arrangementButton);
|
||||
pane.add(button3);
|
||||
pane.add(importButton);
|
||||
|
||||
setupSplitPane();
|
||||
setupTabbedPane();
|
||||
|
||||
progressContent.add(progressBar, BorderLayout.NORTH);
|
||||
progressBar.setBorder(BorderFactory.createTitledBorder("Import..."));
|
||||
|
||||
this.add(pane, BorderLayout.SOUTH);
|
||||
this.add(splitpane, BorderLayout.CENTER);
|
||||
this.add(menupanel, BorderLayout.NORTH);
|
||||
|
@ -152,6 +170,7 @@ public class MainFrame extends JFrame {
|
|||
private void setCloseOperations() {
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
arrangementDialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
|
||||
progressDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||
}
|
||||
|
||||
private void setDimensions() {
|
||||
|
@ -161,9 +180,9 @@ public class MainFrame extends JFrame {
|
|||
rmPanel.setMinimumSize(new Dimension(400, 500));
|
||||
arrangementDialog.setSize(new Dimension(800, 800));
|
||||
output.setMinimumSize(new Dimension(400, 500));
|
||||
progressDialog.setSize(300, 100);
|
||||
}
|
||||
|
||||
|
||||
private void setLayouts() {
|
||||
this.setLayout(new BorderLayout());
|
||||
pane.setLayout(new FlowLayout());
|
||||
|
@ -178,6 +197,10 @@ public class MainFrame extends JFrame {
|
|||
|
||||
//Dialogs
|
||||
arrangementDialog = new JDialog();
|
||||
progressDialog = new JDialog();
|
||||
progressDialog.setLocationRelativeTo(null);
|
||||
progressContent = progressDialog.getContentPane();
|
||||
progressBar = new JProgressBar();
|
||||
|
||||
//Panes
|
||||
tabbedPane = new JTabbedPane();
|
||||
|
@ -186,12 +209,12 @@ public class MainFrame extends JFrame {
|
|||
|
||||
//Buttons
|
||||
arrangementButton = new JButton();
|
||||
button3 = new JButton();
|
||||
importButton = new JButton();
|
||||
}
|
||||
|
||||
private void setActionListeners() {
|
||||
arrangementButton.addActionListener((ActionEvent e) -> {
|
||||
Thread t = new Thread(() -> getPresenter().startArrangementVisualization());
|
||||
Thread t = new Thread(() -> getPresenter().visualizeDualLines());
|
||||
t.start();
|
||||
});
|
||||
|
||||
|
@ -206,8 +229,42 @@ public class MainFrame extends JFrame {
|
|||
() -> this.getPresenter().calculateRM(rmPanel.getInput()));
|
||||
t.start();
|
||||
});
|
||||
|
||||
importButton.addActionListener((ActionEvent e) -> {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
File file = null;
|
||||
JFileChooser chooser = new JFileChooser();
|
||||
chooser.setPreferredSize(new Dimension(800,700));
|
||||
chooser.setFileFilter(new FileNameExtensionFilter("Comma-Separated Value", "csv", "text"));
|
||||
|
||||
chooser.setMultiSelectionEnabled(false);
|
||||
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
|
||||
|
||||
|
||||
if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION){
|
||||
System.out.println ("Datei "+chooser.getSelectedFile()+
|
||||
" ausgewählt.");
|
||||
file = chooser.getSelectedFile();
|
||||
final File input = file;
|
||||
Thread t = new Thread(() -> this.getPresenter().startImport(input));
|
||||
t.start();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public void enableFunctionality(){
|
||||
this.getLmsPanel().getStartButton().setEnabled(true);
|
||||
this.getRmPanel().getStartButton().setEnabled(true);
|
||||
this.getArrangementButton().setEnabled(true);
|
||||
}
|
||||
|
||||
public void disableFunctionality(){
|
||||
this.getLmsPanel().getStartButton().setEnabled(false);
|
||||
this.getRmPanel().getStartButton().setEnabled(false);
|
||||
this.getArrangementButton().setEnabled(false);
|
||||
}
|
||||
|
||||
/*******************************************************************************************************************
|
||||
* log Methode
|
||||
|
@ -268,12 +325,12 @@ public class MainFrame extends JFrame {
|
|||
this.arrangementButton = arrangementButton;
|
||||
}
|
||||
|
||||
public JButton getButton3() {
|
||||
return button3;
|
||||
public JButton getImportButton() {
|
||||
return importButton;
|
||||
}
|
||||
|
||||
public void setButton3(JButton button3) {
|
||||
this.button3 = button3;
|
||||
public void setImportButton(JButton importButton) {
|
||||
this.importButton = importButton;
|
||||
}
|
||||
|
||||
public JPanel getPane() {
|
||||
|
@ -300,11 +357,11 @@ public class MainFrame extends JFrame {
|
|||
this.output = output;
|
||||
}
|
||||
|
||||
public JPanel getMenupanel() {
|
||||
public MenuPanel getMenupanel() {
|
||||
return menupanel;
|
||||
}
|
||||
|
||||
public JPanel getLmsPanel() {
|
||||
public LMSPanel getLmsPanel() {
|
||||
return lmsPanel;
|
||||
}
|
||||
|
||||
|
@ -324,6 +381,13 @@ public class MainFrame extends JFrame {
|
|||
this.scrollPane = scrollPane;
|
||||
}
|
||||
|
||||
public RMPanel getRmPanel() {
|
||||
return rmPanel;
|
||||
}
|
||||
|
||||
public void setRmPanel(RMPanel rmPanel) {
|
||||
this.rmPanel = rmPanel;
|
||||
}
|
||||
|
||||
public PlotDialog getPlotLMS() {
|
||||
return plotLMS;
|
||||
|
@ -340,4 +404,12 @@ public class MainFrame extends JFrame {
|
|||
public void setPresenter(Presenter presenter) {
|
||||
this.presenter = presenter;
|
||||
}
|
||||
|
||||
public JDialog getProgressDialog() {
|
||||
return progressDialog;
|
||||
}
|
||||
|
||||
public void setProgressDialog(JDialog progressDialog) {
|
||||
this.progressDialog = progressDialog;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,14 +14,16 @@ import org.junit.Test;
|
|||
*/
|
||||
public class DataImporterTest {
|
||||
|
||||
private DataImporter importer;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
DataImporter importer = new DataImporter("", null);
|
||||
//importer = new DataImporter("C:\\Users\\Armin\\Desktop\\test.csv", null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void run() throws Exception {
|
||||
|
||||
//importer.run();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue