TextArea durch JTextPane ersetzt um HTML anzeigen zu können, was eine Ausgabe der Werte [formatiert] leichter macht.

This commit is contained in:
Armin Wolf 2017-06-03 14:06:43 +02:00
parent 753c198853
commit 994a288e84
4 changed files with 117 additions and 22 deletions

View File

@ -6,6 +6,7 @@ import View.MainFrame;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
/**
@ -35,18 +36,27 @@ public class Presenter {
// Float[] y = {18f,26f,30f,40f,70f};
// Double[] x = {1d,3d,4d,5d,8d};
// Double[] y = {4d,2d,1d,0d,0d};
view.log("Koordinaten der Punkte:");
view.logHeading("Dualen Geraden");
for (int j = 0; j < 7; j++) {
Coordinates p = new Coordinates(x[j], y[j]);
view.log("f(x) = " + p.getX() + "* x + " + p.getY());
view.log("f(x) = " + p.getX() + "x + " + p.getY());
this.model.addLine(p);
}
view.log("");
calcArrangementNodes();
//print
List<String> heading = new LinkedList<>();
List<List<String>> rows = new LinkedList<>();
heading.add("X - Koordinate");
heading.add("Y - Koordinate");
for (Coordinates p : model.getNodes()) {
view.log(p.getX() + ", " + p.getY());
LinkedList<String> rowEntry = new LinkedList<>();
rowEntry.add(p.getX().toString());
rowEntry.add(p.getY().toString());
rows.add(rowEntry);
}
view.logHeading("Koordinaten der Punkte");
view.createTable(heading, rows);
view.logSuccess("Berechnung wurde Erfolgreich durchgeführt");
extractBounds();
}

View File

@ -4,10 +4,8 @@ package View;
import Presenter.Presenter;
import javax.swing.*;
import javax.swing.border.TitledBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
/**
* Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
@ -94,7 +92,7 @@ public class MainFrame extends JFrame {
*/
protected void initGUI() {
this.setTitle("MainFrame");
this.setSize(1000, 700);
this.setSize(1900, 1000);
this.setLayout(new BorderLayout());
pane = new JPanel();
sidepanel = new SidePanel();
@ -134,7 +132,7 @@ public class MainFrame extends JFrame {
pane.add(plotButton);
pane.add(button3);
splitpane.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
splitpane.setDividerLocation(0.2);
splitpane.setResizeWeight(.5d);
splitpane.setContinuousLayout(true);
splitpane.setLeftComponent(output);
splitpane.setRightComponent(sidepanel);
@ -152,6 +150,24 @@ public class MainFrame extends JFrame {
*/
public void log(String s) {
SwingUtilities.invokeLater(() -> output.append(s));
SwingUtilities.invokeLater(() -> output.appendParagraph(s));
}
public void logError(String s){
SwingUtilities.invokeLater(() -> output.appendParagraphRed(s));
}
public void logSuccess(String s){
SwingUtilities.invokeLater(() -> output.appendParagraphGreen(s));
}
public void logHeading(String s){
SwingUtilities.invokeLater(() -> output.appendParagraphWithHeading(s));
}
public void createTable(List<String> heading, List<List<String>> rows){
SwingUtilities.invokeLater(() -> output.logTable(heading, rows));
}
}

View File

@ -3,7 +3,7 @@ package View;
import javax.swing.*;
import javax.swing.border.TitledBorder;
import java.awt.*;
import java.util.List;
/**
* Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
*
@ -13,17 +13,20 @@ import java.awt.*;
*/
public class OutputPanel extends JPanel {
private JTextArea output;
private JTextPane output;
private JScrollPane scrollPane;
private StringBuilder content;
public OutputPanel(){
this.setBorder(new TitledBorder("Ausgabekanal"));
this.setLayout(new BorderLayout());
output = new JTextArea();
output = new JTextPane();
output.setEditable(false);
output.setLineWrap(true);
output.setWrapStyleWord(true);
output.setContentType("text/html");
content = new StringBuilder();
scrollPane = new JScrollPane(output);
scrollPane.setWheelScrollingEnabled(true);
this.add(scrollPane, BorderLayout.CENTER);
@ -31,8 +34,52 @@ public class OutputPanel extends JPanel {
}
public void append(String s) {
output.append(s + "\n");
public void appendParagraph(String p) {
content.append("<p>" + p + "</p></br>");
output.setText(content.toString());
}
public void appendParagraphWithHeading(String h1){
content.append("<h1>"+ h1 + "</h1></br>");
output.setText(content.toString());
}
public void appendParagraphRed(String p) {
content.append("<p style=\" color:red \"><em><strong>" + p + "</strong></em></p></br>");
output.setText(content.toString());
}
public void appendParagraphGreen(String p) {
content.append("<p style=\" color:green \"><em><strong>" + p + "</strong></em></p></br>");
output.setText(content.toString());
}
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>");
for (String str : heading) {
content.append("<th style=\" border: 1px solid black; \">" + str + "</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());
}
}

View File

@ -1,6 +1,7 @@
package View;
import javax.swing.*;
import javax.swing.border.LineBorder;
import javax.swing.border.MatteBorder;
import javax.swing.border.TitledBorder;
import java.awt.*;
@ -17,21 +18,42 @@ public class SidePanel extends JPanel {
private JLabel[] labels;
private JTextField[] text;
private JPanel continer;
private GridBagConstraints gbc;
public SidePanel(){
this.setBorder(new TitledBorder("Eingabefelder"));
this.labels = new JLabel[10];
this.text = new JTextField[10];
this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
this.setLayout(new BorderLayout());
this.continer = new JPanel();
continer.setLayout(new GridBagLayout());;
gbc = new GridBagConstraints();
gbc.anchor = GridBagConstraints.NORTH;
gbc.fill = GridBagConstraints.HORIZONTAL;
for (int i=0;i<9;i++){
this.labels[i] = new JLabel("dummy "+i);
this.text[i] = new JTextField();
this.add(this.labels[i]);
this.add(this.text[i]);
}
gbc.insets = new Insets(0, 5,0,0);
gbc.gridx = 0;
gbc.gridy = i;
gbc.weightx = 0.05;
gbc.weighty = 0.05;
continer.add(this.labels[i], gbc);
gbc.gridx = 1;
gbc.gridy = i;
gbc.weightx = 0.9;
gbc.weighty = 0.05;
gbc.insets = new Insets(0, 0,0,5);
continer.add(this.text[i], gbc);
}
this.add(continer, BorderLayout.NORTH);
}