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 UserInterface.AdministrativeRole; import Business.Enterprise.Enterprise; import Business.Organization.AdminOrganization; import Business.Organization.CollectionCenterOrganization; import Business.Organization.LabOrganization; import Business.Organization.Organization; import Business.Organization.ResearchOrganization; import Business.UserAccount.UserAccount; import Business.WorkQueue.FarmerFeedbackWorkRequest; import Business.WorkQueue.WorkRequest; import UserInterface.SignUpJPanel; import UserInterface.SystemAdminRole.ManageNetworkJPanel; import java.awt.CardLayout; import java.awt.Color; import java.awt.Graphics; import java.awt.Image; import java.awt.image.BufferedImage; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; import javax.imageio.ImageIO; 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.PiePlot; import org.jfree.chart.plot.PlotOrientation; import org.jfree.data.category.DefaultCategoryDataset; import org.jfree.data.general.DefaultPieDataset; /** * * @author Lenovo */ public class ReportsJPanel extends javax.swing.JPanel { /** * Creates new form ReportsJPanel */ private JPanel userProcessContainer; private Enterprise enterprise; private Image image2; ReportsJPanel(JPanel userProcessContainer, Enterprise enterprise) { initComponents(); this.userProcessContainer = userProcessContainer; this.enterprise = enterprise; backgroundImage("/resources/imgs/HP2.jpg"); } private void backgroundImage(String str) { try { BufferedImage image1 = ImageIO.read(ManageNetworkJPanel.class.getResource(str)); image2 = image1.getScaledInstance(1200, 800, Image.SCALE_SMOOTH); } catch (IOException ex) { Logger.getLogger(SignUpJPanel.class.getName()).log(Level.SEVERE, null, ex); } } public void paintComponent(Graphics g) { super.paintComponent(g); // Draw the background image. g.drawImage(image2, 0, 0, this); } /** * 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(); jLabel7 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); Report = new javax.swing.JButton(); resultSatisfactionBtn = new javax.swing.JButton(); appEasyReportBtn = new javax.swing.JButton(); ApplicationUsageBtn = new javax.swing.JButton(); deptOpenRequestBtn = new javax.swing.JButton(); jLabel3 = new javax.swing.JLabel(); backBtn = new javax.swing.JButton(); jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N jLabel1.setText("ENTERPRISE REPORT ANALYSIS AND MANAGEMENT"); jLabel7.setIcon( new javax.swing.ImageIcon(getClass().getResource("/resources/imgs/agronomyAdvancement.JPG"))); // NOI18N jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N jLabel2.setText("Farmer Feedbacks Analysis"); Report.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N Report.setText("OverAll Rating Report"); Report.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { ReportActionPerformed(evt); } }); resultSatisfactionBtn.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N resultSatisfactionBtn.setText("Result Satisfaction Report"); resultSatisfactionBtn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { resultSatisfactionBtnActionPerformed(evt); } }); appEasyReportBtn.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N appEasyReportBtn.setText("Application Usage Ease Level"); appEasyReportBtn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { appEasyReportBtnActionPerformed(evt); } }); ApplicationUsageBtn.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N ApplicationUsageBtn.setText("Application Usage Report"); ApplicationUsageBtn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { ApplicationUsageBtnActionPerformed(evt); } }); deptOpenRequestBtn.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N deptOpenRequestBtn.setText("Department performance"); deptOpenRequestBtn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { deptOpenRequestBtnActionPerformed(evt); } }); jLabel3.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N jLabel3.setText("Enterprise Performance Tracker"); backBtn.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N backBtn.setText("<<Back"); backBtn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { backBtnActionPerformed(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().addComponent(jLabel7).addGap(0, 20, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup().addGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout .createSequentialGroup().addGap(181, 181, 181).addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup( javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addGap(8, 8, 8).addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 199, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addComponent(resultSatisfactionBtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(Report, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(appEasyReportBtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) .addGap(178, 178, 178) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 233, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addComponent(ApplicationUsageBtn, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 219, Short.MAX_VALUE) .addComponent(deptOpenRequestBtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))) .addGroup(layout.createSequentialGroup().addGap(236, 236, 236).addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 489, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup().addGap(478, 478, 478).addComponent(backBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(30, 30, 30).addComponent(jLabel1).addGap(75, 75, 75) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel2).addComponent(jLabel3)) .addGap(26, 26, 26) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(ApplicationUsageBtn).addComponent(Report)) .addGap(27, 27, 27) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(resultSatisfactionBtn).addComponent(deptOpenRequestBtn)) .addGap(27, 27, 27).addComponent(appEasyReportBtn) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(backBtn).addGap(52, 52, 52))); }// </editor-fold>//GEN-END:initComponents private void ReportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ReportActionPerformed // TODO add your handling code here: int countBad = 0; int countGood = 0; int countExcellent = 0; for (Organization organization : enterprise.getOrganizationDirectory().getOrganizationList()) { if (organization instanceof AdminOrganization) { for (FarmerFeedbackWorkRequest request : organization.getFeedbackWorkQueue() .getFarmerFeedbackList()) { if (request.getOverallRating().equalsIgnoreCase("Bad")) { countBad++; } else if (request.getOverallRating().equalsIgnoreCase("Good")) { countGood++; } else if (request.getOverallRating().equalsIgnoreCase("Excellent")) { countExcellent++; } } break; } } float total = countBad + countGood + countExcellent; float pGood = (countGood / total) * 100; float pBad = (countBad / total) * 100; float pExcellent = (countExcellent / total) * 100; DefaultPieDataset pieDataSet = new DefaultPieDataset(); pieDataSet.setValue("Bad%: " + pBad, pGood); pieDataSet.setValue("Good%: " + pGood, pBad); pieDataSet.setValue("Excellent%: " + pExcellent, pExcellent); JFreeChart chart = ChartFactory.createPieChart("Overall Application Rating", pieDataSet, true, true, true); PiePlot plot = (PiePlot) chart.getPlot(); ChartFrame frame = new ChartFrame("Overall Application Rating", chart); frame.setVisible(true); frame.setSize(500, 500); }//GEN-LAST:event_ReportActionPerformed private void resultSatisfactionBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_resultSatisfactionBtnActionPerformed // TODO add your handling code here: int notSatisfied = 0; int somewhatSatisfied = 0; int verySatisfied = 0; int notApplicable = 0; for (Organization organization : enterprise.getOrganizationDirectory().getOrganizationList()) { if (organization instanceof AdminOrganization) { for (FarmerFeedbackWorkRequest request : organization.getFeedbackWorkQueue() .getFarmerFeedbackList()) { if (request.getResearchSolutionHelped().equalsIgnoreCase("Not Satisfied")) { notSatisfied++; } else if (request.getResearchSolutionHelped().equalsIgnoreCase("Somewhat Satisfied")) { somewhatSatisfied++; } else if (request.getResearchSolutionHelped().equalsIgnoreCase("Very Satisfied")) { verySatisfied++; } else { notApplicable++; } } break; } } DefaultCategoryDataset dataSet = new DefaultCategoryDataset(); dataSet.setValue(notSatisfied, "", "Not Satisfied"); dataSet.setValue(somewhatSatisfied, "", "Somewhat Satisfied"); dataSet.setValue(verySatisfied, "", "Very Satisfied"); dataSet.setValue(notApplicable, "", "Not Applicable"); JFreeChart chart = ChartFactory.createBarChart("Research Result Satisfaction", "Satisfaction Level", "Number of Farmers", dataSet, PlotOrientation.VERTICAL, false, true, false); CategoryPlot plot = chart.getCategoryPlot(); plot.setRangeGridlinePaint(Color.black); ChartFrame frame = new ChartFrame("Result Satisfaction", chart); frame.setVisible(true); frame.setSize(700, 500); }//GEN-LAST:event_resultSatisfactionBtnActionPerformed private void appEasyReportBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_appEasyReportBtnActionPerformed // TODO add your handling code here: int countEasy = 0; int countSomewhat = 0; int countVery = 0; for (Organization organization : enterprise.getOrganizationDirectory().getOrganizationList()) { if (organization instanceof AdminOrganization) { for (FarmerFeedbackWorkRequest request : organization.getFeedbackWorkQueue() .getFarmerFeedbackList()) { if (request.getSiteUserFriendly().equalsIgnoreCase("Easy To Use")) { countEasy++; } else if (request.getSiteUserFriendly().equalsIgnoreCase("Somewhat Difficult")) { countSomewhat++; } else if (request.getSiteUserFriendly().equalsIgnoreCase("Very Difficult")) { countVery++; } } break; } } float total = countEasy + countSomewhat + countVery; float pEasy = (countEasy / total) * 100; float pSomewhat = (countSomewhat / total) * 100; float pVery = (countVery / total) * 100; DefaultPieDataset pieDataSet = new DefaultPieDataset(); pieDataSet.setValue("Easy To Use%: " + pEasy, pEasy); pieDataSet.setValue("Somewhat Difficult%: " + pSomewhat, pSomewhat); pieDataSet.setValue("Very Difficult%: " + pVery, pVery); JFreeChart chart = ChartFactory.createPieChart("Application Easiness Level", pieDataSet, true, true, true); PiePlot plot = (PiePlot) chart.getPlot(); ChartFrame frame = new ChartFrame("Application Easiness Level", chart); frame.setVisible(true); frame.setSize(500, 500); }//GEN-LAST:event_appEasyReportBtnActionPerformed private void ApplicationUsageBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ApplicationUsageBtnActionPerformed // TODO add your handling code here: int countResearch = 0; int countSale = 0; int countBoth = 0; for (Organization org : enterprise.getOrganizationDirectory().getOrganizationList()) { for (UserAccount userAccount : org.getUserAccountDirectory().getUserAccountList()) { if (userAccount.getFarmer() != null) { if (userAccount.getWorkQueue().getWorkRequestList().size() > 0 && userAccount.getMarketWorkQueue().getMarkerWorkRequestList().isEmpty()) { countResearch++; } else if (userAccount.getWorkQueue().getWorkRequestList().isEmpty() && userAccount.getMarketWorkQueue().getMarkerWorkRequestList().size() > 0) { countSale++; } else if (userAccount.getWorkQueue().getWorkRequestList().size() > 0 && userAccount.getMarketWorkQueue().getMarkerWorkRequestList().size() > 0) { countBoth++; } } } } float total = countResearch + countSale + countBoth; float pResearch = (countResearch / total) * 100; float pSale = (countSale / total) * 100; float pBoth = (countBoth / total) * 100; DefaultPieDataset pieDataSet = new DefaultPieDataset(); pieDataSet.setValue("Farmers Using Soil Research Facility: " + pResearch + "%", pResearch); pieDataSet.setValue("Farmers Using Sale Facility: " + pSale + "%", pSale); pieDataSet.setValue("Farmers Using Both Facility " + pBoth + "%", pBoth); JFreeChart chart = ChartFactory.createPieChart("Application Usage Study", pieDataSet, true, true, true); PiePlot plot = (PiePlot) chart.getPlot(); ChartFrame frame = new ChartFrame("Application Usage Study", chart); frame.setVisible(true); frame.setSize(500, 500); }//GEN-LAST:event_ApplicationUsageBtnActionPerformed private void deptOpenRequestBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deptOpenRequestBtnActionPerformed // TODO add your handling code here: int countCollection = 0; int countLab = 0; int countResearch = 0; for (Organization org : enterprise.getOrganizationDirectory().getOrganizationList()) { if (org instanceof CollectionCenterOrganization) { for (WorkRequest request : org.getWorkQueue().getWorkRequestList()) { if (request.getStatus().equalsIgnoreCase("Pending With Collection Center")) { countCollection++; } } } else if (org instanceof LabOrganization) { for (WorkRequest request : org.getWorkQueue().getWorkRequestList()) { if (request.getStatus().equalsIgnoreCase("Pending With Lab")) { countLab++; } } } else if (org instanceof ResearchOrganization) { for (WorkRequest request : org.getWorkQueue().getWorkRequestList()) { if (request.getStatus().equalsIgnoreCase("Sent For Research")) { countResearch++; } } } } float total = countCollection + countLab + countResearch; float pCollection = (countCollection / total) * 100; float pLab = (countLab / total) * 100; float pResearch = (countResearch / total) * 100; DefaultPieDataset pieDataSet = new DefaultPieDataset(); pieDataSet.setValue("Requests Pending With Collection Center: " + pCollection + "%", pCollection); pieDataSet.setValue("Requests Pending With Lab: " + pLab + "%", pLab); pieDataSet.setValue("Requests Pending With Research Wing: " + pResearch + "%", pResearch); JFreeChart chart = ChartFactory.createPieChart("Department Specific Pending Task", pieDataSet, true, true, true); PiePlot plot = (PiePlot) chart.getPlot(); ChartFrame frame = new ChartFrame("Department Specific Pending Task", chart); frame.setVisible(true); frame.setSize(500, 500); }//GEN-LAST:event_deptOpenRequestBtnActionPerformed private void backBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backBtnActionPerformed // TODO add your handling code here: userProcessContainer.remove(this); CardLayout layout = (CardLayout) userProcessContainer.getLayout(); layout.previous(userProcessContainer); }//GEN-LAST:event_backBtnActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton ApplicationUsageBtn; private javax.swing.JButton Report; private javax.swing.JButton appEasyReportBtn; private javax.swing.JButton backBtn; private javax.swing.JButton deptOpenRequestBtn; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel7; private javax.swing.JButton resultSatisfactionBtn; // End of variables declaration//GEN-END:variables }