Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use NetworkImageFactory service to create network images. #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<properties>
<bundle.symbolicName>org.cytoscape.mcode</bundle.symbolicName>
<bundle.namespace>ca.utoronto.tdccbr.mcode.internal</bundle.namespace>
<cytoscape.api.version>3.8.0</cytoscape.api.version>
<cytoscape.impl.version>3.8.0</cytoscape.impl.version>
<cytoscape.api.version>3.9.0-SNAPSHOT</cytoscape.api.version>
<cytoscape.impl.version>3.9.0-SNAPSHOT</cytoscape.impl.version>
<maven.build.timestamp.format>MMMM yyyy</maven.build.timestamp.format>
<buildDate>${maven.build.timestamp}</buildDate>
</properties>
Expand Down
14 changes: 2 additions & 12 deletions src/main/java/ca/utoronto/tdccbr/mcode/internal/CyActivator.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
package ca.utoronto.tdccbr.mcode.internal;

import static org.cytoscape.work.ServiceProperties.COMMAND;
import static org.cytoscape.work.ServiceProperties.COMMAND_DESCRIPTION;
import static org.cytoscape.work.ServiceProperties.COMMAND_EXAMPLE_JSON;
import static org.cytoscape.work.ServiceProperties.COMMAND_LONG_DESCRIPTION;
import static org.cytoscape.work.ServiceProperties.COMMAND_NAMESPACE;
import static org.cytoscape.work.ServiceProperties.COMMAND_SUPPORTS_JSON;
import static org.cytoscape.work.ServiceProperties.PREFERRED_MENU;
import static org.cytoscape.work.ServiceProperties.TITLE;
import static org.cytoscape.work.ServiceProperties.*;

import java.util.Properties;

