001 /*
002 * Copyright 2002-2007 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.springframework.richclient.image;
017
018 import java.awt.Component;
019 import java.awt.Graphics;
020
021 import javax.swing.GrayFilter;
022 import javax.swing.Icon;
023 import javax.swing.ImageIcon;
024
025 /**
026 * Code taken from
027 * http://www.jroller.com/santhosh/entry/beautify_swing_applications_toolbar_with
028 *
029 * @author Santhosh Kumar
030 */
031 public class ShadowedIcon implements Icon {
032 private int shadowWidth = 2;
033
034 private int shadowHeight = 2;
035
036 private Icon icon, shadow;
037
038 public ShadowedIcon(Icon icon) {
039 this.icon = icon;
040 shadow = new ImageIcon(GrayFilter.createDisabledImage(((ImageIcon) icon).getImage()));
041 }
042
043 public ShadowedIcon(Icon icon, int shadowWidth, int shadowHeight) {
044 this(icon);
045 this.shadowWidth = shadowWidth;
046 this.shadowHeight = shadowHeight;
047 }
048
049 public int getIconHeight() {
050 return icon.getIconWidth() + shadowWidth;
051 }
052
053 public int getIconWidth() {
054 return icon.getIconHeight() + shadowHeight;
055 }
056
057 public void paintIcon(Component c, Graphics g, int x, int y) {
058 shadow.paintIcon(c, g, x + shadowWidth, y + shadowHeight);
059 icon.paintIcon(c, g, x, y);
060 }
061 }