Skip to content

Commit

Permalink
Merge pull request #184 from VWoeltjen/icons
Browse files Browse the repository at this point in the history
[Icons] Refactor icon support, implement variant processing
  • Loading branch information
harleigh committed Sep 19, 2013
2 parents 5ed7b1b + 211691b commit 0f6cd60
Show file tree
Hide file tree
Showing 53 changed files with 1,824 additions and 547 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ViewInfo> 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<MenuItemInfo> getMenuItemInfos() {
Expand Down Expand Up @@ -201,5 +204,14 @@ public Collection<PolicyInfo> getPolicyInfos() {
@Override
public Collection<ViewInfo> getViews(String componentTypeId) {
return VIEW_INFOS;
}

@Override
public <T> T getAsset(TypeInfo<?> typeInfo, Class<T> assetClass) {
if (assetClass.isAssignableFrom(ImageIcon.class) &&
typeInfo.getTypeClass().equals(CanvasManifestation.class)) {
return assetClass.cast(ICON);
}
return super.getAsset(typeInfo, assetClass);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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
Expand All @@ -60,5 +63,14 @@ public Collection<ComponentTypeInfo> getComponentTypes() {
@Override
public Collection<ViewInfo> getViews(String componentTypeId) {
return Collections.<ViewInfo>emptyList();
}
}

@Override
public <T> T getAsset(TypeInfo<?> typeInfo, Class<T> assetClass) {
if (assetClass.isAssignableFrom(ImageIcon.class) &&
typeInfo.getTypeClass().equals(CollectionComponent.class)) {
return assetClass.cast(ICON);
}
return super.getAsset(typeInfo, assetClass);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
});
Expand Down Expand Up @@ -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<List<ComponentInfo>, Void> {
private AtomicInteger total = new AtomicInteger();
Expand Down Expand Up @@ -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<View> getSelectedManifestations() {
Object[] selectedValues = list.getSelectedValues();
Expand Down
Loading

0 comments on commit 0f6cd60

Please sign in to comment.