112 lines
3.1 KiB
Java
112 lines
3.1 KiB
Java
package de.wwwu.awolf.view.panels;
|
|
|
|
import javax.swing.*;
|
|
import javax.swing.border.TitledBorder;
|
|
import java.awt.*;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
|
|
*
|
|
* @Author: Armin Wolf
|
|
* @Email: a_wolf28@uni-muenster.de
|
|
* @Date: 02.06.2017.
|
|
*/
|
|
public class InfoPanel extends JPanel {
|
|
|
|
private JTextPane output;
|
|
private JScrollPane scrollPane;
|
|
private StringBuilder content;
|
|
|
|
/**
|
|
* Konstruktor
|
|
*/
|
|
public InfoPanel() {
|
|
this.setBorder(new TitledBorder("Ausgabekanal"));
|
|
this.setLayout(new BorderLayout());
|
|
output = new JTextPane();
|
|
output.setEditable(false);
|
|
output.setContentType("text/html");
|
|
|
|
content = new StringBuilder();
|
|
|
|
scrollPane = new JScrollPane(output);
|
|
scrollPane.setWheelScrollingEnabled(true);
|
|
this.add(scrollPane, BorderLayout.CENTER);
|
|
|
|
}
|
|
|
|
/**
|
|
* 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; \">");
|
|
content.append("<tr>");
|
|
if (heading.size() > 1) {
|
|
for (String str : heading) {
|
|
content.append("<th style=\" border: 1px solid black; \">" + str + "</th>");
|
|
}
|
|
} else {
|
|
content.append("<th style=\" border: 1px solid black;\" colspan=\"" + rows.get(0).size() + "\"; >" + heading.get(0) + "</th>");
|
|
}
|
|
|
|
content.append("</tr>");
|
|
for (List<String> row : rows) {
|
|
content.append("<tr>");
|
|
for (String entry : row) {
|
|
content.append("<td style=\" border: 1px solid black; \">" + entry + "</td>");
|
|
}
|
|
content.append("</tr>");
|
|
}
|
|
content.append("</table>");
|
|
content.append("</center>");
|
|
output.setText(content.toString());
|
|
}
|
|
|
|
|
|
}
|