Search in sources :

Example 16 with MathObject

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

the class NotebookPanel method copy.

public void copy() {
    MathObject mObj = getCurrentDocViewer().getFocusedObject();
    if (mObj != null) {
        // application internal clipboard
        setClipBoardContents(mObj.clone());
        addToSystemClipboard(mObj);
    }
}
Also used : MathObject(doc.mathobjects.MathObject)

Example 17 with MathObject

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

the class NotebookPanel method viewProblemGenrator.

public void viewProblemGenrator(ProblemGenerator probGen) {
    Document newDoc = new Document("Problem Generator");
    newDoc.addBlankPage();
    Page page = newDoc.getPage(0);
    TextObject textObj = new TextObject(page, 5 + page.getyMargin(), 5 + newDoc.getPage(0).getxMargin(), page.getWidth() - 2 * page.getxMargin(), 150, 12, VIEW_PROBLEM_FORUMLA_MESSAGE);
    try {
        textObj.setAttributeValue(TextObject.SHOW_BOX, false);
    } catch (AttributeException e) {
    // should not happen
    }
    newDoc.getPage(0).addObject(textObj);
    MathObject newProb = ((MathObject) probGen).clone();
    newProb.setParentContainer(newDoc.getPage(0));
    newProb.setyPos(page.getxMargin() + 165);
    newProb.setxPos((newDoc.getPage(0).getWidth() - 2 * page.getxMargin() - newProb.getWidth()) / 2 + page.getxMargin());
    newDoc.getPage(0).addObject(newProb);
    this.addDoc(newDoc);
}
Also used : TextObject(doc.mathobjects.TextObject) MathObject(doc.mathobjects.MathObject) AttributeException(doc.attributes.AttributeException)

Example 18 with MathObject

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

the class Document method stripAnswers.

public boolean stripAnswers() {
    Vector<MathObject> pageObjects;
    Page p;
    MathObject mObj;
    int oldSize;
    boolean problemsGenerated = false;
    for (int i = 0; i < getPages().size(); i++) {
        pageObjects = getPages().get(i).getObjects();
        oldSize = pageObjects.size();
        for (int j = 0; j < oldSize; j++) {
            mObj = pageObjects.get(j);
            if (mObj instanceof GeneratedProblem) {
                ((GeneratedProblem) mObj).generateNewProblem();
                problemsGenerated = true;
                j--;
                oldSize--;
            }
        }
    }
    return problemsGenerated;
}
Also used : GeneratedProblem(doc.mathobjects.GeneratedProblem) MathObject(doc.mathobjects.MathObject)

Example 19 with MathObject

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

the class Document method layoutProblems.

