001: /*
002: * Gruntspud
003: *
004: * Copyright (C) 2002 Brett Smith.
005: *
006: * Written by: Brett Smith <t_magicthize@users.sourceforge.net>
007: *
008: * This program is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU Library General Public License
010: * as published by the Free Software Foundation; either version 2 of
011: * the License, or (at your option) any later version.
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU Library General Public License for more details.
016: *
017: * You should have received a copy of the GNU Library General Public
018: * License along with this program; if not, write to the Free Software
019: * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
020: */
021:
022: package gruntspud.ui.icons;
023:
024: import java.awt.Component;
025: import java.awt.Graphics;
026: import java.awt.Insets;
027:
028: import javax.swing.Icon;
029:
030: /**
031: * DOCUMENT ME!
032: *
033: * @author $author$
034: */
035: public class CompoundIcon implements Icon {
036: private Icon icon1;
037: private Icon icon2;
038: private int gap;
039: private Insets margin;
040:
041: /**
042: * Creates a new CompoundIcon object.
043: *
044: * @param icon1 DOCUMENT ME!
045: * @param icon2 DOCUMENT ME!
046: */
047: public CompoundIcon(Icon icon1, Icon icon2) {
048: this ();
049: setIcon1(icon1);
050: setIcon2(icon2);
051: margin = new Insets(0, 0, 0, 0);
052: }
053:
054: /**
055: * Creates a new CompoundIcon object.
056: */
057: public CompoundIcon() {
058: gap = 2;
059: }
060:
061: public void setGap(int gap) {
062: this .gap = gap;
063: }
064:
065: public void setMargin(Insets margin) {
066: this .margin = margin;
067: }
068:
069: /**
070: * DOCUMENT ME!
071: *
072: * @param c DOCUMENT ME!
073: * @param g DOCUMENT ME!
074: * @param x DOCUMENT ME!
075: * @param y DOCUMENT ME!
076: */
077: public void paintIcon(Component c, Graphics g, int x, int y) {
078: if ((icon1 != null) && (icon2 != null)) {
079: icon1.paintIcon(c, g, 0 + margin.left,
080: ((getIconHeight() - icon1.getIconHeight()) / 2)
081: + margin.top);
082: icon2.paintIcon(c, g, icon1.getIconWidth() + gap
083: + margin.left, ((getIconHeight() - icon2
084: .getIconHeight()) / 2)
085: + margin.top);
086: }
087: }
088:
089: /**
090: * DOCUMENT ME!
091: *
092: * @param icon1 DOCUMENT ME!
093: */
094: public void setIcon1(Icon icon1) {
095: this .icon1 = icon1;
096: }
097:
098: /**
099: * DOCUMENT ME!
100: *
101: * @param icon2 DOCUMENT ME!
102: */
103: public void setIcon2(Icon icon2) {
104: this .icon2 = icon2;
105: }
106:
107: /**
108: * DOCUMENT ME!
109: *
110: * @return DOCUMENT ME!
111: */
112: public int getIconWidth() {
113: return (((icon1 == null) || (icon2 == null)) ? 16 : (icon1
114: .getIconWidth()
115: + gap + icon2.getIconWidth()))
116: + margin.left + margin.right;
117: }
118:
119: /**
120: * DOCUMENT ME!
121: *
122: * @return DOCUMENT ME!
123: */
124: public int getIconHeight() {
125: return (((icon1 == null) || (icon2 == null)) ? 16 : Math.max(
126: icon1.getIconHeight(), icon2.getIconHeight()))
127: + margin.top + margin.bottom;
128: }
129: }
|