Search in sources :

Example 1 with Document

use of doc.Document in project OpenNotebook by jaltekruse.

the class DocReader method startElement.

@Override
public void startElement(String uri, String name, String qName, Attributes atts) {
    if (qName.equals(Document.OPEN_NOTEBOOK_DOC)) {
        // the name of the file in the filesystem
        // will allow documents that are renamed outside of
        // the application to take their new name
        doc = new Document(fileName);
        doc.setAuthor(atts.getValue(Document.AUTHOR));
        if (atts.getValue(Document.LAST_PROBLEM_NUMBER) != null) {
            doc.setLastProblemNumber(Integer.parseInt(atts.getValue(Document.LAST_PROBLEM_NUMBER)));
        }
        if (atts.getValue(Document.X_MARGIN) != null) {
            doc.setxMargin(Double.parseDouble(atts.getValue(Document.X_MARGIN)));
        }
        if (atts.getValue(Document.Y_MARGIN) != null) {
            doc.setyMargin(Double.parseDouble(atts.getValue(Document.Y_MARGIN)));
        }
        return;
    } else if (qName.equals(ProblemDatabase.NAME)) {
        database = new ProblemDatabase();
        readingProblemDatabase = true;
        return;
    } else if (qName.equals(Document.GENERATORS)) {
        readingGenerators = true;
        return;
    } else if (qName.equals(ListAttribute.LIST)) {
        if (mObj != null) {
            // grab the list from the current object with the specified name
            list = mObj.getListWithName(atts.getValue(NAME));
            if (list != null && !overridenLists.contains(atts.getValue(ListAttribute.NAME))) {
                // the object had a list with the given name
                list.removeAll();
                readingList = true;
            }
            if (DEBUG) {
                System.out.println("list added: " + list);
            }
            return;
        }
    } else if (qName.equals(ListAttribute.ENTRY)) {
        if (!readingList) {
            // this is an entry for a list that is currently not in use
            if (DEBUG) {
                System.out.println("  found entry tag, but not reading a list");
            }
            return;
        }
        try {
            list.addValueWithString(atts.getValue(ListAttribute.VAL));
            return;
        } catch (AttributeException e) {
            hadAttributeError = true;
            attributeNameInError = atts.getValue(NAME);
            attributeValueInError = atts.getValue(VALUE);
            objectWithError = mObj.getClass().getSimpleName();
            return;
        }
    } else if (doc != null || readingProblemDatabase) {
        if (qName.equals("Page")) {
            page = new Page(doc);
            doc.addPage(page);
            return;
        }
        if (page != null || readingGenerators || readingProblemDatabase) {
            if (mObj != null) {
                if (DEBUG) {
                    System.out.println("in object, should be finding attributes, or other objects if in group");
                }
                if (readAttribute(uri, name, qName, atts)) {
                    // if the current tag was an attribute
                    if (DEBUG) {
                        System.out.println("return found attribute");
                    }
                    return;
                }
            }
            if (DEBUG) {
                System.out.println("tag was not attribute " + qName);
            }
            if (qName.equals("survey")) {
                int j = 1;
            }
            mObj = MathObject.newInstanceWithType(qName);
            if (mObj == null) {
                mObj = readOldObjectName(qName);
            }
            if (mObj != null) {
                if (DEBUG) {
                    System.out.println();
                    System.out.println("added Object: " + mObj.getClass().getSimpleName());
                }
                if (page != null) {
                    mObj.setParentContainer(page);
                }
            } else {
                foundBadTag = true;
                badTag = qName;
                return;
            }
            if (!containerStack.isEmpty()) {
                // if an object tag was found in a group, there is an object in a group
                if (mObj != null) {
                    objectsInGroup.get(objectsInGroup.size() - 1).add(mObj);
                    if (mObj instanceof Grouping) {
                        containerStack.add((Grouping) mObj);
                        objectsInGroup.add(new Vector<MathObject>());
                    }
                }
            } else {
                // in the document, or in the background of the application
                if (readingGenerators || readingProblemDatabase) {
                    if (DEBUG) {
                        System.out.println("wait until attributes are read before adding to database");
                    }
                } else {
                    page.addObject(mObj);
                }
                if (mObj instanceof Grouping) {
                    containerStack.add((Grouping) mObj);
                    objectsInGroup.add(new Vector<MathObject>());
                }
            }
        }
    }
}
Also used : Page(doc.Page) Grouping(doc.mathobjects.Grouping) ProblemDatabase(doc.ProblemDatabase) Document(doc.Document) AttributeException(doc.attributes.AttributeException) Vector(java.util.Vector)

Example 2 with Document

use of doc.Document in project OpenNotebook by jaltekruse.

the class TestDocumentManipulation method testDocCreation.

public void testDocCreation() {
    Document doc = new Document("doc");
    doc.addBlankPage();
    assertEquals(doc.getPages().size(), 1);
}
Also used : Document(doc.Document)

Example 3 with Document

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

Example 4 with Document

use of doc.Document in project OpenNotebook by jaltekruse.

the class DocViewerPanel method destroyAllUndoStates.

public void destroyAllUndoStates() {
    for (Document doc : actions) {
        notebook.getNotebookPanel().destroyDoc(doc);
    }
    for (Document doc : actions) {
        notebook.getNotebookPanel().destroyDoc(doc);
    }
    notebook.getNotebookPanel().destroyDoc(lastAction);
    undoneActions = new Stack<>();
    actions = new Stack<>();
}
Also used : Document(doc.Document) PointInDocument(doc.PointInDocument)

Aggregations

Document (doc.Document)4 Page (doc.Page)2 PointInDocument (doc.PointInDocument)1 ProblemDatabase (doc.ProblemDatabase)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 Grouping (doc.mathobjects.Grouping)1 NumberLineObject (doc.mathobjects.NumberLineObject)1 OvalObject (doc.mathobjects.OvalObject)1 ParallelogramObject (doc.mathobjects.ParallelogramObject)1 RectangleObject (doc.mathobjects.RectangleObject)1 TextObject (doc.mathobjects.TextObject)1 TrapezoidObject (doc.mathobjects.TrapezoidObject)1 TriangleObject (doc.mathobjects.TriangleObject)1 Vector (java.util.Vector)1