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.Organization; import Business.Organization.ProcurementOrganization; import Business.WorkQueue.WorkRequest; import java.awt.CardLayout; import java.awt.Color; import java.awt.Dimension; import java.io.FileWriter; import javax.swing.JOptionPane; import javax.swing.JPanel; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartFrame; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.plot.CategoryPlot; import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.renderer.category.BarRenderer; import org.jfree.data.category.DefaultCategoryDataset; /** * * @author Abhishek */ public class RequestAnalysis extends javax.swing.JPanel { /** * Creates new form RequestAnalysis */ private JPanel container; private Enterprise enterprise; public RequestAnalysis(JPanel container, Enterprise enterprise) { initComponents(); this.container = container; 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() { jButton3 = new javax.swing.JButton(); jButton1 = new javax.swing.JButton(); backjButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); ExportBtn = new javax.swing.JButton(); jButton3.setText("jButton3"); setBackground(new java.awt.Color(0, 204, 153)); setPreferredSize(new java.awt.Dimension(1000, 700)); jButton1.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N jButton1.setText("All Request Processing Time"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); backjButton1.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N backjButton1.setText("<< Back"); backjButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { backjButton1ActionPerformed(evt); } }); jButton2.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N jButton2.setText("Search Request"); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); ExportBtn.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N ExportBtn.setText("Export Request To Excel"); ExportBtn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { ExportBtnActionPerformed(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().addGap(325, 325, 325) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(backjButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(ExportBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 253, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(501, Short.MAX_VALUE))); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGap(49, 49, 49).addComponent(jButton1) .addGap(18, 18, 18).addComponent(jButton2).addGap(18, 18, 18).addComponent(ExportBtn) .addGap(53, 53, 53).addComponent(backjButton1).addContainerGap(314, Short.MAX_VALUE))); }// </editor-fold>//GEN-END:initComponents private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: Organization organization = null; //System.out.println(enterprise.getOrganizationDirectory().getOrganizationList().size()); for (Organization org : enterprise.getOrganizationDirectory().getOrganizationList()) { if (org instanceof ProcurementOrganization) { organization = org; //System.out.println(organization); break; } } DefaultCategoryDataset dataset = new DefaultCategoryDataset(); if (organization != null) { for (WorkRequest request : organization.getWorkQueue().getWorkRequestList()) { if (request.getStatus().equalsIgnoreCase("Serviced")) { //System.out.println(organization.getName()); long i = request.getResolveDate().getTime() - request.getRequestDate().getTime(); System.out.println(i); float j = i / (100 * 24); dataset.setValue(j, request.getSensorStatusOld(), "Request Id: " + request.getWorkRequestId() + "time " + j); } //dataset.setValue(i,"test",i); } JFreeChart chart = ChartFactory.createBarChart("All Request", "Time(Seconds)", "Value", dataset, PlotOrientation.VERTICAL.VERTICAL, true, true, false); //JFreeChart chart = ChartFactory.createPieChart("Sample Pie Chart"+vitalsign.getTimeStamp(),dataset,true,true,false ); ChartPanel chartPanel = new ChartPanel(chart, false); chartPanel.setPreferredSize(new Dimension(500, 270)); CategoryPlot plot = (CategoryPlot) chart.getPlot(); ChartFrame cFrame = new ChartFrame("Name", chart); BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setSeriesPaint(0, Color.orange); cFrame.pack(); cFrame.setVisible(true); } else { JOptionPane.showMessageDialog(null, "No Request Present"); } }//GEN-LAST:event_jButton1ActionPerformed private void backjButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backjButton1ActionPerformed // TODO add your handling code here: container.remove(this); CardLayout layout = (CardLayout) container.getLayout(); layout.previous(container); }//GEN-LAST:event_backjButton1ActionPerformed private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed // TODO add your handling code here: SearchRequestJPanel srJP = new SearchRequestJPanel(container, enterprise); container.add("manageEmployeeJPanel", srJP); CardLayout layout = (CardLayout) container.getLayout(); layout.next(container); }//GEN-LAST:event_jButton2ActionPerformed private void ExportBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ExportBtnActionPerformed // TODO add your handling code here: try { if (enterprise.getOrganizationDirectory().getOrganizationList().size() > 0) { Organization organization = null; //System.out.println(enterprise.getOrganizationDirectory().getOrganizationList().size()); for (Organization org : enterprise.getOrganizationDirectory().getOrganizationList()) { if (org instanceof ProcurementOrganization) { organization = org; //System.out.println(organization); break; } } FileWriter writer = new FileWriter(System.getProperty("user.dir") + "\\test.csv"); //in = new FileInputStream(new File (System.getProperty("user.dir")+"\\Sound.wav")); writer.append("Request ID"); writer.append(','); writer.append("Requester"); writer.append(','); writer.append("Requester Organization"); writer.append(','); writer.append("Machine Name"); writer.append(','); writer.append("Machine Status"); writer.append(','); writer.append("Requested Date"); writer.append(','); writer.append("Total Price"); writer.append(','); writer.append("Requester Message"); writer.append(','); writer.append('\n'); if (organization.getWorkQueue().getWorkRequestList().size() > 0) { for (WorkRequest request : organization.getWorkQueue().getWorkRequestList()) { writer.append(String.valueOf(request.getWorkRequestId())); writer.append(','); writer.append(request.getSender().getUsername()); writer.append(','); writer.append(request.getOrg().getName()); writer.append(','); writer.append(request.getMachine().getMachineName()); writer.append(','); writer.append(request.getMachine().getSensorData().getSensorVlaue()); writer.append(','); writer.append(request.getRequestDate().toString()); writer.append(','); writer.append(String.valueOf(request.getTotalPrice())); writer.append(','); writer.append(request.getMessage()); writer.append(','); writer.append('\n'); } } writer.flush(); writer.close(); JOptionPane.showMessageDialog(this, "Record Exported Successfully", "Export", JOptionPane.INFORMATION_MESSAGE); } else { JOptionPane.showMessageDialog(null, "No Organization Present"); } } catch (Exception e) { System.out.println("inside"); System.out.println(e.getMessage()); } }//GEN-LAST:event_ExportBtnActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton ExportBtn; private javax.swing.JButton backjButton1; private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JButton jButton3; // End of variables declaration//GEN-END:variables }