Survive by day and develop by night.
talk for import biz , show your perfect code,full busy,skip hardness,make a better result,wait for change,challenge Survive.
happy for hardess to solve denpendies.
ProcessDiagramSVGGraphics2D是一个非常常见的需求。
public interface ProcessDiagramGenerator {
/**
* Generates a diagram of the given process definition, using the diagram interchange information of the process.
* If there is no interchange information available, an ActivitiInterchangeInfoNotFoundException is thrown.
* @param bpmnModel bpmn model to get diagram for
* @param highLightedActivities activities to highlight
* @param highLightedFlows flows to highlight
* @param activityFontName override the default activity font
* @param labelFontName override the default label font
*/
InputStream generateDiagram(BpmnModel bpmnModel,
List<String> highLightedActivities,
List<String> highLightedFlows,
String activityFontName,
String labelFontName,
String annotationFontName);
/**
* Generates a diagram of the given process definition, using the diagram interchange information of the process,
* or the default diagram image, if generateDefaultDiagram param is true.
* @param bpmnModel bpmn model to get diagram for
* @param highLightedActivities activities to highlight
* @param highLightedFlows flows to highlight
* @param activityFontName override the default activity font
* @param labelFontName override the default label font
* @param generateDefaultDiagram true if a default diagram should be generated if there is no graphic info available
*/
InputStream generateDiagram(BpmnModel bpmnModel,
List<String> highLightedActivities,
List<String> highLightedFlows,
String activityFontName,
String labelFontName,
String annotationFontName,
boolean generateDefaultDiagram);
/**
* Generates a diagram of the given process definition, using the diagram interchange information of the process,
* or the default diagram image, if generateDefaultDiagram param is true.
* @param bpmnModel bpmn model to get diagram for
* @param highLightedActivities activities to highlight
* @param highLightedFlows flows to highlight
* @param currentActivities current activities to highlight
* @param erroredActivities errored activities to highlight
* @param activityFontName override the default activity font
* @param labelFontName override the default label font
* @param generateDefaultDiagram true if a default diagram should be generated if there is no graphic info available
* @param defaultDiagramImageFileName override the default diagram image file name
*/
InputStream generateDiagram(BpmnModel bpmnModel,
List<String> highLightedActivities,
List<String> highLightedFlows,
List<String> currentActivities,
List<String> erroredActivities,
String activityFontName,
String labelFontName,
String annotationFontName,
boolean generateDefaultDiagram,
String defaultDiagramImageFileName);
/**
* Generates a diagram of the given process definition, using the diagram interchange information of the process.
* If there is no interchange information available, an ActivitiInterchangeInfoNotFoundException is thrown.
* @param bpmnModel bpmn model to get diagram for
* @param highLightedActivities activities to highlight
* @param highLightedFlows flows to highlight
*/
InputStream generateDiagram(BpmnModel bpmnModel,
List<String> highLightedActivities,
List<String> highLightedFlows);
/**
* Generates a diagram of the given process definition, using the diagram interchange information of the process.
* If there is no interchange information available, an ActivitiInterchangeInfoNotFoundException is thrown.
* @param bpmnModel bpmn model to get diagram for
* @param highLightedActivities activities to highlight
*/
InputStream generateDiagram(BpmnModel bpmnModel,
List<String> highLightedActivities);
/**
* Generates a diagram of the given process definition, using the diagram interchange information of the process.
* If there is no interchange information available, an ActivitiInterchangeInfoNotFoundException is thrown.
* @param bpmnModel bpmn model to get diagram for
*/
InputStream generateDiagram(BpmnModel bpmnModel,
String activityFontName,
String labelFontName,
String annotationFontName);
String getDefaultActivityFontName();
String getDefaultLabelFontName();
String getDefaultAnnotationFontName();
String getDefaultDiagramImageFileName();
}
public class ProcessDiagramSVGGraphics2D extends SVGGraphics2D {
public ProcessDiagramSVGGraphics2D(Document domFactory) {
super(domFactory);
this.setDOMGroupManager(new ProcessDiagramDOMGroupManager(this.getGraphicContext(),
this.getDOMTreeManager()));
}
@Override
public void setRenderingHints(@SuppressWarnings("rawtypes") Map hints) {
super.setRenderingHints(hints);
}
@Override
public void addRenderingHints(@SuppressWarnings("rawtypes") Map hints) {
super.addRenderingHints(hints);
}
public void setCurrentGroupId(String id) {
this.getExtendDOMGroupManager().setCurrentGroupId(id);
}
public ProcessDiagramDOMGroupManager getExtendDOMGroupManager() {
return (ProcessDiagramDOMGroupManager) super.getDOMGroupManager();
}
}
public class ProcessDiagramDOMGroupManager extends DOMGroupManager {
public ProcessDiagramDOMGroupManager(GraphicContext gc,
DOMTreeManager domTreeManager) {
super(gc,
domTreeManager);
}
public void setCurrentGroupId(String id) {
this.currentGroup.setAttribute("id",
id);
}
}
public class DefaultProcessDiagramGenerator implements ProcessDiagramGenerator {
private static final String DEFAULT_ACTIVITY_FONT_NAME = "Arial";
private static final String DEFAULT_LABEL_FONT_NAME = "Arial";
private static final String DEFAULT_ANNOTATION_FONT_NAME = "Arial";
private static final String DEFAULT_DIAGRAM_IMAGE_FILE_NAME = "/image/na.svg";
protected Map<Class<? extends BaseElement>, ActivityDrawInstruction> activityDrawInstructions = new HashMap<Class<? extends BaseElement>, ActivityDrawInstruction>();
protected Map<Class<? extends BaseElement>, ArtifactDrawInstruction> artifactDrawInstructions = new HashMap<Class<? extends BaseElement>, ArtifactDrawInstruction>();
@Override
public String getDefaultActivityFontName() {
return DEFAULT_ACTIVITY_FONT_NAME;
}
@Override
public String getDefaultLabelFontName() {
return DEFAULT_LABEL_FONT_NAME;
}
@Override
public String getDefaultAnnotationFontName() {
return DEFAULT_ANNOTATION_FONT_NAME;
}
@Override
public String getDefaultDiagramImageFileName() {
return DEFAULT_DIAGRAM_IMAGE_FILE_NAME;
}
// The instructions on how to draw a certain construct is
// created statically and stored in a map for performance.
public DefaultProcessDiagramGenerator() {
// start event
activityDrawInstructions.put(StartEvent.class,
new ActivityDrawInstruction() {
@Override
public void draw(DefaultProcessDiagramCanvas processDiagramCanvas,
BpmnModel bpmnModel,
FlowNode flowNode) {
GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(flowNode.getId());
StartEvent startEvent = (StartEvent) flowNode;
if (startEvent.getEventDefinitions() != null && !startEvent.getEventDefinitions().isEmpty()) {
EventDefinition eventDefinition = startEvent.getEventDefinitions().get(0);
if (eventDefinition instanceof TimerEventDefinition) {
processDiagramCanvas.drawTimerStartEvent(flowNode.getId(),
graphicInfo);
} else if (eventDefinition instanceof ErrorEventDefinition) {
processDiagramCanvas.drawErrorStartEvent(flowNode.getId(),
graphicInfo);
} else if (eventDefinition instanceof SignalEventDefinition) {
processDiagramCanvas.drawSignalStartEvent(flowNode.getId(),
graphicInfo);
} else if (eventDefinition instanceof MessageEventDefinition) {
processDiagramCanvas.drawMessageStartEvent(flowNode.getId(),
graphicInfo);
} else {
processDiagramCanvas.drawNoneStartEvent(flowNode.getId(),
graphicInfo);
}
} else {
processDiagramCanvas.drawNoneStartEvent(flowNode.getId(),
graphicInfo);
}
}
});
// signal catch
activityDrawInstructions.put(IntermediateCatchEvent.class,
new ActivityDrawInstruction() {
@Override
public void draw(DefaultProcessDiagramCanvas processDiagramCanvas,
BpmnModel bpmnModel,
FlowNode flowNode) {
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.getId(),
flowNode.getName(),
graphicInfo,
true);
} else if (intermediateCatchEvent.getEventDefinitions().get(0) instanceof TimerEventDefinition) {
processDiagramCanvas.drawCatchingTimerEvent(flowNode.getId(),
flowNode.getName(),
graphicInfo,
true);
} else if (intermediateCatchEvent.getEventDefinitions().get(0) instanceof MessageEventDefinition) {
processDiagramCanvas.drawCatchingMessageEvent(flowNode.getId(),
flowNode.getName(),
graphicInfo,
true);
}
}
}
});
// signal throw
activityDrawInstructions.put(ThrowEvent.class,
new ActivityDrawInstruction() {
@Override
public void draw(DefaultProcessDiagramCanvas processDiagramCanvas,
BpmnModel bpmnModel,
FlowNode flowNode) {
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(flowNode.getId(),
graphicInfo);
} else if (throwEvent.getEventDefinitions().get(0) instanceof CompensateEventDefinition) {
processDiagramCanvas.drawThrowingCompensateEvent(flowNode.getId(),
graphicInfo);
} else {
processDiagramCanvas.drawThrowingNoneEvent(flowNode.getId(),
graphicInfo);
}
} else {
processDiagramCanvas.drawThrowingNoneEvent(flowNode.getId(),
graphicInfo);
}
}
});
// end event
activityDrawInstructions.put(EndEvent.class,
new ActivityDrawInstruction() {
@Override
public void draw(DefaultProcessDiagramCanvas processDiagramCanvas,
BpmnModel bpmnModel,
FlowNode flowNode) {
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.getId(),
flowNode.getName(),
graphicInfo);
} else {
processDiagramCanvas.drawNoneEndEvent(flowNode.getId(),
flowNode.getName(),
graphicInfo);
}
} else {
processDiagramCanvas.drawNoneEndEvent(flowNode.getId(),
flowNode.getName(),
graphicInfo);
}
}
});
// task
activityDrawInstructions.put(Task.class,
new ActivityDrawInstruction() {
@Override
public void draw(DefaultProcessDiagramCanvas processDiagramCanvas,
BpmnModel bpmnModel,
FlowNode flowNode) {
GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(flowNode.getId());
processDiagramCanvas.drawTask(flowNode.getId(),
flowNode.getName(),
graphicInfo);
}
});
// user task
activityDrawInstructions.put(UserTask.class,
new ActivityDrawInstruction() {
@Override
public void draw(DefaultProcessDiagramCanvas processDiagramCanvas,
BpmnModel bpmnModel,
FlowNode flowNode) {
GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(flowNode.getId());
processDiagramCanvas.drawUserTask(flowNode.getId(),
flowNode.getName(),
graphicInfo);
}
});
// script task
activityDrawInstructions.put(ScriptTask.class,
new ActivityDrawInstruction() {
@Override
public void draw(DefaultProcessDiagramCanvas processDiagramCanvas,
BpmnModel bpmnModel,
FlowNode flowNode) {
GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(flowNode.getId());
processDiagramCanvas.drawScriptTask(flowNode.getId(),
flowNode.getName(),
graphicInfo);
}
});
// service task
activityDrawInstructions.put(ServiceTask.class,
new ActivityDrawInstruction() {
@Override
public void draw(DefaultProcessDiagramCanvas processDiagramCanvas,
BpmnModel bpmnModel,
FlowNode flowNode) {
GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(flowNode.getId());
ServiceTask serviceTask = (ServiceTask) flowNode;
processDiagramCanvas.drawServiceTask(flowNode.getId(),
serviceTask.getName(),
graphicInfo);
}
});
// receive task
activityDrawInstructions.put(ReceiveTask.class,
new ActivityDrawInstruction() {
@Override
public void draw(DefaultProcessDiagramCanvas processDiagramCanvas,
BpmnModel bpmnModel,
FlowNode flowNode) {
GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(flowNode.getId());
processDiagramCanvas.drawReceiveTask(flowNode.getId(),
flowNode.getName(),
graphicInfo);
}
});
// send task
activityDrawInstructions.put(SendTask.class,
new ActivityDrawInstruction() {
@Override
public void draw(DefaultProcessDiagramCanvas processDiagramCanvas,
BpmnModel bpmnModel,
FlowNode flowNode) {
GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(flowNode.getId());
processDiagramCanvas.drawSendTask(flowNode.getId(),
flowNode.getName(),
graphicInfo);
}
});
// manual task
activityDrawInstructions.put(ManualTask.class,
new ActivityDrawInstruction() {
@Override
public void draw(DefaultProcessDiagramCanvas processDiagramCanvas,
BpmnModel bpmnModel,
FlowNode flowNode) {
GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(flowNode.getId());
processDiagramCanvas.drawManualTask(flowNode.getId(),
flowNode.getName(),
graphicInfo);
}
});
// businessRuleTask task
activityDrawInstructions.put(BusinessRuleTask.class,
new ActivityDrawInstruction() {
@Override
public void draw(DefaultProcessDiagramCanvas processDiagramCanvas,
BpmnModel bpmnModel,
FlowNode flowNode) {
GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(flowNode.getId());
processDiagramCanvas.drawBusinessRuleTask(flowNode.getId(),
flowNode.getName(),
graphicInfo);
}
});
// exclusive gateway
activityDrawInstructions.put(ExclusiveGateway.class,
new ActivityDrawInstruction() {
@Override
public void draw(DefaultProcessDiagramCanvas processDiagramCanvas,
BpmnModel bpmnModel,
FlowNode flowNode) {
GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(flowNode.getId());
processDiagramCanvas.drawExclusiveGateway(flowNode.getId(),
graphicInfo);
}
});
// inclusive gateway
activityDrawInstructions.put(InclusiveGateway.class,
new ActivityDrawInstruction() {
@Override
public void draw(DefaultProcessDiagramCanvas processDiagramCanvas,
BpmnModel bpmnModel,
FlowNode flowNode) {
GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(flowNode.getId());
processDiagramCanvas.drawInclusiveGateway(flowNode.getId(),
graphicInfo);
}
});
// parallel gateway
activityDrawInstructions.put(ParallelGateway.class,
new ActivityDrawInstruction() {
@Override
public void draw(DefaultProcessDiagramCanvas processDiagramCanvas,
BpmnModel bpmnModel,
FlowNode flowNode) {
GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(flowNode.getId());
processDiagramCanvas.drawParallelGateway(flowNode.getId(),
graphicInfo);
}
});
[1]. www.acitivte.org
欢迎阅读,各位老铁,如果对你有帮助,点个赞加个关注呗!~