//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.unis.flowable.server.util;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.flowable.bpmn.model.Activity;
import org.flowable.bpmn.model.AdhocSubProcess;
import org.flowable.bpmn.model.Artifact;
import org.flowable.bpmn.model.Association;
import org.flowable.bpmn.model.AssociationDirection;
import org.flowable.bpmn.model.BaseElement;
import org.flowable.bpmn.model.BoundaryEvent;
import org.flowable.bpmn.model.BpmnModel;
import org.flowable.bpmn.model.BusinessRuleTask;
import org.flowable.bpmn.model.CallActivity;
import org.flowable.bpmn.model.CompensateEventDefinition;
import org.flowable.bpmn.model.EndEvent;
import org.flowable.bpmn.model.ErrorEventDefinition;
import org.flowable.bpmn.model.Event;
import org.flowable.bpmn.model.EventDefinition;
import org.flowable.bpmn.model.EventGateway;
import org.flowable.bpmn.model.EventSubProcess;
import org.flowable.bpmn.model.ExclusiveGateway;
import org.flowable.bpmn.model.FlowElement;
import org.flowable.bpmn.model.FlowElementsContainer;
import org.flowable.bpmn.model.FlowNode;
import org.flowable.bpmn.model.Gateway;
import org.flowable.bpmn.model.GraphicInfo;
import org.flowable.bpmn.model.HttpServiceTask;
import org.flowable.bpmn.model.InclusiveGateway;
import org.flowable.bpmn.model.IntermediateCatchEvent;
import org.flowable.bpmn.model.Lane;
import org.flowable.bpmn.model.ManualTask;
import org.flowable.bpmn.model.MessageEventDefinition;
import org.flowable.bpmn.model.MultiInstanceLoopCharacteristics;
import org.flowable.bpmn.model.ParallelGateway;
import org.flowable.bpmn.model.Pool;
import org.flowable.bpmn.model.Process;
import org.flowable.bpmn.model.ReceiveTask;
import org.flowable.bpmn.model.ScriptTask;
import org.flowable.bpmn.model.SendTask;
import org.flowable.bpmn.model.SequenceFlow;
import org.flowable.bpmn.model.ServiceTask;
import org.flowable.bpmn.model.SignalEventDefinition;
import org.flowable.bpmn.model.StartEvent;
import org.flowable.bpmn.model.SubProcess;
import org.flowable.bpmn.model.Task;
import org.flowable.bpmn.model.TextAnnotation;
import org.flowable.bpmn.model.ThrowEvent;
import org.flowable.bpmn.model.TimerEventDefinition;
import org.flowable.bpmn.model.Transaction;
import org.flowable.bpmn.model.UserTask;
import com.unis.flowable.server.util.DefaultProcessDiagramCanvas.SHAPE_TYPE;

public class DefaultProcessDiagramGenerator {
    protected Map<Class<? extends BaseElement>, DefaultProcessDiagramGenerator.ActivityDrawInstruction> activityDrawInstructions;
    protected Map<Class<? extends BaseElement>, DefaultProcessDiagramGenerator.ArtifactDrawInstruction> artifactDrawInstructions;

    public DefaultProcessDiagramGenerator() {
        this(1.0D);
    }

