1 package org.columba.core.gui.base; 2 3 import java.awt.Component ; 4 import java.awt.Graphics ; 5 6 import javax.swing.Icon ; 7 8 public class IconDecorator implements Icon { 9 10 private Icon originalIcon; 11 12 private Icon decorationIcon; 13 14 private int xDiff; 15 16 private int yDiff; 17 18 private Location location; 19 20 public enum Location { 22 UPPER_LEFT, UPPER_RIGHT, LOWER_LEFT, LOWER_RIGHT 23 }; 24 25 public IconDecorator(Icon original, Icon decoration) { 26 this(original, decoration, Location.LOWER_LEFT); 27 } 28 29 public IconDecorator(Icon original, Icon decoration, Location loc) { 30 31 this.location = loc; 32 this.originalIcon = original; 33 this.decorationIcon = decoration; 34 if (decoration.getIconHeight() > original.getIconHeight() 35 || decoration.getIconWidth() > original.getIconWidth()) { 36 throw new IllegalArgumentException ( 37 "Decoration must be smaller than the original"); 38 } 39 this.xDiff = originalIcon.getIconWidth() 40 + decorationIcon.getIconWidth()/4; 41 this.yDiff = originalIcon.getIconHeight() - decorationIcon.getIconHeight(); 42 } 43 44 public int getIconHeight() { 45 return originalIcon.getIconHeight(); 46 } 47 48 public int getIconWidth() { 49 return originalIcon.getIconWidth(); 50 } 51 52 public void paintIcon(Component owner, Graphics g, int x, int y) { 53 originalIcon.paintIcon(owner, g, x, y); 55 56 int decorationX = x; 57 int decorationY = y; 58 if (location == Location.UPPER_RIGHT 60 || location == Location.LOWER_RIGHT) { 61 decorationX += xDiff; 62 } 63 if (location == Location.LOWER_LEFT || location == Location.LOWER_RIGHT) { 65 decorationY += yDiff; 66 } 67 68 decorationIcon.paintIcon(owner, g, decorationX, decorationY); 69 } 70 71 } | Popular Tags |