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