    public DefaultProcessDiagramGenerator(final double scaleFactor) {
        this.activityDrawInstructions = new HashMap();
        this.artifactDrawInstructions = new HashMap();
        this.activityDrawInstructions.put(StartEvent.class, new DefaultProcessDiagramGenerator.ActivityDrawInstruction() {
            @Override
            public void draw(DefaultProcessDiagramCanvas processDiagramCanvas, BpmnModel bpmnModel, FlowNode flowNode,String actColor) {
                System.out.println("tttttt====="+25);
                GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(flowNode.getId());
                StartEvent startEvent = (StartEvent)flowNode;
                if(startEvent.getEventDefinitions() != null && !startEvent.getEventDefinitions().isEmpty()) {
                    EventDefinition eventDefinition = (EventDefinition)startEvent.getEventDefinitions().get(0);
                    if(eventDefinition instanceof TimerEventDefinition) {
                        processDiagramCanvas.drawTimerStartEvent(graphicInfo, scaleFactor);
                    } else if(eventDefinition instanceof ErrorEventDefinition) {
                        processDiagramCanvas.drawErrorStartEvent(graphicInfo, scaleFactor);
                    } else if(eventDefinition instanceof SignalEventDefinition) {
                        processDiagramCanvas.drawSignalStartEvent(graphicInfo, scaleFactor);
                    } else if(eventDefinition instanceof MessageEventDefinition) {
                        processDiagramCanvas.drawMessageStartEvent(graphicInfo, scaleFactor);
                    } else {
                        processDiagramCanvas.drawNoneStartEvent(graphicInfo);
                    }
                } else {
                    processDiagramCanvas.drawNoneStartEvent(graphicInfo);
                }

            }
        });
        this.activityDrawInstructions.put(IntermediateCatchEvent.class, new DefaultProcessDiagramGenerator.ActivityDrawInstruction() {
            @Override
            public void draw(DefaultProcessDiagramCanvas processDiagramCanvas, BpmnModel bpmnModel, FlowNode flowNode,String actColor) {
                System.out.println("tttttt====="+24);
                GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(flowNode.getId());
                IntermediateCatchEvent intermediateCatchEvent = (IntermediateCatchEvent)flowNode;
                if(intermediateCatchEvent.getEventDefinitions() != null && !intermediateCatchEvent.getEventDefinitions().isEmpty()) {
                    if(intermediateCatchEvent.getEventDefinitions().get(0) instanceof SignalEventDefinition) {
                        processDiagramCanvas.drawCatchingSignalEvent(flowNode.getName(), graphicInfo, true, scaleFactor);
                    } else if(intermediateCatchEvent.getEventDefinitions().get(0) instanceof TimerEventDefinition) {
                        processDiagramCanvas.drawCatchingTimerEvent(flowNode.getName(), graphicInfo, true, scaleFactor);
                    } else if(intermediateCatchEvent.getEventDefinitions().get(0) instanceof MessageEventDefinition) {
                        processDiagramCanvas.drawCatchingMessageEvent(flowNode.getName(), graphicInfo, true, scaleFactor);
                    }
                }

            }
        });
        this.activityDrawInstructions.put(ThrowEvent.class, new DefaultProcessDiagramGenerator.ActivityDrawInstruction() {
            @Override
            public void draw(DefaultProcessDiagramCanvas processDiagramCanvas, BpmnModel bpmnModel, FlowNode flowNode,String actColor) {
                System.out.println("tttttt====="+23);
                GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(flowNode.getId());
                ThrowEvent throwEvent = (ThrowEvent)flowNode;
                if(throwEvent.getEventDefinitions() != null && !throwEvent.getEventDefinitions().isEmpty()) {
                    if(throwEvent.getEventDefinitions().get(0) instanceof SignalEventDefinition) {
                        processDiagramCanvas.drawThrowingSignalEvent(graphicInfo, scaleFactor);
                    } else if(throwEvent.getEventDefinitions().get(0) instanceof CompensateEventDefinition) {
                        processDiagramCanvas.drawThrowingCompensateEvent(graphicInfo, scaleFactor);
                    } else {
                        processDiagramCanvas.drawThrowingNoneEvent(graphicInfo, scaleFactor);
                    }
                } else {
                    processDiagramCanvas.drawThrowingNoneEvent(graphicInfo, scaleFactor);
                }

            }
        });
        this.activityDrawInstructions.put(EndEvent.class, new DefaultProcessDiagramGenerator.ActivityDrawInstruction() {
            @Override
            public void draw(DefaultProcessDiagramCanvas processDiagramCanvas, BpmnModel bpmnModel, FlowNode flowNode,String actColor) {
                System.out.println("tttttt====="+22);
                GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(flowNode.getId());
                EndEvent endEvent = (EndEvent)flowNode;
                if(endEvent.getEventDefinitions() != null && !endEvent.getEventDefinitions().isEmpty()) {
                    if(endEvent.getEventDefinitions().get(0) instanceof ErrorEventDefinition) {
                        processDiagramCanvas.drawErrorEndEvent(flowNode.getName(), graphicInfo, scaleFactor);
                    } else {
                        processDiagramCanvas.drawNoneEndEvent(graphicInfo, scaleFactor);
                    }
                } else {
                    processDiagramCanvas.drawNoneEndEvent(graphicInfo, scaleFactor);
                }

            }
        });
        this.activityDrawInstructions.put(Task.class, new DefaultProcessDiagramGenerator.ActivityDrawInstruction() {
            @Override
            public void draw(DefaultProcessDiagramCanvas processDiagramCanvas, BpmnModel bpmnModel, FlowNode flowNode,String actColor) {
                System.out.println("tttttt====="+21);
                GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(flowNode.getId());
                processDiagramCanvas.drawTask(flowNode.getName(), graphicInfo, scaleFactor,actColor);
            }
        });

        //各个节点运行的程序
        this.activityDrawInstructions.put(UserTask.class, new DefaultProcessDiagramGenerator.ActivityDrawInstruction() {
            @Override
            public void draw(DefaultProcessDiagramCanvas processDiagramCanvas, BpmnModel bpmnModel, FlowNode flowNode,String actColor) {
                System.out.println("tttttt====="+20);
                System.out.println("活动节点颜色："+actColor);
                GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(flowNode.getId());
                processDiagramCanvas.drawUserTask(flowNode.getName(), graphicInfo, scaleFactor,actColor);
            }
        });
        this.activityDrawInstructions.put(ScriptTask.class, new DefaultProcessDiagramGenerator.ActivityDrawInstruction() {
            @Override
            public void draw(DefaultProcessDiagramCanvas processDiagramCanvas, BpmnModel bpmnModel, FlowNode flowNode,String actColor) {
                System.out.println("tttttt====="+19);
                GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(flowNode.getId());
                processDiagramCanvas.drawScriptTask(flowNode.getName(), graphicInfo, scaleFactor,actColor);
            }
        });
        this.activityDrawInstructions.put(ServiceTask.class, new DefaultProcessDiagramGenerator.ActivityDrawInstruction() {
            @Override
            public void draw(DefaultProcessDiagramCanvas processDiagramCanvas, BpmnModel bpmnModel, FlowNode flowNode,String actColor) {
                System.out.println("tttttt====="+18);
                GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(flowNode.getId());
                ServiceTask serviceTask = (ServiceTask)flowNode;
                if("camel".equalsIgnoreCase(serviceTask.getType())) {
                    processDiagramCanvas.drawCamelTask(serviceTask.getName(), graphicInfo, scaleFactor,actColor);
                } else if("mule".equalsIgnoreCase(serviceTask.getType())) {
                    processDiagramCanvas.drawMuleTask(serviceTask.getName(), graphicInfo, scaleFactor,actColor);
                } else if("http".equalsIgnoreCase(serviceTask.getType())) {
                    processDiagramCanvas.drawHttpTask(serviceTask.getName(), graphicInfo, scaleFactor,actColor);
                } else if("dmn".equalsIgnoreCase(serviceTask.getType())) {
                    processDiagramCanvas.drawDMNTask(serviceTask.getName(), graphicInfo, scaleFactor,actColor);
                } else if("shell".equalsIgnoreCase(serviceTask.getType())) {
                    processDiagramCanvas.drawShellTask(serviceTask.getName(), graphicInfo, scaleFactor,actColor);
                } else {
                    processDiagramCanvas.drawServiceTask(serviceTask.getName(), graphicInfo, scaleFactor,actColor);
                }

            }
        });
        this.activityDrawInstructions.put(HttpServiceTask.class, new DefaultProcessDiagramGenerator.ActivityDrawInstruction() {
            @Override
            public void draw(DefaultProcessDiagramCanvas processDiagramCanvas, BpmnModel bpmnModel, FlowNode flowNode,String actColor) {
                System.out.println("tttttt====="+17);
                GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(flowNode.getId());
                processDiagramCanvas.drawHttpTask(flowNode.getName(), graphicInfo, scaleFactor,actColor);
            }
        });
        this.activityDrawInstructions.put(ReceiveTask.class, new DefaultProcessDiagramGenerator.ActivityDrawInstruction() {
            @Override
            public void draw(DefaultProcessDiagramCanvas processDiagramCanvas, BpmnModel bpmnModel, FlowNode flowNode,String actColor) {
                System.out.println("tttttt====="+16);
                GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(flowNode.getId());
                processDiagramCanvas.drawReceiveTask(flowNode.getName(), graphicInfo, scaleFactor,actColor);
            }
        });
        this.activityDrawInstructions.put(SendTask.class, new DefaultProcessDiagramGenerator.ActivityDrawInstruction() {
            @Override
            public void draw(DefaultProcessDiagramCanvas processDiagramCanvas, BpmnModel bpmnModel, FlowNode flowNode,String actColor) {
                System.out.println("tttttt====="+15);
                GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(flowNode.getId());
                processDiagramCanvas.drawSendTask(flowNode.getName(), graphicInfo, scaleFactor,actColor);
            }
        });
        this.activityDrawInstructions.put(ManualTask.class, new DefaultProcessDiagramGenerator.ActivityDrawInstruction() {
            @Override
            public void draw(DefaultProcessDiagramCanvas processDiagramCanvas, BpmnModel bpmnModel, FlowNode flowNode,String actColor) {
                System.out.println("tttttt====="+14);
                GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(flowNode.getId());
                processDiagramCanvas.drawManualTask(flowNode.getName(), graphicInfo, scaleFactor,actColor);
            }
        });
        this.activityDrawInstructions.put(BusinessRuleTask.class, new DefaultProcessDiagramGenerator.ActivityDrawInstruction() {
            @Override
            public void draw(DefaultProcessDiagramCanvas processDiagramCanvas, BpmnModel bpmnModel, FlowNode flowNode,String actColor) {
                System.out.println("tttttt====="+13);
                GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(flowNode.getId());
                processDiagramCanvas.drawBusinessRuleTask(flowNode.getName(), graphicInfo, scaleFactor,actColor);
            }
        });
        this.activityDrawInstructions.put(ExclusiveGateway.class, new DefaultProcessDiagramGenerator.ActivityDrawInstruction() {
            @Override
            public void draw(DefaultProcessDiagramCanvas processDiagramCanvas, BpmnModel bpmnModel, FlowNode flowNode,String actColor) {
                System.out.println("tttttt====="+12);
                GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(flowNode.getId());
                processDiagramCanvas.drawExclusiveGateway(graphicInfo, scaleFactor);
            }
        });
        this.activityDrawInstructions.put(InclusiveGateway.class, new DefaultProcessDiagramGenerator.ActivityDrawInstruction() {
            public void draw(DefaultProcessDiagramCanvas processDiagramCanvas, BpmnModel bpmnModel, FlowNode flowNode,String actColor) {
                System.out.println("tttttt====="+11);
                GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(flowNode.getId());
                processDiagramCanvas.drawInclusiveGateway(graphicInfo, scaleFactor);
            }
        });
        this.activityDrawInstructions.put(ParallelGateway.class, new DefaultProcessDiagramGenerator.ActivityDrawInstruction() {
            @Override
            public void draw(DefaultProcessDiagramCanvas processDiagramCanvas, BpmnModel bpmnModel, FlowNode flowNode,String actColor) {
                System.out.println("tttttt====="+10);
                GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(flowNode.getId());
                processDiagramCanvas.drawParallelGateway(graphicInfo, scaleFactor);
            }
        });
        this.activityDrawInstructions.put(EventGateway.class, new DefaultProcessDiagramGenerator.ActivityDrawInstruction() {
            @Override
            public void draw(DefaultProcessDiagramCanvas processDiagramCanvas, BpmnModel bpmnModel, FlowNode flowNode,String actColor) {
                System.out.println("tttttt====="+9);
                GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(flowNode.getId());
                processDiagramCanvas.drawEventBasedGateway(graphicInfo, scaleFactor);
            }
        });
        this.activityDrawInstructions.put(BoundaryEvent.class, new DefaultProcessDiagramGenerator.ActivityDrawInstruction() {
            @Override
            public void draw(DefaultProcessDiagramCanvas processDiagramCanvas, BpmnModel bpmnModel, FlowNode flowNode,String actColor) {
                System.out.println("tttttt====="+8);
                GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(flowNode.getId());
                BoundaryEvent boundaryEvent = (BoundaryEvent)flowNode;
                if(boundaryEvent.getEventDefinitions() != null && !boundaryEvent.getEventDefinitions().isEmpty()) {
                    if(boundaryEvent.getEventDefinitions().get(0) instanceof TimerEventDefinition) {
                        processDiagramCanvas.drawCatchingTimerEvent(flowNode.getName(), graphicInfo, boundaryEvent.isCancelActivity(), scaleFactor);
                    } else if(boundaryEvent.getEventDefinitions().get(0) instanceof ErrorEventDefinition) {
                        processDiagramCanvas.drawCatchingErrorEvent(graphicInfo, boundaryEvent.isCancelActivity(), scaleFactor);
                    } else if(boundaryEvent.getEventDefinitions().get(0) instanceof SignalEventDefinition) {
                        processDiagramCanvas.drawCatchingSignalEvent(flowNode.getName(), graphicInfo, boundaryEvent.isCancelActivity(), scaleFactor);
                    } else if(boundaryEvent.getEventDefinitions().get(0) instanceof MessageEventDefinition) {
                        processDiagramCanvas.drawCatchingMessageEvent(flowNode.getName(), graphicInfo, boundaryEvent.isCancelActivity(), scaleFactor);
                    } else if(boundaryEvent.getEventDefinitions().get(0) instanceof CompensateEventDefinition) {
                        processDiagramCanvas.drawCatchingCompensateEvent(graphicInfo, boundaryEvent.isCancelActivity(), scaleFactor);
                    }
                }

            }
        });
        this.activityDrawInstructions.put(SubProcess.class, new DefaultProcessDiagramGenerator.ActivityDrawInstruction() {
            @Override
            public void draw(DefaultProcessDiagramCanvas processDiagramCanvas, BpmnModel bpmnModel, FlowNode flowNode,String actColor) {
                System.out.println("tttttt====="+7);
                GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(flowNode.getId());
                if(graphicInfo.getExpanded() != null && !graphicInfo.getExpanded().booleanValue()) {
                    processDiagramCanvas.drawCollapsedSubProcess(flowNode.getName(), graphicInfo, Boolean.valueOf(false), scaleFactor,actColor);
                } else {
                    processDiagramCanvas.drawExpandedSubProcess(flowNode.getName(), graphicInfo, false, scaleFactor);
                }

            }
        });
        this.activityDrawInstructions.put(Transaction.class, new DefaultProcessDiagramGenerator.ActivityDrawInstruction() {
            @Override
            public void draw(DefaultProcessDiagramCanvas processDiagramCanvas, BpmnModel bpmnModel, FlowNode flowNode,String actColor) {
                System.out.println("tttttt====="+6);
                GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(flowNode.getId());
                if(graphicInfo.getExpanded() != null && !graphicInfo.getExpanded().booleanValue()) {
                    processDiagramCanvas.drawCollapsedSubProcess(flowNode.getName(), graphicInfo, Boolean.valueOf(false), scaleFactor,actColor);
                } else {
                    processDiagramCanvas.drawExpandedTransaction(flowNode.getName(), graphicInfo, scaleFactor);
                }

            }
        });
        this.activityDrawInstructions.put(EventSubProcess.class, new DefaultProcessDiagramGenerator.ActivityDrawInstruction() {
            @Override
            public void draw(DefaultProcessDiagramCanvas processDiagramCanvas, BpmnModel bpmnModel, FlowNode flowNode,String actColor) {
                System.out.println("tttttt====="+5);
                GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(flowNode.getId());
                if(graphicInfo.getExpanded() != null && !graphicInfo.getExpanded().booleanValue()) {
                    processDiagramCanvas.drawCollapsedSubProcess(flowNode.getName(), graphicInfo, Boolean.valueOf(true), scaleFactor,actColor);
                } else {
                    processDiagramCanvas.drawExpandedSubProcess(flowNode.getName(), graphicInfo, true, scaleFactor);
                }

            }
        });
        this.activityDrawInstructions.put(AdhocSubProcess.class, new DefaultProcessDiagramGenerator.ActivityDrawInstruction() {
            @Override
            public void draw(DefaultProcessDiagramCanvas processDiagramCanvas, BpmnModel bpmnModel, FlowNode flowNode,String actColor) {
                System.out.println("tttttt====="+4);
                GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(flowNode.getId());
                if(graphicInfo.getExpanded() != null && !graphicInfo.getExpanded().booleanValue()) {
                    processDiagramCanvas.drawCollapsedSubProcess(flowNode.getName(), graphicInfo, Boolean.valueOf(false), scaleFactor,actColor);
                } else {
                    processDiagramCanvas.drawExpandedSubProcess(flowNode.getName(), graphicInfo, false, scaleFactor);
                }

            }
        });
        this.activityDrawInstructions.put(CallActivity.class, new DefaultProcessDiagramGenerator.ActivityDrawInstruction() {
            @Override
            public void draw(DefaultProcessDiagramCanvas processDiagramCanvas, BpmnModel bpmnModel, FlowNode flowNode,String actColor) {
                System.out.println("tttttt====="+3);
                GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(flowNode.getId());
                processDiagramCanvas.drawCollapsedCallActivity(flowNode.getName(), graphicInfo, scaleFactor,actColor);
            }
        });
        this.artifactDrawInstructions.put(TextAnnotation.class, new DefaultProcessDiagramGenerator.ArtifactDrawInstruction() {
            @Override
            public void draw(DefaultProcessDiagramCanvas processDiagramCanvas, BpmnModel bpmnModel, Artifact artifact) {
                System.out.println("tttttt====="+2);
                GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(artifact.getId());
                TextAnnotation textAnnotation = (TextAnnotation)artifact;
                processDiagramCanvas.drawTextAnnotation(textAnnotation.getText(), graphicInfo, scaleFactor);
            }
        });
        this.artifactDrawInstructions.put(Association.class, new DefaultProcessDiagramGenerator.ArtifactDrawInstruction() {
            @Override
            public void draw(DefaultProcessDiagramCanvas processDiagramCanvas, BpmnModel bpmnModel, Artifact artifact) {
                System.out.println("tttttt====="+1);
                Association association = (Association)artifact;
                String sourceRef = association.getSourceRef();
                String targetRef = association.getTargetRef();
                Object sourceElement = bpmnModel.getFlowElement(sourceRef);
                Object targetElement = bpmnModel.getFlowElement(targetRef);
                if(sourceElement == null) {
                    sourceElement = bpmnModel.getArtifact(sourceRef);
                }

                if(targetElement == null) {
                    targetElement = bpmnModel.getArtifact(targetRef);
                }

                List graphicInfoList = bpmnModel.getFlowLocationGraphicInfo(artifact.getId());
                graphicInfoList = DefaultProcessDiagramGenerator.connectionPerfectionizer(processDiagramCanvas, bpmnModel, (BaseElement)sourceElement, (BaseElement)targetElement, graphicInfoList);
                int[] xPoints = new int[graphicInfoList.size()];
                int[] yPoints = new int[graphicInfoList.size()];

                for(int associationDirection = 1; associationDirection < graphicInfoList.size(); ++associationDirection) {
                    GraphicInfo graphicInfo = (GraphicInfo)graphicInfoList.get(associationDirection);
                    GraphicInfo previousGraphicInfo = (GraphicInfo)graphicInfoList.get(associationDirection - 1);
                    if(associationDirection == 1) {
                        xPoints[0] = (int)previousGraphicInfo.getX();
                        yPoints[0] = (int)previousGraphicInfo.getY();
                    }

                    xPoints[associationDirection] = (int)graphicInfo.getX();
                    yPoints[associationDirection] = (int)graphicInfo.getY();
                }

                AssociationDirection var15 = association.getAssociationDirection();
                processDiagramCanvas.drawAssociation(xPoints, yPoints, var15, false, scaleFactor);
            }
        });
    }

