Search in sources :

Example 1 with ProblemGenerator

use of doc.mathobjects.ProblemGenerator in project OpenNotebook by jaltekruse.

the class ProblemDatabase method exportToXML.

public String exportToXML() {
    String output = "";
    output += "<" + NAME + ">\n";
    for (ProblemGenerator problem : getExportableProblems()) {
        output += problem.exportToXML();
    }
    output += "</" + NAME + ">\n";
    return output;
}
Also used : ProblemGenerator(doc.mathobjects.ProblemGenerator)

Example 2 with ProblemGenerator

use of doc.mathobjects.ProblemGenerator in project OpenNotebook by jaltekruse.

the class Document method addGenerator.

public void addGenerator(ProblemGenerator generator) throws Exception {
    for (ProblemGenerator gen : generators) {
        if (gen.getProblemID().compareTo(generator.getProblemID()) == 0) {
            throw new Exception("UUID already in use");
        }
    }
    generator.setProblemHoldingDocument(this);
    generators.add(generator);
}
Also used : AttributeException(doc.attributes.AttributeException) ProblemGenerator(doc.mathobjects.ProblemGenerator)

Example 3 with ProblemGenerator

use of doc.mathobjects.ProblemGenerator in project OpenNotebook by jaltekruse.

the class Document method generateProblems.

public void generateProblems(Vector<ProblemGenerator> generators, Vector<Integer> frequencies, int numberOfProblems, String directions, boolean problemNumbers) {
    for (ProblemGenerator gen : generators) {
        gen.setProblemHoldingDocument(this);
        try {
            addGenerator(gen);
        } catch (Exception e) {
        // problem formula has already been added
        }
    }
    int j = 0;
    Vector<GeneratedProblem> newProblems = new Vector<>(numberOfProblems);
    for (int i = 0; j < numberOfProblems; j++, i++) {
        if (i < numberOfProblems / 3) {
            newProblems.add(generators.get(pickRandomIndex(frequencies)).generateProblem(ProblemGenerator.EASY));
        } else if (i < numberOfProblems * (2.0 / 3)) {
            newProblems.add(generators.get(pickRandomIndex(frequencies)).generateProblem(ProblemGenerator.MEDIUM));
        } else {
            newProblems.add(generators.get(pickRandomIndex(frequencies)).generateProblem(ProblemGenerator.HARD));
        }
    }
    layoutProblems(newProblems, directions, this, problemNumbers);
    docPanel.repaint();
}
Also used : GeneratedProblem(doc.mathobjects.GeneratedProblem) AttributeException(doc.attributes.AttributeException) ProblemGenerator(doc.mathobjects.ProblemGenerator)

Example 4 with ProblemGenerator

use of doc.mathobjects.ProblemGenerator in project OpenNotebook by jaltekruse.

the class Document method exportToXML.

public String exportToXML() {
    String output = "";
    output += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
    output += "<" + OPEN_NOTEBOOK_DOC + " " + "version=\"0.1\" " + FILENAME + "=\"" + getName() + "\" " + AUTHOR + "=\"" + getAuthor() + "\" " + DATE + "=\"" + getDate() + "\" " + LAST_PROBLEM_NUMBER + "=\"" + getLastProblemNumber() + "\" " + X_MARGIN + "=\"" + getxMargin() / 72.0 + "\" " + Y_MARGIN + "=\"" + getyMargin() / 72.0 + "\" " + ">\n";
    for (String s : subjectsCovered) {
        output += "<subject name=\"" + s + "\"></subject>";
    }
    output += "<" + GENERATORS + ">\n";
    for (ProblemGenerator gen : generators) {
        output += gen.exportToXML();
    }
    output += "</" + GENERATORS + ">\n";
    for (Page p : pages) {
        output += p.exportToXML();
    }
    output += "</" + OPEN_NOTEBOOK_DOC + ">";
    return output;
}
Also used : ProblemGenerator(doc.mathobjects.ProblemGenerator)

Example 5 with ProblemGenerator

use of doc.mathobjects.ProblemGenerator in project OpenNotebook by jaltekruse.

the class Document method clone.

public Document clone() {
    Document newDoc = new Document(new String(getName()));
    newDoc.attributes = new Vector<>();
    MathObject lastWithFocus = this.getLastFocused();
    for (MathObjectAttribute mAtt : getAttributes()) {
        newDoc.addAttribute(mAtt.clone());
    }
    for (ProblemGenerator gen : generators) {
        try {
            newDoc.addGenerator((ProblemGenerator) gen.clone());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    for (Page p : pages) {
        newDoc.addPage(p.clone());
    }
    // the last focused member of this document is used to pass back
    // its cloned version from the page cloning method
    newDoc.setLastFocused(this.getLastFocused());
    // the last focused object is saved at the beginning of the method
    // to prevent being overridden as described in the above comment
    // this.setLastFocused(lastWithFocus);
    newDoc.setDocViewerPanel(getDocViewerPanel());
    return newDoc;
}
Also used : MathObjectAttribute(doc.attributes.MathObjectAttribute) MathObject(doc.mathobjects.MathObject) AttributeException(doc.attributes.AttributeException) ProblemGenerator(doc.mathobjects.ProblemGenerator)

Aggregations

ProblemGenerator (doc.mathobjects.ProblemGenerator)8 AttributeException (doc.attributes.AttributeException)3 MathObject (doc.mathobjects.MathObject)2 JComponent (javax.swing.JComponent)2 MathObjectAttribute (doc.attributes.MathObjectAttribute)1 GeneratedProblem (doc.mathobjects.GeneratedProblem)1 Component (java.awt.Component)1 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 Insets (java.awt.Insets)1 ItemEvent (java.awt.event.ItemEvent)1 ItemListener (java.awt.event.ItemListener)1 MouseEvent (java.awt.event.MouseEvent)1 MouseListener (java.awt.event.MouseListener)1 JCheckBox (javax.swing.JCheckBox)1 JComboBox (javax.swing.JComboBox)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1 JScrollPane (javax.swing.JScrollPane)1 JSeparator (javax.swing.JSeparator)1