drugsupplychain.neu.css.gui.common.pharmaco.ProductDistributionDetailJPanel.java Source code

Java tutorial

Introduction

Here is the source code for drugsupplychain.neu.css.gui.common.pharmaco.ProductDistributionDetailJPanel.java

Source

/*
 * Class : ProductDistributionDetailJPanel.java
 * Developer : Laksh Lumba
 * Reviewer :
 * Description : 
 * Created On : Dec 2, 2014, 11:46:03 PM
 * ---------------------------------------------------------------------------
 * Change History
 * Develper :
 * Reviwer :
 * Changed ON :
 * ---------------------------------------------------------------------------
 * 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 drugsupplychain.neu.css.gui.common.pharmaco;

import drugsupplychain.neu.css.log.ImplLogger;
import drugsupplychain.neu.css.model.distributor.Distributor;
import drugsupplychain.neu.css.model.distributor.RegionalDistributor;
import drugsupplychain.neu.css.model.product.Product;
import drugsupplychain.neu.css.model.product.TrackOrganization;
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Color;
import javax.swing.JPanel;
import javax.swing.table.DefaultTableModel;
import org.jfree.chart.ChartFactory;
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.data.category.DefaultCategoryDataset;

/**
 *
 * @author Laksh
 */
public class ProductDistributionDetailJPanel extends javax.swing.JPanel {
    private final JPanel userProcessContainer;
    private final Product product;

    /**
     * Creates new form ProductDistributionDetailJPanel
     * @param userProcessContainer
     * @param product
     */
    public ProductDistributionDetailJPanel(JPanel userProcessContainer, Product product) {
        initComponents();
        this.product = product;
        this.userProcessContainer = userProcessContainer;
        populateDistributionTable();
        showDistribution();
    }

    /**
     * populate distribution table
     */
    private void populateDistributionTable() {
        DefaultTableModel defaultTableModel = (DefaultTableModel) distributionTable.getModel();
        defaultTableModel.setRowCount(0);
        if (null != product) {
            if (null != product.getProductTracker()) {
                for (String id : product.getProductTracker().keySet()) {
                    TrackOrganization trackOrganization = product.getProductTracker().get(id);
                    if (trackOrganization.getOrganization() instanceof RegionalDistributor) {
                        Object[] rows = new Object[5];
                        rows[0] = trackOrganization.getOrganization().getLocation();
                        rows[1] = trackOrganization;
                        rows[2] = trackOrganization.getOrganization();
                        rows[3] = trackOrganization.getQuantity();
                        rows[4] = trackOrganization.getQuantity() * product.getPrice();
                        defaultTableModel.addRow(rows);
                    }
                }
            }
        }
    }

    /**
     * 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();
        jScrollPane1 = new javax.swing.JScrollPane();
        distributionTable = new javax.swing.JTable();
        barPanelDisplay = new javax.swing.JPanel();
        backButton = new javax.swing.JButton();

        setBackground(new java.awt.Color(204, 204, 255));

        jLabel1.setFont(new java.awt.Font("Tahoma", 3, 18)); // NOI18N
        jLabel1.setText("Medicine Distribution Detail");

        distributionTable.setModel(new javax.swing.table.DefaultTableModel(new Object[][] {

        }, new String[] { "Region", "Distributor ID", "Distributor Name", "Quantity", "Total Sale Value" }) {
            boolean[] canEdit = new boolean[] { true, false, true, false, true };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit[columnIndex];
            }
        });
        jScrollPane1.setViewportView(distributionTable);

        barPanelDisplay.setBackground(new java.awt.Color(255, 255, 255));
        barPanelDisplay.setLayout(new java.awt.BorderLayout());

        backButton.setFont(new java.awt.Font("Tahoma", 3, 12)); // NOI18N
        backButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/drugsupplychain/images/back.png"))); // NOI18N
        backButton.setText("Back");
        backButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                backButtonActionPerformed(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()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup().addGap(381, 381, 381).addComponent(jLabel1,
                                        javax.swing.GroupLayout.PREFERRED_SIZE, 295,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(layout.createSequentialGroup().addContainerGap().addComponent(backButton))
                                .addGroup(layout.createSequentialGroup().addGap(65, 65, 65).addGroup(
                                        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        935, Short.MAX_VALUE)
                                                .addComponent(barPanelDisplay, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                        .addContainerGap(125, Short.MAX_VALUE)));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addContainerGap().addComponent(jLabel1).addGap(18, 18, 18)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 101,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 450, Short.MAX_VALUE)
                        .addComponent(barPanelDisplay, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(backButton).addContainerGap()));
    }// </editor-fold>//GEN-END:initComponents

    /**
     * back button
     * @param evt 
     */
    private void backButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backButtonActionPerformed
        ImplLogger.enterMethod();
        userProcessContainer.remove(this);
        CardLayout layout = (CardLayout) userProcessContainer.getLayout();
        layout.previous(userProcessContainer);
        ImplLogger.exitMethod();
    }//GEN-LAST:event_backButtonActionPerformed

    /**
     * show distribution
     */
    private void showDistribution() {
        // TODO add your handling code here:
        DefaultCategoryDataset barchartDataset = new DefaultCategoryDataset();
        if (null != product && null != product.getProductTracker() && product.getProductTracker().size() > 0) {
            for (String id : product.getProductTracker().keySet()) {
                TrackOrganization trackOrganization = product.getProductTracker().get(id);
                if (trackOrganization.getOrganization() instanceof Distributor) {
                    barchartDataset.setValue(trackOrganization.getQuantity(), "QUANTITY",
                            trackOrganization.getOrganization().getLocation());
                }
            }
            JFreeChart barChartData = ChartFactory.createBarChart("MEDICINE DISTRIBUTION", "LOCATION", "QUANTITY",
                    barchartDataset, PlotOrientation.VERTICAL, false, true, true);
            CategoryPlot barchart = barChartData.getCategoryPlot();
            barchart.setRangeGridlinePaint(Color.ORANGE);
            ChartPanel barPanel = new ChartPanel(barChartData);
            barPanelDisplay.removeAll();
            barPanelDisplay.add(barPanel, BorderLayout.CENTER);
            barPanelDisplay.validate();
        }
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton backButton;
    private javax.swing.JPanel barPanelDisplay;
    private javax.swing.JTable distributionTable;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables
}