1 14 package org.netbeans.swing.plaf.aqua; 15 16 import java.awt.Color ; 17 import java.awt.Component ; 18 import java.awt.Graphics ; 19 import java.awt.Graphics2D ; 20 import java.awt.Insets ; 21 import java.awt.Shape ; 22 import java.awt.geom.AffineTransform ; 23 import java.awt.geom.GeneralPath ; 24 import java.awt.image.BufferedImage ; 25 import java.util.HashMap ; 26 import java.util.Map ; 27 import javax.imageio.ImageIO ; 28 import javax.swing.border.Border ; 29 30 36 public class FakeDropShadowBorder implements Border { 37 38 public FakeDropShadowBorder() { 39 } 40 41 private static final int WIDTH = 17; 42 private static final int HEIGHT = 17; 43 public static final int ARC = 12; 44 public Insets getBorderInsets(Component c) { 45 return new Insets (1, 13, 25, 13); 46 } 47 48 54 public void fillBackground (Component c, Graphics2D gg,int x, int y, int w, int h) { 55 Shape clip = gg.getClip(); 56 gg.setColor (Color.WHITE); 57 Insets ins = getBorderInsets(c); 58 int bottom = h - ins.bottom + 6; int bottomOffCurve = bottom - 20; int top = ins.top + 3; int left = ins.left - 2; int shoulderTop = top + 16; int shoulderTopOffCurve = shoulderTop + 9; int rightOffCurve = x + w - 34; int right = rightOffCurve + 24; 78 GeneralPath gp = new GeneralPath (); 82 gp.moveTo (left, bottomOffCurve); 85 gp.lineTo (left, shoulderTopOffCurve); 86 gp.curveTo (left, shoulderTop, left + 6, shoulderTop, left + 8, shoulderTop + 1); 88 gp.curveTo (left + 11, top, left + 19, top + 1, left + 25, top); 90 gp.lineTo (rightOffCurve, top); 92 gp.curveTo (rightOffCurve + 6, top, rightOffCurve + 17, top + 5, rightOffCurve + 16, shoulderTop); 94 gp.curveTo (right - 4, shoulderTop + 1, right, shoulderTop, right, shoulderTop + 9); 96 gp.lineTo (right, bottomOffCurve); 98 gp.curveTo (right + 1, bottom, right - 1, bottom + 1, right - 12, bottom); 100 gp.lineTo (left + 14, bottom); 102 gp.curveTo (left + 1, bottom, left - 1, bottom, left, bottomOffCurve); 104 gp.closePath(); 105 gg.fill(gp); 109 } 110 111 public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { 112 Graphics2D gg = (Graphics2D ) g; 113 fillBackground (c, gg, x, y, w, h); 116 BufferedImage b = getImage(upLeft); 118 int yoff = b.getHeight(); 119 int topL = b.getWidth(); 120 draw(gg, b, x, y); 121 122 b = getImage(downRight); 123 draw(gg, b, x + w - b.getWidth(), y + h - b.getHeight()); 124 int woff = b.getWidth(); 125 126 b = getImage(upRight); 127 draw(gg, b, x + w - b.getWidth(), y); 128 int topR = b.getWidth(); 129 130 b = getImage(downLeft); 131 int hoff = b.getHeight(); 132 int xoff = b.getWidth(); 133 draw(gg, b, x, y + h - b.getHeight()); 134 135 b = getImage (leftEdge); 136 tileVertical (x, y, yoff, hoff, h, b, gg); 137 138 b = getImage (rightEdge); 139 tileVertical (x + w - (b.getWidth()), y, yoff, hoff, h, b, gg); 140 141 b = getImage (bottom); 142 tileHorizontal(x, y + h - (b.getHeight() + 0), xoff, woff, w, b, gg); 143 144 b = getImage (top); 145 tileHorizontal(x, y, xoff, woff, w, b, gg); 146 147 } 148 149 private final Color xpar = new Color (255, 255, 255, 0); 150 private void draw(Graphics2D g, BufferedImage b, int x, int y) { 151 g.setColor (xpar); 152 g.fillRect (x, y, b.getWidth(), b.getHeight()); 153 g.drawRenderedImage(b, AffineTransform.getTranslateInstance(x,y)); 154 } 155 156 private void tileVertical (int x, int y, int yoff, int hoff, int h, BufferedImage img, Graphics2D g) { 157 h -= (hoff + yoff); 158 int times = h / img.getHeight(); 159 int rem = h % img.getHeight(); 160 y = y + yoff; 161 162 for (int i=0; i < times; i++) { 163 g.drawRenderedImage (img, AffineTransform.getTranslateInstance(x, y)); 164 y += img.getHeight(); 165 } 166 if (rem > 0) { 167 img = img.getSubimage(0, 0, img.getWidth(), rem); 168 g.drawRenderedImage(img, AffineTransform.getTranslateInstance(x,y)); 169 } 170 } 171 172 private void tileHorizontal (int x, int y, int xoff, int woff, int w, BufferedImage img, Graphics2D g) { 173 w -= (woff + xoff); 174 int times = w / img.getWidth(); 175 int rem = w % img.getWidth(); 176 x += xoff; 177 178 for (int i=0; i < times; i++) { 179 draw (g, img, x, y); 180 x += img.getWidth(); 181 } 182 if (rem > 0) { 183 img = img.getSubimage(0, 0, rem, img.getHeight()); 184 draw (g, img, x, y); 185 } 186 } 187 188 189 public boolean isBorderOpaque() { 190 return false; 191 } 192 193 private static final String upLeft = "upLeft.png"; private static final String downRight = "downRight.png"; private static final String downLeft = "upRight.png"; private static final String upRight = "downLeft.png"; private static final String bottom = "bottom.png"; private static final String leftEdge = "leftEdge.png"; private static final String rightEdge = "rightEdge.png"; private static final String top = "top.png"; 201 202 private static Map <String , BufferedImage > imgs = new HashMap <String , BufferedImage >(); 205 private static BufferedImage getImage(String s) { 206 BufferedImage result = imgs.get(s); 207 if (result == null) { 208 Exception e1 = null; 209 try { 210 result = ImageIO.read( 211 FakeDropShadowBorder.class.getResourceAsStream(s)); 212 } catch (Exception e) { 213 result = new BufferedImage (1, 1, BufferedImage.TYPE_INT_ARGB); 214 e1 = e; 215 } 216 imgs.put (s, result); 217 if (e1 != null) { 218 throw new IllegalStateException (e1); 219 } 220 } 221 return result; 222 } 223 } 224 | Popular Tags |