    public InputStream generateDiagram(BpmnModel bpmnModel, String imageType,List<String> highLightedFinishes, List<String> highLightedActivities, List<String> highLightedFlows, String activityFontName, String labelFontName, String annotationFontName, ClassLoader customClassLoader, double scaleFactor, boolean drawSequenceFlowNameWithNoLabelDI) {
        return this.generateProcessDiagram(bpmnModel, imageType,highLightedFinishes,highLightedActivities, highLightedFlows, activityFontName, labelFontName, annotationFontName, customClassLoader, scaleFactor, drawSequenceFlowNameWithNoLabelDI).generateImage(imageType);
    }
    public InputStream generateDiagram(BpmnModel bpmnModel, String imageType,List<String> highLightedFinishes, List<String> highLightedActivities, List<String> highLightedFlows, boolean drawSequenceFlowNameWithNoLabelDI) {
        return this.generateDiagram(bpmnModel, imageType, highLightedFinishes, highLightedActivities, highLightedFlows, (String) null, (String) null, (String) null, (ClassLoader) null, 1.0D, drawSequenceFlowNameWithNoLabelDI);
    }
    public InputStream generateDiagram(BpmnModel bpmnModel, String imageType,List<String> highLightedFinishes, List<String> highLightedActivities, List<String> highLightedFlows, double scaleFactor, boolean drawSequenceFlowNameWithNoLabelDI) {
        return this.generateDiagram(bpmnModel, imageType,highLightedFinishes, highLightedActivities, highLightedFlows, (String)null, (String)null, (String)null, (ClassLoader)null, scaleFactor, drawSequenceFlowNameWithNoLabelDI);
    }
    public InputStream generateDiagram(BpmnModel bpmnModel, String imageType,List<String> highLightedFinishes, List<String> highLightedActivities, boolean drawSequenceFlowNameWithNoLabelDI) {
        return this.generateDiagram(bpmnModel, imageType, highLightedActivities, Collections.emptyList(), drawSequenceFlowNameWithNoLabelDI);
    }
    public InputStream generateDiagram(BpmnModel bpmnModel, String imageType,List<String> highLightedFinishes, List<String> highLightedActivities, double scaleFactor, boolean drawSequenceFlowNameWithNoLabelDI) {
        return this.generateDiagram(bpmnModel, imageType, highLightedActivities, Collections.emptyList(), scaleFactor, drawSequenceFlowNameWithNoLabelDI);
    }

