~ubuntu-branches/ubuntu/precise/triplea/precise

« back to all changes in this revision

Viewing changes to src/games/strategy/ui/OverlayIcon.java

  • Committer: Package Import Robot
  • Author(s): Scott Howard
  • Date: 2011-11-11 21:40:11 UTC
  • Revision ID: package-import@ubuntu.com-20111111214011-sehf2rwat36o2xqf
Tags: upstream-1.3.2.2
ImportĀ upstreamĀ versionĀ 1.3.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package games.strategy.ui;
 
2
 
 
3
import java.awt.Component;
 
4
import java.awt.Graphics;
 
5
 
 
6
import javax.swing.Icon;
 
7
 
 
8
/**
 
9
 * Make one icon from two. 
 
10
 */
 
11
public class OverlayIcon implements Icon
 
12
{
 
13
    private final Icon m_back;
 
14
    private final Icon m_front;
 
15
    private final int m_x_offset;
 
16
    private final int m_y_offset;
 
17
 
 
18
    /**
 
19
     * Create a composite icon by overlaying the front icon over the back icon.
 
20
     * @param back back icon
 
21
     * @param front front icon
 
22
     * @param x, y position of front icon relative to back icon.
 
23
     */
 
24
    public OverlayIcon(Icon back, Icon front, int x, int y) {
 
25
        m_back = back;
 
26
        m_front = front;
 
27
        m_x_offset = x;
 
28
        m_y_offset = y;
 
29
    }
 
30
    
 
31
    public int getIconHeight()
 
32
    {
 
33
        return m_back.getIconHeight() > (m_front.getIconHeight() + m_y_offset) ?
 
34
                m_back.getIconHeight() : (m_front.getIconHeight() + m_y_offset);
 
35
    }
 
36
 
 
37
    public int getIconWidth()
 
38
    {
 
39
        return m_back.getIconWidth() > (m_front.getIconWidth() + m_x_offset) ?
 
40
                m_back.getIconWidth() : (m_front.getIconWidth() + m_x_offset);
 
41
    }
 
42
 
 
43
    public void paintIcon(Component c, Graphics g, int x, int y)
 
44
    {
 
45
        m_back.paintIcon(c, g, x, y);
 
46
        m_front.paintIcon(c, g, x + m_x_offset, y + m_y_offset);
 
47
    }
 
48
 
 
49
}