1 30 31 package com.jgoodies.animation.components; 32 33 import java.awt.Color ; 34 import java.awt.Graphics ; 35 import java.awt.Graphics2D ; 36 import java.awt.Insets ; 37 import java.awt.RenderingHints ; 38 import java.awt.geom.Point2D ; 39 40 import javax.swing.JComponent ; 41 42 import com.jgoodies.animation.renderer.FanRenderer; 43 44 53 public final class FanComponent extends JComponent { 54 55 private final FanRenderer renderer; 56 57 59 67 public FanComponent(int triangleCount, Color baseColor) { 68 this.renderer = new FanRenderer(triangleCount, baseColor); 69 } 70 71 73 public Point2D getOrigin() { 74 return renderer.getOrigin(); 75 } 76 77 public double getRotation() { 78 return renderer.getRotation(); 79 } 80 81 86 public void setOrigin(Point2D origin) { 87 renderer.setOrigin(origin); 88 repaint(); 89 } 90 91 96 public void setRotation(double rotation) { 97 renderer.setRotation(rotation); 98 repaint(); 99 } 100 101 107 public void paintComponent(Graphics g) { 108 Graphics2D g2 = (Graphics2D ) g; 109 110 g2.setRenderingHint( 111 RenderingHints.KEY_ANTIALIASING, 112 RenderingHints.VALUE_ANTIALIAS_ON); 113 g2.setRenderingHint( 114 RenderingHints.KEY_RENDERING, 115 RenderingHints.VALUE_RENDER_QUALITY); 116 117 Insets insets = getInsets(); 118 int x = insets.left; 119 int y = insets.top; 120 int w = getWidth() - x - insets.right; 121 int h = getHeight() - y - insets.bottom; 122 g2.translate(x, y); 123 renderer.render(g2, w, h); 124 g2.translate(-x, -y); 125 } 126 127 } | Popular Tags |