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..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 @@ -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(130,130,130); + + /** * 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/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/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/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/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/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/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..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,18 +21,25 @@ *******************************************************************************/ 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.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; +import org.testng.annotations.Test; public class GraphicalComponentProviderTest { @@ -62,7 +69,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,11 +89,51 @@ public void testComponentTypeInfos() { if (info.getComponentClass().equals(GraphicalComponent.class)){ foundGraphicalComponent = true; Assert.assertTrue(info.isCreatable()); - Assert.assertTrue(info.getWizardUI() instanceof GraphicalComponentWizardUI); } } 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/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/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..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,22 +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.CENTER))); - - 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)); - - views = multiProvider.getViews(MultiComponent.class.getName()); - Assert.assertEquals(views.size(), 3); - 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(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)); + 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/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/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/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/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/main/java/gov/nasa/arc/mct/limits/LimitLineComponentProvider.java b/limits/src/main/java/gov/nasa/arc/mct/limits/LimitLineComponentProvider.java index a8306584..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 @@ -25,6 +25,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 java.util.Collection; @@ -36,15 +38,13 @@ 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() - ); + LimitLineComponent.class); } @Override @@ -66,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/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/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/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 }, + }; + } + +} 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..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 @@ -37,16 +37,15 @@ 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; +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; @@ -67,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 @@ -96,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; @@ -171,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. @@ -709,6 +709,20 @@ 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 && info.getComponentClass().equals(getClass())) { + typeInfo = info; + break; + } + } + if (typeInfo == null) { + typeInfo = new ComponentTypeInfo(getClass().getSimpleName(), getClass().getSimpleName(), getClass()); + } + } + return capability.cast(typeInfo); } return handleGetCapability(capability); @@ -872,18 +886,25 @@ public int getVersion() { return version; } + /** + * 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) + */ + public T getAsset(Class assetClass) { + return getCapability(ComponentTypeInfo.class).getAsset(assetClass); + } + /** * Returns the icon image for this component. * @return an icon image + * @deprecated use getAsset(Icon.class) instead */ - public final ImageIcon getIcon() { - Collection infos = ExternalComponentRegistryImpl.getInstance().getComponentInfos(); - for (ExtendedComponentTypeInfo info : infos) { - if (getClass() == info.getComponentClass()) { - return info.getIcon(); - } - } - return MCTIcons.getComponent(); + @Deprecated + public final javax.swing.ImageIcon getIcon() { + return getAsset(javax.swing.ImageIcon.class); } /** @@ -891,14 +912,15 @@ public final ImageIcon getIcon() { * @param className of the component type * @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(); + @Deprecated + public static javax.swing.ImageIcon getIconForComponentType(String className) { + for (ComponentTypeInfo componentTypeInfo : + ExternalComponentRegistryImpl.getInstance().getComponentInfos()) { + if (componentTypeInfo.getTypeClass().getName().equals(className)) { + return componentTypeInfo.getAsset(javax.swing.ImageIcon.class); } } - return MCTIcons.getComponent(); + return null; } /** 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/registry/ExternalComponentRegistryImpl.java b/mctcore/src/main/java/gov/nasa/arc/mct/registry/ExternalComponentRegistryImpl.java index 5db90e13..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 @@ -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; @@ -74,7 +75,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 +149,18 @@ public Set getViewInfos(String componentTypeId, ViewType type) { */ public Collection getComponentInfos() { return availableComponents.values(); + } + + + @Override + public T getAsset(TypeInfo objectType, Class assetClass) { + for (ExtendedComponentProvider provider : activeProviders.get()) { + T asset = provider.getAsset(objectType, assetClass); + if (asset != null) { + return asset; + } + } + return defaultViewProvider.get().getAsset(objectType, assetClass); } /** @@ -309,6 +322,11 @@ public Collection getStatusAreaWidgetInfos() { @Override public SearchProvider getSearchProvider() { return provider.getSearchProvider(); + } + + @Override + public T getAsset(TypeInfo objectType, Class assetType) { + return provider.getAsset(objectType, assetType); } } @@ -329,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; } @@ -412,5 +430,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 ffdc8a0d..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 @@ -21,11 +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 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; /** * An abstract class that implements ComponentProvider. @@ -69,5 +69,9 @@ public Collection getStatusAreaWidgetInfos() { public SearchProvider getSearchProvider() { return null; } - + + @Override + 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 b4654e36..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 @@ -21,10 +21,10 @@ *******************************************************************************/ 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; /** * This interface can be implemented as an OSGI service to provide one @@ -80,5 +80,17 @@ 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 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) + */ + 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 113c4156..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 @@ -21,14 +21,8 @@ *******************************************************************************/ 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 @@ -36,26 +30,23 @@ * @author chris.webster@nasa.gov * */ -public class ComponentTypeInfo { - private static final int ICON_SIZE = 14; - private static final Color BASE_ICON_COLOR = Color.WHITE; - +public class ComponentTypeInfo extends TypeInfo { + private final String displayName; private final String description; - private final Class componentClass; private final String componentTypeId; private final boolean isCreatable; - private final CreateWizardUI wizard; - private final ImageIcon icon; /** * 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) { - this(displayName,description,componentClass, componentClass.getName(), true, null, null); + public ComponentTypeInfo(String displayName, String description, Class componentClass) throws IllegalArgumentException { + this(displayName,description,componentClass, componentClass.getName(), true); } /** @@ -63,10 +54,12 @@ public ComponentTypeInfo(String displayName, String description, ClassAbstractComponent */ - public ComponentTypeInfo(String displayName, String description, Class componentClass, boolean isCreatable) { - this(displayName,description,componentClass, componentClass.getName(), isCreatable, null, null); + public ComponentTypeInfo(String displayName, String description, Class componentClass, boolean isCreatable) throws IllegalArgumentException { + this(displayName,description,componentClass, componentClass.getName(), isCreatable); } /** @@ -75,10 +68,14 @@ 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 + * @throws IllegalArgumentException if componentClass, id, or displayName is null or if component class does not meet the requirements of + * AbstractComponent + * @deprecated icon and wizard now specified using ComponentProvider.getAsset + */ + @Deprecated + public ComponentTypeInfo(String displayName, String description, Class componentClass, boolean isCreatable, javax.swing.ImageIcon icon) throws IllegalArgumentException { + this(displayName,description,componentClass, componentClass.getName(), isCreatable); } @@ -87,10 +84,14 @@ public ComponentTypeInfo(String displayName, String description, Class componentClass, CreateWizardUI wizard){ - this(displayName,description,componentClass,componentClass.getName(), true, wizard, null); + * @param wizard creates the panel to be displayed for the dialog box + * @throws IllegalArgumentException if componentClass, id, or displayName is null or if component class does not meet the requirements of + * AbstractComponent + * @deprecated icon and wizard now specified using ComponentProvider.getAsset + */ + @Deprecated + public ComponentTypeInfo(String displayName, String description, Class componentClass, CreateWizardUI wizard) throws IllegalArgumentException { + this(displayName,description,componentClass,componentClass.getName(), true); } /** @@ -100,10 +101,43 @@ public ComponentTypeInfo(String displayName, String description, Class componentClass, CreateWizardUI wizard, ImageIcon icon){ - this(displayName,description,componentClass,componentClass.getName(), true, wizard, icon); + * @throws IllegalArgumentException if componentClass, id, or displayName is null or if component class does not meet the requirements of + * AbstractComponent + * @deprecated icon and wizard now specified using ComponentProvider.getAsset + */ + @Deprecated + public ComponentTypeInfo(String displayName, String description, Class componentClass, CreateWizardUI wizard, javax.swing.ImageIcon icon) throws IllegalArgumentException { + 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) 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; + } /** * Creates a new ComponentTypeInfo representing a unique component type. @@ -116,30 +150,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 { - 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.componentClass = componentClass; - 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); } @@ -148,7 +163,7 @@ protected ComponentTypeInfo(String displayName, String description, Class getComponentClass() { - return componentClass; + return getTypeClass(); } /** @@ -190,18 +205,22 @@ 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 - */ - public final ImageIcon getIcon() { - return icon; + * @return icon for component type + * @deprecated use getAsset(ImageIcon.class) instead + */ + @Deprecated + public final javax.swing.ImageIcon getIcon() { + return getAsset(javax.swing.ImageIcon.class); } @Override 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..5b6fa724 --- /dev/null +++ b/mctcore/src/main/java/gov/nasa/arc/mct/services/component/TypeInfo.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * 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; + +/** + * 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 + * @param the type of asset desired + * @return an object of the desired type (or null if none is available) + */ + public A getAsset(Class 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 36555f14..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 @@ -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 { - private static final int ICON_SIZE = 9; - private static final Color BASE_ICON_COLOR = Color.WHITE; - +public class ViewInfo extends TypeInfo { 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,30 +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 { - 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); } /** @@ -199,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 @@ -243,9 +259,10 @@ public View call() throws Exception { /** * Returns the icon to be placed in a button for this view. * @return icon; null if no provided - */ - public ImageIcon getIcon() { - return icon; + */ + @Deprecated + public javax.swing.ImageIcon getIcon() { + return getAsset(javax.swing.ImageIcon.class); } /** @@ -254,8 +271,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/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..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 @@ -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 @@ -53,5 +54,17 @@ 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 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) + */ + public T getAsset(TypeInfo objectType, Class assetClass); } 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); + } +} 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/defaults/view/DefaultViewProvider.java b/platform/src/main/java/gov/nasa/arc/mct/defaults/view/DefaultViewProvider.java index 847e682f..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 @@ -21,13 +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.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.TypeInfo; 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; @@ -43,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"); @@ -55,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; } @@ -65,5 +71,25 @@ public DefaultViewProvider() { public Collection getViews(String componentTypeId) { return myViewInfos; } - + + @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; + } else if (AbstractComponent.class.isAssignableFrom(type.getTypeClass())) { + sz = 14; + } + return assetClass.cast(MCTIcons.generateIcon( + type.getTypeClass().getName().hashCode(), + sz, Color.WHITE)); + } + return super.getAsset(type, assetClass); + } + + } 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/defaults/view/NodeViewManifestation.java b/platform/src/main/java/gov/nasa/arc/mct/defaults/view/NodeViewManifestation.java index 5c22a571..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 @@ -37,8 +37,10 @@ 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.Color; import java.awt.Dimension; import java.awt.Font; import java.beans.PropertyChangeListener; @@ -48,6 +50,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 +95,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 = ac.getAsset(ImageIcon.class); + return MCTIcons.processIcon(baseIcon, new Color(129, 154, 204), new Color(101, 131, 192), false); + } 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/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 30ae410b..9a9800aa 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. @@ -88,7 +91,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); 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 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(80,80,80), 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/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/platform/src/test/java/gov/nasa/arc/mct/defaults/view/TestComponentIcon.java b/platform/src/test/java/gov/nasa/arc/mct/defaults/view/TestComponentIcon.java index 24d8c02b..304e6d8c 100644 --- a/platform/src/test/java/gov/nasa/arc/mct/defaults/view/TestComponentIcon.java +++ b/platform/src/test/java/gov/nasa/arc/mct/defaults/view/TestComponentIcon.java @@ -26,11 +26,11 @@ import gov.nasa.arc.mct.registry.ExternalComponentRegistryImpl.ExtendedComponentProvider; import gov.nasa.arc.mct.services.component.ComponentProvider; import gov.nasa.arc.mct.services.component.ComponentTypeInfo; - + import java.util.Collections; - + import javax.swing.ImageIcon; - + import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; @@ -49,6 +49,7 @@ public void setup() { component = new MockComponent(); } + @SuppressWarnings("deprecation") // getIcon deprecated but may still be used, so test @Test public void testCreateManifestation() { ImageIcon icon = new ImageIcon(); 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())); + } } diff --git a/platform/src/test/java/gov/nasa/arc/mct/defaults/view/TestInfoView.java b/platform/src/test/java/gov/nasa/arc/mct/defaults/view/TestInfoView.java index 445481e2..9f407310 100644 --- a/platform/src/test/java/gov/nasa/arc/mct/defaults/view/TestInfoView.java +++ b/platform/src/test/java/gov/nasa/arc/mct/defaults/view/TestInfoView.java @@ -132,6 +132,7 @@ public void testExtendedFieldRefresh(VisualControlDescriptor a, VisualControlDes break; } case ComboBox: { + @SuppressWarnings("rawtypes") JComboBox comboBox = findLastComponentOfType(infoView, JComboBox.class); comboBox.setSelectedItem("other"); break; @@ -229,6 +230,7 @@ public Object[][] getExtendedFieldTestCases() { return testCases; } + @SuppressWarnings({ "rawtypes", "unchecked" }) private PropertyDescriptor buildMockDescriptor(VisualControlDescriptor vcd) { PropertyDescriptor mockDescriptor = Mockito.mock(PropertyDescriptor.class); PropertyEditor mockEditor = Mockito.mock(PropertyEditor.class); 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); } 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); + } } 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)); + } + + } + } 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..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; @@ -149,6 +150,12 @@ public AbstractComponent newInstance(String componentType) { public boolean isCreatable(Class clazz) { // TODO Auto-generated method stub return true; + } + + @Override + public T getAsset(TypeInfo objectType, Class assetClass) { + // TODO Auto-generated method stub + return null; } }; 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..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 @@ -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, @@ -150,7 +151,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); } @@ -160,15 +161,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); @@ -216,34 +212,194 @@ 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}; + 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); + } + + /** + * 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); + + 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( - icon.getIconWidth() + 2, - icon.getIconHeight() + 2, - BufferedImage.TYPE_4BYTE_ABGR); + pd.icon.getIconWidth() + 2, + pd.icon.getIconHeight() + 2, + BufferedImage.TYPE_INT_ARGB); - if (dropShadow) { + 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) - icon.paintIcon(null, bufferedImage.getGraphics(), 0, 0); + pd.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); + pd.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); + // 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()) { + // 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 { + // Repaint original icon & colorize + pd.icon.paintIcon(null, bufferedImage.getGraphics(), 1, 1); + bufferedImage = colorize(bufferedImage, pd.firstColor); + } + } + return new ImageIcon(bufferedImage); } - + + 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; // 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; + } + } + + 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. + * + */ + 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(); + } + } + } + } 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..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 @@ -88,6 +88,38 @@ 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); + + // 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 { private int hash; private BufferedImage image;