| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
package org.dishevelled.iconbundle.tango; |
| 25 | |
|
| 26 | |
import java.awt.Image; |
| 27 | |
import java.awt.Color; |
| 28 | |
import java.awt.Component; |
| 29 | |
|
| 30 | |
import java.awt.image.BufferedImage; |
| 31 | |
|
| 32 | |
import java.net.URL; |
| 33 | |
|
| 34 | |
import javax.imageio.ImageIO; |
| 35 | |
|
| 36 | |
import javax.swing.UIManager; |
| 37 | |
|
| 38 | |
import org.dishevelled.iconbundle.IconSize; |
| 39 | |
import org.dishevelled.iconbundle.IconState; |
| 40 | |
import org.dishevelled.iconbundle.IconBundle; |
| 41 | |
import org.dishevelled.iconbundle.IconTextDirection; |
| 42 | |
|
| 43 | |
import org.dishevelled.iconbundle.impl.IconBundleUtils; |
| 44 | |
|
| 45 | |
import org.dishevelled.iconbundle.impl.svg.SVGIconBundleUtils; |
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
final class TangoProjectIconBundle |
| 53 | |
implements IconBundle |
| 54 | |
{ |
| 55 | |
|
| 56 | |
private static final String BASE_URL = "/org/freedesktop/tango/"; |
| 57 | |
|
| 58 | |
|
| 59 | |
private final String context; |
| 60 | |
|
| 61 | |
|
| 62 | |
private final String name; |
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
TangoProjectIconBundle(final String context, |
| 73 | |
final String name) |
| 74 | 0 | { |
| 75 | 0 | this.context = context; |
| 76 | 0 | this.name = name; |
| 77 | 0 | } |
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
public Image getImage(final Component component, |
| 82 | |
final IconTextDirection direction, |
| 83 | |
final IconState state, |
| 84 | |
final IconSize size) |
| 85 | |
{ |
| 86 | 0 | if (direction == null) |
| 87 | |
{ |
| 88 | 0 | throw new IllegalArgumentException("direction must not be null"); |
| 89 | |
} |
| 90 | 0 | if (state == null) |
| 91 | |
{ |
| 92 | 0 | throw new IllegalArgumentException("state must not be null"); |
| 93 | |
} |
| 94 | 0 | if (size == null) |
| 95 | |
{ |
| 96 | 0 | throw new IllegalArgumentException("size must not be null"); |
| 97 | |
} |
| 98 | |
|
| 99 | 0 | URL url = null; |
| 100 | 0 | BufferedImage image = null; |
| 101 | |
|
| 102 | 0 | if (TangoProject.EXTRA_SMALL.equals(size) || TangoProject.SMALL.equals(size) || TangoProject.MEDIUM.equals(size)) |
| 103 | |
{ |
| 104 | |
try |
| 105 | |
{ |
| 106 | 0 | url = this.getClass().getResource(BASE_URL + size.toString() + "/" + context + "/" + name + ".png"); |
| 107 | 0 | image = ImageIO.read(url); |
| 108 | |
} |
| 109 | 0 | catch (Exception e) |
| 110 | |
{ |
| 111 | 0 | System.err.println("couldn't find image for url=" + url); |
| 112 | 0 | System.err.println(" or=" + BASE_URL + size.toString() + "/" + context + "/" + name + ".png"); |
| 113 | 0 | e.printStackTrace(); |
| 114 | |
|
| 115 | 0 | } |
| 116 | |
} |
| 117 | |
else |
| 118 | |
{ |
| 119 | 0 | int width = size.getWidth(); |
| 120 | 0 | int height = size.getHeight(); |
| 121 | |
|
| 122 | 0 | url = this.getClass().getResource(BASE_URL + "scalable/" + context + "/" + name + ".svg"); |
| 123 | 0 | image = SVGIconBundleUtils.readSVG(url, width, height); |
| 124 | |
} |
| 125 | |
|
| 126 | 0 | if (IconState.ACTIVE == state) |
| 127 | |
{ |
| 128 | 0 | return IconBundleUtils.makeActive(image); |
| 129 | |
} |
| 130 | 0 | else if (IconState.MOUSEOVER == state) |
| 131 | |
{ |
| 132 | 0 | return IconBundleUtils.makeMouseover(image); |
| 133 | |
} |
| 134 | 0 | else if (IconState.SELECTED == state) |
| 135 | |
{ |
| 136 | 0 | Color selectionColor = UIManager.getColor("List.selectionBackground"); |
| 137 | 0 | return IconBundleUtils.makeSelected(image, selectionColor); |
| 138 | |
} |
| 139 | 0 | else if (IconState.SELECTED_MOUSEOVER == state) |
| 140 | |
{ |
| 141 | 0 | Color selectionColor = UIManager.getColor("List.selectionBackground"); |
| 142 | 0 | return IconBundleUtils.makeSelectedMouseover(image, selectionColor); |
| 143 | |
} |
| 144 | 0 | else if (IconState.DRAGGING == state) |
| 145 | |
{ |
| 146 | 0 | return IconBundleUtils.makeDragging(image); |
| 147 | |
} |
| 148 | 0 | else if (IconState.DISABLED == state) |
| 149 | |
{ |
| 150 | 0 | return IconBundleUtils.makeDisabled(image); |
| 151 | |
} |
| 152 | |
else |
| 153 | |
{ |
| 154 | 0 | return image; |
| 155 | |
} |
| 156 | |
} |
| 157 | |
} |