View Javadoc
1   /*
2    * Copyright (c) 2005, The JUNG Authors
3    * All rights reserved.
4    *
5    * This software is open-source under the BSD license; see either "license.txt"
6    * or https://github.com/jrtom/jung/blob/master/LICENSE for a description.
7    *
8    * Created on Jul 11, 2005
9    */
10  
11  package edu.uci.ics.jung.visualization.transform.shape;
12  
13  import java.awt.Component;
14  import java.awt.Graphics2D;
15  import java.awt.Shape;
16  
17  import javax.swing.CellRendererPane;
18  import javax.swing.Icon;
19  
20  
21  /**
22   * an extendion of Graphics2DWrapper that adds enhanced
23   * methods for drawing icons and components
24   * 
25   * @see TransformingGraphics as an example subclass
26   * 
27   * @author Tom Nelson 
28   *
29   *
30   */
31  public class GraphicsDecorator extends Graphics2DWrapper {
32      
33      public GraphicsDecorator() {
34          this(null);
35      }
36      public GraphicsDecorator(Graphics2D delegate) {
37          super(delegate);
38      }
39      
40      public void draw(Icon icon, Component c, Shape clip, int x, int y) {
41      	int w = icon.getIconWidth();
42      	int h = icon.getIconHeight();
43      	icon.paintIcon(c, delegate, x-w/2, y-h/2);
44      }
45      
46      public void draw(Component c, CellRendererPane rendererPane, 
47      		int x, int y, int w, int h, boolean shouldValidate) {
48      	rendererPane.paintComponent(delegate, c, c.getParent(), x, y, w, h, shouldValidate);
49      }
50  }