    public InputStream generatePngDiagram(BpmnModel bpmnModel, boolean drawSequenceFlowNameWithNoLabelDI) {
        return this.generatePngDiagram(bpmnModel, 1.0D, drawSequenceFlowNameWithNoLabelDI);
    }
    public InputStream generatePngDiagram(BpmnModel bpmnModel, double scaleFactor, boolean drawSequenceFlowNameWithNoLabelDI) {
        return this.generateDiagram(bpmnModel, "png", Collections.emptyList(), Collections.emptyList(), scaleFactor, drawSequenceFlowNameWithNoLabelDI);
    }
    public InputStream generateJpgDiagram(BpmnModel bpmnModel) {
        return this.generateJpgDiagram(bpmnModel, 1.0D, false);
    }
    public InputStream generateJpgDiagram(BpmnModel bpmnModel, double scaleFactor, boolean drawSequenceFlowNameWithNoLabelDI) {
        return this.generateDiagram(bpmnModel, "jpg", Collections.emptyList(), Collections.emptyList(), drawSequenceFlowNameWithNoLabelDI);
    }

    public BufferedImage generateImage(BpmnModel bpmnModel, String imageType, List<String> highLightedFinishes,List<String> highLightedActivities, List<String> highLightedFlows, String activityFontName, String labelFontName, String annotationFontName, ClassLoader customClassLoader, double scaleFactor, boolean drawSequenceFlowNameWithNoLabelDI) {
        return this.generateProcessDiagram(bpmnModel, imageType, highLightedFinishes,highLightedActivities, highLightedFlows, activityFontName, labelFontName, annotationFontName, customClassLoader, scaleFactor, drawSequenceFlowNameWithNoLabelDI).generateBufferedImage(imageType);
    }

    public BufferedImage generateImage(BpmnModel bpmnModel, String imageType,List<String> highLightedFinishes, List<String> highLightedActivities, List<String> highLightedFlows, double scaleFactor, boolean drawSequenceFlowNameWithNoLabelDI) {
        return this.generateImage(bpmnModel, imageType, highLightedFinishes, highLightedActivities, highLightedFlows, (String) null, (String) null, (String) null, (ClassLoader) null, scaleFactor, drawSequenceFlowNameWithNoLabelDI);
    }



    protected DefaultProcessDiagramCanvas generateProcessDiagram(BpmnModel bpmnModel, String imageType,List<String> highLightedFinishes, List<String> highLightedActivities, List<String> highLightedFlows, String activityFontName, String labelFontName, String annotationFontName, ClassLoader customClassLoader, double scaleFactor, boolean drawSequenceFlowNameWithNoLabelDI) {
        this.prepareBpmnModel(bpmnModel);
        DefaultProcessDiagramCanvas processDiagramCanvas = initProcessDiagramCanvas(bpmnModel, imageType, activityFontName, labelFontName, annotationFontName, customClassLoader);
        Iterator var13 = bpmnModel.getPools().iterator();

        while(var13.hasNext()) {
            Pool process = (Pool)var13.next();
            GraphicInfo subProcesses = bpmnModel.getGraphicInfo(process.getId());
            processDiagramCanvas.drawPoolOrLane(process.getName(), subProcesses, scaleFactor);
        }

        var13 = bpmnModel.getProcesses().iterator();

        Process process1;
        Iterator subProcesses1;
        while(var13.hasNext()) {
            process1 = (Process)var13.next();
            subProcesses1 = process1.getLanes().iterator();

            while(subProcesses1.hasNext()) {
                Lane artifact = (Lane)subProcesses1.next();
                GraphicInfo subProcess = bpmnModel.getGraphicInfo(artifact.getId());
                processDiagramCanvas.drawPoolOrLane(artifact.getName(), subProcess, scaleFactor);
            }
        }

        var13 = bpmnModel.getProcesses().iterator();

        while(var13.hasNext()) {
            process1 = (Process)var13.next();
            subProcesses1 = process1.findFlowElementsOfType(FlowNode.class).iterator();

            while(subProcesses1.hasNext()) {
                FlowNode artifact1 = (FlowNode)subProcesses1.next();
                if(!this.isPartOfCollapsedSubProcess(artifact1, bpmnModel)) {
                    this.drawActivity(processDiagramCanvas, bpmnModel, artifact1,highLightedFinishes, highLightedActivities, highLightedFlows, scaleFactor, Boolean.valueOf(drawSequenceFlowNameWithNoLabelDI));
                }
            }
        }

        var13 = bpmnModel.getProcesses().iterator();

        label75:
        while(true) {
            List subProcesses2;
            do {
                if(!var13.hasNext()) {
                    return processDiagramCanvas;
                }

                process1 = (Process)var13.next();
                subProcesses1 = process1.getArtifacts().iterator();

                while(subProcesses1.hasNext()) {
                    Artifact artifact2 = (Artifact)subProcesses1.next();
                    this.drawArtifact(processDiagramCanvas, bpmnModel, artifact2);
                }

                subProcesses2 = process1.findFlowElementsOfType(SubProcess.class, true);
            } while(subProcesses2 == null);

            Iterator artifact3 = subProcesses2.iterator();

            while(true) {
                GraphicInfo graphicInfo;
                SubProcess subProcess1;
                do {
                    do {
                        if(!artifact3.hasNext()) {
                            continue label75;
                        }

                        subProcess1 = (SubProcess)artifact3.next();
                        graphicInfo = bpmnModel.getGraphicInfo(subProcess1.getId());
                    } while(graphicInfo != null && graphicInfo.getExpanded() != null && !graphicInfo.getExpanded().booleanValue());
                } while(this.isPartOfCollapsedSubProcess(subProcess1, bpmnModel));

                Iterator var19 = subProcess1.getArtifacts().iterator();

                while(var19.hasNext()) {
                    Artifact subProcessArtifact = (Artifact)var19.next();
                    this.drawArtifact(processDiagramCanvas, bpmnModel, subProcessArtifact);
                }
            }
        }
    }

