userInterface.CustomerWorkArea.CustomerWorkAreaJPanel.java Source code

Java tutorial

Introduction

Here is the source code for userInterface.CustomerWorkArea.CustomerWorkAreaJPanel.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.CustomerWorkArea;

import Business.CarInspection.CarInspection;
import Business.Enterprise.InsuranceEnterprise;
import Business.Network.Network;
import Business.Organization.CustomerOrganization;
import Business.UserAccount.UserAccount;
import java.awt.CardLayout;
import java.awt.Color;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;

/**
 *
 * @author amuly
 */
public class CustomerWorkAreaJPanel extends javax.swing.JPanel {

    private JPanel userProcessContainer;
    private CustomerOrganization organization;
    private InsuranceEnterprise enterprise;
    private UserAccount userAccount;
    private Network network;

    public CustomerWorkAreaJPanel(JPanel userProcessContainer, UserAccount account,
            CustomerOrganization customerOrganization, InsuranceEnterprise insuranceEnterprise, Network network) {
        initComponents();
        this.userProcessContainer = userProcessContainer;
        this.organization = customerOrganization;
        this.enterprise = insuranceEnterprise;
        this.userAccount = account;
        this.network = network;

    }

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

        jPanel1 = new javax.swing.JPanel();
        sensorInputBtn = new javax.swing.JButton();
        viewSensorDataHistoryBtn = new javax.swing.JButton();
        viewSensorHistoryBtn = new javax.swing.JButton();
        viewGraphsBtn = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();

        setLayout(new java.awt.BorderLayout());

        jPanel1.setBackground(new java.awt.Color(153, 153, 255));

