Skip to content

Commit

Permalink
[Icons] Fix icon coloration
Browse files Browse the repository at this point in the history
  • Loading branch information
VWoeltjen committed Sep 11, 2013
1 parent ade08df commit 5051429
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
*/
public class TransferableIcon extends JLabel {
private static final long serialVersionUID = -7380332900682920418L;
private static final Color ICON_COLOR = new Color(230,230,230);
private static final Color ICON_COLOR = new Color(130,130,130);


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -713,11 +713,14 @@ public final <T> T getCapability(Class<T> capability) {
if (typeInfo == null) {
for (ComponentTypeInfo info :
ExternalComponentRegistryImpl.getInstance().getComponentInfos()) {
if (info != null) {
if (info != null && info.getComponentClass().equals(getClass())) {
typeInfo = info;
break;
}
}
if (typeInfo == null) {
typeInfo = new ComponentTypeInfo(getClass().getSimpleName(), getClass().getSimpleName(), getClass());
}
}
return capability.cast(typeInfo);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ public static class ExtendedComponentTypeInfo extends ComponentTypeInfo {
* @param bundleSymName the OSGi bundle symbolic name
*/
public ExtendedComponentTypeInfo(ComponentTypeInfo info, String bundleSymName) {
super(info.getDisplayName(), info.getShortDescription(), info.getComponentClass(), info.getId(), info.isCreatable(), info.getWizardUI(), info.getIcon());
super(info.getDisplayName(), info.getShortDescription(), info.getComponentClass(), info.getId(), info.isCreatable());
assert bundleSymName != null: "bundleSymbolicName should not be null";
symbolicName = bundleSymName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@
package gov.nasa.arc.mct.services.component;

import gov.nasa.arc.mct.components.AbstractComponent;
import gov.nasa.arc.mct.util.MCTIcons;

import java.awt.Color;

import javax.swing.ImageIcon;

/**
* This class describes an component type. This description is used in the platform to create new component type
Expand All @@ -35,15 +31,11 @@
*
*/
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 String componentTypeId;
private final boolean isCreatable;
private final CreateWizardUI wizard;
private final ImageIcon icon;

/**
* Creates new ComponentTypeInfo representing a unique component type.
Expand All @@ -52,7 +44,7 @@ public class ComponentTypeInfo extends TypeInfo<AbstractComponent> {
* @param componentClass non null component class, this class must provide the required no-argument constructor
*/
public ComponentTypeInfo(String displayName, String description, Class<? extends AbstractComponent> componentClass) {
this(displayName,description,componentClass, componentClass.getName(), true, null, null);
this(displayName,description,componentClass, componentClass.getName(), true);
}

/**
Expand All @@ -63,7 +55,7 @@ public ComponentTypeInfo(String displayName, String description, Class<? extends
* @param isCreatable indicates if this component type is creatable under the Create menu.
*/
public ComponentTypeInfo(String displayName, String description, Class<? extends AbstractComponent> componentClass, boolean isCreatable) {
this(displayName,description,componentClass, componentClass.getName(), isCreatable, null, null);
this(displayName,description,componentClass, componentClass.getName(), isCreatable);
}

/**
Expand All @@ -72,10 +64,12 @@ public ComponentTypeInfo(String displayName, String description, Class<? extends
* @param description human readable string describing the component type
* @param componentClass non null component class, this class must have a no argument constructor
* @param isCreatable indicates if this component type is creatable under the Create menu.
* @param icon the icon that represents this component type
*/
public ComponentTypeInfo(String displayName, String description, Class<? extends AbstractComponent> componentClass, boolean isCreatable, ImageIcon icon) {
this(displayName,description,componentClass, componentClass.getName(), isCreatable, null, icon);
* @param icon the icon that represents this component type
* @deprecated icon and wizard now specified using ComponentProvider.getAsset
*/
@Deprecated
public ComponentTypeInfo(String displayName, String description, Class<? extends AbstractComponent> componentClass, boolean isCreatable, javax.swing.ImageIcon icon) {
this(displayName,description,componentClass, componentClass.getName(), isCreatable);
}


Expand All @@ -84,10 +78,12 @@ public ComponentTypeInfo(String displayName, String description, Class<? extends
* @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
* @param wizard creates the panel to be displayed for the dialog box
*/
* @param wizard creates the panel to be displayed for the dialog box
* @deprecated icon and wizard now specified using ComponentProvider.getAsset
*/
@Deprecated
public ComponentTypeInfo(String displayName, String description, Class<? extends AbstractComponent> componentClass, CreateWizardUI wizard){
this(displayName,description,componentClass,componentClass.getName(), true, wizard, null);
this(displayName,description,componentClass,componentClass.getName(), true);
}

/**
Expand All @@ -97,10 +93,41 @@ public ComponentTypeInfo(String displayName, String description, Class<? extends
* @param componentClass non null component class
* @param wizard creates the panel to be displayed for the dialog box
* @param icon the icon that represents this component type
*/
public ComponentTypeInfo(String displayName, String description, Class<? extends AbstractComponent> componentClass, CreateWizardUI wizard, ImageIcon icon){
this(displayName,description,componentClass,componentClass.getName(), true, wizard, icon);
* @deprecated icon and wizard now specified using ComponentProvider.getAsset
*/
@Deprecated
public ComponentTypeInfo(String displayName, String description, Class<? extends AbstractComponent> componentClass, CreateWizardUI wizard, javax.swing.ImageIcon icon){
this(displayName,description,componentClass,componentClass.getName(), true);
}

/**
* Creates a new ComponentTypeInfo representing a unique component type.
* @param displayName non null human readable name for the component type
* @param description human readable string describing the component type
* @param componentClass non null component class, this class must have a no argument constructor
* @param id globally unique identifier (across all modules) identifying this component.
* @param isCreatable indicates if this component type can be created from the Create menu.
* @throws IllegalArgumentException if componentClass, id, or displayName is null or if component class does not meet the requirements of
* <code>AbstractComponent</code>
*/
protected ComponentTypeInfo(String displayName, String description, Class<? extends AbstractComponent> componentClass, String id, boolean isCreatable) {
super(componentClass);
if (componentClass == null) {
throw new IllegalArgumentException("componentClass must not be null");
}
AbstractComponent.checkBaseComponentRequirements(componentClass);

if (id == null) {
throw new IllegalArgumentException("id must not be null");
}
if (displayName == null) {
throw new IllegalArgumentException("displayName must not be null");
}
this.displayName = displayName;
this.description = description;
this.componentTypeId = id;
this.isCreatable = isCreatable;
}

/**
* Creates a new ComponentTypeInfo representing a unique component type.
Expand All @@ -113,30 +140,11 @@ public ComponentTypeInfo(String displayName, String description, Class<? extends
* @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
* <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");
}
AbstractComponent.checkBaseComponentRequirements(componentClass);

if (id == null) {
throw new IllegalArgumentException("id must not be null");
}
if (displayName == null) {
throw new IllegalArgumentException("displayName must not be null");
}
this.displayName = displayName;
this.description = description;
this.componentTypeId = id;
this.isCreatable = isCreatable;
this.wizard = wizard;
this.icon = MCTIcons.processIcon(
icon != null ? icon :
MCTIcons.generateIcon(
componentClass.getName().hashCode(),
ICON_SIZE, BASE_ICON_COLOR));
* @deprecated icon and wizard now specified using ComponentProvider.getAsset
*/
@Deprecated
protected ComponentTypeInfo(String displayName, String description, Class<? extends AbstractComponent> componentClass, String id, boolean isCreatable, CreateWizardUI wizard, javax.swing.ImageIcon icon) throws IllegalArgumentException {
this(displayName, description, componentClass, id, isCreatable);
}


Expand Down Expand Up @@ -201,8 +209,8 @@ public final CreateWizardUI getWizardUI() {
* @deprecated use getAsset(ImageIcon.class) instead
*/
@Deprecated
public final ImageIcon getIcon() {
return getAsset(ImageIcon.class);
public final javax.swing.ImageIcon getIcon() {
return getAsset(javax.swing.ImageIcon.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public <T> T getAsset(TypeInfo<?> type, Class<T> assetClass) {
}
return assetClass.cast(MCTIcons.generateIcon(
type.getTypeClass().getName().hashCode(),
sz, Color.ORANGE));
sz, Color.WHITE));
}
return super.getAsset(type, assetClass);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import gov.nasa.arc.mct.util.MCTIcons;
import gov.nasa.arc.mct.util.internal.ElapsedTimer;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.beans.PropertyChangeListener;
Expand Down Expand Up @@ -104,7 +105,7 @@ public NodeViewManifestation(AbstractComponent component, ViewInfo viewinfo) {

private ImageIcon getIcon(AbstractComponent ac) {
ImageIcon baseIcon = ac.getAsset(ImageIcon.class);
return MCTIcons.processIcon(baseIcon, 1f, 0.25f, 1f, true);
return MCTIcons.processIcon(baseIcon, new Color(101, 131, 192), false);
}

private void doLockRendering(JLabel widget, AbstractComponent comp) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,40 @@
*******************************************************************************/
package gov.nasa.arc.mct.gui.menu;

import gov.nasa.arc.mct.components.AbstractComponent;
import gov.nasa.arc.mct.gui.ActionContext;
import gov.nasa.arc.mct.gui.CompositeAction;
import gov.nasa.arc.mct.gui.MCTMutableTreeNode;
import gov.nasa.arc.mct.gui.View;
import gov.nasa.arc.mct.gui.dialogs.DefaultWizardUI;
import gov.nasa.arc.mct.gui.dialogs.NewObjectDialog;
import gov.nasa.arc.mct.gui.housing.MCTDirectoryArea;
import gov.nasa.arc.mct.components.AbstractComponent;
import gov.nasa.arc.mct.gui.ActionContext;
import gov.nasa.arc.mct.gui.CompositeAction;
import gov.nasa.arc.mct.gui.MCTMutableTreeNode;
import gov.nasa.arc.mct.gui.View;
import gov.nasa.arc.mct.gui.dialogs.DefaultWizardUI;
import gov.nasa.arc.mct.gui.dialogs.NewObjectDialog;
import gov.nasa.arc.mct.gui.housing.MCTDirectoryArea;
import gov.nasa.arc.mct.gui.impl.ActionContextImpl;
import gov.nasa.arc.mct.policy.PolicyContext;
import gov.nasa.arc.mct.policy.PolicyInfo;
import gov.nasa.arc.mct.policymgr.PolicyManagerImpl;
import gov.nasa.arc.mct.registry.ExternalComponentRegistryImpl;
import gov.nasa.arc.mct.registry.ExternalComponentRegistryImpl.ExtendedComponentTypeInfo;
import gov.nasa.arc.mct.registry.ExternalComponentRegistryImpl;
import gov.nasa.arc.mct.registry.ExternalComponentRegistryImpl.ExtendedComponentTypeInfo;
import gov.nasa.arc.mct.roles.events.PropertyChangeEvent;
import gov.nasa.arc.mct.services.component.CreateWizardUI;
import gov.nasa.arc.mct.util.logging.MCTLogger;

import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.Collection;
import gov.nasa.arc.mct.services.component.ComponentTypeInfo;
import gov.nasa.arc.mct.services.component.CreateWizardUI;
import gov.nasa.arc.mct.util.MCTIcons;
import gov.nasa.arc.mct.util.logging.MCTLogger;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.ImageIcon;
import javax.swing.JTree;
import javax.swing.event.TreeExpansionEvent;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;
import java.util.List;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.ImageIcon;
import javax.swing.JTree;
import javax.swing.event.TreeExpansionEvent;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;

@SuppressWarnings("serial")
public class NewObjectAction extends CompositeAction {
Expand Down Expand Up @@ -82,7 +85,7 @@ public boolean canHandle(ActionContext context) {
AbstractComponent tempComponent = extCompRegistry.newInstance(info);
policyContext.setProperty(PolicyContext.PropertyName.SOURCE_COMPONENTS.getName(), Collections.singleton(tempComponent));
if (PolicyManagerImpl.getInstance().execute(compositionKey, policyContext).getStatus()) {
subActions.add(new NewTypeAction(info.getDisplayName(), info.getComponentClass(), targetComponent, info.getWizardUI(), info.getIcon()));
subActions.add(new NewTypeAction(info, targetComponent));
}
}
}
Expand All @@ -100,13 +103,12 @@ private class NewTypeAction extends AbstractAction {
private AbstractComponent targetComponent;
private CreateWizardUI wizardUI;

public NewTypeAction(String componentDisplayName, Class<? extends AbstractComponent> componentClass,
AbstractComponent targetComponent, CreateWizardUI wizard, ImageIcon icon) {
putValue(Action.NAME, componentDisplayName);
putValue(Action.SMALL_ICON, icon);
this.componentClass = componentClass;
public NewTypeAction(ComponentTypeInfo info, AbstractComponent targetComponent) {
putValue(Action.NAME, info.getDisplayName());
putValue(Action.SMALL_ICON, MCTIcons.processIcon(info.getAsset(ImageIcon.class), new Color(40,40,40), false));
this.componentClass = info.getTypeClass();
this.targetComponent = targetComponent;
this.wizardUI = wizard;
this.wizardUI = info.getAsset(CreateWizardUI.class);
if (wizardUI == null){
wizardUI = new DefaultWizardUI(this.componentClass);
}
Expand Down
8 changes: 5 additions & 3 deletions util/src/main/java/gov/nasa/arc/mct/util/MCTIcons.java
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ private static ImageIcon doProcessing(ProcessDescription pd) {
BufferedImage bufferedImage = new BufferedImage(
pd.icon.getIconWidth() + 2,
pd.icon.getIconHeight() + 2,
BufferedImage.TYPE_4BYTE_ABGR);
BufferedImage.TYPE_INT_ARGB);

if (pd.dropShadow) {
// Color rescale for shadowing
Expand Down Expand Up @@ -301,10 +301,12 @@ private static ImageIcon doProcessing(ProcessDescription pd) {
// Convert color to scaling factor
int rgb = pd.firstColor.getRGB();
float coloration[] = new float[4];
for (int i = 0; i < coloration.length; i++) {
coloration[i] = (float) (rgb & 0xFF) / 255f;
for (int i = 0; i < 3; i++) {
coloration[2-i] = (float) (rgb & 0xFF) / 255f;
rgb >>>= 8;
}
coloration[3] = 1f; // Always full alpha

float offset[] = {0f,0f,0f,0f};

// Repaint original icon & colorize
Expand Down

0 comments on commit 5051429

Please sign in to comment.