    protected void prepareBpmnModel(BpmnModel bpmnModel) {
        ArrayList allGraphicInfos = new ArrayList();
        if(bpmnModel.getLocationMap() != null) {
            allGraphicInfos.addAll(bpmnModel.getLocationMap().values());
        }

        if(bpmnModel.getLabelLocationMap() != null) {
            allGraphicInfos.addAll(bpmnModel.getLabelLocationMap().values());
        }

        if(bpmnModel.getFlowLocationMap() != null) {
            Iterator needsTranslationX = bpmnModel.getFlowLocationMap().values().iterator();

            while(needsTranslationX.hasNext()) {
                List needsTranslationY = (List)needsTranslationX.next();
                allGraphicInfos.addAll(needsTranslationY);
            }
        }

        if(allGraphicInfos.size() > 0) {
            boolean needsTranslationX1 = false;
            boolean needsTranslationY1 = false;
            double lowestX = 0.0D;
            double lowestY = 0.0D;
            Iterator translationX = allGraphicInfos.iterator();

            double translationY;
            while(translationX.hasNext()) {
                GraphicInfo graphicInfo = (GraphicInfo)translationX.next();
                translationY = graphicInfo.getX();
                double y = graphicInfo.getY();
                if(translationY < lowestX) {
                    needsTranslationX1 = true;
                    lowestX = translationY;
                }

                if(y < lowestY) {
                    needsTranslationY1 = true;
                    lowestY = y;
                }
            }

            if(needsTranslationX1 || needsTranslationY1) {
                double translationX1 = Math.abs(lowestX);
                translationY = Math.abs(lowestY);
                Iterator y1 = allGraphicInfos.iterator();

                while(y1.hasNext()) {
                    GraphicInfo graphicInfo1 = (GraphicInfo)y1.next();
                    if(needsTranslationX1) {
                        graphicInfo1.setX(graphicInfo1.getX() + translationX1);
                    }

                    if(needsTranslationY1) {
                        graphicInfo1.setY(graphicInfo1.getY() + translationY);
                    }
                }
            }
        }

    }

    protected void drawActivity(DefaultProcessDiagramCanvas processDiagramCanvas, BpmnModel bpmnModel, FlowNode flowNode,List<String> highLightedFinishes, List<String> highLightedActivities, List<String> highLightedFlows, double scaleFactor, Boolean drawSequenceFlowNameWithNoLabelDI) {
        String act="";
        if(highLightedFinishes.size()>0){
             act=highLightedFinishes.get(0);
        }

        DefaultProcessDiagramGenerator.ActivityDrawInstruction drawInstruction = (DefaultProcessDiagramGenerator.ActivityDrawInstruction)this.activityDrawInstructions.get(flowNode.getClass());
        boolean highLighted;
        if(drawInstruction != null) {
            System.out.println("运行节点=="+flowNode.getName());
            String actColor="";
            if(act.equals(flowNode.getId())){
                actColor="1";
            }
            for(String clor:highLightedActivities){
                if(clor.equals(flowNode.getId()) && !clor.equals(act)){
                    actColor="2";
                    break;
                }
            }

            drawInstruction.draw(processDiagramCanvas, bpmnModel, flowNode,actColor);
            boolean multiInstanceSequential = false;
            boolean nestedFlowElement = false;
            highLighted = false;
            if(flowNode instanceof Activity) {
                Activity defaultFlow = (Activity)flowNode;
                MultiInstanceLoopCharacteristics isDefault = defaultFlow.getLoopCharacteristics();
                if(isDefault != null) {
                    multiInstanceSequential = isDefault.isSequential();
                    nestedFlowElement = !multiInstanceSequential;
                }
            }

            GraphicInfo var29 = bpmnModel.getGraphicInfo(flowNode.getId());
            if(!(flowNode instanceof SubProcess)) {
                if(flowNode instanceof CallActivity) {
                    highLighted = true;
                }
            } else {
                highLighted = var29.getExpanded() != null && !var29.getExpanded().booleanValue();
            }

            if(scaleFactor == 1.0D) {
                processDiagramCanvas.drawActivityMarkers((int) var29.getX(), (int) var29.getY(), (int) var29.getWidth(), (int) var29.getHeight(), multiInstanceSequential, nestedFlowElement, highLighted);
            }

            if(highLightedActivities.contains(flowNode.getId())) {
                if(act.equals(flowNode.getId())){
                    drawHighLight(processDiagramCanvas, bpmnModel.getGraphicInfo(flowNode.getId()),DefaultProcessDiagramCanvas.ACTIVE_COLOR);
                }else{
                    drawHighLight(processDiagramCanvas, bpmnModel.getGraphicInfo(flowNode.getId()),DefaultProcessDiagramCanvas.FINSH_COLOR);
                }
            }

        }

        Iterator var26 = flowNode.getOutgoingFlows().iterator();

        while(var26.hasNext()) {
            SequenceFlow var27 = (SequenceFlow)var26.next();
            highLighted = highLightedFlows.contains(var27.getId());
            String var30 = null;
            if(flowNode instanceof Activity) {
                var30 = ((Activity)flowNode).getDefaultFlow();
            } else if(flowNode instanceof Gateway) {
                var30 = ((Gateway)flowNode).getDefaultFlow();
            }

            boolean var31 = false;
            if(var30 != null && var30.equalsIgnoreCase(var27.getId())) {
                var31 = true;
            }

            boolean drawConditionalIndicator = var27.getConditionExpression() != null && !(flowNode instanceof Gateway);
            String sourceRef = var27.getSourceRef();
            String targetRef = var27.getTargetRef();
            FlowElement sourceElement = bpmnModel.getFlowElement(sourceRef);
            FlowElement targetElement = bpmnModel.getFlowElement(targetRef);
            List graphicInfoList = bpmnModel.getFlowLocationGraphicInfo(var27.getId());
            if(graphicInfoList != null && graphicInfoList.size() > 0) {
                graphicInfoList = connectionPerfectionizer(processDiagramCanvas, bpmnModel, sourceElement, targetElement, graphicInfoList);
                int[] xPoints = new int[graphicInfoList.size()];
                int[] yPoints = new int[graphicInfoList.size()];

                GraphicInfo lineCenter;
                for(int labelGraphicInfo = 1; labelGraphicInfo < graphicInfoList.size(); ++labelGraphicInfo) {
                    lineCenter = (GraphicInfo)graphicInfoList.get(labelGraphicInfo);
                    GraphicInfo previousGraphicInfo = (GraphicInfo)graphicInfoList.get(labelGraphicInfo - 1);
                    if(labelGraphicInfo == 1) {
                        xPoints[0] = (int)previousGraphicInfo.getX();
                        yPoints[0] = (int)previousGraphicInfo.getY();
                    }

                    xPoints[labelGraphicInfo] = (int)lineCenter.getX();
                    yPoints[labelGraphicInfo] = (int)lineCenter.getY();
                }

                processDiagramCanvas.drawSequenceflow(xPoints, yPoints, drawConditionalIndicator, var31, highLighted, scaleFactor);
                GraphicInfo var32 = bpmnModel.getLabelGraphicInfo(var27.getId());
                if(var32 != null) {
                    processDiagramCanvas.drawLabel(var27.getName(), var32, false);
                } else if(drawSequenceFlowNameWithNoLabelDI.booleanValue()) {
                    lineCenter = getLineCenter(graphicInfoList);
                    processDiagramCanvas.drawLabel(var27.getName(), lineCenter, false);
                }
            }
        }

        if(flowNode instanceof FlowElementsContainer) {
            var26 = ((FlowElementsContainer)flowNode).getFlowElements().iterator();

            while(var26.hasNext()) {
                FlowElement var28 = (FlowElement)var26.next();
                if(var28 instanceof FlowNode && !this.isPartOfCollapsedSubProcess(var28, bpmnModel)) {
                    this.drawActivity(processDiagramCanvas, bpmnModel, (FlowNode)var28, highLightedFinishes,highLightedActivities, highLightedFlows, scaleFactor, drawSequenceFlowNameWithNoLabelDI);
                }
            }
        }

    }

