From 5fa458a9893e50a60c6f5dde1cf970d485fc77cd Mon Sep 17 00:00:00 2001 From: herme Date: Thu, 8 Feb 2024 11:40:12 +0100 Subject: [PATCH] fixes and changes --- .../be/kuleuven/mgG/internal/CyActivator.java | 26 ++++-- .../mgG/internal/model/MGGManager.java | 91 +++++++++++++------ .../mgG/internal/tasks/AboutTask.java | 61 +++++++++++++ .../mgG/internal/tasks/AboutTaskFactory.java | 24 +++++ .../internal/tasks/CreateMGGVisualStyle.java | 2 +- .../tasks/CreateMGGVisualStyleTask.java | 6 +- .../mgG/internal/utils/AboutPanel.java | 52 +++++++++++ .../utils/BlueUnderlineHTMLRenderer.java | 1 - .../mgG/internal/utils/HTTPUtils.java | 28 +----- .../mgG/internal/utils/ImportUtils.java | 55 ----------- .../kuleuven/mgG/internal/utils/Mutils.java | 32 ++++--- .../internal/utils/SwingLinkCellRenderer.java | 42 +++++---- .../mgG/internal/view/CollapsablePanel.java | 16 ++-- .../mgG/internal/view/JSONDisplayPanel.java | 34 +------ .../mgG/internal/view/JsonResultPanel.java | 34 +++---- 15 files changed, 297 insertions(+), 207 deletions(-) create mode 100644 src/main/java/be/kuleuven/mgG/internal/tasks/AboutTask.java create mode 100644 src/main/java/be/kuleuven/mgG/internal/tasks/AboutTaskFactory.java create mode 100644 src/main/java/be/kuleuven/mgG/internal/utils/AboutPanel.java delete mode 100644 src/main/java/be/kuleuven/mgG/internal/utils/ImportUtils.java diff --git a/src/main/java/be/kuleuven/mgG/internal/CyActivator.java b/src/main/java/be/kuleuven/mgG/internal/CyActivator.java index bd7abef..6cd811f 100644 --- a/src/main/java/be/kuleuven/mgG/internal/CyActivator.java +++ b/src/main/java/be/kuleuven/mgG/internal/CyActivator.java @@ -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; @@ -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"); @@ -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"); @@ -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"); @@ -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"); @@ -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"); @@ -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"); @@ -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"); @@ -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); diff --git a/src/main/java/be/kuleuven/mgG/internal/model/MGGManager.java b/src/main/java/be/kuleuven/mgG/internal/model/MGGManager.java index cdf7510..7148ad5 100644 --- a/src/main/java/be/kuleuven/mgG/internal/model/MGGManager.java +++ b/src/main/java/be/kuleuven/mgG/internal/model/MGGManager.java @@ -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 files = new ArrayList(); - 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 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 files = new ArrayList(); +// files.add(jsonFile); +// +// try { +// e.addAppFiles(APP_NAME, files); +// } catch (Exception add) { +// add.printStackTrace(); +// } +// } catch (Exception jsonException) { +// jsonException.printStackTrace(); +// } +// +// } diff --git a/src/main/java/be/kuleuven/mgG/internal/tasks/AboutTask.java b/src/main/java/be/kuleuven/mgG/internal/tasks/AboutTask.java new file mode 100644 index 0000000..620ba4d --- /dev/null +++ b/src/main/java/be/kuleuven/mgG/internal/tasks/AboutTask.java @@ -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); + + } + } + + + diff --git a/src/main/java/be/kuleuven/mgG/internal/tasks/AboutTaskFactory.java b/src/main/java/be/kuleuven/mgG/internal/tasks/AboutTaskFactory.java new file mode 100644 index 0000000..41c6ded --- /dev/null +++ b/src/main/java/be/kuleuven/mgG/internal/tasks/AboutTaskFactory.java @@ -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; + } + +} diff --git a/src/main/java/be/kuleuven/mgG/internal/tasks/CreateMGGVisualStyle.java b/src/main/java/be/kuleuven/mgG/internal/tasks/CreateMGGVisualStyle.java index 1c59486..14040b4 100644 --- a/src/main/java/be/kuleuven/mgG/internal/tasks/CreateMGGVisualStyle.java +++ b/src/main/java/be/kuleuven/mgG/internal/tasks/CreateMGGVisualStyle.java @@ -204,7 +204,7 @@ public void actionPerformed(ActionEvent e) { // Create a continuous mapping for edge color based on the "weight" attribute ContinuousMapping edgeColorMapping = (ContinuousMapping) 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 negativeRange = new BoundaryRangeValues<>(Color.PINK, Color.PINK, Color.PINK); // for values from -1 to -0.01 diff --git a/src/main/java/be/kuleuven/mgG/internal/tasks/CreateMGGVisualStyleTask.java b/src/main/java/be/kuleuven/mgG/internal/tasks/CreateMGGVisualStyleTask.java index 036109a..88be1a9 100644 --- a/src/main/java/be/kuleuven/mgG/internal/tasks/CreateMGGVisualStyleTask.java +++ b/src/main/java/be/kuleuven/mgG/internal/tasks/CreateMGGVisualStyleTask.java @@ -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; @@ -210,7 +211,7 @@ public void run(TaskMonitor taskMonitor) throws Exception { // Create a continuous mapping for edge color based on the "weight" attribute ContinuousMapping edgeColorMapping = (ContinuousMapping) 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 negativeRange = new BoundaryRangeValues<>(Color.PINK, Color.PINK, Color.PINK); // for values from -1 to -0.01 @@ -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); diff --git a/src/main/java/be/kuleuven/mgG/internal/utils/AboutPanel.java b/src/main/java/be/kuleuven/mgG/internal/utils/AboutPanel.java new file mode 100644 index 0000000..c40c28b --- /dev/null +++ b/src/main/java/be/kuleuven/mgG/internal/utils/AboutPanel.java @@ -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(" Documentation"); + 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(); + } + } + } + + diff --git a/src/main/java/be/kuleuven/mgG/internal/utils/BlueUnderlineHTMLRenderer.java b/src/main/java/be/kuleuven/mgG/internal/utils/BlueUnderlineHTMLRenderer.java index 51c36e4..26b5705 100644 --- a/src/main/java/be/kuleuven/mgG/internal/utils/BlueUnderlineHTMLRenderer.java +++ b/src/main/java/be/kuleuven/mgG/internal/utils/BlueUnderlineHTMLRenderer.java @@ -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 = "" + value.toString() + ""; setText(htmlValue); } diff --git a/src/main/java/be/kuleuven/mgG/internal/utils/HTTPUtils.java b/src/main/java/be/kuleuven/mgG/internal/utils/HTTPUtils.java index 14021ae..a7b3212 100644 --- a/src/main/java/be/kuleuven/mgG/internal/utils/HTTPUtils.java +++ b/src/main/java/be/kuleuven/mgG/internal/utils/HTTPUtils.java @@ -34,9 +34,7 @@ import org.cytoscape.work.TaskMonitor; public class HTTPUtils { - public static final String WS_URL = "https://webservices.rbvi.ucsf.edu/scnetviz/api/v1/"; - public static final String WS_URL_V2 = "https://webservices.rbvi.ucsf.edu/scnetviz/api/v2/"; - // public static final String WS_URL = "http://localhost:8000/scnetviz/api/v1/"; + public static JSONObject getJSON(String uri, CloseableHttpClient httpclient, TaskMonitor monitor) throws Exception { HttpGet httpGet = new HttpGet(uri); @@ -174,27 +172,5 @@ public static ZipInputStream getZipStream(String uri, CloseableHttpClient httpcl return stream; } - /* - * public static String getWebServicesURL(String command, Experiment exp, String - * args) { - * - * String url = - * WS_URL+command+"?source="+exp.getSource().getName()+"&accession="+ - * exp.getMetadata().get(Metadata.ACCESSION).toString(); - * - * String url = WS_URL_V2+command+"/"+exp.getSource().getName()+"/"+ - * exp.getMetadata().get(Metadata.ACCESSION).toString(); if (args != null) { url - * += "?"+args; } return url; } - */ - - // public static void showWebPage(ScNVManager manager, String uri, TaskMonitor - // monitor) { - // Map args = new HashMap<>(); - // args.put("newTab", "true"); - // args.put("id", "GXA"); - // args.put("url", uri); - - // manager.executeCommand("cybrowser", "dialog", args); - - // } + } diff --git a/src/main/java/be/kuleuven/mgG/internal/utils/ImportUtils.java b/src/main/java/be/kuleuven/mgG/internal/utils/ImportUtils.java deleted file mode 100644 index 223acb6..0000000 --- a/src/main/java/be/kuleuven/mgG/internal/utils/ImportUtils.java +++ /dev/null @@ -1,55 +0,0 @@ -package be.kuleuven.mgG.internal.utils; - -public class ImportUtils { - - - - -// if (!csvData.isEmpty()) { -// String[] headers = csvData.remove(0); // Assuming the first line contains headers -// -// for (String[] row : csvData) { -// JSONObject jsonObj = new JSONObject(); -// for (int i = 0; i < headers.length; i++) { -// jsonObj.put(headers[i], row[i]); -// } -// jsonArray.add(jsonObj); -// } -// } -// -// finalObject.put("data", jsonArray); -// return finalObject; -// - - - -// JSONArray inputParameters = new JSONArray(); -// -// JSONObject inputParam = new JSONObject(); -// inputParam.put("input", input.getSelectedValue()); -// inputParameters.add(inputParam); -// -// JSONObject taxonomyParam = new JSONObject(); -// taxonomyParam.put("taxonomy", taxonomy.getSelectedValue()); -// inputParameters.add(taxonomyParam); -// -// JSONObject delimiterParam = new JSONObject(); -// delimiterParam.put("delimiter", delimiter.getSelectedValue()); -// inputParameters.add(delimiterParam); -// -// // Add other parameters in a similar way -// JSONObject phenDBParam = new JSONObject(); -// phenDBParam.put("phenDB", phenDB); -// inputParameters.add(phenDBParam); -// -// -// -// -// jsonObject.put("inputParameters", inputParameters); -// - - - - - -} diff --git a/src/main/java/be/kuleuven/mgG/internal/utils/Mutils.java b/src/main/java/be/kuleuven/mgG/internal/utils/Mutils.java index 7b6eee3..9e3f5f7 100644 --- a/src/main/java/be/kuleuven/mgG/internal/utils/Mutils.java +++ b/src/main/java/be/kuleuven/mgG/internal/utils/Mutils.java @@ -35,7 +35,7 @@ public class Mutils { public static String MY_ATTRIBUTE = "id"; public static String PhenDbSc_NAMESPACE = "phendbScore"; public static String PhenDb_NAMESPACE = "phendb"; - public static String Weight_NAMESPACE = "weight"; + public static String Weight_NAMESPACE = "microbetag"; public static String Seed_NAMESPACE = "seed"; public static String Faprotax_NAMESPACE = "faprotax"; @@ -44,9 +44,9 @@ public static boolean isMGGNetwork(CyNetwork network) { if (network == null) return false; //this is new CyTable nodeTable = network.getDefaultNodeTable(); // if (nodeTable.getColumn("@id") == null) { -// return false; // Return false if @id column is missing in node table +// return false; // if @id column is missing in node table // } - + CyTable edgeTable = network.getDefaultEdgeTable(); for (CyColumn column : nodeTable.getColumns()) { @@ -58,12 +58,12 @@ public static boolean isMGGNetwork(CyNetwork network) { - CyTable edgeTable = network.getDefaultEdgeTable(); - if (edgeTable.getColumn("weight::weight") == null) { - return false; // Return false if weight::weight column is missing in edge table + + if (edgeTable.getColumn("microbetag::weight") == null) { + return false; } - return true; // All checks passed, return true + return true; } public static boolean isMGGNetworkMicrobetagDB(CyNetwork network) { @@ -74,12 +74,16 @@ public static boolean isMGGNetworkMicrobetagDB(CyNetwork network) { // return false; //return isMGGNetwork(network); - // Get the value of the "name" column for this network + + if (network==null) { + return false; + } + String nameValue = network.getRow(network).get("name", String.class); - // Check if the "name" contains "microbetag network" or any other variations - if (nameValue != null && (nameValue.contains("microbetag network") || nameValue.matches(".*microbetag network\\(\\d+\\).*"))) { - // If the "name" contains "microbetag network" or similar variations, + // Does the "name" contains "microbetag network" or any other variation + if ( nameValue != null && (nameValue.contains("microbetag network") || nameValue.matches(".*microbetag network\\(\\d+\\).*"))) { + // the "name" contains "microbetag network" or similar variations return true; } @@ -322,7 +326,7 @@ public static List < String > getWeightList(CyNetwork network) { // System.out.println("network is null"); return weight; } - Collection < CyColumn > columns = network.getDefaultEdgeTable().getColumns(Weight_NAMESPACE); + Collection < CyColumn > columns = network.getDefaultEdgeTable().getColumns("microbetag"); if (columns == null || columns.size() == 0) return weight; for (CyColumn col: columns) { weight.add(col.getNameOnly()); @@ -378,7 +382,7 @@ public static String getCategoryForAttribute(String attribute) { Map attributeCategoryMap = new HashMap<>(); // Add mappings for each attribute to its category - // Example: attributeCategoryMap.put("aSaccharolytic", "Lifestyle: Energy Source"); + // Lifestyle String[] lifestyleAttributes = { @@ -520,7 +524,7 @@ public static String getCategoryForAttribute(String attribute) { return attributeCategoryMap.getOrDefault(attribute, "Unknown"); } - // Method to get all categories + // to get all categories public static List getCategories() { return Arrays.asList( "Lifestyle", diff --git a/src/main/java/be/kuleuven/mgG/internal/utils/SwingLinkCellRenderer.java b/src/main/java/be/kuleuven/mgG/internal/utils/SwingLinkCellRenderer.java index 66deb8b..2d630a1 100644 --- a/src/main/java/be/kuleuven/mgG/internal/utils/SwingLinkCellRenderer.java +++ b/src/main/java/be/kuleuven/mgG/internal/utils/SwingLinkCellRenderer.java @@ -15,22 +15,32 @@ public class SwingLinkCellRenderer extends DefaultTableCellRenderer { - @Override - public Component getTableCellRendererComponent(JTable table, Object value, - boolean isSelected, boolean hasFocus, - int row, int column) { - - - - if (value instanceof SwingLink) { - return (SwingLink) value; - } else { - return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); - - } - } -} - +// @Override +// public Component getTableCellRendererComponent(JTable table, Object value, +// boolean isSelected, boolean hasFocus, +// int row, int column) { +// +// +// +// if (value instanceof SwingLink) { +// return (SwingLink) value; +// } else { +// return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); +// +// } +// } +//} +@Override +public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { + if (value instanceof SwingLink) { + SwingLink link = (SwingLink) value; + JLabel label = (JLabel) super.getTableCellRendererComponent(table, link.getText(), isSelected, hasFocus, row, column); + label.setText("
" + link.getText() + "
"); + return label; + } + return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); +} +} \ No newline at end of file diff --git a/src/main/java/be/kuleuven/mgG/internal/view/CollapsablePanel.java b/src/main/java/be/kuleuven/mgG/internal/view/CollapsablePanel.java index e1b19df..a0b3ee6 100644 --- a/src/main/java/be/kuleuven/mgG/internal/view/CollapsablePanel.java +++ b/src/main/java/be/kuleuven/mgG/internal/view/CollapsablePanel.java @@ -18,6 +18,8 @@ public class CollapsablePanel extends JPanel { private static String RIGHT_ARROW = "\uF0DA"; private static String DOWN_ARROW = "\uF0D7"; + private static String CIRCLE = "\u2022"; + Font awesomeFont; JPanel contentPanel_; @@ -129,22 +131,24 @@ public void setAlwaysExpanded() { headerPanel_.expanded = true; contentPanel_.setVisible(true); headerPanel_.expandButton.setEnabled(false); // Disable the expand/collapse button - headerPanel_.setButton(DOWN_ARROW); // Set to the down arrow symbol - headerPanel_.expandButton.setToolTipText(""); // Remove tooltip + headerPanel_.setButton(CIRCLE); // Set to the circle symbol + headerPanel_.expandButton.setToolTipText(""); // } public void toggleSelection() { - if (headerPanel_.expanded) { + + if (headerPanel_.expanded) { // If the panel is always expanded, do nothing + return; - } + } if (contentPanel_.isShowing()) { - headerPanel_.setButton(RIGHT_ARROW); + headerPanel_.setButton(RIGHT_ARROW);//Right arrow headerPanel_.expandButton.setToolTipText("Click to expand"); // Update tooltip contentPanel_.setVisible(false); } else { contentPanel_.setVisible(true); - headerPanel_.setButton(DOWN_ARROW); + headerPanel_.setButton(DOWN_ARROW);//down arrow headerPanel_.expandButton.setToolTipText("Click to collapse"); // Update tooltip } diff --git a/src/main/java/be/kuleuven/mgG/internal/view/JSONDisplayPanel.java b/src/main/java/be/kuleuven/mgG/internal/view/JSONDisplayPanel.java index fe90b94..78b1717 100644 --- a/src/main/java/be/kuleuven/mgG/internal/view/JSONDisplayPanel.java +++ b/src/main/java/be/kuleuven/mgG/internal/view/JSONDisplayPanel.java @@ -47,39 +47,7 @@ public JSONDisplayPanel(final MGGManager manager,JSONObject jsonObject) { } } -// // Check if the jsonObject contains an array named "data" -// if (jsonObject.containsKey("data")) { -// JSONArray dataJsonArray = (JSONArray) jsonObject.get("data"); -// createTable(dataJsonArray, "Data Table"); -// -// //add the button for annotated network -// // JButton sendButton = createSendButton(jsonObject); -// // add(sendButton, BorderLayout.NORTH); -// } else if (jsonObject.containsKey("network")) { -// // If there's no "data" but "metadata" exists, display metadata table without button -// JSONArray networkJsonArray = (JSONArray) jsonObject.get("network"); -// createTable(networkJsonArray , "Network Table");} -// -// else if (jsonObject.containsKey("metadata")) { -// // If there's no "data" but "metadata" exists, display metadata table without button -// JSONArray metadataJsonArray = (JSONArray) jsonObject.get("metadata"); -// createTable(metadataJsonArray, "Metadata Table"); -// }} - - //private JButton createSendButton(JSONObject jsonObject) { - // JButton sendButton = new JButton("Get Annotated Network"); - // sendButton.addActionListener(new ActionListener() { - // public void actionPerformed(ActionEvent e) { - // TaskIterator taskIterator = new SendDataToServerTaskFactory( manager).createTaskIterator(); - // manager.executeTasks(taskIterator); - // } - // }); - - // configureButtonAppearance(sendButton); - - // return sendButton; - //} private void configureButtonAppearance(JButton button) { button.setForeground(Color.BLACK); @@ -119,7 +87,7 @@ private void createTable(JSONArray jsonArray, String tableName) { } // Add the data to the table model - int numberOfRows = Math.min(jsonArray.size(), 21); //Limit to 20 rows plus header + int numberOfRows = Math.min(jsonArray.size(), 41); //Limit to 40 rows plus header for (int i = 1; i < numberOfRows; i++) { JSONArray row = (JSONArray) jsonArray.get(i); Object[] rowData = new Object[row.size()]; diff --git a/src/main/java/be/kuleuven/mgG/internal/view/JsonResultPanel.java b/src/main/java/be/kuleuven/mgG/internal/view/JsonResultPanel.java index 7486d6d..0ba11b5 100644 --- a/src/main/java/be/kuleuven/mgG/internal/view/JsonResultPanel.java +++ b/src/main/java/be/kuleuven/mgG/internal/view/JsonResultPanel.java @@ -57,18 +57,18 @@ public JsonResultPanel(final MGGManager manager,JSONObject jsonObject) { this.manager = manager; - // Set the scroll bar policies + // scroll bar policies scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); - // Set the preferred size of the scroll pane + // preferred size of the scroll pane scrollPane.setPreferredSize(new Dimension(800, 600)); // Add the scroll pane to the center of the JSONDisplayPanel add(scrollPane, BorderLayout.CENTER); - // Add the button that will execute the SendDataToServerTask when clicked + //button for SendDataToServerTask JButton sendButton = new JButton("Get Annotated Network "); sendButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { @@ -84,31 +84,31 @@ public void actionPerformed(ActionEvent e) { }); // Set button appearance - sendButton.setForeground(Color.BLACK); // Set the text color of the button - sendButton.setFont(sendButton.getFont().deriveFont(Font.BOLD, 14f)); // Set the font style and size of the button text - sendButton.setBackground(new Color(144, 238, 144)); // Set the background color of the button - sendButton.setFocusPainted(false); // Remove the focus border around the button - sendButton.setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 10)); // Add padding to the button + sendButton.setForeground(Color.BLACK); // text color of the button + sendButton.setFont(sendButton.getFont().deriveFont(Font.BOLD, 14f)); // font style and size of the button text + sendButton.setBackground(new Color(144, 238, 144)); // background color of the button + sendButton.setFocusPainted(false); // Remove the focus border + sendButton.setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 10)); // Add padding - // Create a rounded border for the button + // rounded border for the button int borderRadius = 20; int borderThickness = 2; sendButton.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createLineBorder(Color.WHITE, borderThickness), BorderFactory.createEmptyBorder(borderRadius, borderRadius, borderRadius, borderRadius))); - // Add hover effect for the button + // hover effect for the button sendButton.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseEntered(java.awt.event.MouseEvent evt) { - sendButton.setBackground(Color.GREEN); // Set the background color when mouse enters the button + sendButton.setBackground(Color.GREEN); // background color when mouse enters } public void mouseExited(java.awt.event.MouseEvent evt) { - sendButton.setBackground(new Color(144, 238, 144)); // Set the background color when mouse exits the button + sendButton.setBackground(new Color(144, 238, 144)); // background color when mouse exits } }); - // Add the button to the JSONDisplayPanel + // Add button to JSONDisplayPanel add(sendButton, BorderLayout.NORTH); } @@ -117,13 +117,13 @@ private void createTable(JSONArray jsonArray) { DefaultTableModel tableModel = new DefaultTableModel(); table = new JTable(tableModel); - // Set the column names + // Set column names JSONArray headers = (JSONArray) jsonArray.get(0); for (Object header : headers) { tableModel.addColumn(header.toString()); } - // Add the data to the table model + // Add data to table model for (int i = 1; i < jsonArray.size(); i++) { JSONArray row = (JSONArray) jsonArray.get(i); Object[] rowData = new Object[row.size()]; @@ -146,7 +146,7 @@ public Component getComponent() { @Override public CytoPanelName getCytoPanelName() { - return CytoPanelName.EAST; // Or where you would like to dock this panel + return CytoPanelName.EAST; } @Override @@ -156,6 +156,6 @@ public String getTitle() { @Override public Icon getIcon() { - return null; // Optionally, return an Icon to be displayed + return null; } } \ No newline at end of file