1 package org.columba.core.gui.base; 2 3 import java.awt.Color ; 4 import java.awt.Component ; 5 import java.awt.Graphics ; 6 import java.awt.Insets ; 7 8 import javax.swing.UIManager ; 9 import javax.swing.border.Border ; 10 11 public class ShadowBorder implements Border { 12 private Insets insets; 13 14 public ShadowBorder() { 15 insets = new Insets (2, 2, 4, 4); 16 } 17 18 public Insets getBorderInsets(Component c) { 19 return insets; 20 } 21 22 public boolean isBorderOpaque() { 23 return true; 24 } 25 26 public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { 27 Color bg = c.getBackground(); 28 if (c.getParent() != null) 29 bg = c.getParent().getBackground(); 30 Color mid = bg.darker(); 31 Color rect = UIManager.getColor("control").darker(); 32 Color edge = average(mid, bg); 33 34 39 w-=3; 40 h-=3; 41 g.setColor(rect); 42 int ovalHeight = 3; 44 int ovalWidth = 3; 45 g.drawLine(x, y + ovalHeight, x, y +h); 47 g.drawArc(x, y, 2 * ovalWidth, 2 * ovalHeight, 180, -90); 48 g.drawLine(x + ovalWidth, y, x + w - ovalWidth, y); 50 g.drawArc(x + w - 2 * ovalWidth, y, 2 * ovalWidth, 2 * ovalHeight, 90, 51 -90); 52 g.drawLine(x + w, y + ovalHeight, x + w, y + h); 54 g.drawLine(x, y + h, x + w, y + h); 56 57 w+=1; 58 h+=1; 59 g.setColor(edge); 61 g.drawLine(x+1, h, x+w, h ); 63 g.drawLine(x+w, y+ovalHeight+1, x+w , y+h); 65 74 } 75 76 private static Color average(Color c1, Color c2) { 77 int red = c1.getRed() + (c2.getRed() - c1.getRed()) / 2; 78 int green = c1.getGreen() + (c2.getGreen() - c1.getGreen()) / 2; 79 int blue = c1.getBlue() + (c2.getBlue() - c1.getBlue()) / 2; 80 return new Color (red, green, blue); 81 } 82 } | Popular Tags |