diff --git a/pom.xml b/pom.xml index a9c8d5b..1dc50b6 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ org.nrnb.gsoc.enrichment 3.8.0 - 4.2.1 + 5.1.9 3.8.0 6.0.0 diff --git a/src/main/java/org/nrnb/gsoc/enrichment/CyActivator.java b/src/main/java/org/nrnb/gsoc/enrichment/CyActivator.java index c4dafd6..36e6129 100644 --- a/src/main/java/org/nrnb/gsoc/enrichment/CyActivator.java +++ b/src/main/java/org/nrnb/gsoc/enrichment/CyActivator.java @@ -1,5 +1,9 @@ package org.nrnb.gsoc.enrichment; +import java.util.Properties; + +import org.cytoscape.application.events.SetCurrentNetworkListener; +import org.cytoscape.application.swing.CyAction; import org.cytoscape.application.swing.CySwingApplication; import org.cytoscape.application.swing.CytoPanel; import org.cytoscape.application.swing.CytoPanelComponent; @@ -7,19 +11,17 @@ import org.cytoscape.application.swing.CytoPanelName; import org.cytoscape.application.swing.CytoPanelState; import org.cytoscape.model.events.NetworkAboutToBeDestroyedListener; -import org.cytoscape.application.events.SetCurrentNetworkListener; import org.cytoscape.model.events.SelectedNodesAndEdgesListener; import org.cytoscape.service.util.AbstractCyActivator; import org.cytoscape.service.util.CyServiceRegistrar; import org.cytoscape.session.events.SessionLoadedListener; import org.cytoscape.work.ServiceProperties; import org.cytoscape.work.TaskFactory; +import org.nrnb.gsoc.enrichment.actions.ShowAppTableAction; import org.nrnb.gsoc.enrichment.tasks.EnrichmentTaskFactory; import org.nrnb.gsoc.enrichment.ui.EnrichmentCytoPanel; import org.osgi.framework.BundleContext; -import java.util.Properties; - /** * @author ighosh98 * {@code CyActivator} is a class that is a starting point for OSGi bundles. @@ -52,6 +54,7 @@ public class CyActivator extends AbstractCyActivator { * environment. You use {@code BundleContext} to import services or ask OSGi * about the status of some service. */ + @Override public void start(BundleContext context) throws Exception { // Get the services we're going to want to use CyServiceRegistrar registrar = getService(context, CyServiceRegistrar.class); @@ -74,6 +77,9 @@ public void start(BundleContext context) throws Exception { registrar.registerService(enrichmentPanel, SetCurrentNetworkListener.class, new Properties()); //registrar.registerService(enrichmentPanel, SetCurrentNetworkListener.class, new Properties()); //registrar.registerService(enrichmentPanel, NetworkAddedListener.class, new Properties()); + + ShowAppTableAction showAppTableAction = new ShowAppTableAction(registrar); + registerService(context, showAppTableAction, CyAction.class); if (cytoPanel.getState() == CytoPanelState.HIDE) cytoPanel.setState(CytoPanelState.DOCK); diff --git a/src/main/java/org/nrnb/gsoc/enrichment/actions/ShowAppTableAction.java b/src/main/java/org/nrnb/gsoc/enrichment/actions/ShowAppTableAction.java new file mode 100644 index 0000000..d46c0d6 --- /dev/null +++ b/src/main/java/org/nrnb/gsoc/enrichment/actions/ShowAppTableAction.java @@ -0,0 +1,46 @@ +package org.nrnb.gsoc.enrichment.actions; + +import static org.nrnb.gsoc.enrichment.utils.IconUtil.APP_ICON_COLORS; +import static org.nrnb.gsoc.enrichment.utils.IconUtil.APP_ICON_LAYERS; + +import java.awt.event.ActionEvent; + +import org.cytoscape.application.swing.AbstractCyAction; +import org.cytoscape.application.swing.CySwingApplication; +import org.cytoscape.application.swing.CytoPanelName; +import org.cytoscape.application.swing.CytoPanelState; +import org.cytoscape.service.util.CyServiceRegistrar; +import org.cytoscape.util.swing.TextIcon; +import org.nrnb.gsoc.enrichment.utils.IconUtil; + +@SuppressWarnings("serial") +public class ShowAppTableAction extends AbstractCyAction { + + private final CyServiceRegistrar serviceRegistrar; + + public ShowAppTableAction(CyServiceRegistrar serviceRegistrar) { + super("Enrichment Table"); + this.serviceRegistrar = serviceRegistrar; + + inToolBar = true; + insertToolbarSeparatorBefore = true; + toolbarGravity = 11.0f; + + var iconFont = IconUtil.getIconFont(30.0f); + var icon = new TextIcon(APP_ICON_LAYERS, iconFont, APP_ICON_COLORS, 32, 32, 1); + + putValue(SHORT_DESCRIPTION, "Show Enrichment Table"); // Tooltip's short description + putValue(LARGE_ICON_KEY, icon); + } + + @Override + public void actionPerformed(ActionEvent e) { + var swingApp = serviceRegistrar.getService(CySwingApplication.class); + var cytoPanel = swingApp.getCytoPanel(CytoPanelName.SOUTH); + + if (cytoPanel.getState() == CytoPanelState.HIDE) + cytoPanel.setState(CytoPanelState.DOCK); + + cytoPanel.setSelectedIndex(cytoPanel.indexOfComponent("org.nrnb.gsoc.enrichment")); + } +} diff --git a/src/main/java/org/nrnb/gsoc/enrichment/ui/EnrichmentCytoPanel.java b/src/main/java/org/nrnb/gsoc/enrichment/ui/EnrichmentCytoPanel.java index 93a2a57..726f932 100644 --- a/src/main/java/org/nrnb/gsoc/enrichment/ui/EnrichmentCytoPanel.java +++ b/src/main/java/org/nrnb/gsoc/enrichment/ui/EnrichmentCytoPanel.java @@ -30,6 +30,7 @@ import org.nrnb.gsoc.enrichment.utils.ModelUtils; import org.cytoscape.application.swing.CytoPanelState; import org.cytoscape.property.CyProperty; +import org.nrnb.gsoc.enrichment.utils.IconUtil; import org.nrnb.gsoc.enrichment.utils.SessionUtils; import org.nrnb.gsoc.enrichment.utils.ViewUtils; @@ -177,8 +178,8 @@ public String getTitle() { @Override public Icon getIcon() { if (icon == null) { - var font = registrar.getService(IconManager.class).getIconFont(14.0f); - icon = new TextIcon(IconManager.ICON_REFRESH, font, 16, 16); + var font = IconUtil.getIconFont(14.0f); + icon = new TextIcon(IconUtil.APP_LOGO_MONO, font, 16, 16); } return icon; diff --git a/src/main/java/org/nrnb/gsoc/enrichment/utils/IconUtil.java b/src/main/java/org/nrnb/gsoc/enrichment/utils/IconUtil.java new file mode 100644 index 0000000..37dcd7b --- /dev/null +++ b/src/main/java/org/nrnb/gsoc/enrichment/utils/IconUtil.java @@ -0,0 +1,45 @@ +package org.nrnb.gsoc.enrichment.utils; + +import java.awt.Color; +import java.awt.Font; +import java.awt.FontFormatException; +import java.io.IOException; + +public abstract class IconUtil { + + public static final String APP_LOGO_MONO = "a"; + public static final String APP_LOGO_LAYER_1 = "b"; + public static final String APP_LOGO_LAYER_2 = "c"; + public static final String APP_LOGO_LAYER_3 = "d"; + + public static final String[] APP_ICON_LAYERS = new String[] { + APP_LOGO_LAYER_1, + APP_LOGO_LAYER_2, + APP_LOGO_LAYER_3 + }; + public static final Color[] APP_ICON_COLORS = new Color[] { + new Color(5, 62, 96), + Color.WHITE, + new Color(56, 120, 158) + }; + + private static Font iconFont; + + static { + try { + iconFont = Font.createFont(Font.TRUETYPE_FONT, IconUtil.class.getResourceAsStream("/fonts/enrichmenttable.ttf")); + } catch (FontFormatException e) { + throw new RuntimeException(); + } catch (IOException e) { + throw new RuntimeException(); + } + } + + public static Font getIconFont(float size) { + return iconFont.deriveFont(size); + } + + private IconUtil() { + // ... + } +} diff --git a/src/main/resources/fonts/enrichmenttable.ttf b/src/main/resources/fonts/enrichmenttable.ttf new file mode 100644 index 0000000..2270e41 Binary files /dev/null and b/src/main/resources/fonts/enrichmenttable.ttf differ diff --git a/src/main/resources/images/enrichment-table.png b/src/main/resources/images/enrichment-table.png deleted file mode 100644 index f027b34..0000000 Binary files a/src/main/resources/images/enrichment-table.png and /dev/null differ