use of uk.ac.ed.ph.jqtiplus.node.item.interaction.graphic.HotspotChoice in project openolat by klemens.
the class HotspotEditorController method scaleHotspot.
private void scaleHotspot(Size oldSize, Size newSize) {
if (oldSize == null || newSize == null || choiceWrappers.isEmpty())
return;
int oldWidth = oldSize.getWidth();
int newWidth = newSize.getWidth();
int oldHeight = oldSize.getHeight();
int newHeight = newSize.getHeight();
if (oldWidth <= 0 || oldHeight <= 0 || newWidth <= 0 || newHeight <= 0)
return;
double widthFactor = ((double) oldWidth / newWidth);
double heightFactor = ((double) oldHeight / newHeight);
for (HotspotWrapper wrapper : choiceWrappers) {
HotspotChoice choice = wrapper.getChoice();
if (choice != null) {
if (Shape.CIRCLE.equals(choice.getShape())) {
scaleCircle(choice.getCoords(), widthFactor, heightFactor);
} else if (Shape.RECT.equals(choice.getShape())) {
scaleRect(choice.getCoords(), widthFactor, heightFactor);
}
}
}
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.graphic.HotspotChoice in project openolat by klemens.
the class HotspotEditorController method rebuildWrappersAndCorrectSelection.
private void rebuildWrappersAndCorrectSelection() {
choiceWrappers.clear();
List<HotspotChoice> choices = itemBuilder.getHotspotChoices();
String[] keys = new String[choices.size()];
String[] values = new String[choices.size()];
for (int i = 0; i < choices.size(); i++) {
HotspotChoice choice = choices.get(i);
keys[i] = choice.getIdentifier().toString();
values[i] = Integer.toString(i + 1) + ".";
choiceWrappers.add(new HotspotWrapper(choice, itemBuilder));
}
correctHotspotsEl.setKeysAndValues(keys, values);
for (int i = 0; i < choices.size(); i++) {
if (itemBuilder.isCorrect(choices.get(i))) {
correctHotspotsEl.select(keys[i], true);
}
}
hotspotsCont.contextPut("hotspots", choiceWrappers);
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.graphic.HotspotChoice in project openolat by klemens.
the class HotspotEditorController method doCorrectAnswers.
private void doCorrectAnswers(Collection<String> correctResponseIds) {
List<HotspotChoice> choices = itemBuilder.getHotspotChoices();
for (int i = 0; i < choices.size(); i++) {
HotspotChoice choice = choices.get(i);
boolean correct = correctResponseIds.contains(choice.getIdentifier().toString());
itemBuilder.setCorrect(choice, correct);
}
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.graphic.HotspotChoice in project OpenOLAT by OpenOLAT.
the class HotspotChoiceScoreController method sync.
@Override
public void sync(UserRequest ureq, AssessmentItemBuilder assessmentItemBuilder) {
if (itemBuilder == assessmentItemBuilder) {
Set<Identifier> choiceIdentifiers = new HashSet<>();
for (HotspotChoice choice : itemBuilder.getHotspotChoices()) {
HotspotChoiceWrapper wrapper = getHotspotChoiceWrapper(choice);
if (wrapper == null) {
wrappers.add(createHotspotChoiceWrapper(choice));
}
choiceIdentifiers.add(choice.getIdentifier());
}
for (Iterator<HotspotChoiceWrapper> wrapperIt = wrappers.iterator(); wrapperIt.hasNext(); ) {
HotspotChoiceWrapper wrapper = wrapperIt.next();
if (!choiceIdentifiers.contains(wrapper.getChoice().getIdentifier())) {
wrapperIt.remove();
}
}
updateBackground();
}
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.graphic.HotspotChoice in project OpenOLAT by OpenOLAT.
the class HotspotChoiceScoreController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
super.initForm(formLayout, listener, ureq);
setFormContextHelp("Test editor QTI 2.1 in detail#details_testeditor_score");
ScoreBuilder minScore = itemBuilder.getMinScoreBuilder();
String minValue = minScore == null ? "" : (minScore.getScore() == null ? "" : minScore.getScore().toString());
minScoreEl = uifactory.addTextElement("min.score", "min.score", 8, minValue, formLayout);
minScoreEl.setElementCssClass("o_sel_assessment_item_min_score");
minScoreEl.setEnabled(!restrictedEdit && !readOnly);
ScoreBuilder maxScore = itemBuilder.getMaxScoreBuilder();
String maxValue = maxScore == null ? "" : (maxScore.getScore() == null ? "" : maxScore.getScore().toString());
maxScoreEl = uifactory.addTextElement("max.score", "max.score", 8, maxValue, formLayout);
maxScoreEl.setElementCssClass("o_sel_assessment_item_max_score");
maxScoreEl.setEnabled(!restrictedEdit && !readOnly);
String[] modeValues = new String[] { translate("form.score.assessment.all.correct"), translate("form.score.assessment.per.answer") };
assessmentModeEl = uifactory.addRadiosHorizontal("assessment.mode", "form.score.assessment.mode", formLayout, modeKeys, modeValues);
assessmentModeEl.addActionListener(FormEvent.ONCHANGE);
assessmentModeEl.setEnabled(!restrictedEdit && !readOnly);
if (itemBuilder.getScoreEvaluationMode() == ScoreEvaluation.perAnswer) {
assessmentModeEl.select(ScoreEvaluation.perAnswer.name(), true);
} else {
assessmentModeEl.select(ScoreEvaluation.allCorrectAnswers.name(), true);
}
String scorePage = velocity_root + "/hotspot_choices_score.html";
scoreCont = FormLayoutContainer.createCustomFormLayout("scores", getTranslator(), scorePage);
formLayout.add(scoreCont);
scoreCont.setLabel(null, null);
for (HotspotChoice choice : itemBuilder.getHotspotChoices()) {
HotspotChoiceWrapper wrapper = createHotspotChoiceWrapper(choice);
wrappers.add(wrapper);
}
scoreCont.contextPut("choices", wrappers);
scoreCont.contextPut("mapperUri", backgroundMapperUri);
scoreCont.setVisible(assessmentModeEl.isSelected(1));
updateBackground();
// Submit Button
FormLayoutContainer buttonsContainer = FormLayoutContainer.createButtonLayout("buttons", getTranslator());
buttonsContainer.setRootForm(mainForm);
buttonsContainer.setVisible(!readOnly);
formLayout.add(buttonsContainer);
uifactory.addFormSubmitButton("submit", buttonsContainer);
}
Aggregations