Search in sources :

Example 1 with TextObject

use of doc.mathobjects.TextObject 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 2 with TextObject

use of doc.mathobjects.TextObject 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 3 with TextObject

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

the class OldReader method startElement.

@Override
public void startElement(String uri, String name, String qName, Attributes atts) {
    boolean justAddedObject = false;
    if (qName.equals("OpenNotebookDoc")) {
        doc = new Document(atts.getValue(Document.FILENAME));
        doc.setAuthor(atts.getValue(Document.AUTHOR));
    }
    if (doc != null) {
        if (qName.equals("Page")) {
            page = new Page(doc);
            doc.addPage(page);
            return;
        }
        if (page != null) {
            if (mObj != null) {
                readAttribute(uri, name, qName, atts);
            }
            if (qName.equals("AnswerBox")) {
                mObj = new AnswerBoxObject(page);
                justAddedObject = true;
            }
            if (qName.equals("CubeObject")) {
                mObj = new CubeObject(page);
                justAddedObject = true;
            } else if (qName.equals("ExpressionObject")) {
                mObj = new ExpressionObject(page);
                justAddedObject = true;
            } else if (qName.equals("GraphObject")) {
                mObj = new GraphObject(page);
                justAddedObject = true;
            } else if (qName.equals("NumberLineObject")) {
                mObj = new NumberLineObject(page);
                justAddedObject = true;
            } else if (qName.equals("OvalObject")) {
                mObj = new OvalObject(page);
                justAddedObject = true;
            } else if (qName.equals("ParallelogramObject")) {
                mObj = new ParallelogramObject(page);
                justAddedObject = true;
            } else if (qName.equals("RectangleObject")) {
                mObj = new RectangleObject(page);
                justAddedObject = true;
            } else if (qName.equals("TextObject")) {
                mObj = new TextObject(page);
                justAddedObject = true;
            } else if (qName.equals("TrapezoidObject")) {
                mObj = new TrapezoidObject(page);
                justAddedObject = true;
            } else if (qName.equals("TriangleObject")) {
                mObj = new TriangleObject(page);
                justAddedObject = true;
            }
            if (justAddedObject) {
                if (page != null) {
                    page.addObject(mObj);
                }
            }
        }
    }
}
Also used : NumberLineObject(doc.mathobjects.NumberLineObject) RectangleObject(doc.mathobjects.RectangleObject) Page(doc.Page) Document(doc.Document) GraphObject(doc.mathobjects.GraphObject) TrapezoidObject(doc.mathobjects.TrapezoidObject) TextObject(doc.mathobjects.TextObject) TriangleObject(doc.mathobjects.TriangleObject) ExpressionObject(doc.mathobjects.ExpressionObject) AnswerBoxObject(doc.mathobjects.AnswerBoxObject) CubeObject(doc.mathobjects.CubeObject) OvalObject(doc.mathobjects.OvalObject) ParallelogramObject(doc.mathobjects.ParallelogramObject)

Aggregations

TextObject (doc.mathobjects.TextObject)3 MathObject (doc.mathobjects.MathObject)2 Document (doc.Document)1 Page (doc.Page)1 AttributeException (doc.attributes.AttributeException)1 AnswerBoxObject (doc.mathobjects.AnswerBoxObject)1 CubeObject (doc.mathobjects.CubeObject)1 ExpressionObject (doc.mathobjects.ExpressionObject)1 GraphObject (doc.mathobjects.GraphObject)1 NumberLineObject (doc.mathobjects.NumberLineObject)1 OvalObject (doc.mathobjects.OvalObject)1 ParallelogramObject (doc.mathobjects.ParallelogramObject)1 ProblemNumberObject (doc.mathobjects.ProblemNumberObject)1 RectangleObject (doc.mathobjects.RectangleObject)1 TrapezoidObject (doc.mathobjects.TrapezoidObject)1 TriangleObject (doc.mathobjects.TriangleObject)1