| 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.impl; |
| 25 | |
|
| 26 | |
import java.io.File; |
| 27 | |
|
| 28 | |
import java.net.URL; |
| 29 | |
|
| 30 | |
import java.awt.Image; |
| 31 | |
import java.awt.Color; |
| 32 | |
import java.awt.Component; |
| 33 | |
|
| 34 | |
import java.awt.image.BufferedImage; |
| 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 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
public final class SVGIconBundle |
| 50 | |
implements IconBundle |
| 51 | |
{ |
| 52 | |
|
| 53 | |
private URL url; |
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
public SVGIconBundle(final File file) |
| 63 | 2 | { |
| 64 | 2 | if (file == null) |
| 65 | |
{ |
| 66 | 1 | throw new IllegalArgumentException("file must not be null"); |
| 67 | |
} |
| 68 | |
|
| 69 | |
try |
| 70 | |
{ |
| 71 | 1 | url = new URL("file://" + file.getAbsolutePath()); |
| 72 | |
} |
| 73 | 0 | catch (Exception e) |
| 74 | |
{ |
| 75 | 0 | throw new IllegalArgumentException("could not create base image URL: " + e.getMessage()); |
| 76 | 1 | } |
| 77 | 1 | } |
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | |
|
| 85 | |
public SVGIconBundle(final URL url) |
| 86 | 13 | { |
| 87 | 13 | if (url == null) |
| 88 | |
{ |
| 89 | 1 | throw new IllegalArgumentException("url must not be null"); |
| 90 | |
} |
| 91 | |
|
| 92 | 12 | this.url = url; |
| 93 | 12 | } |
| 94 | |
|
| 95 | |
|
| 96 | |
|
| 97 | |
public Image getImage(final Component component, |
| 98 | |
final IconTextDirection direction, |
| 99 | |
final IconState state, |
| 100 | |
final IconSize size) |
| 101 | |
{ |
| 102 | 1851 | if (direction == null) |
| 103 | |
{ |
| 104 | 1 | throw new IllegalArgumentException("direction must not be null"); |
| 105 | |
} |
| 106 | 1850 | if (state == null) |
| 107 | |
{ |
| 108 | 1 | throw new IllegalArgumentException("state must not be null"); |
| 109 | |
} |
| 110 | 1849 | if (size == null) |
| 111 | |
{ |
| 112 | 1 | throw new IllegalArgumentException("size must not be null"); |
| 113 | |
} |
| 114 | |
|
| 115 | 1848 | int height = size.getHeight(); |
| 116 | 1848 | int width = size.getWidth(); |
| 117 | |
|
| 118 | 1848 | BufferedImage image = IconBundleUtils.readSVG(url, width, height); |
| 119 | |
|
| 120 | 1848 | if (IconState.ACTIVE == state) |
| 121 | |
{ |
| 122 | 308 | return IconBundleUtils.makeActive(image); |
| 123 | |
} |
| 124 | 1540 | else if (IconState.MOUSEOVER == state) |
| 125 | |
{ |
| 126 | 308 | return IconBundleUtils.makeMouseover(image); |
| 127 | |
} |
| 128 | 1232 | else if (IconState.SELECTED == state) |
| 129 | |
{ |
| 130 | 308 | Color selectionColor = UIManager.getColor("List.selectionBackground"); |
| 131 | 308 | return IconBundleUtils.makeSelected(image, selectionColor); |
| 132 | |
} |
| 133 | 924 | else if (IconState.DRAGGING == state) |
| 134 | |
{ |
| 135 | 308 | return IconBundleUtils.makeDragging(image); |
| 136 | |
} |
| 137 | 616 | else if (IconState.DISABLED == state) |
| 138 | |
{ |
| 139 | 308 | return IconBundleUtils.makeDisabled(image); |
| 140 | |
} |
| 141 | |
else |
| 142 | |
{ |
| 143 | 308 | return image; |
| 144 | |
} |
| 145 | |
} |
| 146 | |
} |