1 18 package org.apache.batik.ext.awt.image.spi; 19 20 import java.awt.Color ; 21 import java.awt.Graphics2D ; 22 import java.awt.image.BufferedImage ; 23 import java.util.Hashtable ; 24 25 import org.apache.batik.ext.awt.image.GraphicsUtil; 26 import org.apache.batik.ext.awt.image.renderable.Filter; 27 import org.apache.batik.ext.awt.image.renderable.RedRable; 28 import org.apache.batik.i18n.LocalizableSupport; 29 30 public class DefaultBrokenLinkProvider 31 implements BrokenLinkProvider { 32 33 static Filter brokenLinkImg = null; 34 35 public static String formatMessage(Object base, 36 String code, 37 Object [] params) { 38 String res = (base.getClass().getPackage().getName() + 39 ".resources.Messages"); 40 ClassLoader cl = null; 42 try { 43 cl = DefaultBrokenLinkProvider.class.getClassLoader(); 45 cl = base.getClass().getClassLoader(); 48 } catch (SecurityException se) { 49 } 50 LocalizableSupport ls = new LocalizableSupport(res, cl); 51 return ls.formatMessage(code, params); 52 } 53 54 public Filter getBrokenLinkImage(Object base, 55 String code, Object [] params) { 56 synchronized (DefaultBrokenLinkProvider.class) { 57 if (brokenLinkImg != null) 58 return brokenLinkImg; 59 60 BufferedImage bi; 61 bi = new BufferedImage (100, 100, BufferedImage.TYPE_INT_ARGB); 62 63 Hashtable ht = new Hashtable (); 66 ht.put(BROKEN_LINK_PROPERTY, 67 formatMessage(base, code, params)); 68 bi = new BufferedImage (bi.getColorModel(), bi.getRaster(), 69 bi.isAlphaPremultiplied(), 70 ht); 71 Graphics2D g2d = bi.createGraphics(); 72 73 g2d.setColor(new Color (255,255,255,190)); 74 g2d.fillRect(0, 0, 100, 100); 75 g2d.setColor(Color.black); 76 g2d.drawRect(2, 2, 96, 96); 77 g2d.drawString("Broken Image", 6, 50); 78 g2d.dispose(); 79 80 brokenLinkImg = new RedRable(GraphicsUtil.wrap(bi)); 81 return brokenLinkImg; 82 } 83 } 84 } 85 | Popular Tags |