Q: Can I use MindFusion's Java diagramming library in a web application?
A: JThere are several ways to utilize JDiagram in web applications.
If you need to let users edit flowcharts and diagrams interactively on a web page, you can load the control via the HTML applet tag. You can either create your own applet that hosts a DiagramView instance and additional Java Swing UI controls, or use the DiagramApplet class included in JDiagram.jar. The example below show how to load the built-in applet and attach a diagram event handler to it.
<applet id="jDiagApplet name="jDiagApplet" width="800" height="600" code="com/mindfusion/diagramming/DiagramApplet.class archive="JDiagram.jar" mayscript="mayscript"> <param name="NodeClicked" value="onNodeClicked"> </applet>
If a read-only flowchart image is sufficient for your needs, you can use the Diagram class to generate an image, and either save it as a file to be served by the web server, or use a Java servlet as the source of an html img tag to return the image bytes to the browser. Along with the generated flowchart image, you can use the HtmlBuilder class to generate html imgmap object whose area elements correspond to the items in the diagram, and whose target links are set to the hyperlink attributes of DiagramItem objects. This approach is demonstrated in the JspSample project included in the JDiagram distribution, which shows how to generate diagrams dynamically from a JSP page and arrange them using the automatic graph layout algorithms coming with the component. An excerpt from the sample is shown below:
<jsp:useBean id="diagram" class="com.mindfusion.diagramming.Diagram" scope="session" /> <jsp:setProperty name="diagram" property="measureUnit" value="<%= GraphicsUnit.Pixel %>" /> <jsp:setProperty name="diagram" property="bounds" value="<%= new Rectangle2D.Float(0, 0, 600, 400) %>" /> <jsp:setProperty name="diagram" property="backBrush" value="<%= new SolidBrush(Color.white) %>" /> <jsp:setProperty name="diagram" property="selectAfterCreate" value="false" /> <img id="imgChart" src="ImageGen?id=diagram" usemap='#map'> <%= new HtmlBuilder(diagram).createImageMap("map") %>
Another application of JDiagram on the server side is to use the PDFExporter class to generate PDF files containing diagram elements rendered as PDF graphic objects.