Search in sources :

Example 1 with AttributeException

use of doc.attributes.AttributeException in project OpenNotebook by jaltekruse.

the class BasicDistributiveProperty method setAttributes.

@Override
protected void setAttributes() {
    setName("Basic Distribution");
    setAuthor("Open Notebook Staff");
    setDirections("Simplify.");
    try {
        setAttributeValue(UUID_STR, new UUID(41209481357524305L, 3562391204983210319L));
        addTags("Distribution", "multiplication", "linear factor", "simplify");
    } catch (AttributeException e) {
        // should not be thrown
        throw new RuntimeException(e);
    }
    setDate(new Date(2, 1, 2011));
}
Also used : UUID(java.util.UUID) AttributeException(doc.attributes.AttributeException) Date(doc.attributes.Date)

Example 2 with AttributeException

use of doc.attributes.AttributeException in project OpenNotebook by jaltekruse.

the class ExpressionGenerator method generateProblem.

public GeneratedProblem generateProblem(int difficulty) {
    GeneratedProblem newProblem = new GeneratedProblem();
    ExpressionObject expressionObj = new ExpressionObject();
    try {
        newProblem.setDifficulty(difficulty);
        newProblem.getListWithName(GeneratedProblem.GEN_LIST).getValues().clear();
        ((ListAttribute<UUIDAttribute>) newProblem.getListWithName(GeneratedProblem.GEN_LIST)).addValueWithString(getProblemID().toString());
        Node[] n = generateExpression(difficulty);
        expressionObj.setExpression(n[0].toStringRepresentation());
        expressionObj.addCorrectAnswer(n[1].toStringRepresentation());
    } catch (AttributeException e) {
        e.printStackTrace();
    } catch (NodeException e) {
        e.printStackTrace();
    }
    getProblemHoldingDocument().getDocViewerPanel().drawObjectInBackground(expressionObj);
    expressionObj.setParentContainer(newProblem.getParentContainer());
    newProblem.addObjectFromPage(expressionObj);
    return newProblem;
}
Also used : ExpressionObject(doc.mathobjects.ExpressionObject) Node(expression.Node) GeneratedProblem(doc.mathobjects.GeneratedProblem) NodeException(expression.NodeException) AttributeException(doc.attributes.AttributeException) ListAttribute(doc.attributes.ListAttribute)

Example 3 with AttributeException

use of doc.attributes.AttributeException in project OpenNotebook by jaltekruse.

the class PropertyOfOppositiesWithVariables method setAttributes.

@Override
protected void setAttributes() {
    setName("Property of Opposites");
    setAuthor("Open Notebook Staff");
    setDirections("Simplify.");
    try {
        this.setAttributeValue(UUID_STR, new UUID(282395472492378295L, 1905635205832531290L));
        getTags().addValueWithString("Arithmetic");
        getTags().addValueWithString("Addition");
        getTags().addValueWithString("Integers");
        getTags().addValueWithString("Negative Numbers");
        getTags().addValueWithString("Opposities");
        getTags().addValueWithString("Cancel terms");
        getTags().addValueWithString("Variables");
    } catch (AttributeException e) {
        // should not be thrown
        throw new RuntimeException(e);
    }
    setDate(new Date(2, 1, 2011));
}
Also used : UUID(java.util.UUID) AttributeException(doc.attributes.AttributeException) Date(doc.attributes.Date)

Example 4 with AttributeException

use of doc.attributes.AttributeException 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 5 with AttributeException

use of doc.attributes.AttributeException in project OpenNotebook by jaltekruse.

the class AssociativePropertiesWithVariables method setAttributes.

@Override
protected void setAttributes() {
    setName("Associative Property Problem With Variables");
    setAuthor("Open Notebook Staff");
    setDirections("Simplify. Use the associative and commutative properties of addition and multiplication" + " to reorder and regroup the numbers into easier calculations.");
    try {
        this.setAttributeValue(UUID_STR, new UUID(4190756404850524305L, 3560661854204360419L));
        getTags().addValueWithString("Arithmetic");
        getTags().addValueWithString("Addition");
        getTags().addValueWithString("Multiplication");
        getTags().addValueWithString("Integers");
        getTags().addValueWithString("Variables");
        getTags().addValueWithString("Mental Math");
    } catch (AttributeException e) {
        // should not be thrown
        throw new RuntimeException("error that should not happen in BaiscArithmaticExpression");
    }
    setDate(new Date(2, 1, 2011));
}
Also used : UUID(java.util.UUID) AttributeException(doc.attributes.AttributeException) Date(doc.attributes.Date)

Aggregations

AttributeException (doc.attributes.AttributeException)20 Date (doc.attributes.Date)9 UUID (java.util.UUID)9 StringAttribute (doc.attributes.StringAttribute)4 Node (expression.Node)3 NodeException (expression.NodeException)3 Vector (java.util.Vector)3 MathObjectAttribute (doc.attributes.MathObjectAttribute)2 GridBagConstraints (java.awt.GridBagConstraints)2 Insets (java.awt.Insets)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 JLabel (javax.swing.JLabel)2 Document (doc.Document)1 GridPoint (doc.GridPoint)1 Page (doc.Page)1 ProblemDatabase (doc.ProblemDatabase)1 BooleanAttribute (doc.attributes.BooleanAttribute)1 DoubleAttribute (doc.attributes.DoubleAttribute)1 GridPointAttribute (doc.attributes.GridPointAttribute)1