1 21 package com.sshtools.ui.swing; 22 23 import java.awt.Component ; 24 import java.awt.Graphics ; 25 26 import javax.swing.Icon ; 27 import javax.swing.SwingConstants ; 28 29 38 public class OverlayIcon implements Icon { 39 40 42 private Icon icon; 43 private Icon overlayIcon; 44 private int position; 45 46 53 public OverlayIcon(Icon overlayIcon, Icon icon, int position) { 54 this.icon = icon; 55 this.overlayIcon = overlayIcon; 56 this.position = position; 57 } 58 59 64 public Icon getOverlayIcon() { 65 return overlayIcon; 66 } 67 68 71 public int getIconHeight() { 72 return (icon == null) ? 16 : icon.getIconHeight(); 73 } 74 75 78 public int getIconWidth() { 79 return (icon == null) ? 16 : icon.getIconWidth(); 80 } 81 82 85 public void paintIcon(Component c, Graphics g, int x, int y) { 86 if (icon != null) { 87 icon.paintIcon(c, g, x, y); 88 89 switch (position) { 90 case SwingConstants.NORTH_WEST: 92 overlayIcon.paintIcon(c, g, x, y); 93 break; 94 case SwingConstants.SOUTH_WEST: 95 overlayIcon.paintIcon(c, g, x, (y + icon.getIconHeight()) - overlayIcon.getIconHeight()); 96 break; 97 case SwingConstants.NORTH_EAST: 98 overlayIcon.paintIcon(c, g, (x + icon.getIconWidth()) - overlayIcon.getIconWidth(), y); 99 default: 100 overlayIcon.paintIcon(c, g, (x + icon.getIconWidth()) - overlayIcon.getIconWidth(), (y + icon.getIconHeight()) 101 - overlayIcon.getIconHeight()); 102 } 103 } 104 } 105 } 106 | Popular Tags |