Permalink
Browse files

[Icons] Add abstract class TypeInfo

Adds the abstract superclass TypeInfo for
ComponentTypeInfo, ViewInfo, etc. Serves as a
common container for class information, and
supports getAsset() calls (without requiring
these shorthands to be implemented separately
for every type described in this manner.)

Future enhancements may include support for
PolicyInfo, and addition of ActionInfo.
  • Loading branch information...
1 parent 94c0abc commit bf0432b80d7ed4a5bf3c6740595b55a151f1d05c @VWoeltjen VWoeltjen committed Sep 11, 2013
@@ -40,12 +40,12 @@
import gov.nasa.arc.mct.roles.events.AddChildEvent;
import gov.nasa.arc.mct.roles.events.PropertyChangeEvent;
import gov.nasa.arc.mct.roles.events.RemoveChildEvent;
+import gov.nasa.arc.mct.services.component.ComponentTypeInfo;
import gov.nasa.arc.mct.services.component.PolicyManager;
import gov.nasa.arc.mct.services.component.ViewInfo;
import gov.nasa.arc.mct.services.component.ViewType;
import gov.nasa.arc.mct.services.internal.component.ComponentInitializer;
import gov.nasa.arc.mct.services.internal.component.Updatable;
-import gov.nasa.arc.mct.util.MCTIcons;
import gov.nasa.arc.mct.util.WeakHashSet;
import gov.nasa.arc.mct.util.exception.MCTRuntimeException;
@@ -95,6 +95,7 @@
/** The unique ID of the component, filled in by the framework. */
private String id;
+ private ComponentTypeInfo typeInfo;
private String owner;
private String originalOwner;
private String creator;
@@ -170,7 +171,7 @@ public AbstractComponent getWorkUnitDelegate() {
public String getComponentTypeID() {
return this.getClass().getName();
}
-
+
/**
* Returns the views for the desired view type. This method will apply the <code>PolicyInfo.CategoryType.FILTER_VIEW_ROLE</code> policy
* and the <code>PolicyInfo.CategoryType.PREFERRED_VIEW</code> policy before returning the appropriate list of views.
@@ -708,6 +709,17 @@ public final void open(GraphicsConfiguration graphicsConfig) {
initializer = new Initializer();
}
return capability.cast(initializer);
+ } else if (capability.isAssignableFrom(ComponentTypeInfo.class)) {
+ if (typeInfo == null) {
+ for (ComponentTypeInfo info :
+ ExternalComponentRegistryImpl.getInstance().getComponentInfos()) {
+ if (info != null) {
+ typeInfo = info;
+ break;
+ }
+ }
+ }
+ return capability.cast(typeInfo);
}
return handleGetCapability(capability);
@@ -874,11 +886,11 @@ public int getVersion() {
/**
* Get an asset of a specified type. For instance, an
* Icon may be retrieved using getAsset(Icon.class).
- * @param assetType the desired type of asset
+ * @param assetClass the desired type of asset
* @return an asset of the desired type (or null if there is none)
*/
- public final <T> T getAsset(Class<T> assetType) {
- return ExternalComponentRegistryImpl.getInstance().getAsset(getClass(), assetType);
+ public <T> T getAsset(Class<T> assetClass) {
+ return getCapability(ComponentTypeInfo.class).getAsset(assetClass);
}
/**
@@ -888,9 +900,7 @@ public int getVersion() {
*/
@Deprecated
public final ImageIcon getIcon() {
- ImageIcon icon = ExternalComponentRegistryImpl.getInstance()
- .getAsset(getClass(), ImageIcon.class);
- return icon != null ? icon : MCTIcons.getComponent();
+ return getAsset(ImageIcon.class);
}
/**
@@ -900,14 +910,13 @@ public final ImageIcon getIcon() {
*/
@Deprecated
public static ImageIcon getIconForComponentType(String className) {
- try {
- Class<?> c = Class.forName(className);
- ImageIcon icon = ExternalComponentRegistryImpl.getInstance()
- .getAsset(c, ImageIcon.class);
- return icon != null ? icon : MCTIcons.getComponent();
- } catch (ClassNotFoundException e) {
- return MCTIcons.getComponent();
- }
+ for (ComponentTypeInfo componentTypeInfo :
+ ExternalComponentRegistryImpl.getInstance().getComponentInfos()) {
+ if (componentTypeInfo.getTypeClass().getName().equals(className)) {
+ return componentTypeInfo.getAsset(ImageIcon.class);
+ }
+ }
+ return null;
}
/**
@@ -33,6 +33,7 @@
import gov.nasa.arc.mct.services.component.ProviderDelegate;
import gov.nasa.arc.mct.services.component.SearchProvider;
import gov.nasa.arc.mct.services.component.StatusAreaWidgetInfo;
+import gov.nasa.arc.mct.services.component.TypeInfo;
import gov.nasa.arc.mct.services.component.ViewInfo;
import gov.nasa.arc.mct.services.component.ViewType;
import gov.nasa.arc.mct.services.internal.component.ComponentInitializer;
@@ -152,14 +153,14 @@ protected String getDefaultUser() {
@Override
- public <T> T getAsset(Class<?> objectClass, Class<T> assetClass) {
+ public <T> T getAsset(TypeInfo<?> objectType, Class<T> assetClass) {
for (ExtendedComponentProvider provider : activeProviders.get()) {
- T asset = provider.getAsset(objectClass, assetClass);
+ T asset = provider.getAsset(objectType, assetClass);
if (asset != null) {
return asset;
}
}
- return defaultViewProvider.get().getAsset(objectClass, assetClass);
+ return defaultViewProvider.get().getAsset(objectType, assetClass);
}
/**
@@ -324,7 +325,7 @@ public SearchProvider getSearchProvider() {
}
@Override
- public <T> T getAsset(Class<?> objectType, Class<T> assetType) {
+ public <T> T getAsset(TypeInfo<?> objectType, Class<T> assetType) {
return null;
}
@@ -71,7 +71,7 @@ public SearchProvider getSearchProvider() {
}
@Override
- public <T> T getAsset(Class<?> type, Class<T> assetClass) {
+ public <T> T getAsset(TypeInfo<?> type, Class<T> assetClass) {
return null;
}
}
@@ -88,8 +88,8 @@
* types, but are not incorporated into those types directly to preserve separation of
* concerns.
* @param objectType the type with which the requested asset is associated
- * @param assetType the type of the requested asset
+ * @param assetClass the type of the requested asset
* @return an asset of the requested type (or null, if none is provided)
*/
- <T> T getAsset(Class<?> objectType, Class<T> assetType);
+ <T> T getAsset(TypeInfo<?> objectType, Class<T> assetClass);
}
@@ -21,10 +21,7 @@
*******************************************************************************/
package gov.nasa.arc.mct.services.component;
-
-
import gov.nasa.arc.mct.components.AbstractComponent;
-import gov.nasa.arc.mct.platform.spi.PlatformAccess;
import gov.nasa.arc.mct.util.MCTIcons;
import java.awt.Color;
@@ -37,13 +34,12 @@
* @author chris.webster@nasa.gov
*
*/
-public class ComponentTypeInfo {
+public class ComponentTypeInfo extends TypeInfo<AbstractComponent> {
private static final int ICON_SIZE = 14;
private static final Color BASE_ICON_COLOR = Color.WHITE;
private final String displayName;
private final String description;
- private final Class<? extends AbstractComponent> componentClass;
private final String componentTypeId;
private final boolean isCreatable;
private final CreateWizardUI wizard;
@@ -119,6 +115,7 @@ public ComponentTypeInfo(String displayName, String description, Class<? extends
* <code>AbstractComponent</code>
*/
protected ComponentTypeInfo(String displayName, String description, Class<? extends AbstractComponent> componentClass, String id, boolean isCreatable, CreateWizardUI wizard, ImageIcon icon) throws IllegalArgumentException {
+ super(componentClass);
if (componentClass == null) {
throw new IllegalArgumentException("componentClass must not be null");
}
@@ -132,7 +129,6 @@ protected ComponentTypeInfo(String displayName, String description, Class<? exte
}
this.displayName = displayName;
this.description = description;
- this.componentClass = componentClass;
this.componentTypeId = id;
this.isCreatable = isCreatable;
this.wizard = wizard;
@@ -149,7 +145,7 @@ protected ComponentTypeInfo(String displayName, String description, Class<? exte
* @return component class of this component type
*/
public final Class<? extends AbstractComponent> getComponentClass() {
- return componentClass;
+ return getTypeClass();
}
/**
@@ -208,17 +204,6 @@ public final CreateWizardUI getWizardUI() {
public final ImageIcon getIcon() {
return getAsset(ImageIcon.class);
}
-
- /**
- * Get an asset associated with this view type.
- * For instance, getAsset(ImageIcon.class) to get
- * an icon for this view.
- * @param assetClass the type of asset desired
- * @return an object of the desired type (or null if none is available)
- */
- public <T> T getAsset(Class<T> assetClass) {
- return PlatformAccess.getPlatform().getComponentRegistry().getAsset(componentClass, assetClass);
- }
@Override
public final boolean equals(Object obj) {
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * Mission Control Technologies, Copyright (c) 2009-2012, United States Government
+ * as represented by the Administrator of the National Aeronautics and Space
+ * Administration. All rights reserved.
+ *
+ * The MCT platform is licensed under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0.
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ *
+ * MCT includes source code licensed under additional open source licenses. See
+ * the MCT Open Source Licenses file included with this distribution or the About
+ * MCT Licenses dialog available at runtime from the MCT Help menu for additional
+ * information.
+ *******************************************************************************/
+package gov.nasa.arc.mct.services.component;
+
+import gov.nasa.arc.mct.platform.spi.PlatformAccess;
+
+/**
+ * Provides information about a type relevant to MCT.
+ * Serves as an abstract superclass for ComponentTypeInfo,
+ * ViewInfo, and PolicyInfo, allowing these to be dealt
+ * with in a unified manner where appropriate.
+ *
+ * This should typically be parameterized with a high-level
+ * class (such as AbstractComponent, View, or Policy)
+ * and given a specific concrete subclass thereof in the
+ * constructor.
+ *
+ * @author vwoeltje
+ *
+ * @param <T> the class which characterizes these types
+ */
+public abstract class TypeInfo<T> {
+ private Class<? extends T> typeClass;
+
+ /**
+ * Instantiate a new new TypeInfo object for the
+ * specified class.
+ * @param typeClass the specific class being described
+ */
+ public TypeInfo(Class<? extends T> typeClass) {
+ this.typeClass = typeClass;
+ }
+
+ /**
+ * Get the specific class being described by this
+ * type info.
+ * @return the specific class being described
+ */
+ public Class<? extends T> getTypeClass() {
+ return typeClass;
+ }
+
+ /**
+ * Get an asset associated with this type.
+ * For instance, getAsset(ImageIcon.class) to get
+ * an icon.
+ * @param assetClass the type of asset desired
+ * @return an object of the desired type (or null if none is available)
+ */
+ public <A> A getAsset(Class<A> assetClass) {
+ return PlatformAccess.getPlatform().getComponentRegistry().getAsset(this, assetClass);
+ }
+}
@@ -23,7 +23,6 @@
import gov.nasa.arc.mct.components.AbstractComponent;
import gov.nasa.arc.mct.gui.View;
-import gov.nasa.arc.mct.platform.spi.PlatformAccess;
import gov.nasa.arc.mct.util.LookAndFeelSettings;
import gov.nasa.arc.mct.util.MCTIcons;
@@ -38,7 +37,7 @@
* The ViewInfo class describes metadata about a view. This class is used to create new view instances.
*
*/
-public class ViewInfo {
+public class ViewInfo extends TypeInfo<View> {
private static final int ICON_SIZE = 9;
private static final Color BASE_ICON_COLOR = Color.WHITE;
@@ -143,6 +142,7 @@ public ViewInfo(Class<? extends View> aViewClass, String name, String aType, Vie
* @throws IllegalArgumentException if the view type is null or the class doesn't have the right type of constructor
*/
public ViewInfo(Class<? extends View> aViewClass, String name, String aType, ViewType viewType, ImageIcon icon, ImageIcon selectedIcon, boolean shouldExpandCenterPaneInWindow, Class<? extends AbstractComponent> preferredComponentType) throws IllegalArgumentException {
+ super(aViewClass);
type = aType;
viewName = name;
this.icon = MCTIcons.processIcon(
@@ -267,17 +267,6 @@ public ImageIcon getSelectedIcon() {
public boolean shouldExpandCenterPaneInWindow() {
return shouldExpandCenterPaneInWindow;
}
-
- /**
- * Get an asset associated with this view type.
- * For instance, getAsset(ImageIcon.class) to get
- * an icon for this view.
- * @param assetClass the type of asset desired
- * @return an object of the desired type (or null if none is available)
- */
- public <T> T getAsset(Class<T> assetClass) {
- return PlatformAccess.getPlatform().getComponentRegistry().getAsset(getViewClass(), assetClass);
- }
private Constructor<? extends View> getConstructor(Class<? extends View> viewClass) {
Constructor<? extends View> c = null;
@@ -21,13 +21,14 @@
*******************************************************************************/
package gov.nasa.arc.mct.services.internal.component;
-import gov.nasa.arc.mct.components.AbstractComponent;
-import gov.nasa.arc.mct.services.component.ComponentRegistry;
-import gov.nasa.arc.mct.services.component.ComponentTypeInfo;
-import gov.nasa.arc.mct.services.component.ViewInfo;
-import gov.nasa.arc.mct.services.component.ViewType;
-
-import java.util.Set;
+import gov.nasa.arc.mct.components.AbstractComponent;
+import gov.nasa.arc.mct.services.component.ComponentRegistry;
+import gov.nasa.arc.mct.services.component.ComponentTypeInfo;
+import gov.nasa.arc.mct.services.component.TypeInfo;
+import gov.nasa.arc.mct.services.component.ViewInfo;
+import gov.nasa.arc.mct.services.component.ViewType;
+
+import java.util.Set;
/**
* This interface extends the ComponentRegistry interface to provide additional
@@ -60,9 +61,9 @@
* For instance, this can be used to obtain an Icon
* for a specific component or view class.
*
- * @param objectClass the type with which the asset is associated
+ * @param objectType the type with which the asset is associated
* @param assetClass the type of the desired asset
* @return an asset of the desired type (or null if none is available)
*/
- public <T> T getAsset(Class<?> objectClass, Class<T> assetClass);
+ public <T> T getAsset(TypeInfo<?> objectType, Class<T> assetClass);
}
@@ -27,6 +27,7 @@
import gov.nasa.arc.mct.gui.housing.Inspector;
import gov.nasa.arc.mct.gui.housing.MCTDirectoryArea;
import gov.nasa.arc.mct.services.component.AbstractComponentProvider;
+import gov.nasa.arc.mct.services.component.TypeInfo;
import gov.nasa.arc.mct.services.component.ViewInfo;
import gov.nasa.arc.mct.services.component.ViewType;
import gov.nasa.arc.mct.util.MCTIcons;
@@ -71,16 +72,16 @@ public DefaultViewProvider() {
}
@Override
- public <T> T getAsset(Class<?> type, Class<T> assetClass) {
+ public <T> T getAsset(TypeInfo<?> type, Class<T> assetClass) {
if (assetClass.isAssignableFrom(ImageIcon.class)) {
int sz = 16;
- if (View.class.isAssignableFrom(type)) {
+ if (View.class.isAssignableFrom(type.getTypeClass())) {
sz = 9;
- } else if (AbstractComponent.class.isAssignableFrom(type)) {
+ } else if (AbstractComponent.class.isAssignableFrom(type.getTypeClass())) {
sz = 14;
}
return assetClass.cast(MCTIcons.generateIcon(
- type.getName().hashCode(),
+ type.getTypeClass().getName().hashCode(),
sz, Color.ORANGE));
}
return super.getAsset(type, assetClass);
Oops, something went wrong.

0 comments on commit bf0432b

Please sign in to comment.