private final Color BACKGROUND_COLOR = new Color(255, 255, 255, 192);
private static final Rectangle2D EMPTY_BOUNDS = new Rectangle2D.Double(0, 0, 0, 0);
- // NOTE: this is a hack
- String id;
-
protected double xOffset;
protected double yOffset;
- public TextGridStyle() {
- this(0.0, 2.1);
+ public TextGridStyle(Resource r) {
+ this(r, 0.0, 2.1);
}
- public TextGridStyle(double xOffset, double yOffset) {
+ public TextGridStyle(Resource r, double xOffset, double yOffset) {
+ super(r);
this.xOffset = xOffset;
this.yOffset = yOffset;
}
String name = graph.getPossibleRelatedValue(config, getPropertyRelation(graph,element), Bindings.STRING);
return name;
}
-
+
public AffineTransform getTransform(INode node, AffineTransform parentTransform, Rectangle2D elementBounds, int location, boolean up) {
return getTransform(parentTransform, elementBounds, location, up);
}
at.scale(0.15, 0.15);
return at;
-
+
}
protected String rowId() {
String value2 = result != null ? result.getText2() : null;
String value3 = result != null ? result.getText3() : null;
-
+
double spacing = result.getSpacing();
final Function1<String, String> modifier = result != null ? result.getModifier() : null;
// This assumes that this TextGridStyle instance will be devoted to
// this row ID until the end of its life.
- String id = result.getRowId();
- //System.out.println(this + " ID: " + id);
- if (!id.equals(this.id)) {
- //System.out.println(this + " SET ID: " + this.id + " -> " + id);
- this.id = id;
- }
+// String id = result.getRowId();
+// System.out.println(this + " ID: " + id);
+// if (!id.equals(this.id)) {
+// System.out.println(this + " SET ID: " + this.id + " -> " + id);
+// this.id = id;
+// }
Integer newRow = observer.getTemporaryProperty(_node, "location");
if (newRow == null)
newRow = 1;
// Remove from existing row to add to another row if necessary.
- Integer row = observer.getProperty(_node, id);
+ Integer row = getCurrentRowNumber(observer, _node);
if (row != null && row != newRow) {
String actualId = node.getRowId(row);
+ String id = observer.getProperty(_node, rowIdKey());
if (id.equals(actualId)) {
node.removeRow(row);
}
}
row = newRow;
- node.setRowId(row, id);
- observer.setProperty(_node, id, row);
+ node.setRowId(row, result.getRowId());
+
+ setCurrentRowNumber(observer, _node, result.getRowId(), row);
+
observer.setTemporaryProperty(_node, "location", row + 1);
node.setText(2, row, value2);
node.setCache(1, row, result);
boolean isConnection = _node instanceof ConnectionNode;
-
+
Rectangle2D elementBounds = isConnection ? EMPTY_BOUNDS : NodeUtil.getLocalElementBounds(_node);
if(elementBounds == null) {
new Exception("Cannot get local element bounds for node " + _node.toString()).printStackTrace();
Vec2d offset = result.getOffset();
Point2D[] cellOffsets = getCellOffsets();
-
+
AffineTransform at1 = new AffineTransform(at);
at1.translate(cellOffsets[0].getX(),cellOffsets[0].getY());
AffineTransform at2 = new AffineTransform(at);
at2.translate(cellOffsets[1].getX()+spacing,cellOffsets[1].getY());
AffineTransform at3 = new AffineTransform(at);
at3.translate(cellOffsets[2].getX()+spacing,cellOffsets[2].getY());
-
+
at1.translate(offset.x, offset.y);
at2.translate(offset.x, offset.y);
at3.translate(offset.x, offset.y);
node.setHorizontalAlignment(2, row, (byte) getAlignment(2).ordinal());
node.setHorizontalAlignment(3, row, (byte) getAlignment(3).ordinal());
}
-
+
Alignment[] verticalAlignments = result.getVerticalAlignments();
if(verticalAlignments != null) {
node.setVerticalAlignment(1, row, (byte) verticalAlignments[0].ordinal());
node.setZIndex(3000);
org.simantics.common.color.Color color = result.getColor();
- java.awt.Color awtColor = color != null ? Colors.awt(color) : Color.DARK_GRAY;
+ Color awtColor = color != null ? Colors.awt(color) : Color.DARK_GRAY;
+ Color bgColor = getBackgroundColor();
+ Font font = getFont();
- setTextNodeData(node, 1, row, value, FONT, awtColor, BACKGROUND_COLOR);
- setTextNodeData(node, 2, row, value2, result.getPending(), FONT, awtColor, BACKGROUND_COLOR);
- setTextNodeData(node, 3, row, value3, FONT, awtColor, BACKGROUND_COLOR);
+ setTextNodeData(node, 1, row, value, font, awtColor, bgColor);
+ setTextNodeData(node, 2, row, value2, result.getPending(), font, awtColor, bgColor);
+ setTextNodeData(node, 3, row, value3, font, awtColor, bgColor);
node.setEditable(1, row, false);
node.setForceEventListening(2, row, true);
node.setInputValidator(2, row, validator);
node.setTranslator(translator);
-
+
node.setRVI(2, row, rvi);
postProcessNode(node, row);
node.setPending(x, y, pending);
}
+ protected Font getFont() {
+ return FONT;
+ }
+
+ protected Color getBackgroundColor() {
+ return BACKGROUND_COLOR;
+ }
+
protected Alignment getAlignment(int column) {
switch(column) {
case 1: return Alignment.TRAILING;
@Override
protected void cleanupStyleForNode(EvaluationContext observer, INode _node) {
- Integer row = observer.getProperty(_node, id);
+ Integer row = getCurrentRowNumber(observer, _node);
//System.out.println(this + " cleanup(" + id + ", " + row + ")");
//System.out.println(element);
if (row == null)
return;
- observer.setProperty(_node, id, null);
+ clearCurrentRowNumber(observer, _node);
TextGridNode node = ProfileVariables.browseChild(_node, "TextGridStyle");
if (node != null)
node.removeRow(row);
}
+ private Integer getCurrentRowNumber(EvaluationContext observer, INode _node) {
+ String rowId = observer.getProperty(_node, rowIdKey());
+ return observer.getProperty(_node, rowId);
+ }
+
+ private void setCurrentRowNumber(EvaluationContext observer, INode _node, String rowId, int row) {
+ // Mapping style identity -> rowId (resourceId)
+ observer.setProperty(_node, rowIdKey(), rowId);
+ // Mapping rowId (resourceId) -> row number
+ observer.setProperty(_node, rowId, row);
+ }
+
+ private void clearCurrentRowNumber(EvaluationContext observer, INode _node) {
+ String rowId = observer.getProperty(_node, rowIdKey());
+ if(rowId != null) {
+ observer.setProperty(_node, rowIdKey(), null);
+ Integer row = observer.getProperty(_node, rowId);
+ if(row != null) {
+ observer.setProperty(_node, rowId, null);
+ }
+ }
+ }
+
protected void postProcessNode(TextGridNode node, int row) {
}
+ private String rowIdKey() {
+ return "style" + getIdentity().toString();
+ }
+
}