001/* 002 * Copyright 2010-2015 Institut Pasteur. 003 * 004 * This file is part of Icy. 005 * 006 * Icy is free software: you can redistribute it and/or modify 007 * it under the terms of the GNU General Public License as published by 008 * the Free Software Foundation, either version 3 of the License, or 009 * (at your option) any later version. 010 * 011 * Icy is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU General Public License for more details. 015 * 016 * You should have received a copy of the GNU General Public License 017 * along with Icy. If not, see <http://www.gnu.org/licenses/>. 018 */ 019package icy.resource; 020 021import java.awt.Color; 022import java.awt.Image; 023import java.awt.image.BufferedImage; 024import java.io.File; 025import java.net.URL; 026import java.util.ArrayList; 027 028import javax.swing.ImageIcon; 029 030import icy.image.ImageUtil; 031import icy.resource.icon.IcyIcon; 032import icy.util.StringUtil; 033 034/** 035 * Resources (images, icons...) utilities class. 036 * 037 * @author Stephane 038 */ 039public class ResourceUtil 040{ 041 // image and icon path 042 public static final String ICON_PATH = "res/icon/"; 043 public static final String IMAGE_PATH = "res/image/"; 044 045 public static final String ALPHA_ICON_PATH = "alpha/"; 046 public static final String COLOR_ICON_PATH = "color/"; 047 048 // default icon size 049 public static final int DEFAULT_ICON_SIZE = IcyIcon.DEFAULT_SIZE; 050 051 // application images 052 public static final Image IMAGE_ICY_16 = ResourceUtil.getIconAsImage("icy16.png"); 053 public static final Image IMAGE_ICY_32 = ResourceUtil.getIconAsImage("icy32.png"); 054 public static final Image IMAGE_ICY_256 = ResourceUtil.getImage("logo.png"); 055 056 public static final Image IMAGE_PLUGIN_SMALL = ResourceUtil.getImage("app/plugin_small.png"); 057 public static final Image IMAGE_PLUGIN = ResourceUtil.getImage("app/plugin.png"); 058 public static final Image IMAGE_ACCOLADE_LEFT = ResourceUtil.getImage("app/accol_left.png"); 059 060 // alpha mask icons 061 public static final ImageIcon ICON_ICY_16 = ResourceUtil.getImageIcon(IMAGE_ICY_16); 062 public static final ImageIcon ICON_ICY_32 = ResourceUtil.getImageIcon(IMAGE_ICY_32); 063 064 public static final Image ICON_NULL = ResourceUtil.getAlphaIconAsImage("null.png"); 065 066 public static final Image ICON_WINDOW_EXPAND = ResourceUtil.getAlphaIconAsImage("top_right_expand.png"); 067 public static final Image ICON_WINDOW_COLLAPSE = ResourceUtil.getAlphaIconAsImage("top_right_collapse.png"); 068 public static final Image ICON_PICTURE = ResourceUtil.getAlphaIconAsImage("picture.png"); 069 public static final Image ICON_PICTURE_COPY = ResourceUtil.getAlphaIconAsImage("picture_copy.png"); 070 public static final Image ICON_PICTURE_PASTE = ResourceUtil.getAlphaIconAsImage("picture_paste.png"); 071 public static final Image ICON_WINDOW = ResourceUtil.getAlphaIconAsImage("app_window.png"); 072 public static final Image ICON_DETACHED_WINDOW = ResourceUtil.getAlphaIconAsImage("app_detached.png"); 073 public static final Image ICON_DOC = ResourceUtil.getAlphaIconAsImage("document.png"); 074 public static final Image ICON_DOC_NEW = ResourceUtil.getAlphaIconAsImage("doc_new.png"); 075 public static final Image ICON_DOC_COPY = ResourceUtil.getAlphaIconAsImage("doc_copy.png"); 076 public static final Image ICON_DOC_IMPORT = ResourceUtil.getAlphaIconAsImage("doc_import.png"); 077 public static final Image ICON_DOC_EXPORT = ResourceUtil.getAlphaIconAsImage("doc_export.png"); 078 public static final Image ICON_XLS_EXPORT = ResourceUtil.getAlphaIconAsImage("xls_export.png"); 079 public static final Image ICON_DOCEDIT = ResourceUtil.getAlphaIconAsImage("doc_edit.png"); 080 public static final Image ICON_DOCTEXT1 = ResourceUtil.getAlphaIconAsImage("doc_lines.png"); 081 public static final Image ICON_DOCTEXT2 = ResourceUtil.getAlphaIconAsImage("doc_lines_stright.png"); 082 public static final Image ICON_DUPLICATE = ResourceUtil.getAlphaIconAsImage("duplicate.png"); 083 public static final Image ICON_FOLDER = ResourceUtil.getAlphaIconAsImage("folder.png"); 084 public static final Image ICON_OPEN = ResourceUtil.getAlphaIconAsImage("folder_open.png"); 085 public static final Image ICON_LOAD = ICON_OPEN; 086 public static final Image ICON_SAVE = ResourceUtil.getAlphaIconAsImage("save.png"); 087 public static final Image ICON_CLOSE = ResourceUtil.getAlphaIconAsImage("round_delete.png"); 088 public static final Image ICON_CLIPBOARD_CLEAR = ResourceUtil.getAlphaIconAsImage("clipboard_clear.png"); 089 public static final Image ICON_COPY = ResourceUtil.getAlphaIconAsImage("clipboard_copy.png"); 090 public static final Image ICON_CUT = ResourceUtil.getAlphaIconAsImage("clipboard_cut.png"); 091 public static final Image ICON_LINK_COPY = ResourceUtil.getAlphaIconAsImage("clipboard_link_copy.png"); 092 public static final Image ICON_PASTE = ResourceUtil.getAlphaIconAsImage("clipboard_past.png"); 093 public static final Image ICON_LINK_PASTE = ResourceUtil.getAlphaIconAsImage("clipboard_link_past.png"); 094 095 public static final Image ICON_HELP = ResourceUtil.getAlphaIconAsImage("help.png"); 096 public static final Image ICON_INFO = ResourceUtil.getAlphaIconAsImage("info.png"); 097 098 public static final Image ICON_ON_OFF = ResourceUtil.getAlphaIconAsImage("on-off.png"); 099 public static final Image ICON_TRASH = ResourceUtil.getAlphaIconAsImage("trash.png"); 100 public static final Image ICON_DELETE = ResourceUtil.getAlphaIconAsImage("delete.png"); 101 public static final Image ICON_COG = ResourceUtil.getAlphaIconAsImage("cog.png"); 102 public static final Image ICON_UNCHECKED = ResourceUtil.getAlphaIconAsImage("checkbox_unchecked.png"); 103 public static final Image ICON_CHECKED = ResourceUtil.getAlphaIconAsImage("checkbox_checked.png"); 104 public static final Image ICON_LOCK_OPEN = ResourceUtil.getAlphaIconAsImage("unlocked.png"); 105 public static final Image ICON_LOCK_CLOSE = ResourceUtil.getAlphaIconAsImage("locked.png"); 106 public static final Image ICON_DOWNLOAD = ResourceUtil.getAlphaIconAsImage("download.png"); 107 public static final Image ICON_PROPERTIES = ICON_DOCTEXT1; 108 public static final Image ICON_TAG = ResourceUtil.getAlphaIconAsImage("tag.png"); 109 public static final Image ICON_TOOLS = ResourceUtil.getAlphaIconAsImage("wrench_plus_2.png"); 110 public static final Image ICON_LIGHTING = ResourceUtil.getAlphaIconAsImage("lighting.png"); 111 public static final Image ICON_SEARCH = ResourceUtil.getAlphaIconAsImage("zoom.png"); 112 public static final Image ICON_WAIT = ResourceUtil.getAlphaIconAsImage("sand.png"); 113 public static final Image ICON_VISIBLE = ResourceUtil.getAlphaIconAsImage("eye_open.png"); 114 public static final Image ICON_NOT_VISIBLE = ResourceUtil.getAlphaIconAsImage("eye_close.png"); 115 public static final Image ICON_EYE_INV = ResourceUtil.getAlphaIconAsImage("eye_inv.png"); 116 public static final Image ICON_UNDO = ResourceUtil.getAlphaIconAsImage("undo.png"); 117 public static final Image ICON_REDO = ResourceUtil.getAlphaIconAsImage("redo.png"); 118 119 public static final Image ICON_CENTER_IMAGE = ResourceUtil.getAlphaIconAsImage("center.png"); 120 public static final Image ICON_CROP = ResourceUtil.getAlphaIconAsImage("crop.png"); 121 public static final Image ICON_FIT_IMAGE = ResourceUtil.getAlphaIconAsImage("fit_in2.png"); 122 public static final Image ICON_FIT_CANVAS = ResourceUtil.getAlphaIconAsImage("fit_out.png"); 123 124 public static final Image ICON_TARGET = ResourceUtil.getAlphaIconAsImage("simple_target.png"); 125 public static final Image ICON_PENCIL = ResourceUtil.getAlphaIconAsImage("pencil.png"); 126 public static final Image ICON_BRUSH = ResourceUtil.getAlphaIconAsImage("brush.png"); 127 public static final Image ICON_LINK = ResourceUtil.getAlphaIconAsImage("link.png"); 128 129 public static final Image ICON_LAYER_H1 = ResourceUtil.getAlphaIconAsImage("layers_h1.png"); 130 public static final Image ICON_LAYER_H2 = ResourceUtil.getAlphaIconAsImage("layers_h2.png"); 131 public static final Image ICON_LAYER_REVERSE_H = ResourceUtil.getAlphaIconAsImage("layers_reverse_h.png"); 132 public static final Image ICON_LAYER_EXTRACT_H = ResourceUtil.getAlphaIconAsImage("layers_extract_h.png"); 133 public static final Image ICON_LAYER_ADD_H = ResourceUtil.getAlphaIconAsImage("layers_add_h.png"); 134 public static final Image ICON_LAYER_INSERT_H = ResourceUtil.getAlphaIconAsImage("layers_insert_h.png"); 135 public static final Image ICON_LAYER_REMOVE_H = ResourceUtil.getAlphaIconAsImage("layers_remove_h.png"); 136 public static final Image ICON_LAYER_REMOVE_ADV_H = ResourceUtil.getAlphaIconAsImage("layers_remove_adv_h.png"); 137 public static final Image ICON_LAYER_V1 = ResourceUtil.getAlphaIconAsImage("layers_v1.png"); 138 public static final Image ICON_LAYER_V2 = ResourceUtil.getAlphaIconAsImage("layers_v2.png"); 139 public static final Image ICON_LAYER_REVERSE_V = ResourceUtil.getAlphaIconAsImage("layers_reverse_v.png"); 140 public static final Image ICON_LAYER_EXTRACT_V = ResourceUtil.getAlphaIconAsImage("layers_extract_v.png"); 141 public static final Image ICON_LAYER_ADD_V = ResourceUtil.getAlphaIconAsImage("layers_add_v.png"); 142 public static final Image ICON_LAYER_INSERT_V = ResourceUtil.getAlphaIconAsImage("layers_insert_v.png"); 143 public static final Image ICON_LAYER_REMOVE_V = ResourceUtil.getAlphaIconAsImage("layers_remove_v.png"); 144 public static final Image ICON_LAYER_REMOVE_ADV_V = ResourceUtil.getAlphaIconAsImage("layers_remove_adv_v.png"); 145 public static final Image ICON_LAYER_ADJUST_HV = ResourceUtil.getAlphaIconAsImage("layers_adjust_hv.png"); 146 147 public static final Image ICON_ROI = ResourceUtil.getAlphaIconAsImage("roi.png"); 148 public static final Image ICON_ROI_POINT = ResourceUtil.getAlphaIconAsImage("roi_point.png"); 149 public static final Image ICON_ROI_LINE = ResourceUtil.getAlphaIconAsImage("roi_line.png"); 150 public static final Image ICON_ROI_OVAL = ResourceUtil.getAlphaIconAsImage("roi_oval.png"); 151 public static final Image ICON_ROI_POLYLINE = ResourceUtil.getAlphaIconAsImage("roi_polyline.png"); 152 public static final Image ICON_ROI_POLYGON = ResourceUtil.getAlphaIconAsImage("roi_polygon.png"); 153 public static final Image ICON_ROI_RECTANGLE = ResourceUtil.getAlphaIconAsImage("roi_rectangle.png"); 154 public static final Image ICON_ROI_AREA = ResourceUtil.getAlphaIconAsImage("roi_area.png"); 155 156 public static final Image ICON_ROI_NOT = ResourceUtil.getAlphaIconAsImage("roi_not.png"); 157 public static final Image ICON_ROI_OR = ResourceUtil.getAlphaIconAsImage("roi_or.png"); 158 public static final Image ICON_ROI_AND = ResourceUtil.getAlphaIconAsImage("roi_and.png"); 159 public static final Image ICON_ROI_XOR = ResourceUtil.getAlphaIconAsImage("roi_xor.png"); 160 public static final Image ICON_ROI_SUB = ResourceUtil.getAlphaIconAsImage("roi_sub.png"); 161 162 public static final Image ICON_ROI_INTERIOR = ResourceUtil.getAlphaIconAsImage("roi_interior.png"); 163 public static final Image ICON_ROI_UPSCALE = ResourceUtil.getAlphaIconAsImage("roi_upscale.png"); 164 public static final Image ICON_ROI_DOWNSCALE = ResourceUtil.getAlphaIconAsImage("roi_downscale.png"); 165 166 public static final Image ICON_ROI_COMP = ResourceUtil.getAlphaIconAsImage("separate_obj.png"); 167 168 public static final Image ICON_BOOL_MASK = ResourceUtil.getAlphaIconAsImage("boolean_mask.png"); 169 170 public static final Image ICON_INDENT_DECREASE = ResourceUtil.getAlphaIconAsImage("indent_decrease.png"); 171 public static final Image ICON_INDENT_INCREASE = ResourceUtil.getAlphaIconAsImage("indent_increase.png"); 172 public static final Image ICON_INDENT_REMOVE = ResourceUtil.getAlphaIconAsImage("indent_remove.png"); 173 174 public static final Image ICON_TOIJ = ResourceUtil.getAlphaIconAsImage("to_ij.png"); 175 public static final Image ICON_TOICY = ResourceUtil.getAlphaIconAsImage("to_icy.png"); 176 177 public static final Image ICON_PLAY = ResourceUtil.getAlphaIconAsImage("playback_play.png"); 178 public static final Image ICON_STOP = ResourceUtil.getAlphaIconAsImage("playback_stop.png"); 179 public static final Image ICON_PAUSE = ResourceUtil.getAlphaIconAsImage("playback_pause.png"); 180 public static final Image ICON_PLAY_NEXT = ResourceUtil.getAlphaIconAsImage("playback_next.png"); 181 public static final Image ICON_PLAY_PREV = ResourceUtil.getAlphaIconAsImage("playback_prev.png"); 182 public static final Image ICON_RELOAD = ResourceUtil.getAlphaIconAsImage("playback_reload.png"); 183 184 public static final Image ICON_PLUS = ResourceUtil.getAlphaIconAsImage("plus.png"); 185 public static final Image ICON_MINUS = ResourceUtil.getAlphaIconAsImage("minus.png"); 186 187 public static final Image ICON_ROUND_PLUS = ResourceUtil.getAlphaIconAsImage("round_plus.png"); 188 public static final Image ICON_ROUND_MINUS = ResourceUtil.getAlphaIconAsImage("round_minus.png"); 189 190 public static final Image ICON_ROTATE_UNCLOCK = ResourceUtil.getAlphaIconAsImage("rot_unclock.png"); 191 public static final Image ICON_ROTATE_CLOCK = ICON_RELOAD; 192 193 public static final Image ICON_ARROW_UP = ResourceUtil.getAlphaIconAsImage("arrow_top.png"); 194 public static final Image ICON_ARROW_LEFT = ResourceUtil.getAlphaIconAsImage("arrow_left.png"); 195 public static final Image ICON_ARROW_RIGHT = ResourceUtil.getAlphaIconAsImage("arrow_right.png"); 196 public static final Image ICON_ARROW_DOWN = ResourceUtil.getAlphaIconAsImage("arrow_bottom.png"); 197 public static final Image ICON_ARROW_TOP_RIGHT = ResourceUtil.getAlphaIconAsImage("arrow_top_right.png"); 198 199 public static final Image ICON_ROUND_ARROW_UP = ResourceUtil.getAlphaIconAsImage("round_arrow_up.png"); 200 public static final Image ICON_ROUND_ARROW_LEFT = ResourceUtil.getAlphaIconAsImage("round_arrow_left.png"); 201 public static final Image ICON_ROUND_ARROW_RIGHT = ResourceUtil.getAlphaIconAsImage("round_arrow_right.png"); 202 public static final Image ICON_ROUND_ARROW_DOWN = ResourceUtil.getAlphaIconAsImage("round_arrow_down.png"); 203 204 public static final Image ICON_SQUARE_DOWN = ResourceUtil.getAlphaIconAsImage("sq_down.png"); 205 public static final Image ICON_SQUARE_UP = ResourceUtil.getAlphaIconAsImage("sq_up.png"); 206 public static final Image ICON_SQUARE_PREV = ResourceUtil.getAlphaIconAsImage("sq_prev.png"); 207 public static final Image ICON_SQUARE_NEXT = ResourceUtil.getAlphaIconAsImage("sq_next.png"); 208 209 public static final Image ICON_CLEAR_BEFORE = ResourceUtil.getAlphaIconAsImage("clear_top.png"); 210 public static final Image ICON_CLEAR_AFTER = ResourceUtil.getAlphaIconAsImage("clear_bottom.png"); 211 212 public static final Image ICON_PANEL_EXPAND = ResourceUtil.getAlphaIconAsImage("br_next.png"); 213 public static final Image ICON_PANEL_COLLAPSE = ResourceUtil.getAlphaIconAsImage("br_down.png"); 214 public static final Image ICON_PIN = ResourceUtil.getAlphaIconAsImage("pin.png"); 215 216 public static final Image ICON_NODE_EXPANDED = ResourceUtil.getAlphaIconAsImage("node_expanded.png"); 217 public static final Image ICON_NODE_COLLAPSED = ResourceUtil.getAlphaIconAsImage("node_collapsed.png"); 218 219 public static final Image ICON_BAND_RIGHT = ResourceUtil.getAlphaIconAsImage("arrow_r.png"); 220 public static final Image ICON_BAND_LEFT = ResourceUtil.getAlphaIconAsImage("arrow_l.png"); 221 222 public static final Image ICON_RESIZE = ResourceUtil.getAlphaIconAsImage("cursor_drag_arrow.png"); 223 public static final Image ICON_RESIZE_2 = ResourceUtil.getAlphaIconAsImage("cursor_drag_arrow_2.png"); 224 225 public static final Image ICON_TEXT = ResourceUtil.getAlphaIconAsImage("text_letter_t.png"); 226 227 public static final Image ICON_SMILEY_HAPPY = ResourceUtil.getAlphaIconAsImage("emotion_smile.png"); 228 public static final Image ICON_SMILEY_SAD = ResourceUtil.getAlphaIconAsImage("emotion_sad.png"); 229 230 public static final Image ICON_CUBE_3D = ResourceUtil.getAlphaIconAsImage("cube.png"); 231 232 public static final Image ICON_PLUGIN = ResourceUtil.getAlphaIconAsImage("plugin.png"); 233 public static final Image ICON_BOX = ResourceUtil.getAlphaIconAsImage("box.png"); 234 public static final Image ICON_DATABASE = ResourceUtil.getAlphaIconAsImage("db.png"); 235 public static final Image ICON_HDD = ICON_DATABASE; 236 public static final Image ICON_HDD_STREAM = ResourceUtil.getAlphaIconAsImage("hdd_stream.png");; 237 public static final Image ICON_STAR = ResourceUtil.getAlphaIconAsImage("star_fav.png"); 238 public static final Image ICON_NETWORK = ResourceUtil.getAlphaIconAsImage("network.png"); 239 public static final Image ICON_BROWSER = ResourceUtil.getAlphaIconAsImage("browser.png"); 240 public static final Image ICON_CHAT = ResourceUtil.getAlphaIconAsImage("spechbubble.png"); 241 public static final Image ICON_PHOTO = ResourceUtil.getAlphaIconAsImage("photo.png"); 242 public static final Image ICON_PHOTO_SMALL = ResourceUtil.getAlphaIconAsImage("photo_small.png"); 243 244 /** 245 * @deprecated Use {@link #ICON_DOC_NEW} instead. 246 */ 247 @Deprecated 248 public static final Image ICON_NEWDOC = ICON_DOC_NEW; 249 /** 250 * @deprecated Use {@link #ICON_DOC_COPY} instead. 251 */ 252 @Deprecated 253 public static final Image ICON_DOCCOPY = ICON_DOC_COPY; 254 /** 255 * @deprecated Use {@link #ICON_DOC_IMPORT} instead. 256 */ 257 @Deprecated 258 public static final Image ICON_DOCIMPORT = ICON_DOC_IMPORT; 259 /** 260 * @deprecated Use {@link #ICON_DOC_EXPORT} instead. 261 */ 262 @Deprecated 263 public static final Image ICON_DOCEXPORT = ICON_DOC_EXPORT; 264 /** 265 * @deprecated Use {@link #ICON_ARROW_DOWN} instead. 266 */ 267 @Deprecated 268 public static final Image ICON_ARROW_BOTTOM = ICON_ARROW_DOWN; 269 /** 270 * @deprecated Use {@link #ICON_ARROW_UP} instead. 271 */ 272 @Deprecated 273 public static final Image ICON_ARROW_TOP = ICON_ARROW_UP; 274 /** 275 * @deprecated Use {@link #ICON_WINDOW_EXPAND} instead. 276 */ 277 @Deprecated 278 public static final Image ICON_EXPAND = ICON_WINDOW_EXPAND; 279 /** 280 * @deprecated Use {@link #ICON_WINDOW_COLLAPSE} instead. 281 */ 282 @Deprecated 283 public static final Image ICON_COLLAPSE = ICON_WINDOW_COLLAPSE; 284 285 // color icons 286 public static final Image ICON_ALPHA_COLOR = ResourceUtil.getColorIconAsImage("alpha.png"); 287 public static final Image ICON_ARGB_COLOR = ResourceUtil.getColorIconAsImage("argb.png"); 288 public static final Image ICON_RGB_COLOR = ResourceUtil.getColorIconAsImage("rgb.png"); 289 public static final Image ICON_GRAY_COLOR = ResourceUtil.getColorIconAsImage("gray.png"); 290 291 public static final Image ICON_PLUGIN_COLOR = ResourceUtil.getColorIconAsImage("plugin.png"); 292 293 public static ArrayList<Image> getIcyIconImages() 294 { 295 final ArrayList<Image> result = new ArrayList<Image>(); 296 297 result.add(ResourceUtil.IMAGE_ICY_256); 298 result.add(ResourceUtil.IMAGE_ICY_32); 299 result.add(ResourceUtil.IMAGE_ICY_16); 300 301 return result; 302 } 303 304 private static Image scaleImage(Image image, int size) 305 { 306 // resize if needed 307 if ((image != null) && (size != -1)) 308 { 309 // be sure image data are ready 310 ImageUtil.waitImageReady(image); 311 // resize only if image has different size 312 if ((image.getWidth(null) != size) || (image.getWidth(null) != size)) 313 return ImageUtil.scale(image, size, size); 314 } 315 316 return image; 317 } 318 319 /** 320 * Return an image with wanted size located in res/image<br> 321 * For any other location use the ImageUtil.loadImage() method 322 * 323 * @param name 324 */ 325 public static Image getImage(String name) 326 { 327 final Image result; 328 final URL url = ResourceUtil.class.getResource("/" + IMAGE_PATH + name); 329 330 // TODO: this actually return the image asynchronously, check it does not bring problems 331 // if (url != null) 332 // result = ImageUtil.loadAsync(url); 333 // else 334 // result = ImageUtil.loadAsync(ICON_PATH + name); 335 336 if (url != null) 337 result = ImageUtil.load(url, true); 338 else 339 result = ImageUtil.load(new File(IMAGE_PATH + name), true); 340 341 if (result == null) 342 { 343 System.out.println("Resource name can't be found: " + name); 344 return null; 345 } 346 347 return result; 348 } 349 350 /** 351 * Return lock image with specified number. 352 */ 353 public static BufferedImage getLockedImage(int number) 354 { 355 final BufferedImage result = ImageUtil.getCopy(ICON_LOCK_CLOSE); 356 357 // nice for 48 pixels image 358 ImageUtil.drawTextTopRight(result, StringUtil.toString(number), 26, true, Color.black); 359 360 return result; 361 } 362 363 /** 364 * Return lock image with specified letter. 365 */ 366 public static BufferedImage getLockedImage(char letter) 367 { 368 final BufferedImage result = ImageUtil.getCopy(ICON_LOCK_CLOSE); 369 370 // nice for 48 pixels image 371 ImageUtil.drawTextTopRight(result, String.valueOf(letter), 26, true, Color.black); 372 373 return result; 374 } 375 376 /** 377 * Return an image with wanted size located in res/icon from its name<br> 378 * For any other location use the ImageUtil.loadImage() method 379 * 380 * @param name 381 */ 382 public static Image getIconAsImage(String name, int size) 383 { 384 final Image image; 385 386 final URL url = ResourceUtil.class.getResource("/" + ICON_PATH + name); 387 388 // TODO: this actually return the image asynchronously, check it does not bring problems 389 // if (url != null) 390 // image = ImageUtil.loadAsync(url); 391 // else 392 // image = ImageUtil.loadAsync(ICON_PATH + name); 393 394 if (url != null) 395 image = ImageUtil.load(url, true); 396 else 397 image = ImageUtil.load(new File(ICON_PATH + name), true); 398 399 if (image == null) 400 { 401 System.out.println("Resource name can't be found: " + name); 402 return null; 403 } 404 405 return scaleImage(image, size); 406 } 407 408 /** 409 * Return an image located in res/icon from its name<br> 410 * For any other location use the ImageUtil.loadImage() method 411 * 412 * @param name 413 */ 414 public static Image getIconAsImage(String name) 415 { 416 return getIconAsImage(name, -1); 417 } 418 419 /** 420 * Create an ImageIcon with specified size from the specified image<br> 421 */ 422 public static ImageIcon getImageIcon(Image image, int size) 423 { 424 if (image != null) 425 return new ImageIcon(scaleImage(image, size)); 426 427 return null; 428 } 429 430 /** 431 * Create an ImageIcon from the specified image (default image size is used as icon size)<br> 432 */ 433 public static ImageIcon getImageIcon(Image image) 434 { 435 if (image != null) 436 return new ImageIcon(image); 437 438 return null; 439 } 440 441 /** 442 * Return an image located in res/icon with specified square size from its name<br> 443 */ 444 public static ImageIcon getImageIcon(String resourceName, int size) 445 { 446 return getImageIcon(getIconAsImage(resourceName, size)); 447 } 448 449 /** 450 * Return an image located in res/icon from its name<br> 451 */ 452 public static ImageIcon getImageIcon(String resourceName) 453 { 454 return getImageIcon(getIconAsImage(resourceName)); 455 } 456 457 /** 458 * Return an image located in res/icon/alpha with specified square size from its name<br> 459 */ 460 public static Image getAlphaIconAsImage(String resourceName, int size) 461 { 462 final String finalName; 463 464 if (resourceName.toLowerCase().endsWith(".png")) 465 finalName = resourceName; 466 else 467 finalName = resourceName + ".png"; 468 469 return getIconAsImage(ALPHA_ICON_PATH + finalName, size); 470 } 471 472 /** 473 * Return an image located in res/icon/alpha from its name<br> 474 */ 475 public static Image getAlphaIconAsImage(String resourceName) 476 { 477 return getAlphaIconAsImage(resourceName, -1); 478 } 479 480 /** 481 * Return an ImageIcon located in res/icon/alpha with specified square size<br> 482 */ 483 public static ImageIcon getAlphaIcon(String resourceName, int size) 484 { 485 final String finalName; 486 487 if (resourceName.toLowerCase().endsWith(".png")) 488 finalName = resourceName; 489 else 490 finalName = resourceName + ".png"; 491 492 return getImageIcon(getIconAsImage(ALPHA_ICON_PATH + finalName, size)); 493 } 494 495 /** 496 * Return an ImageIcon located in res/icon/alpha<br> 497 */ 498 public static ImageIcon getAlphaIcon(String resourceName) 499 { 500 return getAlphaIcon(resourceName, -1); 501 } 502 503 /** 504 * Return an image located in res/icon/color with specified square size from its name<br> 505 */ 506 public static Image getColorIconAsImage(String resourceName, int size) 507 { 508 final String finalName; 509 510 if (resourceName.toLowerCase().endsWith(".png")) 511 finalName = resourceName; 512 else 513 finalName = resourceName + ".png"; 514 515 return getIconAsImage(COLOR_ICON_PATH + finalName, size); 516 } 517 518 /** 519 * Return an image located in res/icon/color from its name<br> 520 */ 521 public static Image getColorIconAsImage(String resourceName) 522 { 523 return getColorIconAsImage(resourceName, -1); 524 } 525 526 /** 527 * Return an ImageIcon located in res/icon/color with specified square size<br> 528 */ 529 public static ImageIcon getColorIcon(String resourceName, int size) 530 { 531 final String finalName; 532 533 if (resourceName.toLowerCase().endsWith(".png")) 534 finalName = resourceName; 535 else 536 finalName = resourceName + ".png"; 537 538 return getImageIcon(getIconAsImage(COLOR_ICON_PATH + finalName, size)); 539 } 540 541 /** 542 * Return an ImageIcon located in res/icon/color<br> 543 */ 544 public static ImageIcon getColorIcon(String resourceName) 545 { 546 return getColorIcon(resourceName, -1); 547 } 548 549 /** 550 * @deprecated use {@link #getAlphaIconAsImage(String, int)} instead 551 */ 552 @Deprecated 553 public static Image getBlackIconAsImage(String resourceName, int size) 554 { 555 return getAlphaIconAsImage(resourceName, size); 556 } 557 558 /** 559 * @deprecated use {@link #getAlphaIconAsImage(String)} instead 560 */ 561 @Deprecated 562 public static Image getBlackIconAsImage(String resourceName) 563 { 564 return getAlphaIconAsImage(resourceName); 565 } 566 567 /** 568 * @deprecated use {@link #getAlphaIcon(String, int)} instead 569 */ 570 @Deprecated 571 public static ImageIcon getBlackIcon(String resourceName, int size) 572 { 573 return getAlphaIcon(resourceName, size); 574 } 575 576 /** 577 * @deprecated use {@link #getAlphaIcon(String)} instead 578 */ 579 @Deprecated 580 public static ImageIcon getBlackIcon(String resourceName) 581 { 582 return getAlphaIcon(resourceName); 583 } 584 585 /** 586 * @deprecated use {@link #getAlphaIcon(String, int)} instead 587 */ 588 @Deprecated 589 public static ImageIcon getWhiteIcon(String resourceName, int size) 590 { 591 return getAlphaIcon(resourceName, size); 592 } 593 594 /** 595 * @deprecated use {@link #getAlphaIcon(String)} instead 596 */ 597 @Deprecated 598 public static ImageIcon getWhiteIcon(String resourceName) 599 { 600 return getAlphaIcon(resourceName); 601 } 602 603 // public static ImageIcon getColorIcon(String resourceName, int size) 604 // { 605 // return getImageIcon(getIconAsImage(COLOR_ICON_PATH + resourceName, size)); 606 // } 607 // 608 // public static ImageIcon getColorIcon(String resourceName) 609 // { 610 // return getColorIcon(resourceName, -1); 611 // } 612 613 /** 614 * @deprecated use {@link #getAlphaIcon(String, int)} instead 615 */ 616 @Deprecated 617 public static ImageIcon getIcyIcon(String resourceName, int size) 618 { 619 return getAlphaIcon(resourceName, size); 620 } 621 622 /** 623 * @deprecated use {@link #getAlphaIcon(String)} instead 624 */ 625 @Deprecated 626 public static ImageIcon getIcyIcon(String resourceName) 627 { 628 return getAlphaIcon(resourceName); 629 } 630 631 /** 632 * Return a new ImageIcon scaled with specified size 633 */ 634 public static ImageIcon scaleIcon(ImageIcon icon, int size) 635 { 636 if (icon != null) 637 return getImageIcon(icon.getImage(), size); 638 639 return null; 640 } 641}