Advertisement
LaCaraDeLaVerga

PanelCarritoRepuestosView

Nov 22nd, 2020
622
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 13.01 KB | None | 0 0
  1. package presentacion.views.cajero;
  2.  
  3. import java.awt.BorderLayout;
  4. import java.awt.Color;
  5. import java.awt.Container;
  6. import java.awt.FlowLayout;
  7. import java.awt.SystemColor;
  8. import java.awt.event.ActionListener;
  9. import java.util.ArrayList;
  10. import java.util.List;
  11.  
  12. import javax.swing.BoxLayout;
  13. import javax.swing.DefaultComboBoxModel;
  14. import javax.swing.JButton;
  15. import javax.swing.JComboBox;
  16. import javax.swing.JInternalFrame;
  17. import javax.swing.JLabel;
  18. import javax.swing.JPanel;
  19. import javax.swing.JScrollPane;
  20. import javax.swing.JTable;
  21. import javax.swing.JTextField;
  22. import javax.swing.SwingConstants;
  23. import javax.swing.UIManager;
  24. import javax.swing.border.TitledBorder;
  25. import javax.swing.table.DefaultTableModel;
  26.  
  27. import com.jgoodies.forms.layout.ColumnSpec;
  28. import com.jgoodies.forms.layout.FormLayout;
  29. import com.jgoodies.forms.layout.FormSpecs;
  30. import com.jgoodies.forms.layout.RowSpec;
  31.  
  32. import dto.ClienteDTO;
  33. import dto.RepuestoCompradoDTO;
  34. import dto.RepuestoDTO;
  35. import dto.RepuestoPlanificadoDTO;
  36. import presentacion.views.supervisor.ClientePanelView;
  37.  
  38. import javax.swing.JSplitPane;
  39. import javax.swing.border.BevelBorder;
  40. import java.awt.event.ActionEvent;
  41.  
  42. public class PanelCarritoRepuestoView extends JPanel {
  43.  
  44.     private static final long serialVersionUID = -3149040258338164711L;
  45.  
  46.     private final JPanel panelDerecho = new JPanel();
  47.  
  48.     private static final String[] nombreColumnasSuperior = { "Codigo", "Descripcion", "Marca", "Fabricante", "Stock",
  49.             "Precio" };
  50.     private static final String[] nombreColumnasInferior = { "Codigo", "Descripcion", "Marca", "Fabricante",
  51.             "Cantidad" };
  52.  
  53.     private JPanel panelSuperior = new JPanel();
  54.     private JPanel panelInterior = new JPanel();
  55.     private JComboBox<String> comboMarcas;
  56.     private JLabel lblDescripcion;
  57.     private JTextField textDescipcion;
  58.     private JButton btnBuscar;
  59.     private JScrollPane scrollPaneRepuestos;
  60.     private DefaultTableModel modelRepuestos;
  61.     private JTable tablaRepuestos;
  62.  
  63.     private JPanel panelInferior = new JPanel();
  64.     private JScrollPane scrollPaneRepuestosInferior;
  65.     private DefaultTableModel modelRepuestosInferior;
  66.     private JTable tablaRepuestosInferior;
  67.  
  68.     static PanelCarritoRepuestoView vista;
  69.  
  70.     private JButton btnLimpiar;
  71.     private JButton btnQuitar;
  72.     private JButton btnEditar;
  73.     private JButton btnAgregar;
  74.     private JLabel lblCantidad;
  75.     private JTextField textCantidad;
  76.     private JPanel panel;
  77.     private JPanel panel_1;
  78.     private JPanel panel_2;
  79.     private List<Integer> idRepuestos;
  80.     private JButton btnCrearFactura;
  81.     private JButton btnCancelar;
  82.     private ClientePanelView panelCliente;
  83.     private JSplitPane splitPane;
  84.     private JPanel panelBotonesCliente;
  85.     private JButton btnRegistrarCliente;
  86.     private JPanel panelBuscador;
  87.     private JTextField tfDni;
  88.     private JButton btnBuscarCliente;
  89.  
  90.     private List<Integer> idRepuestosComprados;
  91.     private JLabel lblMarca;
  92.     private JTextField tfTotalFactura;
  93.     private JLabel lblTotalFactura;
  94.  
  95.     public static PanelCarritoRepuestoView getInstance() {
  96.         if (vista == null)
  97.             vista = new PanelCarritoRepuestoView();
  98.         return vista;
  99.     }
  100.  
  101.     @SuppressWarnings("serial")
  102.     private PanelCarritoRepuestoView() {
  103.         setBounds(100, 100, 712, 600);
  104.         setLayout(new BorderLayout());
  105.         idRepuestos = new ArrayList<>();
  106.         idRepuestosComprados = new ArrayList<>();
  107.        
  108.         modelRepuestos = new DefaultTableModel(null, nombreColumnasSuperior) {
  109.             @Override
  110.             public boolean isCellEditable(int row, int column) {
  111.                 return false;
  112.             }
  113.         };
  114.  
  115.         modelRepuestosInferior = new DefaultTableModel(null, nombreColumnasInferior) {
  116.             @Override
  117.             public boolean isCellEditable(int row, int column) {
  118.                 return false;
  119.             }
  120.         };
  121.  
  122.         JPanel buttonPane = new JPanel();
  123.         buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
  124.         add(buttonPane, BorderLayout.SOUTH);
  125.  
  126.         btnCrearFactura = new JButton("Aceptar");
  127.         btnCrearFactura.addActionListener(new ActionListener() {
  128.             public void actionPerformed(ActionEvent arg0) {
  129.             }
  130.         });
  131.        
  132.         lblTotalFactura = new JLabel("Total factura: ");
  133.         buttonPane.add(lblTotalFactura);
  134.        
  135.         tfTotalFactura = new JTextField();
  136.         tfTotalFactura.setEditable(false);
  137.         buttonPane.add(tfTotalFactura);
  138.         tfTotalFactura.setColumns(10);
  139.         btnCrearFactura.setActionCommand("OK");
  140.         buttonPane.add(btnCrearFactura);
  141. //      tfTotalFactura.setText(arg0);
  142.  
  143.         btnCancelar = new JButton("Cancelar");
  144.         btnCancelar.setVisible(false);
  145.         btnCancelar.setActionCommand("Cancel");
  146.         buttonPane.add(btnCancelar);
  147.  
  148.         splitPane = new JSplitPane();
  149.         splitPane.setEnabled(false);
  150.         splitPane.setResizeWeight(0.0);
  151.         add(splitPane, BorderLayout.CENTER);
  152.         splitPane.setRightComponent(panelDerecho);
  153.        
  154.         JPanel panelIzquierdo = new JPanel(new BorderLayout());
  155.        
  156.         panelCliente = new ClientePanelView();
  157.         panelIzquierdo.add(panelCliente, BorderLayout.CENTER);
  158.        
  159.        
  160.         splitPane.setLeftComponent(panelIzquierdo);
  161.        
  162.         panelBotonesCliente = new JPanel();
  163.         FlowLayout flowLayout = (FlowLayout) panelBotonesCliente.getLayout();
  164.         flowLayout.setAlignment(FlowLayout.LEFT);
  165.         panelIzquierdo.add(panelBotonesCliente, BorderLayout.SOUTH);
  166.        
  167.         btnRegistrarCliente = new JButton("Registrar Cliente");
  168.         panelBotonesCliente.add(btnRegistrarCliente);
  169.        
  170.         panelBuscador = new JPanel();
  171.         panelIzquierdo.add(panelBuscador, BorderLayout.NORTH);
  172.        
  173.         tfDni = new JTextField();
  174.         panelBuscador.add(tfDni);
  175.         tfDni.setColumns(15);
  176.        
  177.         btnBuscarCliente = new JButton("Buscar");
  178.         panelBuscador.add(btnBuscarCliente);
  179.        
  180.         panelDerecho.setLayout(new BoxLayout(panelDerecho, BoxLayout.Y_AXIS));
  181.  
  182.         panelSuperior = new JPanel();
  183.         panelSuperior.setForeground(SystemColor.menu);
  184.         panelSuperior.setBorder(
  185.                 new TitledBorder(null, "Repuestos disponibles", TitledBorder.CENTER, TitledBorder.TOP, null, null));
  186.         panelSuperior.setBackground(SystemColor.menu);
  187.         panelDerecho.add(panelSuperior);
  188.         panelSuperior.setLayout(new BorderLayout(0, 0));
  189.  
  190.         panel_1 = new JPanel();
  191.         panelSuperior.add(panel_1, BorderLayout.NORTH);
  192.         panel_1.setLayout(new FormLayout(new ColumnSpec[] {
  193.                 ColumnSpec.decode("10px"),
  194.                 ColumnSpec.decode("max(34dlu;default)"),
  195.                 FormSpecs.RELATED_GAP_COLSPEC,
  196.                 ColumnSpec.decode("132px"),
  197.                 FormSpecs.LABEL_COMPONENT_GAP_COLSPEC,
  198.                 ColumnSpec.decode("right:75px"),
  199.                 FormSpecs.LABEL_COMPONENT_GAP_COLSPEC,
  200.                 ColumnSpec.decode("78px:grow"),
  201.                 FormSpecs.LABEL_COMPONENT_GAP_COLSPEC,
  202.                 ColumnSpec.decode("85px"),},
  203.             new RowSpec[] {
  204.                 FormSpecs.LINE_GAP_ROWSPEC,
  205.                 RowSpec.decode("23px"),}));
  206.        
  207.         lblMarca = new JLabel("Marca");
  208.         panel_1.add(lblMarca, "2, 2, right, default");
  209.  
  210.         comboMarcas = new JComboBox<>();
  211.         panel_1.add(comboMarcas, "4, 2, default, center");
  212.  
  213.         lblDescripcion = new JLabel();
  214.         panel_1.add(lblDescripcion, "6, 2, right, center");
  215.         lblDescripcion.setHorizontalAlignment(SwingConstants.CENTER);
  216.         lblDescripcion.setText("Descripción");
  217.  
  218.         textDescipcion = new JTextField();
  219.         panel_1.add(textDescipcion, "8, 2, default, center");
  220.         textDescipcion.setColumns(10);
  221.  
  222.         btnBuscar = new JButton("Buscar");
  223.         panel_1.add(btnBuscar, "10, 2, fill, top");
  224.  
  225.         panelInterior = new JPanel();
  226.         panelInterior.setBackground(SystemColor.menu);
  227.         panelSuperior.add(panelInterior, BorderLayout.CENTER);
  228.         panelInterior.setLayout(new BorderLayout(0, 0));
  229.         tablaRepuestos = new JTable(modelRepuestos);
  230.         scrollPaneRepuestos = new JScrollPane(tablaRepuestos);
  231.         panelInterior.add(scrollPaneRepuestos, BorderLayout.CENTER);
  232.  
  233.         panel_2 = new JPanel(new FlowLayout(FlowLayout.RIGHT));
  234.         panelSuperior.add(panel_2, BorderLayout.SOUTH);
  235.  
  236.         lblCantidad = new JLabel("Cantidad");
  237.         panel_2.add(lblCantidad);
  238.         lblCantidad.setHorizontalAlignment(SwingConstants.CENTER);
  239.  
  240.         textCantidad = new JTextField();
  241.         panel_2.add(textCantidad);
  242.         textCantidad.setColumns(10);
  243.  
  244.         btnAgregar = new JButton("Agregar");
  245.         btnAgregar.addActionListener(new ActionListener() {
  246.             public void actionPerformed(ActionEvent arg0) {
  247.             }
  248.         });
  249.         panel_2.add(btnAgregar);
  250.  
  251.         panelInferior = new JPanel();
  252.         panelInferior.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Carrito",
  253.                 TitledBorder.CENTER, TitledBorder.TOP, null, new Color(0, 0, 0)));
  254.         panelInferior.setBackground(SystemColor.menu);
  255.         panelDerecho.add(panelInferior);
  256.         panelInferior.setLayout(new BorderLayout(0, 0));
  257.  
  258.         scrollPaneRepuestosInferior = new JScrollPane();
  259.         panelInferior.add(scrollPaneRepuestosInferior, BorderLayout.CENTER);
  260.  
  261.         tablaRepuestosInferior = new JTable(modelRepuestosInferior);
  262.  
  263.         scrollPaneRepuestosInferior.setViewportView(tablaRepuestosInferior);
  264.  
  265.         panel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
  266.         panelInferior.add(panel, BorderLayout.SOUTH);
  267.  
  268.         btnEditar = new JButton("Editar");
  269.         btnEditar.setVisible(false);
  270.         panel.add(btnEditar);
  271.  
  272.         btnQuitar = new JButton("Quitar");
  273.         panel.add(btnQuitar);
  274.  
  275.         btnLimpiar = new JButton("Limpiar");
  276.         panel.add(btnLimpiar);
  277.         btnLimpiar.setVisible(false);
  278.     }
  279.  
  280.     public void clearDataRepuestos() {
  281.         modelRepuestos.setRowCount(0);
  282.     }
  283.  
  284.     public void clearDataRepuestosPlanificados() {
  285.         modelRepuestosInferior.setRowCount(0);
  286.     }
  287.  
  288.     public void display() {
  289.         setVisible(true);
  290.     }
  291.  
  292.     public void setDataRepuestosComprados(List<RepuestoCompradoDTO> repuestos) {
  293.         modelRepuestosInferior.setRowCount(0);
  294.         for (RepuestoCompradoDTO r : repuestos) {
  295.             idRepuestosComprados.add(r.getIdRepuestoComprado());
  296.             Object[] row = { r.getRepuesto().getCodigoRepuesto(), r.getRepuesto().getDescripcionRepuesto(),
  297.                     r.getRepuesto().getMarcaRepuesto(), r.getRepuesto().getFabricante(), r.getCantidad() };
  298.             modelRepuestosInferior.addRow(row);
  299.         }
  300.     }
  301.  
  302.     public void setDataRepuestos(List<RepuestoDTO> repuestos) {
  303.         modelRepuestos.setRowCount(0);
  304.         idRepuestos.clear();
  305.         for (RepuestoDTO r : repuestos) {
  306.             idRepuestos.add(r.getIdRepuesto());
  307.             Object[] row = { r.getCodigoRepuesto(), r.getDescripcionRepuesto(), r.getMarcaRepuesto(), r.getFabricante(),
  308.                     r.getStockRepuesto(), r.getPrecioRepuesto() };
  309.             modelRepuestos.addRow(row);
  310.         }
  311.     }
  312.  
  313.     public String getIdRepuesto() {
  314.         String ret = -1 + "";
  315.         if (tablaRepuestos.getSelectedRow() >= 0) {
  316.             ret = "" + idRepuestos.get(tablaRepuestos.getSelectedRow());
  317.         }
  318.         return ret;
  319.     }
  320.  
  321.     public String getCantidad() {
  322.         return textCantidad.getText();
  323.     }
  324.  
  325.     public void setActionOnAgregar(ActionListener listener) {
  326.         this.btnAgregar.addActionListener(listener);
  327.     }
  328.  
  329.     public void setActionOnCancelar(ActionListener listener) {
  330.         this.btnCancelar.addActionListener(listener);
  331.     }
  332.  
  333.     public void setActionOnAceptar(ActionListener listener) {
  334.         this.btnCrearFactura.addActionListener(listener);
  335.     }
  336.  
  337.     public void close() {
  338.         setVisible(false);
  339.     }
  340.  
  341.     public void setActionOnBuscar(ActionListener listener) {
  342.         this.btnBuscar.addActionListener(listener);
  343.     }
  344.    
  345.     public void setActionOnBuscarCliente(ActionListener listener) {
  346.         this.btnBuscarCliente.addActionListener(listener);
  347.     }
  348.  
  349.     public void setActionOnAgregarCliente(ActionListener listener) {
  350.         this.btnRegistrarCliente.addActionListener(listener);
  351.     }
  352.  
  353.     public String getMarca() {
  354.         return (String) comboMarcas.getSelectedItem();
  355.     }
  356.  
  357.     public String getDescripcion() {
  358.         return textDescipcion.getText();
  359.     }
  360.  
  361.     public void setDataMarcas(List<String> marcas) {
  362.         DefaultComboBoxModel<String> modelo = new DefaultComboBoxModel<>();
  363.         for (String marca : marcas) {
  364.             modelo.addElement(marca);
  365.         }
  366.         comboMarcas.setModel(modelo);
  367.     }
  368.  
  369.     public void setActionOnQuitar(ActionListener Listener) {
  370.         this.btnQuitar.addActionListener(Listener);
  371.     }
  372.  
  373.     public Integer getSeleccionado() {
  374.         return tablaRepuestosInferior.getSelectedRow();
  375.     }
  376.  
  377.     public void clearClienteData() {
  378.         panelCliente.clearData();
  379.     }
  380.  
  381.     public String getDniCliente() {
  382.         return this.tfDni.getText();
  383.     }
  384.  
  385.     public void setDataCliente(ClienteDTO cliente) {
  386.         this.panelCliente.setData(cliente);
  387.     }
  388.    
  389.     public void setData(List<RepuestoCompradoDTO> repuestos) {
  390.         modelRepuestosInferior.setRowCount(0);
  391.         idRepuestos.clear();
  392.         for (RepuestoCompradoDTO r : repuestos) {
  393.             idRepuestos.add(r.getIdRepuestoComprado());
  394.             Object[] row = { r.getRepuesto().getCodigoRepuesto(), r.getRepuesto().getDescripcionRepuesto(), r.getRepuesto().getMarcaRepuesto(), r.getRepuesto().getFabricante(),
  395.                     r.getRepuesto().getStockRepuesto(), r.getRepuesto().getStockMinimo(), r.getRepuesto().getPrecioRepuesto() };
  396.             modelRepuestosInferior.addRow(row);
  397.         }
  398.     }
  399.  
  400.     public JLabel getLblTotalFactura() {
  401.         return lblTotalFactura;
  402.     }
  403.  
  404.     public void setLblTotalFactura(JLabel lblTotalFactura) {
  405.         this.lblTotalFactura = lblTotalFactura;
  406.     }
  407.  
  408.     public JTextField getTfTotalFactura() {
  409.         return tfTotalFactura;
  410.     }
  411.  
  412.     public void setTfTotalFactura(JTextField tfTotalFactura) {
  413.         this.tfTotalFactura = tfTotalFactura;
  414.     }
  415.  
  416.     public void setActionOnCrearFactura(ActionListener listener) {
  417.         this.btnCrearFactura.addActionListener(listener);
  418.         //poner algun modal de confirmacion issue32s
  419.     }
  420.    
  421.     public void clear() {
  422.     this.modelRepuestosInferior.setRowCount(0);
  423.     this.panelCliente.clearData();
  424.     this.tfTotalFactura.setText("0.0");
  425.    
  426.     }
  427. }
  428.    
  429.    
  430.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement