Search in sources :

Example 6 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 7 with BooleanAttribute

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

the class CubeObject method addDefaultAttributes.

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

Example 8 with BooleanAttribute

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

the class CylinderObject method addDefaultAttributes.

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

Example 9 with BooleanAttribute

use of doc.attributes.BooleanAttribute 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 10 with BooleanAttribute

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

the class TextObjectGUI method drawMathObject.

// Not used, an older alternative implementation of how to render text
public void drawMathObject(TextObject object, Graphics g, Point pageOrigin, float zoomLevel, boolean unused) {
    Font f = g.getFont();
    g.setColor(Color.BLACK);
    ScaledSizeAndPosition sap = getSizeAndPositionWithFontSize(object, pageOrigin, zoomLevel, object.getFontSize());
    Graphics2D g2d = (Graphics2D) g;
    g2d.setFont(g.getFont().deriveFont(sap.getFontSize()));
    //draw lines of text with loop
    int textyPos = sap.getyOrigin() + g.getFontMetrics().getHeight() + (int) (3 * zoomLevel);
    int textxPos = sap.getxOrigin() + (int) (3 * zoomLevel);
    String s = object.getText();
    g.drawString(s, textxPos, textyPos);
    textyPos += g.getFontMetrics().getHeight();
    if (((BooleanAttribute) object.getAttributeWithName("showBox")).getValue()) {
        g.setColor(Color.BLUE);
        g.drawRect(sap.getxOrigin(), sap.getyOrigin(), sap.getWidth(), sap.getHeight());
    }
    g.setFont(f);
}
Also used : BooleanAttribute(doc.attributes.BooleanAttribute) AttributedString(java.text.AttributedString) Font(java.awt.Font) Point(java.awt.Point) Graphics2D(java.awt.Graphics2D)

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