Search in sources :

Example 16 with AttributeException

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

the class BasicAdditionWithNegatives method setAttributes.

@Override
protected void setAttributes() {
    setName("Basic Addition with Negatives");
    setAuthor("Open Notebook Staff");
    setDirections("Simplify.");
    try {
        this.setAttributeValue(UUID_STR, new UUID(28463475628230495L, 3540572839103937290L));
        getTags().addValueWithString("Arithmetic");
        getTags().addValueWithString("Addition");
        getTags().addValueWithString("Integers");
        getTags().addValueWithString("Negative Numbers");
        getTags().addValueWithString("Subtraction");
        getTags().addValueWithString("Negation");
    } 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 17 with AttributeException

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

the class MathObject method setAttributeValueWithString.

public void setAttributeValueWithString(String s, String val) throws AttributeException {
    int i = 5;
    if (s.equals("selection")) {
        i++;
    }
    if (getAttributeWithName(s) == null) {
        throw new AttributeException("Object does not have an attribute with that name");
    }
    setAttributeValue(s, getAttributeWithName(s).readValueFromString(val));
}
Also used : AttributeException(doc.attributes.AttributeException) GridPoint(doc.GridPoint)

Example 18 with AttributeException

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

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

the class ListAdjuster method addPanelContent.

public void addPanelContent() {
    // TODO - stopwatch and logging
    //		System.out.println("start list gui" + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
    this.removeAll();
    GridBagConstraints con = new GridBagConstraints();
    con.gridx = 0;
    con.gridy = 0;
    con.fill = GridBagConstraints.NONE;
    // this code below ended up not working as well as I thought it would
    // I really need to revalidate the parent frame, but I don't want to limit its
    // functionality in different uses, so for now I'm just going to disable it
    //		if (expanded){
    //			JButton expandButton = new JButton(docPanel.getIcon(EXPANDED_PIC));
    //			expandButton.addActionListener(new ExpandedButtonListener());
    //			this.add(expandButton, con);
    //		}
    //		else{
    //			JButton notExpandedButton = new JButton(docPanel.getIcon(NOT_EXPANDED_PIC));
    //			notExpandedButton.addActionListener(new NotExpandedButtonListener());
    //			this.add(notExpandedButton, con);
    //			con.gridx = 1;
    //			con.weightx = 1;
    //			con.weighty = 1;
    //			con.fill = GridBagConstraints.HORIZONTAL;
    //			this.add(new JLabel(lAtt.getName()), con);
    //			this.revalidate();
    //			return;
    //		}
    con.gridx = 1;
    con.weightx = 1;
    con.weighty = 1;
    con.fill = GridBagConstraints.HORIZONTAL;
    this.add(new JLabel(lAtt.getName()), con);
    con.gridx = 0;
    con.gridy++;
    con.gridwidth = 2;
    GridBagConstraints pcon = new GridBagConstraints();
    pcon.gridx = 0;
    pcon.gridy = 0;
    pcon.fill = GridBagConstraints.BOTH;
    pcon.weightx = 1;
    pcon.weighty = 1;
    int index = 0;
    JPanel p;
    for (MathObjectAttribute mAtt : (Vector<MathObjectAttribute>) lAtt.getValues()) {
        p = new JPanel();
        p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
        last = ObjectPropertiesFrame.getAdjuster(mAtt, notebookPanel, p);
        p.add(last);
        p.add(Box.createRigidArea(new Dimension(3, 0)));
        JButton button = new JButton("x");
        button.setMargin(new Insets(0, 0, 0, 0));
        button.addActionListener(new CloseButtonListener(index));
        button.setMaximumSize(new Dimension(15, 15));
        p.add(button);
        p.add(Box.createRigidArea(new Dimension(3, 0)));
        this.add(p, con);
        con.gridy++;
        index++;
    }
    con.fill = GridBagConstraints.HORIZONTAL;
    JButton addButton = new JButton("Add new");
    addButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent ev) {
            try {
                lAtt.addNewValue();
                //					if ( lAtt.getParentObject() != null)
                //					{// forces the object property frame to be layed out again
                //						notebookPanel.getCurrentDocViewer().setFocusedObject(lAtt.getParentObject());
                //					}
                //					notebookPanel.getCurrentDocViewer().updateObjectToolFrame();
                //					notebookPanel.getCurrentDocViewer().repaintDoc();
                addPanelContent();
                notebookPanel.getCurrentDocViewer().propertiesFrameRefacoringNeeded = true;
                notebookPanel.getCurrentDocViewer().repaintDoc();
            } catch (AttributeException e) {
                if (!showingDialog) {
                    showingDialog = true;
                    JOptionPane.showMessageDialog(null, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
                    showingDialog = false;
                }
            }
        }
    });
    this.add(addButton, con);
//		this.revalidate();
//		System.out.println("finish list gui" + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) AttributeException(doc.attributes.AttributeException) MathObjectAttribute(doc.attributes.MathObjectAttribute) ActionListener(java.awt.event.ActionListener) Vector(java.util.Vector)

Example 20 with AttributeException

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

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