Skip to content

Commit

Permalink
added cytopanel and showresults panel
Browse files Browse the repository at this point in the history
  • Loading branch information
ermismd committed Sep 7, 2023
1 parent 1e06678 commit 2fd07e6
Show file tree
Hide file tree
Showing 9 changed files with 863 additions and 25 deletions.
31 changes: 31 additions & 0 deletions src/main/java/be/kuleuven/mgG/internal/model/MGGManager.java
Expand Up @@ -50,6 +50,7 @@
import org.cytoscape.session.events.SessionAboutToBeSavedListener;
import org.cytoscape.session.events.SessionLoadedEvent;
import org.cytoscape.session.events.SessionLoadedListener;
import org.cytoscape.view.model.CyNetworkView;
import org.cytoscape.work.SynchronousTaskManager;
import org.cytoscape.work.Task;
import org.cytoscape.work.TaskFactory;
Expand All @@ -74,6 +75,12 @@ public class MGGManager implements SessionAboutToBeSavedListener, SessionLoadedL
public final static String APP_NAME = "be.kuleuven.mgG";
public final static String SERVER_RESPONSE_FILE = "Response.json";

//-----------------------------------------------------------
final CommandExecutorTaskFactory commandExecutorTaskFactory;
final SynchronousTaskManager<?> synchronousTaskManager;
final TaskManager<?,?> dialogTaskManager;

//----------------------------------------------------------------
final TaskManager taskManager;
final SynchronousTaskManager syncTaskManager;

Expand Down Expand Up @@ -114,6 +121,9 @@ public MGGManager(final CyServiceRegistrar cyRegistrar) {
cyRegistrar.registerService(this, SessionAboutToBeSavedListener.class, new Properties());
cyRegistrar.registerService(this, SessionLoadedListener.class, new Properties());

synchronousTaskManager = cyRegistrar.getService(SynchronousTaskManager.class);
commandExecutorTaskFactory = cyRegistrar.getService(CommandExecutorTaskFactory.class);
dialogTaskManager = cyRegistrar.getService(TaskManager.class);
//MGGicon = new ImageIcon(getClass().getResource("/images/scNetViz.png"));

}
Expand Down Expand Up @@ -177,6 +187,27 @@ public CyNetwork getCurrentNetwork() {

//------------------------------------------------SErvice Register and execute Tasks-----------------------------------------------------------------------------------------------




public void executeCommand(String namespace, String command,
Map<String, Object> args, TaskObserver observer) {
TaskIterator ti = commandExecutorTaskFactory.createTaskIterator(namespace, command, args, observer);
execute(ti, true);
}

public void execute(TaskIterator iterator, boolean synchronous) {
if (synchronous) {
synchronousTaskManager.execute(iterator);
} else {
dialogTaskManager.execute(iterator);
}
}

public CyNetworkView getCurrentNetworkView() {
return cyRegistrar.getService(CyApplicationManager.class).getCurrentNetworkView();
}

/**
* Executes a set of tasks.
* This method is used to execute a set of tasks using the task manager.
Expand Down
16 changes: 9 additions & 7 deletions src/main/java/be/kuleuven/mgG/internal/tasks/ImportFileTask.java
Expand Up @@ -39,6 +39,7 @@
import be.kuleuven.mgG.internal.utils.CSVReader;
import be.kuleuven.mgG.internal.utils.HTTPUtils;
import be.kuleuven.mgG.internal.view.JSONDisplayPanel;
import be.kuleuven.mgG.internal.view.JsonResultPanel;



Expand Down Expand Up @@ -245,14 +246,15 @@ public void run(TaskMonitor taskMonitor) {


private void showDataInPanel(JSONObject jsonObject) {
JSONDisplayPanel panel = new JSONDisplayPanel(mggManager, jsonObject);

//JSONDisplayPanel panel = new JSONDisplayPanel(mggManager, jsonObject);
JsonResultPanel panel = new JsonResultPanel(mggManager, jsonObject);
mggManager.registerService(panel, CytoPanelComponent.class, new Properties());

JFrame frame = new JFrame("OTU/ASV Data");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.getContentPane().add(panel);
frame.pack();
frame.setVisible(true);
/*
* JFrame frame = new JFrame("OTU/ASV Data");
* frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
* frame.getContentPane().add(panel); frame.pack(); frame.setVisible(true);
*/
}