        sensorInputBtn.setText("Sensor data input");
        sensorInputBtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        sensorInputBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sensorInputBtnActionPerformed(evt);
            }
        });

        viewSensorDataHistoryBtn.setText("View Repair History");
        viewSensorDataHistoryBtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        viewSensorDataHistoryBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                viewSensorDataHistoryBtnActionPerformed(evt);
            }
        });

        viewSensorHistoryBtn.setText("View Sensor data history ");
        viewSensorHistoryBtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        viewSensorHistoryBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                viewSensorHistoryBtnActionPerformed(evt);
            }
        });

        viewGraphsBtn.setText("View Graphs");
        viewGraphsBtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        viewGraphsBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                viewGraphsBtnActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Tempus Sans ITC", 0, 24)); // NOI18N
        jLabel1.setText("CUSTOMER WORK AREA");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(jPanel1Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup().addGroup(jPanel1Layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup().addGap(685, 685, 685).addGroup(jPanel1Layout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(viewSensorHistoryBtn)
                                .addComponent(sensorInputBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 179,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(viewSensorDataHistoryBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 179,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(viewGraphsBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 179,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGroup(jPanel1Layout.createSequentialGroup().addGap(630, 630, 630).addComponent(jLabel1,
                                javax.swing.GroupLayout.PREFERRED_SIZE, 284,
                                javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addContainerGap(933, Short.MAX_VALUE)));

        jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] { sensorInputBtn,
                viewGraphsBtn, viewSensorDataHistoryBtn, viewSensorHistoryBtn });

        jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup().addGap(107, 107, 107).addComponent(jLabel1)
                        .addGap(130, 130, 130).addComponent(sensorInputBtn).addGap(69, 69, 69)
                        .addComponent(viewSensorHistoryBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 25,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(75, 75, 75)
                        .addComponent(viewSensorDataHistoryBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 25,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(76, 76, 76).addComponent(viewGraphsBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 25,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(221, Short.MAX_VALUE)));

        jPanel1Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] { sensorInputBtn,
                viewGraphsBtn, viewSensorDataHistoryBtn, viewSensorHistoryBtn });

        add(jPanel1, java.awt.BorderLayout.CENTER);
    }// </editor-fold>//GEN-END:initComponents

    private void sensorInputBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sensorInputBtnActionPerformed
        // TODO add your handling code here:
        SensorDataInputJPanel sensorDataInputJPanel = new SensorDataInputJPanel(userProcessContainer, organization,
                enterprise, userAccount, network);
        userProcessContainer.add("sensorDataInputJPanel", sensorDataInputJPanel);
        CardLayout layout = (CardLayout) userProcessContainer.getLayout();
        layout.next(userProcessContainer);
    }//GEN-LAST:event_sensorInputBtnActionPerformed

    private void viewSensorDataHistoryBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_viewSensorDataHistoryBtnActionPerformed

        ViewCustomerHistoryJPanel viewCustomerHistoryJPanel = new ViewCustomerHistoryJPanel(userProcessContainer,
                organization, enterprise, userAccount);
        userProcessContainer.add("viewCustomerHistoryJPanel", viewCustomerHistoryJPanel);
        CardLayout layout = (CardLayout) userProcessContainer.getLayout();
        layout.next(userProcessContainer);
        // TODO add your handling code here:
    }//GEN-LAST:event_viewSensorDataHistoryBtnActionPerformed

    private void viewSensorHistoryBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_viewSensorHistoryBtnActionPerformed

        ViewSensorHistoryJPanel viewSensorHistoryJPanel = new ViewSensorHistoryJPanel(userProcessContainer,
                organization, enterprise, userAccount);
        userProcessContainer.add("viewSensorHistoryJPanel", viewSensorHistoryJPanel);
        CardLayout layout = (CardLayout) userProcessContainer.getLayout();
        layout.next(userProcessContainer);
        // TODO add your handling code here:
    }//GEN-LAST:event_viewSensorHistoryBtnActionPerformed

    private void viewGraphsBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_viewGraphsBtnActionPerformed
        ViewChartJPanel viewChartJPanel = new ViewChartJPanel(userProcessContainer, userAccount);
        userProcessContainer.add("viewChartJPanel", viewChartJPanel);
        CardLayout layout = (CardLayout) userProcessContainer.getLayout();
        layout.next(userProcessContainer);

        // TODO add your handling code here:
    }//GEN-LAST:event_viewGraphsBtnActionPerformed

    private void createChart() {
        DefaultCategoryDataset CarInspectionDataset = new DefaultCategoryDataset();

        ArrayList<CarInspection> carInspectionList = userAccount.getPerson().getCarInspectionHistory()
                .getCarInspectionHistory();
        /*At least 2 vital sign records needed to show chart */
        if (carInspectionList.isEmpty() || carInspectionList.size() == 1) {
            JOptionPane.showMessageDialog(this, " At least 2 car Inspection records needed to show chart!",
                    "Warning", JOptionPane.INFORMATION_MESSAGE);
            return;
        }
        for (CarInspection carList : carInspectionList) {
            CarInspectionDataset.addValue(carList.getAlignment(), "RR", carList.getTimestamp());
            CarInspectionDataset.addValue(carList.getBattery(), "HR", carList.getTimestamp());
            CarInspectionDataset.addValue(carList.getBrakingSys(), "BP", carList.getTimestamp());
            CarInspectionDataset.addValue(carList.getOilCheck(), "WT", carList.getTimestamp());
        }

        JFreeChart carInspectionChart = ChartFactory.createBarChart3D("Car Inspection Chart", "Time Stamp",
                "Values", CarInspectionDataset, PlotOrientation.VERTICAL, true, false, false);
        carInspectionChart.setBackgroundPaint(Color.white);
        CategoryPlot carChartPlot = carInspectionChart.getCategoryPlot();
        carChartPlot.setBackgroundPaint(Color.lightGray);

        CategoryAxis vitalSignDomainAxis = carChartPlot.getDomainAxis();
        vitalSignDomainAxis
                .setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));

        NumberAxis vitalSignRangeAxis = (NumberAxis) carChartPlot.getRangeAxis();
        vitalSignRangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

        ChartFrame chartFrame = new ChartFrame("Chart", carInspectionChart);
        chartFrame.setVisible(true);
        chartFrame.setSize(500, 500);

    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JButton sensorInputBtn;
    private javax.swing.JButton viewGraphsBtn;
    private javax.swing.JButton viewSensorDataHistoryBtn;
    private javax.swing.JButton viewSensorHistoryBtn;
    // End of variables declaration//GEN-END:variables
}