use of cbit.vcell.graph.ReactionCartoonFull in project vcell by virtualcell.
the class ITextWriter method generateDocReactionsImage.
public static BufferedImage generateDocReactionsImage(Model model, Integer width) throws Exception {
// if (model == null || !isValidResolutionSetting(resolution)) {
// throw new IllegalArgumentException("Invalid parameters for generating reactions image for model: " + model.getName());
// }
ReactionCartoon rcartoon = new ReactionCartoonFull();
rcartoon.setModel(model);
StructureSuite structureSuite = new AllStructureSuite(new Model.Owner() {
@Override
public Model getModel() {
return model;
}
});
rcartoon.setStructureSuite(structureSuite);
rcartoon.refreshAll();
// dummy settings to get the real dimensions.
BufferedImage dummyBufferedImage = new BufferedImage(DEF_IMAGE_WIDTH, DEF_IMAGE_HEIGHT, BufferedImage.TYPE_3BYTE_BGR);
Graphics2D dummyGraphics = (Graphics2D) dummyBufferedImage.getGraphics();
Dimension prefDim = rcartoon.getPreferedCanvasSize(dummyGraphics);
dummyGraphics.dispose();
// double width = prefDim.getWidth();
// double height = prefDim.getHeight();
double widthHeightRatio = (double) prefDim.getWidth() / (double) prefDim.getHeight();
if (width == null) {
width = ITextWriter.DEF_IMAGE_WIDTH;
}
int height = (int) ((double) width / widthHeightRatio);
// int MAX_IMAGE_HEIGHT = 532;
// if (width < ITextWriter.DEF_IMAGE_WIDTH) {
// width = ITextWriter.DEF_IMAGE_WIDTH;
// }
// height= height * width/prefDim.getWidth();
// if (height < ITextWriter.DEF_IMAGE_HEIGHT) {
// height = ITextWriter.DEF_IMAGE_HEIGHT;
// } else if (height > MAX_IMAGE_HEIGHT) {
// height = MAX_IMAGE_HEIGHT;
// }
// width= width * height/prefDim.getHeight();
Dimension newDim = new Dimension((int) width, (int) height);
rcartoon.getResizeManager().setZoomPercent((int) (100 * width / prefDim.getWidth()));
BufferedImage bufferedImage = new BufferedImage(newDim.width, newDim.height, BufferedImage.TYPE_3BYTE_BGR);
Graphics2D g = (Graphics2D) bufferedImage.getGraphics();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
GraphContainerLayoutReactions containerLayout = new GraphContainerLayoutReactions();
containerLayout.layout(rcartoon, g, prefDim);
rcartoon.paint(g);
g.dispose();
return bufferedImage;
}
Aggregations