Expand Down
@@ -0,0 +1,72 @@
package be.kuleuven.mgG.internal.tasks;

import java.awt.Component;
import java.util.Properties;

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.RowsSetListener;
import org.cytoscape.work.AbstractTask;
import org.cytoscape.work.ProvidesTitle;
import org.cytoscape.work.TaskMonitor;

import be.kuleuven.mgG.internal.model.MGGManager;
import be.kuleuven.mgG.internal.view.MGGCytoPanel;



public class ShowResultsPanelTask extends AbstractTask {
final MGGManager manager;
final ShowResultsPanelTaskFactory factory;
final boolean show;

public ShowResultsPanelTask(final MGGManager manager,
final ShowResultsPanelTaskFactory factory, boolean show) {
this.manager = manager;
this.factory = factory;
this.show = show;
}

public void run(TaskMonitor monitor) {
monitor.setTitle("Show/hide results panel");

CySwingApplication swingApplication = manager.getService(CySwingApplication.class);
CytoPanel cytoPanel = swingApplication.getCytoPanel(CytoPanelName.EAST);

// If the panel is not already registered, create it
if (cytoPanel.indexOfComponent("be.kuleuven.mgG.internal.MGG") < 0) {
CytoPanelComponent2 panel = new MGGCytoPanel(manager);

// Register it
manager.registerService(panel, CytoPanelComponent.class, new Properties());

if (cytoPanel.getState() == CytoPanelState.HIDE)
cytoPanel.setState(CytoPanelState.DOCK);

} else {
int compIndex = cytoPanel.indexOfComponent("be.kuleuven.mgG.internal.MGG");
Component panel = cytoPanel.getComponentAt(compIndex);
if (panel instanceof CytoPanelComponent2) {
// Unregister it
manager.unregisterService(panel, CytoPanelComponent.class);
manager.setCytoPanel(null);
}
}

// factory.reregister();
}

public static boolean isPanelRegistered(MGGManager manager) {
CySwingApplication swingApplication = manager.getService(CySwingApplication.class);
CytoPanel cytoPanel = swingApplication.getCytoPanel(CytoPanelName.EAST);

if (cytoPanel.indexOfComponent("be.kuleuven.mgG.internal.MGG") >= 0)
return true;

return false;
}
}
@@ -0,0 +1,58 @@
package be.kuleuven.mgG.internal.tasks;

import java.util.Properties;

import static org.cytoscape.work.ServiceProperties.COMMAND;
import static org.cytoscape.work.ServiceProperties.COMMAND_DESCRIPTION;
import static org.cytoscape.work.ServiceProperties.COMMAND_NAMESPACE;
import static org.cytoscape.work.ServiceProperties.ENABLE_FOR;
import static org.cytoscape.work.ServiceProperties.INSERT_SEPARATOR_BEFORE;
import static org.cytoscape.work.ServiceProperties.IN_MENU_BAR;
import static org.cytoscape.work.ServiceProperties.MENU_GRAVITY;
import static org.cytoscape.work.ServiceProperties.PREFERRED_MENU;
import static org.cytoscape.work.ServiceProperties.TITLE;

import org.cytoscape.model.CyNetwork;
import org.cytoscape.view.model.CyNetworkView;
import org.cytoscape.work.AbstractTaskFactory;
import org.cytoscape.work.TaskFactory;
import org.cytoscape.work.TaskIterator;

import be.kuleuven.mgG.internal.model.MGGManager;


public class ShowResultsPanelTaskFactory extends AbstractTaskFactory {
final MGGManager manager;
boolean show = false;

public ShowResultsPanelTaskFactory(final MGGManager manager) {
this.manager = manager;
}

public TaskIterator createTaskIterator() {
return new TaskIterator(new ShowResultsPanelTask(manager, this, show));
}


public boolean isReady() {
// We always want to be able to shut it off
if (!show) return true;

CyNetwork net = manager.getCurrentNetwork();
if (net == null) return false;

//* Check for the existence of the 'flashweave-score' column in the edge table
boolean hasFlashweaveScore = net.getRow(net).get("flashweave-score",Double.class) != null;

// Implement other checks if necessary
// boolean hasIdColumn = net.getDefaultNodeTable().getColumn("@id") != null;
// boolean hasScoreColumn = net.getDefaultEdgeTable().getColumn("score") != null;

//* Return true if the column exists, otherwise return false
return hasFlashweaveScore;



}
}

