KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > applications > whiteboard > graph > ScaledVertexView


1 /*
2  * Copyright (C) 2001-2004 Gaudenz Alder
3  *
4  * JGraphpad is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * 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 JavaDoc;
22 import java.awt.Graphics JavaDoc;
23 import java.awt.Image JavaDoc;
24
25 import javax.swing.Icon JavaDoc;
26 import javax.swing.ImageIcon JavaDoc;
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 {
36     public static VertexRenderer renderer = new ScaledVertexRenderer();
37     
38     public ScaledVertexView(Object JavaDoc v, JGraph graph, CellMapper cm)
39     {
40         super(v, graph, cm);
41     }
42     
43     public CellViewRenderer getRenderer()
44     {
45         return renderer;
46     }
47     
48     public static class ScaledVertexRenderer extends VertexRenderer
49     {
50         public void paint(Graphics JavaDoc g)
51         {
52             Icon JavaDoc icon = getIcon();
53             setIcon(null);
54             Dimension JavaDoc d = getSize();
55             Image JavaDoc img = null;
56             if (icon instanceof ImageIcon JavaDoc)
57                 img = ((ImageIcon JavaDoc) icon).getImage();
58             if (img != null)
59                 g.drawImage(img, 0, 0, d.width - 1, d.height - 1, graph);
60             super.paint(g);
61         }
62     }
63 }
Popular Tags