Expand All @@ -29,7 +22,6 @@
import org.cytoscape.util.swing.FileUtil;
import org.cytoscape.view.model.CyNetworkViewFactory;
import org.cytoscape.view.model.CyNetworkViewManager;
import org.cytoscape.view.presentation.RenderingEngineFactory;
import org.cytoscape.view.vizmap.VisualMappingFunctionFactory;
import org.cytoscape.view.vizmap.VisualMappingManager;
import org.cytoscape.view.vizmap.VisualStyleFactory;
Expand Down Expand Up @@ -89,7 +81,6 @@ public class CyActivator extends AbstractCyActivator {
private MainPanelMediator mainPanelMediator;

@Override
@SuppressWarnings("unchecked")
public void start(BundleContext bc) {
registrar = getService(bc, CyServiceRegistrar.class);

Expand All @@ -101,7 +92,6 @@ public void start(BundleContext bc) {
var rootNetworkMgr = getService(bc, CyRootNetworkManager.class);

var swingApp = getService(bc, CySwingApplication.class);
var dingRenderingEngineFactory = getService(bc, RenderingEngineFactory.class, "(id=ding)");

var visualStyleFactory = getService(bc, VisualStyleFactory.class);
var visualMappingMgr = getService(bc, VisualMappingManager.class);
Expand All @@ -110,7 +100,7 @@ public void start(BundleContext bc) {

var fileUtil = getService(bc, FileUtil.class);

mcodeUtil = new MCODEUtil(dingRenderingEngineFactory, netViewFactory, rootNetworkMgr,
mcodeUtil = new MCODEUtil(netViewFactory, rootNetworkMgr,
appMgr, netMgr, netViewMgr, visualStyleFactory,
visualMappingMgr, swingApp, discreteMappingFactory,
continuousMappingFactory, fileUtil);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
package ca.utoronto.tdccbr.mcode.internal.util;

import static org.cytoscape.view.presentation.property.BasicVisualLexicon.EDGE_PAINT;
import static org.cytoscape.view.presentation.property.BasicVisualLexicon.EDGE_SELECTED_PAINT;
import static org.cytoscape.view.presentation.property.BasicVisualLexicon.EDGE_STROKE_SELECTED_PAINT;
import static org.cytoscape.view.presentation.property.BasicVisualLexicon.EDGE_STROKE_UNSELECTED_PAINT;
import static org.cytoscape.view.presentation.property.BasicVisualLexicon.EDGE_UNSELECTED_PAINT;
import static org.cytoscape.view.presentation.property.BasicVisualLexicon.EDGE_WIDTH;
import static org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_BORDER_WIDTH;
import static org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_FILL_COLOR;
import static org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_HEIGHT;
import static org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_PAINT;
import static org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_SHAPE;
import static org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_SIZE;
import static org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_WIDTH;
import static org.cytoscape.view.presentation.property.BasicVisualLexicon.*;

import java.awt.Color;
import java.awt.Font;
Expand All @@ -36,7 +24,6 @@
import java.util.Set;

import javax.swing.JOptionPane;
import javax.swing.JPanel;

import org.cytoscape.application.CyApplicationManager;
import org.cytoscape.application.NetworkViewRenderer;
Expand All @@ -56,8 +43,6 @@
import org.cytoscape.view.model.CyNetworkViewFactory;
import org.cytoscape.view.model.CyNetworkViewManager;
import org.cytoscape.view.model.VisualProperty;
import org.cytoscape.view.presentation.RenderingEngine;
import org.cytoscape.view.presentation.RenderingEngineFactory;
import org.cytoscape.view.presentation.property.BasicVisualLexicon;
import org.cytoscape.view.presentation.property.NodeShapeVisualProperty;
import org.cytoscape.view.presentation.property.values.NodeShape;
Expand Down Expand Up @@ -143,7 +128,7 @@ public class MCODEUtil {
private static final Color NODE_MIN_COLOR = Color.BLACK;
private static final Color NODE_MAX_COLOR = Color.RED;

private final RenderingEngineFactory<CyNetwork> renderingEngineFactory;
// private final RenderingEngineFactory<CyNetwork> renderingEngineFactory;
private final CyNetworkViewFactory networkViewFactory;
private final CyRootNetworkManager rootNetworkMgr;
private final CyApplicationManager applicationMgr;
Expand All @@ -169,7 +154,6 @@ public class MCODEUtil {
private static final Logger logger = LoggerFactory.getLogger(MCODEUtil.class);

public MCODEUtil(
RenderingEngineFactory<CyNetwork> renderingEngineFactory,
CyNetworkViewFactory networkViewFactory,
CyRootNetworkManager rootNetworkMgr,
CyApplicationManager applicationMgr,
Expand All @@ -182,7 +166,6 @@ public MCODEUtil(
VisualMappingFunctionFactory continuousMappingFactory,
FileUtil fileUtil
) {
this.renderingEngineFactory = renderingEngineFactory;
this.networkViewFactory = networkViewFactory;
this.rootNetworkMgr = rootNetworkMgr;
this.applicationMgr = applicationMgr;
Expand Down Expand Up @@ -365,9 +348,6 @@ public CyNetworkView createNetworkView(CyNetwork net, VisualStyle vs) {
return view;
}

public RenderingEngine<CyNetwork> createRenderingEngine(JPanel panel, CyNetworkView view) {
return renderingEngineFactory.createRenderingEngine(panel, view);
}

public void displayNetworkView(CyNetworkView view) {
networkMgr.addNetwork(view.getModel());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@
import static org.cytoscape.util.swing.LookAndFeelUtil.isMac;
import static org.cytoscape.util.swing.LookAndFeelUtil.makeSmall;
import static org.cytoscape.util.swing.LookAndFeelUtil.setDefaultOkCancelKeyStrokes;
import static org.cytoscape.view.presentation.property.BasicVisualLexicon.NETWORK_BACKGROUND_PAINT;
import static org.cytoscape.view.presentation.property.BasicVisualLexicon.NETWORK_HEIGHT;
import static org.cytoscape.view.presentation.property.BasicVisualLexicon.NETWORK_WIDTH;
import static org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_X_LOCATION;
import static org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_Y_LOCATION;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dialog.ModalityType;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
Expand All @@ -38,7 +35,6 @@
import javax.swing.JFrame;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JSlider;
import javax.swing.SwingUtilities;
Expand All @@ -62,6 +58,7 @@
import org.cytoscape.util.swing.IconManager;
import org.cytoscape.util.swing.TextIcon;
import org.cytoscape.view.model.CyNetworkViewManager;
import org.cytoscape.view.presentation.NetworkImageFactory;
import org.cytoscape.view.vizmap.VisualMappingManager;
import org.cytoscape.view.vizmap.VisualStyle;
import org.cytoscape.work.AbstractTask;
Expand Down Expand Up @@ -664,30 +661,15 @@ private void createClusterImage(MCODECluster cluster, MCODEResult res, VisualSty
layouter.doLayout();
}

invokeOnEDT(() -> {
try {
var panel = new JPanel();
var size = new Dimension(width, height);
panel.setPreferredSize(size);
panel.setSize(size);
panel.setMinimumSize(size);
panel.setMaximumSize(size);
panel.setBackground((Color) style.getDefaultValue(NETWORK_BACKGROUND_PAINT));

var re = mcodeUtil.createRenderingEngine(panel, clusterView);
style.apply(clusterView);
clusterView.updateView();
clusterView.fitContent();

if (!clusterView.getNodeViews().isEmpty())
cluster.setView(clusterView);

var image = re.createImage(width, height);
cluster.setImage(image);
} catch (Exception ex) {
logger.error("Cannot update cluster image.", ex);
}
});

style.apply(clusterView);

var networkImageFactory = registrar.getService(NetworkImageFactory.class);
var image = networkImageFactory.createImage(clusterView, width, height);

cluster.setView(clusterView);
cluster.setImage(image);

} catch (Exception ex) {
logger.error("Cannot create cluster image.", ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.cytoscape.util.swing.FileUtil;
import org.cytoscape.view.model.CyNetworkViewFactory;
import org.cytoscape.view.model.CyNetworkViewManager;
import org.cytoscape.view.presentation.RenderingEngineFactory;
import org.cytoscape.view.vizmap.VisualMappingFunctionFactory;
import org.cytoscape.view.vizmap.VisualMappingManager;
import org.cytoscape.view.vizmap.VisualStyleFactory;
Expand Down Expand Up @@ -74,7 +73,6 @@ public class MCODEAlgorithmTest extends AbstractMCODETest {

CyNetwork networkSmall;

@Mock RenderingEngineFactory<CyNetwork> rendererFactory;
@Mock CyRootNetworkManager rootNetMgr;
@Mock CyApplicationManager appMgr;
@Mock CyNetworkManager netMgr;
Expand All @@ -96,7 +94,7 @@ public void setUp() throws Exception {
rootNetMgr = netViewTestSupport.getRootNetworkFactory();
netViewFactory = netViewTestSupport.getNetworkViewFactory();

mcodeUtil = new MCODEUtil(rendererFactory, netViewFactory, rootNetMgr, appMgr, netMgr, netViewMgr,
mcodeUtil = new MCODEUtil(netViewFactory, rootNetMgr, appMgr, netMgr, netViewMgr,
styleFactory, vmMgr, swingApp, vmfFactory, vmfFactory, fileUtil);
resultsMgr = new MCODEResultsManager(mcodeUtil);
// networkSmall = Cytoscape.createNetworkFromFile("testData" + File.separator + "smallTest.sif");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.cytoscape.util.swing.FileUtil;
import org.cytoscape.view.model.CyNetworkViewFactory;
import org.cytoscape.view.model.CyNetworkViewManager;
import org.cytoscape.view.presentation.RenderingEngineFactory;
import org.cytoscape.view.vizmap.VisualMappingFunctionFactory;
import org.cytoscape.view.vizmap.VisualMappingManager;
import org.cytoscape.view.vizmap.VisualStyleFactory;
Expand Down Expand Up @@ -72,7 +71,6 @@
public class MCODEUtilTest extends AbstractMCODETest {

CyNetwork networkSmall;
@Mock RenderingEngineFactory<CyNetwork> rendererFactory;
@Mock CyRootNetworkManager rootNetMgr;
@Mock CyApplicationManager appMgr;
@Mock CyNetworkManager netMgr;
Expand All @@ -91,7 +89,7 @@ public void setUp() throws Exception {
rootNetMgr = netViewTestSupport.getRootNetworkFactory();
netViewFactory = netViewTestSupport.getNetworkViewFactory();

mcodeUtil = new MCODEUtil(rendererFactory, netViewFactory, rootNetMgr, appMgr, netMgr, netViewMgr,
mcodeUtil = new MCODEUtil(netViewFactory, rootNetMgr, appMgr, netMgr, netViewMgr,
styleFactory, vmMgr, swingApp, vmfFactory, vmfFactory, fileUtil);
resultsMgr = new MCODEResultsManager(mcodeUtil);
}
Expand Down