List of usage examples for javax.swing JDialog add
public Component add(Component comp)
From source file:interfaces.InterfazPrincipal.java
private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed // TODO add your handling code here: String nombre = jTextFieldNombreSaldoProveedores.getText(); ControladorProveedores controladorProveedores = new ControladorProveedores(); ArrayList<Proveedores> listaProveedores = controladorProveedores.obtenerProveedores("", nombre); final JDialog dialogoEditar = new JDialog(this); dialogoEditar.setTitle("Buscar proveedores"); dialogoEditar.setSize(500, 300);//from ww w . j av a 2 s . c o m dialogoEditar.setResizable(false); JPanel panelDialogo = new JPanel(); panelDialogo.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; JLabel ediitarTextoPrincipalDialogo = new JLabel("Buscar Proveedores"); c.gridx = 0; c.gridy = 0; c.gridwidth = 3; c.insets = new Insets(10, 60, 10, 10); Font textoGrande = new Font("Arial", 1, 16); ediitarTextoPrincipalDialogo.setFont(textoGrande); panelDialogo.add(ediitarTextoPrincipalDialogo, c); c.gridx = 0; c.gridy = 1; c.gridwidth = 3; c.insets = new Insets(10, 10, 10, 10); final JTable tablaDialogo = new JTable(); DefaultTableModel modeloTabla = new DefaultTableModel() { @Override public boolean isCellEditable(int row, int column) { //all cells false return false; } }; ; modeloTabla.addColumn("ID"); modeloTabla.addColumn("Identificacin"); modeloTabla.addColumn("Nombre"); //LLenar tabla for (int i = 0; i < listaProveedores.size(); i++) { Object[] data = { "1", "2", "3" }; data[0] = listaProveedores.get(i).getID(); data[1] = listaProveedores.get(i).getIdentificacion(); data[2] = listaProveedores.get(i).getNombre(); System.out.println("Nombre!!" + data[2]); modeloTabla.addRow(data); } tablaDialogo.setModel(modeloTabla); tablaDialogo.getColumn("ID").setMinWidth(70); tablaDialogo.getColumn("Identificacin").setMinWidth(60); tablaDialogo.getColumn("Nombre").setMinWidth(150); tablaDialogo.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JScrollPane scroll = new JScrollPane(tablaDialogo); scroll.setPreferredSize(new Dimension(220, 150)); panelDialogo.add(scroll, c); c.insets = new Insets(0, 0, 0, 10); c.gridx = 0; c.gridy = 2; c.gridwidth = 1; JButton botonGuardarClienteDialogo = new JButton("Elegir"); panelDialogo.add(botonGuardarClienteDialogo, c); c.gridx = 1; c.gridy = 2; c.gridwidth = 1; JButton botonCerrarClienteDialogo = new JButton("Cancelar"); panelDialogo.add(botonCerrarClienteDialogo, c); dialogoEditar.add(panelDialogo); dialogoEditar.setVisible(true); botonCerrarClienteDialogo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dialogoEditar.dispose(); } }); botonGuardarClienteDialogo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int row = tablaDialogo.getSelectedRow(); if (row == -1) { JOptionPane.showMessageDialog(dialogoEditar, "Por favor seleccione una fila"); } else { Object identificacionCliente = tablaDialogo.getValueAt(row, 0); Object idCliente = tablaDialogo.getValueAt(row, 1); mostrarIDProveedor.setText(String.valueOf(identificacionCliente)); String nombreClientePago = String.valueOf(tablaDialogo.getValueAt(row, 2)); //Limitar a 15 caracteres if (nombreClientePago.length() >= 15) { nombreClientePago = nombreClientePago.substring(0, 12); } textoNombreProveedor.setText(nombreClientePago); DefaultTableModel modeloClientes = (DefaultTableModel) TablaDeSaldoProveedor.getModel(); for (int i = 0; i < modeloClientes.getRowCount(); i++) { modeloClientes.removeRow(i); } modeloClientes.setRowCount(0); ControladorFlujoCompras controladorFlujoCompra = new ControladorFlujoCompras(); //SELECT * FROM Flujo_Factura where factura_id in (select factura_id from Factura where cliente_id = 1130614506); ArrayList<Flujo_Compra> flujosProveedor = controladorFlujoCompra.obtenerFlujosCompras( " where ID_CompraProveedor in (select ID_CompraProveedor from Compra_Proveedores where IDProveedor = " + String.valueOf(identificacionCliente) + ") order by ID_CompraProveedor"); double pago = 0.0; for (int i = 0; i < flujosProveedor.size(); i++) { Flujo_Compra datos = flujosProveedor.get(i); Object[] rowData = { datos.getID_CompraProveedor(), datos.getTipo_flujo(), datos.getFecha(), datos.getMonto() }; if (datos.getTipo_flujo().equals("deuda")) { pago += Double.parseDouble(datos.getMonto() + ""); } else { pago -= Double.parseDouble(datos.getMonto() + ""); } modeloClientes.addRow(rowData); } TablaDeSaldoProveedor.setModel(modeloClientes); deudaActualProveedor.setText(String.valueOf(pago)); dialogoEditar.dispose(); //Mostrar en table de clientes los datos botonRegistrarAbono.setEnabled(true); } } }); }
From source file:interfaces.InterfazPrincipal.java
private void TablaDeFacturaProductoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_TablaDeFacturaProductoMouseClicked final int fila = TablaDeFacturaProducto.getSelectedRow(); final DefaultTableModel modeloTabla = (DefaultTableModel) TablaDeFacturaProducto.getModel(); //int identificacion = (int) TablaDeFacturaProducto.getValueAt(fila, 0); // TODO add your handling code here: final JDialog dialogoEdicionProducto = new JDialog(this); dialogoEdicionProducto.setTitle("Editar producto"); dialogoEdicionProducto.setSize(250, 150); dialogoEdicionProducto.setResizable(false); JPanel panelDialogo = new JPanel(); panelDialogo.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; JLabel editarTextoPrincipalDialogo = new JLabel("Editar producto"); c.gridx = 0;/*w ww.j a v a 2 s. c o m*/ c.gridy = 0; c.gridwidth = 3; c.insets = new Insets(15, 40, 10, 0); Font textoGrande = new Font("Arial", 1, 18); editarTextoPrincipalDialogo.setFont(textoGrande); panelDialogo.add(editarTextoPrincipalDialogo, c); c.insets = new Insets(0, 0, 0, 0); c.gridwidth = 0; c.gridy = 1; c.gridx = 0; JLabel textoUnidades = new JLabel("Unidades"); panelDialogo.add(textoUnidades, c); c.gridy = 1; c.gridx = 1; c.gridwidth = 2; final JTextField valorUnidades = new JTextField(); valorUnidades.setText(String.valueOf(modeloTabla.getValueAt(fila, 4))); panelDialogo.add(valorUnidades, c); c.gridwidth = 1; c.gridy = 2; c.gridx = 0; JButton guardarCambios = new JButton("Guardar"); panelDialogo.add(guardarCambios, c); c.gridy = 2; c.gridx = 1; JButton eliminarProducto = new JButton("Eliminar"); panelDialogo.add(eliminarProducto, c); c.gridy = 2; c.gridx = 2; JButton botonCancelar = new JButton("Cerrar"); panelDialogo.add(botonCancelar, c); botonCancelar.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dialogoEdicionProducto.dispose(); } }); eliminarProducto.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { double precio = (double) modeloTabla.getValueAt(fila, 6); double precioActual = Double.parseDouble(valorActualFactura.getText()); precioActual -= precio; valorActualFactura.setText(String.valueOf(precioActual)); modeloTabla.removeRow(fila); dialogoEdicionProducto.dispose(); } }); guardarCambios.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { int numeroUnidades = Integer.parseInt(valorUnidades.getText()); modeloTabla.setValueAt(numeroUnidades, fila, 4); double precioARestar = (double) modeloTabla.getValueAt(fila, 6); double valorUnitario = Double.parseDouble((String) modeloTabla.getValueAt(fila, 5)); double precioNuevo = valorUnitario * numeroUnidades; modeloTabla.setValueAt(precioNuevo, fila, 6); double precioActual = Double.parseDouble(valorActualFactura.getText()); precioActual -= precioARestar; precioActual += precioNuevo; valorActualFactura.setText(String.valueOf(precioActual)); dialogoEdicionProducto.dispose(); } catch (Exception eve) { JOptionPane.showMessageDialog(dialogoEdicionProducto, "Por favor ingrese un valor numrico"); } } }); dialogoEdicionProducto.add(panelDialogo); dialogoEdicionProducto.setVisible(true); }
From source file:interfaces.InterfazPrincipal.java
private void TablaDeProductosMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_TablaDeProductosMouseClicked // TODO add your handling code here: int fila = TablaDeProductos.getSelectedRow(); final int identificacion = (int) TablaDeProductos.getValueAt(fila, 1); final ControladorProducto controladorP = new ControladorProducto(); ArrayList<Productos> listaProductos = controladorP.getProducto(" where producto_id = " + identificacion); final Productos productoActual = listaProductos.get(0); final JDialog dialogoEditar = new JDialog(this); dialogoEditar.setTitle("Editar clientes"); dialogoEditar.setSize(600, 310);/* ww w.j av a2 s .c o m*/ dialogoEditar.setResizable(false); JPanel panelDialogo = new JPanel(); panelDialogo.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; JLabel editarTextoPrincipalDialogo = new JLabel("Editar producto"); c.gridx = 0; c.gridy = 0; c.gridwidth = 4; c.insets = new Insets(15, 200, 40, 0); c.ipadx = 100; Font textoGrande = new Font("Arial", 1, 18); editarTextoPrincipalDialogo.setFont(textoGrande); panelDialogo.add(editarTextoPrincipalDialogo, c); c.insets = new Insets(0, 5, 10, 0); c.gridx = 0; c.gridy = 1; c.gridwidth = 1; c.ipadx = 40; JLabel editarNombreClienteDialogo = new JLabel("Nombre:"); panelDialogo.add(editarNombreClienteDialogo, c); c.gridx = 1; c.gridy = 1; c.gridwidth = 1; c.ipadx = 100; c.insets = new Insets(0, 15, 10, 15); final JTextField valorEditarNombreClienteDialogo = new JTextField(); valorEditarNombreClienteDialogo.setText(productoActual.getNombre()); panelDialogo.add(valorEditarNombreClienteDialogo, c); final JTextField valorEditarUnidadesProductoDialogo = new JTextField(); valorEditarUnidadesProductoDialogo.setText(String.valueOf(productoActual.getUnidadesDisponibles())); panelDialogo.add(valorEditarUnidadesProductoDialogo, c); c.gridx = 2; c.gridy = 1; c.gridwidth = 1; c.ipadx = 40; c.insets = new Insets(0, 15, 10, 0); JLabel editarTelefonoClienteDialogo = new JLabel("Precio"); panelDialogo.add(editarTelefonoClienteDialogo, c); c.gridx = 3; c.gridy = 1; c.gridwidth = 1; c.ipadx = 100; c.insets = new Insets(0, 0, 10, 0); c.gridx = 0; c.gridy = 2; c.gridwidth = 1; c.ipadx = 40; c.insets = new Insets(0, 5, 10, 0); JLabel editarCelularClienteDialogo = new JLabel("Descripcion:"); panelDialogo.add(editarCelularClienteDialogo, c); c.gridx = 1; c.gridy = 2; c.gridwidth = 1; c.ipadx = 100; c.insets = new Insets(0, 15, 10, 15); final JTextField valorEditarDescripcionProductoDialogo = new JTextField(); valorEditarDescripcionProductoDialogo.setText(productoActual.getDescripcion()); panelDialogo.add(valorEditarDescripcionProductoDialogo, c); c.gridx = 2; c.gridy = 2; c.gridwidth = 1; c.ipadx = 40; c.insets = new Insets(0, 5, 10, 0); JLabel editarMontoClienteDialogo = new JLabel("Unidades"); panelDialogo.add(editarMontoClienteDialogo, c); c.gridx = 3; c.gridy = 2; c.gridwidth = 1; c.ipadx = 100; c.insets = new Insets(0, 15, 10, 15); final JTextField valorEditarPrecioProductoDialogo = new JTextField(); valorEditarPrecioProductoDialogo.setText(productoActual.getPrecio() + ""); panelDialogo.add(valorEditarPrecioProductoDialogo, c); c.gridx = 0; c.gridy = 3; c.gridwidth = 1; c.ipadx = 40; c.insets = new Insets(0, 5, 10, 0); JLabel editarCodigoBarrasProyecto = new JLabel("Cdigo de barras:"); panelDialogo.add(editarCodigoBarrasProyecto, c); c.gridx = 1; c.gridy = 3; c.gridwidth = 1; c.ipadx = 100; c.insets = new Insets(0, 15, 10, 15); final JTextField valorCodigoDeBarras = new JTextField(); valorCodigoDeBarras.setText(productoActual.getCodigoBarras()); panelDialogo.add(valorCodigoDeBarras, c); c.gridx = 0; c.gridy = 4; c.gridwidth = 2; c.ipadx = 100; c.insets = new Insets(15, 40, 0, 0); JButton botonGuardarProductoDialogo = new JButton("Guardar"); panelDialogo.add(botonGuardarProductoDialogo, c); c.gridx = 2; c.gridy = 4; c.gridwidth = 2; c.insets = new Insets(15, 40, 0, 0); c.ipadx = 100; JButton botonCerrarProductoDialogo = new JButton("Cancelar"); panelDialogo.add(botonCerrarProductoDialogo, c); dialogoEditar.add(panelDialogo); botonCerrarProductoDialogo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dialogoEditar.dispose(); } }); botonGuardarProductoDialogo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { String[] selection = { "nombre", "descripcion", "unidades", "precio", "codigoBarras" }; String[] value = { valorEditarNombreClienteDialogo.getText(), valorEditarDescripcionProductoDialogo.getText(), valorEditarUnidadesProductoDialogo.getText(), valorEditarPrecioProductoDialogo.getText(), valorCodigoDeBarras.getText() }; String[] type_value = { "varchar", "varchar", "int", "double", "varchar" }; String restriction = " where producto_id = " + identificacion; controladorP.updateProduct(selection, value, type_value, restriction); JOptionPane.showMessageDialog(dialogoEditar, "Se ha editado el producto xitosamente"); dialogoEditar.dispose(); //Refrescar busqueda actual jButton2ActionPerformed(null); } catch (Exception event) { JOptionPane.showMessageDialog(dialogoEditar, "El valor del monto debe ser numrico"); } } }); dialogoEditar.setVisible(true); }
From source file:interfaces.InterfazPrincipal.java
private void botonAgregarProductoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonAgregarProductoActionPerformed String nombre = jTextField_Factura_Producto_Nombre.getText(); String descripcion = jTextField_Factura_Producto_Descripcion.getText(); ControladorProducto controladorPro = new ControladorProducto(); String restriccion = ""; boolean encounter = true; if (!nombre.equals("")) { if (encounter) { encounter = false;/*from w w w .j av a 2s.c om*/ restriccion = " where "; } else { restriccion += " OR "; } restriccion += " nombre like '%" + nombre + "%'"; } if (!descripcion.equals("")) { if (encounter) { encounter = false; restriccion = " where "; } else { restriccion += " OR "; } restriccion += " descripcion like '%" + descripcion + "%'"; } ArrayList<Productos> listaDeProductos = controladorPro.getProducto(restriccion); final JDialog dialogoEditar = new JDialog(this); dialogoEditar.setTitle("Buscar clientes"); dialogoEditar.setSize(600, 310); dialogoEditar.setResizable(false); JPanel panelDialogo = new JPanel(); panelDialogo.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; JLabel editarTextoPrincipalDialogo = new JLabel("Buscar Producto"); c.gridx = 0; c.gridy = 0; c.gridwidth = 6; c.insets = new Insets(15, 200, 40, 0); c.ipadx = 100; Font textoGrande = new Font("Arial", 1, 18); editarTextoPrincipalDialogo.setFont(textoGrande); panelDialogo.add(editarTextoPrincipalDialogo, c); final JTable table = new JTable(); DefaultTableModel modeloTabla = new DefaultTableModel() { @Override public boolean isCellEditable(int row, int column) { //all cells false return false; } }; ; modeloTabla.addColumn("Numero"); modeloTabla.addColumn("Identificacin"); modeloTabla.addColumn("Nombre"); modeloTabla.addColumn("Descripcion"); modeloTabla.addColumn("Unidades Disponibles"); modeloTabla.addColumn("Precio"); //LLenar tabla for (int i = 0; i < listaDeProductos.size(); i++) { Object[] data = { "1", "2", "3", "4", "5", "6" }; data[0] = (i + 1); data[1] = listaDeProductos.get(i).getProductoId(); data[2] = listaDeProductos.get(i).getNombre(); data[3] = listaDeProductos.get(i).getDescripcion(); data[4] = listaDeProductos.get(i).getUnidadesDisponibles(); data[5] = listaDeProductos.get(i).getPrecio(); modeloTabla.addRow(data); } table.setModel(modeloTabla); table.getColumn("Numero").setMinWidth(50); table.getColumn("Identificacin").setMinWidth(50); table.getColumn("Nombre").setMinWidth(110); table.getColumn("Descripcion").setMinWidth(110); table.getColumn("Unidades Disponibles").setMinWidth(40); table.getColumn("Precio").setMinWidth(110); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JScrollPane scroll = new JScrollPane(table); scroll.setPreferredSize(new Dimension(320, 150)); //final JTable table = new JTable(row, col); table.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { //jTextField_Factura_Cliente_Id.setText(table.getValueAt(table.getSelectedRow(), 1).toString()); //System.out.println(table.getValueAt(table.getSelectedRow(), 3).toString()); DefaultTableModel modelo = (DefaultTableModel) TablaDeFacturaProducto.getModel(); Object[] fila = new Object[7]; fila[0] = table.getValueAt(table.getSelectedRow(), 0).toString(); fila[1] = table.getValueAt(table.getSelectedRow(), 1).toString(); fila[2] = table.getValueAt(table.getSelectedRow(), 2).toString(); fila[3] = table.getValueAt(table.getSelectedRow(), 3).toString(); //fila[4] = table.getValueAt(table.getSelectedRow(), 4).toString(); fila[4] = (String) JOptionPane.showInputDialog("Ingrese el nmero de unidades que va a vender"); fila[5] = table.getValueAt(table.getSelectedRow(), 5).toString(); Double valorProducto = Double.parseDouble((String) fila[5]); String valorActualProducto = String.valueOf(Double.parseDouble(valorActualFactura.getText()) + Double.parseDouble((String) fila[4]) * valorProducto); valorActualFactura.setText(valorActualProducto); fila[6] = Double.parseDouble((String) fila[4]) * valorProducto; modelo.addRow(fila); //modelo.getColumnName(4). /*TablaDeFacturaProducto.setModel(modelo); TablaDeFacturaProducto.getColumnClass(4). ;*/ dialogoEditar.dispose(); } }); c.insets = new Insets(0, 5, 10, 0); c.gridx = 0; c.gridy = 1; c.gridwidth = 1; c.ipadx = 200; panelDialogo.add(scroll, c); //panelDialogo.add(table, c); dialogoEditar.add(panelDialogo); dialogoEditar.setVisible(true); }
From source file:interfaces.InterfazPrincipal.java
private void TablaDeClientesMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_TablaDeClientesMouseClicked // TODO add your handling code here: int fila = TablaDeClientes.getSelectedRow(); int identificacion = (int) TablaDeClientes.getValueAt(fila, 0); final ControladorCliente controladorCliente = new ControladorCliente(); ArrayList<Cliente> listaClientes = controladorCliente.obtenerClientes("", identificacion); final Cliente clienteActual = listaClientes.get(0); final JDialog dialogoEditar = new JDialog(this); dialogoEditar.setTitle("Editar clientes"); dialogoEditar.setSize(600, 310);//from w ww . j a v a2s .c o m dialogoEditar.setResizable(false); JPanel panelDialogo = new JPanel(); panelDialogo.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; JLabel editarTextoPrincipalDialogo = new JLabel("Editar clientes"); c.gridx = 0; c.gridy = 0; c.gridwidth = 4; c.insets = new Insets(15, 200, 40, 0); c.ipadx = 100; Font textoGrande = new Font("Arial", 1, 18); editarTextoPrincipalDialogo.setFont(textoGrande); panelDialogo.add(editarTextoPrincipalDialogo, c); c.insets = new Insets(0, 5, 10, 0); c.gridx = 0; c.gridy = 1; c.gridwidth = 1; c.ipadx = 40; JLabel editarNombreClienteDialogo = new JLabel("Nombre:"); panelDialogo.add(editarNombreClienteDialogo, c); c.gridx = 1; c.gridy = 1; c.gridwidth = 1; c.ipadx = 100; c.insets = new Insets(0, 15, 10, 15); final JTextField valorEditarNombreClienteDialogo = new JTextField(); valorEditarNombreClienteDialogo.setText(clienteActual.getNombre()); panelDialogo.add(valorEditarNombreClienteDialogo, c); c.gridx = 0; c.gridy = 2; c.gridwidth = 1; c.ipadx = 40; c.insets = new Insets(0, 5, 10, 0); JLabel editarCelularClienteDialogo = new JLabel("Celular:"); panelDialogo.add(editarCelularClienteDialogo, c); c.gridx = 1; c.gridy = 2; c.gridwidth = 1; c.ipadx = 100; c.insets = new Insets(0, 15, 10, 15); final JTextField valorEditarCelularClienteDialogo = new JTextField(); valorEditarCelularClienteDialogo.setText(clienteActual.getNumero_celular()); panelDialogo.add(valorEditarCelularClienteDialogo, c); c.gridx = 2; c.gridy = 2; c.gridwidth = 1; c.ipadx = 40; c.insets = new Insets(0, 5, 10, 0); JLabel editarMontoClienteDialogo = new JLabel("Monto a prestar:"); panelDialogo.add(editarMontoClienteDialogo, c); c.gridx = 3; c.gridy = 2; c.gridwidth = 1; c.ipadx = 100; c.insets = new Insets(0, 15, 10, 15); final JTextField valorEditarMontoClienteDialogo = new JTextField(); valorEditarMontoClienteDialogo.setText(String.valueOf(clienteActual.getMonto_prestamo())); panelDialogo.add(valorEditarMontoClienteDialogo, c); c.gridx = 2; c.gridy = 1; c.gridwidth = 1; c.ipadx = 40; c.insets = new Insets(0, 15, 10, 0); JLabel editarTelefonoClienteDialogo = new JLabel("Telefono:"); panelDialogo.add(editarTelefonoClienteDialogo, c); c.gridx = 3; c.gridy = 1; c.gridwidth = 1; c.ipadx = 100; c.insets = new Insets(0, 0, 10, 0); final JTextField valorEditarTelefonoClienteDialogo = new JTextField(); valorEditarTelefonoClienteDialogo.setText(clienteActual.getNumero_telefono()); panelDialogo.add(valorEditarTelefonoClienteDialogo, c); c.gridx = 0; c.gridy = 3; c.gridwidth = 1; c.ipadx = 40; c.insets = new Insets(0, 0, 10, 0); JLabel editarAddressClienteDialogo = new JLabel("Direccin:"); panelDialogo.add(editarAddressClienteDialogo, c); c.gridx = 1; c.gridy = 3; c.gridwidth = 3; c.ipadx = 400; c.insets = new Insets(0, 15, 10, 0); final JTextField valorEditarAddressClienteDialogo = new JTextField(); valorEditarAddressClienteDialogo.setText(clienteActual.getDireccion()); panelDialogo.add(valorEditarAddressClienteDialogo, c); c.gridx = 0; c.gridy = 4; c.gridwidth = 2; c.ipadx = 100; c.insets = new Insets(15, 40, 0, 0); JButton botonGuardarClienteDialogo = new JButton("Guardar"); panelDialogo.add(botonGuardarClienteDialogo, c); c.gridx = 2; c.gridy = 4; c.gridwidth = 2; c.insets = new Insets(15, 40, 0, 0); c.ipadx = 100; JButton botonCerrarClienteDialogo = new JButton("Cancelar"); panelDialogo.add(botonCerrarClienteDialogo, c); dialogoEditar.add(panelDialogo); botonCerrarClienteDialogo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dialogoEditar.dispose(); } }); botonGuardarClienteDialogo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { clienteActual.setDireccion(valorEditarAddressClienteDialogo.getText()); clienteActual.setMonto_prestamo(Double.parseDouble(valorEditarMontoClienteDialogo.getText())); clienteActual.setNombre(valorEditarNombreClienteDialogo.getText()); clienteActual.setNumero_celular(valorEditarCelularClienteDialogo.getText()); clienteActual.setNumero_telefono(valorEditarTelefonoClienteDialogo.getText()); controladorCliente.editarCliente(clienteActual); JOptionPane.showMessageDialog(dialogoEditar, "Se ha editado el cliente xitosamente"); dialogoEditar.dispose(); //Refrescar busqueda actual String nombreCliente = nombreClienteBusqueda.getText(); int identificacionClienteInt = 0; ControladorCliente controladorCliente = new ControladorCliente(); ArrayList<Cliente> listaDeClientes = controladorCliente.obtenerClientes(nombreCliente, identificacionClienteInt); //Agregar filas DefaultTableModel modelo = (DefaultTableModel) TablaDeClientes.getModel(); for (int i = 0; i < modelo.getRowCount(); i++) { modelo.removeRow(i); } modelo.setRowCount(0); for (int i = 0; i < listaDeClientes.size(); i++) { Cliente cliente = listaDeClientes.get(i); Object[] fila = new Object[4]; fila[0] = cliente.getCliente_id(); fila[1] = cliente.getNombre(); fila[2] = cliente.getMonto_prestamo(); //button.setText("<HTML>Click the <FONT color=\"#000099\"><U>link "+i+"</U></FONT>"+ " to go to the Java website.</HTML>"); fila[3] = "Editar"; modelo.addRow(fila); } TablaDeClientes.setModel(modelo); } catch (Exception event) { JOptionPane.showMessageDialog(dialogoEditar, "El valor del monto debe ser numrico"); } } }); dialogoEditar.setVisible(true); /*Action mostrarMensaje; mostrarMensaje = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { JTable table = (JTable) e.getSource(); int modelRow = Integer.valueOf(e.getActionCommand()); ((DefaultTableModel) table.getModel()).removeRow(modelRow); } }; ButtonColumn buttonColumn = new ButtonColumn(TablaDeClientes, mostrarMensaje, 3); buttonColumn.setMnemonic(KeyEvent.VK_E);*/ }
From source file:interfaces.InterfazPrincipal.java
private void tablaUsuariosDelSistemaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tablaUsuariosDelSistemaMouseClicked // TODO add your handling code here: String opcionHabilitar = "Habilitar"; String nombreUsuario = String .valueOf(tablaUsuariosDelSistema.getValueAt(tablaUsuariosDelSistema.getSelectedRow(), 0)); String estado = String .valueOf(tablaUsuariosDelSistema.getValueAt(tablaUsuariosDelSistema.getSelectedRow(), 2)); if (estado.equals("Habilitado")) { opcionHabilitar = "Deshabilitar"; }/*from w ww . j a va2 s . c o m*/ Object[] opciones = { "Cancelar", "Editar", opcionHabilitar }; final ControladorUsuarios controladorUsuarios = new ControladorUsuarios(); final Usuarios usuarioSelecionado = controladorUsuarios.obtenerUsuario(nombreUsuario); if (nombreUsuario.equals("admin") || nombreUsuario.equals(JTextFieldnombreDeUsuario.getText())) { JOptionPane.showMessageDialog(this, "No se puede editarse a si mismo o el usuario administrador del sistema", "Mensaje del sistema", JOptionPane.WARNING_MESSAGE); } else { int opcionElegida = JOptionPane.showOptionDialog(this, "Por favor elija una opcin", "Editar cliente", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, null, opciones, null); switch (opcionElegida) { case 1: final JDialog dialogoEditar = new JDialog(this); dialogoEditar.setTitle("Editar usuario"); dialogoEditar.setSize(400, 310); dialogoEditar.setResizable(false); JPanel panelDialogo = new JPanel(); panelDialogo.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; JLabel editarTextoPrincipalDialogo = new JLabel("Editar clientes"); c.gridx = 0; c.gridy = 0; c.gridwidth = 2; c.insets = new Insets(15, 10, 40, 0); c.ipadx = 0; Font textoGrande = new Font("Arial", 1, 18); editarTextoPrincipalDialogo.setFont(textoGrande); panelDialogo.add(editarTextoPrincipalDialogo, c); c.insets = new Insets(0, 5, 10, 0); c.gridx = 0; c.gridy = 1; c.gridwidth = 1; c.ipadx = 0; JLabel editarNombreClienteDialogo = new JLabel("Login:"); panelDialogo.add(editarNombreClienteDialogo, c); final JTextField valorEditarNombreClienteDialogo = new JTextField(); c.gridx = 1; c.gridy = 1; c.gridwidth = 1; c.ipadx = 0; c.insets = new Insets(0, 5, 10, 0); valorEditarNombreClienteDialogo.setText(usuarioSelecionado.getLogin()); panelDialogo.add(valorEditarNombreClienteDialogo, c); c.gridx = 0; c.gridy = 2; c.gridwidth = 1; c.ipadx = 0; c.insets = new Insets(0, 5, 10, 0); JLabel editarPasswordClienteDialogo = new JLabel("Contrasea:"); panelDialogo.add(editarPasswordClienteDialogo, c); final JTextField valoreditarPasswordClienteDialogo = new JTextField(); c.gridx = 1; c.gridy = 2; c.gridwidth = 1; c.ipadx = 0; c.insets = new Insets(0, 5, 10, 0); panelDialogo.add(valoreditarPasswordClienteDialogo, c); c.gridx = 0; c.gridy = 3; c.gridwidth = 2; c.ipadx = 0; c.insets = new Insets(0, 5, 10, 0); JLabel mensajeEditarPassword = new JLabel( "Si no desea editar la contrasea deje este espacio en blanco:"); panelDialogo.add(mensajeEditarPassword, c); c.gridx = 0; c.gridy = 4; c.gridwidth = 1; c.ipadx = 0; c.insets = new Insets(0, 15, 10, 15); JButton botonGuardarClienteDialogo = new JButton("Guardar"); panelDialogo.add(botonGuardarClienteDialogo, c); c.gridx = 1; c.gridy = 4; c.gridwidth = 1; c.insets = new Insets(0, 15, 10, 15); c.ipadx = 0; JButton botonCerrarClienteDialogo = new JButton("Cancelar"); panelDialogo.add(botonCerrarClienteDialogo, c); botonCerrarClienteDialogo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dialogoEditar.dispose(); } }); botonGuardarClienteDialogo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String nombreUsuario = valorEditarNombreClienteDialogo.getText(); usuarioSelecionado.setLogin(nombreUsuario); if (!valoreditarPasswordClienteDialogo.getText().equals("")) { usuarioSelecionado.setPassword(valoreditarPasswordClienteDialogo.getText()); } controladorUsuarios.modificarUsuario(usuarioSelecionado.getUser_id(), usuarioSelecionado.getLogin(), usuarioSelecionado.getPassword()); JOptionPane.showMessageDialog(dialogoEditar, "Se ha modificado el usuario con xito", "Mensaje del sistema", JOptionPane.INFORMATION_MESSAGE); generarTablaUsuarios(); dialogoEditar.dispose(); } }); dialogoEditar.add(panelDialogo); dialogoEditar.setVisible(true); break; case 2: if (estado.equals("Habilitado")) { usuarioSelecionado.setStatus('i'); } else { usuarioSelecionado.setStatus('e'); } controladorUsuarios.modificarEstadoUsuario(usuarioSelecionado); JOptionPane.showMessageDialog(this, "Se ha cambiado el estado del usuario", "Mensaje del sistema", JOptionPane.INFORMATION_MESSAGE); generarTablaUsuarios(); break; default: break; } } // TODO add your handling code here: }
From source file:interfaces.InterfazPrincipal.java
private void botonBuscarClienteCrearFacturaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonBuscarClienteCrearFacturaActionPerformed String nombre = nombreClienteCrearFactura.getText(); String identificacion = IdentificacionClienteBuscarFactura.getText(); ControladorCliente controladorCliente = new ControladorCliente(); try {/*www .ja v a 2 s . c o m*/ int id = 0; if (!identificacion.equals("")) { id = Integer.parseInt(identificacion); } ArrayList<Cliente> listaClientes = controladorCliente.obtenerClientes(nombre, id); if (listaClientes.isEmpty()) { mensajesBusquedaClientesFactura.setText("La busqueda no arrojo resultados"); return; } final JDialog dialogoEditar = new JDialog(this); dialogoEditar.setTitle("Buscar clientes"); dialogoEditar.setSize(600, 310); dialogoEditar.setResizable(false); JPanel panelDialogo = new JPanel(); panelDialogo.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; JLabel editarTextoPrincipalDialogo = new JLabel("Buscar Cliente"); c.gridx = 0; c.gridy = 0; c.gridwidth = 4; c.insets = new Insets(15, 200, 40, 0); c.ipadx = 100; Font textoGrande = new Font("Arial", 1, 18); editarTextoPrincipalDialogo.setFont(textoGrande); panelDialogo.add(editarTextoPrincipalDialogo, c); /*Vector col = new Vector(); col.add("1"); col.add("2"); col.add("3"); col.add("4"); Vector row = new Vector(); for (int i = 0; i < listaClientes.size(); i++) { Cliente cliente = listaClientes.get(i); Vector temp = new Vector(); temp.add((i + 1) + ""); temp.add(cliente.getNombre()); temp.add(cliente.getCliente_id() + ""); temp.add(cliente.getMonto_prestamo() + ""); System.out.println("info" + cliente.getNombre() + "," + cliente.getMonto_prestamo()); row.add(temp); } final JTable table = new JTable(row, col); */ final JTable table = new JTable(); DefaultTableModel modeloTabla = new DefaultTableModel() { @Override public boolean isCellEditable(int row, int column) { //all cells false return false; } }; ; modeloTabla.addColumn("Numero"); modeloTabla.addColumn("Identificacin"); modeloTabla.addColumn("Nombre"); modeloTabla.addColumn("Monto Prestamo"); //LLenar tabla for (int i = 0; i < listaClientes.size(); i++) { Object[] data = { "1", "2", "3", "4" }; data[0] = (i + 1); data[1] = listaClientes.get(i).getCliente_id(); data[2] = listaClientes.get(i).getNombre(); data[3] = listaClientes.get(i).getMonto_prestamo(); modeloTabla.addRow(data); } table.setModel(modeloTabla); table.getColumn("Numero").setMinWidth(50); table.getColumn("Identificacin").setMinWidth(50); table.getColumn("Nombre").setMinWidth(110); table.getColumn("Monto Prestamo").setMinWidth(110); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JScrollPane scroll = new JScrollPane(table); scroll.setPreferredSize(new Dimension(320, 150)); table.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { jTextField_Factura_Cliente_Id.setText(table.getValueAt(table.getSelectedRow(), 1).toString()); String identificacion = table.getValueAt(table.getSelectedRow(), 3).toString(); ControladorFlujoFactura controladorFlujoFactura = new ControladorFlujoFactura(); //SELECT * FROM Flujo_Factura where factura_id in (select factura_id from Factura where cliente_id = 1130614506); ArrayList<String[]> flujosCliente = controladorFlujoFactura.getTodosFlujo_Factura( " where factura_id in (select factura_id from Factura where cliente_id = " + String.valueOf(identificacion) + " and estado=\"fiado\") order by factura_id"); double pago = 0.0; for (int i = 0; i < flujosCliente.size(); i++) { String[] datos = flujosCliente.get(i); Object[] rowData = { datos[1], datos[2], datos[3], datos[4] }; if (datos[2].equals("deuda")) { pago += Double.parseDouble(datos[4]); } else { pago -= Double.parseDouble(datos[4]); } } nombreClienteCrearFactura.setText(table.getValueAt(table.getSelectedRow(), 2).toString()); IdentificacionClienteBuscarFactura .setText(table.getValueAt(table.getSelectedRow(), 1).toString()); double montoPrestamo = Double .parseDouble(table.getValueAt(table.getSelectedRow(), 3).toString()); Double totalDisponible = montoPrestamo - pago; valorActualPrestamo.setText(String.valueOf(totalDisponible)); //System.out.println(table.getValueAt(table.getSelectedRow(), 3).toString()); botonAgregarProducto.setEnabled(true); botonGuardarFactura.setEnabled(true); botonEstablecerMontoFactura.setEnabled(true); dialogoEditar.dispose(); } }); c.insets = new Insets(0, 5, 10, 0); c.gridx = 0; c.gridy = 1; c.gridwidth = 1; c.ipadx = 200; //panelDialogo.add(table, c); panelDialogo.add(scroll, c); dialogoEditar.add(panelDialogo); dialogoEditar.setVisible(true); } catch (Exception e) { mensajesBusquedaClientesFactura.setText("La identificacion debe ser un numero"); } }
From source file:interfaces.InterfazPrincipal.java
private void botonGenerarReporteClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonGenerarReporteClienteActionPerformed // TODO add your handling code here: try {// w ww . java 2s . com if (clienteReporteClienteFechaFinal.getSelectedDate().getTime() .compareTo(clienteReporteClienteFechaInicial.getSelectedDate().getTime()) < 0) { JOptionPane.showMessageDialog(this, "La fecha final debe ser posterior al dia de inicio"); } else { final ArrayList<Integer> listaIDFlujos = new ArrayList<>(); final JDialog dialogoEditar = new JDialog(); dialogoEditar.setTitle("Reporte cliente"); dialogoEditar.setSize(350, 610); dialogoEditar.setResizable(false); JPanel panelDialogo = new JPanel(); panelDialogo.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); //c.fill = GridBagConstraints.HORIZONTAL; JLabel ediitarTextoPrincipalDialogo = new JLabel("Informe cliente"); c.gridx = 0; c.gridy = 0; c.gridwidth = 1; c.insets = new Insets(10, 45, 10, 10); Font textoGrande = new Font("Arial", 1, 18); ediitarTextoPrincipalDialogo.setFont(textoGrande); panelDialogo.add(ediitarTextoPrincipalDialogo, c); final JTable tablaDialogo = new JTable(); DefaultTableModel modeloTabla = new DefaultTableModel() { @Override public boolean isCellEditable(int row, int column) { //all cells false return false; } }; ; modeloTabla.addColumn("Factura"); modeloTabla.addColumn("Tipo Flujo"); modeloTabla.addColumn("Fecha"); modeloTabla.addColumn("Valor"); //Llenar tabla ControladorFlujoFactura controladorFlujoFactura = new ControladorFlujoFactura(); ArrayList<String[]> flujosCliente = controladorFlujoFactura.getTodosFlujo_Factura( " where factura_id in (select factura_id from Factura where cliente_id = " + String.valueOf(jTextFieldIdentificacionClienteReporte.getText()) + ") order by factura_id"); // {"flujo_id","factura_id","tipo_flujo","fecha","valor"}; ArrayList<Calendar> fechasFlujos = new ArrayList<>(); for (int i = 0; i < flujosCliente.size(); i++) { String fila[] = new String[4]; String[] objeto = flujosCliente.get(i); fila[0] = objeto[1]; fila[1] = objeto[2]; fila[2] = objeto[3]; fila[3] = objeto[4]; //Filtrar, mirar las fechas String[] partirEspacios = objeto[3].split("\\s"); //El primer string es la fecha sin hora //Ahora esparamos por - String[] tomarAgeMesDia = partirEspacios[0].split("-"); //Realizar filtro int ageConsulta = Integer.parseInt(tomarAgeMesDia[0]); int mesConsulta = Integer.parseInt(tomarAgeMesDia[1]); int diaConsulta = Integer.parseInt(tomarAgeMesDia[2]); //Obtenemos dias, mes y ao de la consulta //Inicial int anioInicial = clienteReporteClienteFechaFinal.getSelectedDate().get(Calendar.YEAR); int mesInicial = clienteReporteClienteFechaFinal.getSelectedDate().get(Calendar.MONTH) + 1; int diaInicial = clienteReporteClienteFechaFinal.getSelectedDate().get(Calendar.DAY_OF_MONTH); //Final int anioFinal = clienteReporteClienteFechaInicial.getSelectedDate().get(Calendar.YEAR); int mesFinal = clienteReporteClienteFechaInicial.getSelectedDate().get(Calendar.MONTH) + 1; int diaFinal = clienteReporteClienteFechaInicial.getSelectedDate().get(Calendar.DAY_OF_MONTH); //Construir fechas Calendar fechaDeLaBD = new GregorianCalendar(ageConsulta, mesConsulta, diaConsulta); //Set year, month, day) Calendar fechaInicialRango = new GregorianCalendar(anioInicial, mesInicial, diaInicial); Calendar fechaFinalRango = new GregorianCalendar(anioFinal, mesFinal, diaFinal); if (fechaDeLaBD.compareTo(fechaInicialRango) <= 0 && fechaDeLaBD.compareTo(fechaFinalRango) >= 0) { fechasFlujos.add(fechaDeLaBD); modeloTabla.addRow(fila); } } if (modeloTabla.getRowCount() > 0) { tablaDialogo.setModel(modeloTabla); tablaDialogo.getColumn("Factura").setMinWidth(80); tablaDialogo.getColumn("Tipo Flujo").setMinWidth(80); tablaDialogo.getColumn("Fecha").setMinWidth(90); tablaDialogo.getColumn("Valor").setMinWidth(80); tablaDialogo.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JScrollPane scroll = new JScrollPane(tablaDialogo); scroll.setPreferredSize(new Dimension(330, 150)); c.gridx = 0; c.gridy = 1; c.gridwidth = 1; c.insets = new Insets(0, 0, 0, 0); panelDialogo.add(scroll, c); TimeSeries localTimeSeries = new TimeSeries("Compras del cliente en el periodo"); Map listaAbonos = new HashMap(); for (int i = 0; i < modeloTabla.getRowCount(); i++) { listaIDFlujos.add(Integer.parseInt(flujosCliente.get(i)[0])); if (modeloTabla.getValueAt(i, 1).equals("abono")) { Calendar fechaFlujo = fechasFlujos.get(i); double valor = Double.parseDouble(String.valueOf(modeloTabla.getValueAt(i, 3))); int anoDato = fechaFlujo.get(Calendar.YEAR); int mesDato = fechaFlujo.get(Calendar.MONTH) + 1; int diaDato = fechaFlujo.get(Calendar.DAY_OF_MONTH); Day FechaDato = new Day(diaDato, mesDato, anoDato); if (listaAbonos.get(FechaDato) != null) { double valorAbono = (double) listaAbonos.get(FechaDato); listaAbonos.remove(FechaDato); listaAbonos.put(FechaDato, valorAbono + valor); } else { listaAbonos.put(FechaDato, valor); } } } Double maximo = 0.0; Iterator iterator = listaAbonos.keySet().iterator(); while (iterator.hasNext()) { Day key = (Day) iterator.next(); Double value = (double) listaAbonos.get(key); maximo = Math.max(maximo, value); localTimeSeries.add(key, value); } //localTimeSeries.add(); TimeSeriesCollection datos = new TimeSeriesCollection(localTimeSeries); JFreeChart chart = ChartFactory.createTimeSeriesChart("Compras del cliente en el periodo", // Title "Tiempo", // x-axis Label "Total ($)", // y-axis Label datos, // Dataset true, // Show Legend true, // Use tooltips false // Configure chart to generate URLs? ); /*Altering the graph */ XYPlot plot = (XYPlot) chart.getPlot(); plot.setAxisOffset(new RectangleInsets(5.0, 10.0, 10.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis(); numberAxis.setRange(new Range(0, maximo * 1.2)); Font font = new Font("Dialog", Font.PLAIN, 9); numberAxis.setTickLabelFont(font); numberAxis.setLabelFont(font); DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("dd-MM-yyyy")); axis.setAutoTickUnitSelection(false); axis.setVerticalTickLabels(true); axis.setTickLabelFont(font); axis.setLabelFont(font); LegendTitle leyendaChart = chart.getLegend(); leyendaChart.setItemFont(font); Font fontTitulo = new Font("Dialog", Font.BOLD, 12); TextTitle tituloChart = chart.getTitle(); tituloChart.setFont(fontTitulo); ChartPanel CP = new ChartPanel(chart); Dimension D = new Dimension(330, 300); CP.setPreferredSize(D); CP.setVisible(true); c.gridx = 0; c.gridy = 2; c.gridwidth = 1; c.insets = new Insets(10, 0, 0, 0); panelDialogo.add(CP, c); c.gridx = 0; c.gridy = 3; c.gridwidth = 1; c.anchor = GridBagConstraints.WEST; c.insets = new Insets(10, 30, 0, 0); JButton botonCerrar = new JButton("Cerrar"); botonCerrar.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dialogoEditar.dispose(); } }); panelDialogo.add(botonCerrar, c); JButton botonGenerarPDF = new JButton("Guardar archivo"); botonGenerarPDF.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { ReporteFlujosCliente reporteFlujosCliente = new ReporteFlujosCliente(); reporteFlujosCliente.guardarDocumentoDialogo(dialogoEditar, listaIDFlujos, Integer.parseInt(jTextFieldIdentificacionClienteReporte.getText()), clienteReporteClienteFechaInicial.getSelectedDate(), clienteReporteClienteFechaFinal.getSelectedDate()); } }); c.insets = new Insets(10, 100, 0, 0); panelDialogo.add(botonGenerarPDF, c); JButton botonImprimir = new JButton("Imprimir"); botonImprimir.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { ReporteFlujosCliente reporteFlujosCliente = new ReporteFlujosCliente(); reporteFlujosCliente.imprimirFlujo(listaIDFlujos, Integer.parseInt(jTextFieldIdentificacionClienteReporte.getText()), clienteReporteClienteFechaInicial.getSelectedDate(), clienteReporteClienteFechaFinal.getSelectedDate()); } }); c.insets = new Insets(10, 230, 0, 0); panelDialogo.add(botonImprimir, c); dialogoEditar.add(panelDialogo); dialogoEditar.setVisible(true); } else { JOptionPane.showMessageDialog(this, "El cliente no registra movimientos en el rango de fechas seleccionado"); } } } catch (Exception e) { JOptionPane.showMessageDialog(this, "Debe seleccionar un da inicial y final de fechas"); } }
From source file:userinterface.properties.GUIGraphHandler.java
public void defineConstantsAndPlot(Expression expr, JPanel graph, String seriesName, Boolean isNewGraph, boolean is2D) { JDialog dialog; JButton ok, cancel;/*ww w . j ava2s. co m*/ JScrollPane scrollPane; ConstantPickerList constantList; JComboBox<String> xAxis, yAxis; //init everything dialog = new JDialog(GUIPrism.getGUI()); dialog.setTitle("Define constants and select axes"); dialog.setSize(500, 400); dialog.setLocationRelativeTo(GUIPrism.getGUI()); dialog.setLayout(new BoxLayout(dialog.getContentPane(), BoxLayout.Y_AXIS)); dialog.setModal(true); constantList = new ConstantPickerList(); scrollPane = new JScrollPane(constantList); xAxis = new JComboBox<String>(); yAxis = new JComboBox<String>(); ok = new JButton("Ok"); ok.setMnemonic('O'); cancel = new JButton("Cancel"); cancel.setMnemonic('C'); //add all components to their dedicated panels JPanel exprPanel = new JPanel(new FlowLayout()); exprPanel.setBorder(new TitledBorder("Function")); exprPanel.add(new JLabel(expr.toString())); JPanel axisPanel = new JPanel(); axisPanel.setBorder(new TitledBorder("Select axis constants")); axisPanel.setLayout(new BoxLayout(axisPanel, BoxLayout.Y_AXIS)); JPanel xAxisPanel = new JPanel(new FlowLayout()); xAxisPanel.add(new JLabel("X axis:")); xAxisPanel.add(xAxis); JPanel yAxisPanel = new JPanel(new FlowLayout()); yAxisPanel.add(new JLabel("Y axis:")); yAxisPanel.add(yAxis); axisPanel.add(xAxisPanel); axisPanel.add(yAxisPanel); JPanel constantPanel = new JPanel(new BorderLayout()); constantPanel.setBorder(new TitledBorder("Please define the following constants")); constantPanel.add(scrollPane, BorderLayout.CENTER); constantPanel.add(new ConstantHeader(), BorderLayout.NORTH); JPanel bottomPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); bottomPanel.add(ok); bottomPanel.add(cancel); //fill the axes components for (int i = 0; i < expr.getAllConstants().size(); i++) { xAxis.addItem(expr.getAllConstants().get(i)); if (!is2D) yAxis.addItem(expr.getAllConstants().get(i)); } if (!is2D) { yAxis.setSelectedIndex(1); } //fill the constants table for (int i = 0; i < expr.getAllConstants().size(); i++) { ConstantLine line = new ConstantLine(expr.getAllConstants().get(i), TypeDouble.getInstance()); constantList.addConstant(line); if (!is2D) { if (line.getName().equals(xAxis.getSelectedItem().toString()) || line.getName().equals(yAxis.getSelectedItem().toString())) { line.doFuncEnables(false); } else { line.doFuncEnables(true); } } } //do enables if (is2D) { yAxis.setEnabled(false); } ok.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "ok"); ok.getActionMap().put("ok", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { ok.doClick(); } }); cancel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "cancel"); cancel.getActionMap().put("cancel", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { cancel.doClick(); } }); //add action listeners xAxis.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (is2D) { return; } String item = xAxis.getSelectedItem().toString(); if (item.equals(yAxis.getSelectedItem().toString())) { int index = yAxis.getSelectedIndex(); if (index != yAxis.getItemCount() - 1) { yAxis.setSelectedIndex(++index); } else { yAxis.setSelectedIndex(--index); } } for (int i = 0; i < constantList.getNumConstants(); i++) { ConstantLine line = constantList.getConstantLine(i); if (line.getName().equals(xAxis.getSelectedItem().toString()) || line.getName().equals(yAxis.getSelectedItem().toString())) { line.doFuncEnables(false); } else { line.doFuncEnables(true); } } } }); yAxis.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String item = yAxis.getSelectedItem().toString(); if (item.equals(xAxis.getSelectedItem().toString())) { int index = xAxis.getSelectedIndex(); if (index != xAxis.getItemCount() - 1) { xAxis.setSelectedIndex(++index); } else { xAxis.setSelectedIndex(--index); } } for (int i = 0; i < constantList.getNumConstants(); i++) { ConstantLine line = constantList.getConstantLine(i); if (line.getName().equals(xAxis.getSelectedItem().toString()) || line.getName().equals(yAxis.getSelectedItem().toString())) { line.doFuncEnables(false); } else { line.doFuncEnables(true); } } } }); ok.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { constantList.checkValid(); } catch (PrismException e2) { JOptionPane.showMessageDialog(dialog, "<html> One or more of the defined constants are invalid. <br><br> <font color=red>Error: </font>" + e2.getMessage() + "</html>", "Parse Error", JOptionPane.ERROR_MESSAGE); return; } if (is2D) { // it will always be a parametric graph in 2d case ParametricGraph pGraph = (ParametricGraph) graph; ConstantLine xAxisConstant = constantList.getConstantLine(xAxis.getSelectedItem().toString()); if (xAxisConstant == null) { //should never happen JOptionPane.showMessageDialog(dialog, "The selected axis is invalid.", "Error", JOptionPane.ERROR_MESSAGE); return; } double xStartValue = Double.parseDouble(xAxisConstant.getStartValue()); double xEndValue = Double.parseDouble(xAxisConstant.getEndValue()); double xStepValue = Double.parseDouble(xAxisConstant.getStepValue()); int seriesCount = 0; for (int i = 0; i < constantList.getNumConstants(); i++) { ConstantLine line = constantList.getConstantLine(i); if (line.getName().equals(xAxis.getSelectedItem().toString())) { seriesCount++; } else { seriesCount += line.getTotalNumOfValues(); } } // if there will be too many series to be plotted, ask the user if they are sure they know what they are doing if (seriesCount > 10) { int res = JOptionPane.showConfirmDialog(dialog, "This configuration will create " + seriesCount + " series. Continue?", "Confirm", JOptionPane.YES_NO_OPTION); if (res == JOptionPane.NO_OPTION) { return; } } Values singleValuesGlobal = new Values(); //add the single values to a global values list for (int i = 0; i < constantList.getNumConstants(); i++) { ConstantLine line = constantList.getConstantLine(i); if (line.getTotalNumOfValues() == 1) { double singleValue = Double.parseDouble(line.getSingleValue()); singleValuesGlobal.addValue(line.getName(), singleValue); } } // we just have one variable so we can plot directly if (constantList.getNumConstants() == 1 || singleValuesGlobal.getNumValues() == constantList.getNumConstants() - 1) { SeriesKey key = pGraph.addSeries(seriesName); pGraph.hideShape(key); pGraph.getXAxisSettings().setHeading(xAxis.getSelectedItem().toString()); pGraph.getYAxisSettings().setHeading("function"); for (double x = xStartValue; x <= xEndValue; x += xStepValue) { double ans = -1; Values vals = new Values(); vals.addValue(xAxis.getSelectedItem().toString(), x); for (int ii = 0; ii < singleValuesGlobal.getNumValues(); ii++) { try { vals.addValue(singleValuesGlobal.getName(ii), singleValuesGlobal.getDoubleValue(ii)); } catch (PrismLangException e1) { e1.printStackTrace(); } } try { ans = expr.evaluateDouble(vals); } catch (PrismLangException e1) { e1.printStackTrace(); } pGraph.addPointToSeries(key, new PrismXYDataItem(x, ans)); } if (isNewGraph) { addGraph(pGraph); } dialog.dispose(); return; } for (int i = 0; i < constantList.getNumConstants(); i++) { ConstantLine line = constantList.getConstantLine(i); if (line == xAxisConstant || singleValuesGlobal.contains(line.getName())) { continue; } double lineStart = Double.parseDouble(line.getStartValue()); double lineEnd = Double.parseDouble(line.getEndValue()); double lineStep = Double.parseDouble(line.getStepValue()); for (double j = lineStart; j < lineEnd; j += lineStep) { SeriesKey key = pGraph.addSeries(seriesName); pGraph.hideShape(key); for (double x = xStartValue; x <= xEndValue; x += xStepValue) { double ans = -1; Values vals = new Values(); vals.addValue(xAxis.getSelectedItem().toString(), x); vals.addValue(line.getName(), j); for (int ii = 0; ii < singleValuesGlobal.getNumValues(); ii++) { try { vals.addValue(singleValuesGlobal.getName(ii), singleValuesGlobal.getDoubleValue(ii)); } catch (PrismLangException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } for (int ii = 0; ii < constantList.getNumConstants(); ii++) { if (constantList.getConstantLine(ii) == xAxisConstant || singleValuesGlobal .contains(constantList.getConstantLine(ii).getName()) || constantList.getConstantLine(ii) == line) { continue; } ConstantLine temp = constantList.getConstantLine(ii); double val = Double.parseDouble(temp.getStartValue()); vals.addValue(temp.getName(), val); } try { ans = expr.evaluateDouble(vals); } catch (PrismLangException e1) { e1.printStackTrace(); } pGraph.addPointToSeries(key, new PrismXYDataItem(x, ans)); } } } if (isNewGraph) { addGraph(graph); } } else { // this will always be a parametric graph for the 3d case ParametricGraph3D pGraph = (ParametricGraph3D) graph; //add the graph to the gui addGraph(pGraph); //Get the constants we want to put on the x and y axis ConstantLine xAxisConstant = constantList.getConstantLine(xAxis.getSelectedItem().toString()); ConstantLine yAxisConstant = constantList.getConstantLine(yAxis.getSelectedItem().toString()); //add the single values to a global values list Values singleValuesGlobal = new Values(); for (int i = 0; i < constantList.getNumConstants(); i++) { ConstantLine line = constantList.getConstantLine(i); if (line.getTotalNumOfValues() == 1) { double singleValue = Double.parseDouble(line.getSingleValue()); singleValuesGlobal.addValue(line.getName(), singleValue); } } pGraph.setGlobalValues(singleValuesGlobal); pGraph.setAxisConstants(xAxis.getSelectedItem().toString(), yAxis.getSelectedItem().toString()); pGraph.setBounds(xAxisConstant.getStartValue(), xAxisConstant.getEndValue(), yAxisConstant.getStartValue(), yAxisConstant.getEndValue()); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { //plot the graph pGraph.plot(expr.toString(), xAxis.getSelectedItem().toString(), "Function", yAxis.getSelectedItem().toString()); //calculate the sampling rates from the step sizes as given by the user int xSamples = (int) ((Double.parseDouble(xAxisConstant.getEndValue()) - Double.parseDouble(xAxisConstant.getStartValue())) / Double.parseDouble(xAxisConstant.getStepValue())); int ySamples = (int) ((Double.parseDouble(xAxisConstant.getEndValue()) - Double.parseDouble(xAxisConstant.getStartValue())) / Double.parseDouble(xAxisConstant.getStepValue())); pGraph.setSamplingRates(xSamples, ySamples); } }); } dialog.dispose(); } }); cancel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dialog.dispose(); } }); //add everything to the dialog show the dialog dialog.add(exprPanel); dialog.add(axisPanel); dialog.add(constantPanel); dialog.add(bottomPanel); dialog.setVisible(true); }
From source file:nz.ac.massey.cs.gql4jung.browser.queryviews.GraphBasedQueryView.java
public static void show(JFrame parent, Motif motif, String title) { JDialog dlg = new JDialog(parent, title, false); GraphBasedQueryView qv = new GraphBasedQueryView(); qv.display(motif, null);/* w w w .j a va 2 s. c om*/ dlg.add(qv); dlg.setTitle(title); dlg.setSize(900, 600); dlg.setLocation(100, 100); dlg.setVisible(true); }