Line | Hits | Source |
---|---|---|
1 | /******************************************************************************* | |
2 | * Demetrix process modelling system | |
3 | * | |
4 | * Copyright (c) 2003, 2004 Dimitri A. Pissarenko | |
5 | * | |
6 | * This file is part of Demetrix. | |
7 | * | |
8 | * Demetrix is free software; you can redistribute it and/or modify | |
9 | * it under the terms of the GNU General Public License as published by | |
10 | * the Free Software Foundation; either version 2.1 of the License, or | |
11 | * (at your option) any later version. | |
12 | * | |
13 | * Demetrix is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with Demetrix; if not, write to the Free Software | |
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 | * | |
22 | * For further information you may | |
23 | * | |
24 | * - send an e-mail in Russian, German or English to dimitri.pissarenko@gmx.net | |
25 | * - look at http://sourceforge.net/projects/demetrix/ | |
26 | * - look at http://demetrix.sourceforge.net/ | |
27 | * - look at http://members.inode.at/d.pissarenko/ | |
28 | * | |
29 | *****************************************************************************/ | |
30 | /* | |
31 | * Created on 15.01.2004 | |
32 | */ | |
33 | package net.sourceforge.demetrix.util; | |
34 | ||
35 | import java.awt.Graphics2D; | |
36 | import java.awt.image.BufferedImage; | |
37 | import java.io.File; | |
38 | import java.io.IOException; | |
39 | ||
40 | import javax.imageio.ImageIO; | |
41 | ||
42 | import org.apache.log4j.Logger; | |
43 | import org.jgraph.JGraph; | |
44 | ||
45 | /** | |
46 | * @author Dimitri Pissarenko | |
47 | * | |
48 | */ | |
49 | public class JGraphExporter { | |
50 | private static JGraphExporter instance; | |
51 | private Logger logger=Logger.getLogger(getClass()); | |
52 | public final static String PNG_FORMAT = "png"; | |
53 | private JGraphExporter() | |
54 | 0 | { |
55 | 0 | } |
56 | public static JGraphExporter getInstance() | |
57 | { | |
58 | 0 | if (instance==null) |
59 | { | |
60 | 0 | instance=new JGraphExporter(); |
61 | } | |
62 | 0 | return instance; |
63 | } | |
64 | public void exportJGraph(JGraph jgraph, String fileFormat, File file) | |
65 | { | |
66 | 0 | Graphics2D graphics2D=null; |
67 | 0 | BufferedImage img=null; |
68 | ||
69 | ||
70 | 0 | img = new BufferedImage(jgraph.getPreferredScrollableViewportSize().width, jgraph.getPreferredScrollableViewportSize().height, BufferedImage.TYPE_INT_RGB); |
71 | 0 | graphics2D=(Graphics2D)img.getGraphics(); |
72 | 0 | jgraph.paint(graphics2D); |
73 | 0 | graphics2D.dispose(); |
74 | ||
75 | try | |
76 | { | |
77 | 0 | ImageIO.write(img, fileFormat, file); |
78 | } | |
79 | 0 | catch (IOException exception) |
80 | { | |
81 | this.logger.error("", exception); | |
82 | 0 | } |
83 | 0 | } |
84 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |