*******************************************************************************/
package org.simantics.diagram.adapter;
+import java.awt.Font;
import java.awt.Shape;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
import org.simantics.databoard.Bindings;
import org.simantics.databoard.binding.error.RuntimeBindingConstructionException;
import org.simantics.databoard.util.Bean;
-import org.simantics.datatypes.literal.Font;
import org.simantics.datatypes.literal.RGB;
import org.simantics.db.AsyncReadGraph;
import org.simantics.db.ReadGraph;
e.setHint(FlagClass.KEY_FLAG_TEXT, flagText);
flagTextIsSet = true;
}
+
+ Font flagFont = info.getFont();
+ if(flagFont != null) {
+ e.setHint(FlagClass.KEY_FLAG_FONT, flagFont);
+ }
if (info.getTextArea() != null) {
e.setHint(FlagClass.KEY_FLAG_TEXT_AREA, info.getTextArea());
*******************************************************************************/
package org.simantics.diagram.flag;
+import java.awt.Font;
import java.awt.Shape;
import java.awt.geom.Rectangle2D;
private Rectangle2D textArea;
private Alignment horizontalAlignment = Alignment.LEADING;
private Alignment verticalAlignment = Alignment.CENTER;
+ private Font font;
public static FlagInfoBuilder fill(Type type) {
return new FlagInfoBuilder().type(type);
}
public FlagInfo create() {
- return new FlagInfoImpl(shape, text, type, textArea, horizontalAlignment, verticalAlignment);
+ return new FlagInfoImpl(shape, text, type, textArea, horizontalAlignment, verticalAlignment, font);
}
public Shape shape() {
return text;
}
+ public Font font() {
+ return font;
+ }
+
public Type type() {
return type;
}
this.text = text;
return this;
}
+
+ public FlagInfoBuilder font(Font font) {
+ this.font = font;
+ return this;
+ }
public FlagInfoBuilder type(Type type) {
this.type = type;
*******************************************************************************/
package org.simantics.diagram.flag;
+import java.awt.Font;
import java.awt.Shape;
import java.awt.geom.Rectangle2D;
private final Rectangle2D textArea;
private final Alignment horizontalAlignment;
private final Alignment verticalAlignment;
+ private final Font font;
public FlagInfoImpl(Shape shape, String[] text, Type type, Rectangle2D textArea,
- Alignment horizontalAlignment, Alignment verticalAlignment) {
+ Alignment horizontalAlignment, Alignment verticalAlignment, Font font) {
this.shape = shape;
this.text = text;
this.type = type;
this.textArea = textArea;
this.horizontalAlignment = horizontalAlignment;
this.verticalAlignment = verticalAlignment;
+ this.font = font;
}
@Override
return verticalAlignment;
}
+ @Override
+ public Font getFont() {
+ return font;
+ }
}
package org.simantics.diagram.flag;
import java.awt.Color;
+import java.awt.Font;
import java.awt.Shape;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
Alignment horizAlign = ElementUtils.getHintOrDefault(e, FlagClass.KEY_TEXT_HORIZONTAL_ALIGN, Alignment.LEADING);
Alignment vertAlign = ElementUtils.getHintOrDefault(e, FlagClass.KEY_TEXT_VERTICAL_ALIGN, Alignment.CENTER);
+ Font font = ElementUtils.getHintOrDefault(e, FlagClass.KEY_FLAG_FONT, FlagNode.DEFAULT_FONT);
+
ElementUtils.removePossibleNode(e, KEY_VISUAL_SG_NODE);
e.removeHint(KEY_VISUAL_SG_NODE);
(float) beakAngle,
textArea,
horizAlign.ordinal(),
- vertAlign.ordinal());
+ vertAlign.ordinal(),
+ font);
AffineTransform at = ElementUtils.getTransform(e);
if(at != null) flag.setTransform(at);
*******************************************************************************/
package org.simantics.diagram.flag;
+import java.awt.Font;
import java.awt.Shape;
import java.awt.geom.Rectangle2D;
FlagClass.Type getType();
Alignment getHorizontalAlignment();
Alignment getVerticalAlignment();
+ Font getFont();
}
/**
import java.awt.BasicStroke;
import java.awt.Color;
+import java.awt.Font;
import java.awt.Shape;
import java.awt.geom.AffineTransform;
import java.awt.geom.Path2D;
public static final Key KEY_SHAPE = new KeyOf(Shape.class, "SHAPE");
public static final Key KEY_TEXT_HORIZONTAL_ALIGN = new KeyOf(Alignment.class, "TEXT_HORIZONTAL_ALIGN");
public static final Key KEY_TEXT_VERTICAL_ALIGN = new KeyOf(Alignment.class, "TEXT_VERTICAL_ALIGN");
+ public static final Key KEY_FLAG_FONT = new KeyOf(Font.class, "FLAG_FONT");
public static final Key KEY_SG_NODE = new SceneGraphNodeKey(Node.class, "FLAG_SG_NODE");
Alignment horizAlign = ElementUtils.getHintOrDefault(e, KEY_TEXT_HORIZONTAL_ALIGN, Alignment.LEADING);
Alignment vertAlign = ElementUtils.getHintOrDefault(e, KEY_TEXT_VERTICAL_ALIGN, Alignment.CENTER);
+ Font font = ElementUtils.getHintOrDefault(e, KEY_FLAG_FONT, FlagNode.DEFAULT_FONT);
+
FlagNode flag = ElementUtils.getOrCreateNode(e, parent, KEY_SG_NODE, ElementUtils.generateNodeId(e), FlagNode.class);
flag.init(shape,
flagText,
(float) beakAngle,
textArea,
horizAlign.ordinal(),
- vertAlign.ordinal());
+ vertAlign.ordinal(),
+ font);
AffineTransform at = ElementUtils.getTransform(e);
if(at != null) flag.setTransform(at);
static transient final BasicStroke STROKE = new BasicStroke(0.25f, BasicStroke.CAP_BUTT,
BasicStroke.JOIN_MITER);
- final transient Font FONT = Font.decode("Arial 12");
+ public final static Font DEFAULT_FONT = Font.decode("Arial 12");
protected boolean visible;
protected Rectangle2D textArea;
protected byte hAlign;
protected byte vAlign;
+ protected Font font = DEFAULT_FONT;
private transient final Point2D origin = new Point2D.Double();
private transient final Point2D xa = new Point2D.Double();
return visible;
}
- @SyncField({"visible", "flagShape", "flagText", "stroke", "border", "fill", "textColor", "width", "height", "direction", "beakAngle", "textSize", "hAlign", "vAlign"})
- public void init(Shape flagShape, String[] flagText, Stroke stroke, Color border, Color fill, Color textColor, float width, float height, double direction, float beakAngle, Rectangle2D textArea, int hAlign, int vAlign) {
+ @SyncField({"visible", "flagShape", "flagText", "stroke", "border", "fill", "textColor", "width", "height", "direction", "beakAngle", "textSize", "hAlign", "vAlign", "font"})
+ public void init(Shape flagShape, String[] flagText, Stroke stroke, Color border, Color fill, Color textColor, float width, float height, double direction, float beakAngle, Rectangle2D textArea, int hAlign, int vAlign, Font font) {
this.visible = true;
this.flagShape = flagShape;
this.flagText = flagText;
this.textArea = textArea;
this.hAlign = (byte) hAlign;
this.vAlign = (byte) vAlign;
+ this.font = font;
resetCaches();
}
}
// Paint flag text
- Font f = FONT;
- g.setFont(f);
+ g.setFont(font);
g.setColor(textColor);
AffineTransform orig = g.getTransform();
System.out.println("transform: " + g.getTransform());
}
- FontMetrics fm = g.getFontMetrics(f);
+ FontMetrics fm = g.getFontMetrics(font);
double fontHeight = fm.getHeight();
if (textLayout == null || (float) scale != lastViewScale)
textHeight = 0;
for (int i = 0; i < flagText.length; ++i) {
String txt = flagText[i].isEmpty() ? " " : flagText[i];
- textLayout[i] = new TextLayout(txt, f, frc);
+ textLayout[i] = new TextLayout(txt, font, frc);
rects[i] = textLayout[i].getBounds();
// If the bb height is not overridden with the font height