Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.signalcollect.sna.visualization; import com.signalcollect.sna.GraphProperties; import com.signalcollect.sna.gephiconnectors.BetweennessSignalCollectGephiConnectorImpl; import com.signalcollect.sna.gephiconnectors.ClosenessSignalCollectGephiConnectorImpl; import com.signalcollect.sna.gephiconnectors.DegreeSignalCollectGephiConnectorImpl; import com.signalcollect.sna.gephiconnectors.LabelPropagationSignalCollectGephiConnectorImpl; import com.signalcollect.sna.gephiconnectors.LocalClusterCoefficientSignalCollectGephiConnectorImpl; import com.signalcollect.sna.gephiconnectors.PageRankSignalCollectGephiConnectorImpl; import com.signalcollect.sna.gephiconnectors.SignalCollectGephiConnector; import com.signalcollect.sna.gephiconnectors.TriadCensusSignalCollectGephiConnectorImpl; import java.awt.Cursor; import java.awt.Dimension; import java.io.File; import java.util.Map; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.filechooser.FileNameExtensionFilter; import org.gephi.io.importer.api.Container; import org.gephi.io.importer.api.ImportController; import org.gephi.io.processor.plugin.DefaultProcessor; import org.gephi.project.api.ProjectController; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.netbeans.api.settings.ConvertAsProperties; import org.openide.awt.ActionID; import org.openide.awt.ActionReference; import org.openide.util.Lookup; import org.openide.util.NbBundle.Messages; import org.openide.windows.TopComponent; /** * Top component which displays the functionalities to use Signal/Collect SNA. */ @ConvertAsProperties(dtd = "-//com.signalcollect.sna.visualization//SignalCollectSNA//EN", autostore = false) @TopComponent.Description(preferredID = "signal-collect-sna", //iconBase="SET/PATH/TO/ICON/HERE", persistenceType = TopComponent.PERSISTENCE_ALWAYS) @TopComponent.Registration(mode = "contextmode", openAtStartup = true) @ActionID(category = "Window", id = "com.signalcollect.sna.visualization.SignalCollectSNATopComponent") @ActionReference(path = "Menu/Window" /*, position = 333 */) @TopComponent.OpenActionRegistration(displayName = "#CTL_SignalCollectSNAAction", preferredID = "SignalCollectSNATopComponent") @Messages({ "CTL_SignalCollectSNAAction=SignalCollect SNA", "CTL_SignalCollectSNATopComponent=Signal/Collect SNA", "HINT_SignalCollectSNATopComponent=Plugin to perform SNA with Signal/Collect" }) public final class SignalCollectSNATopComponent extends TopComponent { private SignalCollectGephiConnector scgc; private String fileName; JFrame messageFrame; /** * Constructor */ public SignalCollectSNATopComponent() { initComponents(); setName(Bundle.CTL_SignalCollectSNATopComponent()); setToolTipText(Bundle.HINT_SignalCollectSNATopComponent()); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; metricResultFrame = new javax.swing.JFrame(); metricValuesScrollPane = new javax.swing.JScrollPane(metricValuesTextPane); metricValuesTextPane = new javax.swing.JTextPane(); distributionFrame = new javax.swing.JFrame(); jFrame1 = new javax.swing.JFrame(); jScrollPane1 = new javax.swing.JScrollPane(); mainPanel = new javax.swing.JPanel(); propertyPanel = new javax.swing.JPanel(); propertyButton = new javax.swing.JButton(); propertyInfo = new javax.swing.JLabel(); propertyDisplay = new javax.swing.JScrollPane(); propertyContentDisplay = new javax.swing.JEditorPane(); infoPanel = new javax.swing.JPanel(); imageLabel = new javax.swing.JLabel(); fileChooserButton = new javax.swing.JButton(); filePathScrollPane = new javax.swing.JScrollPane(); jTextArea1 = new javax.swing.JTextArea(); metricPanel = new javax.swing.JPanel(); metricDropDown = new javax.swing.JComboBox(); runMetricButton = new javax.swing.JButton(); infoTextLabel = new javax.swing.JLabel(); distributionPanel = new javax.swing.JPanel(); degreeDistributionButton = new javax.swing.JButton(); distributionInfo = new javax.swing.JLabel(); clusterDistributionButton = new javax.swing.JButton(); labelPropagationPanel = new javax.swing.JPanel(); labelPropagationButton = new javax.swing.JButton(); labelPropagationInfo = new javax.swing.JLabel(); stepNumberPane = new javax.swing.JScrollPane(); jTextPane1 = new javax.swing.JTextPane(); metricValuesTextPane.setContentType("text/html"); metricValuesTextPane.setFocusable(false); metricValuesTextPane.setMargin(new java.awt.Insets(20, 20, 20, 20)); metricResultFrame.getContentPane().add(metricValuesTextPane, java.awt.BorderLayout.CENTER); metricValuesScrollPane.setViewportView(metricValuesTextPane); metricResultFrame.getContentPane().add(metricValuesScrollPane, java.awt.BorderLayout.PAGE_START); metricResultFrame.setContentPane(metricValuesScrollPane); metricResultFrame.setLocation(50, 50); distributionFrame.setLocation(50, 50); jFrame1.getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER); setAutoscrolls(true); setLayout(new java.awt.GridBagLayout()); mainPanel.setBackground(new java.awt.Color(100, 150, 255)); mainPanel.setMaximumSize(new java.awt.Dimension(1000, 800)); mainPanel.setMinimumSize(new java.awt.Dimension(0, 0)); mainPanel.setLayout(new java.awt.GridBagLayout()); propertyPanel.setBackground(new java.awt.Color(100, 150, 255)); propertyPanel.setBorder( javax.swing.BorderFactory.createMatteBorder(2, 2, 2, 2, new java.awt.Color(102, 102, 102))); propertyPanel.setLayout(new java.awt.GridBagLayout()); org.openide.awt.Mnemonics.setLocalizedText(propertyButton, org.openide.util.NbBundle.getMessage( SignalCollectSNATopComponent.class, "SignalCollectSNATopComponent.propertyButton.text")); // NOI18N propertyButton.setAutoscrolls(true); propertyButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { propertyButtonActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; gridBagConstraints.insets = new java.awt.Insets(10, 15, 0, 15); propertyPanel.add(propertyButton, gridBagConstraints); propertyInfo.setFont(new java.awt.Font("Verdana", 0, 14)); // NOI18N org.openide.awt.Mnemonics.setLocalizedText(propertyInfo, org.openide.util.NbBundle .getMessage(SignalCollectSNATopComponent.class, "SignalCollectSNATopComponent.propertyInfo.text")); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; gridBagConstraints.insets = new java.awt.Insets(10, 15, 0, 15); propertyPanel.add(propertyInfo, gridBagConstraints); propertyContentDisplay.setEditable(false); propertyContentDisplay.setContentType("text/html"); // NOI18N propertyContentDisplay.setFocusable(false); propertyDisplay.setViewportView(propertyContentDisplay); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 0; gridBagConstraints.gridheight = 2; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.ipadx = 5; gridBagConstraints.ipady = 5; gridBagConstraints.weightx = 2.0; gridBagConstraints.weighty = 1.0; gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10); propertyPanel.add(propertyDisplay, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 2; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.5; mainPanel.add(propertyPanel, gridBagConstraints); infoPanel.setBackground(new java.awt.Color(100, 150, 255)); infoPanel.setBorder( javax.swing.BorderFactory.createMatteBorder(2, 2, 2, 2, new java.awt.Color(102, 102, 102))); infoPanel.setLayout(new java.awt.GridBagLayout()); imageLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/sc-logo-white-bg_200px.png"))); org.openide.awt.Mnemonics.setLocalizedText(imageLabel, org.openide.util.NbBundle .getMessage(SignalCollectSNATopComponent.class, "SignalCollectSNATopComponent.imageLabel.text")); // NOI18N imageLabel.setToolTipText(org.openide.util.NbBundle.getMessage(SignalCollectSNATopComponent.class, "SignalCollectSNATopComponent.imageLabel.toolTipText")); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.weightx = 2.0; gridBagConstraints.weighty = 1.0; gridBagConstraints.insets = new java.awt.Insets(10, 15, 10, 15); infoPanel.add(imageLabel, gridBagConstraints); org.openide.awt.Mnemonics.setLocalizedText(fileChooserButton, org.openide.util.NbBundle.getMessage( SignalCollectSNATopComponent.class, "SignalCollectSNATopComponent.fileChooserButton.text")); // NOI18N fileChooserButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { fileChooserButtonActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = new java.awt.Insets(10, 15, 10, 15); infoPanel.add(fileChooserButton, gridBagConstraints); filePathScrollPane.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); filePathScrollPane.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER); jTextArea1.setColumns(20); jTextArea1.setRows(1); filePathScrollPane.setViewportView(jTextArea1); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.weightx = 2.0; gridBagConstraints.insets = new java.awt.Insets(10, 15, 10, 15); infoPanel.add(filePathScrollPane, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.weighty = 1.0; mainPanel.add(infoPanel, gridBagConstraints); metricPanel.setBackground(new java.awt.Color(100, 150, 255)); metricPanel.setBorder( javax.swing.BorderFactory.createMatteBorder(2, 2, 2, 2, new java.awt.Color(102, 102, 102))); metricPanel.setLayout(new java.awt.GridBagLayout()); metricDropDown.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Degree", "PageRank", "Closeness", "Betweenness", "Local Cluster Coefficient", "Triad Census" })); metricDropDown.setAutoscrolls(true); metricDropDown.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { metricDropDownActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 0; gridBagConstraints.ipady = 10; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; gridBagConstraints.insets = new java.awt.Insets(10, 15, 10, 15); metricPanel.add(metricDropDown, gridBagConstraints); org.openide.awt.Mnemonics.setLocalizedText(runMetricButton, org.openide.util.NbBundle.getMessage( SignalCollectSNATopComponent.class, "SignalCollectSNATopComponent.runMetricButton.text")); // NOI18N runMetricButton.setAutoscrolls(true); runMetricButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { runMetricButtonActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 2; gridBagConstraints.gridy = 0; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.weightx = 4.0; gridBagConstraints.weighty = 1.0; gridBagConstraints.insets = new java.awt.Insets(10, 15, 10, 15); metricPanel.add(runMetricButton, gridBagConstraints); infoTextLabel.setFont(new java.awt.Font("Verdana", 0, 14)); // NOI18N org.openide.awt.Mnemonics.setLocalizedText(infoTextLabel, org.openide.util.NbBundle .getMessage(SignalCollectSNATopComponent.class, "SignalCollectSNATopComponent.infoTextLabel.text")); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.weightx = 2.0; gridBagConstraints.weighty = 1.0; gridBagConstraints.insets = new java.awt.Insets(10, 15, 10, 15); metricPanel.add(infoTextLabel, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.weighty = 0.75; mainPanel.add(metricPanel, gridBagConstraints); distributionPanel.setBackground(new java.awt.Color(100, 150, 255)); distributionPanel.setBorder( javax.swing.BorderFactory.createMatteBorder(2, 2, 2, 2, new java.awt.Color(102, 102, 102))); distributionPanel.setLayout(new java.awt.GridBagLayout()); org.openide.awt.Mnemonics.setLocalizedText(degreeDistributionButton, org.openide.util.NbBundle.getMessage( SignalCollectSNATopComponent.class, "SignalCollectSNATopComponent.degreeDistributionButton.text")); // NOI18N degreeDistributionButton.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); degreeDistributionButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { degreeDistributionButtonActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; gridBagConstraints.insets = new java.awt.Insets(10, 15, 10, 15); distributionPanel.add(degreeDistributionButton, gridBagConstraints); distributionInfo.setFont(new java.awt.Font("Verdana", 0, 14)); // NOI18N org.openide.awt.Mnemonics.setLocalizedText(distributionInfo, org.openide.util.NbBundle.getMessage( SignalCollectSNATopComponent.class, "SignalCollectSNATopComponent.distributionInfo.text")); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.gridwidth = 2; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(10, 15, 10, 15); distributionPanel.add(distributionInfo, gridBagConstraints); org.openide.awt.Mnemonics.setLocalizedText(clusterDistributionButton, org.openide.util.NbBundle.getMessage( SignalCollectSNATopComponent.class, "SignalCollectSNATopComponent.clusterDistributionButton.text")); // NOI18N clusterDistributionButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { clusterDistributionButtonActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 1; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; gridBagConstraints.insets = new java.awt.Insets(10, 15, 10, 15); distributionPanel.add(clusterDistributionButton, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 3; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.weighty = 0.75; mainPanel.add(distributionPanel, gridBagConstraints); labelPropagationPanel.setBackground(new java.awt.Color(100, 150, 255)); labelPropagationPanel.setBorder( javax.swing.BorderFactory.createMatteBorder(2, 2, 2, 2, new java.awt.Color(102, 102, 102))); labelPropagationPanel.setLayout(new java.awt.GridBagLayout()); org.openide.awt.Mnemonics.setLocalizedText(labelPropagationButton, org.openide.util.NbBundle.getMessage( SignalCollectSNATopComponent.class, "SignalCollectSNATopComponent.labelPropagationButton.text")); // NOI18N labelPropagationButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { labelPropagationButtonActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 1; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.weightx = 1.0; labelPropagationPanel.add(labelPropagationButton, gridBagConstraints); labelPropagationInfo.setFont(new java.awt.Font("Verdana", 0, 14)); // NOI18N org.openide.awt.Mnemonics.setLocalizedText(labelPropagationInfo, org.openide.util.NbBundle.getMessage( SignalCollectSNATopComponent.class, "SignalCollectSNATopComponent.labelPropagationInfo.text")); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.gridwidth = 2; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(10, 15, 10, 15); labelPropagationPanel.add(labelPropagationInfo, gridBagConstraints); stepNumberPane.setViewportView(jTextPane1); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = new java.awt.Insets(10, 15, 10, 15); labelPropagationPanel.add(stepNumberPane, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 4; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.weighty = 1.0; mainPanel.add(labelPropagationPanel, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; add(mainPanel, gridBagConstraints); }// </editor-fold>//GEN-END:initComponents /** * Runs a Signal/Collect SNA method when the "Run" button is clicked * * @param evt */ private void runMetricButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_runMetricButtonActionPerformed try { mainPanel.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); if (jTextArea1.getText() == null) { throw new IllegalArgumentException("No file was chosen!\nPlease choose a valid .gml file"); } if (!jTextArea1.getText().contains(".gml")) { throw new IllegalArgumentException( "The chosen file doesn't have the right format!\nPlease choose a valid .gml file"); } String actualMetric = metricDropDown.getSelectedItem().toString(); if (actualMetric.equals("Degree")) { scgc = new DegreeSignalCollectGephiConnectorImpl(fileName); scgc.executeGraph(); metricValuesTextPane.setText(setMetricText(scgc.getAverage(), scgc.getAll())); } else if (actualMetric.equals("PageRank")) { scgc = new PageRankSignalCollectGephiConnectorImpl(fileName); scgc.executeGraph(); metricValuesTextPane.setText(setMetricText(scgc.getAverage(), scgc.getAll())); } else if (actualMetric.equals("Betweenness")) { scgc = new BetweennessSignalCollectGephiConnectorImpl(fileName); scgc.executeGraph(); metricValuesTextPane.setText(setMetricText(scgc.getAverage(), scgc.getAll())); } else if (actualMetric.equals("Closeness")) { scgc = new ClosenessSignalCollectGephiConnectorImpl(fileName); scgc.executeGraph(); metricValuesTextPane.setText(setMetricText(scgc.getAverage(), scgc.getAll())); } else if (actualMetric.equals("Local Cluster Coefficient")) { scgc = new LocalClusterCoefficientSignalCollectGephiConnectorImpl(fileName); scgc.executeGraph(); metricValuesTextPane.setText(setMetricText(scgc.getAverage(), scgc.getAll())); } else if (actualMetric.equals("Triad Census")) { scgc = new TriadCensusSignalCollectGephiConnectorImpl(fileName); scgc.executeGraph(); metricValuesTextPane.setText(setTriadCensusText(scgc.getAll())); } else { throw new IllegalArgumentException("invalid Signal/Collect metric chosen!\nPlease try again"); } Dimension dim = new Dimension(750, 450); metricResultFrame.setMinimumSize(dim); metricResultFrame.pack(); metricValuesTextPane.setVisible(true); metricValuesScrollPane.setVisible(true); metricResultFrame.setVisible(true); } catch (IllegalArgumentException exception) { messageFrame = new JFrame(); JOptionPane.showMessageDialog(messageFrame, exception.getMessage(), "Signal/Collect Error", JOptionPane.ERROR_MESSAGE); } catch (Exception exception) { messageFrame = new JFrame(); exception.printStackTrace(); JOptionPane.showMessageDialog(messageFrame, "Technical exception happened (" + exception.getCause() + ")", "Signal/Collect Error", JOptionPane.ERROR_MESSAGE); } finally { mainPanel.setCursor(Cursor.getDefaultCursor()); } }//GEN-LAST:event_runMetricButtonActionPerformed private void metricDropDownActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_metricDropDownActionPerformed // TODO add your handling code here: }//GEN-LAST:event_metricDropDownActionPerformed /** * Gets the properties of the current graph by clicking on the property * button * * @param evt */ private void propertyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_propertyButtonActionPerformed try { mainPanel.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); if (jTextArea1.getText() == null) { throw new IllegalArgumentException("No file was chosen!\nPlease choose a valid .gml file"); } if (!jTextArea1.getText().contains(".gml")) { throw new IllegalArgumentException( "The chosen file doesn't have the right format!\nPlease choose a valid .gml file"); } if (scgc == null || !scgc.getFileName().equals(fileName)) { scgc = new DegreeSignalCollectGephiConnectorImpl(fileName); } propertyContentDisplay.setText(setPropertyText(scgc.getGraphProperties())); } catch (IllegalArgumentException exception) { messageFrame = new JFrame(); JOptionPane.showMessageDialog(messageFrame, exception.getMessage(), "Signal/Collect Error", JOptionPane.ERROR_MESSAGE); } catch (Exception exception) { messageFrame = new JFrame(); exception.printStackTrace(); JOptionPane.showMessageDialog(messageFrame, "Technical exception happened (" + exception.getCause() + ")", "Signal/Collect Error", JOptionPane.ERROR_MESSAGE); } finally { mainPanel.setCursor(Cursor.getDefaultCursor()); } }//GEN-LAST:event_propertyButtonActionPerformed /** * Gets and visualizes the chart of the Degree Distribution * * @param evt */ private void degreeDistributionButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_degreeDistributionButtonActionPerformed try { mainPanel.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); if (jTextArea1.getText() == null) { throw new IllegalArgumentException("No file was chosen!\nPlease choose a valid .gml file"); } if (!jTextArea1.getText().contains(".gml")) { throw new IllegalArgumentException( "The chosen file doesn't have the right format!\nPlease choose a valid .gml file"); } distributionFrame.setVisible(false); distributionFrame = new JFrame(); scgc = new DegreeSignalCollectGephiConnectorImpl(fileName); JFreeChart chart = scgc.createDegreeDistributionChart(scgc.getDegreeDistribution()); ChartPanel chartPanel = new ChartPanel(chart); Dimension dim = new Dimension(750, 450); distributionFrame.setMinimumSize(dim); distributionFrame.add(chartPanel); chartPanel.setVisible(true); chartPanel.validate(); distributionFrame.pack(); distributionFrame.setVisible(true); } catch (IllegalArgumentException exception) { messageFrame = new JFrame(); JOptionPane.showMessageDialog(messageFrame, exception.getMessage(), "Signal/Collect Error", JOptionPane.ERROR_MESSAGE); } catch (Exception exception) { messageFrame = new JFrame(); exception.printStackTrace(); JOptionPane.showMessageDialog(messageFrame, "Technical exception happened (" + exception.getCause() + ")", "Signal/Collect Error", JOptionPane.ERROR_MESSAGE); } finally { mainPanel.setCursor(Cursor.getDefaultCursor()); } }//GEN-LAST:event_degreeDistributionButtonActionPerformed /** * Displays a file chooser when clicking on the "Choose File" button The * chosen file is then used for a new gephi project * * @param evt */ private void fileChooserButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fileChooserButtonActionPerformed FileNameExtensionFilter filter = new FileNameExtensionFilter("Graph Files", "gml"); JFileChooser chooser = new JFileChooser(); chooser.setFileFilter(filter); int result = chooser.showOpenDialog(this); if (chooser.getSelectedFile() != null && result == JFileChooser.APPROVE_OPTION) { fileName = chooser.getSelectedFile().getAbsolutePath(); jTextArea1.setText(fileName); distributionFrame = new JFrame(); try { ProjectController pc = Lookup.getDefault().lookup(ProjectController.class); pc.newProject(); ImportController ic = Lookup.getDefault().lookup(ImportController.class); File file = new File(fileName); Container c = ic.importFile(file); ic.process(c, new DefaultProcessor(), pc.newWorkspace(pc.getCurrentProject())); propertyContentDisplay.setText(""); } catch (Exception exception) { messageFrame = new JFrame(); exception.printStackTrace(); JOptionPane.showMessageDialog(messageFrame, "Error while creating graph (" + exception.getCause() + "), please choose a valid .gml-File", "Signal/Collect Error", JOptionPane.ERROR_MESSAGE); } } }//GEN-LAST:event_fileChooserButtonActionPerformed /** * Gets and visualizes the chart of the Local Cluster Coefficient * Distribution * * @param evt */ private void clusterDistributionButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clusterDistributionButtonActionPerformed try { mainPanel.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); if (jTextArea1.getText() == null) { throw new IllegalArgumentException("No file was chosen!\nPlease choose a valid .gml file"); } if (!jTextArea1.getText().contains(".gml")) { throw new IllegalArgumentException( "The chosen file doesn't have the right format!\nPlease choose a valid .gml file"); } distributionFrame.setVisible(false); distributionFrame = new JFrame(); scgc = new LocalClusterCoefficientSignalCollectGephiConnectorImpl(fileName); JFreeChart chart = scgc.createClusterDistributionChart(scgc.getClusterDistribution()); ChartPanel chartPanel = new ChartPanel(chart); Dimension dim = new Dimension(750, 450); distributionFrame.setMinimumSize(dim); chartPanel.setVisible(true); chartPanel.validate(); distributionFrame.add(chartPanel); distributionFrame.pack(); distributionFrame.setVisible(true); } catch (IllegalArgumentException exception) { messageFrame = new JFrame(); JOptionPane.showMessageDialog(messageFrame, exception.getMessage(), "Signal/Collect Error", JOptionPane.ERROR_MESSAGE); } catch (Exception exception) { messageFrame = new JFrame(); exception.printStackTrace(); JOptionPane.showMessageDialog(messageFrame, "Technical exception happened (" + exception.getCause() + ")", "Signal/Collect Error", JOptionPane.ERROR_MESSAGE); } finally { mainPanel.setCursor(Cursor.getDefaultCursor()); } }//GEN-LAST:event_clusterDistributionButtonActionPerformed /** * Executes the label propagation algorithm * * @param evt */ private void labelPropagationButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_labelPropagationButtonActionPerformed try { mainPanel.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); if (jTextPane1.getText() == null) { throw new IllegalArgumentException("No input found!"); } if (Integer.parseInt(jTextPane1.getText()) < 1) { throw new IllegalArgumentException("The number has to be greater than 0"); } scgc = new LabelPropagationSignalCollectGephiConnectorImpl(fileName, scala.Option.apply(Integer.parseInt(jTextPane1.getText()))); scgc.getLabelPropagation(); } catch (IllegalArgumentException exception) { JOptionPane.showMessageDialog(messageFrame, "Error when parsing input " + jTextPane1.getText() + ": " + exception.getMessage(), "Signal/Collect Error", JOptionPane.ERROR_MESSAGE); } catch (Exception exception) { messageFrame = new JFrame(); exception.printStackTrace(); JOptionPane.showMessageDialog(messageFrame, "Technical exception happened (" + exception.getCause() + ")", "Signal/Collect Error", JOptionPane.ERROR_MESSAGE); } finally { scgc = null; mainPanel.setCursor(Cursor.getDefaultCursor()); } }//GEN-LAST:event_labelPropagationButtonActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton clusterDistributionButton; private javax.swing.JButton degreeDistributionButton; private javax.swing.JFrame distributionFrame; private javax.swing.JLabel distributionInfo; private javax.swing.JPanel distributionPanel; private javax.swing.JButton fileChooserButton; private javax.swing.JScrollPane filePathScrollPane; private javax.swing.JLabel imageLabel; private javax.swing.JPanel infoPanel; private javax.swing.JLabel infoTextLabel; private javax.swing.JFrame jFrame1; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTextArea jTextArea1; private javax.swing.JTextPane jTextPane1; private javax.swing.JButton labelPropagationButton; private javax.swing.JLabel labelPropagationInfo; private javax.swing.JPanel labelPropagationPanel; private javax.swing.JPanel mainPanel; private javax.swing.JComboBox metricDropDown; private javax.swing.JPanel metricPanel; private javax.swing.JFrame metricResultFrame; private javax.swing.JScrollPane metricValuesScrollPane; private javax.swing.JTextPane metricValuesTextPane; private javax.swing.JButton propertyButton; private javax.swing.JEditorPane propertyContentDisplay; private javax.swing.JScrollPane propertyDisplay; private javax.swing.JLabel propertyInfo; private javax.swing.JPanel propertyPanel; private javax.swing.JButton runMetricButton; private javax.swing.JScrollPane stepNumberPane; // End of variables declaration//GEN-END:variables @Override public void componentOpened() { } @Override public void componentClosed() { } void writeProperties(java.util.Properties p) { // better to version settings since initial version as advocated at // http://wiki.apidesign.org/wiki/PropertyFiles p.setProperty("version", "1.0"); // TODO store your settings } void readProperties(java.util.Properties p) { String version = p.getProperty("version"); // TODO read your settings according to their version } /** * Sets the formatted text for the execution of a SNA method * * @param avg * @param vertexMap * @return HTML-formatted String */ private String setMetricText(double avg, Map<String, Object> vertexMap) { String res = "<!doctype html><html><head><title>Execution Results</title><style type=\"text/css\"></style>" + "</head>" + "<body>" + "<h1><span style=\"font-family:verdana,geneva,sans-serif;font-size:12px;font-weight:normal\">Execution Results</span></h1>" + "<h2><span style=\"font-family:verdana,geneva,sans-serif;font-size:11px;font-weight:normal;\">Average: </span></h2>\n" + "<p><span style=\"font-family:verdana,geneva,sans-serif;font-size:10px;\">The average value of the vertices is: " + avg + "</span></p><ul>" + "<h2><span style=\"font-family:verdana,geneva,sans-serif;font-size:11px;font-weight:normal;\">Single Values:</span></h2>"; for (Map.Entry<String, Object> entry : vertexMap.entrySet()) { res += "<li><span style=\"font-family:verdana,geneva,sans-serif;font-size:10px;\">Vertex id: " + entry.getKey() + " Value: " + entry.getValue() + "</span></li>"; } res += "</ul><p> </p></body></html>"; return res; } /** * Sets the formatted text for the execution of the Triad Census * * @param vertexMap * @return HTML-formatted String */ private String setTriadCensusText(Map<String, Object> vertexMap) { String res = "<!doctype html><html><head><title>Execution Results</title><style type=\"text/css\"></style>" + "</head>" + "<body>" + "<h1><span style=\"font-family:verdana,geneva,sans-serif;font-size:12px;font-weight:normal\">Execution Results</span></h1>" + "<h2><span style=\"font-family:verdana,geneva,sans-serif;font-size:11px;font-weight:normal;\">Triad Census Values:</span></h2>"; for (Map.Entry<String, Object> entry : vertexMap.entrySet()) { res += "<li><span style=\"font-family:verdana,geneva,sans-serif;font-size:10px;\">Triad type: " + entry.getKey() + " Value: " + entry.getValue() + "</span></li>"; } res += "</ul><p> </p></body></html>"; return res; } /** * Sets the formatted text for the network properties * * @param props * @return HTML-formatted String */ private String setPropertyText(GraphProperties props) { String res = "<!doctype html><html><head><title>Execution Results</title><style type=\"text/css\">" + "table.tablestyle {border-collapse:collapse}" + "table.tablestyle td {border: 2px solid #000000; font-family:verdana,geneva,sans-serif;font-size:10px;font-weight:normal;text-align: left; padding: 5px;}" + "table.tablestyle th {border: 2px solid #000000; font-family:verdana,geneva,sans-serif;font-size:11px;font-weight:bold;text-align:left; padding: 5px;}" + "</style>" + "</head>" + "<body>" + "<table class = \"tablestyle\">" + "<tr><th>Property</th><th>Value</th></tr>" + "<tr><td>Size</td><td>" + props.calcSize() + "</td></tr>" + "<tr><td>Density</td><td>" + props.calcDensity() + "</td></tr>" + "<tr><td>Diameter</td><td>" + props.calcDiameter() + "</td></tr>" + "<tr><td>Reciprocity</td><td>" + props.calcReciprocity() + "</td></tr>" + "</table></body></html>"; return res; } }