| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.bulenkov.iconloader.util; |
| 18 |
|
| 19 |
import javax.swing.*; |
| 20 |
import java.awt.*; |
| 21 |
import java.util.HashMap; |
| 22 |
import java.util.Map; |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
public class EmptyIcon implements Icon { |
| 28 |
private static final Map<Integer, Icon> cache = new HashMap<Integer, Icon>(); |
| 29 |
private final int width; |
| 30 |
private final int height; |
| 31 |
|
| 32 |
public static Icon create(int size) { |
| 33 |
Icon icon = cache.get(size); |
| 34 |
if (icon == null && size < 129) { |
| 35 |
cache.put(size, icon = new EmptyIcon(size, size)); |
| 36 |
} |
| 37 |
return icon == null ? new EmptyIcon(size, size) : icon; |
| 38 |
} |
| 39 |
|
| 40 |
public static Icon create(int width, int height) { |
| 41 |
return width == height ? create(width) : new EmptyIcon(width, height); |
| 42 |
} |
| 43 |
|
| 44 |
public static Icon create(Icon base) { |
| 45 |
return create(base.getIconWidth(), base.getIconHeight()); |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
public EmptyIcon(int size) { |
| 52 |
this(size, size); |
| 53 |
} |
| 54 |
|
| 55 |
public EmptyIcon(int width, int height) { |
| 56 |
this.width = width; |
| 57 |
this.height = height; |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
public EmptyIcon(Icon base) { |
| 64 |
this(base.getIconWidth(), base.getIconHeight()); |
| 65 |
} |
| 66 |
|
| 67 |
public int getIconWidth() { |
| 68 |
return width; |
| 69 |
} |
| 70 |
|
| 71 |
public int getIconHeight() { |
| 72 |
return height; |
| 73 |
} |
| 74 |
|
| 75 |
public void paintIcon(Component component, Graphics g, int i, int j) { |
| 76 |
} |
| 77 |
|
| 78 |
public boolean equals(Object o) { |
| 79 |
if (this == o) return true; |
| 80 |
if (!(o instanceof EmptyIcon)) return false; |
| 81 |
|
| 82 |
final EmptyIcon icon = (EmptyIcon) o; |
| 83 |
|
| 84 |
return height == icon.height && width == icon.width; |
| 85 |
|
| 86 |
} |
| 87 |
|
| 88 |
public int hashCode() { |
| 89 |
int sum = width + height; |
| 90 |
return sum * (sum + 1) / 2 + width; |
| 91 |
} |
| 92 |
} |