Search in sources :

Example 11 with StringAttribute

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

the class ProblemGenerator method addProblemAttributes.

private void addProblemAttributes() {
    addAttribute(new StringAttribute(NAME, false));
    addAttribute(new StringAttribute(DIRECTIONS, false));
    addAttribute(new StringAttribute(AUTHOR, false));
    addAttribute(new DateAttribute(DATE, false));
    addAttribute(new UUIDAttribute(UUID_STR, UUID.randomUUID(), false));
    addList(new ListAttribute<>(TAGS, new StringAttribute(""), false));
    addList(new ListAttribute<>(SCRIPTS, new StringAttribute("")));
}
Also used : StringAttribute(doc.attributes.StringAttribute) UUIDAttribute(doc.attributes.UUIDAttribute) DateAttribute(doc.attributes.DateAttribute)

Example 12 with StringAttribute

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

the class VariableValueInsertionProblem method subInVal.

public MathObject subInVal(String s, Node val, MathObject mObj) {
    MathObject newObj = mObj.clone();
    // TODO - use inheritance for this
    if (newObj instanceof Grouping) {
        Grouping newGroup = (Grouping) newObj.clone();
        newGroup.removeAllObjects();
        for (MathObject mathObj : ((Grouping) newObj).getObjects()) {
            newGroup.addObjectFromPage(subInVal(s, val, mathObj));
        }
        return newGroup;
    } else if (newObj instanceof ExpressionObject) {
        final String exString = ((ExpressionObject) newObj).getExpression();
        // TODO - review, make this work with multiple answers
        final String ansString = ((ExpressionObject) newObj).getCorrectAnswers().get(0).getValue();
        if (exString != null && !exString.equals("")) {
            try {
                Node expression = Node.parseNode(exString);
                expression = expression.replace(s, val);
                ((ExpressionObject) newObj).setExpression(expression.toStringRepresentation());
                Node ansExpression = Node.parseNode(ansString);
                ansExpression = ansExpression.replace(s, val);
                // TODO - make this work with multiple answers
                ((ExpressionObject) newObj).getCorrectAnswers().clear();
                ((ExpressionObject) newObj).addCorrectAnswer(ansExpression.toStringRepresentation());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    } else if (newObj instanceof GraphObject) {
        for (StringAttribute exAtt : ((GraphObject) newObj).getExpressions()) {
            if (exAtt.getValue() != null && !exAtt.getValue().equals("")) {
                try {
                    Node expression = Node.parseNode(exAtt.getValue());
                    expression = expression.replace(s, val);
                    exAtt.setValue(expression.toStringRepresentation());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    } else if (newObj instanceof TextObject) {
        final String textString = replaceInString(s, ((TextObject) newObj).getText(), val);
        try {
            ((TextObject) newObj).setText(textString);
        } catch (AttributeException e) {
            e.printStackTrace();
        }
    } else if (newObj instanceof AnswerBoxObject) {
        String str;
        for (StringAttribute strAtt : ((AnswerBoxObject) newObj).getCorrectAnswers().getValues()) {
            str = strAtt.getValue();
            str = replaceInString(s, str, val);
            strAtt.setValue(str);
        }
    }
    return newObj;
}
Also used : Node(expression.Node) StringAttribute(doc.attributes.StringAttribute) AttributeException(doc.attributes.AttributeException) AttributeException(doc.attributes.AttributeException) NodeException(expression.NodeException)

Example 13 with StringAttribute

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

the class OldReader method readAttribute.

public void readAttribute(String uri, String name, String qName, Attributes atts) {
    MathObjectAttribute mAtt = null;
    boolean justAddedAttribute = false;
    if (qName.equals("BooleanAttribute")) {
        mAtt = new BooleanAttribute(atts.getValue(NAME));
        justAddedAttribute = true;
    } else if (qName.equals("DoubleAttribute")) {
        mAtt = new DoubleAttribute(atts.getValue(NAME));
        justAddedAttribute = true;
    } else if (qName.equals("GridPointAttribute")) {
        mAtt = new GridPointAttribute(atts.getValue(NAME));
        justAddedAttribute = true;
    } else if (qName.equals("IntegerAttribute")) {
        mAtt = new IntegerAttribute(atts.getValue(NAME));
        justAddedAttribute = true;
    } else if (qName.equals("StringAttribute")) {
        mAtt = new StringAttribute(atts.getValue(NAME));
        justAddedAttribute = true;
    } else {
        if (mObj == group) {
            return;
        }
        if (DEBUG) {
            System.out.println("bad attribute found! " + qName);
        }
    }
    if (justAddedAttribute) {
        try {
            mAtt.setValueWithString(atts.getValue(VALUE));
            mObj.addAttribute(mAtt);
            mObj.setAttributeValue(mAtt.getName(), mAtt.getValue());
        } catch (AttributeException e) {
            if (DEBUG) {
                System.out.println(e.getMessage());
            }
            hadAttributeError = true;
            attributeNameInError = atts.getValue(NAME);
            attributeValueInError = atts.getValue(VALUE);
            objectWithError = mObj.getClass().getSimpleName();
            justAddedAttribute = false;
            return;
        }
    } else {
        for (int i = 0; i < atts.getLength(); i++) {
            if (DEBUG) {
                System.out.println(atts.getValue(i).toString());
            }
        }
        hadAttributeError = true;
        attributeNameInError = atts.getValue(NAME);
        attributeValueInError = atts.getValue(VALUE);
        objectWithError = mObj.getClass().getSimpleName();
        justAddedAttribute = false;
        return;
    }
}
Also used : BooleanAttribute(doc.attributes.BooleanAttribute) MathObjectAttribute(doc.attributes.MathObjectAttribute) GridPointAttribute(doc.attributes.GridPointAttribute) StringAttribute(doc.attributes.StringAttribute) IntegerAttribute(doc.attributes.IntegerAttribute) AttributeException(doc.attributes.AttributeException) DoubleAttribute(doc.attributes.DoubleAttribute)

Example 14 with StringAttribute

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

the class GraphObjectGUI method drawMathObject.

public void drawMathObject(GraphObject object, Graphics g, Point pageOrigin, float zoomLevel) {
    ScaledSizeAndPosition sap = getSizeAndPosition(object, pageOrigin, zoomLevel);
    graph.removeAllSingleGraphs();
    graph.removeAllPoints();
    int colorIndex = 0;
    boolean hadError = false;
    for (StringAttribute ex : object.getExpressions()) {
        if (!ex.getValue().equals("")) {
            try {
                graph.AddGraph(new GraphedCartFunction(graph, "y=" + ex.getValue(), "x", "y", true, graphColors[colorIndex]));
            } catch (NodeException e) {
                // TODO Auto-generated catch block
                hadError = true;
            }
        }
        colorIndex++;
    }
    //graph.lineGraph.linePoints = object.getPoints();
    graph.lineGraph.linePoints.removeAllElements();
    graph.removeAllPoints();
    for (GridPointAttribute pt : object.getPoints()) {
        if (pt != null) {
            graph.addPoint(pt.getValue().getx(), pt.getValue().gety());
        }
    }
    graph.barGraph.values.removeAllElements();
    for (DoubleAttribute d : object.getBarGraphValues().getValues()) {
        graph.barGraph.values.add(d.getValue());
    }
    graph.barGraph.labels.removeAllElements();
    for (StringAttribute strAttr : object.getBarGraphLabels().getValues()) {
        graph.barGraph.labels.add(strAttr.getValue());
    }
    graph.barGraph.groupSize = object.getBarGraphGroupSize();
    graph.lineGraph.setColor(object.getLineGraphColor());
    synchronized (object.getLineGraphPoints().getValues()) {
        for (GridPointAttribute pt : object.getLineGraphPoints().getValues()) {
            if (pt != null) {
                graph.lineGraph.linePoints.add(new GridPoint(pt.getValue().getx(), pt.getValue().gety()));
            }
        }
    }
    graph.repaint(g, sap.getWidth(), sap.getHeight(), zoomLevel, sap.getxOrigin(), sap.getyOrigin(), object);
    if (hadError) {
        FontMetrics fm = g.getFontMetrics();
        int errorWidth = fm.stringWidth("error");
        g.setColor(Color.WHITE);
        g.fillRect((sap.getxOrigin() + sap.getWidth() / 2) - errorWidth / 2, (sap.getyOrigin() + sap.getHeight() / 2) - fm.getHeight() / 2, errorWidth + 4, fm.getHeight() + 4);
        g.setColor(Color.BLACK);
        g.drawRect((sap.getxOrigin() + sap.getWidth() / 2) - errorWidth / 2, (sap.getyOrigin() + sap.getHeight() / 2) - fm.getHeight() / 2, errorWidth + 4, fm.getHeight() + 4);
        g.setColor(Color.RED);
        g.drawString("error", (sap.getxOrigin() + sap.getWidth() / 2) - errorWidth / 2 + 2, (sap.getyOrigin() + sap.getHeight() / 2) + fm.getHeight() / 2);
    }
}
Also used : GridPoint(doc.GridPoint) FontMetrics(java.awt.FontMetrics) GridPointAttribute(doc.attributes.GridPointAttribute) StringAttribute(doc.attributes.StringAttribute) NodeException(expression.NodeException) GraphedCartFunction(doc_gui.graph.GraphedCartFunction) Point(java.awt.Point) GridPoint(doc.GridPoint) DoubleAttribute(doc.attributes.DoubleAttribute)

Aggregations

StringAttribute (doc.attributes.StringAttribute)14 IntegerAttribute (doc.attributes.IntegerAttribute)6 AttributeException (doc.attributes.AttributeException)5 NodeException (expression.NodeException)5 BooleanAttribute (doc.attributes.BooleanAttribute)4 DoubleAttribute (doc.attributes.DoubleAttribute)4 Node (expression.Node)4 GridPointAttribute (doc.attributes.GridPointAttribute)3 Vector (java.util.Vector)3 ColorAttribute (doc.attributes.ColorAttribute)2 DateAttribute (doc.attributes.DateAttribute)2 EnumeratedAttribute (doc.attributes.EnumeratedAttribute)2 MathObjectAttribute (doc.attributes.MathObjectAttribute)2 Expression (expression.Expression)2 Point (java.awt.Point)2 GridPoint (doc.GridPoint)1 ListAttribute (doc.attributes.ListAttribute)1 SelectionAttribute (doc.attributes.SelectionAttribute)1 UUIDAttribute (doc.attributes.UUIDAttribute)1 ExpressionObject (doc.mathobjects.ExpressionObject)1