01: /*
02: * Copyright (C) 2001-2004 Gaudenz Alder
03: *
04: * JGraphpad is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU General Public License
06: * as published by the Free Software Foundation; either version 2
07: * of the License, or (at your option) any later version.
08: *
09: * JGraphpad is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: * GNU General Public License for more details.
13: *
14: * You should have received a copy of the GNU General Public License
15: * along with JGraphpad; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17: *
18: */
19: package org.lucane.applications.whiteboard.graph;
20:
21: import java.awt.Dimension;
22: import java.awt.Graphics;
23: import java.awt.Image;
24:
25: import javax.swing.Icon;
26: import javax.swing.ImageIcon;
27:
28: import org.jgraph.JGraph;
29: import org.jgraph.graph.CellMapper;
30: import org.jgraph.graph.CellViewRenderer;
31: import org.jgraph.graph.VertexRenderer;
32: import org.jgraph.graph.VertexView;
33:
34: public class ScaledVertexView extends VertexView {
35: public static VertexRenderer renderer = new ScaledVertexRenderer();
36:
37: public ScaledVertexView(Object v, JGraph graph, CellMapper cm) {
38: super (v, graph, cm);
39: }
40:
41: public CellViewRenderer getRenderer() {
42: return renderer;
43: }
44:
45: public static class ScaledVertexRenderer extends VertexRenderer {
46: public void paint(Graphics g) {
47: Icon icon = getIcon();
48: setIcon(null);
49: Dimension d = getSize();
50: Image img = null;
51: if (icon instanceof ImageIcon)
52: img = ((ImageIcon) icon).getImage();
53: if (img != null)
54: g
55: .drawImage(img, 0, 0, d.width - 1,
56: d.height - 1, graph);
57: super.paint(g);
58: }
59: }
60: }
|