More Work

This commit is contained in:
Felix Homa 2022-03-27 22:40:52 +02:00
parent ad432c45fb
commit 7eb519f9b5
Signed by: felix.homa
GPG Key ID: 43610F311720D3DA
14 changed files with 141 additions and 41 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
target/

View File

@ -11,11 +11,12 @@ import javax.swing.border.EmptyBorder;
/**
* @author Pingger
*/
public abstract class AbstractNode extends JPanel implements Node
public abstract class AbstractNode implements Node
{
private static final long serialVersionUID = 2766238124985613235L;
/** Content-Panel */
protected final JPanel content;
private final JPanel main;
private final JPanel sub;
/** Sub-Nodes */
protected final LinkedHashSet<Node> subNodes = new LinkedHashSet<>();
@ -25,18 +26,23 @@ public abstract class AbstractNode extends JPanel implements Node
*/
public AbstractNode()
{
super(true);
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
main = new JPanel(true);
main.setLayout(new BoxLayout(main, BoxLayout.Y_AXIS));
content = new JPanel(new BorderLayout(), true);
sub = new JPanel(true);
sub.setLayout(new BoxLayout(sub, BoxLayout.Y_AXIS));
sub.setBorder(new EmptyBorder(0, 8, 8, 0));
add(content);
add(sub);
main.add(content);
main.add(sub);
}
/**
* Resets this node
*/
protected abstract void _reset();
@Override
public void addSubNode(Node n)
{
@ -46,7 +52,7 @@ public abstract class AbstractNode extends JPanel implements Node
@Override
public Component getComponent()
{ return this; }
{ return main; }
@Override
public LinkedHashSet<Node> getSubNodes()
@ -55,6 +61,7 @@ public abstract class AbstractNode extends JPanel implements Node
@Override
public void reset()
{
_reset();
subNodes.forEach(Node::reset);
}
}

View File

@ -5,13 +5,25 @@ import java.math.MathContext;
import javax.swing.JCheckBox;
/**
* @author Pingger
*/
public class CheckboxNode extends AbstractNode
{
private static String ptsToString(BigDecimal p)
{
return (p.signum() > 0 ? "+" : "") + p.toPlainString();
}
private final JCheckBox cbx;
private final String message;
private final BigDecimal points;
/**
* @param configString config String to parse
*/
public CheckboxNode(String configString)
{
if (configString.contains("\n"))
@ -23,7 +35,14 @@ public class CheckboxNode extends AbstractNode
{ throw new IllegalArgumentException("Not a [] Node"); }
points = new BigDecimal(spl[1]);
message = spl[2];
cbx = new JCheckBox();
cbx = new JCheckBox(ptsToString(points) + "P " + message);
content.add(cbx);
}
@Override
protected void _reset()
{
cbx.setSelected(false);
}
@Override
@ -45,14 +64,14 @@ public class CheckboxNode extends AbstractNode
@Override
public String toConfigString()
{
return "[]\t" + (points.signum() > 0 ? "+" : "") + points.toPlainString() + "\t" + message;
return "[]\t" + ptsToString(points) + "\t" + message;
}
@Override
public String toResultHtml()
public String toResultHtml(HtmlContext hc)
{
// TODO Auto-generated method stub
return null;
return "<li" + hc.styleText(points.signum()) + "><span" + hc.stylePts(points.signum()) + ">"
+ ptsToString(achievedPoints(hc.mc)) + "P</span>" + message + "</li>";
}
}

View File

@ -1,5 +1,6 @@
package de.tuDortmund.cs.rvs.pingger.korrekturHelper;
import java.awt.BorderLayout;
import java.awt.Font;
import java.math.BigDecimal;
import java.math.MathContext;
@ -13,7 +14,6 @@ public class HeaderNode extends AbstractNode
{
private static final String[] configStyles = { "", "#", "##", "###", "####", "#####", "######", "*", "_" };
private static final String[] htmlStyles = { "", "h1", "h2", "h3", "h4", "h5", "h6", "b", "i" };
private static final long serialVersionUID = -5511548087337263042L;
private static int indexOf(String[] array, String elem)
{
@ -84,6 +84,13 @@ public class HeaderNode extends AbstractNode
lbl.setFont(new Font(lbl.getFont().getFontName(), Font.ITALIC, lbl.getFont().getSize()));
break;
}
content.add(lbl, BorderLayout.CENTER);
}
@Override
protected void _reset()
{
// does nothing
}
@Override
@ -109,7 +116,7 @@ public class HeaderNode extends AbstractNode
}
@Override
public String toResultHtml()
public String toResultHtml(HtmlContext hc)
{
return (style == 0 ? "" : "<" + htmlStyles[style] + (css == null ? "" : " style=\"" + css + "\"") + ">") + message
+ (style == 0 ? "" : "</" + htmlStyles[style] + ">");

View File

@ -0,0 +1,61 @@
package de.tuDortmund.cs.rvs.pingger.korrekturHelper;
import java.math.MathContext;
/**
* @author Pingger
*/
public class HtmlContext
{
/** Style for the Points, when the best case Points have been achieved */
public String fullPtsStyle = "";
/** Style for the Text, when the best case Points have been achieved */
public String fullPtsTextStyle = "";
/** {@link MathContext} for Output */
public MathContext mc;
/** Style for the Points, when the worst case Points have been achieved */
public String noPtsStyle = "";
/** Style for the Text, when the best case Points have been achieved */
public String noPtsTextStyle = "";
/**
* Style for the Points, when neither best nor worst case Points have been
* achieved
*/
public String partialPtsStyle = "";
/**
* Style for the Text, when neither best nor worst case Points have been
* achieved
*/
public String partialPtsTextStyle = "";
/**
* @param signum the style-signum -1 worst case, 0 partial case, 1 best case
* @return the style tag-parameter for the given signum for the Points
*/
public String stylePts(int signum)
{
return switch (signum)
{
case 0 -> partialPtsStyle.isBlank() ? "" : " style=\"" + partialPtsStyle + "\"";
case 1 -> fullPtsStyle.isBlank() ? "" : " style=\"" + fullPtsStyle + "\"";
case -1 -> noPtsStyle.isBlank() ? "" : " style=\"" + noPtsStyle + "\"";
default -> throw new IllegalArgumentException("Signum must be one of -1, 0, 1");
};
}
/**
* @param signum the style-signum -1 worst case, 0 partial case, 1 best case
* @return the style tag-parameter for the given signum for the Text
*/
public String styleText(int signum)
{
return switch (signum)
{
case 0 -> partialPtsTextStyle.isBlank() ? "" : " style=\"" + partialPtsTextStyle + "\"";
case 1 -> fullPtsTextStyle.isBlank() ? "" : " style=\"" + fullPtsTextStyle + "\"";
case -1 -> noPtsTextStyle.isBlank() ? "" : " style=\"" + noPtsTextStyle + "\"";
default -> throw new IllegalArgumentException("Signum must be one of -1, 0, 1");
};
}
}

View File

@ -2,9 +2,16 @@ package de.tuDortmund.cs.rvs.pingger.korrekturHelper;
import java.io.IOException;
/**
* @author Pingger
*/
public class KorrekturHelper
{
/**
* @param args [0] input File
* @throws IOException in case reading the input file fails
*/
public static void main(String[] args) throws IOException
{
var in = KorrekturHelper.class.getClassLoader()

View File

@ -55,7 +55,9 @@ public interface Node
String toConfigString();
/**
* @return the current Result-HTML
* @param hc the HtmlContext
* @return the current Result-HTML (regardless of
* {@link #isVisibleInResultHtml()})
*/
String toResultHtml();
String toResultHtml(HtmlContext hc);
}

View File

@ -1,8 +1,14 @@
// Kommentare
// :base gibt die Start-Punkte an
:base 0.0
// Design für Punkte. Pts ist dabei für die Punkte, PtsText für den Text. die Punkte zählen als Teil des Textes (<li style=PtsText><span style=Pts>'Punkte'</span>Text</li>)
// full -> best-Case
:fullPts color: #0f0;
:fullPtsText
// no -> worst-case
:noPts color: #f00;
:noPtsText
// partial -> alle verbleibenden Fälle. Sonderfall: Elemente die 0 Punkte bringen (egal was ausgewählt ist) haben auch diesen Fall!
:partialPts color: #fb0;
:partialPtsText
!header # Test-Schema
@ -22,3 +28,16 @@
50% Halbe Punkte in Prozent
1/3 Ein Drittel Punkte als Bruch
0 Null Punkte
\\ 5.0 Text der immer angezeigt wird. Dadurch wird der Text bei den Punkten zur Begründung
5.0 Volle Punkte
2.5 Halbe Punkte
50% Halbe Punkte in Prozent
1/3 Ein Drittel Punkte als Bruch
0 Null Punkte
\\ 5.0 Text der immer angezeigt wird. Dadurch wird der Text bei den Punkten zur Begründung (Multi-Select anstatt Radio-Box, das kann nicht gemischt werden!)
[] 1.0 Ziel 1
[] 1.0 Ziel 2
[] 2.0 Ziel 3
[] 0.5 Ziel 4
[] 0.5 Ziel 5
// Zeilenumbruch am Ende der Datei wichtig!

View File

@ -1,24 +0,0 @@
:base 0.0
:fullPts color: #0f0;
:fullPtsText
:noPts color: #f00;
:noPtsText
:partialPts color: #fb0;
:partialPtsText
!header # Test-Schema
[] -0.5 Punktabzug
[] +0.5 Bonus-Punkt
!header ## Sub-Header zum versteck-Test
[] -0.5 Punktabzug (uncheck um Sub-Header zu verstecken)
!header ## Sub-Header für Punkte
\ 1.0 Element existiert | Element existiert nicht
\ 2 Anderes Element existiert | Anderes Element fehlt
\ 1.5 Beispiel | fehlt
[] -0.5 Punktabzug weil is so.
!header ## Sub-Header für Punkte Multiline
\\ 5.0
5.0 Volle Punkte
2.5 Halbe Punkte
50% Halbe Punkte in Prozent
1/3 Ein Drittel Punkte als Bruch
0 Null Punkte