use of org.eclipse.elk.alg.graphviz.dot.dot.util.DotSwitch in project elk by eclipse.
the class DotImporter method transform.
/*---------- Transformation Dot to KGraph ----------*/
/**
* Transform a Dot graph to a KNode.
*
* @param statements
* a list of Dot statements
* @param parent
* a KNode
* @param transData
* transformation data instance
* @param nodeProps
* properties that are applied to all nodes
* @param edgeProps
* properties that are applied to all edges
*/
private void transform(final List<Statement> statements, final ElkNode parent, final IDotTransformationData<GraphvizModel, ElkNode> transData, final IPropertyHolder nodeProps, final IPropertyHolder edgeProps) {
DotSwitch<Object> statementSwitch = new DotSwitch<Object>() {
public Object caseNodeStatement(final NodeStatement statement) {
transformNode(statement, parent, transData, nodeProps);
return null;
}
public Object caseEdgeStatement(final EdgeStatement statement) {
transformEdge(statement, parent, transData, edgeProps);
return null;
}
public Object caseSubgraph(final Subgraph subgraph) {
ElkNode subElkNode = parent;
if (subgraph.getName() != null && subgraph.getName().startsWith("cluster")) {
subElkNode = transformNode(subgraph.getName(), parent, transData);
if (subElkNode.getProperty(PROP_STATEMENT) != null) {
transData.log("Discarding cluster subgraph \"" + subgraph.getName() + "\" since its id is already used.");
return null;
} else {
// the subgraph inherits all settings of its parent
subElkNode.copyProperties(parent);
subElkNode.setProperty(PROP_STATEMENT, subgraph);
}
}
MapPropertyHolder subNodeProps = new MapPropertyHolder();
subNodeProps.copyProperties(nodeProps);
MapPropertyHolder subEdgeProps = new MapPropertyHolder();
subEdgeProps.copyProperties(edgeProps);
transform(subgraph.getStatements(), subElkNode, transData, subNodeProps, subEdgeProps);
return null;
}
public Object caseAttributeStatement(final AttributeStatement statement) {
switch(statement.getType()) {
case GRAPH:
for (Attribute attr : statement.getAttributes()) {
caseAttribute(attr);
}
break;
case NODE:
for (Attribute attr : statement.getAttributes()) {
transformAttribute(nodeProps, attr, transData);
}
break;
case EDGE:
for (Attribute attr : statement.getAttributes()) {
transformAttribute(edgeProps, attr, transData);
}
break;
}
return null;
}
public Object caseAttribute(final Attribute attribute) {
if (Attributes.MARGIN.equals(attribute.getName())) {
ElkPadding padding = parent.getProperty(CoreOptions.PADDING);
if (attribute.getValue().indexOf(',') >= 0) {
KVector value = new KVector();
try {
value.parse(attribute.getValue());
padding.setLeft((float) value.x);
padding.setRight((float) value.x);
padding.setTop((float) value.y);
padding.setBottom((float) value.y);
} catch (IllegalArgumentException exception) {
transData.log("Discarding attribute \"" + attribute.getName() + "\" since its value could not be parsed correctly.");
}
} else {
try {
float value = Float.parseFloat(trimValue(attribute));
padding.setLeft(value);
padding.setRight(value);
padding.setTop(value);
padding.setBottom(value);
} catch (NumberFormatException exception) {
transData.log("Discarding attribute \"" + attribute.getName() + "\" since its value could not be parsed correctly.");
}
}
} else {
transformAttribute(parent, attribute, transData);
}
return null;
}
};
for (Statement statement : statements) {
statementSwitch.doSwitch(statement);
}
}
Aggregations