01: /*
02: * @(#)ShiftedIcon.java 1.0 May 12, 2006
03: *
04: * Copyright (c) 2006 Werner Randelshofer
05: * Staldenmattweg 2, CH-6405 Immensee, Switzerland
06: * All rights reserved.
07: *
08: * This software is the confidential and proprietary information of
09: * Werner Randelshofer. ("Confidential Information"). You shall not
10: * disclose such Confidential Information and shall use it only in
11: * accordance with the terms of the license agreement you entered into
12: * with Werner Randelshofer.
13: */
14:
15: package contrib.ch.randelshofer.quaqua.util;
16:
17: import java.awt.*;
18: import javax.swing.*;
19:
20: /**
21: * ShiftedIcon renders a target icon at a different location and can return
22: * different width and height values than the target.
23: *
24: * @author Werner Randelshofer.
25: * @version 1.0 May 12, 2006 Created.
26: */
27: public class ShiftedIcon implements Icon {
28: private Icon target;
29: private Rectangle shift;
30:
31: /** Creates a new instance. */
32: public ShiftedIcon(Icon target, Point shift) {
33: this .target = target;
34: this .shift = new Rectangle(shift.x, shift.y, target
35: .getIconWidth(), target.getIconHeight());
36: }
37:
38: public ShiftedIcon(Icon target, Rectangle shiftAndSize) {
39: this .target = target;
40: this .shift = shiftAndSize;
41: }
42:
43: public void paintIcon(Component c, Graphics g, int x, int y) {
44: target.paintIcon(c, g, x + shift.x, y + shift.y);
45: }
46:
47: public int getIconWidth() {
48: return shift.width;
49: }
50:
51: public int getIconHeight() {
52: return shift.height;
53: }
54:
55: }
|