From 037d98dae304c24ef3b735a458cdbd14dfab9a7b Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Tue, 27 Aug 2013 16:48:52 -0700 Subject: [PATCH 01/27] [Icons] Add getAsset to ComponentProvider --- .../ExternalComponentRegistryImpl.java | 5 +++++ .../component/AbstractComponentProvider.java | 17 +++++++++----- .../services/component/ComponentProvider.java | 22 ++++++++++++++----- 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/mctcore/src/main/java/gov/nasa/arc/mct/registry/ExternalComponentRegistryImpl.java b/mctcore/src/main/java/gov/nasa/arc/mct/registry/ExternalComponentRegistryImpl.java index 5db90e13..a089eb5b 100644 --- a/mctcore/src/main/java/gov/nasa/arc/mct/registry/ExternalComponentRegistryImpl.java +++ b/mctcore/src/main/java/gov/nasa/arc/mct/registry/ExternalComponentRegistryImpl.java @@ -309,6 +309,11 @@ public Collection getStatusAreaWidgetInfos() { @Override public SearchProvider getSearchProvider() { return provider.getSearchProvider(); + } + + @Override + public T getAsset(Class objectType, Class assetType, Map hints) { + return null; } } diff --git a/mctcore/src/main/java/gov/nasa/arc/mct/services/component/AbstractComponentProvider.java b/mctcore/src/main/java/gov/nasa/arc/mct/services/component/AbstractComponentProvider.java index ffdc8a0d..d121e296 100644 --- a/mctcore/src/main/java/gov/nasa/arc/mct/services/component/AbstractComponentProvider.java +++ b/mctcore/src/main/java/gov/nasa/arc/mct/services/component/AbstractComponentProvider.java @@ -21,11 +21,12 @@ *******************************************************************************/ package gov.nasa.arc.mct.services.component; -import gov.nasa.arc.mct.gui.MenuItemInfo; -import gov.nasa.arc.mct.policy.PolicyInfo; - -import java.util.Collection; -import java.util.Collections; +import gov.nasa.arc.mct.gui.MenuItemInfo; +import gov.nasa.arc.mct.policy.PolicyInfo; + +import java.util.Collection; +import java.util.Collections; +import java.util.Map; /** * An abstract class that implements ComponentProvider. @@ -69,5 +70,9 @@ public Collection getStatusAreaWidgetInfos() { public SearchProvider getSearchProvider() { return null; } - + + @Override + public T getAsset(Class type, Class assetClass, Map hints) { + return null; + } } diff --git a/mctcore/src/main/java/gov/nasa/arc/mct/services/component/ComponentProvider.java b/mctcore/src/main/java/gov/nasa/arc/mct/services/component/ComponentProvider.java index b4654e36..c888e5a0 100644 --- a/mctcore/src/main/java/gov/nasa/arc/mct/services/component/ComponentProvider.java +++ b/mctcore/src/main/java/gov/nasa/arc/mct/services/component/ComponentProvider.java @@ -21,10 +21,11 @@ *******************************************************************************/ package gov.nasa.arc.mct.services.component; -import gov.nasa.arc.mct.gui.MenuItemInfo; -import gov.nasa.arc.mct.policy.PolicyInfo; - -import java.util.Collection; +import gov.nasa.arc.mct.gui.MenuItemInfo; +import gov.nasa.arc.mct.policy.PolicyInfo; + +import java.util.Collection; +import java.util.Map; /** * This interface can be implemented as an OSGI service to provide one @@ -80,5 +81,16 @@ public interface ComponentProvider { * Provides search capability for this plugin. This allows the plugin to handle custom search. * @return a search provider */ - SearchProvider getSearchProvider(); + SearchProvider getSearchProvider(); + + /** + * Get some asset associated with a given object type. Typically this will be used to obtain + * things like icons or create wizards which are associated with specific component or view + * types, but are not incorporated into those types directly to preserve separation of + * concerns. + * @param objectType + * @param assetType + * @return + */ + T getAsset(Class objectType, Class assetType, Map hints); } From 7c44daff36b7f8b223c7f94911ddf54ffbe364ef Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Mon, 9 Sep 2013 15:48:38 -0700 Subject: [PATCH 02/27] [Icons] Hook component icon methods up to getAsset Use getAsset in getIcon methods of AbstractComponent, and deprecate them for future removal. --- .../arc/mct/components/AbstractComponent.java | 28 +++++++++---------- .../ExternalComponentRegistryImpl.java | 19 +++++++++++-- .../component/AbstractComponentProvider.java | 3 +- .../services/component/ComponentProvider.java | 9 +++--- .../component/CoreComponentRegistry.java | 13 ++++++++- 5 files changed, 46 insertions(+), 26 deletions(-) diff --git a/mctcore/src/main/java/gov/nasa/arc/mct/components/AbstractComponent.java b/mctcore/src/main/java/gov/nasa/arc/mct/components/AbstractComponent.java index 7c2bb39c..657f30b7 100644 --- a/mctcore/src/main/java/gov/nasa/arc/mct/components/AbstractComponent.java +++ b/mctcore/src/main/java/gov/nasa/arc/mct/components/AbstractComponent.java @@ -37,7 +37,6 @@ import gov.nasa.arc.mct.policy.PolicyContext; import gov.nasa.arc.mct.policy.PolicyInfo; import gov.nasa.arc.mct.registry.ExternalComponentRegistryImpl; -import gov.nasa.arc.mct.registry.ExternalComponentRegistryImpl.ExtendedComponentTypeInfo; import gov.nasa.arc.mct.roles.events.AddChildEvent; import gov.nasa.arc.mct.roles.events.PropertyChangeEvent; import gov.nasa.arc.mct.roles.events.RemoveChildEvent; @@ -875,15 +874,13 @@ public int getVersion() { /** * Returns the icon image for this component. * @return an icon image + * @deprecated use PlatformAccess.getPlatform().getComponentRegistry().getAsset() instead */ + @Deprecated public final ImageIcon getIcon() { - Collection infos = ExternalComponentRegistryImpl.getInstance().getComponentInfos(); - for (ExtendedComponentTypeInfo info : infos) { - if (getClass() == info.getComponentClass()) { - return info.getIcon(); - } - } - return MCTIcons.getComponent(); + ImageIcon icon = ExternalComponentRegistryImpl.getInstance() + .getAsset(getClass(), ImageIcon.class); + return icon != null ? icon : MCTIcons.getComponent(); } /** @@ -892,13 +889,14 @@ public final ImageIcon getIcon() { * @return an image icon */ public static ImageIcon getIconForComponentType(String className) { - Collection infos = ExternalComponentRegistryImpl.getInstance().getComponentInfos(); - for (ExtendedComponentTypeInfo info : infos) { - if (className.equals(info.getComponentClass().getName())) { - return info.getIcon(); - } - } - return MCTIcons.getComponent(); + try { + Class c = Class.forName(className); + ImageIcon icon = ExternalComponentRegistryImpl.getInstance() + .getAsset(c, ImageIcon.class); + return icon != null ? icon : MCTIcons.getComponent(); + } catch (ClassNotFoundException e) { + return MCTIcons.getComponent(); + } } /** diff --git a/mctcore/src/main/java/gov/nasa/arc/mct/registry/ExternalComponentRegistryImpl.java b/mctcore/src/main/java/gov/nasa/arc/mct/registry/ExternalComponentRegistryImpl.java index a089eb5b..1c14e816 100644 --- a/mctcore/src/main/java/gov/nasa/arc/mct/registry/ExternalComponentRegistryImpl.java +++ b/mctcore/src/main/java/gov/nasa/arc/mct/registry/ExternalComponentRegistryImpl.java @@ -74,7 +74,7 @@ public class ExternalComponentRegistryImpl implements CoreComponentRegistry { private final AtomicReference> activeProviders = new AtomicReference>(Collections.emptyList()); private final AtomicReference defaultViewProvider = - new AtomicReference(); + new AtomicReference(); /** * Creates an instance of the component registry. This method @@ -148,6 +148,18 @@ public Set getViewInfos(String componentTypeId, ViewType type) { */ public Collection getComponentInfos() { return availableComponents.values(); + } + + + @Override + public T getAsset(Class objectClass, Class assetClass) { + for (ExtendedComponentProvider provider : activeProviders.get()) { + T asset = provider.getAsset(objectClass, assetClass); + if (asset != null) { + return asset; + } + } + return null; } /** @@ -312,7 +324,7 @@ public SearchProvider getSearchProvider() { } @Override - public T getAsset(Class objectType, Class assetType, Map hints) { + public T getAsset(Class objectType, Class assetType) { return null; } @@ -417,5 +429,6 @@ public AbstractComponent newInstance(String componentType) { LOGGER.info(e.getMessage()); } return null; - } + } + } diff --git a/mctcore/src/main/java/gov/nasa/arc/mct/services/component/AbstractComponentProvider.java b/mctcore/src/main/java/gov/nasa/arc/mct/services/component/AbstractComponentProvider.java index d121e296..0bc02a6c 100644 --- a/mctcore/src/main/java/gov/nasa/arc/mct/services/component/AbstractComponentProvider.java +++ b/mctcore/src/main/java/gov/nasa/arc/mct/services/component/AbstractComponentProvider.java @@ -26,7 +26,6 @@ import java.util.Collection; import java.util.Collections; -import java.util.Map; /** * An abstract class that implements ComponentProvider. @@ -72,7 +71,7 @@ public SearchProvider getSearchProvider() { } @Override - public T getAsset(Class type, Class assetClass, Map hints) { + public T getAsset(Class type, Class assetClass) { return null; } } diff --git a/mctcore/src/main/java/gov/nasa/arc/mct/services/component/ComponentProvider.java b/mctcore/src/main/java/gov/nasa/arc/mct/services/component/ComponentProvider.java index c888e5a0..762a35b8 100644 --- a/mctcore/src/main/java/gov/nasa/arc/mct/services/component/ComponentProvider.java +++ b/mctcore/src/main/java/gov/nasa/arc/mct/services/component/ComponentProvider.java @@ -25,7 +25,6 @@ import gov.nasa.arc.mct.policy.PolicyInfo; import java.util.Collection; -import java.util.Map; /** * This interface can be implemented as an OSGI service to provide one @@ -88,9 +87,9 @@ public interface ComponentProvider { * things like icons or create wizards which are associated with specific component or view * types, but are not incorporated into those types directly to preserve separation of * concerns. - * @param objectType - * @param assetType - * @return + * @param objectType the type with which the requested asset is associated + * @param assetType the type of the requested asset + * @return an asset of the requested type (or null, if none is provided) */ - T getAsset(Class objectType, Class assetType, Map hints); + T getAsset(Class objectType, Class assetType); } diff --git a/mctcore/src/main/java/gov/nasa/arc/mct/services/internal/component/CoreComponentRegistry.java b/mctcore/src/main/java/gov/nasa/arc/mct/services/internal/component/CoreComponentRegistry.java index e60a4707..c6a236de 100644 --- a/mctcore/src/main/java/gov/nasa/arc/mct/services/internal/component/CoreComponentRegistry.java +++ b/mctcore/src/main/java/gov/nasa/arc/mct/services/internal/component/CoreComponentRegistry.java @@ -53,5 +53,16 @@ public interface CoreComponentRegistry extends ComponentRegistry { * @param type to determine view info for. * @return applicable view infos */ - public Set getViewInfos(String componentTypeId, ViewType type); + public Set getViewInfos(String componentTypeId, ViewType type); + + /** + * Get an asset of a specific type, associated with some other type. + * For instance, this can be used to obtain an Icon + * for a specific component or view class. + * + * @param objectClass the type with which the asset is associated + * @param assetClass the type of the desired asset + * @return an asset of the desired type (or null if none is available) + */ + public T getAsset(Class objectClass, Class assetClass); } From 246b0c381986899dc2c26914363ce5687a56733e Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Mon, 9 Sep 2013 16:05:30 -0700 Subject: [PATCH 03/27] [Icons] Service getAsset from default provider --- .../ExternalComponentRegistryImpl.java | 2 +- .../services/component/ComponentTypeInfo.java | 5 +++-- .../defaults/view/DefaultViewProvider.java | 21 ++++++++++++++++++- .../arc/mct/platform/spi/MockPlatform.java | 6 ++++++ 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/mctcore/src/main/java/gov/nasa/arc/mct/registry/ExternalComponentRegistryImpl.java b/mctcore/src/main/java/gov/nasa/arc/mct/registry/ExternalComponentRegistryImpl.java index 1c14e816..0d0636f2 100644 --- a/mctcore/src/main/java/gov/nasa/arc/mct/registry/ExternalComponentRegistryImpl.java +++ b/mctcore/src/main/java/gov/nasa/arc/mct/registry/ExternalComponentRegistryImpl.java @@ -159,7 +159,7 @@ public T getAsset(Class objectClass, Class assetClass) { return asset; } } - return null; + return defaultViewProvider.get().getAsset(objectClass, assetClass); } /** diff --git a/mctcore/src/main/java/gov/nasa/arc/mct/services/component/ComponentTypeInfo.java b/mctcore/src/main/java/gov/nasa/arc/mct/services/component/ComponentTypeInfo.java index 113c4156..a511a2c6 100644 --- a/mctcore/src/main/java/gov/nasa/arc/mct/services/component/ComponentTypeInfo.java +++ b/mctcore/src/main/java/gov/nasa/arc/mct/services/component/ComponentTypeInfo.java @@ -24,6 +24,7 @@ import gov.nasa.arc.mct.components.AbstractComponent; +import gov.nasa.arc.mct.platform.spi.PlatformAccess; import gov.nasa.arc.mct.util.MCTIcons; import java.awt.Color; @@ -200,8 +201,8 @@ public final CreateWizardUI getWizardUI() { * Returns the image icon that represents this component type. * @return icon for component type */ - public final ImageIcon getIcon() { - return icon; + public final ImageIcon getIcon() { + return PlatformAccess.getPlatform().getComponentRegistry().getAsset(componentClass, ImageIcon.class); } @Override diff --git a/platform/src/main/java/gov/nasa/arc/mct/defaults/view/DefaultViewProvider.java b/platform/src/main/java/gov/nasa/arc/mct/defaults/view/DefaultViewProvider.java index 847e682f..149283cc 100644 --- a/platform/src/main/java/gov/nasa/arc/mct/defaults/view/DefaultViewProvider.java +++ b/platform/src/main/java/gov/nasa/arc/mct/defaults/view/DefaultViewProvider.java @@ -21,13 +21,17 @@ *******************************************************************************/ package gov.nasa.arc.mct.defaults.view; +import gov.nasa.arc.mct.components.AbstractComponent; +import gov.nasa.arc.mct.gui.View; import gov.nasa.arc.mct.gui.housing.InspectionArea; import gov.nasa.arc.mct.gui.housing.Inspector; import gov.nasa.arc.mct.gui.housing.MCTDirectoryArea; import gov.nasa.arc.mct.services.component.AbstractComponentProvider; import gov.nasa.arc.mct.services.component.ViewInfo; import gov.nasa.arc.mct.services.component.ViewType; +import gov.nasa.arc.mct.util.MCTIcons; +import java.awt.Color; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -65,5 +69,20 @@ public DefaultViewProvider() { public Collection getViews(String componentTypeId) { return myViewInfos; } - + + @Override + public T getAsset(Class type, Class assetClass) { + if (assetClass.isAssignableFrom(ImageIcon.class)) { + int sz = 16; + if (View.class.isAssignableFrom(type)) { + sz = 9; + } else if (AbstractComponent.class.isAssignableFrom(type)) { + sz = 14; + } + return assetClass.cast(MCTIcons.generateIcon( + type.getName().hashCode(), + sz, Color.ORANGE)); + } + return super.getAsset(type, assetClass); + } } diff --git a/tests/src/main/java/gov/nasa/arc/mct/platform/spi/MockPlatform.java b/tests/src/main/java/gov/nasa/arc/mct/platform/spi/MockPlatform.java index 0809ee6c..67002050 100644 --- a/tests/src/main/java/gov/nasa/arc/mct/platform/spi/MockPlatform.java +++ b/tests/src/main/java/gov/nasa/arc/mct/platform/spi/MockPlatform.java @@ -149,6 +149,12 @@ public AbstractComponent newInstance(String componentType) { public boolean isCreatable(Class clazz) { // TODO Auto-generated method stub return true; + } + + @Override + public T getAsset(Class objectClass, Class assetClass) { + // TODO Auto-generated method stub + return null; } }; From decc82a9902e90d5860a55140f954a65eab0d8ca Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Mon, 9 Sep 2013 16:15:42 -0700 Subject: [PATCH 04/27] [Icons] Process icon from node view --- .../nasa/arc/mct/components/AbstractComponent.java | 1 + .../mct/defaults/view/NodeViewManifestation.java | 13 ++++++++++--- .../main/java/gov/nasa/arc/mct/util/MCTIcons.java | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/mctcore/src/main/java/gov/nasa/arc/mct/components/AbstractComponent.java b/mctcore/src/main/java/gov/nasa/arc/mct/components/AbstractComponent.java index 657f30b7..d60905bd 100644 --- a/mctcore/src/main/java/gov/nasa/arc/mct/components/AbstractComponent.java +++ b/mctcore/src/main/java/gov/nasa/arc/mct/components/AbstractComponent.java @@ -888,6 +888,7 @@ public final ImageIcon getIcon() { * @param className of the component type * @return an image icon */ + @Deprecated public static ImageIcon getIconForComponentType(String className) { try { Class c = Class.forName(className); diff --git a/platform/src/main/java/gov/nasa/arc/mct/defaults/view/NodeViewManifestation.java b/platform/src/main/java/gov/nasa/arc/mct/defaults/view/NodeViewManifestation.java index 5c22a571..ee2a4166 100644 --- a/platform/src/main/java/gov/nasa/arc/mct/defaults/view/NodeViewManifestation.java +++ b/platform/src/main/java/gov/nasa/arc/mct/defaults/view/NodeViewManifestation.java @@ -37,6 +37,7 @@ import gov.nasa.arc.mct.services.component.PolicyManager; import gov.nasa.arc.mct.services.component.ViewInfo; import gov.nasa.arc.mct.services.component.ViewType; +import gov.nasa.arc.mct.util.MCTIcons; import gov.nasa.arc.mct.util.internal.ElapsedTimer; import java.awt.Dimension; @@ -48,6 +49,7 @@ import java.util.Set; import javax.swing.BoxLayout; +import javax.swing.ImageIcon; import javax.swing.JLabel; import javax.swing.JTree; import javax.swing.event.TreeExpansionEvent; @@ -92,18 +94,23 @@ public NodeViewManifestation(AbstractComponent component, ViewInfo viewinfo) { label = new JLabel(component.getExtendedDisplayName()); label.putClientProperty("TITLE", true); setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); - add(new JLabel(component.getIcon())); + add(new JLabel(getIcon(component))); add(spacebar); add(label); doLockRendering(label,component); setViewListener(new NodeViewManifestationListener()); addPropertyChangeListener(VIEW_STALE_PROPERTY, objectStaleListener); } + + private ImageIcon getIcon(AbstractComponent ac) { + ImageIcon baseIcon = PlatformAccess.getPlatform().getComponentRegistry().getAsset(ac.getClass(), ImageIcon.class); + return MCTIcons.processIcon(baseIcon, 1f, 0.25f, 1f, true); + } private void doLockRendering(JLabel widget, AbstractComponent comp) { - Font myFont = widget.getFont(); + widget.getFont(); if (comp != null) { - String id = comp.getId(); + comp.getId(); } } diff --git a/util/src/main/java/gov/nasa/arc/mct/util/MCTIcons.java b/util/src/main/java/gov/nasa/arc/mct/util/MCTIcons.java index 5b51f7d4..024ca872 100644 --- a/util/src/main/java/gov/nasa/arc/mct/util/MCTIcons.java +++ b/util/src/main/java/gov/nasa/arc/mct/util/MCTIcons.java @@ -244,6 +244,6 @@ public static ImageIcon processIcon(ImageIcon icon, float r, float g, float b, b return new ImageIcon(bufferedImage); } - + } From 96b265e162d37481302be837db8fb4ea20e975f1 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Mon, 9 Sep 2013 16:43:05 -0700 Subject: [PATCH 05/27] [Icons] Refactor icon processing Intermediary commit; refactor icon processing in order to support gradient fill in the future, and to cache icons based on the specific requested processing color etc. --- .../java/gov/nasa/arc/mct/util/MCTIcons.java | 122 ++++++++++++++++++ 1 file changed, 122 insertions(+) diff --git a/util/src/main/java/gov/nasa/arc/mct/util/MCTIcons.java b/util/src/main/java/gov/nasa/arc/mct/util/MCTIcons.java index 024ca872..da1286ce 100644 --- a/util/src/main/java/gov/nasa/arc/mct/util/MCTIcons.java +++ b/util/src/main/java/gov/nasa/arc/mct/util/MCTIcons.java @@ -52,6 +52,7 @@ public class MCTIcons { // Cache processed icons for later retrieval private static Map processedIcons = new HashMap(); + private static Map processedIconCache = new HashMap(); private static enum Icons { WARNING_ICON, @@ -245,5 +246,126 @@ public static ImageIcon processIcon(ImageIcon icon, float r, float g, float b, b return new ImageIcon(bufferedImage); } + + private static ImageIcon processIcon(ProcessDescription pd) { + ImageIcon icon = processedIconCache.get(pd); + + if (icon == null) { // Need to process and cache + icon = doProcessing(pd); + processedIconCache.put(pd, icon); + } + + return icon; + } + + private static ImageIcon doProcessing(ProcessDescription pd) { + // A processed null is still a null + if (pd.icon == null) { + return null; + } + + // Create a copy of the image with some extra padding for drop shadow + BufferedImage bufferedImage = new BufferedImage( + pd.icon.getIconWidth() + 2, + pd.icon.getIconHeight() + 2, + BufferedImage.TYPE_4BYTE_ABGR); + + if (pd.dropShadow) { + // Color rescale for shadowing + float preshadow[] = {0f,0f,0.25f,0.125f}; + float shadow[] = {0.1f,0.1f,0.1f,0.65f}; + float offset[] = {0f,0f,0f,0f}; + + // Draw the icon upper-left "shadow" (subtle outline) + pd.icon.paintIcon(null, bufferedImage.getGraphics(), 0, 0); + bufferedImage = new RescaleOp(preshadow, offset, null).filter(bufferedImage, null); + + // Draw the lower-right shadow + pd.icon.paintIcon(null, bufferedImage.getGraphics(), 2, 2); + bufferedImage = new RescaleOp(shadow, offset, null).filter(bufferedImage, null); + } + + // Repaint original icon + pd.icon.paintIcon(null, bufferedImage.getGraphics(), 1, 1); + + // Colorize + if (pd.firstColor != null) { + // Gradient fill + if (pd.secondColor != null && pd.secondColor.getRGB() != pd.firstColor.getRGB()) { + // TODO: Support gradient fill + } else { + // Convert color to scaling factor + int rgb = pd.firstColor.getRGB(); + float coloration[] = new float[4]; + for (int i = 0; i < coloration.length; i++) { + coloration[i] = (float) (rgb & 0xFF) / 255f; + rgb >>= 8; + } + float offset[] = {0f,0f,0f,0f}; + + // Repaint original icon & colorize + pd.icon.paintIcon(null, bufferedImage.getGraphics(), 1, 1); + bufferedImage = new RescaleOp(coloration, offset, null).filter(bufferedImage, null); + } + } + + return new ImageIcon(bufferedImage); + } + + /** + * Describes a set of processing arguments used upon an icon. + * Used to support a HashMap cache of already-processed icons. + * + */ + private static class ProcessDescription { + private ImageIcon icon; + private Color firstColor; + private Color secondColor; + private boolean dropShadow; + private int hash; + + public ProcessDescription(ImageIcon icon, Color firstColor, Color secondColor, boolean dropShadow) { + super(); + this.icon = icon; + this.firstColor = firstColor; + this.secondColor = secondColor; + this.dropShadow = dropShadow; + + hash = 0; + Object[] objects = {icon, firstColor, secondColor, dropShadow}; + for (Object o : objects) { + if (o != null) { + hash ^= o.hashCode(); + } + } + } + + @Override + public int hashCode() { + return hash; + } + + @Override + public boolean equals(Object o) { + if (o instanceof ProcessDescription) { + ProcessDescription p = (ProcessDescription) o; + return icon == p.icon && + colorsEqual(firstColor, p.firstColor) && + colorsEqual(secondColor, p.secondColor) && + dropShadow == p.dropShadow; + } + return false; + } + + private boolean colorsEqual(Color a, Color b) { + if (a == null) { + return b == null; + } else if (b == null) { + return false; + } else { + return a.getRGB() == b.getRGB(); + } + } + } } From 60ee67c7b9cee6e37031bbd983568baa64b04811 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Tue, 10 Sep 2013 17:11:13 -0700 Subject: [PATCH 06/27] [Icons] Break up icon processing --- .../java/gov/nasa/arc/mct/util/MCTIcons.java | 56 ++++++++++--------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/util/src/main/java/gov/nasa/arc/mct/util/MCTIcons.java b/util/src/main/java/gov/nasa/arc/mct/util/MCTIcons.java index da1286ce..d57ab895 100644 --- a/util/src/main/java/gov/nasa/arc/mct/util/MCTIcons.java +++ b/util/src/main/java/gov/nasa/arc/mct/util/MCTIcons.java @@ -217,35 +217,39 @@ public static ImageIcon processIcon(ImageIcon icon) { * @param dropShadow whether or not to add drop shadow * @return a processed icon */ - public static ImageIcon processIcon(ImageIcon icon, float r, float g, float b, boolean dropShadow) { - float coloration[] = {r,g,b,1f}; - float preshadow[] = {0f,0f,0.25f,0.125f}; - float shadow[] = {0.1f,0.1f,0.1f,0.65f}; - float offset[] = {0f,0f,0f,0f}; - - // Create a copy of the image with some extra padding for drop shadow - BufferedImage bufferedImage = new BufferedImage( - icon.getIconWidth() + 2, - icon.getIconHeight() + 2, - BufferedImage.TYPE_4BYTE_ABGR); + public static ImageIcon processIcon(ImageIcon icon, float r, float g, float b, boolean dropShadow) { + return processIcon(icon, new Color((int)(r * 255f),(int)(g*255f),(int)(b*255f)), dropShadow); + } - if (dropShadow) { - // Draw the icon upper-left "shadow" (subtle outline) - icon.paintIcon(null, bufferedImage.getGraphics(), 0, 0); - bufferedImage = new RescaleOp(preshadow, offset, null).filter(bufferedImage, null); - - // Draw the lower-right shadow - icon.paintIcon(null, bufferedImage.getGraphics(), 2, 2); - bufferedImage = new RescaleOp(shadow, offset, null).filter(bufferedImage, null); - } - - // Repaint original icon & colorize - icon.paintIcon(null, bufferedImage.getGraphics(), 1, 1); - bufferedImage = new RescaleOp(coloration, offset, null).filter(bufferedImage, null); - - return new ImageIcon(bufferedImage); + /** + * Process the given icon to be consistent with MCT + * icon look and feel. Desired color can be specified + * and drop shadow can be enabled / disabled. + * + * @param icon the icon to process + * @param c desired color + * @param dropShadow whether or not to add drop shadow + * @return a processed icon + */ + public static ImageIcon processIcon(ImageIcon icon, Color c, boolean dropShadow) { + return processIcon(new ProcessDescription(icon, c, c, dropShadow)); } + /** + * Process the given icon to be consistent with MCT + * icon look and feel. Desired color is specified for + * a gradient fill from top to bottom, and + * drop shadow can be enabled / disabled. + * + * @param icon the icon to process + * @param top color for top of icon + * @param bottom color for bottom of icon + * @param dropShadow whether or not to add drop shadow + * @return a processed icon + */ + public static ImageIcon processIcon(ImageIcon icon, Color top, Color bottom, boolean dropShadow) { + return processIcon(new ProcessDescription(icon, top, bottom, dropShadow)); + } private static ImageIcon processIcon(ProcessDescription pd) { ImageIcon icon = processedIconCache.get(pd); From 486f7b379fec84e93f151204f1906d1592a45641 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Tue, 10 Sep 2013 17:28:20 -0700 Subject: [PATCH 07/27] [Icons] Add getAsset to AbstractComponent --- .../arc/mct/components/AbstractComponent.java | 12 ++++- .../arc/mct/gui/menu/housing/IconMenu.java | 53 ++++++++++--------- .../java/gov/nasa/arc/mct/util/MCTIcons.java | 2 +- 3 files changed, 41 insertions(+), 26 deletions(-) diff --git a/mctcore/src/main/java/gov/nasa/arc/mct/components/AbstractComponent.java b/mctcore/src/main/java/gov/nasa/arc/mct/components/AbstractComponent.java index d60905bd..992d6184 100644 --- a/mctcore/src/main/java/gov/nasa/arc/mct/components/AbstractComponent.java +++ b/mctcore/src/main/java/gov/nasa/arc/mct/components/AbstractComponent.java @@ -871,10 +871,20 @@ public int getVersion() { return version; } + /** + * Get an asset of a specified type. For instance, an + * Icon may be retrieved using getAsset(Icon.class). + * @param assetType the desired type of asset + * @return an asset of the desired type (or null if there is none) + */ + public final T getAsset(Class assetType) { + return ExternalComponentRegistryImpl.getInstance().getAsset(getClass(), assetType); + } + /** * Returns the icon image for this component. * @return an icon image - * @deprecated use PlatformAccess.getPlatform().getComponentRegistry().getAsset() instead + * @deprecated use getAsset(Icon.class) instead */ @Deprecated public final ImageIcon getIcon() { diff --git a/platform/src/main/java/gov/nasa/arc/mct/gui/menu/housing/IconMenu.java b/platform/src/main/java/gov/nasa/arc/mct/gui/menu/housing/IconMenu.java index 4eda6a09..2f142710 100644 --- a/platform/src/main/java/gov/nasa/arc/mct/gui/menu/housing/IconMenu.java +++ b/platform/src/main/java/gov/nasa/arc/mct/gui/menu/housing/IconMenu.java @@ -21,39 +21,44 @@ *******************************************************************************/ package gov.nasa.arc.mct.gui.menu.housing; -import gov.nasa.arc.mct.gui.ActionContext; -import gov.nasa.arc.mct.gui.ContextAwareMenu; -import gov.nasa.arc.mct.gui.MenuItemInfo; -import gov.nasa.arc.mct.gui.MenuItemInfo.MenuItemType; -import gov.nasa.arc.mct.gui.View; -import gov.nasa.arc.mct.gui.ViewRoleSelection; -import gov.nasa.arc.mct.gui.housing.MCTContentArea; -import gov.nasa.arc.mct.gui.housing.MCTStandardHousing; -import gov.nasa.arc.mct.platform.spi.PlatformAccess; -import gov.nasa.arc.mct.policy.ExecutionResult; -import gov.nasa.arc.mct.policy.PolicyContext; -import gov.nasa.arc.mct.policy.PolicyInfo; -import gov.nasa.arc.mct.policymgr.PolicyManagerImpl; - -import java.awt.Container; -import java.awt.datatransfer.Transferable; -import java.awt.event.MouseEvent; -import java.awt.event.MouseMotionAdapter; -import java.util.Collections; - -import javax.swing.JComponent; -import javax.swing.TransferHandler; +import gov.nasa.arc.mct.gui.ActionContext; +import gov.nasa.arc.mct.gui.ContextAwareMenu; +import gov.nasa.arc.mct.gui.MenuItemInfo; +import gov.nasa.arc.mct.gui.MenuItemInfo.MenuItemType; +import gov.nasa.arc.mct.gui.View; +import gov.nasa.arc.mct.gui.ViewRoleSelection; +import gov.nasa.arc.mct.gui.housing.MCTContentArea; +import gov.nasa.arc.mct.gui.housing.MCTStandardHousing; +import gov.nasa.arc.mct.platform.spi.PlatformAccess; +import gov.nasa.arc.mct.policy.ExecutionResult; +import gov.nasa.arc.mct.policy.PolicyContext; +import gov.nasa.arc.mct.policy.PolicyInfo; +import gov.nasa.arc.mct.policymgr.PolicyManagerImpl; +import gov.nasa.arc.mct.util.MCTIcons; + +import java.awt.Color; +import java.awt.Container; +import java.awt.datatransfer.Transferable; +import java.awt.event.MouseEvent; +import java.awt.event.MouseMotionAdapter; +import java.util.Collections; + +import javax.swing.ImageIcon; +import javax.swing.JComponent; +import javax.swing.TransferHandler; @SuppressWarnings("serial") public class IconMenu extends ContextAwareMenu { + private static final Color ICON_COLOR = new Color(40, 40, 40); public IconMenu() { super(""); } @Override - public boolean canHandle(final ActionContext context) { - setIcon(context.getWindowManifestation().getManifestedComponent().getIcon()); + public boolean canHandle(final ActionContext context) { + ImageIcon icon = context.getWindowManifestation().getManifestedComponent().getAsset(ImageIcon.class); + setIcon(MCTIcons.processIcon(icon, ICON_COLOR, false)); setTransferHandler(new TransferHandler() { @Override diff --git a/util/src/main/java/gov/nasa/arc/mct/util/MCTIcons.java b/util/src/main/java/gov/nasa/arc/mct/util/MCTIcons.java index d57ab895..56a74230 100644 --- a/util/src/main/java/gov/nasa/arc/mct/util/MCTIcons.java +++ b/util/src/main/java/gov/nasa/arc/mct/util/MCTIcons.java @@ -303,7 +303,7 @@ private static ImageIcon doProcessing(ProcessDescription pd) { float coloration[] = new float[4]; for (int i = 0; i < coloration.length; i++) { coloration[i] = (float) (rgb & 0xFF) / 255f; - rgb >>= 8; + rgb >>>= 8; } float offset[] = {0f,0f,0f,0f}; From 94c0abccfaf36718d8ad365870d626d2762253a5 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Tue, 10 Sep 2013 17:39:24 -0700 Subject: [PATCH 08/27] [Icons] Add getAsset to type info classes --- .../services/component/ComponentTypeInfo.java | 27 ++++++++++++++----- .../arc/mct/services/component/ViewInfo.java | 15 ++++++++++- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/mctcore/src/main/java/gov/nasa/arc/mct/services/component/ComponentTypeInfo.java b/mctcore/src/main/java/gov/nasa/arc/mct/services/component/ComponentTypeInfo.java index a511a2c6..b4c854eb 100644 --- a/mctcore/src/main/java/gov/nasa/arc/mct/services/component/ComponentTypeInfo.java +++ b/mctcore/src/main/java/gov/nasa/arc/mct/services/component/ComponentTypeInfo.java @@ -191,19 +191,34 @@ public final boolean isCreatable() { /** * Returns wizard providing UI and action performed after creating. If null, a default wizard is used. - * @return wizard for UI - */ + * @return wizard for UI + * @deprecated use getAsset(CreateWizardUI.class) instead + */ + @Deprecated public final CreateWizardUI getWizardUI() { - return wizard; + return getAsset(CreateWizardUI.class); } /** * Returns the image icon that represents this component type. - * @return icon for component type - */ + * @return icon for component type + * @deprecated use getAsset(ImageIcon.class) instead + */ + @Deprecated public final ImageIcon getIcon() { - return PlatformAccess.getPlatform().getComponentRegistry().getAsset(componentClass, ImageIcon.class); + return getAsset(ImageIcon.class); } + + /** + * Get an asset associated with this view type. + * For instance, getAsset(ImageIcon.class) to get + * an icon for this view. + * @param assetClass the type of asset desired + * @return an object of the desired type (or null if none is available) + */ + public T getAsset(Class assetClass) { + return PlatformAccess.getPlatform().getComponentRegistry().getAsset(componentClass, assetClass); + } @Override public final boolean equals(Object obj) { diff --git a/mctcore/src/main/java/gov/nasa/arc/mct/services/component/ViewInfo.java b/mctcore/src/main/java/gov/nasa/arc/mct/services/component/ViewInfo.java index 36555f14..b2810396 100644 --- a/mctcore/src/main/java/gov/nasa/arc/mct/services/component/ViewInfo.java +++ b/mctcore/src/main/java/gov/nasa/arc/mct/services/component/ViewInfo.java @@ -23,6 +23,7 @@ import gov.nasa.arc.mct.components.AbstractComponent; import gov.nasa.arc.mct.gui.View; +import gov.nasa.arc.mct.platform.spi.PlatformAccess; import gov.nasa.arc.mct.util.LookAndFeelSettings; import gov.nasa.arc.mct.util.MCTIcons; @@ -243,7 +244,8 @@ public View call() throws Exception { /** * Returns the icon to be placed in a button for this view. * @return icon; null if no provided - */ + */ + @Deprecated public ImageIcon getIcon() { return icon; } @@ -265,6 +267,17 @@ public ImageIcon getSelectedIcon() { public boolean shouldExpandCenterPaneInWindow() { return shouldExpandCenterPaneInWindow; } + + /** + * Get an asset associated with this view type. + * For instance, getAsset(ImageIcon.class) to get + * an icon for this view. + * @param assetClass the type of asset desired + * @return an object of the desired type (or null if none is available) + */ + public T getAsset(Class assetClass) { + return PlatformAccess.getPlatform().getComponentRegistry().getAsset(getViewClass(), assetClass); + } private Constructor getConstructor(Class viewClass) { Constructor c = null; From bf0432b80d7ed4a5bf3c6740595b55a151f1d05c Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Wed, 11 Sep 2013 10:54:28 -0700 Subject: [PATCH 09/27] [Icons] Add abstract class TypeInfo Adds the abstract superclass TypeInfo for ComponentTypeInfo, ViewInfo, etc. Serves as a common container for class information, and supports getAsset() calls (without requiring these shorthands to be implemented separately for every type described in this manner.) Future enhancements may include support for PolicyInfo, and addition of ActionInfo. --- .../arc/mct/components/AbstractComponent.java | 41 ++++++----- .../ExternalComponentRegistryImpl.java | 9 +-- .../component/AbstractComponentProvider.java | 2 +- .../services/component/ComponentProvider.java | 4 +- .../services/component/ComponentTypeInfo.java | 21 +----- .../arc/mct/services/component/TypeInfo.java | 72 +++++++++++++++++++ .../arc/mct/services/component/ViewInfo.java | 15 +--- .../component/CoreComponentRegistry.java | 19 ++--- .../defaults/view/DefaultViewProvider.java | 9 +-- .../defaults/view/NodeViewManifestation.java | 2 +- .../arc/mct/platform/spi/MockPlatform.java | 3 +- 11 files changed, 128 insertions(+), 69 deletions(-) create mode 100644 mctcore/src/main/java/gov/nasa/arc/mct/services/component/TypeInfo.java diff --git a/mctcore/src/main/java/gov/nasa/arc/mct/components/AbstractComponent.java b/mctcore/src/main/java/gov/nasa/arc/mct/components/AbstractComponent.java index 992d6184..412d79b8 100644 --- a/mctcore/src/main/java/gov/nasa/arc/mct/components/AbstractComponent.java +++ b/mctcore/src/main/java/gov/nasa/arc/mct/components/AbstractComponent.java @@ -40,12 +40,12 @@ import gov.nasa.arc.mct.roles.events.AddChildEvent; import gov.nasa.arc.mct.roles.events.PropertyChangeEvent; import gov.nasa.arc.mct.roles.events.RemoveChildEvent; +import gov.nasa.arc.mct.services.component.ComponentTypeInfo; import gov.nasa.arc.mct.services.component.PolicyManager; import gov.nasa.arc.mct.services.component.ViewInfo; import gov.nasa.arc.mct.services.component.ViewType; import gov.nasa.arc.mct.services.internal.component.ComponentInitializer; import gov.nasa.arc.mct.services.internal.component.Updatable; -import gov.nasa.arc.mct.util.MCTIcons; import gov.nasa.arc.mct.util.WeakHashSet; import gov.nasa.arc.mct.util.exception.MCTRuntimeException; @@ -95,6 +95,7 @@ public abstract class AbstractComponent implements Cloneable { /** The unique ID of the component, filled in by the framework. */ private String id; + private ComponentTypeInfo typeInfo; private String owner; private String originalOwner; private String creator; @@ -170,7 +171,7 @@ public AbstractComponent getWorkUnitDelegate() { public String getComponentTypeID() { return this.getClass().getName(); } - + /** * Returns the views for the desired view type. This method will apply the PolicyInfo.CategoryType.FILTER_VIEW_ROLE policy * and the PolicyInfo.CategoryType.PREFERRED_VIEW policy before returning the appropriate list of views. @@ -708,6 +709,17 @@ public final T getCapability(Class capability) { initializer = new Initializer(); } return capability.cast(initializer); + } else if (capability.isAssignableFrom(ComponentTypeInfo.class)) { + if (typeInfo == null) { + for (ComponentTypeInfo info : + ExternalComponentRegistryImpl.getInstance().getComponentInfos()) { + if (info != null) { + typeInfo = info; + break; + } + } + } + return capability.cast(typeInfo); } return handleGetCapability(capability); @@ -874,11 +886,11 @@ public int getVersion() { /** * Get an asset of a specified type. For instance, an * Icon may be retrieved using getAsset(Icon.class). - * @param assetType the desired type of asset + * @param assetClass the desired type of asset * @return an asset of the desired type (or null if there is none) */ - public final T getAsset(Class assetType) { - return ExternalComponentRegistryImpl.getInstance().getAsset(getClass(), assetType); + public T getAsset(Class assetClass) { + return getCapability(ComponentTypeInfo.class).getAsset(assetClass); } /** @@ -888,9 +900,7 @@ public final T getAsset(Class assetType) { */ @Deprecated public final ImageIcon getIcon() { - ImageIcon icon = ExternalComponentRegistryImpl.getInstance() - .getAsset(getClass(), ImageIcon.class); - return icon != null ? icon : MCTIcons.getComponent(); + return getAsset(ImageIcon.class); } /** @@ -900,14 +910,13 @@ public final ImageIcon getIcon() { */ @Deprecated public static ImageIcon getIconForComponentType(String className) { - try { - Class c = Class.forName(className); - ImageIcon icon = ExternalComponentRegistryImpl.getInstance() - .getAsset(c, ImageIcon.class); - return icon != null ? icon : MCTIcons.getComponent(); - } catch (ClassNotFoundException e) { - return MCTIcons.getComponent(); - } + for (ComponentTypeInfo componentTypeInfo : + ExternalComponentRegistryImpl.getInstance().getComponentInfos()) { + if (componentTypeInfo.getTypeClass().getName().equals(className)) { + return componentTypeInfo.getAsset(ImageIcon.class); + } + } + return null; } /** diff --git a/mctcore/src/main/java/gov/nasa/arc/mct/registry/ExternalComponentRegistryImpl.java b/mctcore/src/main/java/gov/nasa/arc/mct/registry/ExternalComponentRegistryImpl.java index 0d0636f2..5826003a 100644 --- a/mctcore/src/main/java/gov/nasa/arc/mct/registry/ExternalComponentRegistryImpl.java +++ b/mctcore/src/main/java/gov/nasa/arc/mct/registry/ExternalComponentRegistryImpl.java @@ -33,6 +33,7 @@ import gov.nasa.arc.mct.services.component.ProviderDelegate; import gov.nasa.arc.mct.services.component.SearchProvider; import gov.nasa.arc.mct.services.component.StatusAreaWidgetInfo; +import gov.nasa.arc.mct.services.component.TypeInfo; import gov.nasa.arc.mct.services.component.ViewInfo; import gov.nasa.arc.mct.services.component.ViewType; import gov.nasa.arc.mct.services.internal.component.ComponentInitializer; @@ -152,14 +153,14 @@ public Collection getComponentInfos() { @Override - public T getAsset(Class objectClass, Class assetClass) { + public T getAsset(TypeInfo objectType, Class assetClass) { for (ExtendedComponentProvider provider : activeProviders.get()) { - T asset = provider.getAsset(objectClass, assetClass); + T asset = provider.getAsset(objectType, assetClass); if (asset != null) { return asset; } } - return defaultViewProvider.get().getAsset(objectClass, assetClass); + return defaultViewProvider.get().getAsset(objectType, assetClass); } /** @@ -324,7 +325,7 @@ public SearchProvider getSearchProvider() { } @Override - public T getAsset(Class objectType, Class assetType) { + public T getAsset(TypeInfo objectType, Class assetType) { return null; } diff --git a/mctcore/src/main/java/gov/nasa/arc/mct/services/component/AbstractComponentProvider.java b/mctcore/src/main/java/gov/nasa/arc/mct/services/component/AbstractComponentProvider.java index 0bc02a6c..4a5546ea 100644 --- a/mctcore/src/main/java/gov/nasa/arc/mct/services/component/AbstractComponentProvider.java +++ b/mctcore/src/main/java/gov/nasa/arc/mct/services/component/AbstractComponentProvider.java @@ -71,7 +71,7 @@ public SearchProvider getSearchProvider() { } @Override - public T getAsset(Class type, Class assetClass) { + public T getAsset(TypeInfo type, Class assetClass) { return null; } } diff --git a/mctcore/src/main/java/gov/nasa/arc/mct/services/component/ComponentProvider.java b/mctcore/src/main/java/gov/nasa/arc/mct/services/component/ComponentProvider.java index 762a35b8..fe0711bc 100644 --- a/mctcore/src/main/java/gov/nasa/arc/mct/services/component/ComponentProvider.java +++ b/mctcore/src/main/java/gov/nasa/arc/mct/services/component/ComponentProvider.java @@ -88,8 +88,8 @@ public interface ComponentProvider { * types, but are not incorporated into those types directly to preserve separation of * concerns. * @param objectType the type with which the requested asset is associated - * @param assetType the type of the requested asset + * @param assetClass the type of the requested asset * @return an asset of the requested type (or null, if none is provided) */ - T getAsset(Class objectType, Class assetType); + T getAsset(TypeInfo objectType, Class assetClass); } diff --git a/mctcore/src/main/java/gov/nasa/arc/mct/services/component/ComponentTypeInfo.java b/mctcore/src/main/java/gov/nasa/arc/mct/services/component/ComponentTypeInfo.java index b4c854eb..f7f88cb5 100644 --- a/mctcore/src/main/java/gov/nasa/arc/mct/services/component/ComponentTypeInfo.java +++ b/mctcore/src/main/java/gov/nasa/arc/mct/services/component/ComponentTypeInfo.java @@ -21,10 +21,7 @@ *******************************************************************************/ package gov.nasa.arc.mct.services.component; - - import gov.nasa.arc.mct.components.AbstractComponent; -import gov.nasa.arc.mct.platform.spi.PlatformAccess; import gov.nasa.arc.mct.util.MCTIcons; import java.awt.Color; @@ -37,13 +34,12 @@ * @author chris.webster@nasa.gov * */ -public class ComponentTypeInfo { +public class ComponentTypeInfo extends TypeInfo { private static final int ICON_SIZE = 14; private static final Color BASE_ICON_COLOR = Color.WHITE; private final String displayName; private final String description; - private final Class componentClass; private final String componentTypeId; private final boolean isCreatable; private final CreateWizardUI wizard; @@ -119,6 +115,7 @@ public ComponentTypeInfo(String displayName, String description, ClassAbstractComponent */ protected ComponentTypeInfo(String displayName, String description, Class componentClass, String id, boolean isCreatable, CreateWizardUI wizard, ImageIcon icon) throws IllegalArgumentException { + super(componentClass); if (componentClass == null) { throw new IllegalArgumentException("componentClass must not be null"); } @@ -132,7 +129,6 @@ protected ComponentTypeInfo(String displayName, String description, Class getComponentClass() { - return componentClass; + return getTypeClass(); } /** @@ -208,17 +204,6 @@ public final CreateWizardUI getWizardUI() { public final ImageIcon getIcon() { return getAsset(ImageIcon.class); } - - /** - * Get an asset associated with this view type. - * For instance, getAsset(ImageIcon.class) to get - * an icon for this view. - * @param assetClass the type of asset desired - * @return an object of the desired type (or null if none is available) - */ - public T getAsset(Class assetClass) { - return PlatformAccess.getPlatform().getComponentRegistry().getAsset(componentClass, assetClass); - } @Override public final boolean equals(Object obj) { diff --git a/mctcore/src/main/java/gov/nasa/arc/mct/services/component/TypeInfo.java b/mctcore/src/main/java/gov/nasa/arc/mct/services/component/TypeInfo.java new file mode 100644 index 00000000..daab47dd --- /dev/null +++ b/mctcore/src/main/java/gov/nasa/arc/mct/services/component/TypeInfo.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * Mission Control Technologies, Copyright (c) 2009-2012, United States Government + * as represented by the Administrator of the National Aeronautics and Space + * Administration. All rights reserved. + * + * The MCT platform is licensed under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + * + * MCT includes source code licensed under additional open source licenses. See + * the MCT Open Source Licenses file included with this distribution or the About + * MCT Licenses dialog available at runtime from the MCT Help menu for additional + * information. + *******************************************************************************/ +package gov.nasa.arc.mct.services.component; + +import gov.nasa.arc.mct.platform.spi.PlatformAccess; + +/** + * Provides information about a type relevant to MCT. + * Serves as an abstract superclass for ComponentTypeInfo, + * ViewInfo, and PolicyInfo, allowing these to be dealt + * with in a unified manner where appropriate. + * + * This should typically be parameterized with a high-level + * class (such as AbstractComponent, View, or Policy) + * and given a specific concrete subclass thereof in the + * constructor. + * + * @author vwoeltje + * + * @param the class which characterizes these types + */ +public abstract class TypeInfo { + private Class typeClass; + + /** + * Instantiate a new new TypeInfo object for the + * specified class. + * @param typeClass the specific class being described + */ + public TypeInfo(Class typeClass) { + this.typeClass = typeClass; + } + + /** + * Get the specific class being described by this + * type info. + * @return the specific class being described + */ + public Class getTypeClass() { + return typeClass; + } + + /** + * Get an asset associated with this type. + * For instance, getAsset(ImageIcon.class) to get + * an icon. + * @param assetClass the type of asset desired + * @return an object of the desired type (or null if none is available) + */ + public A getAsset(Class assetClass) { + return PlatformAccess.getPlatform().getComponentRegistry().getAsset(this, assetClass); + } +} diff --git a/mctcore/src/main/java/gov/nasa/arc/mct/services/component/ViewInfo.java b/mctcore/src/main/java/gov/nasa/arc/mct/services/component/ViewInfo.java index b2810396..160c776e 100644 --- a/mctcore/src/main/java/gov/nasa/arc/mct/services/component/ViewInfo.java +++ b/mctcore/src/main/java/gov/nasa/arc/mct/services/component/ViewInfo.java @@ -23,7 +23,6 @@ import gov.nasa.arc.mct.components.AbstractComponent; import gov.nasa.arc.mct.gui.View; -import gov.nasa.arc.mct.platform.spi.PlatformAccess; import gov.nasa.arc.mct.util.LookAndFeelSettings; import gov.nasa.arc.mct.util.MCTIcons; @@ -38,7 +37,7 @@ * The ViewInfo class describes metadata about a view. This class is used to create new view instances. * */ -public class ViewInfo { +public class ViewInfo extends TypeInfo { private static final int ICON_SIZE = 9; private static final Color BASE_ICON_COLOR = Color.WHITE; @@ -143,6 +142,7 @@ public ViewInfo(Class aViewClass, String name, String aType, Vie * @throws IllegalArgumentException if the view type is null or the class doesn't have the right type of constructor */ public ViewInfo(Class aViewClass, String name, String aType, ViewType viewType, ImageIcon icon, ImageIcon selectedIcon, boolean shouldExpandCenterPaneInWindow, Class preferredComponentType) throws IllegalArgumentException { + super(aViewClass); type = aType; viewName = name; this.icon = MCTIcons.processIcon( @@ -267,17 +267,6 @@ public ImageIcon getSelectedIcon() { public boolean shouldExpandCenterPaneInWindow() { return shouldExpandCenterPaneInWindow; } - - /** - * Get an asset associated with this view type. - * For instance, getAsset(ImageIcon.class) to get - * an icon for this view. - * @param assetClass the type of asset desired - * @return an object of the desired type (or null if none is available) - */ - public T getAsset(Class assetClass) { - return PlatformAccess.getPlatform().getComponentRegistry().getAsset(getViewClass(), assetClass); - } private Constructor getConstructor(Class viewClass) { Constructor c = null; diff --git a/mctcore/src/main/java/gov/nasa/arc/mct/services/internal/component/CoreComponentRegistry.java b/mctcore/src/main/java/gov/nasa/arc/mct/services/internal/component/CoreComponentRegistry.java index c6a236de..c33b426b 100644 --- a/mctcore/src/main/java/gov/nasa/arc/mct/services/internal/component/CoreComponentRegistry.java +++ b/mctcore/src/main/java/gov/nasa/arc/mct/services/internal/component/CoreComponentRegistry.java @@ -21,13 +21,14 @@ *******************************************************************************/ package gov.nasa.arc.mct.services.internal.component; -import gov.nasa.arc.mct.components.AbstractComponent; -import gov.nasa.arc.mct.services.component.ComponentRegistry; -import gov.nasa.arc.mct.services.component.ComponentTypeInfo; -import gov.nasa.arc.mct.services.component.ViewInfo; -import gov.nasa.arc.mct.services.component.ViewType; - -import java.util.Set; +import gov.nasa.arc.mct.components.AbstractComponent; +import gov.nasa.arc.mct.services.component.ComponentRegistry; +import gov.nasa.arc.mct.services.component.ComponentTypeInfo; +import gov.nasa.arc.mct.services.component.TypeInfo; +import gov.nasa.arc.mct.services.component.ViewInfo; +import gov.nasa.arc.mct.services.component.ViewType; + +import java.util.Set; /** * This interface extends the ComponentRegistry interface to provide additional @@ -60,9 +61,9 @@ public interface CoreComponentRegistry extends ComponentRegistry { * For instance, this can be used to obtain an Icon * for a specific component or view class. * - * @param objectClass the type with which the asset is associated + * @param objectType the type with which the asset is associated * @param assetClass the type of the desired asset * @return an asset of the desired type (or null if none is available) */ - public T getAsset(Class objectClass, Class assetClass); + public T getAsset(TypeInfo objectType, Class assetClass); } diff --git a/platform/src/main/java/gov/nasa/arc/mct/defaults/view/DefaultViewProvider.java b/platform/src/main/java/gov/nasa/arc/mct/defaults/view/DefaultViewProvider.java index 149283cc..a5e63a8e 100644 --- a/platform/src/main/java/gov/nasa/arc/mct/defaults/view/DefaultViewProvider.java +++ b/platform/src/main/java/gov/nasa/arc/mct/defaults/view/DefaultViewProvider.java @@ -27,6 +27,7 @@ import gov.nasa.arc.mct.gui.housing.Inspector; import gov.nasa.arc.mct.gui.housing.MCTDirectoryArea; import gov.nasa.arc.mct.services.component.AbstractComponentProvider; +import gov.nasa.arc.mct.services.component.TypeInfo; import gov.nasa.arc.mct.services.component.ViewInfo; import gov.nasa.arc.mct.services.component.ViewType; import gov.nasa.arc.mct.util.MCTIcons; @@ -71,16 +72,16 @@ public Collection getViews(String componentTypeId) { } @Override - public T getAsset(Class type, Class assetClass) { + public T getAsset(TypeInfo type, Class assetClass) { if (assetClass.isAssignableFrom(ImageIcon.class)) { int sz = 16; - if (View.class.isAssignableFrom(type)) { + if (View.class.isAssignableFrom(type.getTypeClass())) { sz = 9; - } else if (AbstractComponent.class.isAssignableFrom(type)) { + } else if (AbstractComponent.class.isAssignableFrom(type.getTypeClass())) { sz = 14; } return assetClass.cast(MCTIcons.generateIcon( - type.getName().hashCode(), + type.getTypeClass().getName().hashCode(), sz, Color.ORANGE)); } return super.getAsset(type, assetClass); diff --git a/platform/src/main/java/gov/nasa/arc/mct/defaults/view/NodeViewManifestation.java b/platform/src/main/java/gov/nasa/arc/mct/defaults/view/NodeViewManifestation.java index ee2a4166..eab4d2d4 100644 --- a/platform/src/main/java/gov/nasa/arc/mct/defaults/view/NodeViewManifestation.java +++ b/platform/src/main/java/gov/nasa/arc/mct/defaults/view/NodeViewManifestation.java @@ -103,7 +103,7 @@ public NodeViewManifestation(AbstractComponent component, ViewInfo viewinfo) { } private ImageIcon getIcon(AbstractComponent ac) { - ImageIcon baseIcon = PlatformAccess.getPlatform().getComponentRegistry().getAsset(ac.getClass(), ImageIcon.class); + ImageIcon baseIcon = ac.getAsset(ImageIcon.class); return MCTIcons.processIcon(baseIcon, 1f, 0.25f, 1f, true); } diff --git a/tests/src/main/java/gov/nasa/arc/mct/platform/spi/MockPlatform.java b/tests/src/main/java/gov/nasa/arc/mct/platform/spi/MockPlatform.java index 67002050..ae33b2ef 100644 --- a/tests/src/main/java/gov/nasa/arc/mct/platform/spi/MockPlatform.java +++ b/tests/src/main/java/gov/nasa/arc/mct/platform/spi/MockPlatform.java @@ -33,6 +33,7 @@ import gov.nasa.arc.mct.services.component.MenuManager; import gov.nasa.arc.mct.services.component.PolicyManager; import gov.nasa.arc.mct.services.component.ProviderDelegateService; +import gov.nasa.arc.mct.services.component.TypeInfo; import gov.nasa.arc.mct.services.component.ViewInfo; import gov.nasa.arc.mct.services.component.ViewType; import gov.nasa.arc.mct.services.internal.component.CoreComponentRegistry; @@ -152,7 +153,7 @@ public boolean isCreatable(Class clazz) { } @Override - public T getAsset(Class objectClass, Class assetClass) { + public T getAsset(TypeInfo objectType, Class assetClass) { // TODO Auto-generated method stub return null; } From ade08df12755ba3e7822a3c4acac17db9d22788f Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Wed, 11 Sep 2013 11:17:35 -0700 Subject: [PATCH 10/27] [Icons] Remove references to AbstractComponent.getIcon --- .../mct/canvas/panel/TransferableIcon.java | 53 ++++++++++--------- .../arc/mct/canvas/view/PanelInspector.java | 5 +- .../arc/mct/components/AbstractComponent.java | 10 ++-- .../nasa/arc/mct/gui/housing/Inspector.java | 6 ++- .../mct/gui/housing/MCTStandardHousing.java | 16 ++++-- .../java/gov/nasa/arc/mct/util/MCTIcons.java | 2 +- 6 files changed, 54 insertions(+), 38 deletions(-) diff --git a/canvas/src/main/java/gov/nasa/arc/mct/canvas/panel/TransferableIcon.java b/canvas/src/main/java/gov/nasa/arc/mct/canvas/panel/TransferableIcon.java index 816d1895..32b2b217 100644 --- a/canvas/src/main/java/gov/nasa/arc/mct/canvas/panel/TransferableIcon.java +++ b/canvas/src/main/java/gov/nasa/arc/mct/canvas/panel/TransferableIcon.java @@ -21,28 +21,31 @@ *******************************************************************************/ package gov.nasa.arc.mct.canvas.panel; -import gov.nasa.arc.mct.components.AbstractComponent; -import gov.nasa.arc.mct.gui.View; -import gov.nasa.arc.mct.gui.ViewRoleSelection; -import gov.nasa.arc.mct.platform.spi.Platform; -import gov.nasa.arc.mct.platform.spi.PlatformAccess; -import gov.nasa.arc.mct.policy.ExecutionResult; -import gov.nasa.arc.mct.policy.PolicyContext; -import gov.nasa.arc.mct.policy.PolicyInfo; -import gov.nasa.arc.mct.services.component.PolicyManager; - -import java.awt.Container; -import java.awt.datatransfer.Transferable; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.awt.event.MouseMotionAdapter; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.atomic.AtomicBoolean; - -import javax.swing.JComponent; -import javax.swing.JLabel; -import javax.swing.TransferHandler; +import gov.nasa.arc.mct.components.AbstractComponent; +import gov.nasa.arc.mct.gui.View; +import gov.nasa.arc.mct.gui.ViewRoleSelection; +import gov.nasa.arc.mct.platform.spi.Platform; +import gov.nasa.arc.mct.platform.spi.PlatformAccess; +import gov.nasa.arc.mct.policy.ExecutionResult; +import gov.nasa.arc.mct.policy.PolicyContext; +import gov.nasa.arc.mct.policy.PolicyInfo; +import gov.nasa.arc.mct.services.component.PolicyManager; +import gov.nasa.arc.mct.util.MCTIcons; + +import java.awt.Color; +import java.awt.Container; +import java.awt.datatransfer.Transferable; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.MouseMotionAdapter; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; + +import javax.swing.ImageIcon; +import javax.swing.JComponent; +import javax.swing.JLabel; +import javax.swing.TransferHandler; /** * This class provides an icon view that supports the transferable protocol required for drag and drop. Instances of this @@ -52,7 +55,9 @@ */ public class TransferableIcon extends JLabel { private static final long serialVersionUID = -7380332900682920418L; - + private static final Color ICON_COLOR = new Color(230,230,230); + + /** * This method creates a new Transferable Icon. * @param referencedComponent component that is currently active in the view. @@ -61,7 +66,7 @@ public class TransferableIcon extends JLabel { */ @SuppressWarnings("serial") public TransferableIcon(final AbstractComponent referencedComponent, final ViewTransferCallback viewTransferCallback) { - super(referencedComponent.getIcon()); + super(MCTIcons.processIcon(referencedComponent.getAsset(ImageIcon.class), ICON_COLOR, false)); final AtomicBoolean clicked = new AtomicBoolean(false); setTransferHandler(new TransferHandler() { @Override diff --git a/canvas/src/main/java/gov/nasa/arc/mct/canvas/view/PanelInspector.java b/canvas/src/main/java/gov/nasa/arc/mct/canvas/view/PanelInspector.java index 34ab7056..cc3354c3 100644 --- a/canvas/src/main/java/gov/nasa/arc/mct/canvas/view/PanelInspector.java +++ b/canvas/src/main/java/gov/nasa/arc/mct/canvas/view/PanelInspector.java @@ -24,12 +24,12 @@ import gov.nasa.arc.mct.components.AbstractComponent; import gov.nasa.arc.mct.gui.SelectionProvider; import gov.nasa.arc.mct.gui.SettingsButton; -import gov.nasa.arc.mct.gui.Twistie; import gov.nasa.arc.mct.gui.View; import gov.nasa.arc.mct.gui.ViewRoleSelection; import gov.nasa.arc.mct.services.component.ViewInfo; import gov.nasa.arc.mct.services.component.ViewType; import gov.nasa.arc.mct.util.LafColor; +import gov.nasa.arc.mct.util.MCTIcons; import java.awt.BorderLayout; import java.awt.Color; @@ -46,6 +46,7 @@ import java.beans.PropertyChangeListener; import java.util.Collection; +import javax.swing.ImageIcon; import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JPanel; @@ -137,7 +138,7 @@ private void selectedManifestationChanged(View view) { viewTitle.setTransferHandler(null); content = emptyPanel; } else { - viewTitle.setIcon(view.getManifestedComponent().getIcon()); + viewTitle.setIcon(MCTIcons.processIcon(view.getManifestedComponent().getAsset(ImageIcon.class), new Color(230,230,230), false)); viewTitle.setText(view.getManifestedComponent().getDisplayName() + PANEL_SPECIFIC); viewTitle.setTransferHandler(new WidgetTransferHandler()); content = this.view = view.getInfo().createView(view.getManifestedComponent()); diff --git a/mctcore/src/main/java/gov/nasa/arc/mct/components/AbstractComponent.java b/mctcore/src/main/java/gov/nasa/arc/mct/components/AbstractComponent.java index 412d79b8..ae217451 100644 --- a/mctcore/src/main/java/gov/nasa/arc/mct/components/AbstractComponent.java +++ b/mctcore/src/main/java/gov/nasa/arc/mct/components/AbstractComponent.java @@ -66,9 +66,9 @@ import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; -import javax.swing.ImageIcon; import javax.swing.SwingUtilities; + /** * The superclass of every component type. A component is uniquely identified by its id. * Subclasses must be created by the platform before usage within the system, this is done using the @@ -899,8 +899,8 @@ public T getAsset(Class assetClass) { * @deprecated use getAsset(Icon.class) instead */ @Deprecated - public final ImageIcon getIcon() { - return getAsset(ImageIcon.class); + public final javax.swing.ImageIcon getIcon() { + return getAsset(javax.swing.ImageIcon.class); } /** @@ -909,11 +909,11 @@ public final ImageIcon getIcon() { * @return an image icon */ @Deprecated - public static ImageIcon getIconForComponentType(String className) { + public static javax.swing.ImageIcon getIconForComponentType(String className) { for (ComponentTypeInfo componentTypeInfo : ExternalComponentRegistryImpl.getInstance().getComponentInfos()) { if (componentTypeInfo.getTypeClass().getName().equals(className)) { - return componentTypeInfo.getAsset(ImageIcon.class); + return componentTypeInfo.getAsset(javax.swing.ImageIcon.class); } } return null; diff --git a/platform/src/main/java/gov/nasa/arc/mct/gui/housing/Inspector.java b/platform/src/main/java/gov/nasa/arc/mct/gui/housing/Inspector.java index 6f8a91b5..545dc8f5 100644 --- a/platform/src/main/java/gov/nasa/arc/mct/gui/housing/Inspector.java +++ b/platform/src/main/java/gov/nasa/arc/mct/gui/housing/Inspector.java @@ -23,9 +23,9 @@ import gov.nasa.arc.mct.components.AbstractComponent; import gov.nasa.arc.mct.defaults.view.SwitcherView; -import gov.nasa.arc.mct.gui.SettingsButton; import gov.nasa.arc.mct.gui.OptionBox; import gov.nasa.arc.mct.gui.SelectionProvider; +import gov.nasa.arc.mct.gui.SettingsButton; import gov.nasa.arc.mct.gui.View; import gov.nasa.arc.mct.gui.ViewRoleSelection; import gov.nasa.arc.mct.gui.impl.WindowManagerImpl; @@ -36,6 +36,7 @@ import gov.nasa.arc.mct.services.component.ViewInfo; import gov.nasa.arc.mct.services.component.ViewType; import gov.nasa.arc.mct.util.LafColor; +import gov.nasa.arc.mct.util.MCTIcons; import java.awt.BorderLayout; import java.awt.Color; @@ -59,6 +60,7 @@ import java.util.ResourceBundle; import java.util.Set; +import javax.swing.ImageIcon; import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JPanel; @@ -307,7 +309,7 @@ private void selectedManifestationChanged(View view) { viewTitle.setTransferHandler(null); content = emptyPanel; } else { - viewTitle.setIcon(view.getManifestedComponent().getIcon()); + viewTitle.setIcon(MCTIcons.processIcon(view.getManifestedComponent().getAsset(ImageIcon.class), new Color(230,230,230), false)); viewTitle.setText(view.getManifestedComponent().getDisplayName()); viewTitle.setTransferHandler(new WidgetTransferHandler()); if (this.view != null) diff --git a/platform/src/main/java/gov/nasa/arc/mct/gui/housing/MCTStandardHousing.java b/platform/src/main/java/gov/nasa/arc/mct/gui/housing/MCTStandardHousing.java index 3330ddc6..4d08bc68 100644 --- a/platform/src/main/java/gov/nasa/arc/mct/gui/housing/MCTStandardHousing.java +++ b/platform/src/main/java/gov/nasa/arc/mct/gui/housing/MCTStandardHousing.java @@ -38,14 +38,16 @@ import gov.nasa.arc.mct.gui.ViewProvider; import gov.nasa.arc.mct.gui.housing.registry.UserEnvironmentRegistry; import gov.nasa.arc.mct.gui.impl.WindowManagerImpl; -import gov.nasa.arc.mct.osgi.platform.OSGIRuntimeImpl; import gov.nasa.arc.mct.osgi.platform.OSGIRuntime; +import gov.nasa.arc.mct.osgi.platform.OSGIRuntimeImpl; import gov.nasa.arc.mct.platform.spi.Platform; import gov.nasa.arc.mct.platform.spi.PlatformAccess; import gov.nasa.arc.mct.policy.PolicyContext; import gov.nasa.arc.mct.policy.PolicyInfo; import gov.nasa.arc.mct.services.component.ViewType; +import gov.nasa.arc.mct.util.MCTIcons; +import java.awt.Color; import java.awt.GraphicsConfiguration; import java.awt.GridLayout; import java.awt.event.WindowAdapter; @@ -61,6 +63,7 @@ import java.util.Map; import java.util.ResourceBundle; +import javax.swing.ImageIcon; import javax.swing.JPanel; import org.slf4j.LoggerFactory; @@ -107,8 +110,8 @@ public MCTStandardHousing(GraphicsConfiguration gc, String title, int width, int this.height = height; setSize(this.width, this.height); displayPanel.setSize(this.width, this.height); - setTitle(title); - setIconImage(housingView.getManifestedComponent().getIcon().getImage()); + setTitle(title); + setIcon(housingView.getManifestedComponent().getAsset(ImageIcon.class)); setDefaultCloseOperation(closeAction); MCTHousingViewManifestation housingManifestation = (MCTHousingViewManifestation) housingView; setHousingViewManifesation(housingManifestation); @@ -126,12 +129,17 @@ public MCTStandardHousing(String title, int width, int height, int closeAction, setSize(this.width, this.height); displayPanel.setSize(this.width, this.height); setTitle(title); - setIconImage(housingView.getManifestedComponent().getIcon().getImage()); + setIcon(housingView.getManifestedComponent().getAsset(ImageIcon.class)); setDefaultCloseOperation(closeAction); MCTHousingViewManifestation housingManifestation = (MCTHousingViewManifestation) housingView; setHousingViewManifesation(housingManifestation); addWindowListenerToHousing(); getContentPane().add(displayPanel); + } + + private void setIcon(ImageIcon icon) { + icon = MCTIcons.processIcon(icon, new Color(230,230,230), true); + super.setIconImage(icon.getImage()); } @Override diff --git a/util/src/main/java/gov/nasa/arc/mct/util/MCTIcons.java b/util/src/main/java/gov/nasa/arc/mct/util/MCTIcons.java index 56a74230..2035f199 100644 --- a/util/src/main/java/gov/nasa/arc/mct/util/MCTIcons.java +++ b/util/src/main/java/gov/nasa/arc/mct/util/MCTIcons.java @@ -312,7 +312,7 @@ private static ImageIcon doProcessing(ProcessDescription pd) { bufferedImage = new RescaleOp(coloration, offset, null).filter(bufferedImage, null); } } - + return new ImageIcon(bufferedImage); } From 5051429b85dfa25d6bf64accf557ed4e105ec6a5 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Wed, 11 Sep 2013 11:55:15 -0700 Subject: [PATCH 11/27] [Icons] Fix icon coloration --- .../mct/canvas/panel/TransferableIcon.java | 2 +- .../arc/mct/components/AbstractComponent.java | 5 +- .../ExternalComponentRegistryImpl.java | 2 +- .../services/component/ComponentTypeInfo.java | 102 ++++++++++-------- .../defaults/view/DefaultViewProvider.java | 2 +- .../defaults/view/NodeViewManifestation.java | 3 +- .../arc/mct/gui/menu/NewObjectAction.java | 66 ++++++------ .../java/gov/nasa/arc/mct/util/MCTIcons.java | 8 +- 8 files changed, 103 insertions(+), 87 deletions(-) diff --git a/canvas/src/main/java/gov/nasa/arc/mct/canvas/panel/TransferableIcon.java b/canvas/src/main/java/gov/nasa/arc/mct/canvas/panel/TransferableIcon.java index 32b2b217..217d8ee4 100644 --- a/canvas/src/main/java/gov/nasa/arc/mct/canvas/panel/TransferableIcon.java +++ b/canvas/src/main/java/gov/nasa/arc/mct/canvas/panel/TransferableIcon.java @@ -55,7 +55,7 @@ */ public class TransferableIcon extends JLabel { private static final long serialVersionUID = -7380332900682920418L; - private static final Color ICON_COLOR = new Color(230,230,230); + private static final Color ICON_COLOR = new Color(130,130,130); /** diff --git a/mctcore/src/main/java/gov/nasa/arc/mct/components/AbstractComponent.java b/mctcore/src/main/java/gov/nasa/arc/mct/components/AbstractComponent.java index ae217451..40792517 100644 --- a/mctcore/src/main/java/gov/nasa/arc/mct/components/AbstractComponent.java +++ b/mctcore/src/main/java/gov/nasa/arc/mct/components/AbstractComponent.java @@ -713,11 +713,14 @@ public final T getCapability(Class capability) { if (typeInfo == null) { for (ComponentTypeInfo info : ExternalComponentRegistryImpl.getInstance().getComponentInfos()) { - if (info != null) { + if (info != null && info.getComponentClass().equals(getClass())) { typeInfo = info; break; } } + if (typeInfo == null) { + typeInfo = new ComponentTypeInfo(getClass().getSimpleName(), getClass().getSimpleName(), getClass()); + } } return capability.cast(typeInfo); } diff --git a/mctcore/src/main/java/gov/nasa/arc/mct/registry/ExternalComponentRegistryImpl.java b/mctcore/src/main/java/gov/nasa/arc/mct/registry/ExternalComponentRegistryImpl.java index 5826003a..e59c0120 100644 --- a/mctcore/src/main/java/gov/nasa/arc/mct/registry/ExternalComponentRegistryImpl.java +++ b/mctcore/src/main/java/gov/nasa/arc/mct/registry/ExternalComponentRegistryImpl.java @@ -347,7 +347,7 @@ public static class ExtendedComponentTypeInfo extends ComponentTypeInfo { * @param bundleSymName the OSGi bundle symbolic name */ public ExtendedComponentTypeInfo(ComponentTypeInfo info, String bundleSymName) { - super(info.getDisplayName(), info.getShortDescription(), info.getComponentClass(), info.getId(), info.isCreatable(), info.getWizardUI(), info.getIcon()); + super(info.getDisplayName(), info.getShortDescription(), info.getComponentClass(), info.getId(), info.isCreatable()); assert bundleSymName != null: "bundleSymbolicName should not be null"; symbolicName = bundleSymName; } diff --git a/mctcore/src/main/java/gov/nasa/arc/mct/services/component/ComponentTypeInfo.java b/mctcore/src/main/java/gov/nasa/arc/mct/services/component/ComponentTypeInfo.java index f7f88cb5..3d8193b2 100644 --- a/mctcore/src/main/java/gov/nasa/arc/mct/services/component/ComponentTypeInfo.java +++ b/mctcore/src/main/java/gov/nasa/arc/mct/services/component/ComponentTypeInfo.java @@ -22,11 +22,7 @@ package gov.nasa.arc.mct.services.component; import gov.nasa.arc.mct.components.AbstractComponent; -import gov.nasa.arc.mct.util.MCTIcons; -import java.awt.Color; - -import javax.swing.ImageIcon; /** * This class describes an component type. This description is used in the platform to create new component type @@ -35,15 +31,11 @@ * */ public class ComponentTypeInfo extends TypeInfo { - private static final int ICON_SIZE = 14; - private static final Color BASE_ICON_COLOR = Color.WHITE; - + private final String displayName; private final String description; private final String componentTypeId; private final boolean isCreatable; - private final CreateWizardUI wizard; - private final ImageIcon icon; /** * Creates new ComponentTypeInfo representing a unique component type. @@ -52,7 +44,7 @@ public class ComponentTypeInfo extends TypeInfo { * @param componentClass non null component class, this class must provide the required no-argument constructor */ public ComponentTypeInfo(String displayName, String description, Class componentClass) { - this(displayName,description,componentClass, componentClass.getName(), true, null, null); + this(displayName,description,componentClass, componentClass.getName(), true); } /** @@ -63,7 +55,7 @@ public ComponentTypeInfo(String displayName, String description, Class componentClass, boolean isCreatable) { - this(displayName,description,componentClass, componentClass.getName(), isCreatable, null, null); + this(displayName,description,componentClass, componentClass.getName(), isCreatable); } /** @@ -72,10 +64,12 @@ public ComponentTypeInfo(String displayName, String description, Class componentClass, boolean isCreatable, ImageIcon icon) { - this(displayName,description,componentClass, componentClass.getName(), isCreatable, null, icon); + * @param icon the icon that represents this component type + * @deprecated icon and wizard now specified using ComponentProvider.getAsset + */ + @Deprecated + public ComponentTypeInfo(String displayName, String description, Class componentClass, boolean isCreatable, javax.swing.ImageIcon icon) { + this(displayName,description,componentClass, componentClass.getName(), isCreatable); } @@ -84,10 +78,12 @@ public ComponentTypeInfo(String displayName, String description, Class componentClass, CreateWizardUI wizard){ - this(displayName,description,componentClass,componentClass.getName(), true, wizard, null); + this(displayName,description,componentClass,componentClass.getName(), true); } /** @@ -97,10 +93,41 @@ public ComponentTypeInfo(String displayName, String description, Class componentClass, CreateWizardUI wizard, ImageIcon icon){ - this(displayName,description,componentClass,componentClass.getName(), true, wizard, icon); + * @deprecated icon and wizard now specified using ComponentProvider.getAsset + */ + @Deprecated + public ComponentTypeInfo(String displayName, String description, Class componentClass, CreateWizardUI wizard, javax.swing.ImageIcon icon){ + this(displayName,description,componentClass,componentClass.getName(), true); } + + /** + * Creates a new ComponentTypeInfo representing a unique component type. + * @param displayName non null human readable name for the component type + * @param description human readable string describing the component type + * @param componentClass non null component class, this class must have a no argument constructor + * @param id globally unique identifier (across all modules) identifying this component. + * @param isCreatable indicates if this component type can be created from the Create menu. + * @throws IllegalArgumentException if componentClass, id, or displayName is null or if component class does not meet the requirements of + * AbstractComponent + */ + protected ComponentTypeInfo(String displayName, String description, Class componentClass, String id, boolean isCreatable) { + super(componentClass); + if (componentClass == null) { + throw new IllegalArgumentException("componentClass must not be null"); + } + AbstractComponent.checkBaseComponentRequirements(componentClass); + + if (id == null) { + throw new IllegalArgumentException("id must not be null"); + } + if (displayName == null) { + throw new IllegalArgumentException("displayName must not be null"); + } + this.displayName = displayName; + this.description = description; + this.componentTypeId = id; + this.isCreatable = isCreatable; + } /** * Creates a new ComponentTypeInfo representing a unique component type. @@ -113,30 +140,11 @@ public ComponentTypeInfo(String displayName, String description, ClassAbstractComponent - */ - protected ComponentTypeInfo(String displayName, String description, Class componentClass, String id, boolean isCreatable, CreateWizardUI wizard, ImageIcon icon) throws IllegalArgumentException { - super(componentClass); - if (componentClass == null) { - throw new IllegalArgumentException("componentClass must not be null"); - } - AbstractComponent.checkBaseComponentRequirements(componentClass); - - if (id == null) { - throw new IllegalArgumentException("id must not be null"); - } - if (displayName == null) { - throw new IllegalArgumentException("displayName must not be null"); - } - this.displayName = displayName; - this.description = description; - this.componentTypeId = id; - this.isCreatable = isCreatable; - this.wizard = wizard; - this.icon = MCTIcons.processIcon( - icon != null ? icon : - MCTIcons.generateIcon( - componentClass.getName().hashCode(), - ICON_SIZE, BASE_ICON_COLOR)); + * @deprecated icon and wizard now specified using ComponentProvider.getAsset + */ + @Deprecated + protected ComponentTypeInfo(String displayName, String description, Class componentClass, String id, boolean isCreatable, CreateWizardUI wizard, javax.swing.ImageIcon icon) throws IllegalArgumentException { + this(displayName, description, componentClass, id, isCreatable); } @@ -201,8 +209,8 @@ public final CreateWizardUI getWizardUI() { * @deprecated use getAsset(ImageIcon.class) instead */ @Deprecated - public final ImageIcon getIcon() { - return getAsset(ImageIcon.class); + public final javax.swing.ImageIcon getIcon() { + return getAsset(javax.swing.ImageIcon.class); } @Override diff --git a/platform/src/main/java/gov/nasa/arc/mct/defaults/view/DefaultViewProvider.java b/platform/src/main/java/gov/nasa/arc/mct/defaults/view/DefaultViewProvider.java index a5e63a8e..cce02c79 100644 --- a/platform/src/main/java/gov/nasa/arc/mct/defaults/view/DefaultViewProvider.java +++ b/platform/src/main/java/gov/nasa/arc/mct/defaults/view/DefaultViewProvider.java @@ -82,7 +82,7 @@ public T getAsset(TypeInfo type, Class assetClass) { } return assetClass.cast(MCTIcons.generateIcon( type.getTypeClass().getName().hashCode(), - sz, Color.ORANGE)); + sz, Color.WHITE)); } return super.getAsset(type, assetClass); } diff --git a/platform/src/main/java/gov/nasa/arc/mct/defaults/view/NodeViewManifestation.java b/platform/src/main/java/gov/nasa/arc/mct/defaults/view/NodeViewManifestation.java index eab4d2d4..31aa8e46 100644 --- a/platform/src/main/java/gov/nasa/arc/mct/defaults/view/NodeViewManifestation.java +++ b/platform/src/main/java/gov/nasa/arc/mct/defaults/view/NodeViewManifestation.java @@ -40,6 +40,7 @@ import gov.nasa.arc.mct.util.MCTIcons; import gov.nasa.arc.mct.util.internal.ElapsedTimer; +import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import java.beans.PropertyChangeListener; @@ -104,7 +105,7 @@ public NodeViewManifestation(AbstractComponent component, ViewInfo viewinfo) { private ImageIcon getIcon(AbstractComponent ac) { ImageIcon baseIcon = ac.getAsset(ImageIcon.class); - return MCTIcons.processIcon(baseIcon, 1f, 0.25f, 1f, true); + return MCTIcons.processIcon(baseIcon, new Color(101, 131, 192), false); } private void doLockRendering(JLabel widget, AbstractComponent comp) { diff --git a/platform/src/main/java/gov/nasa/arc/mct/gui/menu/NewObjectAction.java b/platform/src/main/java/gov/nasa/arc/mct/gui/menu/NewObjectAction.java index 8f689196..3e6c54fb 100644 --- a/platform/src/main/java/gov/nasa/arc/mct/gui/menu/NewObjectAction.java +++ b/platform/src/main/java/gov/nasa/arc/mct/gui/menu/NewObjectAction.java @@ -21,37 +21,40 @@ *******************************************************************************/ package gov.nasa.arc.mct.gui.menu; -import gov.nasa.arc.mct.components.AbstractComponent; -import gov.nasa.arc.mct.gui.ActionContext; -import gov.nasa.arc.mct.gui.CompositeAction; -import gov.nasa.arc.mct.gui.MCTMutableTreeNode; -import gov.nasa.arc.mct.gui.View; -import gov.nasa.arc.mct.gui.dialogs.DefaultWizardUI; -import gov.nasa.arc.mct.gui.dialogs.NewObjectDialog; -import gov.nasa.arc.mct.gui.housing.MCTDirectoryArea; +import gov.nasa.arc.mct.components.AbstractComponent; +import gov.nasa.arc.mct.gui.ActionContext; +import gov.nasa.arc.mct.gui.CompositeAction; +import gov.nasa.arc.mct.gui.MCTMutableTreeNode; +import gov.nasa.arc.mct.gui.View; +import gov.nasa.arc.mct.gui.dialogs.DefaultWizardUI; +import gov.nasa.arc.mct.gui.dialogs.NewObjectDialog; +import gov.nasa.arc.mct.gui.housing.MCTDirectoryArea; import gov.nasa.arc.mct.gui.impl.ActionContextImpl; import gov.nasa.arc.mct.policy.PolicyContext; import gov.nasa.arc.mct.policy.PolicyInfo; import gov.nasa.arc.mct.policymgr.PolicyManagerImpl; -import gov.nasa.arc.mct.registry.ExternalComponentRegistryImpl; -import gov.nasa.arc.mct.registry.ExternalComponentRegistryImpl.ExtendedComponentTypeInfo; +import gov.nasa.arc.mct.registry.ExternalComponentRegistryImpl; +import gov.nasa.arc.mct.registry.ExternalComponentRegistryImpl.ExtendedComponentTypeInfo; import gov.nasa.arc.mct.roles.events.PropertyChangeEvent; -import gov.nasa.arc.mct.services.component.CreateWizardUI; -import gov.nasa.arc.mct.util.logging.MCTLogger; - -import java.awt.event.ActionEvent; -import java.util.ArrayList; -import java.util.Collection; +import gov.nasa.arc.mct.services.component.ComponentTypeInfo; +import gov.nasa.arc.mct.services.component.CreateWizardUI; +import gov.nasa.arc.mct.util.MCTIcons; +import gov.nasa.arc.mct.util.logging.MCTLogger; + +import java.awt.Color; +import java.awt.event.ActionEvent; +import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; -import java.util.List; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.ImageIcon; -import javax.swing.JTree; -import javax.swing.event.TreeExpansionEvent; -import javax.swing.tree.DefaultTreeModel; -import javax.swing.tree.TreePath; +import java.util.List; + +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.ImageIcon; +import javax.swing.JTree; +import javax.swing.event.TreeExpansionEvent; +import javax.swing.tree.DefaultTreeModel; +import javax.swing.tree.TreePath; @SuppressWarnings("serial") public class NewObjectAction extends CompositeAction { @@ -82,7 +85,7 @@ public boolean canHandle(ActionContext context) { AbstractComponent tempComponent = extCompRegistry.newInstance(info); policyContext.setProperty(PolicyContext.PropertyName.SOURCE_COMPONENTS.getName(), Collections.singleton(tempComponent)); if (PolicyManagerImpl.getInstance().execute(compositionKey, policyContext).getStatus()) { - subActions.add(new NewTypeAction(info.getDisplayName(), info.getComponentClass(), targetComponent, info.getWizardUI(), info.getIcon())); + subActions.add(new NewTypeAction(info, targetComponent)); } } } @@ -100,13 +103,12 @@ private class NewTypeAction extends AbstractAction { private AbstractComponent targetComponent; private CreateWizardUI wizardUI; - public NewTypeAction(String componentDisplayName, Class componentClass, - AbstractComponent targetComponent, CreateWizardUI wizard, ImageIcon icon) { - putValue(Action.NAME, componentDisplayName); - putValue(Action.SMALL_ICON, icon); - this.componentClass = componentClass; + public NewTypeAction(ComponentTypeInfo info, AbstractComponent targetComponent) { + putValue(Action.NAME, info.getDisplayName()); + putValue(Action.SMALL_ICON, MCTIcons.processIcon(info.getAsset(ImageIcon.class), new Color(40,40,40), false)); + this.componentClass = info.getTypeClass(); this.targetComponent = targetComponent; - this.wizardUI = wizard; + this.wizardUI = info.getAsset(CreateWizardUI.class); if (wizardUI == null){ wizardUI = new DefaultWizardUI(this.componentClass); } diff --git a/util/src/main/java/gov/nasa/arc/mct/util/MCTIcons.java b/util/src/main/java/gov/nasa/arc/mct/util/MCTIcons.java index 2035f199..5274b459 100644 --- a/util/src/main/java/gov/nasa/arc/mct/util/MCTIcons.java +++ b/util/src/main/java/gov/nasa/arc/mct/util/MCTIcons.java @@ -272,7 +272,7 @@ private static ImageIcon doProcessing(ProcessDescription pd) { BufferedImage bufferedImage = new BufferedImage( pd.icon.getIconWidth() + 2, pd.icon.getIconHeight() + 2, - BufferedImage.TYPE_4BYTE_ABGR); + BufferedImage.TYPE_INT_ARGB); if (pd.dropShadow) { // Color rescale for shadowing @@ -301,10 +301,12 @@ private static ImageIcon doProcessing(ProcessDescription pd) { // Convert color to scaling factor int rgb = pd.firstColor.getRGB(); float coloration[] = new float[4]; - for (int i = 0; i < coloration.length; i++) { - coloration[i] = (float) (rgb & 0xFF) / 255f; + for (int i = 0; i < 3; i++) { + coloration[2-i] = (float) (rgb & 0xFF) / 255f; rgb >>>= 8; } + coloration[3] = 1f; // Always full alpha + float offset[] = {0f,0f,0f,0f}; // Repaint original icon & colorize From ec0fd3a996151ed3c7535b7ea56bc269d4350769 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Wed, 11 Sep 2013 13:51:05 -0700 Subject: [PATCH 12/27] [Icons] Deprecate ViewInfo icon methods Additionally, colorize icons in SwitcherView. --- .../arc/mct/services/component/ViewInfo.java | 94 ++++++++++--------- .../arc/mct/defaults/view/SwitcherView.java | 13 ++- 2 files changed, 62 insertions(+), 45 deletions(-) diff --git a/mctcore/src/main/java/gov/nasa/arc/mct/services/component/ViewInfo.java b/mctcore/src/main/java/gov/nasa/arc/mct/services/component/ViewInfo.java index 160c776e..1929e31c 100644 --- a/mctcore/src/main/java/gov/nasa/arc/mct/services/component/ViewInfo.java +++ b/mctcore/src/main/java/gov/nasa/arc/mct/services/component/ViewInfo.java @@ -24,29 +24,20 @@ import gov.nasa.arc.mct.components.AbstractComponent; import gov.nasa.arc.mct.gui.View; import gov.nasa.arc.mct.util.LookAndFeelSettings; -import gov.nasa.arc.mct.util.MCTIcons; -import java.awt.Color; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.util.concurrent.Callable; -import javax.swing.ImageIcon; - /** * The ViewInfo class describes metadata about a view. This class is used to create new view instances. * */ public class ViewInfo extends TypeInfo { - private static final int ICON_SIZE = 9; - private static final Color BASE_ICON_COLOR = Color.WHITE; - private final Constructor viewConstructor; private final String type; private final String viewName; private final ViewType viewType; - private final ImageIcon icon; - private final ImageIcon selectedIcon; private final boolean shouldExpandCenterPaneInWindow; private final Class preferredComponentType; @@ -90,8 +81,10 @@ public ViewInfo(Class aViewClass, String name, String aType, Vie * @param viewType for this view * @param icon to be placed in a button for this view. This icon is typically used for drop-down showing in the inspector. * @throws IllegalArgumentException if the view type is null or the class doesn't have the right type of constructor + * @deprecated icons are now exposed using ComponentProvider.getAsset */ - public ViewInfo(Class aViewClass, String name, ViewType viewType, ImageIcon icon) throws IllegalArgumentException { + @Deprecated + public ViewInfo(Class aViewClass, String name, ViewType viewType, javax.swing.ImageIcon icon) throws IllegalArgumentException { this(aViewClass, name, aViewClass.getName(), viewType, icon, icon, false, null); } @@ -104,8 +97,10 @@ public ViewInfo(Class aViewClass, String name, ViewType viewType * @param viewType for this view * @param icon to be placed in a button for this view. This icon is typically used for drop-down showing in the inspector. * @throws IllegalArgumentException if the view type is null or the class doesn't have the right type of constructor + * @deprecated icons are now exposed using ComponentProvider.getAsset */ - public ViewInfo(Class aViewClass, String name, String aType, ViewType viewType, ImageIcon icon) throws IllegalArgumentException { + @Deprecated + public ViewInfo(Class aViewClass, String name, String aType, ViewType viewType, javax.swing.ImageIcon icon) throws IllegalArgumentException { this(aViewClass, name, aType, viewType, icon, icon, false, null); } @@ -121,11 +116,45 @@ public ViewInfo(Class aViewClass, String name, String aType, Vie * @param icon to be placed in a button for this view. This icon is typically used for button showing in the inspector. * @param selectedIcon icon to be placed in a button for this view. This icon is typically used for button showing in the inspector when the button is selected. * @throws IllegalArgumentException if the view type is null or the class doesn't have the right type of constructor + * @deprecated icons are now exposed using ComponentProvider.getAsset */ - public ViewInfo(Class aViewClass, String name, String aType, ViewType viewType, ImageIcon icon, ImageIcon selectedIcon) throws IllegalArgumentException { + @Deprecated + public ViewInfo(Class aViewClass, String name, String aType, ViewType viewType, javax.swing.ImageIcon icon, javax.swing.ImageIcon selectedIcon) throws IllegalArgumentException { this(aViewClass, name, aType, viewType, icon, selectedIcon, false, null); } - + + /** + * Creates a new instance of ViewInfo. This constructor should only be used when + * attempting to provide backward compatibility for views which have already been serialized. The + * serialized mapping uses the type to determine how to map the state to a view type. + * @param aViewClass representing a view. + * @param name human readable name of the view + * @param aType representing the type used when serializing the view state. The type must be unique across all serialized view + * states so the default type used is the fully qualified class name. + * @param viewType for this view + * @param shouldExpandCenterPaneInWindow indicates whether this view requires expanding the center pane (i.g., hiding both the list and inspector panes) when viewed in a window. + * @param preferredComponentType specifies the component type where this view is the preferred view; null means this view can be attached to any component type in the registry. + * @throws IllegalArgumentException if the view type is null or the class doesn't have the right type of constructor + */ + public ViewInfo(Class aViewClass, String name, String aType, ViewType viewType, boolean shouldExpandCenterPaneInWindow, Class preferredComponentType) throws IllegalArgumentException { + super(aViewClass); + type = aType; + viewName = name; + if (name == null) { + throw new IllegalArgumentException("name must be specified for " + aViewClass); + } + if (viewType == null) { + throw new IllegalArgumentException("view type must be specified for " + name); + } + this.viewType = viewType; + viewConstructor = getConstructor(aViewClass); + if (viewConstructor == null) { + throw new IllegalArgumentException("a constructor must be defined that has AbstractComponent and ViewInfo as the parameters for " + aViewClass); + } + this.shouldExpandCenterPaneInWindow = shouldExpandCenterPaneInWindow; + this.preferredComponentType = preferredComponentType; + } + /** * Creates a new instance of ViewInfo. This constructor should only be used when * attempting to provide backward compatibility for views which have already been serialized. The @@ -139,31 +168,12 @@ public ViewInfo(Class aViewClass, String name, String aType, Vie * @param selectedIcon icon to be placed in a button for this view. This icon is typically used for button showing in the inspector when the button is selected. * @param shouldExpandCenterPaneInWindow indicates whether this view requires expanding the center pane (i.g., hiding both the list and inspector panes) when viewed in a window. * @param preferredComponentType specifies the component type where this view is the preferred view; null means this view can be attached to any component type in the registry. - * @throws IllegalArgumentException if the view type is null or the class doesn't have the right type of constructor - */ - public ViewInfo(Class aViewClass, String name, String aType, ViewType viewType, ImageIcon icon, ImageIcon selectedIcon, boolean shouldExpandCenterPaneInWindow, Class preferredComponentType) throws IllegalArgumentException { - super(aViewClass); - type = aType; - viewName = name; - this.icon = MCTIcons.processIcon( - icon != null ? icon : - MCTIcons.generateIcon( - aViewClass.getName().hashCode(), - ICON_SIZE, BASE_ICON_COLOR)); - this.selectedIcon = icon; - if (name == null) { - throw new IllegalArgumentException("name must be specified for " + aViewClass); - } - if (viewType == null) { - throw new IllegalArgumentException("view type must be specified for " + name); - } - this.viewType = viewType; - viewConstructor = getConstructor(aViewClass); - if (viewConstructor == null) { - throw new IllegalArgumentException("a constructor must be defined that has AbstractComponent and ViewInfo as the parameters for " + aViewClass); - } - this.shouldExpandCenterPaneInWindow = shouldExpandCenterPaneInWindow; - this.preferredComponentType = preferredComponentType; + * @throws IllegalArgumentException if the view type is null or the class doesn't have the right type of constructor + * @deprecated icons are now exposed using ComponentProvider.getAsset + */ + @Deprecated + public ViewInfo(Class aViewClass, String name, String aType, ViewType viewType, javax.swing.ImageIcon icon, javax.swing.ImageIcon selectedIcon, boolean shouldExpandCenterPaneInWindow, Class preferredComponentType) throws IllegalArgumentException { + this(aViewClass, name, aType, viewType, shouldExpandCenterPaneInWindow, preferredComponentType); } /** @@ -246,8 +256,8 @@ public View call() throws Exception { * @return icon; null if no provided */ @Deprecated - public ImageIcon getIcon() { - return icon; + public javax.swing.ImageIcon getIcon() { + return getAsset(javax.swing.ImageIcon.class); } /** @@ -256,8 +266,8 @@ public ImageIcon getIcon() { * @return an icon; null if not provided */ @Deprecated - public ImageIcon getSelectedIcon() { - return selectedIcon; + public javax.swing.ImageIcon getSelectedIcon() { + return getAsset(javax.swing.ImageIcon.class); } /** diff --git a/platform/src/main/java/gov/nasa/arc/mct/defaults/view/SwitcherView.java b/platform/src/main/java/gov/nasa/arc/mct/defaults/view/SwitcherView.java index 54adc85a..c8d4c2ba 100644 --- a/platform/src/main/java/gov/nasa/arc/mct/defaults/view/SwitcherView.java +++ b/platform/src/main/java/gov/nasa/arc/mct/defaults/view/SwitcherView.java @@ -26,6 +26,7 @@ import gov.nasa.arc.mct.gui.ViewProvider; import gov.nasa.arc.mct.services.component.ViewInfo; import gov.nasa.arc.mct.services.component.ViewType; +import gov.nasa.arc.mct.util.MCTIcons; import java.awt.Color; import java.awt.Component; @@ -40,6 +41,7 @@ import javax.swing.BorderFactory; import javax.swing.Icon; +import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JComponent; @@ -62,6 +64,7 @@ public class SwitcherView extends View { private JComboBox comboBox; private JLabel label; private static final float FONT_SIZE = 10f; + private static final Color ICON_COLOR = new Color(144,144,144); /** * The view info used to instantiate this view. @@ -89,7 +92,7 @@ public SwitcherView(AbstractComponent ac, ViewInfo vi) { } else if (viewInfos.length == 1) { // Otherwise, just show the one available view as a label label = new JLabel(); - label.setIcon(vi.getIcon()); + label.setIcon(getIcon(vi)); label.setText(vi.getViewName()); add(label); } else { @@ -133,13 +136,17 @@ private void resetSelection() { comboBox.addItemListener(itemListener); } if (label != null) { - label.setIcon(vi.getIcon()); + label.setIcon(getIcon(vi)); label.setText(vi.getViewName()); } } } } + private static ImageIcon getIcon(ViewInfo vi) { + return MCTIcons.processIcon(vi.getAsset(ImageIcon.class), ICON_COLOR, false); + } + private final ItemListener itemListener = new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { @@ -167,7 +174,7 @@ public Component getListCellRendererComponent(JList list, Object value, int inde label.setFont(label.getFont().deriveFont(FONT_SIZE)); if (value instanceof ViewInfo) { ViewInfo vi = (ViewInfo) value; - label.setIcon(vi.getIcon()); + label.setIcon(getIcon(vi)); label.setText(vi.getViewName()); } else { label.setIcon(null); From 3b17a86157e98c5001fd891b42ff616e5f93476c Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Wed, 11 Sep 2013 14:41:10 -0700 Subject: [PATCH 13/27] [Icons] Implement getAsset in component providers This removes usages of constructor calls for ComponentTypeInfo and ViewInfo which involve elements that have been moved to ComponentProvider.getAsset. (Specifically, these are icons and creation wizards.) Where appropriate, these have been replaced with appropriate getAsset implementations in those component providers. In some cases the icons present do not match up with current icon implementations and have been removed entirely. --- .../provider/ImportExportProvider.java | 6 +- .../provider/CanvasComponentProvider.java | 110 ++++++++++-------- .../CollectionComponentProvider.java | 36 ++++-- .../graphics/GraphicalComponentProvider.java | 66 +++++++---- .../component/EvaluatorComponentProvider.java | 31 +++-- .../component/MultiComponentProvider.java | 18 ++- .../component/ExampleComponentProvider.java | 79 ++++++++----- .../ExecutableButtonComponentProvider.java | 36 ++++-- .../arc/mct/fastplot/PlotViewProvider.java | 47 +++++--- .../limits/LimitLineComponentProvider.java | 40 ++++--- .../core/provider/CoreComponentProvider.java | 27 ++++- .../ExternalComponentRegistryImpl.java | 2 +- .../NonTimePlotComponentProvider.java | 10 +- .../defaults/view/DefaultViewProvider.java | 14 ++- .../nasa/arc/mct/table/TableViewProvider.java | 45 ++++--- 15 files changed, 357 insertions(+), 210 deletions(-) diff --git a/ImportExportProvider/src/main/java/gov/nasa/arc/mct/importExport/provider/ImportExportProvider.java b/ImportExportProvider/src/main/java/gov/nasa/arc/mct/importExport/provider/ImportExportProvider.java index 24158be4..08d98b1e 100644 --- a/ImportExportProvider/src/main/java/gov/nasa/arc/mct/importExport/provider/ImportExportProvider.java +++ b/ImportExportProvider/src/main/java/gov/nasa/arc/mct/importExport/provider/ImportExportProvider.java @@ -33,8 +33,6 @@ import java.util.List; import java.util.ResourceBundle; -import javax.swing.ImageIcon; - /** * The ImportExportProvider provides menu items to import data into a * taxonomy node to the MCT directory and export data from a node. @@ -54,9 +52,7 @@ public ImportExportProvider() { * EventsCollection.class, false), */ new ComponentTypeInfo(bundle.getString("display_name"), bundle - .getString("description"), ImportExportComponent.class, false, - new ImageIcon(ImportExportComponent.class - .getResource("/icons/legacyCollection.png")))); + .getString("description"), ImportExportComponent.class, false)); assert componentTypes != null; } diff --git a/canvas/src/main/java/gov/nasa/arc/mct/canvas/provider/CanvasComponentProvider.java b/canvas/src/main/java/gov/nasa/arc/mct/canvas/provider/CanvasComponentProvider.java index 0885ca72..a5d2167c 100644 --- a/canvas/src/main/java/gov/nasa/arc/mct/canvas/provider/CanvasComponentProvider.java +++ b/canvas/src/main/java/gov/nasa/arc/mct/canvas/provider/CanvasComponentProvider.java @@ -21,65 +21,68 @@ *******************************************************************************/ package gov.nasa.arc.mct.canvas.provider; -import gov.nasa.arc.mct.canvas.policy.CanvasFilterViewPolicy; -import gov.nasa.arc.mct.canvas.policy.EmbeddedCanvasViewsAreNotWriteable; -import gov.nasa.arc.mct.canvas.view.CanvasManifestation; -import gov.nasa.arc.mct.canvas.view.ChangeGridSizeAction; -import gov.nasa.arc.mct.canvas.view.ChangeSnapAction; -import gov.nasa.arc.mct.canvas.view.PanelInspector; -import gov.nasa.arc.mct.canvas.view.ReTileAction; -import gov.nasa.arc.mct.canvas.view.WindowChangeGridSizeAction; -import gov.nasa.arc.mct.canvas.view.WindowChangeSnapAction; -import gov.nasa.arc.mct.canvas.view.WindowReTileAction; -import gov.nasa.arc.mct.gui.MenuItemInfo; +import gov.nasa.arc.mct.canvas.policy.CanvasFilterViewPolicy; +import gov.nasa.arc.mct.canvas.policy.EmbeddedCanvasViewsAreNotWriteable; +import gov.nasa.arc.mct.canvas.view.CanvasManifestation; +import gov.nasa.arc.mct.canvas.view.ChangeGridSizeAction; +import gov.nasa.arc.mct.canvas.view.ChangeSnapAction; +import gov.nasa.arc.mct.canvas.view.PanelInspector; +import gov.nasa.arc.mct.canvas.view.ReTileAction; +import gov.nasa.arc.mct.canvas.view.WindowChangeGridSizeAction; +import gov.nasa.arc.mct.canvas.view.WindowChangeSnapAction; +import gov.nasa.arc.mct.canvas.view.WindowReTileAction; +import gov.nasa.arc.mct.gui.MenuItemInfo; import gov.nasa.arc.mct.gui.MenuItemInfo.MenuItemType; -import gov.nasa.arc.mct.menu.AlignBottomAction; -import gov.nasa.arc.mct.menu.AlignHorizontalCenterAction; -import gov.nasa.arc.mct.menu.AlignLeftAction; -import gov.nasa.arc.mct.menu.AlignRightAction; -import gov.nasa.arc.mct.menu.AlignTopAction; -import gov.nasa.arc.mct.menu.AlignVerticalCenterAction; -import gov.nasa.arc.mct.menu.AlignmentMenu; -import gov.nasa.arc.mct.menu.BorderStylesAction; -import gov.nasa.arc.mct.menu.BorderStylesMenu; -import gov.nasa.arc.mct.menu.BordersAllOrNoneAction; -import gov.nasa.arc.mct.menu.BordersBottomAction; -import gov.nasa.arc.mct.menu.BordersLeftAction; -import gov.nasa.arc.mct.menu.BordersMenu; -import gov.nasa.arc.mct.menu.BordersRightAction; -import gov.nasa.arc.mct.menu.BordersTopAction; -import gov.nasa.arc.mct.menu.BringToFrontAction; +import gov.nasa.arc.mct.menu.AlignBottomAction; +import gov.nasa.arc.mct.menu.AlignHorizontalCenterAction; +import gov.nasa.arc.mct.menu.AlignLeftAction; +import gov.nasa.arc.mct.menu.AlignRightAction; +import gov.nasa.arc.mct.menu.AlignTopAction; +import gov.nasa.arc.mct.menu.AlignVerticalCenterAction; +import gov.nasa.arc.mct.menu.AlignmentMenu; +import gov.nasa.arc.mct.menu.BorderStylesAction; +import gov.nasa.arc.mct.menu.BorderStylesMenu; +import gov.nasa.arc.mct.menu.BordersAllOrNoneAction; +import gov.nasa.arc.mct.menu.BordersBottomAction; +import gov.nasa.arc.mct.menu.BordersLeftAction; +import gov.nasa.arc.mct.menu.BordersMenu; +import gov.nasa.arc.mct.menu.BordersRightAction; +import gov.nasa.arc.mct.menu.BordersTopAction; +import gov.nasa.arc.mct.menu.BringToFrontAction; import gov.nasa.arc.mct.menu.ChangeViewAction; -import gov.nasa.arc.mct.menu.ExportPanelAsImageAction; -import gov.nasa.arc.mct.menu.GridMenu; -import gov.nasa.arc.mct.menu.PanelTitleBarAction; -import gov.nasa.arc.mct.menu.RemovePanelAction; -import gov.nasa.arc.mct.menu.SelectAllAction; -import gov.nasa.arc.mct.menu.SendToBackAction; -import gov.nasa.arc.mct.menu.WindowGridMenu; -import gov.nasa.arc.mct.policy.PolicyInfo; -import gov.nasa.arc.mct.services.component.AbstractComponentProvider; -import gov.nasa.arc.mct.services.component.ViewInfo; -import gov.nasa.arc.mct.services.component.ViewType; - -import java.util.Arrays; -import java.util.Collection; -import java.util.ResourceBundle; - -import javax.swing.ImageIcon; +import gov.nasa.arc.mct.menu.ExportPanelAsImageAction; +import gov.nasa.arc.mct.menu.GridMenu; +import gov.nasa.arc.mct.menu.PanelTitleBarAction; +import gov.nasa.arc.mct.menu.RemovePanelAction; +import gov.nasa.arc.mct.menu.SelectAllAction; +import gov.nasa.arc.mct.menu.SendToBackAction; +import gov.nasa.arc.mct.menu.WindowGridMenu; +import gov.nasa.arc.mct.policy.PolicyInfo; +import gov.nasa.arc.mct.services.component.AbstractComponentProvider; +import gov.nasa.arc.mct.services.component.TypeInfo; +import gov.nasa.arc.mct.services.component.ViewInfo; +import gov.nasa.arc.mct.services.component.ViewType; + +import java.util.Arrays; +import java.util.Collection; +import java.util.ResourceBundle; + +import javax.swing.ImageIcon; public class CanvasComponentProvider extends AbstractComponentProvider { - private static ResourceBundle bundle = ResourceBundle.getBundle("CanvasResourceBundle"); + private static ResourceBundle bundle = ResourceBundle.getBundle("CanvasResourceBundle"); + + private static final ImageIcon ICON = + new ImageIcon(CanvasComponentProvider.class.getResource("/icons/mct_icon_menu_canvas.png")); + private static final Collection VIEW_INFOS = Arrays.asList( new ViewInfo(CanvasManifestation.class, bundle.getString("Canvas"), "gov.nasa.arc.mct.canvas.view.CanvasView", - ViewType.OBJECT, - new ImageIcon(CanvasComponentProvider.class.getResource("/icons/mct_icon_menu_canvas.png"))), + ViewType.OBJECT), new ViewInfo(CanvasManifestation.class, bundle.getString("Canvas"), "gov.nasa.arc.mct.canvas.view.CanvasView", ViewType.CENTER), new ViewInfo(CanvasManifestation.class, bundle.getString("Canvas"), "gov.nasa.arc.mct.canvas.view.CanvasView", - ViewType.EMBEDDED, - new ImageIcon(CanvasComponentProvider.class.getResource("/icons/mct_icon_menu_canvas.png"))), + ViewType.EMBEDDED), new ViewInfo(PanelInspector.class, "Panel Inspector", ViewType.CENTER_OWNED_INSPECTOR)); @Override public Collection getMenuItemInfos() { @@ -201,5 +204,14 @@ public Collection getPolicyInfos() { @Override public Collection getViews(String componentTypeId) { return VIEW_INFOS; + } + + @Override + public T getAsset(TypeInfo typeInfo, Class assetClass) { + if (assetClass.isAssignableFrom(ImageIcon.class) && + typeInfo.getTypeClass().equals(CanvasManifestation.class)) { + return assetClass.cast(ICON); + } + return super.getAsset(typeInfo, assetClass); } } diff --git a/collectionComponent/src/main/java/gov/nasa/arc/mct/collection/CollectionComponentProvider.java b/collectionComponent/src/main/java/gov/nasa/arc/mct/collection/CollectionComponentProvider.java index edb8faa9..e57a3838 100644 --- a/collectionComponent/src/main/java/gov/nasa/arc/mct/collection/CollectionComponentProvider.java +++ b/collectionComponent/src/main/java/gov/nasa/arc/mct/collection/CollectionComponentProvider.java @@ -21,16 +21,17 @@ *******************************************************************************/ package gov.nasa.arc.mct.collection; -import gov.nasa.arc.mct.components.collection.CollectionComponent; -import gov.nasa.arc.mct.services.component.AbstractComponentProvider; -import gov.nasa.arc.mct.services.component.ComponentTypeInfo; -import gov.nasa.arc.mct.services.component.ViewInfo; - -import java.util.Collection; -import java.util.Collections; -import java.util.ResourceBundle; - -import javax.swing.ImageIcon; +import gov.nasa.arc.mct.components.collection.CollectionComponent; +import gov.nasa.arc.mct.services.component.AbstractComponentProvider; +import gov.nasa.arc.mct.services.component.ComponentTypeInfo; +import gov.nasa.arc.mct.services.component.TypeInfo; +import gov.nasa.arc.mct.services.component.ViewInfo; + +import java.util.Collection; +import java.util.Collections; +import java.util.ResourceBundle; + +import javax.swing.ImageIcon; /** * Provides the MCT Collection Component. @@ -40,6 +41,8 @@ public class CollectionComponentProvider extends AbstractComponentProvider { private static ResourceBundle bundle = ResourceBundle.getBundle("CollectionComponent"); private final ComponentTypeInfo componentTypeInfo; + + private static final ImageIcon ICON = new ImageIcon(CollectionComponent.class.getResource("/icons/Collection.png")); /** * Default constructor for a collection component object. @@ -49,7 +52,7 @@ public CollectionComponentProvider() { componentTypeInfo = new ComponentTypeInfo( bundle.getString("display_name"), bundle.getString("description"), - CollectionComponent.class, true, new ImageIcon(CollectionComponent.class.getResource("/icons/Collection.png"))); + CollectionComponent.class, true); } @Override @@ -60,5 +63,14 @@ public Collection getComponentTypes() { @Override public Collection getViews(String componentTypeId) { return Collections.emptyList(); - } + } + + @Override + public T getAsset(TypeInfo typeInfo, Class assetClass) { + if (assetClass.isAssignableFrom(ImageIcon.class) && + typeInfo.getTypeClass().equals(CollectionComponent.class)) { + return assetClass.cast(ICON); + } + return super.getAsset(typeInfo, assetClass); + } } diff --git a/dynamicGraphics/src/main/java/gov/nasa/arc/mct/graphics/GraphicalComponentProvider.java b/dynamicGraphics/src/main/java/gov/nasa/arc/mct/graphics/GraphicalComponentProvider.java index 13268988..56c92df1 100644 --- a/dynamicGraphics/src/main/java/gov/nasa/arc/mct/graphics/GraphicalComponentProvider.java +++ b/dynamicGraphics/src/main/java/gov/nasa/arc/mct/graphics/GraphicalComponentProvider.java @@ -21,35 +21,38 @@ *******************************************************************************/ package gov.nasa.arc.mct.graphics; -import gov.nasa.arc.mct.graphics.component.GraphicalComponent; -import gov.nasa.arc.mct.graphics.component.GraphicalComponentWizardUI; -import gov.nasa.arc.mct.graphics.view.GraphicalManifestation; -import gov.nasa.arc.mct.graphics.view.StaticGraphicalView; -import gov.nasa.arc.mct.policy.PolicyInfo; -import gov.nasa.arc.mct.services.component.AbstractComponentProvider; -import gov.nasa.arc.mct.services.component.ComponentTypeInfo; -import gov.nasa.arc.mct.services.component.ViewInfo; -import gov.nasa.arc.mct.services.component.ViewType; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.ResourceBundle; - -import javax.swing.ImageIcon; +import gov.nasa.arc.mct.graphics.component.GraphicalComponent; +import gov.nasa.arc.mct.graphics.component.GraphicalComponentWizardUI; +import gov.nasa.arc.mct.graphics.view.GraphicalManifestation; +import gov.nasa.arc.mct.graphics.view.StaticGraphicalView; +import gov.nasa.arc.mct.policy.PolicyInfo; +import gov.nasa.arc.mct.services.component.AbstractComponentProvider; +import gov.nasa.arc.mct.services.component.ComponentTypeInfo; +import gov.nasa.arc.mct.services.component.CreateWizardUI; +import gov.nasa.arc.mct.services.component.TypeInfo; +import gov.nasa.arc.mct.services.component.ViewInfo; +import gov.nasa.arc.mct.services.component.ViewType; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.ResourceBundle; + +import javax.swing.ImageIcon; public class GraphicalComponentProvider extends AbstractComponentProvider { private static ResourceBundle bundle = ResourceBundle.getBundle("GraphicsResourceBundle"); final Collection policyInfos; + + private static final ImageIcon VIEW_ICON = + new ImageIcon(GraphicalManifestation.class.getResource("/icons/mct_icon_menu_graphical.png")); private static final List VIEW_INFOS = Arrays.asList( - new ViewInfo(GraphicalManifestation.class, GraphicalManifestation.VIEW_ROLE_NAME, GraphicalManifestation.class.getName(), ViewType.OBJECT, - new ImageIcon(GraphicalManifestation.class.getResource("/icons/mct_icon_menu_graphical.png"))), - new ViewInfo(GraphicalManifestation.class, GraphicalManifestation.VIEW_ROLE_NAME, GraphicalManifestation.class.getName(), ViewType.EMBEDDED, - new ImageIcon(GraphicalManifestation.class.getResource("/icons/mct_icon_menu_graphical.png"))), + new ViewInfo(GraphicalManifestation.class, GraphicalManifestation.VIEW_ROLE_NAME, GraphicalManifestation.class.getName(), ViewType.OBJECT), + new ViewInfo(GraphicalManifestation.class, GraphicalManifestation.VIEW_ROLE_NAME, GraphicalManifestation.class.getName(), ViewType.EMBEDDED), new ViewInfo(StaticGraphicalView.class, GraphicalManifestation.VIEW_ROLE_NAME, ViewType.OBJECT), new ViewInfo(StaticGraphicalView.class, GraphicalManifestation.VIEW_ROLE_NAME, ViewType.EMBEDDED) ); @@ -74,10 +77,23 @@ public Collection getComponentTypes() { return Collections.singleton( new ComponentTypeInfo(bundle.getString("Component_Name"), bundle.getString("Component_Description"), - GraphicalComponent.class, - new GraphicalComponentWizardUI(), - null));//new ImageIcon(GraphicalComponentProvider.class.getResource("/icons/importSVG.png")))); + GraphicalComponent.class)); } - + + @Override + public T getAsset(TypeInfo typeInfo, Class assetClass) { + if (assetClass.isAssignableFrom(ImageIcon.class)) { + if (typeInfo.getTypeClass().equals(GraphicalManifestation.class) || + typeInfo.getTypeClass().equals(StaticGraphicalView.class)) { + return assetClass.cast(VIEW_ICON); + } + } + if (assetClass.isAssignableFrom(CreateWizardUI.class)) { + if (typeInfo.getTypeClass().equals(GraphicalComponent.class)) { + return assetClass.cast(new GraphicalComponentWizardUI()); + } + } + return super.getAsset(typeInfo, assetClass); + } } diff --git a/evaluatorComponent/src/main/java/gov/nasa/arc/mct/evaluator/component/EvaluatorComponentProvider.java b/evaluatorComponent/src/main/java/gov/nasa/arc/mct/evaluator/component/EvaluatorComponentProvider.java index 8929b169..9f91f2a8 100644 --- a/evaluatorComponent/src/main/java/gov/nasa/arc/mct/evaluator/component/EvaluatorComponentProvider.java +++ b/evaluatorComponent/src/main/java/gov/nasa/arc/mct/evaluator/component/EvaluatorComponentProvider.java @@ -31,6 +31,8 @@ import gov.nasa.arc.mct.policy.PolicyInfo; import gov.nasa.arc.mct.services.component.AbstractComponentProvider; import gov.nasa.arc.mct.services.component.ComponentTypeInfo; +import gov.nasa.arc.mct.services.component.CreateWizardUI; +import gov.nasa.arc.mct.services.component.TypeInfo; import gov.nasa.arc.mct.services.component.ViewInfo; import gov.nasa.arc.mct.services.component.ViewType; @@ -48,14 +50,14 @@ public class EvaluatorComponentProvider extends AbstractComponentProvider { private final Collection infos; private final Collection policies = new ArrayList(); - + + private static final ImageIcon VIEW_ICON = new ImageIcon(ExpressionsViewManifestation.class.getResource("/icons/mct_icon_menu_settings.png")); public EvaluatorComponentProvider() { infos = Arrays.asList(new ComponentTypeInfo( bundle.getString("display_name"), bundle.getString("description"), - EvaluatorComponent.class, - new EvaluatorWizardUI())); + EvaluatorComponent.class)); policies.add(new PolicyInfo(PolicyInfo.CategoryType.FILTER_VIEW_ROLE.getKey(), EvaluatorViewPolicy.class)); policies.add(new PolicyInfo(PolicyInfo.CategoryType.FILTER_VIEW_ROLE.getKey(), EnumeratorViewPolicy.class)); } @@ -71,10 +73,9 @@ public Collection getViews(String componentTypeId) { if (EvaluatorComponent.class.getName().equals(componentTypeId)) { List views = new ArrayList(); views.add(new ViewInfo(InfoViewManifestation.class, InfoViewManifestation.VIEW_NAME, ViewType.OBJECT)); - views.add(new ViewInfo(ExpressionsViewManifestation.class, ExpressionsViewManifestation.VIEW_NAME, ExpressionsViewManifestation.class.getName(), - ViewType.OBJECT, - new ImageIcon(ExpressionsViewManifestation.class.getResource("/icons/mct_icon_menu_settings.png")))); - views.add(new ViewInfo(ExpressionsViewManifestation.class, ExpressionsViewManifestation.VIEW_NAME, ExpressionsViewManifestation.class.getName(), ViewType.CENTER, null, null, true, EvaluatorComponent.class)); + views.add(new ViewInfo(ExpressionsViewManifestation.class, ExpressionsViewManifestation.VIEW_NAME, + ExpressionsViewManifestation.class.getName(), ViewType.OBJECT)); + views.add(new ViewInfo(ExpressionsViewManifestation.class, ExpressionsViewManifestation.VIEW_NAME, ExpressionsViewManifestation.class.getName(), ViewType.CENTER, true, EvaluatorComponent.class)); return views; } return Collections.singleton(new ViewInfo(InfoViewManifestation.class, InfoViewManifestation.VIEW_NAME, ViewType.OBJECT)); @@ -95,5 +96,21 @@ public Collection getMenuItemInfos() { MenuItemType.NORMAL, PlaceObjectsInEnumAction.class)); } + + @Override + public T getAsset(TypeInfo typeInfo, Class assetClass) { + if (assetClass.isAssignableFrom(ImageIcon.class)) { + if (typeInfo.getTypeClass().equals(ExpressionsViewManifestation.class)) { + return assetClass.cast(VIEW_ICON); + } + } + if (assetClass.isAssignableFrom(CreateWizardUI.class)) { + if (typeInfo.getTypeClass().equals(EvaluatorComponent.class)) { + return assetClass.cast(new EvaluatorWizardUI()); + } + } + return super.getAsset(typeInfo, assetClass); + } + } diff --git a/evaluatorComponent/src/main/java/gov/nasa/arc/mct/evaluator/component/MultiComponentProvider.java b/evaluatorComponent/src/main/java/gov/nasa/arc/mct/evaluator/component/MultiComponentProvider.java index d2785cff..818faeff 100644 --- a/evaluatorComponent/src/main/java/gov/nasa/arc/mct/evaluator/component/MultiComponentProvider.java +++ b/evaluatorComponent/src/main/java/gov/nasa/arc/mct/evaluator/component/MultiComponentProvider.java @@ -33,6 +33,8 @@ import gov.nasa.arc.mct.policy.PolicyInfo; import gov.nasa.arc.mct.services.component.AbstractComponentProvider; import gov.nasa.arc.mct.services.component.ComponentTypeInfo; +import gov.nasa.arc.mct.services.component.CreateWizardUI; +import gov.nasa.arc.mct.services.component.TypeInfo; import gov.nasa.arc.mct.services.component.ViewInfo; import gov.nasa.arc.mct.services.component.ViewType; @@ -58,8 +60,7 @@ public MultiComponentProvider() { infos = Arrays.asList(new ComponentTypeInfo( bundle.getString("display_name"), bundle.getString("description"), - MultiComponent.class, - new MultiWizardUI())); + MultiComponent.class)); policies.add(new PolicyInfo(PolicyInfo.CategoryType.FILTER_VIEW_ROLE.getKey(), EvaluatorViewPolicy.class)); policies.add(new PolicyInfo(PolicyInfo.CategoryType.FILTER_VIEW_ROLE.getKey(), EnumeratorViewPolicy.class)); policies.add(new PolicyInfo(PolicyInfo.CategoryType.CAN_REMOVE_MANIFESTATION_CATEGORY.getKey(), MultiChildRemovalPolicy.class)); @@ -76,9 +77,9 @@ public Collection getComponentTypes() { public Collection getViews(String componentTypeId) { if (MultiComponent.class.getName().equals(componentTypeId)) { List views = new ArrayList(); - views.add(new ViewInfo(InfoViewManifestation.class, InfoViewManifestation.VIEW_NAME, InfoViewManifestation.class.getName(), ViewType.OBJECT, null, null, false, MultiComponent.class)); + views.add(new ViewInfo(InfoViewManifestation.class, InfoViewManifestation.VIEW_NAME, InfoViewManifestation.class.getName(), ViewType.OBJECT, false, MultiComponent.class)); views.add(new ViewInfo(MultiViewManifestation.class, MultiViewManifestation.VIEW_NAME, ViewType.OBJECT)); - views.add(new ViewInfo(MultiViewManifestation.class, MultiViewManifestation.VIEW_NAME, InfoViewManifestation.class.getName(), ViewType.CENTER, null, null, true, MultiComponent.class)); + views.add(new ViewInfo(MultiViewManifestation.class, MultiViewManifestation.VIEW_NAME, InfoViewManifestation.class.getName(), ViewType.CENTER, true, MultiComponent.class)); return views; } return Collections.singleton(new ViewInfo(InfoViewManifestation.class, InfoViewManifestation.VIEW_NAME, ViewType.OBJECT)); @@ -100,4 +101,13 @@ public Collection getMenuItemInfos() { } + @Override + public T getAsset(TypeInfo typeInfo, Class assetClass) { + if (assetClass.isAssignableFrom(CreateWizardUI.class)) { + if (typeInfo.getTypeClass().equals(MultiComponent.class)) { + return assetClass.cast(new MultiWizardUI()); + } + } + return super.getAsset(typeInfo, assetClass); + } } diff --git a/exampleplugin/src/main/java/org/acme/example/component/ExampleComponentProvider.java b/exampleplugin/src/main/java/org/acme/example/component/ExampleComponentProvider.java index 6aba03a0..69a96e28 100644 --- a/exampleplugin/src/main/java/org/acme/example/component/ExampleComponentProvider.java +++ b/exampleplugin/src/main/java/org/acme/example/component/ExampleComponentProvider.java @@ -21,33 +21,34 @@ *******************************************************************************/ package org.acme.example.component; -import gov.nasa.arc.mct.gui.MenuItemInfo; -import gov.nasa.arc.mct.gui.MenuItemInfo.MenuItemType; -import gov.nasa.arc.mct.policy.PolicyInfo; -import gov.nasa.arc.mct.services.component.AbstractComponentProvider; -import gov.nasa.arc.mct.services.component.ComponentTypeInfo; -import gov.nasa.arc.mct.services.component.ViewInfo; -import gov.nasa.arc.mct.services.component.ViewType; +import gov.nasa.arc.mct.gui.MenuItemInfo; +import gov.nasa.arc.mct.gui.MenuItemInfo.MenuItemType; +import gov.nasa.arc.mct.policy.PolicyInfo; +import gov.nasa.arc.mct.services.component.AbstractComponentProvider; +import gov.nasa.arc.mct.services.component.ComponentTypeInfo; +import gov.nasa.arc.mct.services.component.TypeInfo; +import gov.nasa.arc.mct.services.component.ViewInfo; +import gov.nasa.arc.mct.services.component.ViewType; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.ResourceBundle; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.ResourceBundle; import javax.swing.ImageIcon; -import org.acme.example.actions.APICreationAction; -import org.acme.example.actions.AboutExampleAction; -import org.acme.example.actions.AddOrRemoveNodeBorderAction; -import org.acme.example.actions.BeepAction; -import org.acme.example.actions.SubmenuMenu; -import org.acme.example.policy.FilterViewPolicy; -import org.acme.example.telemetry.TelemetryComponent; -import org.acme.example.view.CenterPanePanel; -import org.acme.example.view.PrivateInfoView; -import org.acme.example.view.PublicInfoView; -import org.acme.example.view.SaveModelStateView; -import org.acme.example.view.ShowChildrenInTableView; +import org.acme.example.actions.APICreationAction; +import org.acme.example.actions.AboutExampleAction; +import org.acme.example.actions.AddOrRemoveNodeBorderAction; +import org.acme.example.actions.BeepAction; +import org.acme.example.actions.SubmenuMenu; +import org.acme.example.policy.FilterViewPolicy; +import org.acme.example.telemetry.TelemetryComponent; +import org.acme.example.view.CenterPanePanel; +import org.acme.example.view.PrivateInfoView; +import org.acme.example.view.PublicInfoView; +import org.acme.example.view.SaveModelStateView; +import org.acme.example.view.ShowChildrenInTableView; /** * The ExampleComponentProvider class exposes the ExampleComponent to MCT. @@ -59,7 +60,10 @@ public class ExampleComponentProvider extends AbstractComponentProvider { private final ComponentTypeInfo exampleComponentType; private final ComponentTypeInfo telemetryComponentType; - + + private static final ImageIcon ICON = + new ImageIcon(ExampleComponentProvider.class.getResource("/icons/mct_icon_telemetry.png")); + public ExampleComponentProvider() { // this is the component type we are providing. The display name and description are used // by the MCT menu system for creating new instances and thus should be human readable @@ -72,8 +76,7 @@ public ExampleComponentProvider() { bundle.getString("telemetry_display_name"), bundle.getString("telemetry_description"), TelemetryComponent.class, - true, - new ImageIcon(getClass().getResource("/icons/mct_icon_telemetry.png"))); + true); } @@ -177,5 +180,27 @@ public Collection getPolicyInfos() { * ExecutionResult result = * policyManager.execute(String categoryKey, PolicyContext context); */ - } + } + + + @Override + public T getAsset(TypeInfo typeInfo, Class assetClass) { + /* + * Relevant "assets" associated with certain types should + * be delivered here. Examples of assets include ImageIcons and + * CreateWizardUI objects. + * + * Typically, it is desirable to provide any needed "assets" + * here for the ComponentTypeInfos and ViewInfos that are + * exposed in the same ComponentProvider. (In principle, + * however, this could be used as a way to introduce assets + * for types defined in a totally different plug-in.) + */ + if (assetClass.isAssignableFrom(ImageIcon.class)) { + if (typeInfo.getTypeClass().equals(TelemetryComponent.class)) { + return assetClass.cast(ICON); + } + } + return super.getAsset(typeInfo, assetClass); + } } diff --git a/executableButtons/src/main/java/gov/nasa/jsc/mct/executable/buttons/ExecutableButtonComponentProvider.java b/executableButtons/src/main/java/gov/nasa/jsc/mct/executable/buttons/ExecutableButtonComponentProvider.java index 479d2d64..53e1d8e8 100644 --- a/executableButtons/src/main/java/gov/nasa/jsc/mct/executable/buttons/ExecutableButtonComponentProvider.java +++ b/executableButtons/src/main/java/gov/nasa/jsc/mct/executable/buttons/ExecutableButtonComponentProvider.java @@ -25,6 +25,8 @@ import gov.nasa.arc.mct.gui.MenuItemInfo.MenuItemType; import gov.nasa.arc.mct.services.component.AbstractComponentProvider; import gov.nasa.arc.mct.services.component.ComponentTypeInfo; +import gov.nasa.arc.mct.services.component.CreateWizardUI; +import gov.nasa.arc.mct.services.component.TypeInfo; import gov.nasa.arc.mct.services.component.ViewInfo; import gov.nasa.arc.mct.services.component.ViewType; import gov.nasa.jsc.mct.executable.buttons.view.ExecutableButtonManifestation; @@ -45,6 +47,9 @@ public class ExecutableButtonComponentProvider extends AbstractComponentProvider private static final ResourceBundle bundle = ResourceBundle.getBundle("ResourceBundle"); private final AtomicReference executableButtonComponentType = new AtomicReference(); + +// private static final ImageIcon VIEW_ICON = +// new ImageIcon(ExecutableButtonComponent.class.getResource("/icons/executableIcon.png")); private static final String OBJECTS_CREATE_EXT_PATH = "/objects/creation.ext"; private static final String THIS_EXECUTE_PATH = "/this/additions"; @@ -58,9 +63,7 @@ private ComponentTypeInfo createTypeInfo() { return new ComponentTypeInfo( bundle.getString("display_name"), bundle.getString("description"), - ExecutableButtonComponent.class, - new CreateExecutableButtonComponentWizardUI(), - new ImageIcon(ExecutableButtonComponent.class.getResource("/icons/executableIcon.png")) + ExecutableButtonComponent.class ); } @@ -74,13 +77,9 @@ public Collection getViews(String componentTypeId) { if (componentTypeId.equals(ExecutableButtonComponent.class.getName())) { Collection views = new ArrayList(); views.add(new ViewInfo(ExecutableButtonManifestation.class, ExecutableButtonManifestation.VIEW_NAME, ExecutableButtonManifestation.class.getName(), - ViewType.OBJECT, - new ImageIcon(getClass().getResource("/icons/executableViewButton-OFF.png")), - new ImageIcon(getClass().getResource("/icons/executableViewButton-ON.png")), false, ExecutableButtonComponent.class)); + ViewType.OBJECT, false, ExecutableButtonComponent.class)); views.add(new ViewInfo(ExecutableButtonManifestation.class, ExecutableButtonManifestation.VIEW_NAME, ExecutableButtonManifestation.class.getName(), - ViewType.EMBEDDED, - new ImageIcon(getClass().getResource("/icons/executableViewButton-OFF.png")), - new ImageIcon(getClass().getResource("/icons/executableViewButton-ON.png")), false, ExecutableButtonComponent.class)); + ViewType.EMBEDDED, false, ExecutableButtonComponent.class)); return views; } @@ -101,6 +100,23 @@ public Collection getMenuItemInfos() { MenuItemType.NORMAL, ExecutableButtonThisAction.class) ); - } + } + + @Override + public T getAsset(TypeInfo typeInfo, Class assetClass) { + if (assetClass.isAssignableFrom(ImageIcon.class)) { + if (typeInfo.getTypeClass().equals(ExecutableButtonManifestation.class)) { + // TODO: Needs new icon + // return assetClass.cast(VIEW_ICON); + } + } + if (assetClass.isAssignableFrom(CreateWizardUI.class)) { + if (typeInfo.getTypeClass().equals(ExecutableButtonComponent.class)) { + return assetClass.cast(new CreateExecutableButtonComponentWizardUI()); + } + } + return super.getAsset(typeInfo, assetClass); + } + } diff --git a/fastPlotViews/src/main/java/gov/nasa/arc/mct/fastplot/PlotViewProvider.java b/fastPlotViews/src/main/java/gov/nasa/arc/mct/fastplot/PlotViewProvider.java index 3dff8326..4b2319d8 100644 --- a/fastPlotViews/src/main/java/gov/nasa/arc/mct/fastplot/PlotViewProvider.java +++ b/fastPlotViews/src/main/java/gov/nasa/arc/mct/fastplot/PlotViewProvider.java @@ -21,19 +21,20 @@ *******************************************************************************/ package gov.nasa.arc.mct.fastplot; -import gov.nasa.arc.mct.fastplot.policy.PlotStringPolicy; -import gov.nasa.arc.mct.fastplot.policy.PlotViewPolicy; -import gov.nasa.arc.mct.fastplot.view.PlotViewManifestation; -import gov.nasa.arc.mct.policy.PolicyInfo; -import gov.nasa.arc.mct.services.component.AbstractComponentProvider; -import gov.nasa.arc.mct.services.component.ViewInfo; -import gov.nasa.arc.mct.services.component.ViewType; - -import java.util.Arrays; -import java.util.Collection; -import java.util.List; - -import javax.swing.ImageIcon; +import gov.nasa.arc.mct.fastplot.policy.PlotStringPolicy; +import gov.nasa.arc.mct.fastplot.policy.PlotViewPolicy; +import gov.nasa.arc.mct.fastplot.view.PlotViewManifestation; +import gov.nasa.arc.mct.policy.PolicyInfo; +import gov.nasa.arc.mct.services.component.AbstractComponentProvider; +import gov.nasa.arc.mct.services.component.TypeInfo; +import gov.nasa.arc.mct.services.component.ViewInfo; +import gov.nasa.arc.mct.services.component.ViewType; + +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + +import javax.swing.ImageIcon; /** * Factory for PlotViewRole. @@ -42,6 +43,9 @@ public class PlotViewProvider extends AbstractComponentProvider { final Collection policyInfos; private final List viewInfos; + + private static final ImageIcon ICON = + new ImageIcon(PlotViewProvider.class.getResource("/icons/mct_icon_menu_plot.png")); public PlotViewProvider() { policyInfos = Arrays.asList(new PolicyInfo(PolicyInfo.CategoryType.FILTER_VIEW_ROLE.getKey(), PlotViewPolicy.class), @@ -49,11 +53,9 @@ public PlotViewProvider() { ); viewInfos = Arrays.asList( - new ViewInfo(PlotViewManifestation.class, PlotViewManifestation.VIEW_ROLE_NAME, "gov.nasa.arc.mct.fastplot.view.PlotViewRole", ViewType.OBJECT, - new ImageIcon(getClass().getResource("/icons/mct_icon_menu_plot.png"))), + new ViewInfo(PlotViewManifestation.class, PlotViewManifestation.VIEW_ROLE_NAME, "gov.nasa.arc.mct.fastplot.view.PlotViewRole", ViewType.OBJECT), new ViewInfo(PlotViewManifestation.class, PlotViewManifestation.VIEW_ROLE_NAME, "gov.nasa.arc.mct.fastplot.view.PlotViewRole", ViewType.CENTER), - new ViewInfo(PlotViewManifestation.class, PlotViewManifestation.VIEW_ROLE_NAME, "gov.nasa.arc.mct.fastplot.view.PlotViewRole", ViewType.EMBEDDED, - new ImageIcon(getClass().getResource("/icons/mct_icon_menu_plot.png")))); + new ViewInfo(PlotViewManifestation.class, PlotViewManifestation.VIEW_ROLE_NAME, "gov.nasa.arc.mct.fastplot.view.PlotViewRole", ViewType.EMBEDDED)); } @Override @@ -64,5 +66,14 @@ public Collection getViews(String componentTypeId) { @Override public Collection getPolicyInfos() { return policyInfos; - } + } + + @Override + public T getAsset(TypeInfo typeInfo, Class assetClass) { + if (assetClass.isAssignableFrom(ImageIcon.class) && + typeInfo.getTypeClass().equals(PlotViewManifestation.class)) { + return assetClass.cast(ICON); + } + return super.getAsset(typeInfo, assetClass); + } } diff --git a/limits/src/main/java/gov/nasa/arc/mct/limits/LimitLineComponentProvider.java b/limits/src/main/java/gov/nasa/arc/mct/limits/LimitLineComponentProvider.java index b001b0b7..4a3ee983 100644 --- a/limits/src/main/java/gov/nasa/arc/mct/limits/LimitLineComponentProvider.java +++ b/limits/src/main/java/gov/nasa/arc/mct/limits/LimitLineComponentProvider.java @@ -21,32 +21,30 @@ *******************************************************************************/ package gov.nasa.arc.mct.limits; -import gov.nasa.arc.mct.gui.MenuItemInfo; -import gov.nasa.arc.mct.policy.PolicyInfo; -import gov.nasa.arc.mct.services.component.AbstractComponentProvider; -import gov.nasa.arc.mct.services.component.ComponentTypeInfo; -import gov.nasa.arc.mct.services.component.ViewInfo; - -import java.util.Collection; -import java.util.Collections; -import java.util.ResourceBundle; - -import javax.swing.ImageIcon; +import gov.nasa.arc.mct.gui.MenuItemInfo; +import gov.nasa.arc.mct.policy.PolicyInfo; +import gov.nasa.arc.mct.services.component.AbstractComponentProvider; +import gov.nasa.arc.mct.services.component.ComponentTypeInfo; +import gov.nasa.arc.mct.services.component.CreateWizardUI; +import gov.nasa.arc.mct.services.component.TypeInfo; +import gov.nasa.arc.mct.services.component.ViewInfo; + +import java.util.Collection; +import java.util.Collections; +import java.util.ResourceBundle; public class LimitLineComponentProvider extends AbstractComponentProvider { private static final ResourceBundle bundle = ResourceBundle.getBundle("Limits"); private final ComponentTypeInfo componentTypeInfo; - + public LimitLineComponentProvider() { componentTypeInfo = new ComponentTypeInfo( bundle.getString("display_name"), bundle.getString("description"), - LimitLineComponent.class, - new LimitLineCreateWizardUI(), - new ImageIcon(LimitLineComponent.class.getResource("/icons/limit.png"))); + LimitLineComponent.class); } @Override @@ -68,5 +66,15 @@ public Collection getMenuItemInfos() { public Collection getPolicyInfos() { return Collections.emptyList(); } - + + @Override + public T getAsset(TypeInfo typeInfo, Class assetClass) { + if (assetClass.isAssignableFrom(CreateWizardUI.class)) { + if (typeInfo.getTypeClass().equals(LimitLineComponent.class)) { + return assetClass.cast(new LimitLineCreateWizardUI()); + } + } + return super.getAsset(typeInfo, assetClass); + } + } diff --git a/mctCoreTaxonomyProvider/src/main/java/gov/nasa/arc/mct/core/provider/CoreComponentProvider.java b/mctCoreTaxonomyProvider/src/main/java/gov/nasa/arc/mct/core/provider/CoreComponentProvider.java index 3fd96e6a..bd22bbf5 100644 --- a/mctCoreTaxonomyProvider/src/main/java/gov/nasa/arc/mct/core/provider/CoreComponentProvider.java +++ b/mctCoreTaxonomyProvider/src/main/java/gov/nasa/arc/mct/core/provider/CoreComponentProvider.java @@ -52,6 +52,7 @@ import gov.nasa.arc.mct.services.component.AbstractComponentProvider; import gov.nasa.arc.mct.services.component.ComponentTypeInfo; import gov.nasa.arc.mct.services.component.ProviderDelegate; +import gov.nasa.arc.mct.services.component.TypeInfo; import gov.nasa.arc.mct.services.component.ViewInfo; import gov.nasa.arc.mct.services.component.ViewType; import gov.nasa.arc.mct.services.internal.component.ComponentInitializer; @@ -68,17 +69,18 @@ public class CoreComponentProvider extends AbstractComponentProvider implements DefaultComponentProvider { private static final ResourceBundle resource = ResourceBundle.getBundle("CoreTaxonomyResourceBundle"); // NO18N - + + private ImageIcon GROUPS_ICON = new ImageIcon(getClass().getResource("/icons/mct_icon_groups.png")); + private ImageIcon DROPBOX_ICON = new ImageIcon(getClass().getResource("/icons/mct_icon_dropbox.png")); + @Override public Collection getComponentTypes() { List compInfos = new ArrayList(); ComponentTypeInfo typeInfo = new ComponentTypeInfo(resource.getString("discipline_component_display_name"), resource - .getString("discipline_component_description"), TelemetryDisciplineComponent.class, false, - new ImageIcon(getClass().getResource("/icons/mct_icon_groups.png"))); + .getString("discipline_component_description"), TelemetryDisciplineComponent.class, false); compInfos.add(typeInfo); typeInfo = new ComponentTypeInfo(resource.getString("user_dropbox_component_display_name"), resource - .getString("user_dropbox_component_description"), TelemetryUserDropBoxComponent.class, false, - new ImageIcon(getClass().getResource("/icons/mct_icon_dropbox.png"))); + .getString("user_dropbox_component_description"), TelemetryUserDropBoxComponent.class, false); compInfos.add(typeInfo); typeInfo = new ComponentTypeInfo(resource.getString("mine_component_display_name"), resource .getString("mine_component_description"), MineTaxonomyComponent.class, false); @@ -195,5 +197,18 @@ public void createDefaultComponents() { public ProviderDelegate getProviderDelegate() { return new CoreComponentProviderDelegate(); } - + + @Override + public T getAsset(TypeInfo typeInfo, Class assetClass) { + if (assetClass.isAssignableFrom(ImageIcon.class)) { + if (typeInfo.getTypeClass().equals(TelemetryDisciplineComponent.class)) { + return assetClass.cast(GROUPS_ICON); + } + if (typeInfo.getTypeClass().equals(TelemetryUserDropBoxComponent.class)) { + return assetClass.cast(DROPBOX_ICON); + } + } + return super.getAsset(typeInfo, assetClass); + } + } diff --git a/mctcore/src/main/java/gov/nasa/arc/mct/registry/ExternalComponentRegistryImpl.java b/mctcore/src/main/java/gov/nasa/arc/mct/registry/ExternalComponentRegistryImpl.java index e59c0120..6a193fc7 100644 --- a/mctcore/src/main/java/gov/nasa/arc/mct/registry/ExternalComponentRegistryImpl.java +++ b/mctcore/src/main/java/gov/nasa/arc/mct/registry/ExternalComponentRegistryImpl.java @@ -326,7 +326,7 @@ public SearchProvider getSearchProvider() { @Override public T getAsset(TypeInfo objectType, Class assetType) { - return null; + return provider.getAsset(objectType, assetType); } } diff --git a/nonTimePlots/src/main/java/gov/nasa/arc/mct/nontimeplot/NonTimePlotComponentProvider.java b/nonTimePlots/src/main/java/gov/nasa/arc/mct/nontimeplot/NonTimePlotComponentProvider.java index 0dd89b83..698b3fbd 100644 --- a/nonTimePlots/src/main/java/gov/nasa/arc/mct/nontimeplot/NonTimePlotComponentProvider.java +++ b/nonTimePlots/src/main/java/gov/nasa/arc/mct/nontimeplot/NonTimePlotComponentProvider.java @@ -32,8 +32,6 @@ import java.util.Collection; import java.util.Collections; -import javax.swing.ImageIcon; - public class NonTimePlotComponentProvider extends AbstractComponentProvider { private Collection policies = @@ -41,15 +39,11 @@ public class NonTimePlotComponentProvider extends AbstractComponentProvider { private Collection views = Arrays.asList(new ViewInfo(NonTimePlotView.class, "Non Time", "gov.nasa.arc.mct.nontimeplot.NonTimePlotView", - ViewType.OBJECT, - new ImageIcon(getClass().getResource("/images/nonTimeViewButton-OFF.png")), - new ImageIcon(getClass().getResource("/images/nonTimeViewButton-ON.png"))), + ViewType.OBJECT), new ViewInfo(NonTimePlotView.class, "Non Time", "gov.nasa.arc.mct.nontimeplot.NonTimePlotView", - ViewType.EMBEDDED, - new ImageIcon(getClass().getResource("/images/nonTimeViewButton-OFF.png")), - new ImageIcon(getClass().getResource("/images/nonTimeViewButton-ON.png")))); + ViewType.EMBEDDED)); @Override public Collection getPolicyInfos() { diff --git a/platform/src/main/java/gov/nasa/arc/mct/defaults/view/DefaultViewProvider.java b/platform/src/main/java/gov/nasa/arc/mct/defaults/view/DefaultViewProvider.java index cce02c79..7959fe3b 100644 --- a/platform/src/main/java/gov/nasa/arc/mct/defaults/view/DefaultViewProvider.java +++ b/platform/src/main/java/gov/nasa/arc/mct/defaults/view/DefaultViewProvider.java @@ -48,7 +48,9 @@ public class DefaultViewProvider extends AbstractComponentProvider { private final List myViewInfos; - + + private ImageIcon ICON = new ImageIcon(getClass().getResource("/icons/mct_icon_menu_info.png")); + public DefaultViewProvider() { ResourceBundle bundle = ResourceBundle.getBundle("DefaultView"); @@ -60,8 +62,7 @@ public DefaultViewProvider() { viewInfos.add(new ViewInfo(LabelViewManifestation.class, bundle.getString("LabelViewRoleName"), ViewType.TITLE)); viewInfos.add(new ViewInfo(InspectionArea.class, InspectionArea.INSPECTION_AREA_VIEW_PROP_KEY, ViewType.RIGHT)); viewInfos.add(new ViewInfo(SwitcherView.class, bundle.getString("SwitcherViewName"), ViewType.VIEW_SWITCHER)); - viewInfos.add(new ViewInfo(InfoView.class, bundle.getString("InfoViewName"), ViewType.OBJECT, - new ImageIcon(getClass().getResource("/icons/mct_icon_menu_info.png")))); + viewInfos.add(new ViewInfo(InfoView.class, bundle.getString("InfoViewName"), ViewType.OBJECT)); myViewInfos = viewInfos; } @@ -74,6 +75,9 @@ public Collection getViews(String componentTypeId) { @Override public T getAsset(TypeInfo type, Class assetClass) { if (assetClass.isAssignableFrom(ImageIcon.class)) { + if (InfoView.class.isAssignableFrom(type.getTypeClass())) { + return assetClass.cast(ICON); + } int sz = 16; if (View.class.isAssignableFrom(type.getTypeClass())) { sz = 9; @@ -85,5 +89,7 @@ public T getAsset(TypeInfo type, Class assetClass) { sz, Color.WHITE)); } return super.getAsset(type, assetClass); - } + } + + } diff --git a/tableViews/src/main/java/gov/nasa/arc/mct/table/TableViewProvider.java b/tableViews/src/main/java/gov/nasa/arc/mct/table/TableViewProvider.java index cda9b7fb..88498a8a 100644 --- a/tableViews/src/main/java/gov/nasa/arc/mct/table/TableViewProvider.java +++ b/tableViews/src/main/java/gov/nasa/arc/mct/table/TableViewProvider.java @@ -22,18 +22,19 @@ package gov.nasa.arc.mct.table; -import gov.nasa.arc.mct.policy.PolicyInfo; -import gov.nasa.arc.mct.services.component.AbstractComponentProvider; -import gov.nasa.arc.mct.services.component.ViewInfo; -import gov.nasa.arc.mct.services.component.ViewType; -import gov.nasa.arc.mct.table.policy.TableViewPolicy; -import gov.nasa.arc.mct.table.view.TableViewManifestation; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; - -import javax.swing.ImageIcon; +import gov.nasa.arc.mct.policy.PolicyInfo; +import gov.nasa.arc.mct.services.component.AbstractComponentProvider; +import gov.nasa.arc.mct.services.component.TypeInfo; +import gov.nasa.arc.mct.services.component.ViewInfo; +import gov.nasa.arc.mct.services.component.ViewType; +import gov.nasa.arc.mct.table.policy.TableViewPolicy; +import gov.nasa.arc.mct.table.view.TableViewManifestation; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; + +import javax.swing.ImageIcon; /** * Factory for TableViewRole. @@ -42,7 +43,8 @@ public class TableViewProvider extends AbstractComponentProvider { final Collection policyInfos; private final Collection viewInfos; - + private static final ImageIcon ICON = + new ImageIcon(TableViewProvider.class.getResource("/icons/mct_icon_menu_alpha.png")); /** * Creates a new view provider service object. Initializes the set * of objects that will be provided to the core. @@ -50,10 +52,8 @@ public class TableViewProvider extends AbstractComponentProvider { public TableViewProvider() { policyInfos = Collections.singleton(new PolicyInfo(PolicyInfo.CategoryType.FILTER_VIEW_ROLE.getKey(), TableViewPolicy.class)); viewInfos = Arrays.asList( - new ViewInfo(TableViewManifestation.class, TableViewManifestation.VIEW_ROLE_NAME, "gov.nasa.arc.mct.table.view.TableViewRole", ViewType.OBJECT, - new ImageIcon(getClass().getResource("/icons/mct_icon_menu_alpha.png"))), - new ViewInfo(TableViewManifestation.class, TableViewManifestation.VIEW_ROLE_NAME, "gov.nasa.arc.mct.table.view.TableViewRole", ViewType.EMBEDDED, - new ImageIcon(getClass().getResource("/icons/mct_icon_menu_alpha.png")))); + new ViewInfo(TableViewManifestation.class, TableViewManifestation.VIEW_ROLE_NAME, "gov.nasa.arc.mct.table.view.TableViewRole", ViewType.OBJECT), + new ViewInfo(TableViewManifestation.class, TableViewManifestation.VIEW_ROLE_NAME, "gov.nasa.arc.mct.table.view.TableViewRole", ViewType.EMBEDDED)); } @Override @@ -65,5 +65,14 @@ public Collection getViews(String componentTypeId) { public Collection getPolicyInfos() { return policyInfos; } - + + + @Override + public T getAsset(TypeInfo typeInfo, Class assetClass) { + if (assetClass.isAssignableFrom(ImageIcon.class) && + typeInfo.getTypeClass().equals(TableViewManifestation.class)) { + return assetClass.cast(ICON); + } + return super.getAsset(typeInfo, assetClass); + } } From 231ac0bb8b2299ff0b918e58407a08093b0bfd14 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Wed, 11 Sep 2013 15:48:51 -0700 Subject: [PATCH 14/27] [Icons] Fix checkstyle/Werror issues --- .../search/DatabaseSearchUI.java | 12 ++++++--- .../GraphicalComponentProviderTest.java | 26 +++++++++---------- .../TestEvaluatorComponentProvider.java | 4 +-- .../arc/mct/components/AbstractComponent.java | 1 + .../nasa/arc/mct/platform/spi/Platform.java | 6 ++++- .../services/component/ComponentProvider.java | 1 + .../services/component/ComponentTypeInfo.java | 26 +++++++++++++------ .../arc/mct/services/component/TypeInfo.java | 1 + .../component/CoreComponentRegistry.java | 1 + .../nasa/arc/mct/defaults/view/InfoView.java | 10 +++++-- .../mct/gui/actions/DeleteObjectAction.java | 1 + .../actions/RemoveManifestationAction.java | 2 ++ .../mct/defaults/view/TestComponentIcon.java | 7 ++--- .../arc/mct/defaults/view/TestInfoView.java | 2 ++ 14 files changed, 67 insertions(+), 33 deletions(-) diff --git a/databasePersistence/src/main/java/gov/nasa/arc/mct/dbpersistence/search/DatabaseSearchUI.java b/databasePersistence/src/main/java/gov/nasa/arc/mct/dbpersistence/search/DatabaseSearchUI.java index fdecfda6..a64a684d 100644 --- a/databasePersistence/src/main/java/gov/nasa/arc/mct/dbpersistence/search/DatabaseSearchUI.java +++ b/databasePersistence/src/main/java/gov/nasa/arc/mct/dbpersistence/search/DatabaseSearchUI.java @@ -52,6 +52,7 @@ import javax.swing.BorderFactory; import javax.swing.DefaultListCellRenderer; import javax.swing.DefaultListModel; +import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JComponent; @@ -125,7 +126,7 @@ public Component getListCellRendererComponent(JList list, Object value, int inde boolean cellHasFocus) { ComponentInfo ci = (ComponentInfo) value; JLabel label = (JLabel) super.getListCellRendererComponent(list, ci.name, index, isSelected, cellHasFocus); - label.setIcon(AbstractComponent.getIconForComponentType(ci.type)); + label.setIcon(getIconForComponentType(ci.type)); return label; } }); @@ -210,6 +211,11 @@ QueryResult search(String pattern, boolean isFindObjectsCreatedByMe) { props.setProperty("creator", PlatformAccess.getPlatform().getCurrentUser().getUserId()); return InternalDBPersistenceAccess.getService().findComponentsByBaseDisplayedNamePattern(pattern, props); } + + private ImageIcon getIconForComponentType(String type) { + AbstractComponent iconInstance = PlatformAccess.getPlatform().getComponentRegistry().newInstance(type); + return iconInstance == null ? null : iconInstance.getAsset(ImageIcon.class); + } private class SearchTask extends SwingWorker, Void> { private AtomicInteger total = new AtomicInteger(); @@ -266,8 +272,8 @@ public void removeSelectionChangeListener(PropertyChangeListener listener) { //Harleigh108: this removes the warning received when we build with respect to java 7; getSelectedValues is now Deprecated in java7 //from java7 javadocs (for JList) 'As of JDK 1.7, replaced by getSelectedValuesList()' - //Note: we supress this warning to stay compatable with java6 - @SuppressWarnings("deprecation") + //Note: we suppress this warning to stay compatible with java6 + @SuppressWarnings("deprecation") @Override public Collection getSelectedManifestations() { Object[] selectedValues = list.getSelectedValues(); diff --git a/dynamicGraphics/src/test/java/gov/nasa/arc/mct/graphics/GraphicalComponentProviderTest.java b/dynamicGraphics/src/test/java/gov/nasa/arc/mct/graphics/GraphicalComponentProviderTest.java index fb3eeeca..78ecdb1c 100644 --- a/dynamicGraphics/src/test/java/gov/nasa/arc/mct/graphics/GraphicalComponentProviderTest.java +++ b/dynamicGraphics/src/test/java/gov/nasa/arc/mct/graphics/GraphicalComponentProviderTest.java @@ -21,18 +21,17 @@ *******************************************************************************/ package gov.nasa.arc.mct.graphics; -import gov.nasa.arc.mct.graphics.component.GraphicalComponent; -import gov.nasa.arc.mct.graphics.component.GraphicalComponentWizardUI; -import gov.nasa.arc.mct.graphics.view.GraphicalManifestation; -import gov.nasa.arc.mct.graphics.view.StaticGraphicalView; -import gov.nasa.arc.mct.policy.PolicyInfo; -import gov.nasa.arc.mct.services.component.AbstractComponentProvider; -import gov.nasa.arc.mct.services.component.ComponentTypeInfo; -import gov.nasa.arc.mct.services.component.ViewInfo; - -import org.testng.Assert; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Test; +import gov.nasa.arc.mct.graphics.component.GraphicalComponent; +import gov.nasa.arc.mct.graphics.view.GraphicalManifestation; +import gov.nasa.arc.mct.graphics.view.StaticGraphicalView; +import gov.nasa.arc.mct.policy.PolicyInfo; +import gov.nasa.arc.mct.services.component.AbstractComponentProvider; +import gov.nasa.arc.mct.services.component.ComponentTypeInfo; +import gov.nasa.arc.mct.services.component.ViewInfo; + +import org.testng.Assert; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; public class GraphicalComponentProviderTest { @@ -62,7 +61,7 @@ public void testPolicyInfos() { boolean foundPolicy = false; for (PolicyInfo info : provider.getPolicyInfos()) { - for (Class c : info.getPolicyClasses()) { + for (Class c : info.getPolicyClasses()) { if (c.equals(GraphicalViewPolicy.class)) { foundPolicy = true; Assert.assertEquals(info.getCategoryKey(), PolicyInfo.CategoryType.FILTER_VIEW_ROLE.getKey()); @@ -82,7 +81,6 @@ public void testComponentTypeInfos() { if (info.getComponentClass().equals(GraphicalComponent.class)){ foundGraphicalComponent = true; Assert.assertTrue(info.isCreatable()); - Assert.assertTrue(info.getWizardUI() instanceof GraphicalComponentWizardUI); } } diff --git a/evaluatorComponent/src/test/java/gov/nasa/arc/mct/evaluator/component/TestEvaluatorComponentProvider.java b/evaluatorComponent/src/test/java/gov/nasa/arc/mct/evaluator/component/TestEvaluatorComponentProvider.java index 078d7e08..8602e379 100644 --- a/evaluatorComponent/src/test/java/gov/nasa/arc/mct/evaluator/component/TestEvaluatorComponentProvider.java +++ b/evaluatorComponent/src/test/java/gov/nasa/arc/mct/evaluator/component/TestEvaluatorComponentProvider.java @@ -94,9 +94,9 @@ public void testViews() { Assert.assertTrue(views.contains(new ViewInfo(MultiViewManifestation.class,"", ViewType.CENTER))); it = multiProvider.getViews(MultiComponent.class.getName()).iterator(); - Assert.assertEquals(it.next(), new ViewInfo(InfoViewManifestation.class, InfoViewManifestation.VIEW_NAME, InfoViewManifestation.class.getName(), ViewType.OBJECT, null, null, false, MultiComponent.class)); + Assert.assertEquals(it.next(), new ViewInfo(InfoViewManifestation.class, InfoViewManifestation.VIEW_NAME, InfoViewManifestation.class.getName(), ViewType.OBJECT)); Assert.assertEquals(it.next(), new ViewInfo(MultiViewManifestation.class, MultiViewManifestation.VIEW_NAME, ViewType.OBJECT)); - Assert.assertEquals(it.next(), new ViewInfo(MultiViewManifestation.class, MultiViewManifestation.VIEW_NAME, InfoViewManifestation.class.getName(), ViewType.CENTER, null, null, true, MultiComponent.class)); + Assert.assertEquals(it.next(), new ViewInfo(MultiViewManifestation.class, MultiViewManifestation.VIEW_NAME, InfoViewManifestation.class.getName(), ViewType.CENTER)); } } diff --git a/mctcore/src/main/java/gov/nasa/arc/mct/components/AbstractComponent.java b/mctcore/src/main/java/gov/nasa/arc/mct/components/AbstractComponent.java index 40792517..c8a90d6a 100644 --- a/mctcore/src/main/java/gov/nasa/arc/mct/components/AbstractComponent.java +++ b/mctcore/src/main/java/gov/nasa/arc/mct/components/AbstractComponent.java @@ -889,6 +889,7 @@ public int getVersion() { /** * Get an asset of a specified type. For instance, an * Icon may be retrieved using getAsset(Icon.class). + * @param the type of asset desired * @param assetClass the desired type of asset * @return an asset of the desired type (or null if there is none) */ diff --git a/mctcore/src/main/java/gov/nasa/arc/mct/platform/spi/Platform.java b/mctcore/src/main/java/gov/nasa/arc/mct/platform/spi/Platform.java index 7269ab30..f9d7a697 100644 --- a/mctcore/src/main/java/gov/nasa/arc/mct/platform/spi/Platform.java +++ b/mctcore/src/main/java/gov/nasa/arc/mct/platform/spi/Platform.java @@ -127,7 +127,11 @@ public interface Platform { * @return provider to access various types of default components */ public DefaultComponentProvider getDefaultComponentProvider(); - + + /** + * Provides an instance of the provider delegate service + * @return the provider delegate service + */ public ProviderDelegateService getProviderDelegateService(); /** diff --git a/mctcore/src/main/java/gov/nasa/arc/mct/services/component/ComponentProvider.java b/mctcore/src/main/java/gov/nasa/arc/mct/services/component/ComponentProvider.java index fe0711bc..18d01092 100644 --- a/mctcore/src/main/java/gov/nasa/arc/mct/services/component/ComponentProvider.java +++ b/mctcore/src/main/java/gov/nasa/arc/mct/services/component/ComponentProvider.java @@ -87,6 +87,7 @@ public interface ComponentProvider { * things like icons or create wizards which are associated with specific component or view * types, but are not incorporated into those types directly to preserve separation of * concerns. + * @param the type of asset desired * @param objectType the type with which the requested asset is associated * @param assetClass the type of the requested asset * @return an asset of the requested type (or null, if none is provided) diff --git a/mctcore/src/main/java/gov/nasa/arc/mct/services/component/ComponentTypeInfo.java b/mctcore/src/main/java/gov/nasa/arc/mct/services/component/ComponentTypeInfo.java index 3d8193b2..e77b66fd 100644 --- a/mctcore/src/main/java/gov/nasa/arc/mct/services/component/ComponentTypeInfo.java +++ b/mctcore/src/main/java/gov/nasa/arc/mct/services/component/ComponentTypeInfo.java @@ -41,9 +41,11 @@ public class ComponentTypeInfo extends TypeInfo { * Creates new ComponentTypeInfo representing a unique component type. * @param displayName non null human readable name for the component type * @param description human readable string describing the component type - * @param componentClass non null component class, this class must provide the required no-argument constructor + * @param componentClass non null component class, this class must provide the required no-argument constructor + * @throws IllegalArgumentException if componentClass, id, or displayName is null or if component class does not meet the requirements of + * AbstractComponent */ - public ComponentTypeInfo(String displayName, String description, Class componentClass) { + public ComponentTypeInfo(String displayName, String description, Class componentClass) throws IllegalArgumentException { this(displayName,description,componentClass, componentClass.getName(), true); } @@ -52,9 +54,11 @@ public ComponentTypeInfo(String displayName, String description, ClassAbstractComponent */ - public ComponentTypeInfo(String displayName, String description, Class componentClass, boolean isCreatable) { + public ComponentTypeInfo(String displayName, String description, Class componentClass, boolean isCreatable) throws IllegalArgumentException { this(displayName,description,componentClass, componentClass.getName(), isCreatable); } @@ -65,10 +69,12 @@ public ComponentTypeInfo(String displayName, String description, ClassAbstractComponent * @deprecated icon and wizard now specified using ComponentProvider.getAsset */ @Deprecated - public ComponentTypeInfo(String displayName, String description, Class componentClass, boolean isCreatable, javax.swing.ImageIcon icon) { + public ComponentTypeInfo(String displayName, String description, Class componentClass, boolean isCreatable, javax.swing.ImageIcon icon) throws IllegalArgumentException { this(displayName,description,componentClass, componentClass.getName(), isCreatable); } @@ -79,10 +85,12 @@ public ComponentTypeInfo(String displayName, String description, ClassAbstractComponent * @deprecated icon and wizard now specified using ComponentProvider.getAsset */ @Deprecated - public ComponentTypeInfo(String displayName, String description, Class componentClass, CreateWizardUI wizard){ + public ComponentTypeInfo(String displayName, String description, Class componentClass, CreateWizardUI wizard) throws IllegalArgumentException { this(displayName,description,componentClass,componentClass.getName(), true); } @@ -93,10 +101,12 @@ public ComponentTypeInfo(String displayName, String description, ClassAbstractComponent * @deprecated icon and wizard now specified using ComponentProvider.getAsset */ @Deprecated - public ComponentTypeInfo(String displayName, String description, Class componentClass, CreateWizardUI wizard, javax.swing.ImageIcon icon){ + public ComponentTypeInfo(String displayName, String description, Class componentClass, CreateWizardUI wizard, javax.swing.ImageIcon icon) throws IllegalArgumentException { this(displayName,description,componentClass,componentClass.getName(), true); } @@ -110,7 +120,7 @@ public ComponentTypeInfo(String displayName, String description, ClassAbstractComponent */ - protected ComponentTypeInfo(String displayName, String description, Class componentClass, String id, boolean isCreatable) { + protected ComponentTypeInfo(String displayName, String description, Class componentClass, String id, boolean isCreatable) throws IllegalArgumentException { super(componentClass); if (componentClass == null) { throw new IllegalArgumentException("componentClass must not be null"); diff --git a/mctcore/src/main/java/gov/nasa/arc/mct/services/component/TypeInfo.java b/mctcore/src/main/java/gov/nasa/arc/mct/services/component/TypeInfo.java index daab47dd..3889dcf2 100644 --- a/mctcore/src/main/java/gov/nasa/arc/mct/services/component/TypeInfo.java +++ b/mctcore/src/main/java/gov/nasa/arc/mct/services/component/TypeInfo.java @@ -64,6 +64,7 @@ public Class getTypeClass() { * For instance, getAsset(ImageIcon.class) to get * an icon. * @param assetClass the type of asset desired + * @param the type of asset desired * @return an object of the desired type (or null if none is available) */ public A getAsset(Class assetClass) { diff --git a/mctcore/src/main/java/gov/nasa/arc/mct/services/internal/component/CoreComponentRegistry.java b/mctcore/src/main/java/gov/nasa/arc/mct/services/internal/component/CoreComponentRegistry.java index c33b426b..fa8b6700 100644 --- a/mctcore/src/main/java/gov/nasa/arc/mct/services/internal/component/CoreComponentRegistry.java +++ b/mctcore/src/main/java/gov/nasa/arc/mct/services/internal/component/CoreComponentRegistry.java @@ -61,6 +61,7 @@ public interface CoreComponentRegistry extends ComponentRegistry { * For instance, this can be used to obtain an Icon * for a specific component or view class. * + * @param the type of asset desired * @param objectType the type with which the asset is associated * @param assetClass the type of the desired asset * @return an asset of the desired type (or null if none is available) diff --git a/platform/src/main/java/gov/nasa/arc/mct/defaults/view/InfoView.java b/platform/src/main/java/gov/nasa/arc/mct/defaults/view/InfoView.java index de99e52c..6f153233 100644 --- a/platform/src/main/java/gov/nasa/arc/mct/defaults/view/InfoView.java +++ b/platform/src/main/java/gov/nasa/arc/mct/defaults/view/InfoView.java @@ -101,6 +101,7 @@ public class InfoView extends View { private JLabel displayNameTag; private JLabel componentType; private JLabel componentTypeTag; + @SuppressWarnings("rawtypes") // Java 7 compatibility private JComboBox owner; private JLabel ownerTag; private JLabel mctId; @@ -257,11 +258,12 @@ private JTextField createDisplayNameField() { return tf; } - private JComboBox createOwnerField() { - + @SuppressWarnings("rawtypes") // Java 7 compatibility + private JComboBox createOwnerField() { List usersAndRoles = new ArrayList(); usersAndRoles.addAll(Arrays.asList(RoleAccess.getAllRoles())); usersAndRoles.addAll(Arrays.asList(RoleAccess.getAllUsers())); + @SuppressWarnings("unchecked") final JComboBox comboBox = new JComboBox(usersAndRoles.toArray()); comboBox.setSelectedItem(getManifestedComponent().getOwner()); return comboBox; @@ -319,6 +321,7 @@ private AbstractComponent getMasterComponent() { * When a component changes locked state, control whether the display name is edit able. */ + @SuppressWarnings("unchecked") // Java 7 compatibility @Override public void enterLockedState() { boolean allowEdit = checkAllowComponentRenamePolicy(); @@ -352,6 +355,7 @@ public void paint(Graphics g) { } } + @SuppressWarnings("unchecked") // Java 7 compatibility @Override public void exitLockedState() { boolean allowEdit = checkAllowComponentRenamePolicy(); @@ -526,6 +530,7 @@ private void refreshExtendedFields() { } } + @SuppressWarnings("rawtypes") // Java 7 compatibility private void populateVisualComponent(JComponent component, PropertyDescriptor p) { Object newValue = null; // Set the visual component (specific method calls vary by component type) @@ -726,6 +731,7 @@ public void actionPerformed(ActionEvent e) { }); } + @SuppressWarnings("rawtypes") // Java 7 compatibility private void hookupComponentListeners(final JComboBox jComponent, final PropertyEditor ed) { jComponent.addActionListener(new ActionListener() { diff --git a/platform/src/main/java/gov/nasa/arc/mct/gui/actions/DeleteObjectAction.java b/platform/src/main/java/gov/nasa/arc/mct/gui/actions/DeleteObjectAction.java index 99fdea64..8203bd8f 100644 --- a/platform/src/main/java/gov/nasa/arc/mct/gui/actions/DeleteObjectAction.java +++ b/platform/src/main/java/gov/nasa/arc/mct/gui/actions/DeleteObjectAction.java @@ -168,6 +168,7 @@ private JPanel buildWarningPanel(Set componentsToBeDeleted) { } JPanel warning = new JPanel(new FlowLayout()); warning.setPreferredSize(new Dimension(400,400)); + @SuppressWarnings({ "rawtypes", "unchecked" }) JList deleteList = new JList(deleteComps.toArray()); JScrollPane scrollPane2 = new JScrollPane(deleteList); scrollPane2.setPreferredSize(new Dimension(300,200)); diff --git a/platform/src/main/java/gov/nasa/arc/mct/gui/actions/RemoveManifestationAction.java b/platform/src/main/java/gov/nasa/arc/mct/gui/actions/RemoveManifestationAction.java index 01c3e1c0..089ec981 100644 --- a/platform/src/main/java/gov/nasa/arc/mct/gui/actions/RemoveManifestationAction.java +++ b/platform/src/main/java/gov/nasa/arc/mct/gui/actions/RemoveManifestationAction.java @@ -243,7 +243,9 @@ private JPanel buildWarningPanel(List Date: Thu, 12 Sep 2013 10:13:37 -0700 Subject: [PATCH 15/27] [Icons] Ensure unit test compliance API changes and some behavioral changes break unit tests. Changes here fall into two categories: * Adjust unit tests to keep up with changes * Add more checks to code to improve robustness (avoiding elaborate mocking when unit testing unrelated behavior) --- .../component/TestEvaluatorComponentProvider.java | 13 +++++++------ .../nasa/arc/mct/services/component/TypeInfo.java | 11 ++++++++++- .../nasa/arc/mct/services/component/ViewInfo.java | 9 +++++++-- .../arc/mct/services/component/ViewInfoTest.java | 8 ++++---- .../arc/mct/gui/housing/MCTStandardHousing.java | 4 +++- .../mct/gui/menu/TestStandardHousingMenuBar.java | 2 +- .../nasa/arc/mct/gui/util/TestSetupUtilities.java | 10 +++++++--- 7 files changed, 39 insertions(+), 18 deletions(-) diff --git a/evaluatorComponent/src/test/java/gov/nasa/arc/mct/evaluator/component/TestEvaluatorComponentProvider.java b/evaluatorComponent/src/test/java/gov/nasa/arc/mct/evaluator/component/TestEvaluatorComponentProvider.java index 8602e379..7439836a 100644 --- a/evaluatorComponent/src/test/java/gov/nasa/arc/mct/evaluator/component/TestEvaluatorComponentProvider.java +++ b/evaluatorComponent/src/test/java/gov/nasa/arc/mct/evaluator/component/TestEvaluatorComponentProvider.java @@ -83,20 +83,21 @@ public void testPolicyInfos() { public void testViews() { Collection views = evaluatorProvider.getViews(EvaluatorComponent.class.getName()); Assert.assertEquals(views.size(), 3); - Assert.assertTrue(views.contains(new ViewInfo(ExpressionsViewManifestation.class,"", ViewType.CENTER))); + Assert.assertTrue(views.contains(new ViewInfo(ExpressionsViewManifestation.class,"", ViewType.OBJECT))); + Assert.assertTrue(views.contains(new ViewInfo(ExpressionsViewManifestation.class,"", ExpressionsViewManifestation.class.getName(), ViewType.CENTER, true, EvaluatorComponent.class))); Iterator it = evaluatorProvider.getViews(EvaluatorComponent.class.getName()).iterator(); - Assert.assertEquals(it.next(), new ViewInfo(InfoViewManifestation.class,"", ViewType.CENTER)); - Assert.assertEquals(it.next(), new ViewInfo(ExpressionsViewManifestation.class,"", ViewType.CENTER)); + Assert.assertEquals(it.next(), new ViewInfo(InfoViewManifestation.class, InfoViewManifestation.VIEW_NAME, ViewType.OBJECT)); + Assert.assertEquals(it.next(), new ViewInfo(ExpressionsViewManifestation.class, ExpressionsViewManifestation.VIEW_NAME, ViewType.OBJECT)); views = multiProvider.getViews(MultiComponent.class.getName()); Assert.assertEquals(views.size(), 3); - Assert.assertTrue(views.contains(new ViewInfo(MultiViewManifestation.class,"", ViewType.CENTER))); + Assert.assertTrue(views.contains(new ViewInfo(MultiViewManifestation.class, MultiViewManifestation.VIEW_NAME, InfoViewManifestation.class.getName(), ViewType.CENTER, true, MultiComponent.class))); it = multiProvider.getViews(MultiComponent.class.getName()).iterator(); - Assert.assertEquals(it.next(), new ViewInfo(InfoViewManifestation.class, InfoViewManifestation.VIEW_NAME, InfoViewManifestation.class.getName(), ViewType.OBJECT)); + Assert.assertEquals(it.next(), new ViewInfo(InfoViewManifestation.class, InfoViewManifestation.VIEW_NAME, InfoViewManifestation.class.getName(), ViewType.OBJECT, false, MultiComponent.class)); Assert.assertEquals(it.next(), new ViewInfo(MultiViewManifestation.class, MultiViewManifestation.VIEW_NAME, ViewType.OBJECT)); - Assert.assertEquals(it.next(), new ViewInfo(MultiViewManifestation.class, MultiViewManifestation.VIEW_NAME, InfoViewManifestation.class.getName(), ViewType.CENTER)); + Assert.assertEquals(it.next(), new ViewInfo(MultiViewManifestation.class, MultiViewManifestation.VIEW_NAME, InfoViewManifestation.class.getName(), ViewType.CENTER, true, MultiComponent.class)); } } diff --git a/mctcore/src/main/java/gov/nasa/arc/mct/services/component/TypeInfo.java b/mctcore/src/main/java/gov/nasa/arc/mct/services/component/TypeInfo.java index 3889dcf2..5b6fa724 100644 --- a/mctcore/src/main/java/gov/nasa/arc/mct/services/component/TypeInfo.java +++ b/mctcore/src/main/java/gov/nasa/arc/mct/services/component/TypeInfo.java @@ -21,7 +21,9 @@ *******************************************************************************/ package gov.nasa.arc.mct.services.component; +import gov.nasa.arc.mct.platform.spi.Platform; import gov.nasa.arc.mct.platform.spi.PlatformAccess; +import gov.nasa.arc.mct.services.internal.component.CoreComponentRegistry; /** * Provides information about a type relevant to MCT. @@ -68,6 +70,13 @@ public Class getTypeClass() { * @return an object of the desired type (or null if none is available) */ public A getAsset(Class assetClass) { - return PlatformAccess.getPlatform().getComponentRegistry().getAsset(this, assetClass); + Platform platform = PlatformAccess.getPlatform(); + if (platform != null) { + CoreComponentRegistry registry = platform.getComponentRegistry(); + if (registry != null) { + return registry.getAsset(this, assetClass); + } + } + return null; } } diff --git a/mctcore/src/main/java/gov/nasa/arc/mct/services/component/ViewInfo.java b/mctcore/src/main/java/gov/nasa/arc/mct/services/component/ViewInfo.java index 1929e31c..8f77e5bf 100644 --- a/mctcore/src/main/java/gov/nasa/arc/mct/services/component/ViewInfo.java +++ b/mctcore/src/main/java/gov/nasa/arc/mct/services/component/ViewInfo.java @@ -210,12 +210,17 @@ public ViewType getViewType() { @Override public int hashCode() { - return getType().hashCode() + (preferredComponentType == null ? 0 : preferredComponentType.hashCode()); + return getType().hashCode() ^ + getViewType().hashCode() ^ + (preferredComponentType == null ? 0 : preferredComponentType.hashCode()); } @Override public boolean equals(Object obj) { - return obj instanceof ViewInfo && ((ViewInfo)obj).getType().equals(type) && ((ViewInfo)obj).getPreferredComponentType() == preferredComponentType; + return obj instanceof ViewInfo && + ((ViewInfo)obj).getType().equals(getType()) && + ((ViewInfo)obj).getViewType().equals(getViewType()) && + ((ViewInfo)obj).getPreferredComponentType() == preferredComponentType; } @Override diff --git a/mctcore/src/test/java/gov/nasa/arc/mct/services/component/ViewInfoTest.java b/mctcore/src/test/java/gov/nasa/arc/mct/services/component/ViewInfoTest.java index 0cd6351b..84722500 100644 --- a/mctcore/src/test/java/gov/nasa/arc/mct/services/component/ViewInfoTest.java +++ b/mctcore/src/test/java/gov/nasa/arc/mct/services/component/ViewInfoTest.java @@ -66,20 +66,20 @@ public void testMethods() { @Test public void testHashCode() { ViewInfo vi = new ViewInfo(TestView.class, "tv", ViewType.INSPECTOR); - Assert.assertEquals(vi.hashCode(), TestView.class.getName().hashCode()); + Assert.assertEquals(vi.hashCode(), TestView.class.getName().hashCode() ^ ViewType.INSPECTOR.hashCode()); } @Test public void testEquals() { ViewInfo vi = new ViewInfo(TestView.class, "tv", ViewType.INSPECTOR); - ViewInfo vi2 = new ViewInfo(TestView.class, "tv", ViewType.CENTER); + ViewInfo vi2 = new ViewInfo(TestView.class, "tv", ViewType.INSPECTOR); View v = Mockito.mock(View.class); ViewInfo vi3 = new ViewInfo(v.getClass(), "tv", TestView.class.getName(),ViewType.LAYOUT); Assert.assertFalse(vi.equals(null)); - Assert.assertEquals(vi, vi2); - Assert.assertEquals(vi, vi3); + Assert.assertTrue (vi.equals(vi2)); + Assert.assertFalse(vi.equals(vi3)); Assert.assertFalse(vi.equals(Integer.valueOf(7))); } diff --git a/platform/src/main/java/gov/nasa/arc/mct/gui/housing/MCTStandardHousing.java b/platform/src/main/java/gov/nasa/arc/mct/gui/housing/MCTStandardHousing.java index 4d08bc68..a87d8744 100644 --- a/platform/src/main/java/gov/nasa/arc/mct/gui/housing/MCTStandardHousing.java +++ b/platform/src/main/java/gov/nasa/arc/mct/gui/housing/MCTStandardHousing.java @@ -139,7 +139,9 @@ public MCTStandardHousing(String title, int width, int height, int closeAction, private void setIcon(ImageIcon icon) { icon = MCTIcons.processIcon(icon, new Color(230,230,230), true); - super.setIconImage(icon.getImage()); + if (icon != null) { + setIconImage(icon.getImage()); + } } @Override diff --git a/platform/src/test/java/gov/nasa/arc/mct/gui/menu/TestStandardHousingMenuBar.java b/platform/src/test/java/gov/nasa/arc/mct/gui/menu/TestStandardHousingMenuBar.java index 16fc1332..69336844 100644 --- a/platform/src/test/java/gov/nasa/arc/mct/gui/menu/TestStandardHousingMenuBar.java +++ b/platform/src/test/java/gov/nasa/arc/mct/gui/menu/TestStandardHousingMenuBar.java @@ -237,7 +237,7 @@ public MockHousing(int width, int height, int closeAction, byte areaSelection, V } - private class MockComposite extends MockComponent { + private static class MockComposite extends MockComponent { public MockComposite() { super(); diff --git a/platform/src/test/java/gov/nasa/arc/mct/gui/util/TestSetupUtilities.java b/platform/src/test/java/gov/nasa/arc/mct/gui/util/TestSetupUtilities.java index 3e979baa..7218ef3a 100644 --- a/platform/src/test/java/gov/nasa/arc/mct/gui/util/TestSetupUtilities.java +++ b/platform/src/test/java/gov/nasa/arc/mct/gui/util/TestSetupUtilities.java @@ -43,13 +43,13 @@ import gov.nasa.arc.mct.services.component.ViewInfo; import gov.nasa.arc.mct.services.component.ViewType; import gov.nasa.arc.mct.services.internal.component.User; - + import java.awt.event.MouseEvent; import java.awt.event.WindowEvent; import java.util.Arrays; import java.util.Collection; import java.util.Collections; - + import javax.swing.JComponent; import javax.swing.WindowConstants; @@ -60,7 +60,11 @@ public class TestSetupUtilities { * getActiveHousing() will return a non-null. */ public static MCTHousing setUpActiveHousing() { - class UtilComponent extends AbstractComponent { + class UtilComponent extends AbstractComponent { + @SuppressWarnings("unused") // Needed for ComponentTypeInfo to validate + public UtilComponent() { + this(IdGenerator.nextComponentId()); + } public UtilComponent(String id) { setId(id); } From 9388c5961f5426fdb3a4f727b678b67e9309d273 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Thu, 12 Sep 2013 13:48:51 -0700 Subject: [PATCH 16/27] [Icons] Test getAsset in component providers --- .../GraphicalComponentProviderTest.java | 51 ++++++- .../TestEvaluatorComponentProvider.java | 89 ++++++++--- ...TestExecutableButtonComponentProvider.java | 82 +++++++--- .../mct/fastplot/TestPlotViewProvider.java | 50 +++++-- .../LimitLineComponentProviderTest.java | 53 +++++-- .../provider/CoreComponentProviderTest.java | 141 ++++++++++++++++++ 6 files changed, 403 insertions(+), 63 deletions(-) create mode 100644 mctCoreTaxonomyProvider/src/test/java/gov/nasa/arc/mct/core/provider/CoreComponentProviderTest.java diff --git a/dynamicGraphics/src/test/java/gov/nasa/arc/mct/graphics/GraphicalComponentProviderTest.java b/dynamicGraphics/src/test/java/gov/nasa/arc/mct/graphics/GraphicalComponentProviderTest.java index 78ecdb1c..365fc91d 100644 --- a/dynamicGraphics/src/test/java/gov/nasa/arc/mct/graphics/GraphicalComponentProviderTest.java +++ b/dynamicGraphics/src/test/java/gov/nasa/arc/mct/graphics/GraphicalComponentProviderTest.java @@ -21,13 +21,21 @@ *******************************************************************************/ package gov.nasa.arc.mct.graphics; +import gov.nasa.arc.mct.components.AbstractComponent; import gov.nasa.arc.mct.graphics.component.GraphicalComponent; import gov.nasa.arc.mct.graphics.view.GraphicalManifestation; import gov.nasa.arc.mct.graphics.view.StaticGraphicalView; +import gov.nasa.arc.mct.gui.View; import gov.nasa.arc.mct.policy.PolicyInfo; import gov.nasa.arc.mct.services.component.AbstractComponentProvider; import gov.nasa.arc.mct.services.component.ComponentTypeInfo; +import gov.nasa.arc.mct.services.component.CreateWizardUI; +import gov.nasa.arc.mct.services.component.TypeInfo; import gov.nasa.arc.mct.services.component.ViewInfo; +import gov.nasa.arc.mct.services.component.ViewType; + +import javax.swing.Icon; +import javax.swing.ImageIcon; import org.testng.Assert; import org.testng.annotations.BeforeTest; @@ -86,5 +94,46 @@ public void testComponentTypeInfos() { Assert.assertTrue(foundGraphicalComponent); } - + + + @Test + public void testAssets() { + for (ViewInfo viewInfo : provider.getViews("")) { + // Verify that there's an icon + Assert.assertNotNull(provider.getAsset(viewInfo, ImageIcon.class)); + // Verify that assignability is correctly assessed + Assert.assertNotNull(provider.getAsset(viewInfo, Icon.class)); + // Verify that unknown types are not reported by getAsset + Assert.assertNull(provider.getAsset(viewInfo, UnknownType.class)); + } + for (ComponentTypeInfo compInfo : provider.getComponentTypes()) { + // Verify that there's a wizard + Assert.assertNotNull(provider.getAsset(compInfo, CreateWizardUI.class)); + // Verify that unknown types are not reported by getAsset + Assert.assertNull(provider.getAsset(compInfo, UnknownType.class)); + } + // Verify that unknown types consistently return null + TypeInfo[] unknowns = { + new TypeInfo(UnknownType.class){}, + new ComponentTypeInfo("","",UnknownComponent.class), + new ViewInfo(UnknownView.class, "", "", ViewType.OBJECT) + }; + for (TypeInfo unknown : unknowns) { + Assert.assertNull(provider.getAsset(unknown, ImageIcon.class)); + Assert.assertNull(provider.getAsset(unknown, CreateWizardUI.class)); + Assert.assertNull(provider.getAsset(unknown, UnknownType.class)); + } + } + + private static class UnknownType {} + private static class UnknownComponent extends AbstractComponent { + @SuppressWarnings("unused") // Verified when ComponentTypeInfo is instantiated + public UnknownComponent() {} + } + private static class UnknownView extends View { + private static final long serialVersionUID = 1L; + + @SuppressWarnings("unused") // Verified when ViewInfo is instantiated + public UnknownView (AbstractComponent ac, ViewInfo vi) {} + } } diff --git a/evaluatorComponent/src/test/java/gov/nasa/arc/mct/evaluator/component/TestEvaluatorComponentProvider.java b/evaluatorComponent/src/test/java/gov/nasa/arc/mct/evaluator/component/TestEvaluatorComponentProvider.java index 7439836a..64cddbd4 100644 --- a/evaluatorComponent/src/test/java/gov/nasa/arc/mct/evaluator/component/TestEvaluatorComponentProvider.java +++ b/evaluatorComponent/src/test/java/gov/nasa/arc/mct/evaluator/component/TestEvaluatorComponentProvider.java @@ -29,14 +29,24 @@ import gov.nasa.arc.mct.evaluator.view.MultiChildRemovalPolicy; import gov.nasa.arc.mct.evaluator.view.MultiCompositionPolicy; import gov.nasa.arc.mct.policy.PolicyInfo; +import gov.nasa.arc.mct.services.component.ComponentProvider; +import gov.nasa.arc.mct.services.component.ComponentTypeInfo; +import gov.nasa.arc.mct.services.component.CreateWizardUI; +import gov.nasa.arc.mct.services.component.TypeInfo; import gov.nasa.arc.mct.services.component.ViewInfo; import gov.nasa.arc.mct.services.component.ViewType; +import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; +import java.util.List; + +import javax.swing.Icon; +import javax.swing.ImageIcon; import org.testng.Assert; import org.testng.annotations.BeforeMethod; +import org.testng.annotations.DataProvider; import org.testng.annotations.Test; public class TestEvaluatorComponentProvider { @@ -81,23 +91,66 @@ public void testPolicyInfos() { @Test public void testViews() { - Collection views = evaluatorProvider.getViews(EvaluatorComponent.class.getName()); - Assert.assertEquals(views.size(), 3); - Assert.assertTrue(views.contains(new ViewInfo(ExpressionsViewManifestation.class,"", ViewType.OBJECT))); - Assert.assertTrue(views.contains(new ViewInfo(ExpressionsViewManifestation.class,"", ExpressionsViewManifestation.class.getName(), ViewType.CENTER, true, EvaluatorComponent.class))); - - Iterator it = evaluatorProvider.getViews(EvaluatorComponent.class.getName()).iterator(); - Assert.assertEquals(it.next(), new ViewInfo(InfoViewManifestation.class, InfoViewManifestation.VIEW_NAME, ViewType.OBJECT)); - Assert.assertEquals(it.next(), new ViewInfo(ExpressionsViewManifestation.class, ExpressionsViewManifestation.VIEW_NAME, ViewType.OBJECT)); - - views = multiProvider.getViews(MultiComponent.class.getName()); - Assert.assertEquals(views.size(), 3); - Assert.assertTrue(views.contains(new ViewInfo(MultiViewManifestation.class, MultiViewManifestation.VIEW_NAME, InfoViewManifestation.class.getName(), ViewType.CENTER, true, MultiComponent.class))); - - it = multiProvider.getViews(MultiComponent.class.getName()).iterator(); - Assert.assertEquals(it.next(), new ViewInfo(InfoViewManifestation.class, InfoViewManifestation.VIEW_NAME, InfoViewManifestation.class.getName(), ViewType.OBJECT, false, MultiComponent.class)); - Assert.assertEquals(it.next(), new ViewInfo(MultiViewManifestation.class, MultiViewManifestation.VIEW_NAME, ViewType.OBJECT)); - Assert.assertEquals(it.next(), new ViewInfo(MultiViewManifestation.class, MultiViewManifestation.VIEW_NAME, InfoViewManifestation.class.getName(), ViewType.CENTER, true, MultiComponent.class)); + Collection views = evaluatorProvider.getViews(EvaluatorComponent.class.getName()); + Assert.assertEquals(views.size(), 3); + Assert.assertTrue(views.contains(new ViewInfo(ExpressionsViewManifestation.class,"", ViewType.OBJECT))); + Assert.assertTrue(views.contains(new ViewInfo(ExpressionsViewManifestation.class,"", ExpressionsViewManifestation.class.getName(), ViewType.CENTER, true, EvaluatorComponent.class))); + + // Should return only one view (info) when component is unknown + Assert.assertEquals(evaluatorProvider.getViews("unknowncomponent").size(), 1); + + Iterator it = evaluatorProvider.getViews(EvaluatorComponent.class.getName()).iterator(); + Assert.assertEquals(it.next(), new ViewInfo(InfoViewManifestation.class, InfoViewManifestation.VIEW_NAME, ViewType.OBJECT)); + Assert.assertEquals(it.next(), new ViewInfo(ExpressionsViewManifestation.class, ExpressionsViewManifestation.VIEW_NAME, ViewType.OBJECT)); + + views = multiProvider.getViews(MultiComponent.class.getName()); + Assert.assertEquals(views.size(), 3); + Assert.assertTrue(views.contains(new ViewInfo(MultiViewManifestation.class, MultiViewManifestation.VIEW_NAME, InfoViewManifestation.class.getName(), ViewType.CENTER, true, MultiComponent.class))); + + it = multiProvider.getViews(MultiComponent.class.getName()).iterator(); + Assert.assertEquals(it.next(), new ViewInfo(InfoViewManifestation.class, InfoViewManifestation.VIEW_NAME, InfoViewManifestation.class.getName(), ViewType.OBJECT, false, MultiComponent.class)); + Assert.assertEquals(it.next(), new ViewInfo(MultiViewManifestation.class, MultiViewManifestation.VIEW_NAME, ViewType.OBJECT)); + Assert.assertEquals(it.next(), new ViewInfo(MultiViewManifestation.class, MultiViewManifestation.VIEW_NAME, InfoViewManifestation.class.getName(), ViewType.CENTER, true, MultiComponent.class)); } - + + @Test (dataProvider="assetTestCases") + public void testAssets(ComponentProvider provider, TypeInfo info, Class assetType, boolean expected) { + // Used to verify whether provider offers certain assets + if (expected) { + Assert.assertNotNull(provider.getAsset(info, assetType)); + } else { + Assert.assertNull(provider.getAsset(info, assetType)); + } + } + + @DataProvider + public Object[][] assetTestCases() { + List cases = new ArrayList(); + // Consider all view types + for (ViewType type : ViewType.values()) { + ViewInfo info = new ViewInfo(InfoViewManifestation.class, InfoViewManifestation.VIEW_NAME, InfoViewManifestation.class.getName(), type); + ViewInfo expr = new ViewInfo(ExpressionsViewManifestation.class, ExpressionsViewManifestation.VIEW_NAME, InfoViewManifestation.class.getName(), type); + TypeInfo eval = new ComponentTypeInfo("","",EvaluatorComponent.class); + TypeInfo mult = new ComponentTypeInfo("","",MultiComponent.class); + for (TypeInfo vi : new TypeInfo[]{info,expr,eval,mult}) { + // Expressions view should have an image icon + cases.add(new Object[] { new EvaluatorComponentProvider(), vi, ImageIcon.class, vi.getTypeClass().equals(ExpressionsViewManifestation.class)}); + // Verify assignable check also recognizes icon + cases.add(new Object[] { new EvaluatorComponentProvider(), vi, Icon.class, vi.getTypeClass().equals(ExpressionsViewManifestation.class)}); + // Evaluator should have a wizard + cases.add(new Object[] { new EvaluatorComponentProvider(), vi, CreateWizardUI.class, vi.getTypeClass().equals(EvaluatorComponent.class)}); + // Multi component providers have no icons + cases.add(new Object[] { new MultiComponentProvider(), vi, ImageIcon.class, false}); + // As above + cases.add(new Object[] { new MultiComponentProvider(), vi, Icon.class, false}); + // MultiComponent should have a wizard + cases.add(new Object[] { new MultiComponentProvider(), vi, CreateWizardUI.class, vi.getTypeClass().equals(MultiComponent.class)}); + } + } + Object[][] returnValue = new Object[cases.size()][]; + for (int i = 0; i < cases.size(); i++) { + returnValue[i] = cases.get(i); + } + return returnValue; + } } diff --git a/executableButtons/src/test/java/gov/nasa/jsc/mct/executables/buttons/TestExecutableButtonComponentProvider.java b/executableButtons/src/test/java/gov/nasa/jsc/mct/executables/buttons/TestExecutableButtonComponentProvider.java index 5bc78d08..63a5cb5a 100644 --- a/executableButtons/src/test/java/gov/nasa/jsc/mct/executables/buttons/TestExecutableButtonComponentProvider.java +++ b/executableButtons/src/test/java/gov/nasa/jsc/mct/executables/buttons/TestExecutableButtonComponentProvider.java @@ -21,24 +21,37 @@ *******************************************************************************/ package gov.nasa.jsc.mct.executables.buttons; -import gov.nasa.arc.mct.gui.MenuItemInfo; -import gov.nasa.arc.mct.platform.spi.Platform; -import gov.nasa.arc.mct.platform.spi.PlatformAccess; -import gov.nasa.arc.mct.platform.spi.RoleService; -import gov.nasa.arc.mct.services.internal.component.User; -import gov.nasa.jsc.mct.executable.buttons.ExecutableButtonComponent; -import gov.nasa.jsc.mct.executable.buttons.ExecutableButtonComponentProvider; -import gov.nasa.jsc.mct.executables.buttons.actions.ExecutableButtonAction; - -import java.util.Collection; - -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; -import org.testng.Assert; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; +import gov.nasa.arc.mct.gui.MenuItemInfo; +import gov.nasa.arc.mct.platform.spi.Platform; +import gov.nasa.arc.mct.platform.spi.PlatformAccess; +import gov.nasa.arc.mct.platform.spi.RoleService; +import gov.nasa.arc.mct.services.component.ComponentProvider; +import gov.nasa.arc.mct.services.component.ComponentTypeInfo; +import gov.nasa.arc.mct.services.component.CreateWizardUI; +import gov.nasa.arc.mct.services.component.TypeInfo; +import gov.nasa.arc.mct.services.component.ViewInfo; +import gov.nasa.arc.mct.services.component.ViewType; +import gov.nasa.arc.mct.services.internal.component.User; +import gov.nasa.jsc.mct.executable.buttons.ExecutableButtonComponent; +import gov.nasa.jsc.mct.executable.buttons.ExecutableButtonComponentProvider; +import gov.nasa.jsc.mct.executable.buttons.view.ExecutableButtonManifestation; +import gov.nasa.jsc.mct.executables.buttons.actions.ExecutableButtonAction; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import javax.swing.Icon; +import javax.swing.ImageIcon; + +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.testng.Assert; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; public class TestExecutableButtonComponentProvider { private ExecutableButtonComponentProvider provider; @@ -92,5 +105,38 @@ public void testMenuItemInfos() { @Test public void testPolicyInfos() { Assert.assertTrue(provider.getPolicyInfos().isEmpty()); + } + + @Test (dataProvider="assetTestCases") + public void testAssets(ComponentProvider provider, TypeInfo info, Class assetType, boolean expected) { + // Used to verify whether provider offers certain assets + if (expected) { + Assert.assertNotNull(provider.getAsset(info, assetType)); + } else { + Assert.assertNull(provider.getAsset(info, assetType)); + } + } + + @DataProvider + public Object[][] assetTestCases() { + List cases = new ArrayList(); + // Consider all view types + for (ViewType type : ViewType.values()) { + TypeInfo view = new ViewInfo(ExecutableButtonManifestation.class, ExecutableButtonManifestation.VIEW_NAME, ExecutableButtonManifestation.class.getName(), type); + TypeInfo comp = new ComponentTypeInfo("","",ExecutableButtonComponent.class); + for (TypeInfo vi : new TypeInfo[]{view, comp}) { + // Executable buttons have no view or component icons currently + cases.add(new Object[] { new ExecutableButtonComponentProvider(), vi, ImageIcon.class, false}); + // As above + cases.add(new Object[] { new ExecutableButtonComponentProvider(), vi, Icon.class, false}); + // Executable buttons should have a wizard + cases.add(new Object[] { new ExecutableButtonComponentProvider(), vi, CreateWizardUI.class, vi.getTypeClass().equals(ExecutableButtonComponent.class)}); + } + } + Object[][] returnValue = new Object[cases.size()][]; + for (int i = 0; i < cases.size(); i++) { + returnValue[i] = cases.get(i); + } + return returnValue; } } diff --git a/fastPlotViews/src/test/java/gov/nasa/arc/mct/fastplot/TestPlotViewProvider.java b/fastPlotViews/src/test/java/gov/nasa/arc/mct/fastplot/TestPlotViewProvider.java index f9ff9f16..5655456e 100644 --- a/fastPlotViews/src/test/java/gov/nasa/arc/mct/fastplot/TestPlotViewProvider.java +++ b/fastPlotViews/src/test/java/gov/nasa/arc/mct/fastplot/TestPlotViewProvider.java @@ -21,17 +21,21 @@ *******************************************************************************/ package gov.nasa.arc.mct.fastplot; -import gov.nasa.arc.mct.policy.PolicyInfo; -import gov.nasa.arc.mct.services.component.ViewInfo; -import gov.nasa.arc.mct.services.component.ViewType; -import gov.nasa.arc.mct.fastplot.view.PlotViewManifestation; - -import java.util.Collection; -import java.util.Collections; - -import org.testng.Assert; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; +import gov.nasa.arc.mct.fastplot.view.PlotViewManifestation; +import gov.nasa.arc.mct.policy.PolicyInfo; +import gov.nasa.arc.mct.services.component.TypeInfo; +import gov.nasa.arc.mct.services.component.ViewInfo; +import gov.nasa.arc.mct.services.component.ViewType; + +import java.util.Collection; +import java.util.Collections; + +import javax.swing.Icon; +import javax.swing.ImageIcon; + +import org.testng.Assert; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; public class TestPlotViewProvider { @@ -57,5 +61,27 @@ public void testGetViewRoles() { public void testGetPolicyInfos() { Collection infos = provider.getPolicyInfos(); Assert.assertEquals(infos.size(), 2); - } + } + + @Test + public void testGetAsset() { + @SuppressWarnings("serial") + class UnknownType extends ImageIcon {}; + + for (ViewInfo viewInfo : provider.getViews("")) { + // Should have an icon + Assert.assertNotNull(provider.getAsset(viewInfo, ImageIcon.class)); + // Should obey assignable rules for icon + Assert.assertNotNull(provider.getAsset(viewInfo, Icon.class)); + Assert.assertNull(provider.getAsset(viewInfo, UnknownType.class)); + } + + // Should not have assets for unknown types + TypeInfo unknownInfo = new TypeInfo(UnknownType.class){}; + for (Class type : new Class[] {ImageIcon.class,Icon.class,UnknownType.class}) { + Assert.assertNull(provider.getAsset(unknownInfo, type)); + } + + } + } diff --git a/limits/src/test/java/gov/nasa/arc/mct/limits/LimitLineComponentProviderTest.java b/limits/src/test/java/gov/nasa/arc/mct/limits/LimitLineComponentProviderTest.java index 5887b145..3d7c197d 100644 --- a/limits/src/test/java/gov/nasa/arc/mct/limits/LimitLineComponentProviderTest.java +++ b/limits/src/test/java/gov/nasa/arc/mct/limits/LimitLineComponentProviderTest.java @@ -21,19 +21,25 @@ *******************************************************************************/ package gov.nasa.arc.mct.limits; -import gov.nasa.arc.mct.gui.MenuItemInfo; -import gov.nasa.arc.mct.platform.spi.Platform; -import gov.nasa.arc.mct.platform.spi.PlatformAccess; -import gov.nasa.arc.mct.services.internal.component.User; - -import java.util.Collection; - -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; -import org.testng.Assert; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; +import gov.nasa.arc.mct.gui.MenuItemInfo; +import gov.nasa.arc.mct.platform.spi.Platform; +import gov.nasa.arc.mct.platform.spi.PlatformAccess; +import gov.nasa.arc.mct.services.component.ComponentTypeInfo; +import gov.nasa.arc.mct.services.component.CreateWizardUI; +import gov.nasa.arc.mct.services.component.TypeInfo; +import gov.nasa.arc.mct.services.internal.component.User; + +import java.util.Collection; + +import javax.swing.Icon; +import javax.swing.ImageIcon; + +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.testng.Assert; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; public class LimitLineComponentProviderTest { @@ -70,5 +76,24 @@ public void testViewInfos() { @Test public void testPolicyInfos() { Assert.assertEquals(provider.getPolicyInfos().size(), 0); - } + } + + @Test + public void testAssets() { + class UnknownType {}; + + for (ComponentTypeInfo info : provider.getComponentTypes()) { + // No icon + Assert.assertNull(provider.getAsset(info, Icon.class)); + // Should have a wizard + Assert.assertNotNull(provider.getAsset(info, CreateWizardUI.class)); + } + + // Should not have assets for unknown types + TypeInfo unknownInfo = new TypeInfo(UnknownType.class){}; + for (Class type : new Class[] {ImageIcon.class,Icon.class,UnknownType.class}) { + Assert.assertNull(provider.getAsset(unknownInfo, type)); + } + } + } diff --git a/mctCoreTaxonomyProvider/src/test/java/gov/nasa/arc/mct/core/provider/CoreComponentProviderTest.java b/mctCoreTaxonomyProvider/src/test/java/gov/nasa/arc/mct/core/provider/CoreComponentProviderTest.java new file mode 100644 index 00000000..3ab97685 --- /dev/null +++ b/mctCoreTaxonomyProvider/src/test/java/gov/nasa/arc/mct/core/provider/CoreComponentProviderTest.java @@ -0,0 +1,141 @@ +/******************************************************************************* + * Mission Control Technologies, Copyright (c) 2009-2012, United States Government + * as represented by the Administrator of the National Aeronautics and Space + * Administration. All rights reserved. + * + * The MCT platform is licensed under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + * + * MCT includes source code licensed under additional open source licenses. See + * the MCT Open Source Licenses file included with this distribution or the About + * MCT Licenses dialog available at runtime from the MCT Help menu for additional + * information. + *******************************************************************************/ +package gov.nasa.arc.mct.core.provider; + +import gov.nasa.arc.mct.core.components.BrokenComponent; +import gov.nasa.arc.mct.core.components.BrokenInfoPanel; +import gov.nasa.arc.mct.core.components.MineTaxonomyComponent; +import gov.nasa.arc.mct.core.components.TelemetryDataTaxonomyComponent; +import gov.nasa.arc.mct.core.components.TelemetryDisciplineComponent; +import gov.nasa.arc.mct.core.components.TelemetryUserDropBoxComponent; +import gov.nasa.arc.mct.core.roles.DropboxCanvasView; +import gov.nasa.arc.mct.core.roles.UsersManifestation; +import gov.nasa.arc.mct.services.component.ComponentTypeInfo; +import gov.nasa.arc.mct.services.component.CreateWizardUI; +import gov.nasa.arc.mct.services.component.TypeInfo; +import gov.nasa.arc.mct.services.component.ViewInfo; + +import java.util.Collection; + +import javax.swing.Icon; +import javax.swing.ImageIcon; + +import org.testng.Assert; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +public class CoreComponentProviderTest { + private CoreComponentProvider provider; + + @BeforeMethod + public void setup() { + provider = new CoreComponentProvider(); + } + + @Test (dataProvider="componentTypesTestCases") + public void testComponentTypes(Class expectedType) { + // Verify that all expected type are in getComponentTypes + Collection typeInfos = provider.getComponentTypes(); + boolean found = false; + for (TypeInfo t : typeInfos) { + found |= t.getTypeClass().equals(expectedType); + } + Assert.assertTrue(found); + } + + @DataProvider + public Object[][] componentTypesTestCases() { + return new Object[][] { + { TelemetryDisciplineComponent.class }, + { TelemetryUserDropBoxComponent.class }, + { MineTaxonomyComponent.class }, + { BrokenComponent.class }, + { TelemetryDataTaxonomyComponent.class } + }; + } + + @Test (dataProvider="viewTestCases") + public void testViews(Class compClass, Class viewClass, int size) { + Collection views = + provider.getViews(compClass.getName()); + Assert.assertEquals(views.size(), size); + if (size > 0) { + boolean found = false; + for (TypeInfo t : views) { + found |= t.getTypeClass().equals(viewClass); + } + Assert.assertTrue(found); + } + } + + @DataProvider + public Object[][] viewTestCases() { + return new Object[][] { + { TelemetryDisciplineComponent.class, UsersManifestation.class, 1 }, + { TelemetryUserDropBoxComponent.class, DropboxCanvasView.class, 2 }, + { MineTaxonomyComponent.class , null, 0}, + { BrokenComponent.class, BrokenInfoPanel.class, 1 }, + { TelemetryDataTaxonomyComponent.class, null, 0 } + }; + } + + @Test + public void testBrokenComponent() { + Assert.assertEquals(provider.getBrokenComponent(), BrokenComponent.class); + } + + @Test (dataProvider="assetTestCases") + public void testAssets(Class compClass, Class assetClass, boolean expected) { + TypeInfo typeInfo = new TypeInfo(compClass){}; + if (expected) { + Assert.assertNotNull(provider.getAsset(typeInfo, assetClass)); + } else { + Assert.assertNull(provider.getAsset(typeInfo, assetClass)); + } + } + + @DataProvider + public Object[][] assetTestCases() { + return new Object[][] { + // Verify that disciplines and drop boxes have icons + { TelemetryDisciplineComponent.class, ImageIcon.class, true }, + { TelemetryUserDropBoxComponent.class, ImageIcon.class, true }, + { MineTaxonomyComponent.class, ImageIcon.class, false }, + { BrokenComponent.class, ImageIcon.class, false }, + { TelemetryDataTaxonomyComponent.class, ImageIcon.class, false }, + // Should also return for icon (assignable) + { TelemetryDisciplineComponent.class, Icon.class, true }, + { TelemetryUserDropBoxComponent.class, Icon.class, true }, + { MineTaxonomyComponent.class, Icon.class, false }, + { BrokenComponent.class, Icon.class, false }, + { TelemetryDataTaxonomyComponent.class, Icon.class, false }, + // No create wizards + { TelemetryDisciplineComponent.class, CreateWizardUI.class, false }, + { TelemetryUserDropBoxComponent.class, CreateWizardUI.class, false }, + { MineTaxonomyComponent.class, CreateWizardUI.class, false }, + { BrokenComponent.class, CreateWizardUI.class, false }, + { TelemetryDataTaxonomyComponent.class, CreateWizardUI.class, false }, + }; + } + +} From af62c198e8cc83cd5ddee2ce3b78a9b218704e16 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Thu, 12 Sep 2013 15:05:07 -0700 Subject: [PATCH 17/27] [Icons] Test getAsset and related changes in mctcore --- .../TestExternalComponentRegistryImpl.java | 79 ++++++++++++++++++- .../AbstractComponentProviderTest.java | 44 +++++++++++ .../component/ComponentTypeInfoTest.java | 74 +++++++++++++++++ .../mct/services/component/TypeInfoTest.java | 70 ++++++++++++++++ 4 files changed, 263 insertions(+), 4 deletions(-) create mode 100644 mctcore/src/test/java/gov/nasa/arc/mct/services/component/AbstractComponentProviderTest.java create mode 100644 mctcore/src/test/java/gov/nasa/arc/mct/services/component/ComponentTypeInfoTest.java create mode 100644 mctcore/src/test/java/gov/nasa/arc/mct/services/component/TypeInfoTest.java diff --git a/mctcore/src/test/java/gov/nasa/arc/mct/registry/TestExternalComponentRegistryImpl.java b/mctcore/src/test/java/gov/nasa/arc/mct/registry/TestExternalComponentRegistryImpl.java index d9bbb228..8c053a57 100644 --- a/mctcore/src/test/java/gov/nasa/arc/mct/registry/TestExternalComponentRegistryImpl.java +++ b/mctcore/src/test/java/gov/nasa/arc/mct/registry/TestExternalComponentRegistryImpl.java @@ -33,9 +33,11 @@ import gov.nasa.arc.mct.services.component.ComponentProvider; import gov.nasa.arc.mct.services.component.ComponentTypeInfo; import gov.nasa.arc.mct.services.component.PolicyManager; +import gov.nasa.arc.mct.services.component.TypeInfo; import gov.nasa.arc.mct.services.component.ViewInfo; import gov.nasa.arc.mct.services.component.ViewType; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; @@ -44,6 +46,7 @@ import org.mockito.Mockito; import org.testng.Assert; import org.testng.annotations.BeforeMethod; +import org.testng.annotations.DataProvider; import org.testng.annotations.Test; public class TestExternalComponentRegistryImpl { @@ -202,11 +205,14 @@ public synchronized List getComponents() { Assert.assertTrue(newComponent2.getClass().equals(TestBaseComponent.class)); } - @Test(enabled=false) + @Test public void testNewCollection() { // Environment setup: platform, collection provider, lock manager, and component registry. Platform mockPlatform = Mockito.mock(Platform.class); - + + // Also need a sandbox + AbstractComponent mockSandbox = Mockito.mock(AbstractComponent.class); + Mockito.when(mockPlatform.getMySandbox()).thenReturn(mockSandbox); MockComponentRegistry registry = new MockComponentRegistry(); @@ -231,7 +237,7 @@ public void testNewCollection() { // Setup registry.clearRegistry(); registry.setDefaultCollection(collection); - registry.setExpectedResultForAddComponents(false); + registry.setExpectedResultForAddComponents(true); // The test newCollection = registry.newCollection(selectedComponents); @@ -288,5 +294,70 @@ public Collection getComponentTypes() { registry.refreshComponents(Arrays.asList(badProvider, goodProvider)); Assert.assertEquals(Collections.singleton(info), registry.getComponentInfos(),"component infos must be the same"); - } + } + + @Test + public void testGetInstance() { + Assert.assertNotNull(ExternalComponentRegistryImpl.getInstance()); + } + + @Test (dataProvider="assetTestCases") + public void testGetAsset(int count, int found, T asset, Class clazz) { + // Setup some mock providers to look at for assets + ComponentProvider mockDefaultProvider = Mockito.mock(ComponentProvider.class); + ExtendedComponentProvider mockProviders[] = new ExtendedComponentProvider[count]; + TypeInfo mockTypeInfo = Mockito.mock(TypeInfo.class); + for (int i = 0; i < count; i++) { + mockProviders[i] = Mockito.mock(ExtendedComponentProvider.class, "provider" + i); + } + // Find the expected item in provider "found" (with default provider at end) + if (found < count) { + Mockito.when(mockProviders[found].getAsset(mockTypeInfo, clazz)).thenReturn(asset); + } else if (found == count) { + Mockito.when(mockDefaultProvider.getAsset(mockTypeInfo, clazz)).thenReturn(asset); + } + registry.setDefaultViewProvider(mockDefaultProvider); + registry.refreshComponents(Arrays.asList(mockProviders)); + + // Should find the object, unless found > count + // (in that case, none of the providers was configured to give it, + // so should have returned null) + Object actual = registry.getAsset(mockTypeInfo, asset.getClass()); + if (found <= count) { // up to / including default provider + Assert.assertEquals(actual, asset); + } else { + Assert.assertNull(actual); + } + + // Should have invoked getAsset on all providers until found + for (int i = 0; i <= found && i < count; i++) { + Mockito.verify(mockProviders[i]).getAsset(mockTypeInfo, clazz); + } + // Should not have invoked getAsset on subsequent providers + for (int i = found + 1; i < count; i++) { + Mockito.verify(mockProviders[i], Mockito.never()).getAsset(mockTypeInfo, clazz); + } + + // Should have invoked getAsset on defaultProvider iff not found earlier + if (found >= count) { + Mockito.verify(mockDefaultProvider).getAsset(mockTypeInfo, clazz); + } else { + Mockito.verify(mockDefaultProvider, Mockito.never()).getAsset(mockTypeInfo, clazz); + } + } + + @DataProvider + public Object[][] assetTestCases() { + class TestClass {} + List caseList = new ArrayList(); + Object[] testAssets = { "a string", new javax.swing.ImageIcon(), new TestClass() }; + for (int count = 0; count < 5; count++) { + for (int found = 0; found <= count + 1; found++) { + for (Object asset : testAssets) { + caseList.add(new Object[]{count,found,asset,asset.getClass()}); + } + } + } + return caseList.toArray(new Object[caseList.size()][]); + } } diff --git a/mctcore/src/test/java/gov/nasa/arc/mct/services/component/AbstractComponentProviderTest.java b/mctcore/src/test/java/gov/nasa/arc/mct/services/component/AbstractComponentProviderTest.java new file mode 100644 index 00000000..747d2459 --- /dev/null +++ b/mctcore/src/test/java/gov/nasa/arc/mct/services/component/AbstractComponentProviderTest.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * Mission Control Technologies, Copyright (c) 2009-2012, United States Government + * as represented by the Administrator of the National Aeronautics and Space + * Administration. All rights reserved. + * + * The MCT platform is licensed under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + * + * MCT includes source code licensed under additional open source licenses. See + * the MCT Open Source Licenses file included with this distribution or the About + * MCT Licenses dialog available at runtime from the MCT Help menu for additional + * information. + *******************************************************************************/ +package gov.nasa.arc.mct.services.component; + +import org.testng.Assert; +import org.testng.annotations.Test; + +public class AbstractComponentProviderTest { + @Test + public void testAbstractComponentProvider() { + // Verify that: + // - Collection methods return empty (non-null) by default + // - Non-collection methods return null + AbstractComponentProvider provider = new AbstractComponentProvider(){}; + + Assert.assertTrue(provider.getComponentTypes().isEmpty()); + Assert.assertTrue(provider.getMenuItemInfos().isEmpty()); + Assert.assertTrue(provider.getPolicyInfos().isEmpty()); + Assert.assertTrue(provider.getStatusAreaWidgetInfos().isEmpty()); + Assert.assertTrue(provider.getViews("").isEmpty()); + Assert.assertNull(provider.getSearchProvider()); + Assert.assertNull(provider.getProviderDelegate()); + Assert.assertNull(provider.getAsset(null, null)); + } +} diff --git a/mctcore/src/test/java/gov/nasa/arc/mct/services/component/ComponentTypeInfoTest.java b/mctcore/src/test/java/gov/nasa/arc/mct/services/component/ComponentTypeInfoTest.java new file mode 100644 index 00000000..0c681c34 --- /dev/null +++ b/mctcore/src/test/java/gov/nasa/arc/mct/services/component/ComponentTypeInfoTest.java @@ -0,0 +1,74 @@ +/******************************************************************************* + * Mission Control Technologies, Copyright (c) 2009-2012, United States Government + * as represented by the Administrator of the National Aeronautics and Space + * Administration. All rights reserved. + * + * The MCT platform is licensed under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + * + * MCT includes source code licensed under additional open source licenses. See + * the MCT Open Source Licenses file included with this distribution or the About + * MCT Licenses dialog available at runtime from the MCT Help menu for additional + * information. + *******************************************************************************/ +package gov.nasa.arc.mct.services.component; + +import gov.nasa.arc.mct.components.AbstractComponent; +import gov.nasa.arc.mct.platform.spi.Platform; +import gov.nasa.arc.mct.platform.spi.PlatformAccess; +import gov.nasa.arc.mct.services.internal.component.CoreComponentRegistry; + +import org.mockito.Mockito; +import org.testng.Assert; +import org.testng.annotations.Test; + + +public class ComponentTypeInfoTest { + + // Deprecated constructors are exercised for coverage + @SuppressWarnings("deprecation") + @Test + public void testIsCreatable() { + ComponentTypeInfo info; + info = new ComponentTypeInfo("","",AbstractComponent.class,true); + Assert.assertTrue(info.isCreatable()); + info = new ComponentTypeInfo("","",AbstractComponent.class,false); + Assert.assertFalse(info.isCreatable()); + info = new ComponentTypeInfo("","",AbstractComponent.class,true,null); + Assert.assertTrue(info.isCreatable()); + info = new ComponentTypeInfo("","",AbstractComponent.class,false,null); + Assert.assertFalse(info.isCreatable()); + } + + @SuppressWarnings("deprecation") + @Test + public void testDeprecatedMethods() { + // Verify that deprecated methods are redirected to getAsset + Platform oldPlatform = PlatformAccess.getPlatform(); + Platform mockPlatform = Mockito.mock(Platform.class); + CoreComponentRegistry mockRegistry = Mockito.mock(CoreComponentRegistry.class); + Mockito.when(mockPlatform.getComponentRegistry()).thenReturn(mockRegistry); + new PlatformAccess().setPlatform(mockPlatform); + + ComponentTypeInfo info; + info = new ComponentTypeInfo("","",AbstractComponent.class); + info.getIcon(); + Mockito.verify(mockRegistry).getAsset(info, javax.swing.ImageIcon.class); + + info = new ComponentTypeInfo("","",AbstractComponent.class); + info.getWizardUI(); + Mockito.verify(mockRegistry).getAsset(info, CreateWizardUI.class); + + + new PlatformAccess().setPlatform(oldPlatform); + } + +} diff --git a/mctcore/src/test/java/gov/nasa/arc/mct/services/component/TypeInfoTest.java b/mctcore/src/test/java/gov/nasa/arc/mct/services/component/TypeInfoTest.java new file mode 100644 index 00000000..3b8580eb --- /dev/null +++ b/mctcore/src/test/java/gov/nasa/arc/mct/services/component/TypeInfoTest.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * Mission Control Technologies, Copyright (c) 2009-2012, United States Government + * as represented by the Administrator of the National Aeronautics and Space + * Administration. All rights reserved. + * + * The MCT platform is licensed under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + * + * MCT includes source code licensed under additional open source licenses. See + * the MCT Open Source Licenses file included with this distribution or the About + * MCT Licenses dialog available at runtime from the MCT Help menu for additional + * information. + *******************************************************************************/ +package gov.nasa.arc.mct.services.component; + +import gov.nasa.arc.mct.platform.spi.Platform; +import gov.nasa.arc.mct.platform.spi.PlatformAccess; +import gov.nasa.arc.mct.services.internal.component.CoreComponentRegistry; + +import javax.swing.Icon; + +import org.mockito.Mockito; +import org.testng.Assert; +import org.testng.annotations.Test; + +public class TypeInfoTest { + @Test + public void testGetTypeClass() { + Assert.assertEquals(new TypeInfo(String.class){}.getTypeClass(), String.class); + Assert.assertEquals(new TypeInfo(TypeInfoTest.class){}.getTypeClass(), TypeInfoTest.class); + } + + @Test + public void testGetAsset() { + // Verify that getAsset is robust to null platform, etc + Platform oldPlatform = PlatformAccess.getPlatform(); + Platform mockPlatform = Mockito.mock(Platform.class); + CoreComponentRegistry mockRegistry = Mockito.mock(CoreComponentRegistry.class); + Icon mockIcon = Mockito.mock(Icon.class); + + TypeInfo info = new TypeInfo(TypeInfoTest.class){}; + + // Try with a null platform - should fail to retrieve asset + new PlatformAccess().setPlatform(null); + Assert.assertNull(info.getAsset(Icon.class)); + + // Try with a platform but no registry - should fail to retrieve asset + new PlatformAccess().setPlatform(mockPlatform); + Assert.assertNull(info.getAsset(Icon.class)); + + // Try with a mock registry (but no assets) - should fail to retrieve + Mockito.when(mockPlatform.getComponentRegistry()).thenReturn(mockRegistry); + Assert.assertNull(info.getAsset(Icon.class)); + + // Try with a mock registry that has the requested asset - should retrieve it + Mockito.when(mockRegistry.getAsset(info, Icon.class)).thenReturn(mockIcon); + Assert.assertEquals(info.getAsset(Icon.class), mockIcon); + + // Restore old platform + new PlatformAccess().setPlatform(oldPlatform); + } +} From 9d6ba48a9204f8190b9be60126dce21cda459145 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Thu, 12 Sep 2013 15:16:22 -0700 Subject: [PATCH 18/27] [Icons] Test default getAsset --- .../view/TestDefaultViewProvider.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/platform/src/test/java/gov/nasa/arc/mct/defaults/view/TestDefaultViewProvider.java b/platform/src/test/java/gov/nasa/arc/mct/defaults/view/TestDefaultViewProvider.java index df7e12b3..1a0928f3 100644 --- a/platform/src/test/java/gov/nasa/arc/mct/defaults/view/TestDefaultViewProvider.java +++ b/platform/src/test/java/gov/nasa/arc/mct/defaults/view/TestDefaultViewProvider.java @@ -21,12 +21,18 @@ *******************************************************************************/ package gov.nasa.arc.mct.defaults.view; +import gov.nasa.arc.mct.components.AbstractComponent; +import gov.nasa.arc.mct.gui.View; +import gov.nasa.arc.mct.services.component.ComponentTypeInfo; +import gov.nasa.arc.mct.services.component.TypeInfo; import gov.nasa.arc.mct.services.component.ViewInfo; import gov.nasa.arc.mct.services.component.ViewType; import java.util.HashSet; import java.util.Set; +import javax.swing.Icon; + import org.testng.Assert; import org.testng.annotations.Test; @@ -64,4 +70,23 @@ public void testGetViews() { Assert.assertTrue(viewTypes.contains(ViewType.RIGHT)); } + @Test + public void testGetAsset() { + // Verify provider is giving default icons + DefaultViewProvider provider = new DefaultViewProvider(); + TypeInfo info; + + // Should give icons for any kind of type info (esp components and views) + info = new ComponentTypeInfo("","",AbstractComponent.class); + Assert.assertNotNull(provider.getAsset(info, Icon.class)); + + info = new ViewInfo(View.class,"",ViewType.OBJECT); + Assert.assertNotNull(provider.getAsset(info, Icon.class)); + + info = new TypeInfo(TestDefaultViewProvider.class){}; + Assert.assertNotNull(provider.getAsset(info, Icon.class)); + + // Should not give anything other than icons + Assert.assertNull(provider.getAsset(info, getClass())); + } } From 06147a53a3713c6b0d86083b3d30dcc96bfeb555 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Thu, 12 Sep 2013 15:17:51 -0700 Subject: [PATCH 19/27] [Icons] Test table provider's getAsset --- .../arc/mct/table/TableViewProviderTest.java | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/tableViews/src/test/java/gov/nasa/arc/mct/table/TableViewProviderTest.java b/tableViews/src/test/java/gov/nasa/arc/mct/table/TableViewProviderTest.java index b2a42547..cf94b083 100644 --- a/tableViews/src/test/java/gov/nasa/arc/mct/table/TableViewProviderTest.java +++ b/tableViews/src/test/java/gov/nasa/arc/mct/table/TableViewProviderTest.java @@ -22,13 +22,17 @@ package gov.nasa.arc.mct.table; import gov.nasa.arc.mct.policy.PolicyInfo; +import gov.nasa.arc.mct.services.component.TypeInfo; import gov.nasa.arc.mct.services.component.ViewInfo; import gov.nasa.arc.mct.services.component.ViewType; import gov.nasa.arc.mct.table.view.TableViewManifestation; - + import java.util.Collection; import java.util.Collections; - + +import javax.swing.Icon; +import javax.swing.ImageIcon; + import org.testng.Assert; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -57,5 +61,27 @@ public void testGetViewInfos() { public void testGetPolicyInfos() { Collection infos = provider.getPolicyInfos(); Assert.assertTrue(infos.size() > 0); - } + } + + @Test + public void testGetAsset() { + @SuppressWarnings("serial") + class UnknownType extends ImageIcon {}; + + for (ViewInfo viewInfo : provider.getViews("")) { + // Should have an icon + Assert.assertNotNull(provider.getAsset(viewInfo, ImageIcon.class)); + // Should obey assignable rules for icon + Assert.assertNotNull(provider.getAsset(viewInfo, Icon.class)); + Assert.assertNull(provider.getAsset(viewInfo, UnknownType.class)); + } + + // Should not have assets for unknown types + TypeInfo unknownInfo = new TypeInfo(UnknownType.class){}; + for (Class type : new Class[] {ImageIcon.class,Icon.class,UnknownType.class}) { + Assert.assertNull(provider.getAsset(unknownInfo, type)); + } + + } + } From 0c6d01f6d3661e8a4191bc54c31a21b9d351d998 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Thu, 12 Sep 2013 16:01:21 -0700 Subject: [PATCH 20/27] [Icons] Unit test caching in MCTIcons --- .../gov/nasa/arc/mct/util/MCTIconsTest.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/util/src/test/java/gov/nasa/arc/mct/util/MCTIconsTest.java b/util/src/test/java/gov/nasa/arc/mct/util/MCTIconsTest.java index 32a1d181..7497ec40 100644 --- a/util/src/test/java/gov/nasa/arc/mct/util/MCTIconsTest.java +++ b/util/src/test/java/gov/nasa/arc/mct/util/MCTIconsTest.java @@ -88,6 +88,33 @@ public void testProcessIcon() { } + @Test + public void testProcessIconCaching() { + // Generate a base image (for convenience) + ImageIcon original = MCTIcons.generateIcon(0x1982, 16, Color.WHITE); + + // Processing it twice should give the same (pointer-identical) image + ImageIcon processed = MCTIcons.processIcon(original); + Assert.assertSame(MCTIcons.processIcon(original), processed); + + // Should also avoid re-processing icons + Assert.assertSame(MCTIcons.processIcon(processed), processed); + + // A processed null should just be a null + Assert.assertNull(MCTIcons.processIcon(null)); + + // Should not use default cache with processing instructions + ImageIcon colorized = MCTIcons.processIcon(original, Color.MAGENTA, true); + Assert.assertNotSame(colorized, processed); + + // Should cache for specific processing instructions + Assert.assertSame(MCTIcons.processIcon(original, Color.MAGENTA, true), colorized); + + // Should not use cache if processing instructions change + Assert.assertNotSame(MCTIcons.processIcon(original, Color.MAGENTA, false), colorized); + Assert.assertNotSame(MCTIcons.processIcon(original, Color.ORANGE, true), colorized); + } + private static class IconTester { private int hash; private BufferedImage image; From b71931334dd613bf2036e3f175ae995bc59655e0 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Fri, 13 Sep 2013 09:30:19 -0700 Subject: [PATCH 21/27] [Icons] Add support for gradients in processIcon --- .../java/gov/nasa/arc/mct/util/MCTIcons.java | 72 +++++++++++++++---- 1 file changed, 59 insertions(+), 13 deletions(-) diff --git a/util/src/main/java/gov/nasa/arc/mct/util/MCTIcons.java b/util/src/main/java/gov/nasa/arc/mct/util/MCTIcons.java index 5274b459..9a5bfdb5 100644 --- a/util/src/main/java/gov/nasa/arc/mct/util/MCTIcons.java +++ b/util/src/main/java/gov/nasa/arc/mct/util/MCTIcons.java @@ -39,6 +39,8 @@ import java.util.Map; import javax.swing.ImageIcon; +import javax.swing.JFrame; +import javax.swing.JLabel; /** * MCT icons for errors, warnings and component object. @@ -296,28 +298,53 @@ private static ImageIcon doProcessing(ProcessDescription pd) { if (pd.firstColor != null) { // Gradient fill if (pd.secondColor != null && pd.secondColor.getRGB() != pd.firstColor.getRGB()) { - // TODO: Support gradient fill + // Repaint original icon & colorize + pd.icon.paintIcon(null, bufferedImage.getGraphics(), 1, 1); + bufferedImage = colorize(bufferedImage, pd.firstColor); + BufferedImage secondBufferedImage = colorize(bufferedImage, pd.secondColor); + fade(secondBufferedImage); + bufferedImage.getGraphics().drawImage(secondBufferedImage, 0, 0, null); } else { - // Convert color to scaling factor - int rgb = pd.firstColor.getRGB(); - float coloration[] = new float[4]; - for (int i = 0; i < 3; i++) { - coloration[2-i] = (float) (rgb & 0xFF) / 255f; - rgb >>>= 8; - } - coloration[3] = 1f; // Always full alpha - - float offset[] = {0f,0f,0f,0f}; - // Repaint original icon & colorize pd.icon.paintIcon(null, bufferedImage.getGraphics(), 1, 1); - bufferedImage = new RescaleOp(coloration, offset, null).filter(bufferedImage, null); + bufferedImage = colorize(bufferedImage, pd.firstColor); } } return new ImageIcon(bufferedImage); } + private static void fade(BufferedImage b) { + float step = 1f / (float) (b.getHeight()); + float fade = 0f; + for (int y = 0; y < b.getHeight(); y++) { + for (int x = 0; x < b.getWidth(); x++) { + int argb = b.getRGB(x, y); + int a = (argb >>> 24) & 0xFF; + int rgb = argb - (a << 24); + a = (int) (((float) a) * fade); + b.setRGB(x, y, rgb | (a << 24)); + } + fade += step; + } + } + + private static BufferedImage colorize(BufferedImage b, Color c) { + // Convert color to scaling factor + int rgb = c.getRGB(); + float coloration[] = new float[4]; + for (int i = 0; i < 3; i++) { + coloration[2-i] = (float) (rgb & 0xFF) / 255f; + rgb >>>= 8; + } + coloration[3] = 1f; // Always full alpha + + float offset[] = {0f,0f,0f,0f}; + + // Repaint original icon & colorize + return new RescaleOp(coloration, offset, null).filter(b, null); + } + /** * Describes a set of processing arguments used upon an icon. * Used to support a HashMap cache of already-processed icons. @@ -373,5 +400,24 @@ private boolean colorsEqual(Color a, Color b) { } } } + + private static void showIcon (ImageIcon icon) { + JFrame frame = new JFrame(); + JLabel label = new JLabel(icon); + frame.getContentPane().add(label); + frame.getContentPane().setBackground(Color.BLACK); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setVisible(true); + frame.pack(); + } + + public static void main(String[] args) { + showIcon( + processIcon ( + generateIcon((int)(Math.random() * 100000f), 128, Color.WHITE), + Color.PINK, Color.BLUE, + false + )); + } } From aee4c347818c6643aa35a30ee51225bb0d953343 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Fri, 13 Sep 2013 09:33:45 -0700 Subject: [PATCH 22/27] [Icons] Add comments to alpha gradient code --- util/src/main/java/gov/nasa/arc/mct/util/MCTIcons.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/util/src/main/java/gov/nasa/arc/mct/util/MCTIcons.java b/util/src/main/java/gov/nasa/arc/mct/util/MCTIcons.java index 9a5bfdb5..ef8198f2 100644 --- a/util/src/main/java/gov/nasa/arc/mct/util/MCTIcons.java +++ b/util/src/main/java/gov/nasa/arc/mct/util/MCTIcons.java @@ -315,16 +315,23 @@ private static ImageIcon doProcessing(ProcessDescription pd) { } private static void fade(BufferedImage b) { + // Reduce alpha in image, such that top is transparent + // and bottom is as opaque as original, with a smooth + // fade in between. This supports color gradients. float step = 1f / (float) (b.getHeight()); - float fade = 0f; + float fade = 0f; // Will increase to 1f by bottom of image for (int y = 0; y < b.getHeight(); y++) { for (int x = 0; x < b.getWidth(); x++) { + // Get pixel as integer int argb = b.getRGB(x, y); + // Separate out alpha from RGB int a = (argb >>> 24) & 0xFF; int rgb = argb - (a << 24); + // Compute new alpha a = (int) (((float) a) * fade); b.setRGB(x, y, rgb | (a << 24)); } + // Linearly interpolate fade += step; } } From 2dd272e17056c4cb0565cfda3f0d16b92f0a55ee Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Fri, 13 Sep 2013 09:36:31 -0700 Subject: [PATCH 23/27] [Icons] Include gradient icon processing in test --- util/src/test/java/gov/nasa/arc/mct/util/MCTIconsTest.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/util/src/test/java/gov/nasa/arc/mct/util/MCTIconsTest.java b/util/src/test/java/gov/nasa/arc/mct/util/MCTIconsTest.java index 7497ec40..a5b2a1dc 100644 --- a/util/src/test/java/gov/nasa/arc/mct/util/MCTIconsTest.java +++ b/util/src/test/java/gov/nasa/arc/mct/util/MCTIconsTest.java @@ -113,6 +113,11 @@ public void testProcessIconCaching() { // Should not use cache if processing instructions change Assert.assertNotSame(MCTIcons.processIcon(original, Color.MAGENTA, false), colorized); Assert.assertNotSame(MCTIcons.processIcon(original, Color.ORANGE, true), colorized); + + // Should also distinguish different gradient choices (and recognize same ones) + ImageIcon gradient = MCTIcons.processIcon(original, Color.MAGENTA, Color.YELLOW, true); + Assert.assertNotSame(gradient, colorized); + Assert.assertSame(MCTIcons.processIcon(original, Color.MAGENTA, Color.YELLOW, true), gradient); } private static class IconTester { From 2420be396a58a33de99e702fa190eafa66224ce3 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Fri, 13 Sep 2013 09:46:30 -0700 Subject: [PATCH 24/27] [Icons] Use gradient fill for tree, menus --- .../gov/nasa/arc/mct/defaults/view/NodeViewManifestation.java | 2 +- .../main/java/gov/nasa/arc/mct/gui/menu/NewObjectAction.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/platform/src/main/java/gov/nasa/arc/mct/defaults/view/NodeViewManifestation.java b/platform/src/main/java/gov/nasa/arc/mct/defaults/view/NodeViewManifestation.java index 31aa8e46..9d43a05a 100644 --- a/platform/src/main/java/gov/nasa/arc/mct/defaults/view/NodeViewManifestation.java +++ b/platform/src/main/java/gov/nasa/arc/mct/defaults/view/NodeViewManifestation.java @@ -105,7 +105,7 @@ public NodeViewManifestation(AbstractComponent component, ViewInfo viewinfo) { private ImageIcon getIcon(AbstractComponent ac) { ImageIcon baseIcon = ac.getAsset(ImageIcon.class); - return MCTIcons.processIcon(baseIcon, new Color(101, 131, 192), false); + return MCTIcons.processIcon(baseIcon, new Color(129, 154, 204), new Color(101, 131, 192), false); } private void doLockRendering(JLabel widget, AbstractComponent comp) { diff --git a/platform/src/main/java/gov/nasa/arc/mct/gui/menu/NewObjectAction.java b/platform/src/main/java/gov/nasa/arc/mct/gui/menu/NewObjectAction.java index 3e6c54fb..4a120fb1 100644 --- a/platform/src/main/java/gov/nasa/arc/mct/gui/menu/NewObjectAction.java +++ b/platform/src/main/java/gov/nasa/arc/mct/gui/menu/NewObjectAction.java @@ -105,7 +105,7 @@ private class NewTypeAction extends AbstractAction { public NewTypeAction(ComponentTypeInfo info, AbstractComponent targetComponent) { putValue(Action.NAME, info.getDisplayName()); - putValue(Action.SMALL_ICON, MCTIcons.processIcon(info.getAsset(ImageIcon.class), new Color(40,40,40), false)); + putValue(Action.SMALL_ICON, MCTIcons.processIcon(info.getAsset(ImageIcon.class), new Color(80,80,80), new Color(40,40,40), false)); this.componentClass = info.getTypeClass(); this.targetComponent = targetComponent; this.wizardUI = info.getAsset(CreateWizardUI.class); From af2973f54e750b2dd035230bbfece87ce981d2ef Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Fri, 13 Sep 2013 09:47:43 -0700 Subject: [PATCH 25/27] [Icons] Tweak generated icons to ensure symmetry Point at the center of generated icons (when present) was slightly off-center due to rounding issues. This special-cases the center point to ensure it is appropriately aligned with respect to other elements drawn. --- util/src/main/java/gov/nasa/arc/mct/util/MCTIcons.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/util/src/main/java/gov/nasa/arc/mct/util/MCTIcons.java b/util/src/main/java/gov/nasa/arc/mct/util/MCTIcons.java index ef8198f2..20792971 100644 --- a/util/src/main/java/gov/nasa/arc/mct/util/MCTIcons.java +++ b/util/src/main/java/gov/nasa/arc/mct/util/MCTIcons.java @@ -153,7 +153,7 @@ public static ImageIcon generateIcon(int hash, int sz, Color color) { for (int radius = 1; radius < sz/2; radius += sz/7) { if (((hash>>>=1) & 1) != 0) { if (radius < 3) { - g.fillOval(sz/2-radius, sz/2-radius, radius*2, radius*2); + g.fillOval(sz/2-1, sz/2-1, 3, 3); } else { g.drawOval(sz/2-radius, sz/2-radius, radius*2, radius*2); } @@ -163,15 +163,10 @@ public static ImageIcon generateIcon(int hash, int sz, Color color) { // Draw concentric Squares for (int radius = 3; radius < sz/2; radius += sz/7) { if (((hash>>>=1) & 1) != 0) { - if (radius < 3) { - g.fillRect(sz/2-radius, sz/2-radius, radius*2, radius*2); - } else { - g.drawRect(sz/2-radius, sz/2-radius, radius*2, radius*2); - } + g.drawRect(sz/2-radius, sz/2-radius, radius*2, radius*2); } } - // Draw top/bottom dots if (((hash>>>=1) & 1) != 0) { g.fillOval(1,sz/2-sz/14,sz/7,sz/7+1); From 5e9eb54ebf8ffeb3020d4d47438ad2ac77c4b809 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Fri, 13 Sep 2013 09:48:17 -0700 Subject: [PATCH 26/27] [Icons] Remove debug code from MCTIcons --- .../java/gov/nasa/arc/mct/util/MCTIcons.java | 20 +------------------ 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/util/src/main/java/gov/nasa/arc/mct/util/MCTIcons.java b/util/src/main/java/gov/nasa/arc/mct/util/MCTIcons.java index 20792971..dbabee04 100644 --- a/util/src/main/java/gov/nasa/arc/mct/util/MCTIcons.java +++ b/util/src/main/java/gov/nasa/arc/mct/util/MCTIcons.java @@ -402,24 +402,6 @@ private boolean colorsEqual(Color a, Color b) { } } } - - private static void showIcon (ImageIcon icon) { - JFrame frame = new JFrame(); - JLabel label = new JLabel(icon); - frame.getContentPane().add(label); - frame.getContentPane().setBackground(Color.BLACK); - frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - frame.setVisible(true); - frame.pack(); - } - - public static void main(String[] args) { - showIcon( - processIcon ( - generateIcon((int)(Math.random() * 100000f), 128, Color.WHITE), - Color.PINK, Color.BLUE, - false - )); - } + } From 0103b604fcd5926615fc3e25a47df4e7ee85eead Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Fri, 13 Sep 2013 10:14:17 -0700 Subject: [PATCH 27/27] [Icons] Remove unused imports from MCTIcons --- util/src/main/java/gov/nasa/arc/mct/util/MCTIcons.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/util/src/main/java/gov/nasa/arc/mct/util/MCTIcons.java b/util/src/main/java/gov/nasa/arc/mct/util/MCTIcons.java index dbabee04..cae62b09 100644 --- a/util/src/main/java/gov/nasa/arc/mct/util/MCTIcons.java +++ b/util/src/main/java/gov/nasa/arc/mct/util/MCTIcons.java @@ -39,8 +39,6 @@ import java.util.Map; import javax.swing.ImageIcon; -import javax.swing.JFrame; -import javax.swing.JLabel; /** * MCT icons for errors, warnings and component object.