Search in sources :

Example 1 with HotspotLayouts

use of org.olat.ims.qti21.QTI21Constants.HotspotLayouts in project OpenOLAT by OpenOLAT.

the class HotspotEditorController method formOK.

@Override
protected void formOK(UserRequest ureq) {
    if (readOnly)
        return;
    itemBuilder.setTitle(titleEl.getValue());
    // set the question with the text entries
    String questionText = textEl.getRawValue();
    itemBuilder.setQuestion(questionText);
    itemBuilder.setResponsive(responsiveEl.isAtLeastSelected(1));
    File objectImg = null;
    if (backgroundImage != null) {
        objectImg = backgroundImage;
    } else if (initialBackgroundImage != null) {
        objectImg = initialBackgroundImage;
    }
    if (cardinalityEl.isOneSelected()) {
        String selectedCardinality = cardinalityEl.getSelectedKey();
        itemBuilder.setCardinality(Cardinality.valueOf(selectedCardinality));
    }
    boolean updateHotspot = true;
    if (objectImg != null) {
        String filename = objectImg.getName();
        String mimeType = WebappHelper.getMimeType(filename);
        Size currentSize = imageService.getSize(new LocalFileImpl(objectImg), null);
        Size size = currentSize;
        if (resizeEl.isVisible() && !resizeEl.isSelected(0)) {
            int maxSize = Integer.parseInt(resizeEl.getSelectedKey());
            if (maxSize < currentSize.getHeight() || maxSize < currentSize.getWidth()) {
                String extension = FileUtils.getFileSuffix(filename);
                size = imageService.scaleImage(objectImg, extension, objectImg, maxSize, maxSize, false);
                setBackgroundSize(size);
                scaleHotspot(currentSize, size);
                optimizeResizeEl(size, false);
                updateHotspot = false;
            }
        }
        int height = -1;
        int width = -1;
        if (size != null) {
            height = size.getHeight();
            width = size.getWidth();
        }
        String relPath = itemFile.getParentFile().toPath().relativize(objectImg.toPath()).toString();
        itemBuilder.setBackground(relPath, mimeType, height, width);
    }
    if (updateHotspot) {
        updateHotspots(ureq);
    }
    if (layoutEl.isOneSelected()) {
        String selectedLayout = layoutEl.getSelectedKey();
        for (HotspotLayouts layout : HotspotLayouts.values()) {
            itemBuilder.removeHotspotInteractionClass(layout.cssClass());
        }
        itemBuilder.addHotspotInteractionClass(selectedLayout);
    }
    if (shadowEl.isAtLeastSelected(1)) {
        itemBuilder.removeHotspotInteractionClass(QTI21Constants.CSS_HOTSPOT_DISABLE_SHADOW);
    } else {
        itemBuilder.addHotspotInteractionClass(QTI21Constants.CSS_HOTSPOT_DISABLE_SHADOW);
    }
    fireEvent(ureq, new AssessmentItemEvent(AssessmentItemEvent.ASSESSMENT_ITEM_CHANGED, itemBuilder.getAssessmentItem(), QTI21QuestionType.hotspot));
}
Also used : HotspotLayouts(org.olat.ims.qti21.QTI21Constants.HotspotLayouts) Size(org.olat.core.commons.services.image.Size) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) File(java.io.File) AssessmentItemEvent(org.olat.ims.qti21.ui.editor.events.AssessmentItemEvent)

Example 2 with HotspotLayouts

use of org.olat.ims.qti21.QTI21Constants.HotspotLayouts in project OpenOLAT by OpenOLAT.

