userInterface.CustomerWorkArea.ViewChartJPanel.java Source code

Java tutorial

Introduction

Here is the source code for userInterface.CustomerWorkArea.ViewChartJPanel.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.UserAccount.UserAccount;
import java.awt.CardLayout;
import java.awt.Color;
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 amuly
 */
public class ViewChartJPanel extends javax.swing.JPanel {

    private JPanel userProcessContainer;
    private UserAccount userAccount;

    /**
     * Creates new form ViewChartJPanel
     */
    public ViewChartJPanel(JPanel userProcessContainer, UserAccount userAccount) {
        initComponents();
        this.userProcessContainer = userProcessContainer;
        this.userAccount = userAccount;
    }

    /**
     * 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();
        viewAlignmentBtn = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        batteryBtn = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        jButton3 = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        jButton4 = new javax.swing.JButton();
        bckBtn = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();

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

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

        viewAlignmentBtn.setText("View Graph");
        viewAlignmentBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                viewAlignmentBtnActionPerformed(evt);
            }
        });

        jLabel1.setText("Alignment");

        batteryBtn.setText("View Graph");
        batteryBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                batteryBtnActionPerformed(evt);
            }
        });

        jLabel2.setText("Battery");

        jLabel3.setText("Brakes");

        jButton2.setText("View Graph");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jLabel4.setText("Oil Check");

        jButton1.setText("View Graph");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel5.setText("Tyre Pressure");

        jButton3.setText("View Graph");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jLabel6.setText("Pollution");

        jButton4.setText("View Graphs");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        bckBtn.setText("Back");
        bckBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bckBtnActionPerformed(evt);
            }
        });

        jLabel7.setFont(new java.awt.Font("Tempus Sans ITC", 0, 24)); // NOI18N
        jLabel7.setText("ANALYTICAL CHARTS");

        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(619, 619, 619).addGroup(jPanel1Layout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(bckBtn)
                                .addGroup(jPanel1Layout.createSequentialGroup().addGroup(
                                        jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jLabel1).addComponent(jLabel2).addComponent(jLabel3)
                                                .addComponent(jLabel4).addComponent(jLabel5).addComponent(jLabel6))
                                        .addGap(123, 123, 123)
                                        .addGroup(jPanel1Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jButton4).addComponent(jButton3)
                                                .addComponent(jButton1).addComponent(jButton2)
                                                .addComponent(batteryBtn).addComponent(viewAlignmentBtn)))))
                        .addGroup(
                                jPanel1Layout.createSequentialGroup().addGap(653, 653, 653).addComponent(jLabel7)))
                        .addContainerGap(931, Short.MAX_VALUE)));
        jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup().addGap(106, 106, 106).addComponent(jLabel7)
                        .addGap(68, 68, 68)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(viewAlignmentBtn).addComponent(jLabel1))
                        .addGap(41, 41, 41)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(batteryBtn).addComponent(jLabel2))
                        .addGap(43, 43, 43)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jLabel3).addComponent(jButton2))
                        .addGap(43, 43, 43)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel4).addComponent(jButton1))
                        .addGap(45, 45, 45)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel5).addComponent(jButton3))
                        .addGap(37, 37, 37)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jLabel6).addComponent(jButton4))
                        .addGap(68, 68, 68).addComponent(bckBtn).addContainerGap(180, Short.MAX_VALUE)));

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

    private void viewAlignmentBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_viewAlignmentBtnActionPerformed
        DefaultCategoryDataset dataSet = new DefaultCategoryDataset();

        for (CarInspection carList : userAccount.getPerson().getCarInspectionHistory().getCarInspectionHistory()) {
            dataSet.setValue(carList.getAlignment(), "Alignment", carList.getTimestamp());
        }
        JFreeChart chart = ChartFactory.createBarChart("Alignment", "Timestamp", "Alignment", dataSet,
                PlotOrientation.HORIZONTAL.VERTICAL, false, true, false);
        CategoryPlot p = chart.getCategoryPlot();
        p.setRangeGridlinePaint(Color.BLACK);
        ChartFrame frame = new ChartFrame("ALIGNMENT GRAPH", chart);
        frame.setVisible(true);
        frame.setSize(600, 600);
        // TODO add your handling code here:
    }//GEN-LAST:event_viewAlignmentBtnActionPerformed

    private void batteryBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_batteryBtnActionPerformed
        DefaultCategoryDataset dataSet = new DefaultCategoryDataset();

        for (CarInspection carList : userAccount.getPerson().getCarInspectionHistory().getCarInspectionHistory()) {
            dataSet.setValue(carList.getBattery(), "Battery", carList.getTimestamp());
        }
        JFreeChart chart = ChartFactory.createBarChart("Battery", "Timestamp", "Battery", dataSet,
                PlotOrientation.HORIZONTAL.VERTICAL, false, true, false);
        CategoryPlot p = chart.getCategoryPlot();
        p.setRangeGridlinePaint(Color.BLACK);
        ChartFrame frame = new ChartFrame("BATTERY GRAPH", chart);
        frame.setVisible(true);
        frame.setSize(600, 600);
        // TODO add your handling code here:
    }//GEN-LAST:event_batteryBtnActionPerformed

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

        DefaultCategoryDataset dataSet = new DefaultCategoryDataset();

        for (CarInspection carList : userAccount.getPerson().getCarInspectionHistory().getCarInspectionHistory()) {
            dataSet.setValue(carList.getBrakingSys(), "Brakes", carList.getTimestamp());
        }
        JFreeChart chart = ChartFactory.createBarChart("Brakes", "Timestamp", "Brakes", dataSet,
                PlotOrientation.HORIZONTAL.VERTICAL, false, true, false);
        CategoryPlot p = chart.getCategoryPlot();
        p.setRangeGridlinePaint(Color.BLACK);
        ChartFrame frame = new ChartFrame("BRAKES GRAPH", chart);
        frame.setVisible(true);
        frame.setSize(600, 600);
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        DefaultCategoryDataset dataSet = new DefaultCategoryDataset();

        for (CarInspection carList : userAccount.getPerson().getCarInspectionHistory().getCarInspectionHistory()) {
            dataSet.setValue(carList.getOilCheck(), "Oil", carList.getTimestamp());
        }
        JFreeChart chart = ChartFactory.createBarChart("Oil", "Timestamp", "Oil", dataSet,
                PlotOrientation.HORIZONTAL.VERTICAL, false, true, false);
        CategoryPlot p = chart.getCategoryPlot();
        p.setRangeGridlinePaint(Color.BLACK);
        ChartFrame frame = new ChartFrame("OIL GRAPH", chart);
        frame.setVisible(true);
        frame.setSize(600, 600); // TODO add your handling code here:
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        DefaultCategoryDataset dataSet = new DefaultCategoryDataset();

        for (CarInspection carList : userAccount.getPerson().getCarInspectionHistory().getCarInspectionHistory()) {
            dataSet.setValue(carList.getTyrePressure(), "Tyre Pressure", carList.getTimestamp());
        }
        JFreeChart chart = ChartFactory.createBarChart("Tyre Pressure", "Timestamp", "Tyre Pressure", dataSet,
                PlotOrientation.HORIZONTAL.VERTICAL, false, true, false);
        CategoryPlot p = chart.getCategoryPlot();
        p.setRangeGridlinePaint(Color.BLACK);
        ChartFrame frame = new ChartFrame("TYRE PRESSURE GRAPH", chart);
        frame.setVisible(true);
        frame.setSize(600, 600); // TODO add your handling code here:
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        DefaultCategoryDataset dataSet = new DefaultCategoryDataset();

        for (CarInspection carList : userAccount.getPerson().getCarInspectionHistory().getCarInspectionHistory()) {
            dataSet.setValue(carList.getPollutionLevel(), "Pollution", carList.getTimestamp());
        }
        JFreeChart chart = ChartFactory.createBarChart("Pollution", "Timestamp", "Pollution", dataSet,
                PlotOrientation.HORIZONTAL.VERTICAL, false, true, false);
        CategoryPlot p = chart.getCategoryPlot();
        p.setRangeGridlinePaint(Color.BLACK);
        ChartFrame frame = new ChartFrame("POLLUTION GRAPH", chart);
        frame.setVisible(true);
        frame.setSize(600, 600); // TODO add your handling code here:
    }//GEN-LAST:event_jButton4ActionPerformed

    private void bckBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bckBtnActionPerformed
        userProcessContainer.remove(this);
        CardLayout layout = (CardLayout) userProcessContainer.getLayout();
        layout.previous(userProcessContainer); // TODO add your handling code here:
    }//GEN-LAST:event_bckBtnActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton batteryBtn;
    private javax.swing.JButton bckBtn;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    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.JPanel jPanel1;
    private javax.swing.JButton viewAlignmentBtn;
    // End of variables declaration//GEN-END:variables
}