Skip to content

Commit

Permalink
New app logo and adds the app icon to Cytoscape's toolbar.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrtannus committed Mar 18, 2024
1 parent af08d98 commit 4952496
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<properties>
<bundle.namespace>org.nrnb.gsoc.enrichment</bundle.namespace>
<cytoscape.api.version>3.8.0</cytoscape.api.version>
<maven-bundle-plugin.version>4.2.1</maven-bundle-plugin.version>
<maven-bundle-plugin.version>5.1.9</maven-bundle-plugin.version>
<maven-compiler-plugin.version>3.8.0</maven-compiler-plugin.version>
<osgi.api.version>6.0.0</osgi.api.version>
</properties>
Expand Down
12 changes: 9 additions & 3 deletions src/main/java/org/nrnb/gsoc/enrichment/CyActivator.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
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;
import org.cytoscape.application.swing.CytoPanelComponent2;
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.
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
45 changes: 45 additions & 0 deletions src/main/java/org/nrnb/gsoc/enrichment/utils/IconUtil.java
Original file line number Diff line number Diff line change
@@ -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() {
// ...
}
}
Binary file added src/main/resources/fonts/enrichmenttable.ttf
Binary file not shown.
Binary file removed src/main/resources/images/enrichment-table.png
Binary file not shown.

0 comments on commit 4952496

Please sign in to comment.