diff --git a/mctcore/src/main/java/gov/nasa/arc/mct/services/component/ViewInfo.java b/mctcore/src/main/java/gov/nasa/arc/mct/services/component/ViewInfo.java index 160c776e..1929e31c 100644 --- a/mctcore/src/main/java/gov/nasa/arc/mct/services/component/ViewInfo.java +++ b/mctcore/src/main/java/gov/nasa/arc/mct/services/component/ViewInfo.java @@ -24,29 +24,20 @@ import gov.nasa.arc.mct.components.AbstractComponent; import gov.nasa.arc.mct.gui.View; import gov.nasa.arc.mct.util.LookAndFeelSettings; -import gov.nasa.arc.mct.util.MCTIcons; -import java.awt.Color; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.util.concurrent.Callable; -import javax.swing.ImageIcon; - /** * The ViewInfo class describes metadata about a view. This class is used to create new view instances. * */ public class ViewInfo extends TypeInfo { - private static final int ICON_SIZE = 9; - private static final Color BASE_ICON_COLOR = Color.WHITE; - private final Constructor viewConstructor; private final String type; private final String viewName; private final ViewType viewType; - private final ImageIcon icon; - private final ImageIcon selectedIcon; private final boolean shouldExpandCenterPaneInWindow; private final Class preferredComponentType; @@ -90,8 +81,10 @@ public ViewInfo(Class aViewClass, String name, String aType, Vie * @param viewType for this view * @param icon to be placed in a button for this view. This icon is typically used for drop-down showing in the inspector. * @throws IllegalArgumentException if the view type is null or the class doesn't have the right type of constructor + * @deprecated icons are now exposed using ComponentProvider.getAsset */ - public ViewInfo(Class aViewClass, String name, ViewType viewType, ImageIcon icon) throws IllegalArgumentException { + @Deprecated + public ViewInfo(Class aViewClass, String name, ViewType viewType, javax.swing.ImageIcon icon) throws IllegalArgumentException { this(aViewClass, name, aViewClass.getName(), viewType, icon, icon, false, null); } @@ -104,8 +97,10 @@ public ViewInfo(Class aViewClass, String name, ViewType viewType * @param viewType for this view * @param icon to be placed in a button for this view. This icon is typically used for drop-down showing in the inspector. * @throws IllegalArgumentException if the view type is null or the class doesn't have the right type of constructor + * @deprecated icons are now exposed using ComponentProvider.getAsset */ - public ViewInfo(Class aViewClass, String name, String aType, ViewType viewType, ImageIcon icon) throws IllegalArgumentException { + @Deprecated + public ViewInfo(Class aViewClass, String name, String aType, ViewType viewType, javax.swing.ImageIcon icon) throws IllegalArgumentException { this(aViewClass, name, aType, viewType, icon, icon, false, null); } @@ -121,11 +116,45 @@ public ViewInfo(Class aViewClass, String name, String aType, Vie * @param icon to be placed in a button for this view. This icon is typically used for button showing in the inspector. * @param selectedIcon icon to be placed in a button for this view. This icon is typically used for button showing in the inspector when the button is selected. * @throws IllegalArgumentException if the view type is null or the class doesn't have the right type of constructor + * @deprecated icons are now exposed using ComponentProvider.getAsset */ - public ViewInfo(Class aViewClass, String name, String aType, ViewType viewType, ImageIcon icon, ImageIcon selectedIcon) throws IllegalArgumentException { + @Deprecated + public ViewInfo(Class aViewClass, String name, String aType, ViewType viewType, javax.swing.ImageIcon icon, javax.swing.ImageIcon selectedIcon) throws IllegalArgumentException { this(aViewClass, name, aType, viewType, icon, selectedIcon, false, null); } - + + /** + * Creates a new instance of ViewInfo. This constructor should only be used when + * attempting to provide backward compatibility for views which have already been serialized. The + * serialized mapping uses the type to determine how to map the state to a view type. + * @param aViewClass representing a view. + * @param name human readable name of the view + * @param aType representing the type used when serializing the view state. The type must be unique across all serialized view + * states so the default type used is the fully qualified class name. + * @param viewType for this view + * @param shouldExpandCenterPaneInWindow indicates whether this view requires expanding the center pane (i.g., hiding both the list and inspector panes) when viewed in a window. + * @param preferredComponentType specifies the component type where this view is the preferred view; null means this view can be attached to any component type in the registry. + * @throws IllegalArgumentException if the view type is null or the class doesn't have the right type of constructor + */ + public ViewInfo(Class aViewClass, String name, String aType, ViewType viewType, boolean shouldExpandCenterPaneInWindow, Class preferredComponentType) throws IllegalArgumentException { + super(aViewClass); + type = aType; + viewName = name; + if (name == null) { + throw new IllegalArgumentException("name must be specified for " + aViewClass); + } + if (viewType == null) { + throw new IllegalArgumentException("view type must be specified for " + name); + } + this.viewType = viewType; + viewConstructor = getConstructor(aViewClass); + if (viewConstructor == null) { + throw new IllegalArgumentException("a constructor must be defined that has AbstractComponent and ViewInfo as the parameters for " + aViewClass); + } + this.shouldExpandCenterPaneInWindow = shouldExpandCenterPaneInWindow; + this.preferredComponentType = preferredComponentType; + } + /** * Creates a new instance of ViewInfo. This constructor should only be used when * attempting to provide backward compatibility for views which have already been serialized. The @@ -139,31 +168,12 @@ public ViewInfo(Class aViewClass, String name, String aType, Vie * @param selectedIcon icon to be placed in a button for this view. This icon is typically used for button showing in the inspector when the button is selected. * @param shouldExpandCenterPaneInWindow indicates whether this view requires expanding the center pane (i.g., hiding both the list and inspector panes) when viewed in a window. * @param preferredComponentType specifies the component type where this view is the preferred view; null means this view can be attached to any component type in the registry. - * @throws IllegalArgumentException if the view type is null or the class doesn't have the right type of constructor - */ - public ViewInfo(Class aViewClass, String name, String aType, ViewType viewType, ImageIcon icon, ImageIcon selectedIcon, boolean shouldExpandCenterPaneInWindow, Class preferredComponentType) throws IllegalArgumentException { - super(aViewClass); - type = aType; - viewName = name; - this.icon = MCTIcons.processIcon( - icon != null ? icon : - MCTIcons.generateIcon( - aViewClass.getName().hashCode(), - ICON_SIZE, BASE_ICON_COLOR)); - this.selectedIcon = icon; - if (name == null) { - throw new IllegalArgumentException("name must be specified for " + aViewClass); - } - if (viewType == null) { - throw new IllegalArgumentException("view type must be specified for " + name); - } - this.viewType = viewType; - viewConstructor = getConstructor(aViewClass); - if (viewConstructor == null) { - throw new IllegalArgumentException("a constructor must be defined that has AbstractComponent and ViewInfo as the parameters for " + aViewClass); - } - this.shouldExpandCenterPaneInWindow = shouldExpandCenterPaneInWindow; - this.preferredComponentType = preferredComponentType; + * @throws IllegalArgumentException if the view type is null or the class doesn't have the right type of constructor + * @deprecated icons are now exposed using ComponentProvider.getAsset + */ + @Deprecated + public ViewInfo(Class aViewClass, String name, String aType, ViewType viewType, javax.swing.ImageIcon icon, javax.swing.ImageIcon selectedIcon, boolean shouldExpandCenterPaneInWindow, Class preferredComponentType) throws IllegalArgumentException { + this(aViewClass, name, aType, viewType, shouldExpandCenterPaneInWindow, preferredComponentType); } /** @@ -246,8 +256,8 @@ public View call() throws Exception { * @return icon; null if no provided */ @Deprecated - public ImageIcon getIcon() { - return icon; + public javax.swing.ImageIcon getIcon() { + return getAsset(javax.swing.ImageIcon.class); } /** @@ -256,8 +266,8 @@ public ImageIcon getIcon() { * @return an icon; null if not provided */ @Deprecated - public ImageIcon getSelectedIcon() { - return selectedIcon; + public javax.swing.ImageIcon getSelectedIcon() { + return getAsset(javax.swing.ImageIcon.class); } /** diff --git a/platform/src/main/java/gov/nasa/arc/mct/defaults/view/SwitcherView.java b/platform/src/main/java/gov/nasa/arc/mct/defaults/view/SwitcherView.java index 54adc85a..c8d4c2ba 100644 --- a/platform/src/main/java/gov/nasa/arc/mct/defaults/view/SwitcherView.java +++ b/platform/src/main/java/gov/nasa/arc/mct/defaults/view/SwitcherView.java @@ -26,6 +26,7 @@ import gov.nasa.arc.mct.gui.ViewProvider; import gov.nasa.arc.mct.services.component.ViewInfo; import gov.nasa.arc.mct.services.component.ViewType; +import gov.nasa.arc.mct.util.MCTIcons; import java.awt.Color; import java.awt.Component; @@ -40,6 +41,7 @@ import javax.swing.BorderFactory; import javax.swing.Icon; +import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JComponent; @@ -62,6 +64,7 @@ public class SwitcherView extends View { private JComboBox comboBox; private JLabel label; private static final float FONT_SIZE = 10f; + private static final Color ICON_COLOR = new Color(144,144,144); /** * The view info used to instantiate this view. @@ -89,7 +92,7 @@ public SwitcherView(AbstractComponent ac, ViewInfo vi) { } else if (viewInfos.length == 1) { // Otherwise, just show the one available view as a label label = new JLabel(); - label.setIcon(vi.getIcon()); + label.setIcon(getIcon(vi)); label.setText(vi.getViewName()); add(label); } else { @@ -133,13 +136,17 @@ private void resetSelection() { comboBox.addItemListener(itemListener); } if (label != null) { - label.setIcon(vi.getIcon()); + label.setIcon(getIcon(vi)); label.setText(vi.getViewName()); } } } } + private static ImageIcon getIcon(ViewInfo vi) { + return MCTIcons.processIcon(vi.getAsset(ImageIcon.class), ICON_COLOR, false); + } + private final ItemListener itemListener = new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { @@ -167,7 +174,7 @@ public Component getListCellRendererComponent(JList list, Object value, int inde label.setFont(label.getFont().deriveFont(FONT_SIZE)); if (value instanceof ViewInfo) { ViewInfo vi = (ViewInfo) value; - label.setIcon(vi.getIcon()); + label.setIcon(getIcon(vi)); label.setText(vi.getViewName()); } else { label.setIcon(null);