| | | | Browse by category |
Question
How do you set a diagram's background to be transparent in a thin-client or JSF application with JViews Diagrammer?
Answer
The class generates the image of the manager through a HTTP request.
To obtain a transparent image of the diagram, you must subclass the and override the method. In addition, you must subclass
and override the method to return your own custom IlvDiagrammerServletSupport.
1) Extend the IlvDiagrammerServletSupport class to override its generateImage(...) method. In this method, force the returned image to be transparent by calling super.generateImage(...) and setting the last parameter tot rue.
Sample code :
public class MyServletSupport extends IlvDiagrammerServletSupport {
public MyServletSupport(ServletContext servletContext) {
super(servletContext);
}
protected BufferedImage generateImage(HttpServletRequest request,
IlvRect bbox, int width, int height, String[] layers,
Color bgColor, boolean transparent) throws ServletException {
// Generate the original image as "transparent": last parameter is true
BufferedImage graphImage = super.generateImage(request, bbox, width, height, layers, bgColor, true);
return graphImage;
}
}
2) Extend the IlvDiagrammerServlet class to return your own Servlet support instance through the createServletSupport(javax.servlet.ServletContext context) method.
Sample code :
public class MyServlet extends IlvDiagrammerServlet {
protected IlvSDMServletSupport createServletSupport(javax.servlet.ServletContext context){
return new MyServletSupport(context);
}
}
3) In order for this servlet to be taken into account, in your JSP you need to add the servlet attribute into the declaration of your diagrammerView:
Sample code :
<jvdf:diagrammerView id="diagrammer"
...
servlet="full.path.MyServlet"
/>
Notices :
1) JPEG images do not support transparency. PNG image format supports transparency.
2) Different browsers yield different results. With Internet Explorer 6.0, only the background color of the HTML page is visible behind the diagram, whereas with Firefox 3.5.7, both the background color and the background image of the HTML page are visible behind the diagram.