    protected static List<GraphicInfo> connectionPerfectionizer(DefaultProcessDiagramCanvas processDiagramCanvas, BpmnModel bpmnModel, BaseElement sourceElement, BaseElement targetElement, List<GraphicInfo> graphicInfoList) {
        GraphicInfo sourceGraphicInfo = bpmnModel.getGraphicInfo(sourceElement.getId());
        GraphicInfo targetGraphicInfo = bpmnModel.getGraphicInfo(targetElement.getId());
        SHAPE_TYPE sourceShapeType = getShapeType(sourceElement);
        SHAPE_TYPE targetShapeType = getShapeType(targetElement);
        return processDiagramCanvas.connectionPerfectionizer(sourceShapeType, targetShapeType, sourceGraphicInfo, targetGraphicInfo, graphicInfoList);
    }

    protected static SHAPE_TYPE getShapeType(BaseElement baseElement) {
        return !(baseElement instanceof Task) && !(baseElement instanceof Activity) && !(baseElement instanceof TextAnnotation)?(baseElement instanceof Gateway?SHAPE_TYPE.Rhombus:(baseElement instanceof Event?SHAPE_TYPE.Ellipse:null)):SHAPE_TYPE.Rectangle;
    }

    protected static GraphicInfo getLineCenter(List<GraphicInfo> graphicInfoList) {
        GraphicInfo gi = new GraphicInfo();
        int[] xPoints = new int[graphicInfoList.size()];
        int[] yPoints = new int[graphicInfoList.size()];
        double length = 0.0D;
        double[] lengths = new double[graphicInfoList.size()];
        lengths[0] = 0.0D;

        int p1;
        GraphicInfo graphicInfo1;
        for(p1 = 1; p1 < graphicInfoList.size(); ++p1) {
            GraphicInfo p2 = (GraphicInfo)graphicInfoList.get(p1);
            graphicInfo1 = (GraphicInfo)graphicInfoList.get(p1 - 1);
            if(p1 == 1) {
                xPoints[0] = (int)graphicInfo1.getX();
                yPoints[0] = (int)graphicInfo1.getY();
            }

            xPoints[p1] = (int)p2.getX();
            yPoints[p1] = (int)p2.getY();
            length += Math.sqrt(Math.pow((double)((int)p2.getX() - (int)graphicInfo1.getX()), 2.0D) + Math.pow((double)((int)p2.getY() - (int)graphicInfo1.getY()), 2.0D));
            lengths[p1] = length;
        }

        double m = length / 2.0D;
        p1 = 0;
        int var29 = 1;

        for(int var30 = 1; var30 < lengths.length; ++var30) {
            double graphicInfo2 = lengths[var30];
            p1 = var30 - 1;
            var29 = var30;
            if(graphicInfo2 > m) {
                break;
            }
        }

        graphicInfo1 = (GraphicInfo)graphicInfoList.get(p1);
        GraphicInfo var31 = (GraphicInfo)graphicInfoList.get(var29);
        double AB = (double)((int)var31.getX() - (int)graphicInfo1.getX());
        double OA = (double)((int)var31.getY() - (int)graphicInfo1.getY());
        double OB = lengths[var29] - lengths[p1];
        double ob = m - lengths[p1];
        double ab = AB * ob / OB;
        double oa = OA * ob / OB;
        double mx = graphicInfo1.getX() + ab;
        double my = graphicInfo1.getY() + oa;
        gi.setX(mx);
        gi.setY(my);
        return gi;
    }

    protected void drawArtifact(DefaultProcessDiagramCanvas processDiagramCanvas, BpmnModel bpmnModel, Artifact artifact) {
        DefaultProcessDiagramGenerator.ArtifactDrawInstruction drawInstruction = (DefaultProcessDiagramGenerator.ArtifactDrawInstruction)this.artifactDrawInstructions.get(artifact.getClass());
        if(drawInstruction != null) {
            drawInstruction.draw(processDiagramCanvas, bpmnModel, artifact);
        }

    }

    private static void drawHighLight(DefaultProcessDiagramCanvas processDiagramCanvas, GraphicInfo graphicInfo,Color color) {
        processDiagramCanvas.drawHighLight((int)graphicInfo.getX(), (int)graphicInfo.getY(), (int)graphicInfo.getWidth(), (int)graphicInfo.getHeight(),color);
    }

