Search in sources :

Example 6 with MathObjectAttribute

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

the class Grouping method clone.

@Override
public Grouping clone() {
    // 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.clone());
        mObj.setParentContainer(this);
    }
    return o;
}
Also used : MathObjectAttribute(doc.attributes.MathObjectAttribute) ListAttribute(doc.attributes.ListAttribute)

Example 7 with MathObjectAttribute

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

the class MathObject method exportToXML.

public String exportToXML() {
    String output = "";
    output += "<" + getType() + ">\n";
    for (MathObjectAttribute mAtt : attributes) {
        output += mAtt.exportToXML();
    }
    for (ListAttribute lAtt : attrLists) {
        output += lAtt.exportToXML();
    }
    output += "</" + getType() + ">\n";
    return output;
}
Also used : MathObjectAttribute(doc.attributes.MathObjectAttribute) ListAttribute(doc.attributes.ListAttribute)

Example 8 with MathObjectAttribute

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

the class MathObject method clone.

@Override
public MathObject clone() {
    MathObject o = 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());
    }
    return o;
}
Also used : MathObjectAttribute(doc.attributes.MathObjectAttribute) ListAttribute(doc.attributes.ListAttribute)

Example 9 with MathObjectAttribute

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

the class AnswerBoxGUI method drawMathObject.

public void drawMathObject(AnswerBoxObject object, Graphics g, Point pageOrigin, float zoomLevel) {
    ScaledSizeAndPosition sap = getSizeAndPositionWithFontSize(object, pageOrigin, zoomLevel, object.getFontSize());
    // TODO - decide how extra whitespace should be handled, should it always be stored?
    // students may use it to format a multi-line answer
    // although useful whitespace will likely not coming at the very beginning or very end
    // of an answer
    List<? extends MathObjectAttribute> correctAnswers = object.getListWithName(AnswerBoxObject.CORRECT_ANSWERS).getValues();
    if (!object.getStudentAnswer().trim().equals("") || !correctAnswers.isEmpty()) {
        Font f = g.getFont();
        g.setColor(new Color(150, 210, 255));
        g.fillRect(sap.getxOrigin(), sap.getyOrigin(), sap.getWidth(), sap.getHeight());
        String message = object.getStudentAnswer();
        for (MathObjectAttribute mAtt : correctAnswers) {
            message += mAtt.getValue().toString() + ";";
        }
        message = message.substring(0, message.length() - 1);
        if (message.isEmpty()) {
            // cannot have an empty string in AttributedString
            message = " ";
        }
        g.setFont(f.deriveFont(sap.getFontSize()));
        g.setColor(Color.BLACK);
        Graphics2D graphics2D = (Graphics2D) g;
        GraphicsEnvironment.getLocalGraphicsEnvironment();
        AttributedString messageAS = new AttributedString(message);
        messageAS.addAttribute(TextAttribute.FONT, g.getFont());
        AttributedCharacterIterator messageIterator = messageAS.getIterator();
        FontRenderContext messageFRC = graphics2D.getFontRenderContext();
        LineBreakMeasurer messageLBM = new LineBreakMeasurer(messageIterator, messageFRC);
        Insets insets = new Insets(2, 2, 2, 2);
        float wrappingWidth = sap.getWidth() - insets.left - insets.right;
        float x = sap.getxOrigin() + insets.left;
        float y = sap.getyOrigin() + insets.top;
        while (messageLBM.getPosition() < messageIterator.getEndIndex()) {
            TextLayout textLayout = messageLBM.nextLayout(wrappingWidth);
            y += textLayout.getAscent();
            textLayout.draw(graphics2D, x, y);
            y += textLayout.getDescent() + textLayout.getLeading();
            x = sap.getxOrigin() + insets.left;
        }
        g.setFont(f);
    } else {
        g.setColor(new Color(230, 230, 230));
        g.fillRect(sap.getxOrigin(), sap.getyOrigin(), sap.getWidth(), sap.getHeight());
    }
    g.setColor(Color.BLACK);
    g.drawRect(sap.getxOrigin(), sap.getyOrigin(), sap.getWidth(), sap.getHeight());
}
Also used : Insets(java.awt.Insets) Color(java.awt.Color) LineBreakMeasurer(java.awt.font.LineBreakMeasurer) AttributedString(java.text.AttributedString) Font(java.awt.Font) Graphics2D(java.awt.Graphics2D) AttributedCharacterIterator(java.text.AttributedCharacterIterator) TextLayout(java.awt.font.TextLayout) MathObjectAttribute(doc.attributes.MathObjectAttribute) AttributedString(java.text.AttributedString) FontRenderContext(java.awt.font.FontRenderContext)

Example 10 with MathObjectAttribute

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

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