1 41 package org.jfree.ui; 42 43 import java.awt.Graphics ; 44 import java.awt.Graphics2D ; 45 import java.awt.Dimension ; 46 import java.awt.geom.Rectangle2D ; 47 import javax.swing.JPanel ; 48 49 import org.jfree.util.Log; 50 51 56 public class DrawablePanel extends JPanel 57 { 58 private Drawable drawable; 59 60 public DrawablePanel() 61 { 62 setOpaque(false); 63 } 64 65 public Drawable getDrawable() 66 { 67 return drawable; 68 } 69 70 public void setDrawable(final Drawable drawable) 71 { 72 this.drawable = drawable; 73 revalidate(); 74 repaint(); 75 } 76 77 87 public Dimension getPreferredSize() 88 { 89 if (drawable instanceof ExtendedDrawable) 90 { 91 final ExtendedDrawable ed = (ExtendedDrawable) drawable; 92 return ed.getPreferredSize(); 93 } 94 return super.getPreferredSize(); 95 } 96 97 107 public Dimension getMinimumSize() 108 { 109 if (drawable instanceof ExtendedDrawable) 110 { 111 final ExtendedDrawable ed = (ExtendedDrawable) drawable; 112 return ed.getPreferredSize(); 113 } 114 return super.getMinimumSize(); 115 } 116 117 132 public boolean isOpaque() 133 { 134 if (drawable == null) 135 { 136 return false; 137 } 138 return super.isOpaque(); 139 } 140 141 165 protected void paintComponent(Graphics g) 166 { 167 super.paintComponent(g); 168 if (drawable == null) 169 { 170 return; 171 } 172 173 final Graphics2D g2 = (Graphics2D ) g.create 174 (0, 0, getWidth(), getHeight()); 175 176 drawable.draw(g2, new Rectangle2D.Double (0, 0, getWidth(), getHeight())); 177 g2.dispose(); 178 } 179 180 } 181 | Popular Tags |