diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..3bc452e --- /dev/null +++ b/.classpath @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..8f7e44e --- /dev/null +++ b/.project @@ -0,0 +1,23 @@ + + + KorrekturHelper + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..aeacc3c --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=17 +org.eclipse.jdt.core.compiler.compliance=17 +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore +org.eclipse.jdt.core.compiler.release=disabled +org.eclipse.jdt.core.compiler.source=17 diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..aaa211b --- /dev/null +++ b/pom.xml @@ -0,0 +1,43 @@ + + 4.0.0 + de.tuDortmund.cs.rvs.pingger + KorrekturHelper + 0.0.1-SNAPSHOT + KorrekturHelper + + 17 + 17 + + + + + maven-jlink-plugin + 3.1.0 + true + + jlink + 2 + true + true + ${project.build.directory}/jlink_output + + java.compiler + java.datatransfer + java.desktop + java.instrument + java.logging + java.management + java.naming + java.prefs + java.rmi + java.scripting + java.sql + java.xml + jdk.compiler + jdk.unsupported + + + + + + \ No newline at end of file diff --git a/src/main/java/de/tuDortmund/cs/rvs/pingger/korrekturHelper/AbstractNode.java b/src/main/java/de/tuDortmund/cs/rvs/pingger/korrekturHelper/AbstractNode.java new file mode 100644 index 0000000..52cfe07 --- /dev/null +++ b/src/main/java/de/tuDortmund/cs/rvs/pingger/korrekturHelper/AbstractNode.java @@ -0,0 +1,60 @@ +package de.tuDortmund.cs.rvs.pingger.korrekturHelper; + +import java.awt.BorderLayout; +import java.awt.Component; +import java.util.LinkedHashSet; + +import javax.swing.BoxLayout; +import javax.swing.JPanel; +import javax.swing.border.EmptyBorder; + +/** + * @author Pingger + */ +public abstract class AbstractNode extends JPanel implements Node +{ + private static final long serialVersionUID = 2766238124985613235L; + /** Content-Panel */ + protected final JPanel content; + private final JPanel sub; + /** Sub-Nodes */ + protected final LinkedHashSet subNodes = new LinkedHashSet<>(); + + /** + * + */ + public AbstractNode() + { + super(true); + setLayout(new BoxLayout(this, 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); + } + + @Override + public void addSubNode(Node n) + { + subNodes.add(n); + sub.add(n.getComponent()); + } + + @Override + public Component getComponent() + { return this; } + + @Override + public LinkedHashSet getSubNodes() + { return subNodes; } + + @Override + public void reset() + { + subNodes.forEach(Node::reset); + } +} diff --git a/src/main/java/de/tuDortmund/cs/rvs/pingger/korrekturHelper/CheckboxNode.java b/src/main/java/de/tuDortmund/cs/rvs/pingger/korrekturHelper/CheckboxNode.java new file mode 100644 index 0000000..1d113d5 --- /dev/null +++ b/src/main/java/de/tuDortmund/cs/rvs/pingger/korrekturHelper/CheckboxNode.java @@ -0,0 +1,58 @@ +package de.tuDortmund.cs.rvs.pingger.korrekturHelper; + +import java.math.BigDecimal; +import java.math.MathContext; + +import javax.swing.JCheckBox; + +public class CheckboxNode extends AbstractNode +{ + private final JCheckBox cbx; + private final String message; + + private final BigDecimal points; + + public CheckboxNode(String configString) + { + if (configString.contains("\n")) + { throw new IllegalArgumentException("Bad config! Found line feed!"); } + var spl = configString.split("\t"); + if (spl.length != 3) + { throw new IllegalArgumentException("Bad Config String! Expected 2 \\t"); } + if (!"[]".equals(spl[0])) + { throw new IllegalArgumentException("Not a [] Node"); } + points = new BigDecimal(spl[1]); + message = spl[2]; + cbx = new JCheckBox(); + } + + @Override + public BigDecimal achievedPoints(MathContext mc) + { + return cbx.isSelected() ? points : BigDecimal.ZERO; + } + + @Override + public boolean isVisibleInResultHtml() + { return cbx.isSelected(); } + + @Override + public BigDecimal maximumPoints() + { + return BigDecimal.ZERO; + } + + @Override + public String toConfigString() + { + return "[]\t" + (points.signum() > 0 ? "+" : "") + points.toPlainString() + "\t" + message; + } + + @Override + public String toResultHtml() + { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/src/main/java/de/tuDortmund/cs/rvs/pingger/korrekturHelper/HeaderNode.java b/src/main/java/de/tuDortmund/cs/rvs/pingger/korrekturHelper/HeaderNode.java new file mode 100644 index 0000000..f8d079d --- /dev/null +++ b/src/main/java/de/tuDortmund/cs/rvs/pingger/korrekturHelper/HeaderNode.java @@ -0,0 +1,118 @@ +package de.tuDortmund.cs.rvs.pingger.korrekturHelper; + +import java.awt.Font; +import java.math.BigDecimal; +import java.math.MathContext; + +import javax.swing.JLabel; + +/** + * @author Pingger + */ +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) + { + for (var i = 0; i < array.length; i++) + { + if (elem.equals(array[i])) + { return i; } + } + return -1; + } + + /** Additional CSS */ + protected final String css; + + /** Text to display */ + protected final String message; + + /** type of header (h#, b, i) */ + protected final int style; + + /** + * Load from config String + * + * @param config the config String + */ + public HeaderNode(String config) + { + if (config.contains("\n")) + { throw new IllegalArgumentException("Bad config! Found line feed!"); } + var spl = config.split("\t"); + if (spl.length < 3 || spl.length > 4) + { throw new IllegalArgumentException("Bad Config String! Expected 2 or 3 \\t"); } + if (!"!header".equals(spl[0])) + { throw new IllegalArgumentException("Not a !header Node"); } + style = indexOf(configStyles, spl[1]); + if (style == -1) + { throw new IllegalArgumentException("Bad Style!"); } + message = spl[2]; + if (spl.length == 3) + { + css = null; + } + else + { + css = spl[3]; + } + var lbl = new JLabel(message); + switch (style) + { + case 0: + break; + + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + lbl.setFont(new Font(lbl.getFont().getFontName(), Font.PLAIN, + (int) (lbl.getFont().getSize() * (1.0 + (6 - style) / 6)))); + break; + + case 7: + lbl.setFont(new Font(lbl.getFont().getFontName(), Font.BOLD, lbl.getFont().getSize())); + break; + + case 8: + lbl.setFont(new Font(lbl.getFont().getFontName(), Font.ITALIC, lbl.getFont().getSize())); + break; + } + } + + @Override + public BigDecimal achievedPoints(MathContext mc) + { + return BigDecimal.ZERO; + } + + @Override + public boolean isVisibleInResultHtml() + { return subNodes.stream().anyMatch(Node::isVisibleInResultHtml); } + + @Override + public BigDecimal maximumPoints() + { + return BigDecimal.ZERO; + } + + @Override + public String toConfigString() + { + return "!header\t" + configStyles[style] + "\t" + message + (css == null ? "" : "\t" + css); + } + + @Override + public String toResultHtml() + { + return (style == 0 ? "" : "<" + htmlStyles[style] + (css == null ? "" : " style=\"" + css + "\"") + ">") + message + + (style == 0 ? "" : ""); + } + +} diff --git a/src/main/java/de/tuDortmund/cs/rvs/pingger/korrekturHelper/KorrekturHelper.java b/src/main/java/de/tuDortmund/cs/rvs/pingger/korrekturHelper/KorrekturHelper.java new file mode 100644 index 0000000..466ebbe --- /dev/null +++ b/src/main/java/de/tuDortmund/cs/rvs/pingger/korrekturHelper/KorrekturHelper.java @@ -0,0 +1,15 @@ +package de.tuDortmund.cs.rvs.pingger.korrekturHelper; + +import java.io.IOException; + +public class KorrekturHelper +{ + + public static void main(String[] args) throws IOException + { + var in = KorrekturHelper.class.getClassLoader() + .getResourceAsStream("de/tuDortmund/cs/rvs/pingger/korrekturHelper/Test.schema"); + in.transferTo(System.out); + } + +} diff --git a/src/main/java/de/tuDortmund/cs/rvs/pingger/korrekturHelper/Node.java b/src/main/java/de/tuDortmund/cs/rvs/pingger/korrekturHelper/Node.java new file mode 100644 index 0000000..b6e2375 --- /dev/null +++ b/src/main/java/de/tuDortmund/cs/rvs/pingger/korrekturHelper/Node.java @@ -0,0 +1,61 @@ +package de.tuDortmund.cs.rvs.pingger.korrekturHelper; + +import java.awt.Component; +import java.math.BigDecimal; +import java.math.MathContext; +import java.util.LinkedHashSet; + +/** + * @author Pingger + */ +public interface Node +{ + /** + * @param mc the {@link MathContext} + * @return the achieved Points + */ + BigDecimal achievedPoints(MathContext mc); + + /** + * Adds a Sub-Node to this Node + * + * @param n the Sub-Node to add + */ + void addSubNode(Node n); + + /** + * @return the AWT-Component for Displaying + */ + Component getComponent(); + + /** + * @return all Sub-Nodes + */ + LinkedHashSet getSubNodes(); + + /** + * @return whether this Element should be visible in the Result HTML + */ + boolean isVisibleInResultHtml(); + + /** + * @return the maximum Points + */ + BigDecimal maximumPoints(); + + /** + * Resets this Element and all sub-elements to their defaults + */ + void reset(); + + /** + * @return this Node as a Config-String (with which this Node can be correctly + * parsed again using the Constructor) + */ + String toConfigString(); + + /** + * @return the current Result-HTML + */ + String toResultHtml(); +} diff --git a/src/main/java/de/tuDortmund/cs/rvs/pingger/korrekturHelper/Test.schema b/src/main/java/de/tuDortmund/cs/rvs/pingger/korrekturHelper/Test.schema new file mode 100644 index 0000000..625ede6 --- /dev/null +++ b/src/main/java/de/tuDortmund/cs/rvs/pingger/korrekturHelper/Test.schema @@ -0,0 +1,24 @@ +: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 \ No newline at end of file diff --git a/target/classes/de/tuDortmund/cs/rvs/pingger/korrekturHelper/AbstractNode.class b/target/classes/de/tuDortmund/cs/rvs/pingger/korrekturHelper/AbstractNode.class new file mode 100644 index 0000000..49a2e6a Binary files /dev/null and b/target/classes/de/tuDortmund/cs/rvs/pingger/korrekturHelper/AbstractNode.class differ diff --git a/target/classes/de/tuDortmund/cs/rvs/pingger/korrekturHelper/CheckboxNode.class b/target/classes/de/tuDortmund/cs/rvs/pingger/korrekturHelper/CheckboxNode.class new file mode 100644 index 0000000..d7f5a68 Binary files /dev/null and b/target/classes/de/tuDortmund/cs/rvs/pingger/korrekturHelper/CheckboxNode.class differ diff --git a/target/classes/de/tuDortmund/cs/rvs/pingger/korrekturHelper/HeaderNode.class b/target/classes/de/tuDortmund/cs/rvs/pingger/korrekturHelper/HeaderNode.class new file mode 100644 index 0000000..292aec1 Binary files /dev/null and b/target/classes/de/tuDortmund/cs/rvs/pingger/korrekturHelper/HeaderNode.class differ diff --git a/target/classes/de/tuDortmund/cs/rvs/pingger/korrekturHelper/KorrekturHelper.class b/target/classes/de/tuDortmund/cs/rvs/pingger/korrekturHelper/KorrekturHelper.class new file mode 100644 index 0000000..4f07abc Binary files /dev/null and b/target/classes/de/tuDortmund/cs/rvs/pingger/korrekturHelper/KorrekturHelper.class differ diff --git a/target/classes/de/tuDortmund/cs/rvs/pingger/korrekturHelper/Node.class b/target/classes/de/tuDortmund/cs/rvs/pingger/korrekturHelper/Node.class new file mode 100644 index 0000000..3dc490f Binary files /dev/null and b/target/classes/de/tuDortmund/cs/rvs/pingger/korrekturHelper/Node.class differ diff --git a/target/classes/de/tuDortmund/cs/rvs/pingger/korrekturHelper/Test.schema b/target/classes/de/tuDortmund/cs/rvs/pingger/korrekturHelper/Test.schema new file mode 100644 index 0000000..625ede6 --- /dev/null +++ b/target/classes/de/tuDortmund/cs/rvs/pingger/korrekturHelper/Test.schema @@ -0,0 +1,24 @@ +: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 \ No newline at end of file