Skip to content

Commit

Permalink
fixes and changes
Browse files Browse the repository at this point in the history
  • Loading branch information
herme committed Feb 8, 2024
1 parent 5131b26 commit 5fa458a
Show file tree
Hide file tree
Showing 15 changed files with 297 additions and 207 deletions.
26 changes: 19 additions & 7 deletions src/main/java/be/kuleuven/mgG/internal/CyActivator.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import be.kuleuven.mgG.internal.tasks.AboutTaskFactory;
import be.kuleuven.mgG.internal.tasks.CheckAbudanceFileTaskFactory;
import be.kuleuven.mgG.internal.tasks.CheckMetaDataFileTaskFactory;
import be.kuleuven.mgG.internal.tasks.CheckNetworkTaskFactory;
Expand Down Expand Up @@ -106,7 +107,7 @@ public void start(BundleContext bc) {
props.setProperty(PREFERRED_MENU, "Apps.MGG.Import Data");
props.setProperty(IN_TOOL_BAR, "FALSE");
props.setProperty(IN_MENU_BAR, "TRUE");
props.setProperty(MENU_GRAVITY, "1");
props.setProperty(MENU_GRAVITY, "2");
props.setProperty(COMMAND_NAMESPACE, "MGG");
props.setProperty(COMMAND_DESCRIPTION, "Load abudance table(TSV/CSV)");
props.setProperty(COMMAND, "Load_Abudance");
Expand All @@ -119,7 +120,7 @@ public void start(BundleContext bc) {
metadataprops.setProperty(PREFERRED_MENU, "Apps.MGG.Import Data");
metadataprops.setProperty(IN_TOOL_BAR, "FALSE");
metadataprops.setProperty(IN_MENU_BAR, "TRUE");
metadataprops.setProperty(MENU_GRAVITY, "2");
metadataprops.setProperty(MENU_GRAVITY, "3");
metadataprops.setProperty(COMMAND_NAMESPACE, "MGG");
metadataprops.setProperty(COMMAND_DESCRIPTION, "Load Metadata File");
metadataprops.setProperty(COMMAND, "Load_MetaData");
Expand All @@ -133,7 +134,7 @@ public void start(BundleContext bc) {
networkprops.setProperty(PREFERRED_MENU, "Apps.MGG.Import Data");
networkprops.setProperty(IN_TOOL_BAR, "FALSE");
networkprops.setProperty(IN_MENU_BAR, "TRUE");
networkprops.setProperty(MENU_GRAVITY, "3");
networkprops.setProperty(MENU_GRAVITY, "4");
networkprops.setProperty(COMMAND_NAMESPACE, "MGG");
networkprops.setProperty(COMMAND_DESCRIPTION, "Load Network Data");
networkprops.setProperty(COMMAND, "Load_Network");
Expand All @@ -146,7 +147,7 @@ public void start(BundleContext bc) {
checkdataprops.setProperty(PREFERRED_MENU, "Apps.MGG.Import Data.Check Data Files");
checkdataprops.setProperty(IN_TOOL_BAR, "FALSE");
checkdataprops.setProperty(IN_MENU_BAR, "TRUE");
checkdataprops.setProperty(MENU_GRAVITY, "1");
checkdataprops.setProperty(MENU_GRAVITY, "5");
checkdataprops.setProperty(COMMAND_NAMESPACE, "MGG");
checkdataprops.setProperty(COMMAND_DESCRIPTION, "Check abudance data File");
checkdataprops.setProperty(COMMAND, "Check_Abudance_Data");
Expand All @@ -161,7 +162,7 @@ public void start(BundleContext bc) {
checkMetaDataprops.setProperty(PREFERRED_MENU, "Apps.MGG.Import Data.Check Data Files");
checkMetaDataprops.setProperty(IN_TOOL_BAR, "FALSE");
checkMetaDataprops.setProperty(IN_MENU_BAR, "TRUE");
checkMetaDataprops.setProperty(MENU_GRAVITY, "2");
checkMetaDataprops.setProperty(MENU_GRAVITY, "6");
checkMetaDataprops.setProperty(COMMAND_NAMESPACE, "MGG");
checkMetaDataprops.setProperty(COMMAND_DESCRIPTION, "Check metadata File");
checkMetaDataprops.setProperty(COMMAND, "Check_MetaData");
Expand All @@ -174,7 +175,7 @@ public void start(BundleContext bc) {
checkNetworkprops.setProperty(PREFERRED_MENU, "Apps.MGG.Import Data.Check Data Files");
checkNetworkprops.setProperty(IN_TOOL_BAR, "FALSE");
checkNetworkprops.setProperty(IN_MENU_BAR, "TRUE");
checkNetworkprops.setProperty(MENU_GRAVITY, "3");
checkNetworkprops.setProperty(MENU_GRAVITY, "7");
checkNetworkprops.setProperty(COMMAND_NAMESPACE, "MGG");
checkNetworkprops.setProperty(COMMAND_DESCRIPTION, "Check network data");
checkNetworkprops.setProperty(COMMAND, "Check_Network_Data");
Expand All @@ -187,7 +188,7 @@ public void start(BundleContext bc) {
createMGGvisualprops.setProperty(PREFERRED_MENU, "Apps.MGG.MGG visual style");
createMGGvisualprops.setProperty(IN_TOOL_BAR, "FALSE");
createMGGvisualprops.setProperty(IN_MENU_BAR, "TRUE");
createMGGvisualprops.setProperty(MENU_GRAVITY, "4");
createMGGvisualprops.setProperty(MENU_GRAVITY, "8");
createMGGvisualprops.setProperty(COMMAND_NAMESPACE, "MGG");
createMGGvisualprops.setProperty(COMMAND_DESCRIPTION, "Create MGG visual style");
createMGGvisualprops.setProperty(COMMAND, "MGG_visual_style");
Expand Down Expand Up @@ -216,7 +217,18 @@ public void start(BundleContext bc) {



AboutTaskFactory mggAboutTaskFactory = new AboutTaskFactory ();
Properties aboutprops = new Properties();
aboutprops.setProperty(TITLE, "About MGG");
aboutprops.setProperty(PREFERRED_MENU, "Apps.MGG");
aboutprops.setProperty(IN_TOOL_BAR, "FALSE");
aboutprops.setProperty(IN_MENU_BAR, "TRUE");
aboutprops.setProperty(MENU_GRAVITY, "10");
aboutprops.setProperty(COMMAND_NAMESPACE, "MGG");
aboutprops.setProperty(COMMAND_DESCRIPTION, "Information about MGG");
aboutprops.setProperty(COMMAND, "About_MGG");

registerService(bc, mggAboutTaskFactory, TaskFactory.class, aboutprops);


// CreateMGGVisualStyle createVisualStyleAction = new CreateMGGVisualStyle(MGGManager);
Expand Down
91 changes: 62 additions & 29 deletions src/main/java/be/kuleuven/mgG/internal/model/MGGManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -474,35 +474,68 @@ public void handleEvent(SessionLoadedEvent e) {
*
* @param e The SessionAboutToBeSavedEvent.
*/

@Override
public void handleEvent(SessionAboutToBeSavedEvent e) {
String tmpDir = System.getProperty("java.io.tmpdir");
File jsonFile = new File(tmpDir, SERVER_RESPONSE_FILE);

try {
FileOutputStream fos = new FileOutputStream(jsonFile);
OutputStreamWriter osw = new OutputStreamWriter(fos, "utf-8");
BufferedWriter writer = new BufferedWriter(osw);

writer.write(serverResponse.toJSONString());
writer.close();
osw.close();
fos.close();

List<File> files = new ArrayList<File>();
files.add(jsonFile);

try {
e.addAppFiles(APP_NAME, files);
} catch (Exception add) {
add.printStackTrace();
}
} catch (Exception jsonException) {
jsonException.printStackTrace();
}

}
@Override
public void handleEvent(SessionAboutToBeSavedEvent e) {
String tmpDir = System.getProperty("java.io.tmpdir");
File jsonFile = new File(tmpDir, SERVER_RESPONSE_FILE);

try {
// Check if serverResponse is not null and not empty
if (serverResponse != null && !serverResponse.isEmpty()) {
FileOutputStream fos = new FileOutputStream(jsonFile);
OutputStreamWriter osw = new OutputStreamWriter(fos, "utf-8");
BufferedWriter writer = new BufferedWriter(osw);

// Write the JSON string representation of serverResponse to file
writer.write(serverResponse.toJSONString());
writer.close();
osw.close();
fos.close();

List<File> files = new ArrayList<>();
files.add(jsonFile);

try {
e.addAppFiles(APP_NAME, files);
} catch (Exception add) {
add.printStackTrace();
}
} else {
// Handle the case where serverResponse is null or empty
System.err.println("serverResponse is null or empty, not writing to file.");
}
} catch (Exception jsonException) {
jsonException.printStackTrace();
}
}
// @Override
// public void handleEvent(SessionAboutToBeSavedEvent e) {
// String tmpDir = System.getProperty("java.io.tmpdir");
// File jsonFile = new File(tmpDir, SERVER_RESPONSE_FILE);
//
// try {
// FileOutputStream fos = new FileOutputStream(jsonFile);
// OutputStreamWriter osw = new OutputStreamWriter(fos, "utf-8");
// BufferedWriter writer = new BufferedWriter(osw);
//
// writer.write(serverResponse.toJSONString());
// writer.close();
// osw.close();
// fos.close();
//
// List<File> files = new ArrayList<File>();
// files.add(jsonFile);
//
// try {
// e.addAppFiles(APP_NAME, files);
// } catch (Exception add) {
// add.printStackTrace();
// }
// } catch (Exception jsonException) {
// jsonException.printStackTrace();
// }
//
// }



Expand Down
61 changes: 61 additions & 0 deletions src/main/java/be/kuleuven/mgG/internal/tasks/AboutTask.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package be.kuleuven.mgG.internal.tasks;

import java.awt.BorderLayout;
import java.awt.Cursor;
import java.awt.Desktop;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;

import org.cytoscape.work.AbstractTask;
import org.cytoscape.work.TaskMonitor;

import be.kuleuven.mgG.internal.utils.AboutPanel;

public class AboutTask extends AbstractTask {



@Override
public void run(TaskMonitor taskMonitor) throws Exception {
SwingUtilities.invokeLater(this::showAboutPanel);
}

private void showAboutPanel() {
// Create a new dialog to display the AboutPanel
JDialog aboutDialog = new JDialog();
aboutDialog.setTitle("About MGG");


// make dialog modal
aboutDialog.setModalityType(JDialog.ModalityType.APPLICATION_MODAL);

// dialog always on top
//aboutDialog.setAlwaysOnTop(true);

// Add AboutPanel
AboutPanel aboutPanel = new AboutPanel();
aboutDialog.add(aboutPanel);

// dialog props
aboutDialog.pack();
aboutDialog.setSize(200, 200); // Set the desired width and height
aboutDialog.setLocationRelativeTo(null); // Center on screen
aboutDialog.setVisible(true);

}
}



24 changes: 24 additions & 0 deletions src/main/java/be/kuleuven/mgG/internal/tasks/AboutTaskFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package be.kuleuven.mgG.internal.tasks;

import javax.swing.JFrame;

import org.cytoscape.work.TaskFactory;
import org.cytoscape.work.TaskIterator;

public class AboutTaskFactory implements TaskFactory{



@Override
public TaskIterator createTaskIterator() {

return new TaskIterator(new AboutTask());
}

@Override
public boolean isReady() {

return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public void actionPerformed(ActionEvent e) {

// Create a continuous mapping for edge color based on the "weight" attribute
ContinuousMapping<Double, Paint> edgeColorMapping = (ContinuousMapping<Double, Paint>) mggManager.getService(VisualMappingFunctionFactory.class, "(mapping.type=continuous)")
.createVisualMappingFunction("weight::weight", Double.class, BasicVisualLexicon.EDGE_STROKE_UNSELECTED_PAINT);
.createVisualMappingFunction("microbetag::weight", Double.class, BasicVisualLexicon.EDGE_STROKE_UNSELECTED_PAINT);

/// Define the points at which the color changes
BoundaryRangeValues<Paint> negativeRange = new BoundaryRangeValues<>(Color.PINK, Color.PINK, Color.PINK); // for values from -1 to -0.01
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.Iterator;
import java.util.Map;

import org.cytoscape.model.CyColumn;
import org.cytoscape.model.CyNetwork;
import org.cytoscape.model.CyNetworkFactory;
import org.cytoscape.model.CyNetworkManager;
Expand Down Expand Up @@ -210,7 +211,7 @@ public void run(TaskMonitor taskMonitor) throws Exception {

// Create a continuous mapping for edge color based on the "weight" attribute
ContinuousMapping<Double, Paint> edgeColorMapping = (ContinuousMapping<Double, Paint>) manager.getService(VisualMappingFunctionFactory.class, "(mapping.type=continuous)")
.createVisualMappingFunction("weight::weight", Double.class, BasicVisualLexicon.EDGE_STROKE_UNSELECTED_PAINT);
.createVisualMappingFunction("microbetag::weight", Double.class, BasicVisualLexicon.EDGE_STROKE_UNSELECTED_PAINT);

/// Define the points at which the color changes
BoundaryRangeValues<Paint> negativeRange = new BoundaryRangeValues<>(Color.PINK, Color.PINK, Color.PINK); // for values from -1 to -0.01
Expand All @@ -233,7 +234,8 @@ public void run(TaskMonitor taskMonitor) throws Exception {






private CyNode getNodeById(CyNetwork network, String nodeId) {
for (CyNode node : network.getNodeList()) {
String id = network.getRow(node).get(CyNetwork.NAME, String.class);
Expand Down
52 changes: 52 additions & 0 deletions src/main/java/be/kuleuven/mgG/internal/utils/AboutPanel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package be.kuleuven.mgG.internal.utils;

import java.awt.BorderLayout;
import java.awt.Cursor;
import java.awt.Desktop;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.net.URI;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;


public class AboutPanel extends JPanel {

public AboutPanel() {
setLayout(new BorderLayout());

// Main content
JPanel contentPanel = new JPanel();
contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS));
contentPanel.add(new JLabel("Under Construction"));
contentPanel.add(new JLabel("App Version: 0.9.2"));
//
add(contentPanel, BorderLayout.CENTER);

// Link label
JLabel linkLabel = new JLabel("<html><a href=''> Documentation</a></html>");
linkLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
linkLabel.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
openWebpage("https://hariszaf.github.io/microbetag/docs/cytoApp/");
}
});
add(linkLabel, BorderLayout.SOUTH);


setBorder(BorderFactory.createEtchedBorder());
}

private void openWebpage(String url) {
try {
Desktop.getDesktop().browse(new URI(url));
} catch (Exception e) {
e.printStackTrace();
}
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public Component getTableCellRendererComponent(JTable table, Object value,
int row, int column) {
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if (value instanceof String) {
// Use HTML to underline and color the text
String htmlValue = "<html><font color='blue'><u>" + value.toString() + "</u></font></html>";
setText(htmlValue);
}
Expand Down
Loading

0 comments on commit 5fa458a

Please sign in to comment.