Search in sources :

Example 1 with MathObjectAttribute

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

the class Document method clone.

public Document clone() {
    Document newDoc = new Document(new String(getName()));
    newDoc.attributes = new Vector<>();
    MathObject lastWithFocus = this.getLastFocused();
    for (MathObjectAttribute mAtt : getAttributes()) {
        newDoc.addAttribute(mAtt.clone());
    }
    for (ProblemGenerator gen : generators) {
        try {
            newDoc.addGenerator((ProblemGenerator) gen.clone());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    for (Page p : pages) {
        newDoc.addPage(p.clone());
    }
    // the last focused member of this document is used to pass back
    // its cloned version from the page cloning method
    newDoc.setLastFocused(this.getLastFocused());
    // the last focused object is saved at the beginning of the method
    // to prevent being overridden as described in the above comment
    // this.setLastFocused(lastWithFocus);
    newDoc.setDocViewerPanel(getDocViewerPanel());
    return newDoc;
}
Also used : MathObjectAttribute(doc.attributes.MathObjectAttribute) MathObject(doc.mathobjects.MathObject) AttributeException(doc.attributes.AttributeException) ProblemGenerator(doc.mathobjects.ProblemGenerator)

Example 2 with MathObjectAttribute

use of doc.attributes.MathObjectAttribute 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));
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) ImageIcon(javax.swing.ImageIcon) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) JTabbedPane(javax.swing.JTabbedPane) JButton(javax.swing.JButton) StringAttribute(doc.attributes.StringAttribute) JLabel(javax.swing.JLabel) GraphObject(doc.mathobjects.GraphObject) Date(java.util.Date) GridLayout(java.awt.GridLayout) MathObjectAttribute(doc.attributes.MathObjectAttribute) ExpressionObject(doc.mathobjects.ExpressionObject) ListAttribute(doc.attributes.ListAttribute)

Example 3 with MathObjectAttribute

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

the class ObjectPropertiesFrame method generatePanel.

public JPanel generatePanel(Document doc, DocViewerPanel docPanel) {
    JPanel panel = new JPanel();
    if (doc != null) {
        panel.setLayout(new GridBagLayout());
        GridBagConstraints con = new GridBagConstraints();
        con.fill = GridBagConstraints.BOTH;
        con.weightx = 1;
        con.weighty = 1;
        con.insets = new Insets(2, 0, 2, 0);
        con.gridx = 0;
        con.gridy = 0;
        for (MathObjectAttribute mAtt : doc.getAttributes()) {
            if (docPanel.isInStudentMode() && mAtt.isStudentEditable() || !docPanel.isInStudentMode()) {
                // only show editing dialog if in teacher mode (not student)
                //or if the attribute has been left student editable
                panel.add(getAdjuster(mAtt, notebookPanel, panel), con);
                con.gridy++;
            }
        }
    }
    return panel;
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) MathObjectAttribute(doc.attributes.MathObjectAttribute) GridBagLayout(java.awt.GridBagLayout)

Example 4 with MathObjectAttribute

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

the class Grouping method exportToXML.

@Override
public String exportToXML() {
    String output = "";
    output += "<" + getType() + ">\n";
    for (MathObjectAttribute mAtt : getAttributes()) {
        output += mAtt.exportToXML();
    }
    for (ListAttribute lAtt : getLists()) {
        output += lAtt.exportToXML();
    }
    for (MathObject mObj : getObjects()) {
        output += mObj.exportToXML();
    }
    output += "</" + getType() + ">\n";
    return output;
}
Also used : MathObjectAttribute(doc.attributes.MathObjectAttribute) ListAttribute(doc.attributes.ListAttribute)

Example 5 with MathObjectAttribute

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

the class Grouping method getObjectWithAnswer.

public MathObject getObjectWithAnswer() {
    // this creation method allows for subclasses of grouping to use this clone method
    Grouping o = (Grouping) newInstanceWithType(getType());
    o.setParentContainer(getParentContainer());
    o.removeAllAttributes();
    for (MathObjectAttribute mAtt : getAttributes()) {
        o.addAttribute(mAtt.clone());
    }
    o.removeAllLists();
    for (ListAttribute list : getLists()) {
        o.addList(list.clone());
    }
    for (MathObject mObj : getObjects()) {
        mObj.setParentContainer(null);
        o.addObjectFromPage(mObj.getObjectWithAnswer());
        mObj.setParentContainer(this);
    }
    return o;
}
Also used : MathObjectAttribute(doc.attributes.MathObjectAttribute) ListAttribute(doc.attributes.ListAttribute)

Aggregations

MathObjectAttribute (doc.attributes.MathObjectAttribute)11 ListAttribute (doc.attributes.ListAttribute)6 Insets (java.awt.Insets)4 AttributeException (doc.attributes.AttributeException)3 GridBagConstraints (java.awt.GridBagConstraints)3 JPanel (javax.swing.JPanel)3 StringAttribute (doc.attributes.StringAttribute)2 GridBagLayout (java.awt.GridBagLayout)2 JButton (javax.swing.JButton)2 JLabel (javax.swing.JLabel)2 BooleanAttribute (doc.attributes.BooleanAttribute)1 DoubleAttribute (doc.attributes.DoubleAttribute)1 GridPointAttribute (doc.attributes.GridPointAttribute)1 IntegerAttribute (doc.attributes.IntegerAttribute)1 ExpressionObject (doc.mathobjects.ExpressionObject)1 GraphObject (doc.mathobjects.GraphObject)1 MathObject (doc.mathobjects.MathObject)1 ProblemGenerator (doc.mathobjects.ProblemGenerator)1 Color (java.awt.Color)1 Dimension (java.awt.Dimension)1