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));
}
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));
}
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;
}
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));
}
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;
}
}
Aggregations