the class HotspotEditorController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    setFormContextHelp("Test editor QTI 2.1 in detail#details_testeditor_fragetypen_hotspot");
    titleEl = uifactory.addTextElement("title", "form.imd.title", -1, itemBuilder.getTitle(), formLayout);
    titleEl.setElementCssClass("o_sel_assessment_item_title");
    titleEl.setMandatory(true);
    titleEl.setEnabled(!readOnly);
    String relativePath = rootDirectory.toPath().relativize(itemFile.toPath().getParent()).toString();
    VFSContainer itemContainer = (VFSContainer) rootContainer.resolve(relativePath);
    String question = itemBuilder.getQuestion();
    textEl = uifactory.addRichTextElementForQTI21("desc", "form.imd.descr", question, 8, -1, itemContainer, formLayout, ureq.getUserSession(), getWindowControl());
    textEl.addActionListener(FormEvent.ONCLICK);
    textEl.setEnabled(!readOnly);
    textEl.setVisible(!readOnly);
    if (readOnly) {
        FlowFormItem textReadOnlyEl = new FlowFormItem("descro", itemFile);
        textReadOnlyEl.setLabel("form.imd.descr", null);
        textReadOnlyEl.setBlocks(itemBuilder.getQuestionBlocks());
        textReadOnlyEl.setMapperUri(mapperUri);
        formLayout.add(textReadOnlyEl);
    }
    String[] cardinalityKeys = new String[] { Cardinality.SINGLE.name(), Cardinality.MULTIPLE.name() };
    String[] cardinalityValues = new String[] { translate(Cardinality.SINGLE.name()), translate(Cardinality.MULTIPLE.name()) };
    cardinalityEl = uifactory.addRadiosHorizontal("form.imd.cardinality", formLayout, cardinalityKeys, cardinalityValues);
    cardinalityEl.setElementCssClass("o_sel_assessment_item_cardinality");
    cardinalityEl.setEnabled(!restrictedEdit && !readOnly);
    if (itemBuilder.isSingleChoice()) {
        cardinalityEl.select(cardinalityKeys[0], true);
    } else {
        cardinalityEl.select(cardinalityKeys[1], true);
    }
    responsiveEl = uifactory.addCheckboxesHorizontal("form.imd.responsive", formLayout, onKeys, new String[] { "" });
    responsiveEl.setHelpText(translate("form.imd.responsive.hint"));
    responsiveEl.setEnabled(!restrictedEdit && !readOnly);
    if (itemBuilder.isResponsive()) {
        responsiveEl.select(onKeys[0], true);
    }
    initialBackgroundImage = getCurrentBackground();
    backgroundEl = uifactory.addFileElement(getWindowControl(), "form.imd.background", "form.imd.background", formLayout);
    backgroundEl.setEnabled(!restrictedEdit && !readOnly);
    if (initialBackgroundImage != null) {
        backgroundEl.setInitialFile(initialBackgroundImage);
    }
    backgroundEl.addActionListener(FormEvent.ONCHANGE);
    backgroundEl.setDeleteEnabled(true);
    backgroundEl.limitToMimeType(mimeTypes, "error.mimetype", new String[] { mimeTypes.toString() });
    String[] resizeKeys = new String[] { "no" };
    String[] resizeValues = new String[] { translate("form.imd.background.resize.no") };
    resizeEl = uifactory.addRadiosHorizontal("form.imd.background.resize", formLayout, resizeKeys, resizeValues);
    resizeEl.setVisible(false);
    resizeEl.setEnabled(!readOnly);
    if (initialBackgroundImage != null) {
        Size size = imageService.getSize(new LocalFileImpl(initialBackgroundImage), null);
        optimizeResizeEl(size, false);
    }
    // responses
    String page = velocity_root + "/hotspots.html";
    hotspotsCont = FormLayoutContainer.createCustomFormLayout("answers", getTranslator(), page);
    hotspotsCont.getFormItemComponent().addListener(this);
    hotspotsCont.setLabel("new.spots", null);
    hotspotsCont.setRootForm(mainForm);
    hotspotsCont.contextPut("mapperUri", backgroundMapperUri);
    hotspotsCont.contextPut("restrictedEdit", restrictedEdit || readOnly);
    JSAndCSSFormItem js = new JSAndCSSFormItem("js", new String[] { "js/jquery/openolat/jquery.drawing.js" });
    formLayout.add(js);
    formLayout.add(hotspotsCont);
    newCircleButton = uifactory.addFormLink("new.circle", "new.circle", null, hotspotsCont, Link.BUTTON);
    newCircleButton.setIconLeftCSS("o_icon o_icon-lg o_icon_circle");
    newCircleButton.setVisible(!restrictedEdit && !readOnly);
    newRectButton = uifactory.addFormLink("new.rectangle", "new.rectangle", null, hotspotsCont, Link.BUTTON);
    newRectButton.setIconLeftCSS("o_icon o_icon-lg o_icon_rectangle");
    newRectButton.setVisible(!restrictedEdit && !readOnly);
    updateBackground();
    String[] emptyKeys = new String[0];
    correctHotspotsEl = uifactory.addCheckboxesHorizontal("form.imd.correct.spots", formLayout, emptyKeys, emptyKeys);
    correctHotspotsEl.setElementCssClass("o_sel_assessment_item_correct_spots");
    correctHotspotsEl.setEnabled(!restrictedEdit && !readOnly);
    correctHotspotsEl.addActionListener(FormEvent.ONCHANGE);
    rebuildWrappersAndCorrectSelection();
    HotspotLayouts[] layouts = HotspotLayouts.values();
    String[] layoutKeys = new String[layouts.length];
    String[] layoutValues = new String[layouts.length];
    for (int i = layouts.length; i-- > 0; ) {
        layoutKeys[i] = layouts[i].cssClass();
        layoutValues[i] = translate("hotspot.layout." + layouts[i].name());
    }
    layoutEl = uifactory.addDropdownSingleselect("hotspot.layout", "hotspot.layout", formLayout, layoutKeys, layoutValues, null);
    layoutEl.addActionListener(FormEvent.ONCHANGE);
    layoutEl.setEnabled(!readOnly);
    boolean found = false;
    for (int i = layoutKeys.length; i-- > 0; ) {
        if (itemBuilder.hasHotspotInteractionClass(layoutKeys[i])) {
            layoutEl.select(layoutKeys[i], true);
            found = true;
        }
    }
    if (!found) {
        layoutEl.select(layoutKeys[0], true);
    }
    shadowEl = uifactory.addCheckboxesHorizontal("hotspot.layout.shadow", "hotspot.layout.shadow", formLayout, onKeys, new String[] { "" });
    shadowEl.setEnabled(!readOnly);
    if (!itemBuilder.hasHotspotInteractionClass(QTI21Constants.CSS_HOTSPOT_DISABLE_SHADOW)) {
        shadowEl.select(onKeys[0], true);
    }
    updateLayoutCssClass();
    // Submit Button
    FormLayoutContainer buttonsContainer = FormLayoutContainer.createButtonLayout("buttons", getTranslator());
    buttonsContainer.setElementCssClass("o_sel_hotspots_save");
    buttonsContainer.setRootForm(mainForm);
    buttonsContainer.setVisible(!readOnly);
    formLayout.add(buttonsContainer);
    uifactory.addFormSubmitButton("submit", buttonsContainer);
}
Also used : FlowFormItem(org.olat.ims.qti21.ui.components.FlowFormItem) HotspotLayouts(org.olat.ims.qti21.QTI21Constants.HotspotLayouts) Size(org.olat.core.commons.services.image.Size) JSAndCSSFormItem(org.olat.core.gui.components.htmlheader.jscss.JSAndCSSFormItem) VFSContainer(org.olat.core.util.vfs.VFSContainer) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)

