com.nicodemo.view.MainForm.java Source code

Java tutorial

Introduction

Here is the source code for com.nicodemo.view.MainForm.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 com.nicodemo.view;

import com.nicodemo.controller.ClientsDebtsController;
import com.nicodemo.controller.DevEntitiesInitializer;
import com.nicodemo.controller.ItemsController;
import com.nicodemo.controller.SaleController;
import com.nicodemo.persistence.DAOs.ItemsDAO;
import java.awt.BorderLayout;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 *
 * @author Nico
 */
public class MainForm extends javax.swing.JFrame {

    private ApplicationContext context;

    /**
     * Creates new form Main
     */
    public MainForm(ApplicationContext context) {
        this.context = context;

        initComponents();

        CashBoxPanel currentCashBoxPanel = new CashBoxPanel();
        currentCashBoxPanel.setVisible(true);
        this.jPanel_tabCurrentCashBox.setLayout(new BorderLayout());
        this.jPanel_tabCurrentCashBox.add(currentCashBoxPanel, BorderLayout.CENTER);

        CurrentSalePanel currentSalePanel = new CurrentSalePanel(this, context.getBean(SaleController.class),
                currentCashBoxPanel, context.getBean(ClientsDebtsController.class));
        currentSalePanel.setVisible(true);
        this.jPanel_tabCurrentSale.setLayout(new BorderLayout());
        this.jPanel_tabCurrentSale.add(currentSalePanel, BorderLayout.CENTER);

        ItemsPanel itemsPanel = new ItemsPanel(this, context.getBean(ItemsController.class));
        itemsPanel.setVisible(true);
        this.jPanel_tabItems.setLayout(new BorderLayout());
        this.jPanel_tabItems.add(itemsPanel, BorderLayout.CENTER);

        ClientsPanel clientsPanel = new ClientsPanel(context.getBean(ClientsDebtsController.class));
        clientsPanel.setVisible(true);
        this.jPanel_tabClients.setLayout(new BorderLayout());
        this.jPanel_tabClients.add(clientsPanel, BorderLayout.CENTER);
    }

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

        jTabbedPane_main = new javax.swing.JTabbedPane();
        jPanel_tabCurrentSale = new javax.swing.JPanel();
        jPanel_tabItems = new javax.swing.JPanel();
        jPanel_tabCurrentCashBox = new javax.swing.JPanel();
        jPanel_tabClients = new javax.swing.JPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(500, 500));

        javax.swing.GroupLayout jPanel_tabCurrentSaleLayout = new javax.swing.GroupLayout(jPanel_tabCurrentSale);
        jPanel_tabCurrentSale.setLayout(jPanel_tabCurrentSaleLayout);
        jPanel_tabCurrentSaleLayout.setHorizontalGroup(jPanel_tabCurrentSaleLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 595, Short.MAX_VALUE));
        jPanel_tabCurrentSaleLayout.setVerticalGroup(jPanel_tabCurrentSaleLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 361, Short.MAX_VALUE));

        jTabbedPane_main.addTab("Venta Actual", jPanel_tabCurrentSale);

        javax.swing.GroupLayout jPanel_tabItemsLayout = new javax.swing.GroupLayout(jPanel_tabItems);
        jPanel_tabItems.setLayout(jPanel_tabItemsLayout);
        jPanel_tabItemsLayout.setHorizontalGroup(jPanel_tabItemsLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 595, Short.MAX_VALUE));
        jPanel_tabItemsLayout.setVerticalGroup(jPanel_tabItemsLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 361, Short.MAX_VALUE));

        jTabbedPane_main.addTab("Articulos", jPanel_tabItems);

        javax.swing.GroupLayout jPanel_tabCurrentCashBoxLayout = new javax.swing.GroupLayout(
                jPanel_tabCurrentCashBox);
        jPanel_tabCurrentCashBox.setLayout(jPanel_tabCurrentCashBoxLayout);
        jPanel_tabCurrentCashBoxLayout.setHorizontalGroup(jPanel_tabCurrentCashBoxLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 595, Short.MAX_VALUE));
        jPanel_tabCurrentCashBoxLayout.setVerticalGroup(jPanel_tabCurrentCashBoxLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 361, Short.MAX_VALUE));

        jTabbedPane_main.addTab("Caja", jPanel_tabCurrentCashBox);

        javax.swing.GroupLayout jPanel_tabClientsLayout = new javax.swing.GroupLayout(jPanel_tabClients);
        jPanel_tabClients.setLayout(jPanel_tabClientsLayout);
        jPanel_tabClientsLayout.setHorizontalGroup(jPanel_tabClientsLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 595, Short.MAX_VALUE));
        jPanel_tabClientsLayout.setVerticalGroup(jPanel_tabClientsLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 361, Short.MAX_VALUE));

        jTabbedPane_main.addTab("Clientes", jPanel_tabClients);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jTabbedPane_main));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addContainerGap().addComponent(jTabbedPane_main)));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MainForm.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MainForm.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MainForm.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainForm.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        }
        //</editor-fold>
        //</editor-fold>

        ApplicationContext context = new ClassPathXmlApplicationContext("main/resources/beans.xml");

        context.getBean(DevEntitiesInitializer.class).Initialize();

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MainForm(context).setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel jPanel_tabClients;
    private javax.swing.JPanel jPanel_tabCurrentCashBox;
    private javax.swing.JPanel jPanel_tabCurrentSale;
    private javax.swing.JPanel jPanel_tabItems;
    private javax.swing.JTabbedPane jTabbedPane_main;
    // End of variables declaration//GEN-END:variables
}