public static void layoutProblems(List<? extends MathObject> objects, String directions, Document doc, boolean problemNumbers) {
    int extraMarginForDirections = 5;
    PointInDocument pt = doc.findFirstWhitespace();
    Page currentPage = doc.getPage(pt.getPage());
    int greatestWidth = 0, greatestHeight = 0;
    for (MathObject mObj : objects) {
        if (mObj.isHidden())
            continue;
        if (mObj.getWidth() > greatestWidth) {
            greatestWidth = mObj.getWidth();
        }
        if (mObj.getHeight() > greatestHeight) {
            greatestHeight = mObj.getHeight();
        }
    }
    int curryPos = pt.getyPos();
    if (directions != null) {
        // add some extra space between lists of problems
        pt.setyPos(pt.getyPos() + minimumBufferSpace / 2);
        TextObject directionText = new TextObject(currentPage, extraMarginForDirections + currentPage.getxMargin(), pt.getyPos(), currentPage.getWidth() - 2 * currentPage.getxMargin() - 2 * extraMarginForDirections, 20, 12, directions);
        curryPos = pt.getyPos() + directionText.getHeight() + minimumBufferSpace / 2;
        // draw the text in the background, so it has its height set correctly
        NotebookPanel.drawObjectToImage(directionText);
        if (curryPos + greatestHeight < currentPage.getHeight() - currentPage.getyMargin()) {
            // the first row of objects will fit on this page, otherwise move the directions down a page
            currentPage.addObject(directionText);
        } else {
            currentPage = nextPage(currentPage);
            curryPos = currentPage.getyMargin() + minimumBufferSpace;
            directionText.setyPos(curryPos);
            currentPage.addObject(directionText);
            directionText.setParentContainer(currentPage);
            curryPos += directionText.getHeight() + minimumBufferSpace / 2;
        }
    }
    int numColumns = (doc.getWidth() - 2 * doc.getxMargin() - 2 * extraMarginForDirections) / (greatestWidth + minimumBufferSpace);
    numColumns = Math.max(1, numColumns);
    int totalExtraSpace = (doc.getWidth() - 2 * doc.getxMargin() - 2 * extraMarginForDirections) % (greatestWidth + minimumBufferSpace);
    int extraColumnSpace = totalExtraSpace / (numColumns);
    int currColumn = 0;
    ProblemNumberObject problemNumber;
    int lastProblemNumber = doc.getLastProblemNumber();
    for (MathObject mObj : objects) {
        if (mObj.isHidden())
            continue;
        mObj.setxPos(currentPage.getxMargin() + minimumBufferSpace + currColumn * (greatestWidth + minimumBufferSpace + extraColumnSpace));
        mObj.setyPos(curryPos);
        mObj.setParentContainer(currentPage);
        if (mObj.getyPos() + greatestHeight > currentPage.getHeight() - currentPage.getyMargin()) {
            currentPage = nextPage(currentPage);
            curryPos = currentPage.getyMargin() + minimumBufferSpace;
            mObj.setyPos(curryPos);
        }
        if (problemNumbers) {
            // add a number for this problem
            problemNumber = new ProblemNumberObject(currentPage, mObj.getxPos() - 38, mObj.getyPos(), 35, 20, lastProblemNumber);
            // draw it in the background so its height is set properly
            NotebookPanel.drawObjectToImage(problemNumber);
            // center of the height of the problem, or at the top if it is very large
            if (problemNumber.getHeight() * 4 >= mObj.getHeight()) {
                problemNumber.setyPos(mObj.getyPos() + (int) Math.round((mObj.getHeight() / 2.0) - (problemNumber.getHeight() / 2.0)));
            //				problemNumber.setyPos(mObj.getyPos() + (mObj.getHeight() - problemNumber.getHeight())/2);
            } else {
                problemNumber.setyPos(mObj.getyPos() + problemNumber.getHeight());
            }
            currentPage.addObject(problemNumber);
            lastProblemNumber++;
        }
        currentPage.addObject(mObj);
        mObj.setParentContainer(currentPage);
        currColumn++;
        if (currColumn > numColumns - 1) {
            curryPos += greatestHeight + minimumBufferSpace;
            currColumn = 0;
        }
    }
    doc.setLastProblemNumber(lastProblemNumber);
}
Also used : TextObject(doc.mathobjects.TextObject) ProblemNumberObject(doc.mathobjects.ProblemNumberObject) MathObject(doc.mathobjects.MathObject)

Example 20 with MathObject

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

the class Document method generateNewVersion.

public boolean generateNewVersion() {
    Vector<MathObject> pageObjects;
    MathObject mObj;
    int oldSize;
    boolean problemsGenerated = false;
    for (int i = 0; i < getPages().size(); i++) {
        pageObjects = getPages().get(i).getObjects();
        oldSize = pageObjects.size();
        for (int j = 0; j < oldSize; j++) {
            mObj = pageObjects.get(j);
            if (mObj instanceof GeneratedProblem) {
                ((GeneratedProblem) mObj).generateNewProblem();
                problemsGenerated = true;
                j--;
                oldSize--;
            } else if (mObj instanceof Grouping && ((Grouping) mObj).containsGeneratedProblems()) {
                ((Grouping) mObj).generateNewVersion();
                problemsGenerated = true;
            }
        }
    }
    return problemsGenerated;
}
Also used : GeneratedProblem(doc.mathobjects.GeneratedProblem) Grouping(doc.mathobjects.Grouping) MathObject(doc.mathobjects.MathObject)

Aggregations

MathObject (doc.mathobjects.MathObject)31 Grouping (doc.mathobjects.Grouping)6 PointInDocument (doc.PointInDocument)4 Point (java.awt.Point)4 AttributeException (doc.attributes.AttributeException)3 Page (doc.Page)2 GeneratedProblem (doc.mathobjects.GeneratedProblem)2 ProblemGenerator (doc.mathobjects.ProblemGenerator)2 ProblemNumberObject (doc.mathobjects.ProblemNumberObject)2 TextObject (doc.mathobjects.TextObject)2 Rectangle (java.awt.Rectangle)2 MathObjectAttribute (doc.attributes.MathObjectAttribute)1 RectangleObject (doc.mathobjects.RectangleObject)1 VariableValueInsertionProblem (doc.mathobjects.VariableValueInsertionProblem)1 BasicStroke (java.awt.BasicStroke)1 Color (java.awt.Color)1 Component (java.awt.Component)1 Graphics2D (java.awt.Graphics2D)1 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1