Example 3 with HotspotLayouts

use of org.olat.ims.qti21.QTI21Constants.HotspotLayouts in project openolat by klemens.

the class HotspotEditorController method formOK.

@Override
protected void formOK(UserRequest ureq) {
    if (readOnly)
        return;
    itemBuilder.setTitle(titleEl.getValue());
    // set the question with the text entries
    String questionText = textEl.getRawValue();
    itemBuilder.setQuestion(questionText);
    itemBuilder.setResponsive(responsiveEl.isAtLeastSelected(1));
    File objectImg = null;
    if (backgroundImage != null) {
        objectImg = backgroundImage;
    } else if (initialBackgroundImage != null) {
        objectImg = initialBackgroundImage;
    }
    if (cardinalityEl.isOneSelected()) {
        String selectedCardinality = cardinalityEl.getSelectedKey();
        itemBuilder.setCardinality(Cardinality.valueOf(selectedCardinality));
    }
    boolean updateHotspot = true;
    if (objectImg != null) {
        String filename = objectImg.getName();
        String mimeType = WebappHelper.getMimeType(filename);
        Size currentSize = imageService.getSize(new LocalFileImpl(objectImg), null);
        Size size = currentSize;
        if (resizeEl.isVisible() && !resizeEl.isSelected(0)) {
            int maxSize = Integer.parseInt(resizeEl.getSelectedKey());
            if (maxSize < currentSize.getHeight() || maxSize < currentSize.getWidth()) {
                String extension = FileUtils.getFileSuffix(filename);
                size = imageService.scaleImage(objectImg, extension, objectImg, maxSize, maxSize, false);
                setBackgroundSize(size);
                scaleHotspot(currentSize, size);
                optimizeResizeEl(size, false);
                updateHotspot = false;
            }
        }
        int height = -1;
        int width = -1;
        if (size != null) {
            height = size.getHeight();
            width = size.getWidth();
        }
        String relPath = itemFile.getParentFile().toPath().relativize(objectImg.toPath()).toString();
        itemBuilder.setBackground(relPath, mimeType, height, width);
    }
    if (updateHotspot) {
        updateHotspots(ureq);
    }
    if (layoutEl.isOneSelected()) {
        String selectedLayout = layoutEl.getSelectedKey();
        for (HotspotLayouts layout : HotspotLayouts.values()) {
            itemBuilder.removeHotspotInteractionClass(layout.cssClass());
        }
        itemBuilder.addHotspotInteractionClass(selectedLayout);
    }
    if (shadowEl.isAtLeastSelected(1)) {
        itemBuilder.removeHotspotInteractionClass(QTI21Constants.CSS_HOTSPOT_DISABLE_SHADOW);
    } else {
        itemBuilder.addHotspotInteractionClass(QTI21Constants.CSS_HOTSPOT_DISABLE_SHADOW);
    }
    fireEvent(ureq, new AssessmentItemEvent(AssessmentItemEvent.ASSESSMENT_ITEM_CHANGED, itemBuilder.getAssessmentItem(), QTI21QuestionType.hotspot));
}
Also used : HotspotLayouts(org.olat.ims.qti21.QTI21Constants.HotspotLayouts) Size(org.olat.core.commons.services.image.Size) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) File(java.io.File) AssessmentItemEvent(org.olat.ims.qti21.ui.editor.events.AssessmentItemEvent)

