use of org.activiti.engine.repository.DiagramNode in project Activiti by Activiti.
the class ProcessDiagramLayoutFactory method getElementBoundsFromBpmnDi.
protected Map<String, DiagramNode> getElementBoundsFromBpmnDi(Document bpmnModel) {
Map<String, DiagramNode> listOfBounds = new HashMap<String, DiagramNode>();
// iterate over all DI shapes
NodeList shapes = bpmnModel.getElementsByTagNameNS(BpmnParser.BPMN_DI_NS, "BPMNShape");
for (int i = 0; i < shapes.getLength(); i++) {
Element shape = (Element) shapes.item(i);
String bpmnElementId = shape.getAttribute("bpmnElement");
// get bounds of shape
NodeList childNodes = shape.getChildNodes();
for (int j = 0; j < childNodes.getLength(); j++) {
Node childNode = childNodes.item(j);
if (childNode instanceof Element && BpmnParser.BPMN_DC_NS.equals(childNode.getNamespaceURI()) && "Bounds".equals(childNode.getLocalName())) {
DiagramNode bounds = parseBounds((Element) childNode);
bounds.setId(bpmnElementId);
listOfBounds.put(bpmnElementId, bounds);
break;
}
}
}
return listOfBounds;
}
use of org.activiti.engine.repository.DiagramNode in project Activiti by Activiti.
the class ProcessDiagramLayoutFactory method getDiagramBoundsFromImage.
protected DiagramNode getDiagramBoundsFromImage(BufferedImage image, int offsetTop, int offsetBottom) {
int width = image.getWidth();
int height = image.getHeight();
Map<Integer, Boolean> rowIsWhite = new TreeMap<Integer, Boolean>();
Map<Integer, Boolean> columnIsWhite = new TreeMap<Integer, Boolean>();
for (int row = 0; row < height; row++) {
if (!rowIsWhite.containsKey(row)) {
rowIsWhite.put(row, true);
}
if (row <= offsetTop || row > image.getHeight() - offsetBottom) {
rowIsWhite.put(row, true);
} else {
for (int column = 0; column < width; column++) {
if (!columnIsWhite.containsKey(column)) {
columnIsWhite.put(column, true);
}
int pixel = image.getRGB(column, row);
int alpha = (pixel >> 24) & 0xff;
int red = (pixel >> 16) & 0xff;
int green = (pixel >> 8) & 0xff;
int blue = (pixel >> 0) & 0xff;
if (!(alpha == 0 || (red >= GREY_THRESHOLD && green >= GREY_THRESHOLD && blue >= GREY_THRESHOLD))) {
rowIsWhite.put(row, false);
columnIsWhite.put(column, false);
}
}
}
}
int marginTop = 0;
for (int row = 0; row < height; row++) {
if (rowIsWhite.get(row)) {
++marginTop;
} else {
// Margin Top Found
break;
}
}
int marginLeft = 0;
for (int column = 0; column < width; column++) {
if (columnIsWhite.get(column)) {
++marginLeft;
} else {
// Margin Left Found
break;
}
}
int marginRight = 0;
for (int column = width - 1; column >= 0; column--) {
if (columnIsWhite.get(column)) {
++marginRight;
} else {
// Margin Right Found
break;
}
}
int marginBottom = 0;
for (int row = height - 1; row >= 0; row--) {
if (rowIsWhite.get(row)) {
++marginBottom;
} else {
// Margin Bottom Found
break;
}
}
DiagramNode diagramBoundsImage = new DiagramNode();
diagramBoundsImage.setX((double) marginLeft);
diagramBoundsImage.setY((double) marginTop);
diagramBoundsImage.setWidth((double) (width - marginRight - marginLeft));
diagramBoundsImage.setHeight((double) (height - marginBottom - marginTop));
return diagramBoundsImage;
}
use of org.activiti.engine.repository.DiagramNode in project Activiti by Activiti.
the class ProcessDiagramLayoutFactory method fixFlowNodePositionsIfModelFromAdonis.
protected Map<String, DiagramNode> fixFlowNodePositionsIfModelFromAdonis(Document bpmnModel, Map<String, DiagramNode> elementBoundsFromBpmnDi) {
if (isExportedFromAdonis50(bpmnModel)) {
Map<String, DiagramNode> mapOfFixedBounds = new HashMap<String, DiagramNode>();
XPathFactory xPathFactory = XPathFactory.newInstance();
XPath xPath = xPathFactory.newXPath();
xPath.setNamespaceContext(new Bpmn20NamespaceContext());
for (Entry<String, DiagramNode> entry : elementBoundsFromBpmnDi.entrySet()) {
String elementId = entry.getKey();
DiagramNode elementBounds = entry.getValue();
String expression = "local-name(//bpmn:*[@id = '" + elementId + "'])";
try {
XPathExpression xPathExpression = xPath.compile(expression);
String elementLocalName = xPathExpression.evaluate(bpmnModel);
if (!"participant".equals(elementLocalName) && !"lane".equals(elementLocalName) && !"textAnnotation".equals(elementLocalName) && !"group".equals(elementLocalName)) {
elementBounds.setX(elementBounds.getX() - elementBounds.getWidth() / 2);
elementBounds.setY(elementBounds.getY() - elementBounds.getHeight() / 2);
}
} catch (XPathExpressionException e) {
throw new ActivitiException("Error while evaluating the following XPath expression on a BPMN XML document: '" + expression + "'.", e);
}
mapOfFixedBounds.put(elementId, elementBounds);
}
return mapOfFixedBounds;
} else {
return elementBoundsFromBpmnDi;
}
}
Aggregations