2
* Copyright (c) 2001-2005 JGoodies Karsten Lentzsch. All Rights Reserved.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions are met:
7
* o Redistributions of source code must retain the above copyright notice,
8
* this list of conditions and the following disclaimer.
10
* o Redistributions in binary form must reproduce the above copyright notice,
11
* this list of conditions and the following disclaimer in the documentation
12
* and/or other materials provided with the distribution.
14
* o Neither the name of JGoodies Karsten Lentzsch nor the names of
15
* its contributors may be used to endorse or promote products derived
16
* from this software without specific prior written permission.
18
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
22
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
27
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
package org.pushingpixels.lafwidget.utils;
35
import javax.swing.ImageIcon;
36
import javax.swing.border.AbstractBorder;
39
* A border with a drop shadow intended to be used as the outer border of
40
* popups. Can paint the screen background if used with heavy-weight popup
43
* @author Stefan Matthias Aust
44
* @author Karsten Lentzsch
45
* @author Andrej Golovnin
48
* see ShadowPopupFactory
50
public final class ShadowPopupBorder extends AbstractBorder {
53
* The drop shadow needs 5 pixels at the bottom and the right hand side.
55
private static final int SHADOW_SIZE = 5;
58
* The singleton instance used to draw all borders.
60
private static ShadowPopupBorder instance = new ShadowPopupBorder();
63
* The drop shadow is created from a PNG image with 8 bit alpha channel.
65
private static Image shadow = new ImageIcon(ShadowPopupBorder.class
66
.getResource("shadow.png")).getImage();
68
// Instance Creation *****************************************************
71
* Returns the singleton instance used to draw all borders.
73
public static ShadowPopupBorder getInstance() {
78
* Paints the border for the specified component with the specified position
82
public void paintBorder(Component c, Graphics g, int x, int y, int width,
84
// fake drop shadow effect in case of heavy weight popups
85
// JComponent popup = (JComponent) c;
86
// Image hShadowBg = (Image)
87
// popup.getClientProperty(ShadowPopupFactory.PROP_HORIZONTAL_BACKGROUND);
88
// if (hShadowBg != null) {
89
// g.drawImage(hShadowBg, x, y + height - 5, c);
91
// Image vShadowBg = (Image)
92
// popup.getClientProperty(ShadowPopupFactory.PROP_VERTICAL_BACKGROUND);
93
// if (vShadowBg != null) {
94
// g.drawImage(vShadowBg, x + width - 5, y, c);
98
g.drawImage(shadow, x + 5, y + height - 5, x + 10, y + height, 0, 6, 5,
100
g.drawImage(shadow, x + 10, y + height - 5, x + width - 5, y + height,
101
5, 6, 6, 11, null, c);
102
g.drawImage(shadow, x + width - 5, y + 5, x + width, y + 10, 6, 0, 11,
104
g.drawImage(shadow, x + width - 5, y + 10, x + width, y + height - 5,
105
6, 5, 11, 6, null, c);
106
g.drawImage(shadow, x + width - 5, y + height - 5, x + width, y
107
+ height, 6, 6, 11, 11, null, c);
111
* Returns the insets of the border.
114
public Insets getBorderInsets(Component c) {
115
return new Insets(0, 0, SHADOW_SIZE, SHADOW_SIZE);
119
* Reinitializes the insets parameter with this Border's current Insets.
122
* the component for which this border insets value applies
124
* the object to be reinitialized
125
* @return the <code>insets</code> object
128
public Insets getBorderInsets(Component c, Insets insets) {
129
insets.left = insets.top = 0;
130
insets.right = insets.bottom = SHADOW_SIZE;