133 changes: 133 additions & 0 deletions src/main/java/be/kuleuven/mgG/internal/view/AbstractMggPanel.java
@@ -0,0 +1,133 @@
package be.kuleuven.mgG.internal.view;



import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.JTextField;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import org.cytoscape.model.CyNetwork;
import org.cytoscape.util.swing.IconManager;
import org.cytoscape.util.swing.OpenBrowser;

import be.kuleuven.mgG.internal.model.MGGManager;



public abstract class AbstractMggPanel extends JPanel {

protected final MGGManager manager;
protected final OpenBrowser openBrowser;
protected final Font iconFont;
protected final Font labelFont;
protected final Font textFont;
protected CyNetwork currentNetwork;
protected Map<CyNetwork, Map<String,Map<String, Double>>> filters;

public AbstractMggPanel(final MGGManager manager) {
this.manager = manager;
this.openBrowser = manager.getService(OpenBrowser.class);
this.currentNetwork = manager.getCurrentNetwork();
IconManager iconManager = manager.getService(IconManager.class);
iconFont = iconManager.getIconFont(17.0f);
labelFont = new Font("SansSerif", Font.BOLD, 10);
textFont = new Font("SansSerif", Font.PLAIN, 10);
filters = new HashMap<>();
filters.put(currentNetwork, new HashMap<>());
}

abstract void doFilter(String type);

abstract void undoFilters();

abstract double initFilter(String type, String text);

protected JComponent createFilterSlider(String type, String text, CyNetwork network, boolean labels, double max) {
double value = 0.0;
if (filters.containsKey(network) &&
filters.get(network).containsKey(type) &&
filters.get(network).get(type).containsKey(text)) {
value = filters.get(network).get(type).get(text);
// System.out.println("value = "+value);
} else {
value = initFilter(type, text);
}
Box box = Box.createHorizontalBox();
if (labels) {
JLabel label = new JLabel(text);
label.setFont(labelFont);
label.setPreferredSize(new Dimension(100,20));
box.add(Box.createRigidArea(new Dimension(10,0)));
box.add(label);
box.add(Box.createHorizontalGlue());
}
JSlider slider;
slider = new JSlider(0,(int)max,(int)(value*100));
slider.setToolTipText("Filter ranges between 0.0 and " + max/100);
slider.setPreferredSize(new Dimension(150,20));
box.add(slider);
// box.add(Box.createHorizontalGlue());
JTextField textField;
textField = new JTextField(String.format("%.2f",value),4);
textField.setPreferredSize(new Dimension(30,20));
textField.setMaximumSize(new Dimension(30,20));
textField.setFont(textFont);
box.add(textField);
// Hook it up
addChangeListeners(type, text, slider, textField, max);
box.setAlignmentX(Component.LEFT_ALIGNMENT);
return box;
}

protected void addChangeListeners(String type, String label, JSlider slider,
JTextField textField, double max) {
slider.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
JSlider sl = (JSlider)e.getSource();
int value = sl.getValue();
double v = ((double)value)/100.0;
textField.setText(String.format("%.2f",v));
addFilter(type, label, v);
doFilter(type);
}
});

textField.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JTextField field = (JTextField)e.getSource();
String text = field.getText();
slider.setValue((int)(Double.parseDouble(text)*100.0));
}
});
}

protected void addFilter(String type, String label, double value) {
Map<String,Double> filter = filters.get(currentNetwork).get(type);
filter.put(label, value);

if (value == 0)
filter.remove(label);
}

protected void removeFilters(CyNetwork network) {
if (network != null && filters.containsKey(network))
filters.remove(network);
}

}

0 comments on commit 2fd07e6

Please sign in to comment.