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());
}
}
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);
}
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);
}
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);
}
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));
}
Aggregations