Example 4 with HotspotLayouts

use of org.olat.ims.qti21.QTI21Constants.HotspotLayouts in project openolat by klemens.

the class HotspotEditorController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    setFormContextHelp("Test editor QTI 2.1 in detail#details_testeditor_fragetypen_hotspot");
    titleEl = uifactory.addTextElement("title", "form.imd.title", -1, itemBuilder.getTitle(), formLayout);
    titleEl.setElementCssClass("o_sel_assessment_item_title");
    titleEl.setMandatory(true);
    titleEl.setEnabled(!readOnly);
    String relativePath = rootDirectory.toPath().relativize(itemFile.toPath().getParent()).toString();
    VFSContainer itemContainer = (VFSContainer) rootContainer.resolve(relativePath);
    String question = itemBuilder.getQuestion();
    textEl = uifactory.addRichTextElementForQTI21("desc", "form.imd.descr", question, 8, -1, itemContainer, formLayout, ureq.getUserSession(), getWindowControl());
    textEl.addActionListener(FormEvent.ONCLICK);
    textEl.setEnabled(!readOnly);
    textEl.setVisible(!readOnly);
    if (readOnly) {
        FlowFormItem textReadOnlyEl = new FlowFormItem("descro", itemFile);
        textReadOnlyEl.setLabel("form.imd.descr", null);
        textReadOnlyEl.setBlocks(itemBuilder.getQuestionBlocks());
        textReadOnlyEl.setMapperUri(mapperUri);
        formLayout.add(textReadOnlyEl);
    }
    String[] cardinalityKeys = new String[] { Cardinality.SINGLE.name(), Cardinality.MULTIPLE.name() };
    String[] cardinalityValues = new String[] { translate(Cardinality.SINGLE.name()), translate(Cardinality.MULTIPLE.name()) };
    cardinalityEl = uifactory.addRadiosHorizontal("form.imd.cardinality", formLayout, cardinalityKeys, cardinalityValues);
    cardinalityEl.setElementCssClass("o_sel_assessment_item_cardinality");
    cardinalityEl.setEnabled(!restrictedEdit && !readOnly);
    if (itemBuilder.isSingleChoice()) {
        cardinalityEl.select(cardinalityKeys[0], true);
    } else {
        cardinalityEl.select(cardinalityKeys[1], true);
    }
    responsiveEl = uifactory.addCheckboxesHorizontal("form.imd.responsive", formLayout, onKeys, new String[] { "" });
    responsiveEl.setHelpText(translate("form.imd.responsive.hint"));
    responsiveEl.setEnabled(!restrictedEdit && !readOnly);
    if (itemBuilder.isResponsive()) {
        responsiveEl.select(onKeys[0], true);
    }
    initialBackgroundImage = getCurrentBackground();
    backgroundEl = uifactory.addFileElement(getWindowControl(), "form.imd.background", "form.imd.background", formLayout);
    backgroundEl.setEnabled(!restrictedEdit && !readOnly);
    if (initialBackgroundImage != null) {
        backgroundEl.setInitialFile(initialBackgroundImage);
    }
    backgroundEl.addActionListener(FormEvent.ONCHANGE);
    backgroundEl.setDeleteEnabled(true);
    backgroundEl.limitToMimeType(mimeTypes, "error.mimetype", new String[] { mimeTypes.toString() });
    String[] resizeKeys = new String[] { "no" };
    String[] resizeValues = new String[] { translate("form.imd.background.resize.no") };
    resizeEl = uifactory.addRadiosHorizontal("form.imd.background.resize", formLayout, resizeKeys, resizeValues);
    resizeEl.setVisible(false);
    resizeEl.setEnabled(!readOnly);
    if (initialBackgroundImage != null) {
        Size size = imageService.getSize(new LocalFileImpl(initialBackgroundImage), null);
        optimizeResizeEl(size, false);
    }
    // responses
    String page = velocity_root + "/hotspots.html";
    hotspotsCont = FormLayoutContainer.createCustomFormLayout("answers", getTranslator(), page);
    hotspotsCont.getFormItemComponent().addListener(this);
    hotspotsCont.setLabel("new.spots", null);
    hotspotsCont.setRootForm(mainForm);
    hotspotsCont.contextPut("mapperUri", backgroundMapperUri);
    hotspotsCont.contextPut("restrictedEdit", restrictedEdit || readOnly);
    JSAndCSSFormItem js = new JSAndCSSFormItem("js", new String[] { "js/jquery/openolat/jquery.drawing.js" });
    formLayout.add(js);
    formLayout.add(hotspotsCont);
    newCircleButton = uifactory.addFormLink("new.circle", "new.circle", null, hotspotsCont, Link.BUTTON);
    newCircleButton.setIconLeftCSS("o_icon o_icon-lg o_icon_circle");
    newCircleButton.setVisible(!restrictedEdit && !readOnly);
    newRectButton = uifactory.addFormLink("new.rectangle", "new.rectangle", null, hotspotsCont, Link.BUTTON);
    newRectButton.setIconLeftCSS("o_icon o_icon-lg o_icon_rectangle");
    newRectButton.setVisible(!restrictedEdit && !readOnly);
    updateBackground();
    String[] emptyKeys = new String[0];
    correctHotspotsEl = uifactory.addCheckboxesHorizontal("form.imd.correct.spots", formLayout, emptyKeys, emptyKeys);
    correctHotspotsEl.setElementCssClass("o_sel_assessment_item_correct_spots");
    correctHotspotsEl.setEnabled(!restrictedEdit && !readOnly);
    correctHotspotsEl.addActionListener(FormEvent.ONCHANGE);
    rebuildWrappersAndCorrectSelection();
    HotspotLayouts[] layouts = HotspotLayouts.values();
    String[] layoutKeys = new String[layouts.length];
    String[] layoutValues = new String[layouts.length];
    for (int i = layouts.length; i-- > 0; ) {
        layoutKeys[i] = layouts[i].cssClass();
        layoutValues[i] = translate("hotspot.layout." + layouts[i].name());
    }
    layoutEl = uifactory.addDropdownSingleselect("hotspot.layout", "hotspot.layout", formLayout, layoutKeys, layoutValues, null);
    layoutEl.addActionListener(FormEvent.ONCHANGE);
    layoutEl.setEnabled(!readOnly);
    boolean found = false;
    for (int i = layoutKeys.length; i-- > 0; ) {
        if (itemBuilder.hasHotspotInteractionClass(layoutKeys[i])) {
            layoutEl.select(layoutKeys[i], true);
            found = true;
        }
    }
    if (!found) {
        layoutEl.select(layoutKeys[0], true);
    }
    shadowEl = uifactory.addCheckboxesHorizontal("hotspot.layout.shadow", "hotspot.layout.shadow", formLayout, onKeys, new String[] { "" });
    shadowEl.setEnabled(!readOnly);
    if (!itemBuilder.hasHotspotInteractionClass(QTI21Constants.CSS_HOTSPOT_DISABLE_SHADOW)) {
        shadowEl.select(onKeys[0], true);
    }
    updateLayoutCssClass();
    // Submit Button
    FormLayoutContainer buttonsContainer = FormLayoutContainer.createButtonLayout("buttons", getTranslator());
    buttonsContainer.setElementCssClass("o_sel_hotspots_save");
    buttonsContainer.setRootForm(mainForm);
    buttonsContainer.setVisible(!readOnly);
    formLayout.add(buttonsContainer);
    uifactory.addFormSubmitButton("submit", buttonsContainer);
}
Also used : FlowFormItem(org.olat.ims.qti21.ui.components.FlowFormItem) HotspotLayouts(org.olat.ims.qti21.QTI21Constants.HotspotLayouts) Size(org.olat.core.commons.services.image.Size) JSAndCSSFormItem(org.olat.core.gui.components.htmlheader.jscss.JSAndCSSFormItem) VFSContainer(org.olat.core.util.vfs.VFSContainer) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)

Aggregations

Size (org.olat.core.commons.services.image.Size)4 LocalFileImpl (org.olat.core.util.vfs.LocalFileImpl)4 HotspotLayouts (org.olat.ims.qti21.QTI21Constants.HotspotLayouts)4 File (java.io.File)2 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)2 JSAndCSSFormItem (org.olat.core.gui.components.htmlheader.jscss.JSAndCSSFormItem)2 VFSContainer (org.olat.core.util.vfs.VFSContainer)2 FlowFormItem (org.olat.ims.qti21.ui.components.FlowFormItem)2 AssessmentItemEvent (org.olat.ims.qti21.ui.editor.events.AssessmentItemEvent)2