Search in sources :

Example 1 with BooleanAttribute

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

the class TextObjectGUI method drawMathObject.

public void drawMathObject(TextObject object, Graphics g, Point pageOrigin, float zoomLevel) {
    ScaledSizeAndPosition sap = getSizeAndPositionWithFontSize(object, pageOrigin, zoomLevel, object.getFontSize());
    if (!object.getText().equals("")) {
        Font f = g.getFont();
        String message = object.getText();
        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;
        try {
            TextLayout textLayout;
            while (messageLBM.getPosition() < messageIterator.getEndIndex()) {
                textLayout = messageLBM.nextLayout(wrappingWidth);
                y += textLayout.getAscent();
                if (object.getAlignment().equals(TextObject.LEFT)) {
                    textLayout.draw(graphics2D, x, y);
                } else if (object.getAlignment().equals(TextObject.RIGHT)) {
                    textLayout.draw(graphics2D, x + (float) (wrappingWidth - textLayout.getBounds().getWidth()), y);
                } else {
                    // centered
                    textLayout.draw(graphics2D, x + (float) (wrappingWidth - textLayout.getBounds().getWidth()) / 2, y);
                }
                y += textLayout.getDescent() + textLayout.getLeading();
                x = sap.getxOrigin() + insets.left;
            }
        } catch (Exception e) {
        // TODO - logging and error reporting to user
        // System.out.println("error with text rendering");
        }
        object.setHeight((int) ((y - sap.getyOrigin()) / zoomLevel));
        g.setFont(f);
    } else {
        // draw the black box around the text box if nothing is in it
        g.setColor(Color.BLACK);
        g.drawRect(sap.getxOrigin(), sap.getyOrigin(), (int) (object.getWidth() * zoomLevel), (int) (object.getHeight() * zoomLevel));
    }
    if (((BooleanAttribute) object.getAttributeWithName(TextObject.SHOW_BOX)).getValue()) {
        g.setColor(Color.BLACK);
        g.drawRect(sap.getxOrigin(), sap.getyOrigin(), sap.getWidth(), sap.getHeight());
    }
}
Also used : BooleanAttribute(doc.attributes.BooleanAttribute) Insets(java.awt.Insets) 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) AttributedString(java.text.AttributedString) FontRenderContext(java.awt.font.FontRenderContext)

Example 2 with BooleanAttribute

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

the class PolygonObject method addPolygonAttributes.

private void addPolygonAttributes() {
    addAttribute(new IntegerAttribute(LINE_THICKNESS, 1, 1, 20));
    addAttribute(new ColorAttribute(FILL_COLOR));
    addAttribute(new BooleanAttribute(HORIZONTALLY_FLIPPED, false, false));
    getAttributeWithName(HORIZONTALLY_FLIPPED).setValue(false);
    addAttribute(new BooleanAttribute(VERTICALLY_FLIPPED, false, false));
    getAttributeWithName(VERTICALLY_FLIPPED).setValue(false);
}
Also used : BooleanAttribute(doc.attributes.BooleanAttribute) ColorAttribute(doc.attributes.ColorAttribute) IntegerAttribute(doc.attributes.IntegerAttribute)

Example 3 with BooleanAttribute

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

Example 4 with BooleanAttribute

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

Example 5 with BooleanAttribute

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

the class ConeObject method addDefaultAttributes.

@Override
public void addDefaultAttributes() {
    addAttribute(new IntegerAttribute(LINE_THICKNESS, 1, 1, 20));
    addAttribute(new ColorAttribute(FILL_COLOR, null));
    addAttribute(new BooleanAttribute(VERTICALLY_FLIPPED, false, false));
}
Also used : BooleanAttribute(doc.attributes.BooleanAttribute) ColorAttribute(doc.attributes.ColorAttribute) IntegerAttribute(doc.attributes.IntegerAttribute)

Aggregations

BooleanAttribute (doc.attributes.BooleanAttribute)11 IntegerAttribute (doc.attributes.IntegerAttribute)9 ColorAttribute (doc.attributes.ColorAttribute)7 StringAttribute (doc.attributes.StringAttribute)4 AttributeException (doc.attributes.AttributeException)2 DoubleAttribute (doc.attributes.DoubleAttribute)2 GridPointAttribute (doc.attributes.GridPointAttribute)2 Font (java.awt.Font)2 Graphics2D (java.awt.Graphics2D)2 AttributedString (java.text.AttributedString)2 EnumeratedAttribute (doc.attributes.EnumeratedAttribute)1 MathObjectAttribute (doc.attributes.MathObjectAttribute)1 SelectionAttribute (doc.attributes.SelectionAttribute)1 Selection (doc_gui.graph.Selection)1 Insets (java.awt.Insets)1 Point (java.awt.Point)1 FontRenderContext (java.awt.font.FontRenderContext)1 LineBreakMeasurer (java.awt.font.LineBreakMeasurer)1 TextLayout (java.awt.font.TextLayout)1 AttributedCharacterIterator (java.text.AttributedCharacterIterator)1