Search in sources :

Example 1 with ProblemNumberObject

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

the class Document method getProblemNumbersInOrder.

private Vector<ObjectAndPosition> getProblemNumbersInOrder() {
    Vector<ObjectAndPosition> allNumbers = new Vector<>();
    for (Page p : getPages()) {
        for (MathObject mObj : p.getObjects()) {
            if (mObj instanceof ProblemNumberObject) {
                allNumbers.add(new ObjectAndPosition(mObj.getPositionInDoc(), mObj));
            } else if (mObj instanceof Grouping) {
                allNumbers.addAll(0, findAllProblemNumbersInGroup(((Grouping) mObj)));
            }
        }
    }
    Collections.sort(allNumbers);
    return allNumbers;
}
Also used : ProblemNumberObject(doc.mathobjects.ProblemNumberObject) Grouping(doc.mathobjects.Grouping) MathObject(doc.mathobjects.MathObject)

Example 2 with ProblemNumberObject

use of doc.mathobjects.ProblemNumberObject 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)

Aggregations

MathObject (doc.mathobjects.MathObject)2 ProblemNumberObject (doc.mathobjects.ProblemNumberObject)2 Grouping (doc.mathobjects.Grouping)1 TextObject (doc.mathobjects.TextObject)1