JavaDoc soweit fertig

This commit is contained in:
Armin Wolf 2017-10-17 08:34:55 +02:00
parent 80d132516e
commit a585f903e6
18 changed files with 463 additions and 230 deletions

View File

@ -1,19 +1,21 @@
import com.sun.java.swing.plaf.windows.WindowsLookAndFeel;
import model.Line;
import model.Point;
import model.LineModel;
import nu.pattern.OpenCV;
import org.apache.commons.io.IOUtils;
import presenter.Presenter;
import presenter.algorithms.advanced.LeastMedianOfSquaresEstimator;
import presenter.algorithms.advanced.RepeatedMedianEstimator;
import presenter.algorithms.advanced.TheilSenEstimator;
import presenter.algorithms.naiv.NaivLeastMedianOfSquaresEstimator;
import presenter.algorithms.naiv.NaivRepeatedMedianEstimator;
import presenter.algorithms.naiv.NaivTheilSenEstimator;
import presenter.algorithms.util.IntersectionComputer;
import presenter.generator.DatasetGenerator;
import view.MainFrame;
import javax.swing.*;
import java.awt.*;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.LinkedList;
import static nu.pattern.OpenCV.loadShared;
@ -27,6 +29,10 @@ import static nu.pattern.OpenCV.loadShared;
*/
public class App {
/**
* Schriftart wird neu gesetzt
* @param f Schriftart
*/
private static void setUIFont(javax.swing.plaf.FontUIResource f) {
java.util.Enumeration<Object> keys = UIManager.getDefaults().keys();
while (keys.hasMoreElements()) {
@ -38,6 +44,10 @@ public class App {
}
}
/**
* Das LookAndFeel wird neu gesetzt.
* @param view View Klasse
*/
private static void setLookAndFeel(JFrame view) {
String[] laf = {"com.jtattoo.plaf.aluminium.AluminiumLookAndFeel",
"com.jtattoo.plaf.acryl.AcrylLookAndFeel",
@ -60,36 +70,9 @@ public class App {
SwingUtilities.updateComponentTreeUI(view);
}
static {
nu.pattern.OpenCV.loadShared();
System.loadLibrary(org.opencv.core.Core.NATIVE_LIBRARY_NAME);
}
public static void main(String[] args) {
final String[] options = {"Normal", "Benchmark"};
String chosen = (String) JOptionPane.showInputDialog(null,
"Bitte wählen Sie eine Ansicht!",
"Ausführungsoptionen",
JOptionPane.QUESTION_MESSAGE,
null,
options,
options[0]);
if (chosen == "Normal"){
final Presenter presenter = new Presenter(new LineModel(), null);
SwingUtilities.invokeLater(() -> {
//JFrame.setDefaultLookAndFeelDecorated(true);
MainFrame view = new MainFrame();
setLookAndFeel(view);
setUIFont(new javax.swing.plaf.FontUIResource(new Font("Verdana", Font.PLAIN, 12)));
view.setPresenter(presenter);
view.setActionListeners();
presenter.setView(view);
});} else {
benchmark();
}
}
/**
* Die Methode rechnet für gegebene Größen die Algorithmen durch und gibt jeweils die benötigte Zeit
*/
public static void benchmark() {
int[] sizes = {50, 500, 1000, 3000, 5000, 10000};
@ -97,27 +80,56 @@ public class App {
System.out.println("---- Datasetgröße: " + sizes[i] + " ----");
DatasetGenerator generator = new DatasetGenerator();
LinkedList<Line> lines = generator.generateDataCloud(sizes[i]);
// IntersectionComputer computer = new IntersectionComputer(lines);
// ArrayList<Point> points = computer.compute();
IntersectionComputer computer = new IntersectionComputer(lines);
ArrayList<Point> points = computer.compute();
//algorithms
//NaivLeastMedianOfSquaresEstimator naivLms = new NaivLeastMedianOfSquaresEstimator(lines);
//naivLms.run();
NaivLeastMedianOfSquaresEstimator naivLms = new NaivLeastMedianOfSquaresEstimator(lines);
naivLms.run();
// NaivRepeatedMedianEstimator naivRm = new NaivRepeatedMedianEstimator(lines);
// naivRm.run();
//
// NaivTheilSenEstimator naivTs = new NaivTheilSenEstimator(lines);
// naivTs.run();
NaivRepeatedMedianEstimator naivRm = new NaivRepeatedMedianEstimator(lines);
naivRm.run();
// LeastMedianOfSquaresEstimator lms = new LeastMedianOfSquaresEstimator(lines,points);
// lms.run();
NaivTheilSenEstimator naivTs = new NaivTheilSenEstimator(lines);
naivTs.run();
LeastMedianOfSquaresEstimator lms = new LeastMedianOfSquaresEstimator(lines,points);
lms.run();
RepeatedMedianEstimator rm = new RepeatedMedianEstimator(lines);
rm.run();
// TheilSenEstimator ts = new TheilSenEstimator(lines,points);
// ts.run();
TheilSenEstimator ts = new TheilSenEstimator(lines,points);
ts.run();
}
}
/**
* Laden der native Library für OpenCV
*/
static {
nu.pattern.OpenCV.loadShared();
System.loadLibrary(org.opencv.core.Core.NATIVE_LIBRARY_NAME);
}
/**
* Maim Methode
* @param args
*/
public static void main(String[] args) {
if (args.length > 0 && args[0] == "--benchmark"){
benchmark();
} else {
final Presenter presenter = new Presenter(new LineModel(), null);
SwingUtilities.invokeLater(() -> {
//JFrame.setDefaultLookAndFeelDecorated(true);
MainFrame view = new MainFrame();
setLookAndFeel(view);
setUIFont(new javax.swing.plaf.FontUIResource(new Font("SansSerif", Font.PLAIN, 12)));
view.setPresenter(presenter);
view.setActionListeners();
presenter.setView(view);
});
}
}

View File

@ -66,6 +66,9 @@ public class MainFrame extends JFrame {
private JTabbedPane tabbedPane;
private EvaluationPanel evaluationPanel;
/**
* Konstruktor
*/
public MainFrame() {
super();
initializeComponents();
@ -86,6 +89,9 @@ public class MainFrame extends JFrame {
* visualisierungs methoden
******************************************************************************************************************/
/**
* Erzeugt den Dialog für die duale Darstellung
*/
public void createDualityDialog() {
arrangement = new DualityPanel();
arrangementDialog = new JDialog();
@ -113,24 +119,47 @@ public class MainFrame extends JFrame {
});
}
/**
* Visualisiert das Ergebnis des LMS-Schätzers
* @param m Steigung
* @param b y-Achsenabschnitt
*/
public void visualizeLMS(double m, double b) {
plotLMS = new PlotPanel();
lmsPanel.setPlotPanel(plotLMS);
createPlot(m, b, plotLMS, lmsPanel, "LMS");
}
/**
* Visualisiert das Ergebnis des RM-Schätzers
* @param m Steigung
* @param b y-Achsenabschnitt
*/
public void visualizeRM(double m, double b) {
plotRM = new PlotPanel();
rmPanel.setPlotPanel(plotRM);
createPlot(m, b, plotRM, rmPanel, "RM");
}
/**
* Visualisiert das Ergebnis des TS-Schätzers
* @param m Steigung
* @param b y-Achsenabschnitt
*/
public void visualizeTS(double m, double b) {
plotTS = new PlotPanel();
tsPanel.setPlotPanel(plotTS);
createPlot(m, b, plotTS, tsPanel, "TS");
}
/**
* Erzeugt den Plot zu einer Eingabe von Punkten und der Lösung eines Schätzers (m,b)
* @param m Steigung
* @param b y-Achsenabschnitt
* @param plot Plot
* @param panel Panel auf dem der Plot plaziert wird
* @param name Bezeichnung der Gerade
*/
public void createPlot(double m, double b, PlotPanel plot, JPanel panel, String name) {
SwingUtilities.invokeLater(() -> {
plot.clear();
@ -140,19 +169,26 @@ public class MainFrame extends JFrame {
});
}
/**
* Visualisierung des Import-Prozesses
* @param progress akteulle Prozentzahl (0-100)
*/
public void showImportProgress(Integer progress) {
progressBar.setValue(progress);
progressBar.setStringPainted(true);
progressDialog.setVisible(true);
}
/**
* Zeigt den Evaluations-Dialog an (ggf. wird dieser erzeugt)
*/
public void showEvauluationDialog() {
if (evaluationDialog == null) {
SwingUtilities.invokeLater(() -> {
evaluationDialog = new JDialog();
evaluationDialog.setTitle("evaluation");
evaluationDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
evaluationDialog.setSize(new Dimension(1800, 800));
evaluationDialog.setSize(new Dimension(1500, 800));
evaluationDialog.setLocationRelativeTo(null);
evaluationPanel = new EvaluationPanel(this);
@ -169,6 +205,12 @@ public class MainFrame extends JFrame {
}
/**
* Fügt der Evaluations-Tabelle eine Spalte mit Daten hinzu
* @param res Daten der Spalte
* @param col Spalte
* @param isApprCol <code>true</code>, falls es sich um die Überschirften der Approximationsgüten handelt
*/
public void appendEvalResult(Object[] res, int col, boolean isApprCol) {
SwingUtilities.invokeLater(() -> {
Object[] tmp = Arrays.asList(res).subList(2, res.length).toArray();
@ -183,6 +225,10 @@ public class MainFrame extends JFrame {
});
}
/**
* Fügt der Evaluations-Tabelle eine Zeile mit Daten hinzu
* @param res Daten der Spalte
*/
public void appendEvalResult(Object[] res) {
SwingUtilities.invokeLater(() -> {
Object[] tmp = Arrays.asList(res).subList(1, res.length).toArray();
@ -192,6 +238,11 @@ public class MainFrame extends JFrame {
});
}
/**
* Visualisiert die Ausgleichsgerade zu gegebenen Algorithmen
* @param res Steigungen und y-Achsenabschnitte
* @param alg Kodierung der Alg.
*/
public void drawLineResult(Object[] res, int alg) {
SwingUtilities.invokeLater(() -> {
Object[] result = Arrays.asList(res).subList(2, res.length).toArray();
@ -201,6 +252,10 @@ public class MainFrame extends JFrame {
});
}
/**
* Visualisiert die Ausgleichsgerade zu einem gegebenen Algorithmus
* @param res Steigungen und y-Achsenabschnitte
*/
public void drawLineResults(Object[] res) {
SwingUtilities.invokeLater(() -> {
Object[] result = Arrays.asList(res).subList(1, res.length).toArray();
@ -220,6 +275,10 @@ public class MainFrame extends JFrame {
});
}
/**
* Evaluations-Datensätze werden Visualisiert
* @param lines Liste der Geraden
*/
public void addEvalDataset(LinkedList<Line> lines) {
SwingUtilities.invokeLater(() -> {
evaluationPanel.setDualPoints(lines);
@ -232,6 +291,10 @@ public class MainFrame extends JFrame {
/*******************************************************************************************************************
* init GUI
******************************************************************************************************************/
/**
* Setzt den Titel der Komponenten
*/
private void setTitles() {
this.setTitle("Algorithmen zur Berechnung von Ausgleichgeraden");
importButton.setText("Import");
@ -240,12 +303,18 @@ public class MainFrame extends JFrame {
arrangementButton.setText("Dualraum");
}
/**
* Fügt die einzelnen Seiten dem TabbedPane hinzu
*/
private void setupTabbedPane() {
tabbedPane.add("Least Median of Squares", lmsPanel);
tabbedPane.add("Repeated Median", rmPanel);
tabbedPane.add("Theil-Sen", tsPanel);
}
/**
* Komponenten werden in Container gesetzt
*/
private void addComponents() {
toolBar.add(arrangementButton);
toolBar.add(importButton);
@ -267,9 +336,11 @@ public class MainFrame extends JFrame {
this.add(toolBar, BorderLayout.NORTH);
this.add(splitpane, BorderLayout.CENTER);
}
/**
* Konfiguration des SplitPane
*/
private void setupSplitPane() {
splitpane.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
splitpane.setResizeWeight(.5d);
@ -278,14 +349,19 @@ public class MainFrame extends JFrame {
splitpane.setRightComponent(tabbedPane);
}
/**
* Fenster Funktionalität wird gesetzt
*/
private void setCloseOperations() {
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
progressDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
}
/**
* Größen der Komponenten werden gesetzt
*/
private void setDimensions() {
this.setPreferredSize(new Dimension(1600,1050));
this.setMinimumSize(new Dimension(1024, 768));
this.setSize(new Dimension(1500, 800));
this.setResizable(true);
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
this.setMaximizedBounds(env.getMaximumWindowBounds());
@ -298,11 +374,17 @@ public class MainFrame extends JFrame {
progressDialog.setUndecorated(true);
}
/**
* Setzen der Layouts
*/
private void setLayouts() {
this.setLayout(new BorderLayout());
toolBar.setLayout(new FlowLayout(FlowLayout.LEFT));
}
/**
* Initialisierung der Komponenten
*/
private void initializeComponents() {
//panels
toolBar = new JToolBar();
@ -330,6 +412,9 @@ public class MainFrame extends JFrame {
pack();
}
/**
* Icons werden passend gesetzt
*/
private void setIcons() {
try {
ClassLoader classLoader = getClass().getClassLoader();
@ -340,7 +425,6 @@ public class MainFrame extends JFrame {
Image imgExport = ImageIO.read(classLoader.getResource("export.png")).getScaledInstance(16, 16, Image.SCALE_SMOOTH);
Image imgFrame = ImageIO.read(classLoader.getResource("frame.png")).getScaledInstance(32, 23, Image.SCALE_SMOOTH);
importButton.setIcon(new ImageIcon(imgImport));
exportButton.setIcon(new ImageIcon(imgExport));
generateButton.setIcon(new ImageIcon(imgGenerate));
@ -354,8 +438,10 @@ public class MainFrame extends JFrame {
}
}
/**
* Funktionalitäten werden hinzugefügt
*/
public void setActionListeners() {
//action listener für MenuItems
menu.addActionListeners();
@ -370,6 +456,9 @@ public class MainFrame extends JFrame {
}
/**
* Funktionalitäten werden aktiviert.
*/
public void enableFunctionality() {
this.getLmsPanel().getStartButton().setEnabled(true);
this.getRmPanel().getStartButton().setEnabled(true);
@ -378,6 +467,9 @@ public class MainFrame extends JFrame {
this.getExportButton().setEnabled(true);
}
/**
* Funktionalitäten werden deaktiviert.
*/
public void disableFunctionality() {
this.getLmsPanel().getStartButton().setEnabled(false);
this.getRmPanel().getStartButton().setEnabled(false);
@ -389,22 +481,39 @@ public class MainFrame extends JFrame {
/*******************************************************************************************************************
* log Methode
******************************************************************************************************************/
/**
* @param s Text der ausgegeben wird
*/
public void log(String s) {
SwingUtilities.invokeLater(() -> output.appendParagraph(s));
}
/**
* @param s Fehlertext der ausgegeben wird
*/
public void logError(String s) {
SwingUtilities.invokeLater(() -> output.appendParagraphRed(s));
}
/**
* @param s Text der in grüner Farbe ausgegeben wird
*/
public void logSuccess(String s) {
SwingUtilities.invokeLater(() -> output.appendParagraphGreen(s));
}
/**
* @param s Text der als Überschrift ausgegeben wird
*/
public void logHeading(String s) {
SwingUtilities.invokeLater(() -> output.appendParagraphWithHeading(s));
}
/**
* Ausgabe einer Tabelle
* @param heading Überschrift
* @param rows Zeilen mit Text
*/
public void createTable(List<String> heading, List<List<String>> rows) {
SwingUtilities.invokeLater(() -> output.logTable(heading, rows));
}
@ -413,139 +522,59 @@ public class MainFrame extends JFrame {
* Getter und Setter Methoden
******************************************************************************************************************/
public Boolean getLmsIsComplete() {
return lmsIsComplete;
}
public void setLmsIsComplete(Boolean lmsIsComplete) {
this.lmsIsComplete = lmsIsComplete;
}
public Boolean getRmIsComplete() {
return rmIsComplete;
}
public void setRmIsComplete(Boolean rmIsComplete) {
this.rmIsComplete = rmIsComplete;
}
public Boolean getTsIsComplete() {
return tsIsComplete;
}
public void setTsIsComplete(Boolean tsIsComplete) {
this.tsIsComplete = tsIsComplete;
}
/**
* @return liefert den Button, zum visualisieren des dualen Raums zurück
*/
public JButton getArrangementButton() {
return arrangementButton;
}
public void setArrangementButton(JButton arrangementButton) {
this.arrangementButton = arrangementButton;
}
public JButton getImportButton() {
return importButton;
}
public void setImportButton(JButton importButton) {
this.importButton = importButton;
}
public JToolBar getToolBar() {
return toolBar;
}
public void setToolBar(JToolBar toolBar) {
this.toolBar = toolBar;
}
public JDialog getArrangementDialog() {
return arrangementDialog;
}
public void setArrangementDialog(JDialog arrangementDialog) {
this.arrangementDialog = arrangementDialog;
}
public InfoPanel getOutput() {
return output;
}
public void setOutput(InfoPanel output) {
this.output = output;
}
public MenuBar getMenu() {
return menu;
}
/**
* @return liefert das Panel zum visualisieren des LMS-Schätzers
*/
public TabPanel getLmsPanel() {
return lmsPanel;
}
public JSplitPane getSplitpane() {
return splitpane;
}
public void setSplitpane(JSplitPane splitpane) {
this.splitpane = splitpane;
}
public JScrollPane getScrollPane() {
return scrollPane;
}
public void setScrollPane(JScrollPane scrollPane) {
this.scrollPane = scrollPane;
}
/**
* @return liefert das Panel zum visualisieren des RM-Schätzers
*/
public TabPanel getRmPanel() {
return rmPanel;
}
public void setRmPanel(TabPanel rmPanel) {
this.rmPanel = rmPanel;
}
public PlotPanel getPlotLMS() {
return plotLMS;
}
public void setPlotLMS(PlotPanel plotLMS) {
this.plotLMS = plotLMS;
}
/**
* @return liefert die Instanz des Presenters zurück
*/
public AbstractPresenter getPresenter() {
return presenter;
}
/**
* @param presenter Presenter Instanz
*/
public void setPresenter(AbstractPresenter presenter) {
this.presenter = presenter;
}
/**
* @return liefert den Dialog zum visualisieren des Import-Fortschrits
*/
public JDialog getProgressDialog() {
return progressDialog;
}
public void setProgressDialog(JDialog progressDialog) {
this.progressDialog = progressDialog;
}
/**
* @return liefert das Panel zum visualisieren des TS-Schätzers
*/
public TabPanel getTsPanel() {
return tsPanel;
}
public void setTsPanel(TabPanel tsPanel) {
this.tsPanel = tsPanel;
}
/**
* @return liefert den Button, exportieren zurück
*/
public JButton getExportButton() {
return exportButton;
}
public void setExportButton(JButton exportButton) {
this.exportButton = exportButton;
}
}

View File

@ -33,6 +33,10 @@ public class MenuBar {
private JMenuItem aboutItem;
private JMenuItem importPicture;
/**
* Konstruktor
* @param view View
*/
public MenuBar(MainFrame view) {
this.menuBar = new JMenuBar();
this.view = view;
@ -67,6 +71,9 @@ public class MenuBar {
menuBar.add(aboutMenu);
}
/**
* Fügt den Komponenten Funktionalitäten hinzu
*/
public void addActionListeners() {
this.exitItem.addActionListener(e -> {
System.exit(0);
@ -90,6 +97,9 @@ public class MenuBar {
}
/**
* @return liefert die MenuBar Instanz zurück
*/
public JMenuBar getMenuBar() {
return menuBar;
}

View File

@ -17,6 +17,10 @@ public class DualityVisualizerListener implements ActionListener {
private Presenter presenter;
/**
* Konstruktor
* @param presenter Presenter
*/
public DualityVisualizerListener(Presenter presenter) {
this.presenter = presenter;
}

View File

@ -22,6 +22,11 @@ public class ExportDataListener implements ActionListener {
private Presenter presenter;
private Container component;
/**
* Konstruktor
* @param presenter Presenter
* @param component visuelle Elternkomponente
*/
public ExportDataListener(Presenter presenter, Container component) {
this.presenter = presenter;
this.component = component;

View File

@ -23,15 +23,17 @@ public class GenerateDataListener implements ActionListener {
private Presenter presenter;
private JDialog dialog;
/**
* Konstruktor
* @param presenter Presenter
*/
public GenerateDataListener(Presenter presenter) {
this.presenter = presenter;
}
@Override
public void actionPerformed(ActionEvent e) {
SwingUtilities.invokeLater(() -> {
if (dialog == null || !dialog.isVisible()) {
dialog = new JDialog();
dialog.setTitle("generiere Datensatz");

View File

@ -22,6 +22,11 @@ public class ImportDataListener implements ActionListener {
private Presenter presenter;
private Container component;
/**
* Konstruktor
* @param presenter Presenter
* @param component visuelle Elternkomponente
*/
public ImportDataListener(Presenter presenter, Container component) {
this.presenter = presenter;
this.component = component;

View File

@ -21,6 +21,11 @@ public class PictureImportListener implements ActionListener {
private Presenter presenter;
private Container component;
/**
* Konstruktor
* @param presenter Presenter
* @param component visuelle Elternkomponente
*/
public PictureImportListener(Presenter presenter, Container component) {
this.presenter = presenter;
this.component = component;

View File

@ -21,6 +21,11 @@ public class StartAlgorithmListener implements ActionListener {
private Presenter presenter;
private TabPanel tabPanel;
/**
* Konstruktor
* @param presenter Presenter
* @param tabPanel Algorithmus Visualisierungskomponente
*/
public StartAlgorithmListener(Presenter presenter, TabPanel tabPanel) {
this.presenter = presenter;
this.tabPanel = tabPanel;

View File

@ -19,6 +19,9 @@ public class AboutPanel extends JPanel {
private JPanel contentPane;
private ImageIcon image;
/**
* Konstruktor
*/
public AboutPanel() {
super();
this.setSize(new Dimension(410, 400));

View File

@ -44,10 +44,12 @@ public class DualityPanel extends JPanel {
private ValueAxis range;
private Double delta = 1d;
private Boolean ctrlPressed = false;
private Boolean shiftPressed = false;
/**
* Konstruktor
*/
public DualityPanel() {
super();
this.setPreferredSize(new Dimension(800, 800));
@ -55,6 +57,15 @@ public class DualityPanel extends JPanel {
this.setLayout(new BorderLayout());
}
/**
* Hilfsmethode um die Parameter im einem Schritt zu setzen
* @param lines Liste der Geraden
* @param points Liste der Schnittpunkte
* @param xmin minimale x-Koordinate
* @param xmax maximale x-Koordinate
* @param ymin minimale y-Koordinate
* @param ymax maximale y-Koordinate
*/
public void setPrameters(LinkedList<Line> lines, ArrayList<Point> points, Double xmin, Double xmax, Double ymin, Double ymax) {
this.lines = new LinkedList<>(lines);
this.points = new LinkedList<>(points);
@ -64,6 +75,9 @@ public class DualityPanel extends JPanel {
this.rangeMax = ymax;
}
/**
* Die Methode erzeugt ein Arrangement von Geraden.
*/
public void createArrangement() {
dataset = new XYSeriesCollection();
@ -135,6 +149,10 @@ public class DualityPanel extends JPanel {
this.add(panel, BorderLayout.CENTER);
}
/**
* Hilfmethode für die Zoom-Funktion im Panel
* @param component Komponente
*/
public void addKeyListener(JComponent component) {
component.addKeyListener(new KeyListener() {
@Override
@ -160,10 +178,15 @@ public class DualityPanel extends JPanel {
});
}
/**
* Zoom-Funktionalität für das Panel
* @param chartPanel
*/
protected void addZooming(ChartPanel chartPanel) {
chartPanel.addMouseWheelListener(new MouseWheelListener() {
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
Double min;
@ -188,13 +211,20 @@ public class DualityPanel extends JPanel {
if (e.getScrollType() != MouseWheelEvent.WHEEL_UNIT_SCROLL)
return;
if (e.getWheelRotation() < 0)
increaseZoom((ChartPanel) e.getComponent(), true, x, y);
increaseZoom((ChartPanel) e.getComponent());
else
decreaseZoom((ChartPanel) e.getComponent(), true, x, y);
decreaseZoom((ChartPanel) e.getComponent());
}
}
/**
* Bewegung im Panel
* @param val Bewegung
* @param min minimale Wert
* @param max maximale Wert
* @return aktuell Sichtbare Teil des Panels
*/
private DateRange move(Double val, Double min, Double max) {
Double minimum = min;
Double maximum = max;
@ -206,17 +236,30 @@ public class DualityPanel extends JPanel {
return new DateRange(minimum, maximum);
}
public synchronized void increaseZoom(JComponent chart, boolean saveAction, Double x, Double y) {
/**
* Reinzoomen
* @param chart chart
*/
public synchronized void increaseZoom(JComponent chart) {
ChartPanel ch = (ChartPanel) chart;
zoomChartAxis(ch, true, x, y);
zoomChartAxis(ch, true);
}
public synchronized void decreaseZoom(JComponent chart, boolean saveAction, Double x, Double y) {
/**
* Rauszoomen
* @param chart chart
*/
public synchronized void decreaseZoom(JComponent chart) {
ChartPanel ch = (ChartPanel) chart;
zoomChartAxis(ch, false, x, y);
zoomChartAxis(ch, false);
}
private void zoomChartAxis(ChartPanel chartP, boolean increase, Double x, Double y) {
/**
* Zoom
* @param chartP
* @param increase
*/
private void zoomChartAxis(ChartPanel chartP, boolean increase) {
int width = chartP.getMaximumDrawWidth() - chartP.getMinimumDrawWidth();
int height = chartP.getMaximumDrawHeight() - chartP.getMinimumDrawWidth();
if (increase) {
@ -229,6 +272,9 @@ public class DualityPanel extends JPanel {
});
}
/**
* Datensatz leeren
*/
public void clear() {
if (dataset != null)
dataset.removeAllSeries();

View File

@ -10,6 +10,8 @@ import javax.swing.*;
import javax.swing.border.TitledBorder;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.filechooser.FileSystemView;
import javax.swing.plaf.FontUIResource;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableColumn;
@ -59,6 +61,10 @@ public class EvaluationPanel extends JPanel {
private PlotPanel plotPanel;
private String[] selections = {"Approximationsgüte", "Least Median of Squares", "Repeated-Median", "Theil-Sen"};
/**
* Konstruktor
* @param view View
*/
public EvaluationPanel(MainFrame view) {
super();
this.view = view;
@ -71,6 +77,9 @@ public class EvaluationPanel extends JPanel {
}
/**
* Initialisiere die Komponenten
*/
private void init() {
datasetCountLabel = new JLabel("Größe des Datensatzes");
Integer[] choice = {50, 100, 200, 500, 1000, 1500};
@ -116,6 +125,9 @@ public class EvaluationPanel extends JPanel {
}
/**
* Hinzufügen der Komponenten zum ContentPane
*/
private void addComponents() {
evalTypeOne.setSelected(true);
lms.setSelected(true);
@ -144,10 +156,8 @@ public class EvaluationPanel extends JPanel {
comp.add(algorithmPanel);
comp.add(datasetCount);
comp.setBorder(new TitledBorder("Konfiguration"));
//Tabelle
model.setColumnIdentifiers(selections);
table.setDragEnabled(true);
@ -176,8 +186,17 @@ public class EvaluationPanel extends JPanel {
TableColumn tm = table.getColumnModel().getColumn(0);
tm.setCellRenderer(new ColorColumnRenderer(Color.lightGray, Color.blue));
for (int i=1;i<4;i++){
DefaultTableCellRenderer rightRenderer = new DefaultTableCellRenderer();
rightRenderer.setHorizontalAlignment(SwingConstants.RIGHT);
rightRenderer.setFont(new FontUIResource("Courier", Font.PLAIN, 12));
table.getColumnModel().getColumn(i).setCellRenderer(rightRenderer);
}
}
/**
* Hinzufügen der Listener
*/
private void addListener() {
start.addActionListener(e -> {
int type;
@ -201,7 +220,6 @@ public class EvaluationPanel extends JPanel {
chooser.setMultiSelectionEnabled(false);
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
//System.out.println ("Datei "+chooser.getSelectedFile()+ " ausgewählt.");
file = chooser.getSelectedFile();
@ -290,7 +308,6 @@ public class EvaluationPanel extends JPanel {
if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
//System.out.println ("Datei "+chooser.getSelectedFile()+ " ausgewählt.");
file = chooser.getSelectedFile();
String filename = file.getAbsolutePath().contains(".csv") ? file.getAbsolutePath() : file.getAbsolutePath().concat(".csv");
File withExtension = new File(filename);
@ -305,8 +322,15 @@ public class EvaluationPanel extends JPanel {
}
public void addColumn(Object[] data, int col, boolean b) {
if (b) {
/**
* Fügt der Tabelle eine Spalte hinzu
*
* @param data Daten der Spalte
* @param col Spalte
* @param isLabel <code>true</code>, falls es sich um die Approximations Überschriften handelt
*/
public void addColumn(Object[] data, int col, boolean isLabel) {
if (isLabel) {
addBlankRows(data.length);
}
for (int i = 0; i < data.length; i++) {
@ -317,6 +341,10 @@ public class EvaluationPanel extends JPanel {
this.revalidate();
}
/**
* Fügt der Tabelle eine Zeile hinzu
* @param data Daten der Zeile
*/
public void addRow(Object[] data) {
addBlankRows(1);
for (int i = 0; i < 4; i++) {
@ -328,6 +356,10 @@ public class EvaluationPanel extends JPanel {
this.revalidate();
}
/**
* Visualisierung der Ausgleichsgeraden
* @param alg Steigung und y-Achsenabschnitt der Geraden, bestimmt durch die Schätzer
*/
public void drawLines(ArrayList<Double[]> alg) {
Paint[] color = {Color.ORANGE, Color.RED, Color.MAGENTA};
String[] name = {"LMS", "RM", "TS"};
@ -340,6 +372,11 @@ public class EvaluationPanel extends JPanel {
}
}
/**
* Visualisierung der Ausgleichsgerade
* @param results Steigung und y-Achsenabschnitt der Gerade, bestimmt durch die Schätzer
* @param alg identifizierung des Alg.
*/
public void drawLines(Object[] results, int alg) {
String[] castedResults = Arrays.copyOf(results, results.length, String[].class);
Paint[] color = {Color.ORANGE, Color.RED, Color.MAGENTA};
@ -355,6 +392,10 @@ public class EvaluationPanel extends JPanel {
plotPanel.addLineToPlot(nM, nB, Color.BLACK, nName[alg]);
}
/**
* Visualisierung der dualen Geraden (Eingabemenge)
* @param points Liste der Geraden
*/
public void setDualPoints(LinkedList<Line> points) {
plotPanel = new PlotPanel();
plotPanel.setBorder(new TitledBorder("Plot"));
@ -364,6 +405,10 @@ public class EvaluationPanel extends JPanel {
plotPanel.revalidate();
}
/**
* Hilfsmethode
* @param n Anzahl der leeren Zeilen
*/
private void addBlankRows(int n) {
for (int i = 0; i < n; i++) {
String[] tmp = {"", "", "", "",};
@ -371,11 +416,17 @@ public class EvaluationPanel extends JPanel {
}
}
/**
* Hilfsmethode
* @param val Anzahl der Zeilen die noch hinzugefügt werden
*/
public void setCurrentRow(int val) {
this.currentRowOfTypes += val;
}
/**
* @return Kodierung welche Algorithmen ausgewählt wurden
*/
private int checkSelection() {
if (lms.isSelected() && rm.isSelected() && ts.isSelected()) {
return 6;

View File

@ -18,6 +18,9 @@ public class InfoPanel extends JPanel {
private JScrollPane scrollPane;
private StringBuilder content;
/**
* Konstruktor
*/
public InfoPanel() {
this.setBorder(new TitledBorder("Ausgabekanal"));
this.setLayout(new BorderLayout());
@ -33,35 +36,47 @@ public class InfoPanel extends JPanel {
}
/**
* Fügt eine Text dem Panel als Paragraph hinzu
* @param p Übergebener Text
*/
public void appendParagraph(String p) {
content.append("<p>" + p + "</p>");
output.setText(content.toString());
}
/**
* Fügt eine Überschrift dem Panel hinzu
* @param h1 Überschrift
*/
public void appendParagraphWithHeading(String h1) {
content.append("<h1>" + h1 + "</h1>");
output.setText(content.toString());
}
/**
* Fügt einen Text in roter Schrift als Paragraph dem Panel hinzu
* @param p Text
*/
public void appendParagraphRed(String p) {
content.append("<p style=\" color:red \"><em><strong>" + p + "</strong></em></p>");
output.setText(content.toString());
}
/**
* Fügt einen Text in grüner Schrift als Paragraph dem Panel hinzu
* @param p Text
*/
public void appendParagraphGreen(String p) {
content.append("<p style=\" color:green \"><em><strong>" + p + "</strong></em></p>");
output.setText(content.toString());
}
/**
* Fügt eine Tabelle mit Werten dem Panel hinzu
* @param heading Überschriften
* @param rows Liste von Daten pro Zeile
*/
public void logTable(List<String> heading, List<List<String>> rows) {
content.append("<center>");
content.append("<table style=\" width:80%; border: 1px solid black; \">");

View File

@ -37,12 +37,19 @@ public class PlotPanel extends JPanel {
private XYLineAndShapeRenderer renderer;
private Shape diamond;
/**
* Konstruktor
*/
public PlotPanel() {
super();
this.setLayout(new BorderLayout());
seriesCount = 1;
}
/**
* Erzeugen des Plots
* @param points Liste der Geraden
*/
public void createPlot(LinkedList<Line> points) {
if (!points.isEmpty()) {
try {
@ -86,11 +93,21 @@ public class PlotPanel extends JPanel {
this.add(panel, BorderLayout.CENTER);
}
/**
* Leeren des Datensatzes
*/
public void clear() {
if (datapoints != null)
datapoints.removeAllSeries();
}
/**
* Fügt eine Gerade zum Plot hinzu
* @param m Steigung
* @param b y-Achsenabschnitt
* @param color Farbe
* @param name Bezeichner
*/
public void addLineToPlot(double m, double b, Paint color, String name) {
XYSeries linesA = new XYSeries(name);
@ -104,13 +121,15 @@ public class PlotPanel extends JPanel {
renderer.setBaseSeriesVisible(true);
renderer.setSeriesLinesVisible(seriesCount, true);
seriesCount++;
}
/**
* Fügt eine Gerade zum Plot hinzu
* @param m Steigung
* @param b y-Achsenabschnitt
* @param name Bezeichner
*/
public void addLineToPlot(double m, double b, String name) {
XYSeries linesA = new XYSeries(name);
linesA.add(min.doubleValue(), min * m + b);
linesA.add(max.doubleValue(), max * m + b);
@ -123,6 +142,10 @@ public class PlotPanel extends JPanel {
renderer.setSeriesLinesVisible(seriesCount, true);
}
/**
* Wandelt die Daten in ein passendes Format um
* @param points Liste der Geraden
*/
private void convertData(LinkedList<Line> points) {
datapoints = new XYSeriesCollection();
ArrayList<Double> coordinates = new ArrayList<>();

View File

@ -19,6 +19,9 @@ public class LMSPanel extends TabPanel {
private GridBagConstraints gbc;
/**
* Konstruktor
*/
public LMSPanel() {
super();
this.labels = new JLabel[2];
@ -64,6 +67,11 @@ public class LMSPanel extends TabPanel {
continer.add(this.input[row], gbc);
}
/**
* Hilftmethode um einen Botton an die passende Stelle zu platzieren
* @param row Zeile
* @param button Button
*/
private void addButton(int row, JButton button) {
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
@ -79,7 +87,10 @@ public class LMSPanel extends TabPanel {
continer.add(buttonPanel, gbc);
}
/**
* Liefert die Eingaben in Form eines Feldes zurück. Die Parameter werden für den Alg. benötigt.
* @return Eingabe
*/
public String[] getInput() {
String[] input = new String[3];
input[0] = this.input[0].getText();
@ -93,12 +104,4 @@ public class LMSPanel extends TabPanel {
}
}
public boolean isNumeric(String str) {
try {
double d = Double.parseDouble(str);
} catch (NumberFormatException nfe) {
return false;
}
return true;
}
}

View File

@ -17,6 +17,9 @@ public class RMPanel extends TabPanel {
private JPanel continer;
private GridBagConstraints gbc;
/**
* Konstruktor
*/
public RMPanel() {
super();
this.labels = new JLabel();
@ -72,7 +75,10 @@ public class RMPanel extends TabPanel {
continer.add(this.input, gbc);
}
/**
* Liefert die Eingabe zurück. Der Parameter wird für den Alg. benötigt.
* @return Eingabe
*/
public String getInput() {
String input = "";
input = this.input.getText();
@ -82,18 +88,4 @@ public class RMPanel extends TabPanel {
JOptionPane.showMessageDialog(this, "Bitte geben Sie numerische Werte als Parameter an.", "Fehler bei der Eingabe", JOptionPane.ERROR_MESSAGE);
return null;
}
public void setInput(JTextField input) {
this.input = input;
}
public boolean isNumeric(String str) {
try {
double d = Double.parseDouble(str);
} catch (NumberFormatException nfe) {
return false;
}
return true;
}
}

View File

@ -16,6 +16,9 @@ public class TSPanel extends TabPanel {
private JPanel continer;
private GridBagConstraints gbc;
/**
* Konstruktor
*/
public TSPanel() {
super();

View File

@ -22,6 +22,9 @@ public abstract class TabPanel extends JPanel {
private JButton startButton;
/**
* Konstruktor
*/
public TabPanel() {
super();
this.centerPanel = new JPanel(new BorderLayout());
@ -38,17 +41,23 @@ public abstract class TabPanel extends JPanel {
this.add(northPanel, BorderLayout.NORTH);
this.startButton = new JButton("Start");
this.startButton.setFont(new Font("Verdana", Font.PLAIN, 16));
this.startButton.setFont(new Font("SansSerif", Font.PLAIN, 16));
}
/**
* Fügt in eine Zeile ein Überschrift(JLabel) und eine Eingabekomponente(JTextField)
* @param row Zeile
* @param name Überschrift
* @param value Standardwert
*/
protected void addTextfieldAndInput(int row, String name, Double value) {
//muss nicht obligatorisch implementiert werden
}
public PlotPanel getPlotPanel() {
return plotPanel;
}
/**
* Hilftmethode um den Plotpanel erst bei Vorhandenen Ergebnissen hinzufügen zu können
* @param plotPanel Plotpanel
*/
public void setPlotPanel(PlotPanel plotPanel) {
this.plotPanel = plotPanel;
if (this.centerPanel.getComponents().length > 0)
@ -60,27 +69,38 @@ public abstract class TabPanel extends JPanel {
this.revalidate();
}
/**
* @return gibt den Startbutton zurück
*/
public JButton getStartButton() {
return startButton;
}
public void setStartButton(JButton startButton) {
this.startButton = startButton;
}
/**
* @return gibt das obere Panel zurück
*/
public JPanel getNorthPanel() {
return northPanel;
}
public void setNorthPanel(JPanel northPanel) {
this.northPanel = northPanel;
}
/**
* @return gibt das untere Panel zurück
*/
public JPanel getCenterPanel() {
return centerPanel;
}
public void setCenterPanel(JPanel centerPanel) {
this.centerPanel = centerPanel;
/**
* Hilfmethode zum prüfen ob die Eingabe numerisch ist.
* @param str Eingabe
* @return <code>true</code>, falls es sich bei der Eingabe um numerische Werte handelt
*/
public boolean isNumeric(String str) {
try {
double d = Double.parseDouble(str);
} catch (NumberFormatException nfe) {
return false;
}
return true;
}
}