Package ui

Source Code of ui.ReservationUI

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package ui;

import beans.Reservation;
import design_patterns.strategy.Book;
import design_patterns.strategy.Product;
import design_patterns.strategy.Video;
import java.util.ArrayList;
import java.util.Map;
import java.util.TreeMap;

/**
*
* @author root
*/
public class ReservationUI extends javax.swing.JFrame {

    private Menu menu_window;
    private Product product,type;
    private ArrayList products;
    /**
     * Creates new form Reservation
     */
    public ReservationUI() {
        initComponents();
        loadComboBox();
    }

    public ReservationUI(Menu menu_window,Product type) {
        initComponents();
        this.menu_window=menu_window;
        this.products= new ArrayList();
        if (type instanceof Video){
            this.type= (Video) type;        
        }
        else if (type instanceof Book ){
            this.type= (Book) type;
        }   
        loadComboBox();
    }

    /**
     * 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.
     */
    private void loadComboBox(){
        this.products_jComboBox.removeAllItems();
        this.user_jComboBox.removeAllItems();
        this.user_jComboBox.addItem(this.menu_window.getUser().getUsername());
        this.user_jComboBox.setEnabled(false);
       
        if (this.type instanceof Video){
            this.products=this.menu_window.getLogin_window().getVideos();
            for (int i=0; i<products.size();i++){       
                Video p = (Video)products.get(i);
                this.products_jComboBox.addItem(p.getName());         
            }
        }
        else if (this.type instanceof Book ){
            this.products=this.menu_window.getLogin_window().getBooks();
            for (int i=0; i<products.size();i++){       
                Book p = (Book)products.get(i);
                this.products_jComboBox.addItem(p.getName());         
            }
        }
       
       
    }
   
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        user_jComboBox = new javax.swing.JComboBox();
        products_jComboBox = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        reserve_btn = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenu2 = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        user_jComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        user_jComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                user_jComboBoxActionPerformed(evt);
            }
        });

        products_jComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        products_jComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                products_jComboBoxActionPerformed(evt);
            }
        });

        jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/booksintomovies_SCALED.jpg"))); // NOI18N

        reserve_btn.setText("Reserve");
        reserve_btn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                reserve_btnActionPerformed(evt);
            }
        });

        jLabel1.setText("User:");

        jLabel2.setText("Product:");

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

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(31, 31, 31)
                                .addComponent(jLabel3)
                                .addGap(0, 112, Short.MAX_VALUE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(products_jComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(34, 34, 34)
                        .addComponent(user_jComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(reserve_btn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(135, 135, 135))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(user_jComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(products_jComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addGap(18, 18, 18)
                .addComponent(reserve_btn)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton1)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jMenu1.setText("File");
        jMenuBar1.add(jMenu1);

        jMenu2.setText("Edit");
        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

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

    private void user_jComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_user_jComboBoxActionPerformed
        // TODO add your handling code here:
      
       
    }//GEN-LAST:event_user_jComboBoxActionPerformed

    private void products_jComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_products_jComboBoxActionPerformed
        // TODO add your handling code here:

        for (int i=0; i<this.products.size();i++){
            this.product = (Product)this.products.get(i);
           
            if(products_jComboBox.getSelectedItem()!=null){
                if (products_jComboBox.getSelectedItem().equals(this.product.getName())){               
                    break;
                }
            }

        }

    }//GEN-LAST:event_products_jComboBoxActionPerformed

    public static int getNextID(Map<Integer, Reservation> map) {
    int count = 0;
                for (Map.Entry entry : map.entrySet()) {
                        count = (Integer)entry.getKey();
    }
                return count+1;
    }
    private void reserve_btnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_reserve_btnActionPerformed
        // TODO add your handling code here:

        Map<Integer, Reservation> treeMap = new TreeMap <Integer, Reservation>(this.menu_window.getLogin_window().getReservations_map());     
       
        if (this.product instanceof Video){
            Reservation reservation = this.product.startReservationManagement(getNextID(treeMap),menu_window.getUser());
            this.menu_window.getLogin_window().getReservations_map().put(reservation.getId(), reservation);
            System.out.println("Instance of VideReservation " + reservation.getReserv_date_start());        
        }
        else if (this.product instanceof Book ){
            Reservation reservation = this.product.startReservationManagement(getNextID(treeMap),menu_window.getUser());
            this.menu_window.getLogin_window().getReservations_map().put(reservation.getId(), reservation);
            System.out.println("Instance of BookReservation " + reservation.getUser().getUsername());
        }
       
        this.menu_window.setVisible(true);
        this.dispose();
       
    }//GEN-LAST:event_reserve_btnActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
     * @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(ReservationUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ReservationUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ReservationUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ReservationUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ReservationUI().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JComboBox products_jComboBox;
    private javax.swing.JButton reserve_btn;
    private javax.swing.JComboBox user_jComboBox;
    // End of variables declaration//GEN-END:variables

    /**
     * @return the menu_window
     */
    public Menu getMenu_window() {
        return menu_window;
    }

    /**
     * @param menu_window the menu_window to set
     */
    public void setMenu_window(Menu menu_window) {
        this.menu_window = menu_window;
    }
}
TOP

Related Classes of ui.ReservationUI

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.