Search in sources :

Example 1 with DoubleAttribute

use of doc.attributes.DoubleAttribute 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));
}
Also used : StringAttribute(doc.attributes.StringAttribute) IntegerAttribute(doc.attributes.IntegerAttribute) DateAttribute(doc.attributes.DateAttribute) DoubleAttribute(doc.attributes.DoubleAttribute)

Example 2 with DoubleAttribute

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

the class GraphObject method setDefaults.

public void setDefaults() {
    try {
        addList(new ListAttribute<>(EXPRESSIONS, new StringAttribute(EXPRESSION), 6, true, false));
        addList(new ListAttribute<>(POINTS, new GridPointAttribute("", -7E8, 7E8, -7E8, 7E8), 1000000, true, false));
        addList(new ListAttribute<>(LINE_GRAPH, new GridPointAttribute("", -7E8, 7E8, -7E8, 7E8), 1000000, true, false));
        addList(new ListAttribute<>(BAR_GRAPH_VALUES, new DoubleAttribute("", -7E8, 7E8), 50, false, true));
        addAttribute(new IntegerAttribute(BAR_GRAPH_GROUP_SIZE, 1, 1, 100, false));
        addList(new ListAttribute<>(BAR_GRAPH_LABELS, new StringAttribute(""), 100, false, true));
        addAttribute(new SelectionAttribute(SELECTION, new Selection(), false));
        addAttribute(new DoubleAttribute(X_MIN, -7E8, 7E8, true, true));
        getAttributeWithName(X_MIN).setValueWithString("-5");
        addAttribute(new DoubleAttribute(X_MAX, -7E8, 7E8, true, true));
        getAttributeWithName(X_MAX).setValueWithString("5");
        addAttribute(new DoubleAttribute(Y_MIN, -7E8, 7E8, true, true));
        getAttributeWithName(Y_MIN).setValueWithString("-5");
        addAttribute(new DoubleAttribute(Y_MAX, -7E8, 7E8, true, true));
        getAttributeWithName(Y_MAX).setValueWithString("5");
        addAttribute(new DoubleAttribute(X_STEP, -3E8, 3E8, true, true));
        getAttributeWithName(X_STEP).setValueWithString("1");
        addAttribute(new DoubleAttribute(Y_STEP, -3E8, 3E8, true, true));
        getAttributeWithName(Y_STEP).setValueWithString("1");
        addAttribute(new IntegerAttribute(FONT_SIZE, 1, 20));
        getAttributeWithName(FONT_SIZE).setValueWithString("8");
        addAttribute(new BooleanAttribute(SHOW_AXIS));
        getAttributeWithName(SHOW_AXIS).setValue(true);
        addAttribute(new BooleanAttribute(SHOW_NUMBERS));
        getAttributeWithName(SHOW_NUMBERS).setValue(true);
        addAttribute(new BooleanAttribute(SHOW_GRID));
        getAttributeWithName(SHOW_GRID).setValue(true);
        addAttribute(new ColorAttribute(LINE_GRAPH_COLOR));
        getAttributeWithName(LINE_GRAPH_COLOR).setValue(Color.BLUE);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : BooleanAttribute(doc.attributes.BooleanAttribute) Selection(doc_gui.graph.Selection) GridPointAttribute(doc.attributes.GridPointAttribute) StringAttribute(doc.attributes.StringAttribute) ColorAttribute(doc.attributes.ColorAttribute) IntegerAttribute(doc.attributes.IntegerAttribute) SelectionAttribute(doc.attributes.SelectionAttribute) AttributeException(doc.attributes.AttributeException) DoubleAttribute(doc.attributes.DoubleAttribute)

Example 3 with DoubleAttribute

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

the class NumberLineObject method addDefaultAttributes.

@Override
public void addDefaultAttributes() {
    addAttribute(new DoubleAttribute(MIN, -10000, 10000));
    addAttribute(new DoubleAttribute(MAX, -10000, 10000));
    addAttribute(new DoubleAttribute(STEP, 0, 5000));
    addAttribute(new IntegerAttribute(FONT_SIZE, 1, 20));
    getAttributeWithName(MIN).setValue(-5.0);
    getAttributeWithName(MAX).setValue(5.0);
    getAttributeWithName(STEP).setValue(1.0);
    getAttributeWithName(FONT_SIZE).setValue(8);
}
Also used : IntegerAttribute(doc.attributes.IntegerAttribute) DoubleAttribute(doc.attributes.DoubleAttribute)

Example 4 with DoubleAttribute

use of doc.attributes.DoubleAttribute 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;
    }
}
Also used : BooleanAttribute(doc.attributes.BooleanAttribute) MathObjectAttribute(doc.attributes.MathObjectAttribute) GridPointAttribute(doc.attributes.GridPointAttribute) StringAttribute(doc.attributes.StringAttribute) IntegerAttribute(doc.attributes.IntegerAttribute) AttributeException(doc.attributes.AttributeException) DoubleAttribute(doc.attributes.DoubleAttribute)

Example 5 with DoubleAttribute

use of doc.attributes.DoubleAttribute 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);
    }
}
Also used : GridPoint(doc.GridPoint) FontMetrics(java.awt.FontMetrics) GridPointAttribute(doc.attributes.GridPointAttribute) StringAttribute(doc.attributes.StringAttribute) NodeException(expression.NodeException) GraphedCartFunction(doc_gui.graph.GraphedCartFunction) Point(java.awt.Point) GridPoint(doc.GridPoint) DoubleAttribute(doc.attributes.DoubleAttribute)

Aggregations

DoubleAttribute (doc.attributes.DoubleAttribute)5 IntegerAttribute (doc.attributes.IntegerAttribute)4 StringAttribute (doc.attributes.StringAttribute)4 GridPointAttribute (doc.attributes.GridPointAttribute)3 AttributeException (doc.attributes.AttributeException)2 BooleanAttribute (doc.attributes.BooleanAttribute)2 GridPoint (doc.GridPoint)1 ColorAttribute (doc.attributes.ColorAttribute)1 DateAttribute (doc.attributes.DateAttribute)1 MathObjectAttribute (doc.attributes.MathObjectAttribute)1 SelectionAttribute (doc.attributes.SelectionAttribute)1 GraphedCartFunction (doc_gui.graph.GraphedCartFunction)1 Selection (doc_gui.graph.Selection)1 NodeException (expression.NodeException)1 FontMetrics (java.awt.FontMetrics)1 Point (java.awt.Point)1