Skip to content

Commit

Permalink
[Icons] Deprecate ViewInfo icon methods
Browse files Browse the repository at this point in the history
Additionally, colorize icons in SwitcherView.
  • Loading branch information
VWoeltjen committed Sep 11, 2013
1 parent 5051429 commit ec0fd3a
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<View> {
private static final int ICON_SIZE = 9;
private static final Color BASE_ICON_COLOR = Color.WHITE;

private final Constructor<? extends View> 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<? extends AbstractComponent> preferredComponentType;

Expand Down Expand Up @@ -90,8 +81,10 @@ public ViewInfo(Class<? extends View> 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<? extends View> aViewClass, String name, ViewType viewType, ImageIcon icon) throws IllegalArgumentException {
@Deprecated
public ViewInfo(Class<? extends View> aViewClass, String name, ViewType viewType, javax.swing.ImageIcon icon) throws IllegalArgumentException {
this(aViewClass, name, aViewClass.getName(), viewType, icon, icon, false, null);
}

Expand All @@ -104,8 +97,10 @@ public ViewInfo(Class<? extends View> 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<? extends View> aViewClass, String name, String aType, ViewType viewType, ImageIcon icon) throws IllegalArgumentException {
@Deprecated
public ViewInfo(Class<? extends View> aViewClass, String name, String aType, ViewType viewType, javax.swing.ImageIcon icon) throws IllegalArgumentException {
this(aViewClass, name, aType, viewType, icon, icon, false, null);
}

Expand All @@ -121,11 +116,45 @@ public ViewInfo(Class<? extends View> 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<? extends View> aViewClass, String name, String aType, ViewType viewType, ImageIcon icon, ImageIcon selectedIcon) throws IllegalArgumentException {
@Deprecated
public ViewInfo(Class<? extends View> 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<? extends View> aViewClass, String name, String aType, ViewType viewType, boolean shouldExpandCenterPaneInWindow, Class<? extends AbstractComponent> 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
Expand All @@ -139,31 +168,12 @@ public ViewInfo(Class<? extends View> 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<? 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(
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<? extends View> aViewClass, String name, String aType, ViewType viewType, javax.swing.ImageIcon icon, javax.swing.ImageIcon selectedIcon, boolean shouldExpandCenterPaneInWindow, Class<? extends AbstractComponent> preferredComponentType) throws IllegalArgumentException {
this(aViewClass, name, aType, viewType, shouldExpandCenterPaneInWindow, preferredComponentType);
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit ec0fd3a

Please sign in to comment.