/*
* 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 GUI;
import Pedidos.Comanda;
import Pedidos.Platillo;
import java.awt.print.PrinterException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableModel;
import org.jvnet.substance.SubstanceLookAndFeel;
import org.jvnet.substance.api.SubstanceConstants;
import org.jvnet.substance.api.SubstanceSkin;
import org.jvnet.substance.skin.CremeCoffeeSkin;
import org.jvnet.substance.watermark.SubstanceImageWatermark;
/**
*
* @author Administrador
*/
public class ventanaVerComanda extends javax.swing.JFrame {
Comanda orden;
/**
* Creates new form ventanaVerComanda
*/
public ventanaVerComanda() {
orden = new Comanda();
initComponents();
// SubstanceImageWatermark watermark = new SubstanceImageWatermark("GUI/res/login.jpg");
// watermark.setKind(SubstanceConstants.ImageWatermarkKind.APP_TILE);
// SubstanceSkin skin = new CremeCoffeeSkin().withWatermark(watermark); // 初始化有水印的皮肤
// SubstanceLookAndFeel.setSkin(skin);
}
/**
* 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();
jButton1 = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
tblOrden = new javax.swing.JTable();
jLabel6 = new javax.swing.JLabel();
txtCuenta = new javax.swing.JLabel();
btnQuitar = new javax.swing.JButton();
btnComentarios = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Resumen de Orden");
jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/res/ciaoicono.jpg"))); // NOI18N
jButton1.setText("volver");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
tblOrden.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
},
new String [] {
"Nombre", "Precio", "IVA", "Cantidad"
}
) {
Class[] types = new Class [] {
java.lang.String.class, java.lang.Double.class, java.lang.Double.class, java.lang.Integer.class
};
public Class getColumnClass(int columnIndex) {
return types [columnIndex];
}
});
jScrollPane1.setViewportView(tblOrden);
jLabel6.setText("Total de la Cuenta:");
txtCuenta.setText(String.format("%.2f", orden.getPrecio()));
txtCuenta.addComponentListener(new java.awt.event.ComponentAdapter() {
public void componentShown(java.awt.event.ComponentEvent evt) {
txtCuentaComponentShown(evt);
}
});
btnQuitar.setText("-");
btnQuitar.setToolTipText("Quitar platillo seleccionado");
btnQuitar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnQuitarActionPerformed(evt);
}
});
btnComentarios.setText("*");
btnComentarios.setToolTipText("Cerrar comanda y dejarla lista apra cobrar");
btnComentarios.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnComentariosActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(18, 18, 18)
.addComponent(jLabel1)
.addGap(18, 18, 18)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 389, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(btnQuitar)
.addComponent(btnComentarios))
.addContainerGap(34, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGap(136, 136, 136)
.addComponent(jLabel6)
.addGap(18, 18, 18)
.addComponent(txtCuenta)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton1)
.addGap(98, 98, 98))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnQuitar, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addComponent(btnComentarios)
.addGap(0, 120, Short.MAX_VALUE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel6)
.addComponent(txtCuenta))
.addComponent(jButton1))
.addGap(54, 54, 54))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
dispose();
}//GEN-LAST:event_jButton1ActionPerformed
private void btnComentariosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnComentariosActionPerformed
// int fila = tblOrden.getSelectedRow();
//
// String nombreSeleccionado = (String) tblOrden.getValueAt(fila, 0);
// System.out.println(nombreSeleccionado);
// Double precioSeleccionado = (Double) tblOrden.getValueAt(fila, 1);
// System.out.println(precioSeleccionado);
// Double IVASeleccionado = (Double) tblOrden.getValueAt(fila, 2);
// System.out.println(IVASeleccionado);
// int opcion = JOptionPane.showOptionDialog(this, "Editar Orden", "¿Qué le desea editar al platillo?", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, null, new String[]{"nombre", "precio", "IVA"}, "");
// if (opcion == JOptionPane.YES_OPTION) {
// //TODO cambiar en orden y cambiar en bd
// //tblOrden.getCellEditor()
// //TODO sincronizar tabla con orden
// //eliminar en órden y planchar a la bd
// //volver a llenar el modelo
////// }
String observaciones = JOptionPane.showInputDialog("Observaciones para el chef", orden.getOvservaciones());
System.out.println("Observaciones a carta:" + observaciones);
orden.setOvservaciones(observaciones);
mostrarPrecioActual();
}//GEN-LAST:event_btnComentariosActionPerformed
private void btnQuitarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnQuitarActionPerformed
//tblOrden.getCellEditor().addCellEditorListener(tblOrden);
int fila = tblOrden.getSelectedRow();
if (fila != -1) {//solo si hay algo seleccionado
String nombreSeleccionado = (String) tblOrden.getValueAt(fila, 0);
System.out.println(nombreSeleccionado);
Double precioSeleccionado = (Double) tblOrden.getValueAt(fila, 1);
System.out.println(precioSeleccionado);
Double IVASeleccionado = (Double) tblOrden.getValueAt(fila, 2);
System.out.println(IVASeleccionado);
if (JOptionPane.showConfirmDialog(this, "¿Relmante desea borrar " + nombreSeleccionado + " de la orden?") == JOptionPane.YES_OPTION) {
//TODO quitar la fila seleccionada
//orden.getPlatillos().remove(fila) //esto debería funcionar pero por si las dudas...
//orden.getPlatillos().contains(evt)
modeloPlatillosDeOrden mod = (modeloPlatillosDeOrden) tblOrden.getModel();
//Platillo platilloAQuitar = mod.getValueAtRow(fila);
mod.removeValueAtRow(fila);
//TODO sincronizar con orden
}
//aquí hay de dos sopas o quitar en la tabla y sincronizar en el objeto comanda
//o quitar en comanda y sincronizar todo el modelo (yo optaría por esa)
mostrarPrecioActual();
}
}//GEN-LAST:event_btnQuitarActionPerformed
private void txtCuentaComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_txtCuentaComponentShown
mostrarPrecioActual();
}//GEN-LAST:event_txtCuentaComponentShown
public Comanda getOrden() {
return orden;
}
public void setOrden(Comanda orden) {
this.orden = orden;
//TODO cargar en tabla fill jtable en google
// Vector<String> nombresDeColumnas = new Vector<>();
// nombresDeColumnas.add("Nombre");
// nombresDeColumnas.add("Precio");
//nombresDeColumnas.add("IVA");
// Vector<Platillo> datos = new Vector<Platillo>(orden.getPlatillosVec());
//TODO error en set table model
//tblOrden.setModel(new DefaultTableModel(datos, nombresDeColumnas));
modeloPlatillosDeOrden modelo = new modeloPlatillosDeOrden(orden);
tblOrden.setModel(modelo);
}
private void mostrarPrecioActual() {
txtCuenta.setText(String.format("%.2f", orden.getPrecio()));//para mostrar el precio cada vez que se abra o cambie algo
}
class modeloPlatillosDeOrden extends AbstractTableModel {
private List<Platillo> l;
private String[] columnNames = {"Nombre", "Precio", "IVA", "Cantidad"};
public modeloPlatillosDeOrden(Comanda orden) {
// Vector<Platillo> datos = new Vector<Platillo>(orden.getPlatillosVec());
// l = new ArrayList<Platillo>();
l = orden.getPlatillos();
// l.add(new Platillo("45.573715", "-73.900295"));
// l.add(new Platillo("45.573715", "-73.900295"));
// l.add(new Platillo("45.573715", "-73.900295"));
}
@Override
public String getColumnName(int column) {
return columnNames[column];
}
@Override
public int getColumnCount() {
return 4;
}
@Override
public int getRowCount() {
return l.size();
}
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
if (rowIndex >= 0) {
if (columnIndex == 0) {
return l.get(rowIndex).getNombrePlatillo();
} else if (columnIndex == 1) {
return l.get(rowIndex).getPrecio();
} else if (columnIndex == 2) {
return l.get(rowIndex).getIva();
} else if (columnIndex == 3) {
return l.get(rowIndex).getCantidad();
}
}
return null;
}
/**
* Permite obtener
*/
public Platillo getValueAtRow(int rowIndex) {
if (rowIndex >= 0) {
return l.get(rowIndex);
}
return null;
}
private void removeValueAtRow(int fila) {
l.remove(getValueAtRow(fila));
}
private void addRow(Object[] row) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
@Override
public void setVisible(boolean b) {
super.setVisible(b);
mostrarPrecioActual();
}
/**
* @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(ventanaVerComanda.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(ventanaVerComanda.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(ventanaVerComanda.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(ventanaVerComanda.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new ventanaVerComanda().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnComentarios;
private javax.swing.JButton btnQuitar;
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel6;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable tblOrden;
private javax.swing.JLabel txtCuenta;
// End of variables declaration//GEN-END:variables
}