1 23 24 package de.progra.charting.render; 25 26 import java.awt.image.BufferedImage ; 27 import java.awt.Rectangle ; 28 import java.awt.Image ; 29 import java.awt.Graphics2D ; 30 import java.awt.Dimension ; 31 import java.awt.Color ; 32 33 43 public abstract class AbstractRenderer implements Renderer { 44 45 Rectangle bounds = new Rectangle (0, 0, 46 Integer.MAX_VALUE, 47 Integer.MAX_VALUE); 48 49 50 public AbstractRenderer() { 51 } 52 53 58 public void setBounds(Rectangle bounds) { 59 this.bounds = bounds; 60 } 61 62 67 public Rectangle getBounds() { 68 return bounds; 69 } 70 71 72 80 public void render(Graphics2D g) { 81 Dimension d = getPreferredSize(); 82 BufferedImage im = new BufferedImage ((int)d.width, 83 (int)d.height, 84 BufferedImage.TYPE_INT_RGB); 85 Graphics2D g2 = im.createGraphics(); 86 g2.setColor(Color.white); 87 g2.fillRect(0, 0, d.width, d.height); 88 g2.setColor(Color.black); 89 90 paintDefault(g2); 91 92 if(d.width > getBounds().getWidth() || 93 d.height > getBounds().getHeight()) { 94 Image scale = im.getScaledInstance((int)getBounds().getWidth(), 96 (int)getBounds().getHeight(), 97 Image.SCALE_SMOOTH); 98 99 g.drawImage(scale, 100 (int)getBounds().getX(), 101 (int)getBounds().getY(), 102 null); 103 } else 104 g.drawImage(im, (int)getBounds().getX(), 105 (int)getBounds().getY(), null); 106 } 107 108 114 public abstract void paintDefault(Graphics2D g); 115 } | Popular Tags |