Commit 8e606961 authored by doc. Ing. Jaroslav Porubän PhD.'s avatar doc. Ing. Jaroslav Porubän PhD.
Browse files

prednaska3

parent 6d5e7cbc
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>
\ No newline at end of file
package sk.tuke.dsl.testlang.builder;
import sk.tuke.dsl.testlang.model.Answer;
import sk.tuke.dsl.testlang.model.Question;
import sk.tuke.dsl.testlang.model.Test;
import sk.tuke.dsl.testlang.model.TestLanguageException;
import java.util.ArrayList;
import java.util.List;
public class FunctionSequenceBuilder {
private static String testTitle;
private static String questionText;
private static List<Question> questions = new ArrayList<>();
private static List<Answer> answers;
public static void test(String title) {
if(testTitle != null)
throw new TestLanguageException("Nedavaj viackrat nazov testu do testu");
testTitle = title;
}
public static void question(String text) {
if(questionText != null) {
createQuestion();
}
answers = new ArrayList<>();
questionText = text;
}
public static void correct_answer(String text) {
answers.add(new Answer(text, true));
}
public static void wrong_answer(String text) {
answers.add(new Answer(text, false));
}
public static Test getTest() {
createQuestion();
return new Test(testTitle, questions.toArray(new Question[] {}));
}
private static void createQuestion() {
questions.add(new Question(questionText, answers.toArray(new Answer[]{})));
}
}
......@@ -3,10 +3,10 @@ package sk.tuke.dsl.testlang.main;
import sk.tuke.dsl.testlang.model.Answer;
import sk.tuke.dsl.testlang.model.Question;
import sk.tuke.dsl.testlang.model.Test;
import sk.tuke.dsl.testlang.semantics.TestPrinter;
public class Main01Model {
public static void main(String[] args) {
/********************************************************************************/
Test test = new Test("Test z astronomie", new Question[]{
new Question("Kolko planet ma Slnecna sustava?", new Answer[]{
new Answer("6", false),
......@@ -14,21 +14,24 @@ public class Main01Model {
new Answer("8", true),
new Answer("9", false)
}),
new Question("Zem je v poradi od Slnka", new Answer[]{
new Question("Zem je v poradi od Slnka?", new Answer[]{
new Answer("1", false),
new Answer("2", false),
new Answer("3", true),
new Answer("4", false)
}),
new Question("Mars je v poradi od Slnka", new Answer[]{
new Question("Mars je v poradi od Slnka?", new Answer[]{
new Answer("1", false),
new Answer("2", false),
new Answer("3", false),
new Answer("4", true)
})
});
/********************************************************************************/
TestPrinter testPrinter = new TestPrinter();
testPrinter.print(test);
test.validate();
// TestPrinter testPrinter = new TestPrinter();
// testPrinter.print(test);
}
}
package sk.tuke.dsl.testlang.main;
import sk.tuke.dsl.testlang.model.Answer;
import sk.tuke.dsl.testlang.model.Question;
import sk.tuke.dsl.testlang.model.Test;
import sk.tuke.dsl.testlang.semantics.TestGeneratorJava;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
public class Main02GeneratorJava {
public static void main(String[] args) throws IOException {
/********************************************************************************/
Test test = new Test("Test z astronomie", new Question[]{
new Question("Kolko planet ma Slnecna sustava?", new Answer[]{
new Answer("6", false),
new Answer("7", false),
new Answer("8", true),
new Answer("9", false)
}),
new Question("Zem je v poradi od Slnka?", new Answer[]{
new Answer("1", false),
new Answer("2", false),
new Answer("3", true),
new Answer("4", false)
}),
new Question("Mars je v poradi od Slnka?", new Answer[]{
new Answer("1", false),
new Answer("2", false),
new Answer("3", false),
new Answer("4", true)
})
});
/********************************************************************************/
test.validate();
try (Writer writer = new FileWriter("test.html")) {
TestGeneratorJava printer = new TestGeneratorJava();
printer.generate(test, writer);
}
}
}
package sk.tuke.dsl.testlang.main;
import sk.tuke.dsl.testlang.model.Answer;
import sk.tuke.dsl.testlang.model.Question;
import sk.tuke.dsl.testlang.model.Test;
import sk.tuke.dsl.testlang.semantics.TestGeneratorJava;
import sk.tuke.dsl.testlang.semantics.TestGeneratorVelocity;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
public class Main03GeneratorVelocity {
public static void main(String[] args) throws IOException {
/********************************************************************************/
Test test = new Test("Test z astronomie", new Question[]{
new Question("Kolko planet ma Slnecna sustava?", new Answer[]{
new Answer("6", false),
new Answer("7", false),
new Answer("8", true),
new Answer("9", false)
}),
new Question("Zem je v poradi od Slnka?", new Answer[]{
new Answer("1", false),
new Answer("2", false),
new Answer("3", true),
new Answer("4", false)
}),
new Question("Mars je v poradi od Slnka?", new Answer[]{
new Answer("1", false),
new Answer("2", false),
new Answer("3", false),
new Answer("4", true)
})
});
/********************************************************************************/
test.validate();
try (Writer writer = new FileWriter("test.html")) {
TestGeneratorVelocity printer = new TestGeneratorVelocity();
printer.generate(test, writer);
}
}
}
package sk.tuke.dsl.testlang.main;
import sk.tuke.dsl.testlang.builder.FunctionSequenceBuilder;
import sk.tuke.dsl.testlang.model.Test;
import sk.tuke.dsl.testlang.semantics.TestPrinter;
import static sk.tuke.dsl.testlang.builder.FunctionSequenceBuilder.*;
public class Main04FunctionSequence {
public static void main(String[] args) {
/********************************************************************************/
test("Test z astronomie");
question("Kolko planet ma Slnecna sustava?");
wrong_answer("6");
wrong_answer("7");
correct_answer("8");
wrong_answer("9");
question("Zem je v poradi?");
wrong_answer("1");
wrong_answer("2");
correct_answer("3");
wrong_answer("4");
/********************************************************************************/
Test test = FunctionSequenceBuilder.getTest();
test.validate();
TestPrinter testPrinter = new TestPrinter();
testPrinter.print(test);
}
}
package sk.tuke.dsl.testlang.model;
import java.util.Arrays;
public class Question {
private String text;
......@@ -28,4 +30,12 @@ public class Question {
public void setAnswers(Answer[] answers) {
this.answers = answers;
}
public void validate() {
if (answers == null || answers.length < 2)
throw new TestLanguageException("Otazka musi mat aspon 2 odpovede");
if (Arrays.stream(answers).filter(a -> a.isCorrect()).count() < 1)
throw new TestLanguageException("Aspon jedna odpoved musi byt spravna");
}
}
package sk.tuke.dsl.testlang.model;
/**
* Test -> Title Question+
* Question -> Text Answer+
* Answer -> Correct Text
* Title -> String
* Text -> String
* Correct -> true | false
* String -> [a-zA-Z]+
*/
public class Test {
private String title;
......@@ -28,4 +37,13 @@ public class Test {
public void setQuestions(Question[] questions) {
this.questions = questions;
}
public void validate() {
if (questions == null || questions.length == 0)
throw new TestLanguageException("Test musi mat aspon jednu otazku");
for(var question : questions) {
question.validate();
}
}
}
package sk.tuke.dsl.testlang.model;
public class TestLanguageException extends RuntimeException {
public TestLanguageException(String message) {
super(message);
}
}
package sk.tuke.dsl.testlang.semantics;
import sk.tuke.dsl.testlang.model.Answer;
import sk.tuke.dsl.testlang.model.Question;
import sk.tuke.dsl.testlang.model.Test;
import java.io.PrintWriter;
import java.io.Writer;
public class TestGeneratorJava {
public void generate(Test test, Writer writer) {
PrintWriter out = new PrintWriter(writer);
out.println("<html>");
out.println("<head>");
out.println("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">");
out.println("<link rel=\"stylesheet\" href=\"test.css\">");
out.printf("<title>%s</title>\n", test.getTitle());
out.println("</head>");
out.println("<body>");
out.printf("<h1>%s</h1>\n", test.getTitle());
out.println("<ol>");
for (Question question : test.getQuestions())
generate(question, out);
out.println("</ol>");
out.println("</body>");
out.println("</html>");
}
private void generate(Question question, PrintWriter out) {
out.println("<li class='question'>" + question.getText());
out.println("<ol type='A'>");
for (Answer answer : question.getAnswers())
generate(answer, out);
out.println("</ol>");
}
private void generate(Answer answer, PrintWriter out) {
String style = answer.isCorrect() ? "correct_answer" : "wrong_answer";
out.printf("<li class='%s'>%s\n", style, answer.getText());
}
}
package sk.tuke.dsl.testlang.semantics;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;
import sk.tuke.dsl.testlang.model.Test;
import java.io.IOException;
import java.io.Writer;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
public class TestGeneratorVelocity {
static {
try {
Properties properties = new Properties();
properties.load(ClassLoader.getSystemClassLoader().getResourceAsStream("velocity.properties"));
Velocity.init(properties);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public void generate(Test test, Writer writer) throws IOException {
//Zvoľme šablónu
Template template = Velocity.getTemplate("templates/test.html.vm");
//Pripravme parametre pre šablónu - objekt testu
Map<String, Object> params = new HashMap<>();
params.put("test", test);
//Vykonajme transformáciu šablónou
VelocityContext context = new VelocityContext(params);
template.merge(context, writer);
}
}
<html>
<head><title>$test.title</title></head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="test.css">
<body>
<h1>$test.title</h1>
<ol>
#foreach($question in $test.questions)
<li class='question'>$question.text</li>
<ol type='A'>
#foreach($answer in $question.answers)
<li class='#if($answer.correct)correct_answer#{else}wrong_answer#end'>$answer.text
#end
</ol>
#end
</ol>
</body>
</html>
resource.default_encoding = UTF-8
resource.loaders = file, class
resource.loader.file.description = Velocity File Resource Loader
resource.loader.file.class = org.apache.velocity.runtime.resource.loader.FileResourceLoader
resource.loader.file.path = .
resource.loader.file.cache = false
resource.loader.file.modification_check_interval = 2
resource.loader.class.description = Velocity Classpath Resource Loader
resource.loader.class.class = org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
body {
background-color: #ffffff;
font-size: 12px;
font-family: Verdana, "Verdana CE", Arial, "Arial CE", "Helvetica CE", sans-serif;
color: #000000;
margin: 10px;
}
h1 {
text-align: center;
font-size: 2em;
font-weight: bold;
margin: 0px;
padding: 0px;
width: 100%;
}
.question {
}
.correct_answer {
}
.wrong_answer {
}
<html>
<head><title>Test z astronomie</title></head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="test.css">
<body>
<h1>Test z astronomie</h1>
<ol>
<li class='question'>Kolko planet ma Slnecna sustava?</li>
<ol type='A'>
<li class='wrong_answer'>6
<li class='wrong_answer'>7
<li class='correct_answer'>8
<li class='wrong_answer'>9
</ol>
<li class='question'>Zem je v poradi od Slnka?</li>
<ol type='A'>
<li class='wrong_answer'>1
<li class='wrong_answer'>2
<li class='correct_answer'>3
<li class='wrong_answer'>4
</ol>
<li class='question'>Mars je v poradi od Slnka?</li>
<ol type='A'>
<li class='wrong_answer'>1
<li class='wrong_answer'>2
<li class='wrong_answer'>3
<li class='correct_answer'>4
</ol>
</ol>
</body>
</html>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment