1 30 31 package com.jgoodies.looks.common; 32 33 import java.awt.Component ; 34 import java.awt.Graphics ; 35 import java.awt.Image ; 36 import java.awt.Insets ; 37 38 import javax.swing.ImageIcon ; 39 import javax.swing.JComponent ; 40 import javax.swing.border.AbstractBorder ; 41 42 55 final class ShadowPopupBorder extends AbstractBorder { 56 57 60 private static final int SHADOW_SIZE = 5; 61 62 65 private static ShadowPopupBorder instance = new ShadowPopupBorder(); 66 67 70 private static Image shadow 71 = new ImageIcon (ShadowPopupBorder.class.getResource("shadow.png")).getImage(); 72 73 74 76 79 public static ShadowPopupBorder getInstance() { 80 return instance; 81 } 82 83 84 88 public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { 89 JComponent popup = (JComponent ) c; 91 Image hShadowBg = (Image ) popup.getClientProperty(ShadowPopupFactory.PROP_HORIZONTAL_BACKGROUND); 92 if (hShadowBg != null) { 93 g.drawImage(hShadowBg, x, y + height - 5, c); 94 } 95 Image vShadowBg = (Image ) popup.getClientProperty(ShadowPopupFactory.PROP_VERTICAL_BACKGROUND); 96 if (vShadowBg != null) { 97 g.drawImage(vShadowBg, x + width - 5, y, c); 98 } 99 100 g.drawImage(shadow, x + 5, y + height - 5, x + 10, y + height, 0, 6, 5, 11, null, c); 102 g.drawImage(shadow, x + 10, y + height - 5, x + width - 5, y + height, 5, 6, 6, 11, null, c); 103 g.drawImage(shadow, x + width - 5, y + 5, x + width, y + 10, 6, 0, 11, 5, null, c); 104 g.drawImage(shadow, x + width - 5, y + 10, x + width, y + height - 5, 6, 5, 11, 6, null, c); 105 g.drawImage(shadow, x + width - 5, y + height - 5, x + width, y + height, 6, 6, 11, 11, null, c); 106 } 107 108 109 112 public Insets getBorderInsets(Component c) { 113 return new Insets (0, 0, SHADOW_SIZE, SHADOW_SIZE); 114 } 115 116 117 123 public Insets getBorderInsets(Component c, Insets insets) { 124 insets.left = insets.top = 0; 125 insets.right = insets.bottom = SHADOW_SIZE; 126 return insets; 127 } 128 129 } 130 | Popular Tags |