    protected static DefaultProcessDiagramCanvas initProcessDiagramCanvas(BpmnModel bpmnModel, String imageType, String activityFontName, String labelFontName, String annotationFontName, ClassLoader customClassLoader) {
        double minX = 1.7976931348623157E308D;
        double maxX = 0.0D;
        double minY = 1.7976931348623157E308D;
        double maxY = 0.0D;

        GraphicInfo nrOfLanes;
        for(Iterator flowNodes = bpmnModel.getPools().iterator(); flowNodes.hasNext(); maxY = nrOfLanes.getY() + nrOfLanes.getHeight()) {
            Pool artifacts = (Pool)flowNodes.next();
            nrOfLanes = bpmnModel.getGraphicInfo(artifacts.getId());
            minX = nrOfLanes.getX();
            maxX = nrOfLanes.getX() + nrOfLanes.getWidth();
            minY = nrOfLanes.getY();
        }

        List var23 = gatherAllFlowNodes(bpmnModel);
        Iterator var24 = var23.iterator();

        label155:
        while(var24.hasNext()) {
            FlowNode var26 = (FlowNode)var24.next();
            GraphicInfo artifact = bpmnModel.getGraphicInfo(var26.getId());
            if(artifact.getX() + artifact.getWidth() > maxX) {
                maxX = artifact.getX() + artifact.getWidth();
            }

            if(artifact.getX() < minX) {
                minX = artifact.getX();
            }

            if(artifact.getY() + artifact.getHeight() > maxY) {
                maxY = artifact.getY() + artifact.getHeight();
            }

            if(artifact.getY() < minY) {
                minY = artifact.getY();
            }

            Iterator process = var26.getOutgoingFlows().iterator();

            while(true) {
                List l;
                do {
                    if(!process.hasNext()) {
                        continue label155;
                    }

                    SequenceFlow graphicInfoList = (SequenceFlow)process.next();
                    l = bpmnModel.getFlowLocationGraphicInfo(graphicInfoList.getId());
                } while(l == null);

                Iterator graphicInfo = l.iterator();

                while(graphicInfo.hasNext()) {
                    GraphicInfo graphicInfo1 = (GraphicInfo)graphicInfo.next();
                    if(graphicInfo1.getX() > maxX) {
                        maxX = graphicInfo1.getX();
                    }

                    if(graphicInfo1.getX() < minX) {
                        minX = graphicInfo1.getX();
                    }

                    if(graphicInfo1.getY() > maxY) {
                        maxY = graphicInfo1.getY();
                    }

                    if(graphicInfo1.getY() < minY) {
                        minY = graphicInfo1.getY();
                    }
                }
            }
        }

        List var25 = gatherAllArtifacts(bpmnModel);
        Iterator var27 = var25.iterator();

        GraphicInfo var37;
        while(var27.hasNext()) {
            Artifact var29 = (Artifact)var27.next();
            GraphicInfo var31 = bpmnModel.getGraphicInfo(var29.getId());
            if(var31 != null) {
                if(var31.getX() + var31.getWidth() > maxX) {
                    maxX = var31.getX() + var31.getWidth();
                }

                if(var31.getX() < minX) {
                    minX = var31.getX();
                }

                if(var31.getY() + var31.getHeight() > maxY) {
                    maxY = var31.getY() + var31.getHeight();
                }

                if(var31.getY() < minY) {
                    minY = var31.getY();
                }
            }

            List var33 = bpmnModel.getFlowLocationGraphicInfo(var29.getId());
            if(var33 != null) {
                Iterator var35 = var33.iterator();

                while(var35.hasNext()) {
                    var37 = (GraphicInfo)var35.next();
                    if(var37.getX() > maxX) {
                        maxX = var37.getX();
                    }

                    if(var37.getX() < minX) {
                        minX = var37.getX();
                    }

                    if(var37.getY() > maxY) {
                        maxY = var37.getY();
                    }

                    if(var37.getY() < minY) {
                        minY = var37.getY();
                    }
                }
            }
        }

        int var28 = 0;
        Iterator var30 = bpmnModel.getProcesses().iterator();

        while(var30.hasNext()) {
            Process var32 = (Process)var30.next();
            Iterator var34 = var32.getLanes().iterator();

            while(var34.hasNext()) {
                Lane var36 = (Lane)var34.next();
                ++var28;
                var37 = bpmnModel.getGraphicInfo(var36.getId());
                if(var37.getX() + var37.getWidth() > maxX) {
                    maxX = var37.getX() + var37.getWidth();
                }

                if(var37.getX() < minX) {
                    minX = var37.getX();
                }

                if(var37.getY() + var37.getHeight() > maxY) {
                    maxY = var37.getY() + var37.getHeight();
                }

                if(var37.getY() < minY) {
                    minY = var37.getY();
                }
            }
        }

        if(var23.isEmpty() && bpmnModel.getPools().isEmpty() && var28 == 0) {
            minX = 0.0D;
            minY = 0.0D;
        }

        return new DefaultProcessDiagramCanvas((int)maxX + 10, (int)maxY + 10, (int)minX, (int)minY, imageType, activityFontName, labelFontName, annotationFontName, customClassLoader);
    }

    protected static List<Artifact> gatherAllArtifacts(BpmnModel bpmnModel) {
        ArrayList artifacts = new ArrayList();
        Iterator var2 = bpmnModel.getProcesses().iterator();

        while(var2.hasNext()) {
            Process process = (Process)var2.next();
            artifacts.addAll(process.getArtifacts());
        }

        return artifacts;
    }

    protected static List<FlowNode> gatherAllFlowNodes(BpmnModel bpmnModel) {
        ArrayList flowNodes = new ArrayList();
        Iterator var2 = bpmnModel.getProcesses().iterator();

        while(var2.hasNext()) {
            Process process = (Process)var2.next();
            flowNodes.addAll(gatherAllFlowNodes((FlowElementsContainer)process));
        }

        return flowNodes;
    }

    protected static List<FlowNode> gatherAllFlowNodes(FlowElementsContainer flowElementsContainer) {
        ArrayList flowNodes = new ArrayList();
        Iterator var2 = flowElementsContainer.getFlowElements().iterator();

        while(var2.hasNext()) {
            FlowElement flowElement = (FlowElement)var2.next();
            if(flowElement instanceof FlowNode) {
                flowNodes.add((FlowNode)flowElement);
            }

            if(flowElement instanceof FlowElementsContainer) {
                flowNodes.addAll(gatherAllFlowNodes((FlowElementsContainer)flowElement));
            }
        }

        return flowNodes;
    }

    protected boolean isPartOfCollapsedSubProcess(FlowElement flowElement, BpmnModel model) {
        SubProcess subProcess = flowElement.getSubProcess();
        if(subProcess != null) {
            GraphicInfo graphicInfo = model.getGraphicInfo(subProcess.getId());
            return graphicInfo != null && graphicInfo.getExpanded() != null && !graphicInfo.getExpanded().booleanValue()?true:this.isPartOfCollapsedSubProcess(subProcess, model);
        } else {
            return false;
        }
    }

    public Map<Class<? extends BaseElement>, DefaultProcessDiagramGenerator.ActivityDrawInstruction> getActivityDrawInstructions() {
        return this.activityDrawInstructions;
    }

    public void setActivityDrawInstructions(Map<Class<? extends BaseElement>, DefaultProcessDiagramGenerator.ActivityDrawInstruction> activityDrawInstructions) {
        this.activityDrawInstructions = activityDrawInstructions;
    }

    public Map<Class<? extends BaseElement>, DefaultProcessDiagramGenerator.ArtifactDrawInstruction> getArtifactDrawInstructions() {
        return this.artifactDrawInstructions;
    }

    public void setArtifactDrawInstructions(Map<Class<? extends BaseElement>, DefaultProcessDiagramGenerator.ArtifactDrawInstruction> artifactDrawInstructions) {
        this.artifactDrawInstructions = artifactDrawInstructions;
    }

    protected interface ArtifactDrawInstruction {
        void draw(DefaultProcessDiagramCanvas var1, BpmnModel var2, Artifact var3);
    }

    protected interface ActivityDrawInstruction {
        void draw(DefaultProcessDiagramCanvas var1, BpmnModel var2, FlowNode var3,String actColor);
    }
}
