01 /* This file is part of the project "Hilbert II" - http://www.qedeq.org
02 *
03 * Copyright 2000-2013, Michael Meyling <mime@qedeq.org>.
04 *
05 * "Hilbert II" is free software; you can redistribute
06 * it and/or modify it under the terms of the GNU General Public
07 * License as published by the Free Software Foundation; either
08 * version 2 of the License, or (at your option) any later version.
09 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16 package org.qedeq.gui.se.util;
17
18 import java.awt.Component;
19 import java.awt.Graphics;
20 import java.util.ArrayList;
21 import java.util.List;
22
23 import javax.swing.ImageIcon;
24
25 /**
26 * Stack various icons. This enables us to decorate a basic icon.
27 *
28 * @author Michael Meyling
29 */
30 public class DecoratedIcon extends ImageIcon {
31
32 /** This is the basic icon. */
33 private ImageIcon basic;
34
35 /** List of decorator icons. */
36 private List overlays;
37
38 /**
39 * Constructor.
40 *
41 * @param basic Basic icon.
42 */
43 public DecoratedIcon(final ImageIcon basic) {
44 super(basic.getImage());
45 this.basic = basic;
46 this.overlays = new ArrayList();
47 }
48
49 /**
50 * Decorate basic icon with this one.
51 *
52 * @param decorator Decorator icon.
53 */
54 public void decorate(final ImageIcon decorator) {
55 overlays.add(decorator);
56 }
57
58 public synchronized void paintIcon(final Component c, final Graphics g, final int x,
59 final int y) {
60 basic.paintIcon(c, g, x, y);
61 for (int i = 0; i < overlays.size(); i++) {
62 final ImageIcon icon = (ImageIcon) overlays.get(i);
63 icon.paintIcon(c, g, x, y);
64 }
65 }
66
67 }
|