Here you can find the source of loadIcons(String list, String path, Set
Parameter | Description |
---|---|
list | a path to a property-file containing key-path-pairs. |
path | the base path to the icons, will be added before any path of the property file, can be <code>null</code> |
ignore | keys that are already present in <code>ignore</code> are not loaded, can be <code>null</code> |
loader | used to transform paths into urls. |
public static Map<String, Icon> loadIcons(String list, String path, Set<String> ignore, ClassLoader loader)
//package com.java2s; /*//w ww . j a v a 2 s. com * Bibliothek - DockingFrames * Library built on Java/Swing, allows the user to "drag and drop" * panels containing any Swing-Co mponent the developer likes to add. * * Copyright (C) 2007 Benjamin Sigg * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * Benjamin Sigg * benjamin_sigg@gmx.ch * CH - Switzerland */ import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.util.HashMap; import java.util.Map; import java.util.Properties; import java.util.Set; import javax.swing.Icon; import javax.swing.ImageIcon; public class Main { /** * Loads a map of icons. * @param list a path to a property-file containing key-path-pairs. * @param path the base path to the icons, will be added before any * path of the property file, can be <code>null</code> * @param loader used to transform paths into urls. * @return the map of {@link Icon}s, the map can be empty if no icons were found * @see Properties#load(InputStream) */ public static Map<String, Icon> loadIcons(String list, String path, ClassLoader loader) { return loadIcons(list, path, null, loader); } /** * Loads a map of icons. * @param list a path to a property-file containing key-path-pairs. * @param path the base path to the icons, will be added before any * path of the property file, can be <code>null</code> * @param ignore keys that are already present in <code>ignore</code> are not loaded, can be <code>null</code> * @param loader used to transform paths into urls. * @return the map of {@link Icon}s, the map can be empty if no icons were found * @see Properties#load(InputStream) */ public static Map<String, Icon> loadIcons(String list, String path, Set<String> ignore, ClassLoader loader) { try { InputStream in = loader.getResourceAsStream(list); if (in == null) return new HashMap<String, Icon>(); Properties properties = new Properties(); properties.load(in); in.close(); int index = list.lastIndexOf('/'); if (index > 0) { if (path == null) { path = list.substring(0, index + 1); } else { path = list.substring(0, index + 1) + path; } } Map<String, Icon> result = new HashMap<String, Icon>(); for (Map.Entry<Object, Object> entry : properties.entrySet()) { String key = (String) entry.getKey(); if (ignore == null || !ignore.contains(key)) { String file = (String) entry.getValue(); if (path != null) file = path + file; URL url = loader.getResource(file); if (url == null) { System.err.println("Missing file: " + file); } else { ImageIcon icon = new ImageIcon(url); result.put(key, icon); } } } return result; } catch (IOException ex) { ex.printStackTrace(); return new HashMap<String, Icon>(); } } }