BundleListRenderer implements ListCellRenderer<BundleItem> { public static String getBundleIconPath(String icons) { if(icons!=null) { List<String> iconList = new ArrayList<>(); if(icons.contains(ICON_SEPARATOR)) { for(String icon_descr : icons.split(ICON_SEPARATOR)) { iconList.add(icon_descr); } } else { iconList.add(icons); } String best_path = ""; int best_width = 0; for(String icon_descr : iconList) { int size_pos = icon_descr.indexOf(ICON_SIZE_PROP); int size_val = 0; String iconPath = new String(icon_descr); if(size_pos>1) { size_val = Integer.valueOf(icon_descr.substring(size_pos+ICON_SIZE_PROP.length() ,icon_descr.length()).trim()); iconPath = icon_descr.substring(0,size_pos-1).trim(); } if(best_width==0 || size_val == bundleIconDimension.width || (size_val > best_width && best_width != bundleIconDimension.width)) { best_path = iconPath; best_width = size_val; } } if(!best_path.isEmpty()) { return best_path; } } return ""; } BundleListRenderer(JList list); static String getBundleIconPath(String icons); @Override Component getListCellRendererComponent(JList<? extends BundleItem> jList, BundleItem bi, int i, boolean b, boolean b2); void updateLFRenderer();  }
@Test public void parseIconTest() { String res = BundleListRenderer.getBundleIconPath("icon.png;size=32"); Assert.assertEquals("icon.png",res); String res2 = BundleListRenderer.getBundleIconPath("icon.png;size=16, icon2.png;size=64"); Assert.assertEquals("icon2.png",res2); String res3 = BundleListRenderer.getBundleIconPath("icon.png;size=32, icon2.png;size=64"); Assert.assertEquals("icon.png",res3); }