use of doc.attributes.StringAttribute in project OpenNotebook by jaltekruse.
the class TextObject method addDefaultAttributes.
@Override
public void addDefaultAttributes() {
addAttribute(new StringAttribute(TEXT, ""));
addAttribute(new IntegerAttribute(FONT_SIZE, 12, 1, 50));
addAttribute(new BooleanAttribute(SHOW_BOX, false));
addAttribute(new EnumeratedAttribute(ALIGNMENT, LEFT, alignments));
addAction(MathObject.MAKE_INTO_PROBLEM);
}
use of doc.attributes.StringAttribute in project OpenNotebook by jaltekruse.
the class VariableValueInsertionProblem method generateProblem.
public GeneratedProblem generateProblem(int difficulty) {
Grouping newProblem = new Grouping(getParentContainer(), getxPos(), getyPos() + getHeight() + bufferSpace, getWidth(), getHeight());
String s;
Node n = null;
Vector<String> varNames = new Vector<>();
Vector<Number> varVals = new Vector<>();
for (StringAttribute strAtt : (Vector<StringAttribute>) getScripts().getValues()) {
s = strAtt.getValue();
if (s == null || s.equals("")) {
continue;
}
try {
n = Node.parseNode(s);
//sub in variables already assigned in previous scripts
for (int i = 0; i < varNames.size(); i++) {
n = n.replace(varNames.get(i), varVals.get(i));
}
n = n.numericSimplify();
if (n instanceof Expression) {
Expression ex = (Expression) n;
if (ex.getOperator() instanceof Operator.Equals) {
if (ex.getChild(0) instanceof Identifier) {
Identifier var = (Identifier) ex.getChild(0);
if (ex.getChild(1) instanceof Number) {
varNames.add(var.getIdentifier());
// this causes a lot of unneeded parenthesis
// but without it, you cannot sub in a value
// where there is an implied parenthesis
// ex.getChild(1).setDisplayParentheses(true);
varVals.add((Number) ex.getChild(1));
}
}
}
}
} catch (NodeException e) {
JOptionPane.showMessageDialog(null, "Error generating a problem, check scripts.", ERROR, JOptionPane.ERROR_MESSAGE);
}
}
MathObject newObj = null;
for (MathObject mObj : getObjects()) {
newObj = mObj.clone();
for (int i = 0; i < varNames.size(); i++) {
newObj = subInVal(varNames.get(i), varVals.get(i), newObj);
}
//shift object down so it doesn't overlap the current problem
newObj.setyPos(newObj.getyPos() + getHeight() + bufferSpace);
//this line sets the bounds to the actual space it takes to render them
if (getParentContainer() != null) {
// if this problem formula is in the background storage for a document
getParentDoc().getDocViewerPanel().drawObjectInBackground(newObj);
} else {
// if this problem formula is actually on a document
getProblemHoldingDocument().getDocViewerPanel().drawObjectInBackground(newObj);
}
newObj.setParentContainer(newProblem.getParentContainer());
newProblem.addObjectFromPage(newObj);
}
return new GeneratedProblem(newProblem.getParentContainer(), this.getProblemID(), newProblem);
}
use of doc.attributes.StringAttribute in project OpenNotebook by jaltekruse.
the class Document method addAttributes.
private void addAttributes() {
addAttribute(new StringAttribute(FILENAME));
addAttribute(new StringAttribute(AUTHOR));
addAttribute(new DateAttribute(DATE));
addAttribute(new IntegerAttribute(LAST_PROBLEM_NUMBER, 1));
addAttribute(new DoubleAttribute(X_MARGIN, .5, .5, 3));
addAttribute(new DoubleAttribute(Y_MARGIN, .5, .5, 3));
}
use of doc.attributes.StringAttribute in project OpenNotebook by jaltekruse.
the class ExpressionObject method addDefaultAttributes.
@Override
protected void addDefaultAttributes() {
addAttribute(new StringAttribute(EXPRESSION));
addList(new ListAttribute<>(CORRECT_ANSWERS, new StringAttribute(""), 20, true, false));
addList(new ListAttribute<>(STEPS, new StringAttribute("val"), false));
addAttribute(new IntegerAttribute(FONT_SIZE, 1, 50));
addAttribute(new ColorAttribute(FILL_COLOR));
addAttribute(new BooleanAttribute(ALWAYS_SHOW_STEPS, true, true, false));
getAttributeWithName(EXPRESSION).setValue("");
getAttributeWithName(FONT_SIZE).setValue(12);
getAttributeWithName(FILL_COLOR).setValue(null);
}
use of doc.attributes.StringAttribute in project OpenNotebook by jaltekruse.
the class ObjectPropertiesFrame method generatePanel.
/**
* Generates a menu for adjusting the properties of a mathobject.
*
* @param o - object to base menu panel on
*/
public void generatePanel(MathObject o) {
System.out.println("generate panel" + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
if (o == null) {
return;
}
this.getContentPane().removeAll();
object = o;
JPanel panel = mainPanel;
mainPanel.removeAll();
adjusters.removeAllElements();
listAdjusters.removeAllElements();
this.setTitle(o.getType());
JTabbedPane panelTabs = null;
JPanel tabOneContents = null, tabTwoContents = null;
GridBagConstraints con = new GridBagConstraints();
con.fill = GridBagConstraints.BOTH;
con.weightx = 1;
con.weighty = 1;
con.insets = new Insets(2, 2, 2, 2);
con.gridx = 0;
con.gridy = 0;
System.out.println("end init stuff" + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
if (o instanceof GraphObject || (o instanceof ExpressionObject && !notebookPanel.isInStudentMode())) {
// there are too many attributes and actions for the graph to put them all in one panel
// add a tabbed pane to make it more reasonable and avoid scrolling
panelTabs = new JTabbedPane();
this.getContentPane().add(panelTabs);
tabOneContents = new JPanel();
tabOneContents.setLayout(new GridBagLayout());
tabTwoContents = new JPanel();
tabTwoContents.setLayout(new GridBagLayout());
System.out.println("1 " + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
JScrollPane tabScrollPane = new JScrollPane(panelTabs);
tabScrollPane.getVerticalScrollBar().setUnitIncrement(16);
tabScrollPane.getHorizontalScrollBar().setUnitIncrement(16);
System.out.println("2 " + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
tabScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
if (o instanceof GraphObject) {
panelTabs.add("Nav", tabOneContents);
panelTabs.add("Grid", tabTwoContents);
panel = tabOneContents;
} else if (o instanceof ExpressionObject) {
panelTabs.add("Expression", tabOneContents);
panelTabs.add("Solve", tabTwoContents);
panel = tabOneContents;
}
System.out.println("3 " + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
this.getContentPane().add(tabScrollPane);
System.out.println("4 " + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
} else {
this.getContentPane().add(scrollPane);
}
System.out.println("done with tabs " + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
con.weighty = .01;
JPanel actionPics = new JPanel();
actionPics.setLayout(new GridLayout(0, 4, 4, 4));
JPanel otherActions = new JPanel();
otherActions.setLayout(new GridLayout(0, 1, 4, 4));
ImageIcon pic;
JButton button;
if (!notebookPanel.isInStudentMode()) {
for (final String s : o.getActions()) {
pic = getIconForAction(s);
if (pic != null)
createButton(s, 0, 0, 0, 0, actionPics);
else
createButton(s, 0, 0, 0, 0, otherActions);
}
}
System.out.println("teacher actions done" + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
boolean skipAction;
for (final String s : o.getStudentActions()) {
skipAction = false;
if (object instanceof GraphObject) {
// use more intuitive
for (String str : graphNavActions) {
if (s.equals(str)) {
skipAction = true;
break;
}
}
}
if (object instanceof ExpressionObject) {
// in a separate panel to make the list of actions smaller
for (String str : expressionOpActions) {
if (s.equals(str)) {
skipAction = true;
break;
}
}
}
if (skipAction) {
continue;
}
pic = getIconForAction(s);
if (pic != null)
createButton(s, 0, 0, 0, 0, actionPics);
else
createButton(s, 0, 0, 0, 0, otherActions);
}
System.out.println("student actions done" + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
if (otherActions.getComponentCount() != 0) {
// only add panel for actions if components have been added to it
panel.add(otherActions, con);
con.gridy++;
}
if (actionPics.getComponentCount() != 0) {
// only add panel for action pics if components have been added to it
panel.add(actionPics, con);
con.gridy++;
}
if (object instanceof GraphObject) {
panel.add(createGraphNavigator(), con);
con.gridy++;
}
if (o instanceof ExpressionObject && !notebookPanel.isInStudentMode()) {
// there are too many attributes and actions for the expression to put them all in one panel
// added a tabbed pane to make it more reasonable and avoid scrolling
// this line moves to the other tab to place components there
panel = tabTwoContents;
}
if (object instanceof ExpressionObject) {
panel.add(createExpressionModifier(), con);
con.gridy++;
}
//Switch back to tab one if in teacher mode, to allow attribute adjusters to be on the first tab
if (o instanceof ExpressionObject && !notebookPanel.isInStudentMode())
panel = tabOneContents;
con.fill = GridBagConstraints.HORIZONTAL;
if (o instanceof GraphObject) {
// there are too many attributes and actions for the graph to put them all in one panel
// added a tabbed pane to make it more reasonable and avoid scrolling
// this line moves to the other tab to place components there
panel = new JPanel();
panel.setLayout(new GridBagLayout());
con.anchor = GridBagConstraints.PAGE_START;
tabTwoContents.add(panel, con);
con.anchor = GridBagConstraints.CENTER;
}
con.fill = GridBagConstraints.BOTH;
for (MathObjectAttribute mAtt : o.getAttributes()) {
if (notebookPanel.isInStudentMode() && mAtt.isStudentEditable() || (!notebookPanel.isInStudentMode() && mAtt.isUserEditable())) {
// only show editing dialog if in teacher mode (not student)
//or if the attribute has been left student editable
adjusters.add(getAdjuster(mAtt, notebookPanel, panel));
if (mAtt instanceof StringAttribute) {
// make string panels stretch vertically
con.weighty = 1;
con.fill = GridBagConstraints.BOTH;
} else {
// make all others stretch very little vertically
con.weighty = 0;
con.fill = GridBagConstraints.HORIZONTAL;
}
panel.add(adjusters.get(adjusters.size() - 1), con);
con.gridy++;
}
}
System.out.println("end att adjusters:" + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
con.weighty = 1;
if (o instanceof GraphObject) {
// see above comments about tabs for some objects
panel = tabOneContents;
}
for (ListAttribute list : o.getLists()) {
if ((notebookPanel.isInStudentMode() && list.isStudentEditable()) || (!notebookPanel.isInStudentMode() && list.isUserEditable())) {
// only show editing dialog if in teacher mode (not student)
//or if the attribute has been left student editable
listAdjusters.add(new ListAdjuster(list, notebookPanel, panel));
panel.add(listAdjusters.get(listAdjusters.size() - 1), con);
con.gridy++;
}
}
System.out.println("end lists:" + +(new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
if (panel.getComponentCount() == 0) {
panel.add(new JLabel("No actions for this object"), con);
}
panel.revalidate();
this.pack();
this.update();
this.setSize(this.getWidth() + 30, this.getHeight());
System.out.println("done making props frame" + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
}
Aggregations