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.SystemAdmin; import Business.Customer.Customer; import Business.Customer.WaterUsage; import Business.EcoSystem; import Business.Employee.Employee; import Business.Enterprise.Enterprise; import Business.Enterprise.RepairEnterprise; import Business.Enterprise.WaterEnterprise; import Business.ExcelReportCreator; import Business.Network.Network; import Business.Organization.CustomerOrganization; import Business.Organization.Organization; import Business.Organization.RepairManagerOrganization; import Business.WaterSupplyAdmin.SensorValue; import Business.WorkQueue.RepairRequest; import Business.WorkQueue.WorkRequest; import java.awt.CardLayout; import java.awt.Color; import java.awt.Desktop; import java.io.File; import java.io.IOException; import java.util.ArrayList; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.table.DefaultTableModel; 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.PiePlot3D; import org.jfree.chart.plot.PlotOrientation; import org.jfree.data.category.DefaultCategoryDataset; import org.jfree.data.general.DefaultPieDataset; import org.jfree.ui.RefineryUtilities; /** * * @author Bhavesh Patel */ public class ReportsJPanel extends javax.swing.JPanel { /** * Creates new form ReportsJPanel */ private JPanel userProcessContainer; private EcoSystem system; private Customer c; public ReportsJPanel(JPanel userProcessContainer, EcoSystem system) { initComponents(); this.userProcessContainer = userProcessContainer; this.system = system; populateComboBox(); populateTotalBIllGenerated(); } private void populateComboBox() { networkJComboBox.removeAllItems(); for (Network network : system.getNetworkList()) { networkJComboBox.addItem(network); } } private void populateTotalBIllGenerated() { int total = 0; if (system.getNetworkList().size() == 0) { totalBillTxt.setText(""); return; } for (Network network : system.getNetworkList()) { for (Enterprise enterprise : network.getEnterpriseDirectory().getEnterpriseList()) { if (enterprise instanceof WaterEnterprise) { for (Organization organization : enterprise.getOrganizationDirectory().getOrganizationList()) { if (organization instanceof CustomerOrganization) { for (Employee employee : organization.getEmployeeDirectory().getEmployeeList()) { Customer customer = (Customer) employee; total += customer.getTotalBill(); } } } } } } totalBillTxt.setText(String.valueOf(Math.ceil(total)) + "$"); } /** * 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() { jLabel2 = new javax.swing.JLabel(); backJButton = new javax.swing.JButton(); jInternalFrame1 = new javax.swing.JInternalFrame(); repairCostTxt = new javax.swing.JTextField(); jLabel10 = new javax.swing.JLabel(); revenueTxt = new javax.swing.JTextField(); jLabel6 = new javax.swing.JLabel(); jLabel7 = new javax.swing.JLabel(); button = new javax.swing.JButton(); jLabel4 = new javax.swing.JLabel(); emailTxt = new javax.swing.JTextField(); note = new javax.swing.JLabel(); jLabel9 = new javax.swing.JLabel(); idTxt = new javax.swing.JTextField(); contactTxt = new javax.swing.JTextField(); jLabel3 = new javax.swing.JLabel(); jLabel1 = new javax.swing.JLabel(); jLabel8 = new javax.swing.JLabel(); jLabel11 = new javax.swing.JLabel(); customerNameTxt = new javax.swing.JTextField(); billTxt = new javax.swing.JTextField(); jLabel12 = new javax.swing.JLabel(); jLabel13 = new javax.swing.JLabel(); usageTxt = new javax.swing.JTextField(); networkJComboBox = new javax.swing.JComboBox(); leakageVolumeTxt = new javax.swing.JTextField(); jLabel5 = new javax.swing.JLabel(); jInternalFrame2 = new javax.swing.JInternalFrame(); jLabel16 = new javax.swing.JLabel(); jLabel15 = new javax.swing.JLabel(); excel = new javax.swing.JButton(); jLabel19 = new javax.swing.JLabel(); spinner = new javax.swing.JSpinner(); usage = new javax.swing.JButton(); totalBillTxt = new javax.swing.JTextField(); jSeparator2 = new javax.swing.JSeparator(); flow = new javax.swing.JButton(); jButton3 = new javax.swing.JButton(); jToggleButton2 = new javax.swing.JToggleButton(); jLabel14 = new javax.swing.JLabel(); jLabel17 = new javax.swing.JLabel(); noteCust = new javax.swing.JLabel(); jToggleButton1 = new javax.swing.JToggleButton(); jScrollPane1 = new javax.swing.JScrollPane(); customerTable = new javax.swing.JTable(); jSeparator3 = new javax.swing.JSeparator(); jSeparator4 = new javax.swing.JSeparator(); jLabel18 = new javax.swing.JLabel(); searchTxt = new javax.swing.JTextField(); jLabel20 = new javax.swing.JLabel(); setBackground(new java.awt.Color(255, 255, 255)); jLabel2.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N jLabel2.setText("Summary Reports"); backJButton.setText("<< Back"); backJButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { backJButtonActionPerformed(evt); } }); jInternalFrame1.setVisible(true); repairCostTxt.setEditable(false); jLabel10.setText("Total Usage"); revenueTxt.setEditable(false); jLabel6.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N jLabel6.setText("Leakage Summary"); jLabel7.setText("Customer Name"); button.setText("Usage Graph"); button.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { buttonActionPerformed(evt); } }); jLabel4.setText("Total Leakage Volume in this network"); emailTxt.setEditable(false); note.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N jLabel9.setText("Customer ID"); idTxt.setEditable(false); contactTxt.setEditable(false); jLabel3.setText("Total Repair Cost in this network"); jLabel1.setText("Select Network"); jLabel8.setText("Total Bill"); jLabel11.setText("Contact No."); customerNameTxt.setEditable(false); billTxt.setEditable(false); jLabel12.setText("Email ID"); jLabel13.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N jLabel13.setText("Customer with Highest Water Usage"); usageTxt.setEditable(false); usageTxt.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { usageTxtActionPerformed(evt); } }); networkJComboBox.setModel( new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); networkJComboBox.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { networkJComboBoxActionPerformed(evt); } }); leakageVolumeTxt.setEditable(false); jLabel5.setText("Total Water lost in terms of revenue"); javax.swing.GroupLayout jInternalFrame1Layout = new javax.swing.GroupLayout( jInternalFrame1.getContentPane()); jInternalFrame1.getContentPane().setLayout(jInternalFrame1Layout); jInternalFrame1Layout.setHorizontalGroup(jInternalFrame1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jInternalFrame1Layout.createSequentialGroup().addContainerGap() .addGroup(jInternalFrame1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jInternalFrame1Layout.createSequentialGroup().addComponent(button) .addGap(26, 26, 26).addComponent(note, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(jInternalFrame1Layout.createSequentialGroup().addGap(13, 13, 13) .addGroup(jInternalFrame1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jInternalFrame1Layout.createSequentialGroup() .addGroup(jInternalFrame1Layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel11).addComponent(jLabel12) .addComponent(jLabel9).addComponent(jLabel8) .addComponent(jLabel7).addComponent(jLabel10)) .addGap(76, 76, 76) .addGroup(jInternalFrame1Layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(customerNameTxt).addComponent(idTxt) .addComponent(contactTxt).addComponent(emailTxt) .addComponent(usageTxt).addComponent(billTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGroup(jInternalFrame1Layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup(jInternalFrame1Layout.createSequentialGroup() .addComponent(jLabel3) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(repairCostTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jInternalFrame1Layout.createSequentialGroup() .addComponent(jLabel4) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(leakageVolumeTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jInternalFrame1Layout.createSequentialGroup() .addComponent(jLabel5).addGap(47, 47, 47) .addComponent(revenueTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE))) .addComponent(jLabel6) .addGroup(jInternalFrame1Layout.createSequentialGroup() .addComponent(jLabel1).addGap(44, 44, 44) .addComponent(networkJComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(jLabel13)))) .addContainerGap())); jInternalFrame1Layout.setVerticalGroup(jInternalFrame1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jInternalFrame1Layout.createSequentialGroup().addContainerGap() .addGroup(jInternalFrame1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1).addComponent(networkJComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(33, 33, 33).addComponent(jLabel6).addGap(26, 26, 26) .addGroup(jInternalFrame1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(repairCostTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel3)) .addGap(40, 40, 40) .addGroup(jInternalFrame1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel4).addComponent(leakageVolumeTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(40, 40, 40) .addGroup(jInternalFrame1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(revenueTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel5)) .addGap(32, 32, 32).addComponent(jLabel13).addGap(18, 18, 18) .addGroup(jInternalFrame1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(button) .addGroup(jInternalFrame1Layout.createSequentialGroup() .addGroup(jInternalFrame1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(customerNameTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel7)) .addGap(25, 25, 25) .addGroup(jInternalFrame1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(idTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel9)) .addGap(25, 25, 25) .addGroup(jInternalFrame1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(contactTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel11)) .addGap(25, 25, 25) .addGroup(jInternalFrame1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(emailTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel12)) .addGap(25, 25, 25) .addGroup(jInternalFrame1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(usageTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel10)) .addGap(25, 25, 25) .addGroup(jInternalFrame1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel8).addComponent(billTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(42, 42, 42).addComponent(note, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGap(30, 30, 30))); jInternalFrame2.setVisible(true); jLabel16.setText("Search Using Customers Name"); jLabel15.setText("Customers with no water usage"); excel.setText("View Excel Report"); excel.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { excelActionPerformed(evt); } }); jLabel19.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N jLabel19.setText("*View excel representation of all customer data"); usage.setText("Usage Graph"); usage.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { usageActionPerformed(evt); } }); totalBillTxt.setEditable(false); jSeparator2.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED)); flow.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N flow.setText("Flow Rate Graph"); flow.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { flowActionPerformed(evt); } }); jButton3.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N jButton3.setText("Pie Chart"); jButton3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton3ActionPerformed(evt); } }); jToggleButton2.setText("Get Customers"); jToggleButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jToggleButton2ActionPerformed(evt); } }); jLabel14.setText("Customers Using Water above(Gallons)"); jLabel17.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N jLabel17.setText("*Summarized view of total Water Usage per Customer in the ecosystem"); noteCust.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N jToggleButton1.setText("Get Customers"); jToggleButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jToggleButton1ActionPerformed(evt); } }); customerTable.setModel(new javax.swing.table.DefaultTableModel( new Object[][] { { null, null, null, null, null }, { null, null, null, null, null }, { null, null, null, null, null }, { null, null, null, null, null } }, new String[] { "Name", "ID", "Contact NO.", "Email ID", "Total Usage" })); customerTable.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { customerTableMouseClicked(evt); } }); customerTable.addKeyListener(new java.awt.event.KeyAdapter() { public void keyReleased(java.awt.event.KeyEvent evt) { customerTableKeyReleased(evt); } }); jScrollPane1.setViewportView(customerTable); jSeparator3.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED)); jSeparator4.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED)); jLabel18.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N jLabel18.setText("Total Water Bill Generated Till Today(To be collected)"); searchTxt.addKeyListener(new java.awt.event.KeyAdapter() { public void keyReleased(java.awt.event.KeyEvent evt) { searchTxtKeyReleased(evt); } }); jLabel20.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N jLabel20.setText("Overall Ecosystem Reporting"); javax.swing.GroupLayout jInternalFrame2Layout = new javax.swing.GroupLayout( jInternalFrame2.getContentPane()); jInternalFrame2.getContentPane().setLayout(jInternalFrame2Layout); jInternalFrame2Layout.setHorizontalGroup(jInternalFrame2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jInternalFrame2Layout.createSequentialGroup().addGroup(jInternalFrame2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jInternalFrame2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(jInternalFrame2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jInternalFrame2Layout.createSequentialGroup().addGap(44, 44, 44) .addGroup(jInternalFrame2Layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jInternalFrame2Layout.createSequentialGroup() .addComponent(jLabel19).addGap(47, 47, 47) .addComponent(excel)) .addGroup(jInternalFrame2Layout.createSequentialGroup() .addGap(6, 6, 6) .addGroup(jInternalFrame2Layout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel17) .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGroup(jInternalFrame2Layout.createSequentialGroup() .addGap(1, 1, 1).addComponent(jLabel18) .addGap(30, 30, 30).addComponent(totalBillTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)))) .addGroup(jInternalFrame2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup(jInternalFrame2Layout.createSequentialGroup() .addGap(30, 30, 30) .addGroup(jInternalFrame2Layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jInternalFrame2Layout .createSequentialGroup() .addGroup(jInternalFrame2Layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel15) .addComponent(jLabel14) .addComponent(jLabel16)) .addGap(18, 18, 18) .addGroup(jInternalFrame2Layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent(searchTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(jInternalFrame2Layout .createSequentialGroup() .addComponent(spinner, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addComponent( jToggleButton1)) .addComponent(jToggleButton2))) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 538, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(noteCust, javax.swing.GroupLayout.PREFERRED_SIZE, 330, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(jInternalFrame2Layout .createSequentialGroup().addComponent(usage) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(flow))) .addGap(0, 0, Short.MAX_VALUE)) .addComponent(jSeparator2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 562, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGroup(jInternalFrame2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jSeparator4, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 1, Short.MAX_VALUE) .addComponent(jSeparator3, javax.swing.GroupLayout.Alignment.TRAILING))) .addGroup(jInternalFrame2Layout.createSequentialGroup().addGap(145, 145, 145) .addComponent(jLabel20))) .addContainerGap())); jInternalFrame2Layout.setVerticalGroup(jInternalFrame2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jInternalFrame2Layout.createSequentialGroup().addContainerGap().addComponent(jLabel20) .addGap(20, 20, 20) .addGroup(jInternalFrame2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel14) .addComponent(spinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jToggleButton1)) .addGap(28, 28, 28) .addGroup(jInternalFrame2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel15).addComponent(jToggleButton2)) .addGap(26, 26, 26) .addGroup(jInternalFrame2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel16).addComponent(searchTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addComponent(noteCust, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(20, 20, 20) .addGroup(jInternalFrame2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(usage) .addComponent(flow)) .addGap(26, 26, 26) .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 13, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18).addComponent(jLabel17) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jButton3) .addGap(18, 18, 18) .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 13, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addGroup(jInternalFrame2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(excel) .addComponent(jLabel19)) .addGap(18, 18, 18) .addComponent(jSeparator4, javax.swing.GroupLayout.PREFERRED_SIZE, 13, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addGroup(jInternalFrame2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel18).addComponent(totalBillTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(75, 75, 75))); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGap(398, 398, 398).addComponent(jLabel2)) .addGroup(layout.createSequentialGroup().addGap(30, 30, 30).addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(backJButton) .addGroup(layout.createSequentialGroup() .addComponent(jInternalFrame1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18).addComponent(jInternalFrame2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))) .addContainerGap(447, Short.MAX_VALUE))); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addContainerGap().addComponent(jLabel2).addGap(23, 23, 23) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jInternalFrame2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jInternalFrame1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(20, 20, 20).addComponent(backJButton).addGap(35, 35, 35))); }// </editor-fold>//GEN-END:initComponents private void backJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backJButtonActionPerformed userProcessContainer.remove(this); CardLayout layout = (CardLayout) userProcessContainer.getLayout(); layout.previous(userProcessContainer); }//GEN-LAST:event_backJButtonActionPerformed private void networkJComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_networkJComboBoxActionPerformed Network network = (Network) networkJComboBox.getSelectedItem(); int repairTotal = 0; int leakageCost = 0; int leakageWaterLost = 0; double total = 0; c = null; if (network != null) { for (Enterprise enterprise : network.getEnterpriseDirectory().getEnterpriseList()) { if (enterprise instanceof RepairEnterprise) { for (Organization organization : enterprise.getOrganizationDirectory().getOrganizationList()) { if (organization instanceof RepairManagerOrganization) { for (WorkRequest workRequest : organization.getWorkQueue().getWorkRequestList()) { RepairRequest repairRequest = (RepairRequest) workRequest; if (repairRequest.getStatus().equalsIgnoreCase("Complete")) repairTotal += repairRequest.getRepairCost(); leakageCost += repairRequest.getLeakageCost(); leakageWaterLost += repairRequest.getLeakageVolume(); } } } } } for (Enterprise enterprise : network.getEnterpriseDirectory().getEnterpriseList()) { if (enterprise instanceof WaterEnterprise) { for (Organization organization : enterprise.getOrganizationDirectory().getOrganizationList()) { if (organization instanceof CustomerOrganization) { for (Employee employee : organization.getEmployeeDirectory().getEmployeeList()) { Customer customer = (Customer) employee; if (customer.getTotalUsageVolume() > total) { total = customer.getTotalUsageVolume(); if (total != 0) { c = customer; } else { c = null; } } } } } } } } else { repairCostTxt.setText(""); leakageVolumeTxt.setText(""); revenueTxt.setText(""); return; } repairCostTxt.setText(String.valueOf(Math.ceil(repairTotal)) + "$"); leakageVolumeTxt.setText(String.valueOf(Math.ceil(leakageWaterLost)) + " Gallons"); revenueTxt.setText(String.valueOf(Math.ceil(leakageCost)) + "$"); if (c != null) { customerNameTxt.setText(c.getName()); idTxt.setText(String.valueOf(c.getId())); contactTxt.setText(String.valueOf(c.getContactNo())); emailTxt.setText(c.getEmailId()); usageTxt.setText(String.valueOf(Math.ceil(c.getTotalUsageVolume())) + " Gallons"); billTxt.setText(String.valueOf(Math.ceil(c.getTotalBill())) + "$"); note.setText(""); button.setEnabled(true); } else { customerNameTxt.setText(""); idTxt.setText(""); contactTxt.setText(""); emailTxt.setText(""); usageTxt.setText(""); billTxt.setText(""); note.setText("*No Customer with usage available yet"); button.setEnabled(false); } }//GEN-LAST:event_networkJComboBoxActionPerformed private void usageTxtActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_usageTxtActionPerformed // TODO add your handling code here: }//GEN-LAST:event_usageTxtActionPerformed private void buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonActionPerformed if (c == null) { JOptionPane.showMessageDialog(null, "No Customer"); return; } DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (WaterUsage waterUsage : c.getWaterUsageHistory()) { dataset.setValue(waterUsage.getUsageVolume(), waterUsage.getDate(), "Usage Volume"); } JFreeChart chart = ChartFactory.createBarChart("Customer Water Usage Trends over a period of time", "Time of Usage", "Gallons", dataset, PlotOrientation.VERTICAL, true, true, true); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.cyan); ChartFrame frame = new ChartFrame("Bar Char for Weight", chart); frame.setVisible(true); frame.setSize(450, 350); }//GEN-LAST:event_buttonActionPerformed private void populateCustomers(ArrayList<Customer> c) { DefaultTableModel model = (DefaultTableModel) customerTable.getModel(); model.setRowCount(0); if (c.size() != 0) { for (Customer cust : c) { Object[] row = new Object[5]; row[0] = cust; row[1] = cust.getId(); row[2] = cust.getContactNo(); row[3] = cust.getEmailId(); row[4] = Math.ceil(cust.getTotalUsageVolume()) + " Gallons"; model.addRow(row); } noteCust.setText(""); } else { model.setRowCount(0); noteCust.setText("*Note : No customers"); } } private void jToggleButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton1ActionPerformed int a = (int) spinner.getValue(); if (a < 0) { JOptionPane.showMessageDialog(null, "Input correct volume"); return; } ArrayList<Customer> c = new ArrayList<Customer>(); for (Network network : system.getNetworkList()) { for (Enterprise enterprise : network.getEnterpriseDirectory().getEnterpriseList()) { if (enterprise instanceof WaterEnterprise) { for (Organization organization : enterprise.getOrganizationDirectory().getOrganizationList()) { if (organization instanceof CustomerOrganization) { for (Employee employee : organization.getEmployeeDirectory().getEmployeeList()) { Customer customer = (Customer) employee; if (customer.getTotalUsageVolume() > a) { c.add(customer); } } } } } } } populateCustomers(c); }//GEN-LAST:event_jToggleButton1ActionPerformed private void jToggleButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton2ActionPerformed ArrayList<Customer> c = new ArrayList<Customer>(); for (Network network : system.getNetworkList()) { for (Enterprise enterprise : network.getEnterpriseDirectory().getEnterpriseList()) { if (enterprise instanceof WaterEnterprise) { for (Organization organization : enterprise.getOrganizationDirectory().getOrganizationList()) { if (organization instanceof CustomerOrganization) { for (Employee employee : organization.getEmployeeDirectory().getEmployeeList()) { Customer customer = (Customer) employee; if (customer.getTotalUsageVolume() == 0) { c.add(customer); } } } } } } } populateCustomers(c); }//GEN-LAST:event_jToggleButton2ActionPerformed private void searchTxtKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_searchTxtKeyReleased ArrayList<Customer> c = new ArrayList<Customer>(); for (Network network : system.getNetworkList()) { for (Enterprise enterprise : network.getEnterpriseDirectory().getEnterpriseList()) { if (enterprise instanceof WaterEnterprise) { for (Organization organization : enterprise.getOrganizationDirectory().getOrganizationList()) { if (organization instanceof CustomerOrganization) { for (Employee employee : organization.getEmployeeDirectory().getEmployeeList()) { Customer customer = (Customer) employee; if (customer.getName().contains(searchTxt.getText())) { c.add(customer); } } } } } } } populateCustomers(c); }//GEN-LAST:event_searchTxtKeyReleased private void usageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_usageActionPerformed int selectedRow = customerTable.getSelectedRow(); if (selectedRow < 0) { JOptionPane.showMessageDialog(null, "Select a customer first"); return; } Customer customer = (Customer) customerTable.getValueAt(selectedRow, 0); if (customer.getWaterUsageHistory().size() == 0) { JOptionPane.showMessageDialog(null, "No water usage yet"); return; } DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (WaterUsage waterUsage : customer.getWaterUsageHistory()) { dataset.setValue(waterUsage.getUsageVolume(), waterUsage.getDate(), "Usage Volume"); } JFreeChart chart = ChartFactory.createBarChart("Customer Water Usage Trends over a period of time", "Time of Usage", "Gallons", dataset, PlotOrientation.VERTICAL, true, true, true); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.cyan); ChartFrame frame = new ChartFrame("Bar Char for Weight", chart); frame.setVisible(true); frame.setSize(450, 350); }//GEN-LAST:event_usageActionPerformed private void flowActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_flowActionPerformed int selectedRow = customerTable.getSelectedRow(); if (selectedRow < 0) { JOptionPane.showMessageDialog(null, "Select a customer first"); return; } Customer customer = (Customer) customerTable.getValueAt(selectedRow, 0); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (SensorValue sensorValue : customer.getTargetSensor().getSensorValueList()) { dataset.addValue(sensorValue.getFlowrate(), "Date", sensorValue.getDate()); } if (customer.getTargetSensor().getSensorValueList().size() == 1) { JFreeChart chart = ChartFactory.createBarChart( "Customer's water flowrate variation over a period of time", "Time of Usage", "FlowRate(gallons/sec)", dataset, PlotOrientation.VERTICAL, true, true, true); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.cyan); ChartFrame frame = new ChartFrame("Bar Char for Weight", chart); frame.setVisible(true); frame.setSize(450, 350); } else { JFreeChart chart = ChartFactory.createLineChart( "Customer's water flowrate variation over a period of time", "Time of Usage", "FlowRate(gallons/sec)", dataset, PlotOrientation.VERTICAL, true, true, true); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.cyan); ChartFrame frame = new ChartFrame("Bar Char for Weight", chart); RefineryUtilities.centerFrameOnScreen(frame); frame.setVisible(true); frame.setSize(450, 350); } }//GEN-LAST:event_flowActionPerformed private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed int total = 0; // for(Network network : system.getNetworkList()){ // for(Enterprise enterprise : network.getEnterpriseDirectory().getEnterpriseList()){ // for(Organization organization : enterprise.getOrganizationDirectory().getOrganizationList()){ // if(organization instanceof CustomerOrganization){ // for(Employee employee : organization.getEmployeeDirectory().getEmployeeList()){ // Customer customer = (Customer) employee; // total += customer.getTotalUsageVolume(); // } // } // } // } // } for (Network network : system.getNetworkList()) { for (Enterprise enterprise : network.getEnterpriseDirectory().getEnterpriseList()) { if (enterprise instanceof WaterEnterprise) { for (Organization organization : enterprise.getOrganizationDirectory().getOrganizationList()) { if (organization instanceof CustomerOrganization) { for (Employee employee : organization.getEmployeeDirectory().getEmployeeList()) { Customer customer = (Customer) employee; total += customer.getTotalUsageVolume(); } } } } } } if (total == 0) { JOptionPane.showMessageDialog(null, "No Customer has used water yet"); return; } DefaultPieDataset dataset = new DefaultPieDataset(); for (Network network : system.getNetworkList()) { for (Enterprise enterprise : network.getEnterpriseDirectory().getEnterpriseList()) { for (Organization organization : enterprise.getOrganizationDirectory().getOrganizationList()) { if (organization instanceof CustomerOrganization) { for (Employee employee : organization.getEmployeeDirectory().getEmployeeList()) { Customer customer = (Customer) employee; dataset.setValue(customer.getName(), customer.getTotalUsageVolume()); } } } } } JFreeChart chart = ChartFactory.createPieChart3D("Customer Water Usage", dataset, true, true, true); ChartFrame frame = new ChartFrame("Pie Chart demonstrating customer water usage ", chart); PiePlot3D plot = (PiePlot3D) chart.getPlot(); plot.setStartAngle(200); plot.setForegroundAlpha(0.50f); RefineryUtilities.centerFrameOnScreen(frame); frame.setVisible(true); frame.setSize(650, 550); }//GEN-LAST:event_jButton3ActionPerformed private void enableDisable() { int selectedRow = customerTable.getSelectedRow(); if (selectedRow < 0) { JOptionPane.showMessageDialog(null, "Select a customer first"); return; } Customer customer = (Customer) customerTable.getValueAt(selectedRow, 0); if (customer.getSourceSensor() == null) { usage.setEnabled(false); flow.setEnabled(false); } else { flow.setEnabled(true); usage.setEnabled(true); } if (customer.getWaterUsageHistory().size() == 0) { usage.setEnabled(false); } else { usage.setEnabled(true); } } private void customerTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_customerTableMouseClicked enableDisable(); }//GEN-LAST:event_customerTableMouseClicked private void customerTableKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_customerTableKeyReleased enableDisable(); }//GEN-LAST:event_customerTableKeyReleased private void excelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_excelActionPerformed for (Network network : system.getNetworkList()) { for (Enterprise enterprise : network.getEnterpriseDirectory().getEnterpriseList()) { if (enterprise instanceof WaterEnterprise) { for (Organization organization : enterprise.getOrganizationDirectory().getOrganizationList()) { if (organization instanceof CustomerOrganization) { if (organization.getUserAccountDirectory().getUserAccountList().size() == 0) { JOptionPane.showMessageDialog(null, "No Customers yet available in the system"); return; } } } } } } int a = ExcelReportCreator.create(system); if (a == 1) JOptionPane.showMessageDialog(null, "Excel Report Generated"); else { JOptionPane.showMessageDialog(null, "Failed to generate report"); return; } try { Desktop.getDesktop().open(new File("Customer_details.xlsx")); } catch (IOException e) { JOptionPane.showMessageDialog(null, "Failed to open"); } }//GEN-LAST:event_excelActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton backJButton; private javax.swing.JTextField billTxt; private javax.swing.JButton button; private javax.swing.JTextField contactTxt; private javax.swing.JTextField customerNameTxt; private javax.swing.JTable customerTable; private javax.swing.JTextField emailTxt; private javax.swing.JButton excel; private javax.swing.JButton flow; private javax.swing.JTextField idTxt; private javax.swing.JButton jButton3; private javax.swing.JInternalFrame jInternalFrame1; private javax.swing.JInternalFrame jInternalFrame2; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel10; private javax.swing.JLabel jLabel11; private javax.swing.JLabel jLabel12; private javax.swing.JLabel jLabel13; private javax.swing.JLabel jLabel14; private javax.swing.JLabel jLabel15; private javax.swing.JLabel jLabel16; private javax.swing.JLabel jLabel17; private javax.swing.JLabel jLabel18; private javax.swing.JLabel jLabel19; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel20; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel6; private javax.swing.JLabel jLabel7; private javax.swing.JLabel jLabel8; private javax.swing.JLabel jLabel9; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JSeparator jSeparator2; private javax.swing.JSeparator jSeparator3; private javax.swing.JSeparator jSeparator4; private javax.swing.JToggleButton jToggleButton1; private javax.swing.JToggleButton jToggleButton2; private javax.swing.JTextField leakageVolumeTxt; private javax.swing.JComboBox networkJComboBox; private javax.swing.JLabel note; private javax.swing.JLabel noteCust; private javax.swing.JTextField repairCostTxt; private javax.swing.JTextField revenueTxt; private javax.swing.JTextField searchTxt; private javax.swing.JSpinner spinner; private javax.swing.JTextField totalBillTxt; private javax.swing.JButton usage; private javax.swing.JTextField usageTxt; // End of variables declaration//GEN-END:variables }