Advertisement
LaCaraDeLaVerga

carrito de compas

Nov 15th, 2020
1,258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.11 KB | None | 0 0
  1. package presentacion.views.cajero;
  2.  
  3. import java.awt.BorderLayout;
  4. import java.awt.Color;
  5. import java.awt.FlowLayout;
  6. import java.awt.SystemColor;
  7. import java.awt.event.ActionListener;
  8. import java.util.ArrayList;
  9. import java.util.List;
  10.  
  11. import javax.swing.BoxLayout;
  12. import javax.swing.DefaultComboBoxModel;
  13. import javax.swing.JButton;
  14. import javax.swing.JComboBox;
  15. import javax.swing.JInternalFrame;
  16. import javax.swing.JLabel;
  17. import javax.swing.JPanel;
  18. import javax.swing.JScrollPane;
  19. import javax.swing.JTable;
  20. import javax.swing.JTextField;
  21. import javax.swing.SwingConstants;
  22. import javax.swing.UIManager;
  23. import javax.swing.border.TitledBorder;
  24. import javax.swing.table.DefaultTableModel;
  25.  
  26. import com.jgoodies.forms.layout.ColumnSpec;
  27. import com.jgoodies.forms.layout.FormLayout;
  28. import com.jgoodies.forms.layout.FormSpecs;
  29. import com.jgoodies.forms.layout.RowSpec;
  30.  
  31. import dto.RepuestoDTO;
  32. import dto.RepuestoPlanificadoDTO;
  33.  
  34. public class PanelCarritoRepuestoView extends JInternalFrame {
  35.  
  36.     private static final long serialVersionUID = -3149040258338164711L;
  37.  
  38.     private final JPanel contentPanel = new JPanel();
  39.  
  40.     private static final String[] nombreColumnasSuperior = { "Codigo", "Descripcion", "Marca", "Fabricante", "Stock",
  41.             "Precio" };
  42.     private static final String[] nombreColumnasInferior = { "Codigo", "Descripcion", "Marca", "Fabricante",
  43.             "Cantidad" };
  44.  
  45.     private JPanel panelSuperior = new JPanel();
  46.     private JPanel panelInterior = new JPanel();
  47.     private JComboBox<String> comboMarcas;
  48.     private JLabel lblDescripcion;
  49.     private JTextField textDescipcion;
  50.     private JButton btnBuscar;
  51.     private JScrollPane scrollPaneRepuestos;
  52.     private DefaultTableModel modelRepuestos;
  53.     private JTable tablaRepuestos;
  54.  
  55.     private JPanel panelInferior = new JPanel();
  56.     private JScrollPane scrollPaneRepuestosInferior;
  57.     private DefaultTableModel modelRepuestosInferior;
  58.     private JTable tablaRepuestosInferior;
  59.  
  60.     static PanelCarritoRepuestoView vista;
  61.  
  62.     private JButton btnLimpiar;
  63.     private JButton btnQuitar;
  64.     private JButton btnEditar;
  65.     private JButton btnAgregar;
  66.     private JLabel lblCantidad;
  67.     private JTextField textCantidad;
  68.     private JPanel panel;
  69.     private JPanel panel_1;
  70.     private JPanel panel_2;
  71.     private List<Integer> idRepuestos;
  72.     private JButton btnAceptar;
  73.     private JButton btnCancelar;
  74.  
  75.     public static PanelCarritoRepuestoView getInstance() {
  76.         if (vista == null)
  77.             vista = new PanelCarritoRepuestoView();
  78.         return vista;
  79.     }
  80.  
  81.     @SuppressWarnings("serial")
  82.     private PanelCarritoRepuestoView() {
  83. //      setModal(true);
  84.         setBounds(100, 100, 500, 600);
  85.         setTitle("Carrito de compras");
  86.         getContentPane().setLayout(new BorderLayout());
  87.  
  88.         idRepuestos = new ArrayList<>();
  89.         getContentPane().add(contentPanel, BorderLayout.CENTER);
  90.         contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS));
  91.  
  92.         panelSuperior = new JPanel();
  93.         panelSuperior.setForeground(SystemColor.menu);
  94.         panelSuperior.setBorder(
  95.                 new TitledBorder(null, "Repuestos disponibles", TitledBorder.CENTER, TitledBorder.TOP, null, null));
  96.         panelSuperior.setBackground(SystemColor.menu);
  97.         contentPanel.add(panelSuperior);
  98.         panelSuperior.setLayout(new BorderLayout(0, 0));
  99.  
  100.         modelRepuestos = new DefaultTableModel(null, nombreColumnasSuperior) {
  101.             @Override
  102.             public boolean isCellEditable(int row, int column) {
  103.                 return false;
  104.             }
  105.         };
  106.  
  107.         panel_1 = new JPanel();
  108.         panelSuperior.add(panel_1, BorderLayout.NORTH);
  109.         panel_1.setLayout(new FormLayout(
  110.                 new ColumnSpec[] { ColumnSpec.decode("10px"), ColumnSpec.decode("132px"),
  111.                         FormSpecs.LABEL_COMPONENT_GAP_COLSPEC, ColumnSpec.decode("right:75px"),
  112.                         FormSpecs.LABEL_COMPONENT_GAP_COLSPEC, ColumnSpec.decode("86px:grow"),
  113.                         FormSpecs.LABEL_COMPONENT_GAP_COLSPEC, ColumnSpec.decode("65px"), },
  114.                 new RowSpec[] { FormSpecs.LINE_GAP_ROWSPEC, RowSpec.decode("23px"), }));
  115.  
  116.         comboMarcas = new JComboBox<>();
  117.         panel_1.add(comboMarcas, "2, 2, default, center");
  118.  
  119.         lblDescripcion = new JLabel();
  120.         panel_1.add(lblDescripcion, "4, 2, right, center");
  121.         lblDescripcion.setHorizontalAlignment(SwingConstants.CENTER);
  122.         lblDescripcion.setText("Descripción");
  123.  
  124.         textDescipcion = new JTextField();
  125.         panel_1.add(textDescipcion, "6, 2, default, center");
  126.         textDescipcion.setColumns(10);
  127.  
  128.         btnBuscar = new JButton("Buscar");
  129.         panel_1.add(btnBuscar, "8, 2, left, top");
  130.  
  131.         panelInterior = new JPanel();
  132.         panelInterior.setBackground(SystemColor.menu);
  133.         panelSuperior.add(panelInterior, BorderLayout.CENTER);
  134.         panelInterior.setLayout(new BorderLayout(0, 0));
  135.         tablaRepuestos = new JTable(modelRepuestos);
  136.         scrollPaneRepuestos = new JScrollPane(tablaRepuestos);
  137.         panelInterior.add(scrollPaneRepuestos, BorderLayout.CENTER);
  138.  
  139.         panel_2 = new JPanel(new FlowLayout(FlowLayout.RIGHT));
  140.         panelSuperior.add(panel_2, BorderLayout.SOUTH);
  141.  
  142.         lblCantidad = new JLabel("Cantidad");
  143.         panel_2.add(lblCantidad);
  144.         lblCantidad.setHorizontalAlignment(SwingConstants.CENTER);
  145.  
  146.         textCantidad = new JTextField();
  147.         panel_2.add(textCantidad);
  148.         textCantidad.setColumns(10);
  149.  
  150.         btnAgregar = new JButton("Agregar");
  151.         panel_2.add(btnAgregar);
  152.  
  153.         panelInferior = new JPanel();
  154.         panelInferior.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Repuestos planificados",
  155.                 TitledBorder.CENTER, TitledBorder.TOP, null, new Color(0, 0, 0)));
  156.         panelInferior.setBackground(SystemColor.menu);
  157.         contentPanel.add(panelInferior);
  158.         panelInferior.setLayout(new BorderLayout(0, 0));
  159.  
  160.         scrollPaneRepuestosInferior = new JScrollPane();
  161.         panelInferior.add(scrollPaneRepuestosInferior, BorderLayout.CENTER);
  162.  
  163.         modelRepuestosInferior = new DefaultTableModel(null, nombreColumnasInferior) {
  164.             @Override
  165.             public boolean isCellEditable(int row, int column) {
  166.                 return false;
  167.             }
  168.         };
  169.  
  170.         tablaRepuestosInferior = new JTable(modelRepuestosInferior);
  171.  
  172.         scrollPaneRepuestosInferior.setViewportView(tablaRepuestosInferior);
  173.  
  174.         panel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
  175.         panelInferior.add(panel, BorderLayout.SOUTH);
  176.  
  177.         btnEditar = new JButton("Editar");
  178.         panel.add(btnEditar);
  179.  
  180.         btnQuitar = new JButton("Quitar");
  181.         panel.add(btnQuitar);
  182.  
  183.         btnLimpiar = new JButton("Limpiar");
  184.         btnLimpiar.setVisible(false);
  185.         panel.add(btnLimpiar);
  186.  
  187.         JPanel buttonPane = new JPanel();
  188.         buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
  189.         getContentPane().add(buttonPane, BorderLayout.SOUTH);
  190.  
  191.         btnAceptar = new JButton("Aceptar");
  192.         btnAceptar.setActionCommand("OK");
  193.         buttonPane.add(btnAceptar);
  194.         getRootPane().setDefaultButton(btnAceptar);
  195.  
  196.         btnCancelar = new JButton("Cancelar");
  197.         btnCancelar.setVisible(false);
  198.         btnCancelar.setActionCommand("Cancel");
  199.         buttonPane.add(btnCancelar);
  200.  
  201.         setVisible(false);
  202.     }
  203.  
  204.     public void clearDataRepuestos() {
  205.         modelRepuestos.setRowCount(0);
  206.     }
  207.  
  208.     public void clearDataRepuestosPlanificados() {
  209.         modelRepuestosInferior.setRowCount(0);
  210.     }
  211.  
  212.     public void display() {
  213.         setVisible(true);
  214.     }
  215.  
  216.     public void setDataRepuestosPlanificados(List<RepuestoPlanificadoDTO> repuestos) {
  217.         modelRepuestosInferior.setRowCount(0);
  218.         for (RepuestoPlanificadoDTO r : repuestos) {
  219.             idRepuestos.add(r.getIdRepuestoPlanificado());
  220.             Object[] row = { r.getRepuesto().getCodigoRepuesto(), r.getRepuesto().getDescripcionRepuesto(),
  221.                     r.getRepuesto().getMarcaRepuesto(), r.getRepuesto().getFabricante(), r.getCantRequerida() };
  222.             modelRepuestosInferior.addRow(row);
  223.         }
  224.     }
  225.  
  226.     public void setDataRepuestos(List<RepuestoDTO> repuestos) {
  227.         modelRepuestos.setRowCount(0);
  228.         for (RepuestoDTO r : repuestos) {
  229.             idRepuestos.add(r.getIdRepuesto());
  230.             Object[] row = { r.getCodigoRepuesto(), r.getDescripcionRepuesto(), r.getMarcaRepuesto(), r.getFabricante(),
  231.                     r.getStockRepuesto(), r.getPrecioRepuesto() };
  232.             modelRepuestos.addRow(row);
  233.         }
  234.     }
  235.  
  236.     public String getIdRepuesto() {
  237.         String ret = -1 + "";
  238.         if (tablaRepuestos.getSelectedRow() >= 0) {
  239.             ret = "" + idRepuestos.get(tablaRepuestos.getSelectedRow());
  240.         }
  241.         return ret;
  242.     }
  243.  
  244.     public String getCantidad() {
  245.         return textCantidad.getText();
  246.     }
  247.  
  248.     public void setActionOnAgregar(ActionListener listener) {
  249.         this.btnAgregar.addActionListener(listener);
  250.     }
  251.  
  252.     public void setActionOnCancelar(ActionListener listener) {
  253.         this.btnCancelar.addActionListener(listener);
  254.     }
  255.  
  256.     public void setActionOnAceptar(ActionListener listener) {
  257.         this.btnAceptar.addActionListener(listener);
  258.     }
  259.  
  260.     public void close() {
  261.         setVisible(false);
  262.     }
  263.  
  264.     public void setActionOnBuscar(ActionListener listener) {
  265.         this.btnBuscar.addActionListener(listener);
  266.     }
  267.  
  268.     public String getMarca() {
  269.         return (String) comboMarcas.getSelectedItem();
  270.     }
  271.  
  272.     public String getDescripcion() {
  273.         return textDescipcion.getText();
  274.     }
  275.  
  276.     public void setDataMarcas(List<String> marcas) {
  277.         DefaultComboBoxModel<String> modelo = new DefaultComboBoxModel<>();
  278.         for (String marca : marcas) {
  279.             modelo.addElement(marca);
  280.         }
  281.         comboMarcas.setModel(modelo);
  282.     }
  283.    
  284.     public void setActionOnQuitar(ActionListener Listener) {
  285.         this.btnQuitar.addActionListener(Listener);
  286.     }
  287.  
  288.     public Integer getSeleccionado() {
  289.         return tablaRepuestosInferior.getSelectedRow();
  290.     }
  291. }
  292.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement