UserInterface.StoreManager.StoreReportsPanel.java Source code

Java tutorial

Introduction

Here is the source code for UserInterface.StoreManager.StoreReportsPanel.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.StoreManager;

import Business.Comparison.Comparison;
import Business.Enterprise.Enterprise;
import Business.Item.ShelfItem;
import Business.Organization.Organization;
import Business.Organization.StoreKeeperOrganization;
import Business.Product.Product;
import Business.Shelf.Shelf;
import Business.UserAccount.UserAccount;
import Business.WorkQueue.WorkRequest;
import java.awt.Color;
import java.util.ArrayList;
import java.util.Collections;
import javax.swing.JPanel;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;

/**
 *
 * @author Prasad
 */
public class StoreReportsPanel extends javax.swing.JPanel {

    /**
     * Creates new form StoreReportsPanel
     */

    JPanel userProcessContainer;
    Enterprise enterprise;

    StoreReportsPanel(JPanel userProcessContainer, Enterprise enterprise) {
        initComponents();
        this.userProcessContainer = userProcessContainer;
        this.enterprise = enterprise;

    }

    /**
     * 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() {

        storeReportsPanel = new javax.swing.JLabel();
        productReportButton = new javax.swing.JButton();
        shelfReportsButton = new javax.swing.JButton();
        storeKeeperButton = new javax.swing.JButton();

        setBackground(java.awt.Color.white);

        storeReportsPanel.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        storeReportsPanel.setText("Store Reports");

        productReportButton.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        productReportButton.setText("Product Report");
        productReportButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                productReportButtonActionPerformed(evt);
            }
        });

        shelfReportsButton.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        shelfReportsButton.setText("Shelf Report");
        shelfReportsButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                shelfReportsButtonActionPerformed(evt);
            }
        });

        storeKeeperButton.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        storeKeeperButton.setText("Store Keeper Report");
        storeKeeperButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                storeKeeperButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addContainerGap(215, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                        .addComponent(shelfReportsButton, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                119, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(121, 121, 121).addComponent(productReportButton)
                                        .addGap(150, 150, 150))
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                        layout.createSequentialGroup().addComponent(storeReportsPanel).addGap(323,
                                                323, 323))
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                        .addComponent(storeKeeperButton).addGap(292, 292, 292)))));

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL,
                new java.awt.Component[] { productReportButton, shelfReportsButton, storeKeeperButton });

        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addGap(24, 24, 24)
                        .addComponent(storeReportsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 38,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(131, 131, 131)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(shelfReportsButton, javax.swing.GroupLayout.PREFERRED_SIZE, 49,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(productReportButton))
                        .addGap(78, 78, 78).addComponent(storeKeeperButton).addContainerGap(162, Short.MAX_VALUE)));

        layout.linkSize(javax.swing.SwingConstants.VERTICAL,
                new java.awt.Component[] { productReportButton, shelfReportsButton, storeKeeperButton });

    }// </editor-fold>//GEN-END:initComponents

    private void productReportButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_productReportButtonActionPerformed
        // TODO add your handling code here:
        ArrayList<Comparison> cmp1 = new ArrayList<>();

        for (Product p : enterprise.getProductCatalog().getProductList()) {
            Comparison c = new Comparison(p.getName(), p.getSearchCount());
            cmp1.add(c);
        }

        Collections.sort(cmp1);

        DefaultCategoryDataset dataset = new DefaultCategoryDataset();

        dataset.setValue(cmp1.get(0).getNumber(), "SearchCount", cmp1.get(0).getString());
        dataset.setValue(cmp1.get(1).getNumber(), "SearchCount", cmp1.get(1).getString());
        dataset.setValue(cmp1.get(2).getNumber(), "SearchCount", cmp1.get(2).getString());

        JFreeChart chart = ChartFactory.createBarChart("Top 3 Searched Products", "Products", "SearchCounts",
                dataset, PlotOrientation.VERTICAL, false, true, false);
        CategoryPlot p = chart.getCategoryPlot();
        p.setRangeGridlinePaint(Color.BLUE);
        ChartFrame frame = new ChartFrame("Search Report", chart);
        frame.setVisible(true);
        frame.setSize(600, 400);
    }//GEN-LAST:event_productReportButtonActionPerformed

    private void storeKeeperButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_storeKeeperButtonActionPerformed
        // TODO add your handling code here:
        ArrayList<Comparison> cmp1 = new ArrayList<>();
        int x = 0;
        for (Organization org : enterprise.getOrganizationDirectory().getOrganizationList()) {
            if (org instanceof StoreKeeperOrganization) {
                System.out.println("Hi");
                for (UserAccount ua : org.getUserAccountDirectory().getUserAccountList()) {
                    x = 0;
                    for (WorkRequest w : ua.getWorkQueue().getWorkRequestList()) {
                        x++;
                    }
                    Comparison c = new Comparison(ua.getEmployee().getName(), x);
                    cmp1.add(c);
                }

            }

        }

        Collections.sort(cmp1);

        DefaultCategoryDataset dataset = new DefaultCategoryDataset();

        if (cmp1.size() >= 3) {
            dataset.setValue(cmp1.get(0).getNumber(), "WorkRequests", cmp1.get(0).getString());
            dataset.setValue(cmp1.get(1).getNumber(), "WorkRequests", cmp1.get(1).getString());
            dataset.setValue(cmp1.get(2).getNumber(), "WorkRequests", cmp1.get(2).getString());
        } else {
            for (Comparison c : cmp1) {
                dataset.setValue(c.getNumber(), "WorkRequests", c.getString());
            }
        }
        JFreeChart chart = ChartFactory.createBarChart("Top StoreKeepers", "Storekeepers",
                "No of Workrequests Solved", dataset, PlotOrientation.VERTICAL, false, true, false);
        CategoryPlot p = chart.getCategoryPlot();
        p.setRangeGridlinePaint(Color.BLUE);
        ChartFrame frame = new ChartFrame("StoreKeeper Report", chart);
        frame.setVisible(true);
        frame.setSize(600, 400);

    }//GEN-LAST:event_storeKeeperButtonActionPerformed

    private void shelfReportsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_shelfReportsButtonActionPerformed
        // TODO add your handling code here:
        ArrayList<Comparison> cmp1 = new ArrayList<>();

        for (Shelf s1 : enterprise.getShelfDirectory().getShelfDirectory()) {
            int xcount = 0;
            for (ShelfItem si : s1.getShelfList()) {
                xcount = xcount + si.getQuantity();
            }
            Comparison c = new Comparison("Shelf " + s1.getShelfID(), xcount);
            cmp1.add(c);
        }

        Collections.sort(cmp1);

        DefaultCategoryDataset dataset = new DefaultCategoryDataset();

        dataset.setValue(cmp1.get(cmp1.size() - 1).getNumber(), "Products", cmp1.get(cmp1.size() - 1).getString());
        dataset.setValue(cmp1.get(cmp1.size() - 2).getNumber(), "Products", cmp1.get(cmp1.size() - 2).getString());
        dataset.setValue(cmp1.get(cmp1.size() - 3).getNumber(), "Products", cmp1.get(cmp1.size() - 3).getString());

        JFreeChart chart = ChartFactory.createBarChart(
                "Top 3 mostly visited shelfs based on no of products remaining", "Products",
                "No of products Remaining", dataset, PlotOrientation.VERTICAL, false, true, false);
        CategoryPlot p = chart.getCategoryPlot();
        p.setRangeGridlinePaint(Color.BLUE);
        ChartFrame frame = new ChartFrame("Mostly visited Shelf Report", chart);
        frame.setVisible(true);
        frame.setSize(600, 400);

    }//GEN-LAST:event_shelfReportsButtonActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton productReportButton;
    private javax.swing.JButton shelfReportsButton;
    private javax.swing.JButton storeKeeperButton;
    private javax.swing.JLabel storeReportsPanel;
    // End of variables declaration//GEN-END:variables
}