1 19 20 25 package org.netbeans.modules.web.dd.impl.common; 26 27 import org.netbeans.modules.schema2beans.BaseBean; 28 import org.netbeans.modules.schema2beans.Version; 29 import org.netbeans.api.web.dd.WebApp; 30 import org.netbeans.api.web.dd.common.*; 31 32 public abstract class ComponentBeanMultiple extends DescriptionBeanMultiple implements DisplayNameInterface, IconInterface { 33 34 public ComponentBeanMultiple(java.util.Vector comps, Version version) { 35 super(comps, version); 36 } 37 public void setIcon(int index, org.netbeans.api.web.dd.Icon icon){} 39 public void setIcon(org.netbeans.api.web.dd.Icon[] icons){} 40 public org.netbeans.api.web.dd.Icon getIcon(int i){return null;} 41 public org.netbeans.api.web.dd.Icon[] getIcon(){return null;} 42 public int sizeIcon(){return 0;} 43 public int addIcon(org.netbeans.api.web.dd.Icon icon){return 0;} 44 public int removeIcon(org.netbeans.api.web.dd.Icon icon){return 0;} 45 46 public abstract void setDisplayName(int index, java.lang.String value); 47 public abstract String getDisplayName(int index); 48 public abstract void setDisplayName(java.lang.String [] value); 49 public abstract int sizeDisplayName(); 51 public abstract int addDisplayName(java.lang.String value); 52 public abstract void setDisplayNameXmlLang(int index, java.lang.String value); 54 public abstract String getDisplayNameXmlLang(int index); 55 56 public void setDisplayName(String locale, String displayName) throws VersionNotSupportedException { 57 if (displayName==null) removeDisplayNameForLocale(locale); 58 else { 59 int size = sizeDisplayName(); 60 boolean found=false; 61 for (int i=0;i<size;i++) { 62 String loc=getDisplayNameXmlLang(i); 63 if ((locale==null && loc==null) || (locale!=null && locale.equalsIgnoreCase(loc))) { 64 found=true; 65 setDisplayName(i, displayName); 66 break; 67 } 68 } 69 if (!found) { 70 addDisplayName(displayName); 71 if (locale!=null) setDisplayNameXmlLang(size, locale.toLowerCase()); 72 } 73 } 74 } 75 76 public void setDisplayName(String displayName) { 77 try { 78 setDisplayName(null,displayName); 79 } catch (VersionNotSupportedException ex){} 80 } 81 82 public void setAllDisplayNames(java.util.Map displayNames) throws VersionNotSupportedException { 83 removeAllDisplayNames(); 84 if (displayNames!=null) { 85 java.util.Iterator keys = displayNames.keySet().iterator(); 86 String [] newDisplayName = new String [displayNames.size()]; 87 int i=0; 88 while (keys.hasNext()) { 89 String key = (String ) keys.next(); 90 addDisplayName((String )displayNames.get(key)); 91 setDisplayNameXmlLang(i++, key); 92 } 93 } 94 } 95 96 public String getDisplayName(String locale) throws VersionNotSupportedException { 97 for (int i=0;i<sizeDisplayName();i++) { 98 String loc=getDisplayNameXmlLang(i); 99 if ((locale==null && loc==null) || (locale!=null && locale.equalsIgnoreCase(loc))) { 100 return getDisplayName(i); 101 } 102 } 103 return null; 104 } 105 public String getDefaultDisplayName() { 106 try { 107 return getDisplayName(null); 108 } catch (VersionNotSupportedException ex){return null;} 109 } 110 public java.util.Map getAllDisplayNames() { 111 java.util.Map map =new java.util.HashMap (); 112 for (int i=0;i<sizeDisplayName();i++) { 113 String desc=getDisplayName(i); 114 String loc=getDisplayNameXmlLang(i); 115 map.put(loc, desc); 116 } 117 return map; 118 } 119 120 public void removeDisplayNameForLocale(String locale) throws VersionNotSupportedException { 121 java.util.Map map = new java.util.HashMap (); 122 for (int i=0;i<sizeDisplayName();i++) { 123 String desc=getDisplayName(i); 124 String loc=getDisplayNameXmlLang(i); 125 if ((locale==null && loc!=null) || (locale!=null && !locale.equalsIgnoreCase(loc))) 126 map.put(loc, desc); 127 } 128 setAllDisplayNames(map); 129 } 130 131 public void removeDisplayName() { 132 try { 133 removeDisplayNameForLocale(null); 134 } catch (VersionNotSupportedException ex){} 135 } 136 public void removeAllDisplayNames() { 137 setDisplayName(new String []{}); 138 } 139 140 public void setSmallIcon(String locale, String icon) throws VersionNotSupportedException { 142 setIcon(locale, icon, true); 143 } 144 public void setSmallIcon(String icon) { 145 try { 146 setSmallIcon(null,icon); 147 } catch (VersionNotSupportedException ex){} 148 } 149 public void setLargeIcon(String locale, String icon) throws VersionNotSupportedException { 150 setIcon(locale, icon, false); 151 } 152 public void setLargeIcon(String icon) { 153 try { 154 setLargeIcon(null,icon); 155 } catch (VersionNotSupportedException ex){} 156 } 157 public void setAllIcons(String [] locales, String [] smallIcons, String [] largeIcons) throws VersionNotSupportedException { 158 org.netbeans.api.web.dd.Icon[] newIcons = new org.netbeans.api.web.dd.Icon[locales.length]; 159 for (int i=0;i<locales.length;i++) { 160 try { 161 newIcons[i] = (org.netbeans.api.web.dd.Icon)createBean("Icon"); if (smallIcons[i]!=null) newIcons[i].setSmallIcon(smallIcons[i]); 163 if (largeIcons[i]!=null) newIcons[i].setLargeIcon(largeIcons[i]); 164 if (locales[i]!=null) newIcons[i].setXmlLang(locales[i]); 165 } catch (ClassNotFoundException ex){} 166 } 167 setIcon(newIcons); 168 } 169 170 public void setIcon(org.netbeans.api.web.dd.Icon icon) { 171 if (icon==null) removeIcon(); 172 else { 173 org.netbeans.api.web.dd.Icon[] oldIcons = getIcon(); 174 boolean found=false; 175 try { 176 String locale = icon.getXmlLang(); 177 for (int i=0;i<oldIcons.length;i++) { 178 String loc=oldIcons[i].getXmlLang(); 179 if ((locale==null && loc==null) || (locale!=null && locale.equalsIgnoreCase(loc))) { 180 found=true; 181 setIcon(i, icon); 182 } 183 } 184 } catch (VersionNotSupportedException ex){} 185 if (!found) { 186 addIcon(icon); 187 } 188 } 189 } 190 191 public String getSmallIcon(String locale) throws VersionNotSupportedException { 192 return getIcon(locale,true); 193 } 194 public String getSmallIcon() { 195 try { 196 return getSmallIcon(null); 197 } catch (VersionNotSupportedException ex){return null;} 198 } 199 public String getLargeIcon(String locale) throws VersionNotSupportedException { 200 return getIcon(locale,false); 201 } 202 public String getLargeIcon() { 203 try { 204 return getLargeIcon(null); 205 } catch (VersionNotSupportedException ex){return null;} 206 } 207 public org.netbeans.api.web.dd.Icon getDefaultIcon() { 208 org.netbeans.api.web.dd.Icon[] icons = getIcon(); 209 for (int i=0;i<icons.length;i++) { 210 try { 211 String loc=icons[i].getXmlLang(); 212 if (loc==null) return icons[i]; 213 } catch (VersionNotSupportedException ex){} 214 } 215 return null; 216 } 217 public java.util.Map getAllIcons() { 218 java.util.Map map =new java.util.HashMap (); 219 org.netbeans.api.web.dd.Icon[] icons = getIcon(); 220 for (int i=0;i<icons.length;i++) { 221 String [] iconPair = new String [] {icons[i].getSmallIcon(),icons[i].getLargeIcon()}; 222 String loc=null; 223 try { 224 loc=icons[i].getXmlLang(); 225 } catch (VersionNotSupportedException ex){} 226 map.put(loc, iconPair); 227 } 228 return map; 229 } 230 231 public void removeSmallIcon(String locale) throws VersionNotSupportedException { 232 removeIcon(locale, true); 233 } 234 public void removeLargeIcon(String locale) throws VersionNotSupportedException { 235 removeIcon(locale, false); 236 } 237 public void removeIcon(String locale) throws VersionNotSupportedException { 238 org.netbeans.api.web.dd.Icon[] icons = getIcon(); 239 for (int i=0;i<icons.length;i++) { 240 String loc=icons[i].getXmlLang(); 241 if ((locale==null && loc==null) || (locale!=null && locale.equalsIgnoreCase(loc))) { 242 removeIcon(icons[i]); 243 } 244 } 245 } 246 public void removeSmallIcon() { 247 try { 248 removeSmallIcon(null); 249 } catch (VersionNotSupportedException ex){} 250 } 251 public void removeLargeIcon() { 252 try { 253 removeLargeIcon(null); 254 } catch (VersionNotSupportedException ex){} 255 } 256 public void removeIcon() { 257 org.netbeans.api.web.dd.Icon[] icons = getIcon(); 258 for (int i=0;i<icons.length;i++) { 259 try { 260 String loc=icons[i].getXmlLang(); 261 if (loc==null) removeIcon(icons[i]); 262 } catch (VersionNotSupportedException ex){} 263 } 264 } 265 public void removeAllIcons() { 266 setIcon(new org.netbeans.api.web.dd.Icon[]{}); 267 } 268 private void setIcon(String locale, String icon, boolean isSmall) throws VersionNotSupportedException { 269 if (icon==null) { 270 if (isSmall) removeSmallIcon(locale); 271 else removeLargeIcon(locale); 272 } 273 else { 274 org.netbeans.api.web.dd.Icon[] oldIcons = getIcon(); 275 boolean found=false; 276 for (int i=0;i<oldIcons.length;i++) { 277 String loc=oldIcons[i].getXmlLang(); 278 if ((locale==null && loc==null) || (locale!=null && locale.equalsIgnoreCase(loc))) { 279 found=true; 280 if (isSmall) oldIcons[i].setSmallIcon(icon); 281 else oldIcons[i].setLargeIcon(icon); 282 break; 283 } 284 } 285 if (!found) { 286 try { 287 org.netbeans.api.web.dd.Icon newIcon = (org.netbeans.api.web.dd.Icon)createBean("Icon"); if (locale!=null) newIcon.setXmlLang(locale.toLowerCase()); 289 if (isSmall) newIcon.setSmallIcon(icon); 290 else newIcon.setLargeIcon(icon); 291 addIcon(newIcon); 292 } catch (ClassNotFoundException ex){} 293 } 294 } 295 } 296 private String getIcon(String locale, boolean isSmall) throws VersionNotSupportedException { 297 for (int i=0;i<sizeIcon();i++) { 298 org.netbeans.api.web.dd.Icon icon = getIcon(i); 299 String loc=icon.getXmlLang(); 300 if ((locale==null && loc==null) || (locale!=null && locale.equalsIgnoreCase(loc))) { 301 if (isSmall) return icon.getSmallIcon(); 302 else return icon.getLargeIcon(); 303 } 304 } 305 return null; 306 } 307 308 public void removeIcon(String locale, boolean isSmall) throws VersionNotSupportedException { 309 org.netbeans.api.web.dd.Icon[] icons = getIcon(); 310 java.util.List iconList = new java.util.ArrayList (); 311 for (int i=0;i<icons.length;i++) { 312 String loc=icons[i].getXmlLang(); 313 if ((locale==null && loc==null) || (locale!=null && locale.equalsIgnoreCase(loc))) { 314 if (isSmall) { 315 icons[i].setSmallIcon(null); 316 if (icons[i].getLargeIcon()==null) iconList.add(icons[i]); 317 } else { 318 icons[i].setLargeIcon(null); 319 if (icons[i].getSmallIcon()==null) iconList.add(icons[i]); 320 } 321 } 322 } 323 java.util.Iterator it = iconList.iterator(); 324 while(it.hasNext()) removeIcon((org.netbeans.api.web.dd.Icon)it.next()); 325 } 326 } 327 | Popular Tags |