userInterface.MonitoringTeamRole.AnalysisJPanel.java Source code

Java tutorial

Introduction

Here is the source code for userInterface.MonitoringTeamRole.AnalysisJPanel.java

Source

/*
 * 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 userInterface.MonitoringTeamRole;

import Business.EcoSystem;
import java.awt.CardLayout;
import java.awt.Color;
import javafx.stage.FileChooser;
import javax.swing.JPanel;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.general.PieDataset;

/**
 *
 * @author jayal
 */
public class AnalysisJPanel extends javax.swing.JPanel {

    JPanel userProcessContainer;
    EcoSystem system;

    // System.out.println(MainJFrame.);
    /**
     * Creates new form AnalysisJPanel
     */
    public AnalysisJPanel(JPanel userProcessContainer, EcoSystem system) {
        initComponents();
        this.userProcessContainer = userProcessContainer;
        this.system = system;

    }

    /**
     * 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.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        rawlogsJCombobox = new javax.swing.JComboBox();
        jButton2 = new javax.swing.JButton();

        setBackground(new java.awt.Color(255, 255, 255));
        setLayout(null);

        jLabel1.setFont(new java.awt.Font("Tw Cen MT", 2, 18)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(255, 0, 0));
        jLabel1.setText("Raw Logs");
        jLabel1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel1MouseClicked(evt);
            }
        });
        add(jLabel1);
        jLabel1.setBounds(290, 110, 66, 21);

        jLabel2.setFont(new java.awt.Font("Tw Cen MT", 2, 18)); // NOI18N
        jLabel2.setForeground(new java.awt.Color(255, 0, 0));
        jLabel2.setText("Alarms");
        jLabel2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel2MouseClicked(evt);
            }
        });
        add(jLabel2);
        jLabel2.setBounds(300, 200, 48, 21);

        rawlogsJCombobox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Employees", "Customers" }));
        rawlogsJCombobox.setEnabled(false);
        rawlogsJCombobox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rawlogsJComboboxActionPerformed(evt);
            }
        });
        add(rawlogsJCombobox);
        rawlogsJCombobox.setBounds(410, 110, 107, 20);

        jButton2.setBackground(new java.awt.Color(255, 255, 255));
        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/home.png"))); // NOI18N
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        add(jButton2);
        jButton2.setBounds(0, 0, 83, 61);
    }// </editor-fold>//GEN-END:initComponents

    private void rawlogsJComboboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rawlogsJComboboxActionPerformed
        String selecteditem = (String) rawlogsJCombobox.getSelectedItem();
        if (selecteditem.equalsIgnoreCase("employees")) {

            // TODO add your handling code here:

            FileChooser f = new FileChooser();
            try

            {
                Runtime.getRuntime().exec("rundll32 url.dll, FileProtocolHandler "
                        + "C:\\Users\\jayal\\Desktop\\NEU\\AED Applications\\ProjectAED\\BankStaffSessions.txt");

            }

            catch (Exception e) {

            }
        }
        if (selecteditem.equalsIgnoreCase("customers"))

        {

            FileChooser f = new FileChooser();
            try

            {
                Runtime.getRuntime().exec("rundll32 url.dll, FileProtocolHandler "
                        + "C:\\Users\\jayal\\Desktop\\NEU\\AED Applications\\ProjectAED\\Session Monitoring.txt");

            }

            catch (Exception e) {

            }

        }

    }//GEN-LAST:event_rawlogsJComboboxActionPerformed

    private void jLabel1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel1MouseClicked
        // TODO add your handling code here:
        rawlogsJCombobox.setEnabled(true);
    }//GEN-LAST:event_jLabel1MouseClicked

    private void jLabel2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel2MouseClicked
        // TODO add your handling code here:

        JFreeChart chart = createChart(createDataset());
        chart.setBackgroundPaint(Color.YELLOW);
        chart.getTitle().setPaint(Color.red);

        ChartFrame frame = new ChartFrame("XYChart", chart);
        frame.setVisible(true);
        frame.setSize(450, 500);
    }//GEN-LAST:event_jLabel2MouseClicked

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:

        userProcessContainer.remove(this);
        CardLayout layout = (CardLayout) userProcessContainer.getLayout();
        layout.previous(userProcessContainer);
    }//GEN-LAST:event_jButton2ActionPerformed

    private static JFreeChart createChart(PieDataset dataset) {
        JFreeChart chart = ChartFactory.createPieChart("Suspicious Events: Network based & User-profiling based", // chart title 
                dataset, // data    
                true, // include legend   
                true, false);

        return chart;
    }

    private PieDataset createDataset() {
        DefaultPieDataset dataset = new DefaultPieDataset();
        dataset.setValue("User Profiling Suspicious events", system.numberofsuspiciousevents);
        dataset.setValue("Network based suspicious events", system.networksuspiciousevents);
        return dataset;

    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JComboBox rawlogsJCombobox;
    // End of variables declaration//GEN-END:variables
}