diff -r 768c414c7ce8 autoupdate.services/apichanges.xml --- a/autoupdate.services/apichanges.xml Fri Dec 24 18:32:29 2010 +0300 +++ b/autoupdate.services/apichanges.xml Sun Jan 02 20:28:18 2011 +0100 @@ -57,6 +57,25 @@ + + + Icons for update centers + + + + + +

+ Define icon when specifying an update center using + categoryIconBase attribute. +

+
+ + + +
Feature enabled only when all its dependencies are enabled diff -r 768c414c7ce8 autoupdate.services/manifest.mf --- a/autoupdate.services/manifest.mf Fri Dec 24 18:32:29 2010 +0300 +++ b/autoupdate.services/manifest.mf Sun Jan 02 20:28:18 2011 +0100 @@ -1,7 +1,7 @@ Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.modules.autoupdate.services OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/autoupdate/services/resources/Bundle.properties -OpenIDE-Module-Specification-Version: 1.22 +OpenIDE-Module-Specification-Version: 1.23 OpenIDE-Module-Layer: org/netbeans/modules/autoupdate/services/resources/layer.xml AutoUpdate-Show-In-Client: false AutoUpdate-Essential-Module: true diff -r 768c414c7ce8 autoupdate.services/src/org/netbeans/api/autoupdate/UpdateElement.java --- a/autoupdate.services/src/org/netbeans/api/autoupdate/UpdateElement.java Fri Dec 24 18:32:29 2010 +0300 +++ b/autoupdate.services/src/org/netbeans/api/autoupdate/UpdateElement.java Sun Jan 02 20:28:18 2011 +0100 @@ -44,9 +44,11 @@ package org.netbeans.api.autoupdate; +import java.awt.Image; import java.util.List; import org.netbeans.modules.autoupdate.services.UpdateElementImpl; import org.netbeans.api.autoupdate.UpdateUnitProvider.CATEGORY; +import org.netbeans.modules.autoupdate.updateprovider.ProviderCategory; /** Instances provided by the UpdateUnit which represents specific version * of update (e.g. module or feature). The UpdateElement can be installed, @@ -132,12 +134,34 @@ /** * @return UpdateUnitProvider.CATEGORY for a quality classification * for update represented by this instance + * @deprecated Use {@link #getSourceIcon()} and {@link #getSourceDescription()}. */ + @Deprecated public CATEGORY getSourceCategory () { UpdateUnitProvider provider = getUpdateUnitProvider(); return (provider != null) ? provider.getCategory() : CATEGORY.COMMUNITY; } + /** Provides an icon associated with the provider of this update element. + * @return icon representing the provider of this element + * @since 1.23 + * @see UpdateUnitProvider#getSourceIcon() + */ + public Image getSourceIcon() { + UpdateUnitProvider provider = getUpdateUnitProvider(); + return provider != null ? provider.getSourceIcon() : ProviderCategory.forValue(CATEGORY.COMMUNITY).getIcon(); + } + + /** Description of the provider of this element. + * @return textual description of the provider of this element + * @since 1.23 + * @see UpdateUnitProvider#getSourceDescription() + */ + public String getSourceDescription() { + UpdateUnitProvider provider = getUpdateUnitProvider(); + return provider != null ? provider.getSourceDescription() : ProviderCategory.forValue(CATEGORY.COMMUNITY).getDisplayName(); + } + private UpdateUnitProvider getUpdateUnitProvider() { String source = getSource(); UpdateUnitProvider retval = null; diff -r 768c414c7ce8 autoupdate.services/src/org/netbeans/api/autoupdate/UpdateUnitProvider.java --- a/autoupdate.services/src/org/netbeans/api/autoupdate/UpdateUnitProvider.java Fri Dec 24 18:32:29 2010 +0300 +++ b/autoupdate.services/src/org/netbeans/api/autoupdate/UpdateUnitProvider.java Sun Jan 02 20:28:18 2011 +0100 @@ -44,6 +44,7 @@ package org.netbeans.api.autoupdate; +import java.awt.Image; import org.netbeans.spi.autoupdate.*; import java.io.IOException; import java.net.URL; @@ -106,10 +107,34 @@ return impl.getDescription (); } - + + /** @deprecated Use {@link #getSourceIcon()} and {@link #getSourceDescription()}. + */ + @Deprecated public CATEGORY getCategory() { return impl.getCategory(); } + + /** The icon associated with this provider. In case no specific icon is + * associated, a general one is returned. + * + * @since 1.23 + * @see UpdateElement#getSourceIcon() + */ + public Image getSourceIcon() { + return impl.getSourceIcon(); + } + + /** The description of this provider. Usually associated with {@link #getSourceIcon()}. + * In case no special description is found, a general one is returned. + * + * @since 1.23 + * @return textual description of the provider + * @see UpdateElement#getSourceDescription() + */ + public String getSourceDescription() { + return impl.getSourceDescription(); + } /** It's special support for UpdateProvider based on Autoupdate Catalog. * It's most kind of Update Providers and have a special support in UI. diff -r 768c414c7ce8 autoupdate.services/src/org/netbeans/api/autoupdate/UpdateUnitProviderFactory.java --- a/autoupdate.services/src/org/netbeans/api/autoupdate/UpdateUnitProviderFactory.java Fri Dec 24 18:32:29 2010 +0300 +++ b/autoupdate.services/src/org/netbeans/api/autoupdate/UpdateUnitProviderFactory.java Sun Jan 02 20:28:18 2011 +0100 @@ -44,12 +44,14 @@ package org.netbeans.api.autoupdate; +import java.awt.Image; import java.io.File; import java.io.IOException; import java.net.URL; import java.util.List; import org.netbeans.api.progress.ProgressHandle; import org.netbeans.modules.autoupdate.services.UpdateUnitProviderImpl; +import org.netbeans.modules.autoupdate.updateprovider.ProviderCategory; /** The factory handles UpdateUnitProvider, allow to create or removed them, * browse the providers or refresh its content. @@ -95,8 +97,20 @@ * comming from returned UpdateUnitProvider * @return URL-based UpdateUnitProvider */ - public UpdateUnitProvider create (String name, String displayName, URL url, UpdateUnitProvider.CATEGORY category) { - return UpdateUnitProviderImpl.createUpdateUnitProvider (name, displayName, url, category); + public UpdateUnitProvider create( + String name, String displayName, URL url, UpdateUnitProvider.CATEGORY category + ) { + return UpdateUnitProviderImpl.createUpdateUnitProvider (name, displayName, url, ProviderCategory.forValue(category)); + } + + /** + * @since 1.23 + */ + public UpdateUnitProvider create( + String name, String displayName, URL url, + String categoryIconBase, String categoryDisplayName + ) { + return UpdateUnitProviderImpl.createUpdateUnitProvider (name, displayName, url, ProviderCategory.create(categoryIconBase, categoryDisplayName)); } /** Creates new UpdateUnitProvider and store its preferences. The new provider @@ -109,7 +123,7 @@ * @return URL-based UpdateUnitProvider */ public UpdateUnitProvider create (String name, String displayName, URL url) { - return UpdateUnitProviderImpl.createUpdateUnitProvider (name, displayName, url, UpdateUnitProvider.CATEGORY.COMMUNITY); + return UpdateUnitProviderImpl.createUpdateUnitProvider (name, displayName, url, ProviderCategory.forValue(UpdateUnitProvider.CATEGORY.COMMUNITY)); } /** Creates new UpdateUnitProvider for temporary usage. This provider contains diff -r 768c414c7ce8 autoupdate.services/src/org/netbeans/modules/autoupdate/services/UpdateUnitProviderImpl.java --- a/autoupdate.services/src/org/netbeans/modules/autoupdate/services/UpdateUnitProviderImpl.java Fri Dec 24 18:32:29 2010 +0300 +++ b/autoupdate.services/src/org/netbeans/modules/autoupdate/services/UpdateUnitProviderImpl.java Sun Jan 02 20:28:18 2011 +0100 @@ -44,6 +44,7 @@ package org.netbeans.modules.autoupdate.services; +import java.awt.Image; import java.io.File; import org.netbeans.api.autoupdate.*; import org.netbeans.spi.autoupdate.*; @@ -73,7 +74,9 @@ import org.openide.util.LookupEvent; import org.openide.util.LookupListener; import org.netbeans.api.autoupdate.UpdateUnitProvider.CATEGORY; +import org.netbeans.modules.autoupdate.updateprovider.ProviderCategory; import org.openide.filesystems.FileUtil; +import org.openide.util.ImageUtilities; /** UpdateProvider providers items for Autoupdate infrastructure. The items @@ -86,7 +89,7 @@ public final class UpdateUnitProviderImpl { private UpdateProvider provider; - private static Logger err = Logger.getLogger ("org.netbeans.modules.autoupdate.services.UpdateUnitProviderImpl"); + private static final Logger err = Logger.getLogger ("org.netbeans.modules.autoupdate.services.UpdateUnitProviderImpl"); private static final String REMOVED_MASK ="_removed"; private static final String URL = "url"; private static final String DISPLAY_NAME = "displayName"; @@ -114,6 +117,22 @@ public CATEGORY getCategory() { return getUpdateProvider().getCategory(); } + public Image getSourceIcon() { + UpdateProvider up = getUpdateProvider(); + if (up instanceof AutoupdateCatalogProvider) { + return ((AutoupdateCatalogProvider)up).getProviderCategory().getIcon(); + } + return ProviderCategory.forValue(CATEGORY.COMMUNITY).getIcon(); + } + public String getSourceDescription() { + UpdateProvider up = getUpdateProvider(); + if (up instanceof AutoupdateCatalogProvider) { + return ((AutoupdateCatalogProvider) up).getProviderCategory().getDisplayName(); + } + return ProviderCategory.forValue(CATEGORY.COMMUNITY).getDisplayName(); + } + + /** Display name of provider. This display name can be visualized in UI. * @@ -201,14 +220,14 @@ } public static UpdateUnitProvider createUpdateUnitProvider (String codeName, String displayName, URL url) { - return createUpdateUnitProvider(codeName, displayName, url, CATEGORY.COMMUNITY); + return createUpdateUnitProvider(codeName, displayName, url, ProviderCategory.forValue(CATEGORY.COMMUNITY)); } // static factory methods - public static UpdateUnitProvider createUpdateUnitProvider (String codeName, String displayName, URL url, CATEGORY category) { + public static UpdateUnitProvider createUpdateUnitProvider (String codeName, String displayName, URL url, ProviderCategory category) { codeName = normalizeCodeName (codeName); // store to Preferences - storeProvider(codeName, displayName, url); + storeProvider(codeName, displayName, url, category); AutoupdateCatalogProvider catalog = new AutoupdateCatalogProvider (codeName, displayName, url, category); @@ -309,7 +328,9 @@ UpdateManagerImpl.getInstance().clearCache (); } - private static void storeProvider (String codeName, String displayName, URL url) { + private static void storeProvider( + String codeName, String displayName, URL url, ProviderCategory c + ) { if (codeName.contains ("/")) { codeName = codeName.replaceAll ("/", "_"); } @@ -318,6 +339,8 @@ providerPreferences.put (URL, url.toString ()); providerPreferences.put (DISPLAY_NAME, displayName); + providerPreferences.put(CATEGORY_NAME, c.getDisplayName()); + providerPreferences.put(AutoupdateCatalogFactory.ORIGINAL_CATEGORY_ICON_BASE, c.getIconBase()); } private static Preferences getPreferences() { @@ -337,7 +360,20 @@ String toUrl = providerPreferences.get (URL, providerPreferences.get (AutoupdateCatalogFactory.ORIGINAL_URL, null)); String displayName = providerPreferences.get (DISPLAY_NAME, providerPreferences.get (AutoupdateCatalogFactory.ORIGINAL_DISPLAY_NAME, codeName)); - CATEGORY category = CATEGORY.valueOf(providerPreferences.get (CATEGORY_NAME, providerPreferences.get (AutoupdateCatalogFactory.ORIGINAL_CATEGORY_NAME, CATEGORY.COMMUNITY.name()))); + String categoryName = providerPreferences.get (CATEGORY_NAME, providerPreferences.get (AutoupdateCatalogFactory.ORIGINAL_CATEGORY_NAME, CATEGORY.COMMUNITY.name())); + CATEGORY c; + try { + c = CATEGORY.valueOf(categoryName); + } catch (IllegalArgumentException ex) { + c = null; + } + String categoryIconBase = providerPreferences.get(AutoupdateCatalogFactory.ORIGINAL_CATEGORY_ICON_BASE, null); + ProviderCategory pc; + if (c != null) { + pc = ProviderCategory.forValue(c); + } else { + pc = ProviderCategory.create(categoryIconBase, categoryName); + } // filter Providers which store only its state if (toUrl == null) { @@ -350,8 +386,7 @@ } catch (MalformedURLException mue) { assert false : mue; } - - return new AutoupdateCatalogProvider (codeName, displayName, url, category); + return new AutoupdateCatalogProvider (codeName, displayName, url, pc); } private static boolean loadState (String codename) { @@ -443,7 +478,7 @@ } } } - + private static class LookupListenerImpl implements LookupListener { final Lookup.Result result = Lookup.getDefault ().lookupResult(UpdateProvider.class); diff -r 768c414c7ce8 autoupdate.services/src/org/netbeans/modules/autoupdate/services/resources/icon-beta.png Binary file autoupdate.services/src/org/netbeans/modules/autoupdate/services/resources/icon-beta.png has changed diff -r 768c414c7ce8 autoupdate.services/src/org/netbeans/modules/autoupdate/services/resources/icon-community.png Binary file autoupdate.services/src/org/netbeans/modules/autoupdate/services/resources/icon-community.png has changed diff -r 768c414c7ce8 autoupdate.services/src/org/netbeans/modules/autoupdate/services/resources/icon-standard.png Binary file autoupdate.services/src/org/netbeans/modules/autoupdate/services/resources/icon-standard.png has changed diff -r 768c414c7ce8 autoupdate.services/src/org/netbeans/modules/autoupdate/updateprovider/AutoupdateCatalogFactory.java --- a/autoupdate.services/src/org/netbeans/modules/autoupdate/updateprovider/AutoupdateCatalogFactory.java Fri Dec 24 18:32:29 2010 +0300 +++ b/autoupdate.services/src/org/netbeans/modules/autoupdate/updateprovider/AutoupdateCatalogFactory.java Sun Jan 02 20:28:18 2011 +0100 @@ -86,6 +86,7 @@ public static final String ORIGINAL_DISPLAY_NAME = "originalDisplayName"; // NOI18N public static final String ORIGINAL_ENABLED = "originalEnabled"; // NOI18N public static final String ORIGINAL_CATEGORY_NAME = "originalCategoryName"; // NOI18N + public static final String ORIGINAL_CATEGORY_ICON_BASE = "originalCategoryIconBase"; // NOI18N public static UpdateProvider createUpdateProvider (FileObject fo) { String sKey = (String) fo.getAttribute ("url_key"); // NOI18N @@ -126,14 +127,36 @@ return null; } url = modifyURL (url); - String categoryName = (String) fo.getAttribute ("category"); // NOI18N - CATEGORY category = (categoryName != null) ? CATEGORY.valueOf(categoryName) : CATEGORY.COMMUNITY; - AutoupdateCatalogProvider au_catalog = new AutoupdateCatalogProvider(name, displayName(fo), url, category); - + String categoryName = (String) fo.getAttribute ("category"); // NOI18N + CATEGORY category; + try { + if (categoryName == null) { + category = CATEGORY.COMMUNITY; + } else { + category = CATEGORY.valueOf(categoryName); + } + } catch (IllegalArgumentException ex) { + // OK, not a valid name + category = null; + } + String categoryIconBase = (String) fo.getAttribute ("iconBase"); // NOI18N Preferences providerPreferences = getPreferences().node(name); + ProviderCategory pc; + if (category == null) { + if (categoryName == null || categoryIconBase == null) { + throw new IllegalStateException("Provide category and iconBase for " + fo); // NOI18N + } + pc = ProviderCategory.create(categoryIconBase, categoryName); + providerPreferences.put (ORIGINAL_CATEGORY_ICON_BASE, categoryIconBase); + } else { + pc = ProviderCategory.forValue(category); + } + AutoupdateCatalogProvider au_catalog = new AutoupdateCatalogProvider(name, displayName(fo), url, pc); providerPreferences.put (ORIGINAL_URL, url.toExternalForm ()); providerPreferences.put (ORIGINAL_DISPLAY_NAME, au_catalog.getDisplayName ()); - providerPreferences.put (ORIGINAL_CATEGORY_NAME, au_catalog.getCategory().name()); + providerPreferences.put (ORIGINAL_CATEGORY_NAME, au_catalog.getProviderCategory().getDisplayName()); + providerPreferences.put (ORIGINAL_CATEGORY_ICON_BASE, au_catalog.getProviderCategory().getIconBase()); + Boolean en = (Boolean) fo.getAttribute("enabled"); // NOI18N if (en != null) { providerPreferences.putBoolean (ORIGINAL_ENABLED, en); diff -r 768c414c7ce8 autoupdate.services/src/org/netbeans/modules/autoupdate/updateprovider/AutoupdateCatalogProvider.java --- a/autoupdate.services/src/org/netbeans/modules/autoupdate/updateprovider/AutoupdateCatalogProvider.java Fri Dec 24 18:32:29 2010 +0300 +++ b/autoupdate.services/src/org/netbeans/modules/autoupdate/updateprovider/AutoupdateCatalogProvider.java Sun Jan 02 20:28:18 2011 +0100 @@ -65,23 +65,26 @@ private String displayName; private AutoupdateCatalogCache cache = AutoupdateCatalogCache.getDefault (); private static final Logger LOG = Logger.getLogger ("org.netbeans.modules.autoupdate.updateprovider.AutoupdateCatalog"); - private String description = null; - private boolean descriptionInitialized = false; - private CATEGORY category = null; + private String description; + private boolean descriptionInitialized; + private ProviderCategory category; public AutoupdateCatalogProvider (String name, String displayName, URL updateCenter) { - this(name, displayName, updateCenter, CATEGORY.COMMUNITY); + this(name, displayName, updateCenter, ProviderCategory.forValue(CATEGORY.COMMUNITY)); } /** * Creates a new instance of AutoupdateCatalog */ - public AutoupdateCatalogProvider (String name, String displayName, URL updateCenter, CATEGORY category) { + public AutoupdateCatalogProvider (String name, String displayName, URL updateCenter, ProviderCategory category) { Parameters.notNull("name", name); this.codeName = name; this.displayName = displayName; this.updateCenter = updateCenter; - this.category = (category != null) ? category : CATEGORY.COMMUNITY; + this.category = category; + } + public AutoupdateCatalogProvider (String name, String displayName, URL updateCenter, CATEGORY category) { + this(name, displayName, updateCenter, ProviderCategory.forValue(category)); } @Override @@ -157,6 +160,10 @@ @Override public CATEGORY getCategory() { + return category.toEnum(); + } + + public ProviderCategory getProviderCategory() { return category; - } + } } diff -r 768c414c7ce8 autoupdate.services/src/org/netbeans/modules/autoupdate/updateprovider/Bundle.properties --- a/autoupdate.services/src/org/netbeans/modules/autoupdate/updateprovider/Bundle.properties Fri Dec 24 18:32:29 2010 +0300 +++ b/autoupdate.services/src/org/netbeans/modules/autoupdate/updateprovider/Bundle.properties Sun Jan 02 20:28:18 2011 +0100 @@ -7,3 +7,7 @@ ArtificialFeaturesProvider_Unsorted_Category=Uncategorized ArtificialFeaturesProvider_Features_Category=Features NetworkAccess_Timeout=Timeout while opening connection to {0} + +AvailableTab_SourceCategory_Tooltip_STANDARD=Certified Plugin +AvailableTab_SourceCategory_Tooltip_BETA=Beta Plugin +AvailableTab_SourceCategory_Tooltip_COMMUNITY=Community Contributed Plugin diff -r 768c414c7ce8 autoupdate.services/src/org/netbeans/modules/autoupdate/updateprovider/ProviderCategory.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/autoupdate.services/src/org/netbeans/modules/autoupdate/updateprovider/ProviderCategory.java Sun Jan 02 20:28:18 2011 +0100 @@ -0,0 +1,125 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2010 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2010 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.autoupdate.updateprovider; + +import java.awt.Image; +import org.netbeans.api.autoupdate.UpdateUnitProvider.CATEGORY; +import org.openide.util.ImageUtilities; +import org.openide.util.NbBundle; + +/** Represents provider category. + * + * @author Jaroslav Tulach + */ +public final class ProviderCategory { + private final String displayName; + private final String iconBase; + private final CATEGORY category; + + private ProviderCategory(String displayName, String iconBase, CATEGORY category) { + assert (category != null) != (displayName != null && iconBase != null) : + "Category: " + category + " displayName: " + displayName + + " iconBase: " + iconBase; + this.displayName = displayName; + this.iconBase = iconBase; + this.category = category; + } + + public static ProviderCategory create(String iconBase, String categoryDisplayName) { + return new ProviderCategory(categoryDisplayName, iconBase, null); + } + public String getDisplayName() { + String name = category != null ? getCategoryName(category) : displayName; + if (name == null) { + name = forValue(CATEGORY.COMMUNITY).getDisplayName(); + assert name != null; + } + return name; + } + public Image getIcon() { + Image img = ImageUtilities.loadImage(getIconBase(), true); + if (img == null) { + img = forValue(CATEGORY.COMMUNITY).getIcon(); + assert img != null; + } + return img; + } + + public static ProviderCategory forValue(CATEGORY c) { + return new ProviderCategory(null, null, c); + } + + CATEGORY toEnum() { + return category == null ? CATEGORY.COMMUNITY : category; + } + + static String getCategoryName(CATEGORY category) { + String key = null; + switch (category) { + case STANDARD: + key = "AvailableTab_SourceCategory_Tooltip_STANDARD"; //NOI18N + break; + case BETA: + key = "AvailableTab_SourceCategory_Tooltip_BETA"; //NOI18N + break; + case COMMUNITY: + key = "AvailableTab_SourceCategory_Tooltip_COMMUNITY"; //NOI18N + break; + } + return (key != null) ? NbBundle.getMessage(ProviderCategory.class, key) : null; + } + + public final String getIconBase() { + if (iconBase != null) { + return iconBase; + } + switch (category) { + case BETA: + return "org/netbeans/modules/autoupdate/services/resources/icon-beta.png"; // NOI18N + case STANDARD: + return "org/netbeans/modules/autoupdate/services/resources/icon-standard.png"; // NOI18N + default: + return "org/netbeans/modules/autoupdate/services/resources/icon-community.png"; // NOI18N + } + } +} diff -r 768c414c7ce8 autoupdate.services/test/unit/src/org/netbeans/api/autoupdate/DeclarationOfUpdateUnitProviderTest.java --- a/autoupdate.services/test/unit/src/org/netbeans/api/autoupdate/DeclarationOfUpdateUnitProviderTest.java Fri Dec 24 18:32:29 2010 +0300 +++ b/autoupdate.services/test/unit/src/org/netbeans/api/autoupdate/DeclarationOfUpdateUnitProviderTest.java Sun Jan 02 20:28:18 2011 +0100 @@ -44,13 +44,9 @@ package org.netbeans.api.autoupdate; -import java.net.URL; import java.util.List; -import junit.framework.TestCase; import org.netbeans.api.autoupdate.UpdateUnitProvider.CATEGORY; -import org.netbeans.api.progress.ProgressHandle; import org.netbeans.junit.NbTestCase; -import org.openide.filesystems.Repository; /** * diff -r 768c414c7ce8 autoupdate.services/test/unit/src/org/netbeans/modules/autoupdate/services/AutoupdateCatalogFactoryTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/autoupdate.services/test/unit/src/org/netbeans/modules/autoupdate/services/AutoupdateCatalogFactoryTest.java Sun Jan 02 20:28:18 2011 +0100 @@ -0,0 +1,87 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2010 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2010 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.autoupdate.services; + +import java.awt.Image; +import java.net.URL; +import org.netbeans.api.autoupdate.UpdateUnitProvider; +import org.netbeans.api.autoupdate.UpdateUnitProviderFactory; +import org.netbeans.junit.NbTestCase; +import org.netbeans.modules.autoupdate.updateprovider.AutoupdateCatalogFactory; +import org.netbeans.spi.autoupdate.UpdateProvider; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; +import org.openide.util.ImageUtilities; + +public class AutoupdateCatalogFactoryTest extends NbTestCase { + + public AutoupdateCatalogFactoryTest(String n) { + super(n); + } + + public void testCreateUpdateProviderWithOwnIcon() throws Exception { + FileObject f = FileUtil.getConfigRoot().createData("whatever.instance"); + f.setAttribute("url", "file:/wherever.xml"); + f.setAttribute("displayName", "Whatever"); + f.setAttribute("category", "Jarda's Updates"); + f.setAttribute("iconBase", "org/netbeans/modules/autoupdate/services/resources/icon-standard.png"); + UpdateProvider up = AutoupdateCatalogFactory.createUpdateProvider(f); + UpdateUnitProvider uup = Trampoline.API.createUpdateUnitProvider (new UpdateUnitProviderImpl (up)); + assertEquals("whatever", uup.getName()); + assertEquals("Whatever", uup.getDisplayName()); + assertEquals(new URL("file:/wherever.xml"), uup.getProviderURL()); + Image img = ImageUtilities.loadImage("org/netbeans/modules/autoupdate/services/resources/icon-standard.png"); + assertEquals("Icons are the same", img, uup.getSourceIcon()); + } + + public void testFactoryMethodsAndIcons() throws Exception { + Image img = ImageUtilities.loadImage("org/netbeans/modules/autoupdate/services/resources/icon-standard.png"); + UpdateUnitProvider res = UpdateUnitProviderFactory.getDefault().create( + "code-name", "Whatever", new URL("file:/whereever.xml"), + "org/netbeans/modules/autoupdate/services/resources/icon-standard.png", "my category" + ); + assertEquals("code-name", res.getName()); + assertEquals("Whatever", res.getDisplayName()); + assertEquals("Good image", img, res.getSourceIcon()); + } +} diff -r 768c414c7ce8 autoupdate.services/test/unit/src/org/netbeans/modules/autoupdate/services/UpdateUnitProviderImplTest.java --- a/autoupdate.services/test/unit/src/org/netbeans/modules/autoupdate/services/UpdateUnitProviderImplTest.java Fri Dec 24 18:32:29 2010 +0300 +++ b/autoupdate.services/test/unit/src/org/netbeans/modules/autoupdate/services/UpdateUnitProviderImplTest.java Sun Jan 02 20:28:18 2011 +0100 @@ -170,7 +170,10 @@ String displayName = "2nd Update Provider"; URL url = URL_TO_TEST_CATALOG; - UpdateUnitProvider newProvider = UpdateUnitProviderImpl.createUpdateUnitProvider(codeName, displayName, url, CATEGORY.COMMUNITY); + UpdateUnitProvider newProvider = UpdateUnitProviderImpl.createUpdateUnitProvider( + codeName, displayName, url, + ProviderCategory.forValue(CATEGORY.COMMUNITY) + ); assertNotNull(codeName + " provider found.", newProvider); result = UpdateUnitProviderImpl.getUpdateUnitProviders(false); diff -r 768c414c7ce8 autoupdate.services/test/unit/src/org/netbeans/modules/autoupdate/updateprovider/AutoupdateCatalogFactoryTest.java --- a/autoupdate.services/test/unit/src/org/netbeans/modules/autoupdate/updateprovider/AutoupdateCatalogFactoryTest.java Fri Dec 24 18:32:29 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2010 Oracle and/or its affiliates. All rights reserved. - * - * Oracle and Java are registered trademarks of Oracle and/or its affiliates. - * Other names may be trademarks of their respective owners. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - * - * Contributor(s): - * - * Portions Copyrighted 2010 Sun Microsystems, Inc. - */ - -package org.netbeans.modules.autoupdate.updateprovider; - -import java.net.URL; -import org.netbeans.junit.NbTestCase; -import org.netbeans.spi.autoupdate.UpdateProvider; -import org.openide.filesystems.FileObject; -import org.openide.filesystems.FileUtil; - -public class AutoupdateCatalogFactoryTest extends NbTestCase { - - public AutoupdateCatalogFactoryTest(String n) { - super(n); - } - - public void testCreateUpdateProvider() throws Exception { - FileObject f = FileUtil.getConfigRoot().createData("whatever.instance"); - f.setAttribute("url", "file:/wherever.xml"); - f.setAttribute("displayName", "Whatever"); - UpdateProvider up = AutoupdateCatalogFactory.createUpdateProvider(f); - assertEquals("whatever", up.getName()); - assertEquals("Whatever", up.getDisplayName()); - assertEquals(AutoupdateCatalogProvider.class, up.getClass()); - assertEquals(new URL("file:/wherever.xml"), ((AutoupdateCatalogProvider) up).getUpdateCenterURL()); - } - -} diff -r 768c414c7ce8 autoupdate.ui/nbproject/project.xml --- a/autoupdate.ui/nbproject/project.xml Fri Dec 24 18:32:29 2010 +0300 +++ b/autoupdate.ui/nbproject/project.xml Sun Jan 02 20:28:18 2011 +0100 @@ -19,7 +19,7 @@ - 1.12 + 1.23 @@ -68,7 +68,7 @@ - 8.0 + 8.12 diff -r 768c414c7ce8 autoupdate.ui/src/org/netbeans/modules/autoupdate/ui/AvailableTableModel.java --- a/autoupdate.ui/src/org/netbeans/modules/autoupdate/ui/AvailableTableModel.java Fri Dec 24 18:32:29 2010 +0300 +++ b/autoupdate.ui/src/org/netbeans/modules/autoupdate/ui/AvailableTableModel.java Sun Jan 02 20:28:18 2011 +0100 @@ -44,6 +44,7 @@ package org.netbeans.modules.autoupdate.ui; +import java.awt.Image; import java.util.Comparator; import java.util.HashSet; import java.util.List; @@ -53,7 +54,6 @@ import org.netbeans.api.autoupdate.OperationContainer.OperationInfo; import org.netbeans.api.autoupdate.UpdateElement; import org.netbeans.api.autoupdate.UpdateUnit; -import org.netbeans.api.autoupdate.UpdateUnitProvider.CATEGORY; import org.openide.DialogDisplayer; import org.openide.NotifyDescriptor; import org.openide.util.NbBundle; @@ -125,7 +125,7 @@ res = u.getCategoryName(); break; case 3 : - res = u.getSourceCategory(); + res = u.getSourceIcon(); break; } @@ -150,7 +150,7 @@ res = String.class; break; case 3 : - res = CATEGORY.class; + res = Image.class; break; } @@ -189,12 +189,13 @@ @Override public String getToolTipText(int row, int col) { if (col == 3) { - CATEGORY category = (CATEGORY) getValueAt (row, 3); - return Utilities.getCategoryName(category); + Unit.Available u = (Unit.Available) getUnitAtRow(row); + return u.getSourceDescription(); } return super.getToolTipText(row, col); } + @Override public int getPreferredWidth(JTableHeader header, int col) { final int minWidth = super.getMinWidth(header, col); switch (col) { diff -r 768c414c7ce8 autoupdate.ui/src/org/netbeans/modules/autoupdate/ui/Bundle.properties --- a/autoupdate.ui/src/org/netbeans/modules/autoupdate/ui/Bundle.properties Fri Dec 24 18:32:29 2010 +0300 +++ b/autoupdate.ui/src/org/netbeans/modules/autoupdate/ui/Bundle.properties Sun Jan 02 20:28:18 2011 +0100 @@ -21,9 +21,6 @@ UnitTab_ActivateCategoryAction=Activate Category UnitTab_DeactivateAction=&Deactivate UnitTab_DeactivateCategoryAction=Deactivate Category -AvailableTab_SourceCategory_Tooltip_STANDARD=Certified Plugin -AvailableTab_SourceCategory_Tooltip_BETA=Beta Plugin -AvailableTab_SourceCategory_Tooltip_COMMUNITY=Community Contributed Plugin InstallTab_Active_Tooltip=Active InstallTab_InActive_Tooltip=Inactive InstallTab_PendingForInstall_Tooltip=Application restart needed to complete installation diff -r 768c414c7ce8 autoupdate.ui/src/org/netbeans/modules/autoupdate/ui/HTMLEditorKitEx.java --- a/autoupdate.ui/src/org/netbeans/modules/autoupdate/ui/HTMLEditorKitEx.java Fri Dec 24 18:32:29 2010 +0300 +++ b/autoupdate.ui/src/org/netbeans/modules/autoupdate/ui/HTMLEditorKitEx.java Sun Jan 02 20:28:18 2011 +0100 @@ -44,29 +44,13 @@ package org.netbeans.modules.autoupdate.ui; import java.awt.Image; -import java.net.URL; -import java.util.HashMap; -import java.util.Map; -import javax.swing.ImageIcon; import javax.swing.text.html.*; import javax.swing.text.*; -import org.netbeans.api.autoupdate.UpdateUnitProvider.CATEGORY; /** * @author Radek Matous */ public class HTMLEditorKitEx extends HTMLEditorKit { - private static final Map ICONS = new HashMap(); - static { - URL u_standard = Utilities.getCategoryIcon(CATEGORY.STANDARD); - ICONS.put(u_standard, new ImageIcon(u_standard)); - - URL u_beta = Utilities.getCategoryIcon(CATEGORY.BETA); - ICONS.put(u_beta, new ImageIcon(u_beta)); - - URL u_community = Utilities.getCategoryIcon(CATEGORY.COMMUNITY); - ICONS.put(u_community, new ImageIcon(u_community)); - } public ViewFactory getViewFactory() { return new HTMLFactory() { @@ -85,8 +69,7 @@ @Override public Image getImage() { - ImageIcon img = ICONS.get(getImageURL()); - return (img != null) ? img.getImage() : super.getImage(); + return super.getImage(); } } } diff -r 768c414c7ce8 autoupdate.ui/src/org/netbeans/modules/autoupdate/ui/SettingsTab.form --- a/autoupdate.ui/src/org/netbeans/modules/autoupdate/ui/SettingsTab.form Fri Dec 24 18:32:29 2010 +0300 +++ b/autoupdate.ui/src/org/netbeans/modules/autoupdate/ui/SettingsTab.form Sun Jan 02 20:28:18 2011 +0100 @@ -1,4 +1,4 @@ - +
diff -r 768c414c7ce8 autoupdate.ui/src/org/netbeans/modules/autoupdate/ui/SettingsTab.java --- a/autoupdate.ui/src/org/netbeans/modules/autoupdate/ui/SettingsTab.java Fri Dec 24 18:32:29 2010 +0300 +++ b/autoupdate.ui/src/org/netbeans/modules/autoupdate/ui/SettingsTab.java Sun Jan 02 20:28:18 2011 +0100 @@ -48,6 +48,7 @@ import java.awt.Component; import java.awt.Dimension; import java.awt.EventQueue; +import java.awt.Image; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; @@ -63,13 +64,13 @@ import javax.swing.AbstractAction; import javax.swing.Action; import javax.swing.DefaultComboBoxModel; +import javax.swing.Icon; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.ListSelectionModel; import javax.swing.SwingConstants; -import javax.swing.SwingUtilities; import javax.swing.UIManager; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; @@ -80,7 +81,6 @@ import javax.swing.table.TableColumn; import javax.swing.table.TableColumnModel; import org.netbeans.api.autoupdate.UpdateUnitProvider; -import org.netbeans.api.autoupdate.UpdateUnitProvider.CATEGORY; import org.netbeans.api.options.OptionsDisplayer; import org.netbeans.modules.autoupdate.ui.actions.AutoupdateSettings; import org.openide.DialogDescriptor; @@ -717,14 +717,9 @@ if (value instanceof UpdateUnitProvider) { UpdateUnitProvider u = (UpdateUnitProvider) value; - CATEGORY state = u.getCategory(); - if (CATEGORY.BETA.equals(state)) { - renderComponent.setIcon(ImageUtilities.loadImageIcon("org/netbeans/modules/autoupdate/ui/resources/icon-beta.png", false)); // NOI18N - } else if (CATEGORY.COMMUNITY.equals(state)) { - renderComponent.setIcon(ImageUtilities.loadImageIcon("org/netbeans/modules/autoupdate/ui/resources/icon-community.png", false)); // NOI18N - } else if (CATEGORY.STANDARD.equals(state)) { - renderComponent.setIcon(ImageUtilities.loadImageIcon("org/netbeans/modules/autoupdate/ui/resources/icon-standard.png", false)); // NOI18N - } + Image img = u.getSourceIcon(); + final Icon icon = ImageUtilities.image2Icon(img); + renderComponent.setIcon(icon); renderComponent.setText (u.getDisplayName()); renderComponent.setHorizontalAlignment(SwingConstants.LEFT); } diff -r 768c414c7ce8 autoupdate.ui/src/org/netbeans/modules/autoupdate/ui/Unit.java --- a/autoupdate.ui/src/org/netbeans/modules/autoupdate/ui/Unit.java Fri Dec 24 18:32:29 2010 +0300 +++ b/autoupdate.ui/src/org/netbeans/modules/autoupdate/ui/Unit.java Sun Jan 02 20:28:18 2011 +0100 @@ -44,6 +44,7 @@ package org.netbeans.modules.autoupdate.ui; +import java.awt.Image; import java.text.Collator; import java.text.DateFormat; import java.text.ParseException; @@ -61,7 +62,6 @@ import org.netbeans.api.autoupdate.UpdateElement; import org.netbeans.api.autoupdate.UpdateManager; import org.netbeans.api.autoupdate.UpdateUnit; -import org.netbeans.api.autoupdate.UpdateUnitProvider.CATEGORY; import org.netbeans.modules.autoupdate.ui.UnitCategoryTableModel.Type; import org.openide.modules.SpecificationVersion; import org.openide.util.NbBundle; @@ -658,7 +658,7 @@ if (u1 instanceof Unit.Available && u2 instanceof Unit.Available) { Unit.Available unit1 = (Unit.Available)u1; Unit.Available unit2 = (Unit.Available)u2; - return Collator.getInstance().compare(unit1.getSourceCategory().name(), unit2.getSourceCategory().name()); + return Collator.getInstance().compare(unit1.getSourceDescription(), unit2.getSourceDescription()); } throw new IllegalStateException(); @@ -699,8 +699,11 @@ return (isNbms) ? UnitCategoryTableModel.Type.LOCAL : UnitCategoryTableModel.Type.AVAILABLE; } - public CATEGORY getSourceCategory() { - return updateEl.getSourceCategory(); + public Image getSourceIcon() { + return updateEl.getSourceIcon(); + } + public String getSourceDescription() { + return updateEl.getSourceDescription(); } } diff -r 768c414c7ce8 autoupdate.ui/src/org/netbeans/modules/autoupdate/ui/UnitDetails.java --- a/autoupdate.ui/src/org/netbeans/modules/autoupdate/ui/UnitDetails.java Fri Dec 24 18:32:29 2010 +0300 +++ b/autoupdate.ui/src/org/netbeans/modules/autoupdate/ui/UnitDetails.java Sun Jan 02 20:28:18 2011 +0100 @@ -44,6 +44,7 @@ package org.netbeans.modules.autoupdate.ui; import java.awt.Color; +import java.awt.Image; import java.io.CharConversionException; import java.net.URL; import java.util.ArrayList; @@ -63,7 +64,6 @@ import org.netbeans.api.autoupdate.UpdateElement; import org.netbeans.api.autoupdate.UpdateManager; import org.netbeans.api.autoupdate.UpdateUnit; -import org.netbeans.api.autoupdate.UpdateUnitProvider.CATEGORY; import org.openide.util.Exceptions; import org.openide.util.NbBundle; import org.openide.util.RequestProcessor; @@ -132,11 +132,14 @@ StringBuilder text = new StringBuilder(); if (u instanceof Unit.Available) { Unit.Available u1 = (Unit.Available) u; - CATEGORY c = u1.getSourceCategory(); - String categoryName = Utilities.getCategoryName(c); - URL icon = Utilities.getCategoryIcon(c); + Image c = u1.getSourceIcon(); + Object url = c.getProperty("url", null); + String categoryName = u1.getSourceDescription(); text.append(""); - text.append(""); + if (url instanceof URL) { + text.append(""); + } + text.append(""); text.append(""); text.append(""); text.append("
  " + categoryName + "

"); diff -r 768c414c7ce8 autoupdate.ui/src/org/netbeans/modules/autoupdate/ui/UnitTab.java --- a/autoupdate.ui/src/org/netbeans/modules/autoupdate/ui/UnitTab.java Fri Dec 24 18:32:29 2010 +0300 +++ b/autoupdate.ui/src/org/netbeans/modules/autoupdate/ui/UnitTab.java Sun Jan 02 20:28:18 2011 +0100 @@ -50,6 +50,7 @@ import org.netbeans.modules.autoupdate.ui.wizards.InstallUnitWizard; import java.awt.Component; import java.awt.Cursor; +import java.awt.Image; import java.awt.Point; import java.awt.Rectangle; import java.awt.event.ActionEvent; @@ -100,7 +101,6 @@ import org.netbeans.api.autoupdate.OperationContainer.OperationInfo; import org.netbeans.api.autoupdate.UpdateManager; import org.netbeans.api.autoupdate.UpdateUnit; -import org.netbeans.api.autoupdate.UpdateUnitProvider.CATEGORY; import org.netbeans.api.progress.ProgressHandle; import org.netbeans.api.progress.ProgressHandleFactory; import org.netbeans.modules.autoupdate.ui.wizards.OperationWizardModel.OperationType; @@ -1975,13 +1975,11 @@ JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { JLabel renderComponent = (JLabel)super.getTableCellRendererComponent (table, value, isSelected, hasFocus, row, column); - if (value instanceof CATEGORY) { + if (value instanceof Image) { Unit u = model.getUnitAtRow (row); if (u instanceof Unit.Available) { Unit.Available a = (Unit.Available)u; - CATEGORY state = a.getSourceCategory(); - URL icon = Utilities.getCategoryIcon(state); - renderComponent.setIcon(new ImageIcon(icon)); + renderComponent.setIcon(ImageUtilities.image2Icon(a.getSourceIcon())); renderComponent.setText (""); renderComponent.setHorizontalAlignment (SwingConstants.CENTER); } diff -r 768c414c7ce8 autoupdate.ui/src/org/netbeans/modules/autoupdate/ui/Utilities.java --- a/autoupdate.ui/src/org/netbeans/modules/autoupdate/ui/Utilities.java Fri Dec 24 18:32:29 2010 +0300 +++ b/autoupdate.ui/src/org/netbeans/modules/autoupdate/ui/Utilities.java Sun Jan 02 20:28:18 2011 +0100 @@ -85,7 +85,6 @@ import org.openide.util.NbBundle; import org.openide.util.NbPreferences; import org.openide.util.RequestProcessor; -import org.netbeans.api.autoupdate.UpdateUnitProvider.CATEGORY; import org.netbeans.modules.autoupdate.ui.actions.Installer; import org.netbeans.modules.autoupdate.ui.actions.ShowNotifications; import org.openide.util.Task; @@ -914,31 +913,4 @@ return NbPreferences.forModule (Utilities.class); } - static String getCategoryName(CATEGORY category) { - String key = null; - switch (category) { - case STANDARD: - key = "AvailableTab_SourceCategory_Tooltip_STANDARD"; //NOI18N - break; - case BETA: - key = "AvailableTab_SourceCategory_Tooltip_BETA"; //NOI18N - break; - case COMMUNITY: - key = "AvailableTab_SourceCategory_Tooltip_COMMUNITY"; //NOI18N - break; - } - return (key != null) ? getBundle(key) : null; - } - - static URL getCategoryIcon(CATEGORY state) { - URL retval = null; - if (CATEGORY.BETA.equals(state)) { - retval = Utilities.class.getResource("/org/netbeans/modules/autoupdate/ui/resources/icon-beta.png"); // NOI18N - } else if (CATEGORY.COMMUNITY.equals(state)) { - retval = Utilities.class.getResource("/org/netbeans/modules/autoupdate/ui/resources/icon-community.png"); // NOI18N - } else if (CATEGORY.STANDARD.equals(state)) { - retval = Utilities.class.getResource("/org/netbeans/modules/autoupdate/ui/resources/icon-standard.png"); // NOI18N - } - return retval; - } } diff -r 768c414c7ce8 autoupdate.ui/src/org/netbeans/modules/autoupdate/ui/resources/icon-beta.png Binary file autoupdate.ui/src/org/netbeans/modules/autoupdate/ui/resources/icon-beta.png has changed diff -r 768c414c7ce8 autoupdate.ui/src/org/netbeans/modules/autoupdate/ui/resources/icon-community.png Binary file autoupdate.ui/src/org/netbeans/modules/autoupdate/ui/resources/icon-community.png has changed diff -r 768c414c7ce8 autoupdate.ui/src/org/netbeans/modules/autoupdate/ui/resources/icon-standard.png Binary file autoupdate.ui/src/org/netbeans/modules/autoupdate/ui/resources/icon-standard.png has changed diff -r 768c414c7ce8 openide.util/apichanges.xml --- a/openide.util/apichanges.xml Fri Dec 24 18:32:29 2010 +0300 +++ b/openide.util/apichanges.xml Sun Jan 02 20:28:18 2011 +0100 @@ -51,6 +51,23 @@ Actions API + + + ImageUtilities support "url" attribute + + + + + +

+ Images loaded by + ImageUtilities.loadImage now + respond to getProperty("url", null) calls. +

+
+ + +
New implementation of WeakSet with two new methods putIfAbsent and resize diff -r 768c414c7ce8 openide.util/manifest.mf --- a/openide.util/manifest.mf Fri Dec 24 18:32:29 2010 +0300 +++ b/openide.util/manifest.mf Sun Jan 02 20:28:18 2011 +0100 @@ -1,5 +1,5 @@ Manifest-Version: 1.0 OpenIDE-Module: org.openide.util OpenIDE-Module-Localizing-Bundle: org/openide/util/Bundle.properties -OpenIDE-Module-Specification-Version: 8.11 +OpenIDE-Module-Specification-Version: 8.12 diff -r 768c414c7ce8 openide.util/src/org/openide/util/ImageUtilities.java --- a/openide.util/src/org/openide/util/ImageUtilities.java Fri Dec 24 18:32:29 2010 +0300 +++ b/openide.util/src/org/openide/util/ImageUtilities.java Sun Jan 02 20:28:18 2011 +0100 @@ -61,6 +61,7 @@ import java.awt.image.WritableRaster; import java.io.IOException; import java.lang.ref.SoftReference; +import java.net.URL; import java.util.HashMap; import java.util.HashSet; import java.util.Hashtable; @@ -139,6 +140,9 @@ * or org/netbeans/modules/foo/resources/foo_mybranding.gif. * *

Caching of loaded images can be used internally to improve performance. + *

Since version 8.12 the returned image object responds to call + * image.getProperty("url", null) by returning the internal + * {@link URL} of the found and loaded resource. * * @param resource resource path of the image (no initial slash) * @param localized true for localized search @@ -245,7 +249,7 @@ return cached; } } - cached = ToolTipImage.createNew(text, image); + cached = ToolTipImage.createNew(text, image, null); imageToolTipCache.put(key, new ActiveRef(cached, imageToolTipCache, key)); return cached; } @@ -527,7 +531,7 @@ ERR.log(Level.FINE, "loading icon {0} = {1}", new Object[] {n, result}); name = new String(name).intern(); // NOPMD - result = ToolTipImage.createNew("", result); + result = ToolTipImage.createNew("", result, url); cache.put(name, new ActiveRef(result, cache, name)); return result; } else { // no icon found @@ -601,7 +605,7 @@ ColorModel model = colorModel(bitmask? Transparency.BITMASK: Transparency.TRANSLUCENT); ToolTipImage buffImage = new ToolTipImage(str.toString(), - model, model.createCompatibleWritableRaster(w, h), model.isAlphaPremultiplied(), null + model, model.createCompatibleWritableRaster(w, h), model.isAlphaPremultiplied(), null, null ); java.awt.Graphics g = buffImage.createGraphics(); @@ -738,14 +742,20 @@ private static class ToolTipImage extends BufferedImage implements Icon { final String toolTipText; ImageIcon imageIcon; + final URL url; - public static ToolTipImage createNew(String toolTipText, Image image) { + public static ToolTipImage createNew(String toolTipText, Image image, URL url) { ImageUtilities.ensureLoaded(image); boolean bitmask = (image instanceof Transparency) && ((Transparency) image).getTransparency() != Transparency.TRANSLUCENT; ColorModel model = colorModel(bitmask ? Transparency.BITMASK : Transparency.TRANSLUCENT); int w = image.getWidth(null); int h = image.getHeight(null); - ToolTipImage newImage = new ToolTipImage(toolTipText, model, model.createCompatibleWritableRaster(w, h), model.isAlphaPremultiplied(), null); + ToolTipImage newImage = new ToolTipImage( + toolTipText, + model, + model.createCompatibleWritableRaster(w, h), + model.isAlphaPremultiplied(), null, url + ); java.awt.Graphics g = newImage.createGraphics(); g.drawImage(image, 0, 0, null); @@ -753,26 +763,21 @@ return newImage; } - public ToolTipImage(String toolTipText, ColorModel cm, WritableRaster raster, boolean isRasterPremultiplied, Hashtable properties) { + public ToolTipImage( + String toolTipText, ColorModel cm, WritableRaster raster, + boolean isRasterPremultiplied, Hashtable properties, URL url + ) { super(cm, raster, isRasterPremultiplied, properties); this.toolTipText = toolTipText; - } - - public ToolTipImage(String toolTipText, int width, int height, int imageType, IndexColorModel cm) { - super(width, height, imageType, cm); - this.toolTipText = toolTipText; + this.url = url; } public ToolTipImage(String toolTipText, int width, int height, int imageType) { super(width, height, imageType); this.toolTipText = toolTipText; + this.url = null; } - public ToolTipImage(String toolTipText, BufferedImage image) { - super(image.getWidth(), image.getHeight(), image.getType()); - this.toolTipText = toolTipText; - } - synchronized ImageIcon getIcon() { if (imageIcon == null) { imageIcon = new ImageIcon(this); @@ -791,6 +796,18 @@ public void paintIcon(Component c, Graphics g, int x, int y) { g.drawImage(this, x, y, null); } + + @Override + public Object getProperty(String name, ImageObserver observer) { + if ("url".equals(name)) { // NOI18N + if (url != null) { + return url; + } else { + return imageIcon.getImage().getProperty("url", observer); + } + } + return super.getProperty(name, observer); + } } private static class LazyDisabledIcon implements Icon { diff -r 768c414c7ce8 openide.util/test/unit/src/org/openide/util/ImageUtilitiesTest.java --- a/openide.util/test/unit/src/org/openide/util/ImageUtilitiesTest.java Fri Dec 24 18:32:29 2010 +0300 +++ b/openide.util/test/unit/src/org/openide/util/ImageUtilitiesTest.java Sun Jan 02 20:28:18 2011 +0100 @@ -47,6 +47,7 @@ import java.awt.Image; import java.awt.Transparency; import java.awt.image.BufferedImage; +import java.net.URL; import javax.swing.Icon; import junit.framework.*; @@ -180,11 +181,17 @@ assertNotNull("Should not be null", icon); assertNotNull("Should not be null", image); + URL u = getClass().getResource("/org/openide/util/testimage.png"); + assertNotNull("URL found", u); + assertEquals("URL obtained", u, image.getProperty("url", null)); + Icon icon2 = ImageUtilities.image2Icon(image); Image image2 = ImageUtilities.icon2Image(icon); assertEquals("Should be same instance", icon, icon2); assertEquals("Should be same instance", image, image2); + + assertEquals("Url is still there", u, image2.getProperty("url", null)); } public void testLoadingNonExisting() {