1
2
3
4
5
6
7
8
9
10 package edu.uci.ics.jung.visualization;
11
12 import java.awt.Dimension;
13 import java.awt.Graphics2D;
14 import java.awt.Image;
15 import java.awt.RenderingHints;
16 import java.awt.geom.Point2D;
17 import java.awt.image.BufferedImage;
18 import java.util.HashMap;
19 import java.util.Map;
20
21 import edu.uci.ics.jung.algorithms.layout.Layout;
22
23
24
25
26
27
28
29
30
31 @SuppressWarnings("serial")
32 public class VisualizationImageServer<V,E> extends BasicVisualizationServer<V,E> {
33
34 Map<RenderingHints.Key, Object> renderingHints = new HashMap<RenderingHints.Key, Object>();
35
36
37
38
39
40
41
42 public VisualizationImageServer(Layout<V,E> layout, Dimension preferredSize) {
43 super(layout, preferredSize);
44 setSize(preferredSize);
45 renderingHints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
46 addNotify();
47 }
48
49 public Image getImage(Point2D center, Dimension d)
50 {
51 int width = getWidth();
52 int height = getHeight();
53
54 float scalex = (float)width/d.width;
55 float scaley = (float)height/d.height;
56 try
57 {
58 renderContext.getMultiLayerTransformer().getTransformer(Layer.VIEW).scale(scalex, scaley, center);
59
60 BufferedImage bi = new BufferedImage(width, height,
61 BufferedImage.TYPE_INT_RGB);
62 Graphics2D graphics = bi.createGraphics();
63 graphics.setRenderingHints(renderingHints);
64 paint(graphics);
65 graphics.dispose();
66 return bi;
67 } finally {
68 renderContext.getMultiLayerTransformer().getTransformer(Layer.VIEW).setToIdentity();
69 }
70 }
71 }