137 lines
4.5 KiB
Java
137 lines
4.5 KiB
Java
/*
|
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
|
*/
|
|
package Controlador;
|
|
|
|
|
|
import Modelo.WS;
|
|
import Vista.Principal1;
|
|
import java.awt.Color;
|
|
import java.awt.Font;
|
|
import java.awt.GridLayout;
|
|
import java.awt.event.ActionEvent;
|
|
import java.awt.event.ActionListener;
|
|
import java.util.ArrayList;
|
|
import javax.swing.JPanel;
|
|
import javax.swing.JTextField;
|
|
|
|
import com.itextpdf.text.Document;
|
|
import com.itextpdf.text.DocumentException;
|
|
import com.itextpdf.text.PageSize;
|
|
import com.itextpdf.text.Phrase;
|
|
import com.itextpdf.text.pdf.PdfPTable;
|
|
import com.itextpdf.text.pdf.PdfWriter;
|
|
import java.io.FileNotFoundException;
|
|
|
|
import java.io.FileOutputStream;
|
|
import java.io.IOException;
|
|
import javax.swing.JOptionPane;
|
|
|
|
/**
|
|
*
|
|
* @author Hp
|
|
*/
|
|
public class GestionSize1 implements ActionListener{
|
|
Principal1 v;
|
|
WS ws=new WS();
|
|
public String numeroTelefonico;
|
|
public GestionSize1(Principal1 v){
|
|
this.v=v;
|
|
}
|
|
//Para la matriz de JTextFields
|
|
public void generarPDF(JTextField[][] matrix, String filePath) throws DocumentException, FileNotFoundException{
|
|
Document document = new Document(PageSize.A4);
|
|
PdfWriter.getInstance(document, new FileOutputStream(filePath));
|
|
document.open();
|
|
for (int i = 0; i < matrix.length; i++) {
|
|
for (int j = 0; j < matrix[i].length; j++) {
|
|
String text = matrix[i][j].getText();
|
|
document.add(new Phrase(text));
|
|
}
|
|
document.add(new Phrase("\n")); // Agrega una nueva línea después de cada fila
|
|
}
|
|
document.close();
|
|
|
|
}
|
|
|
|
@Override
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
if(e.getSource()==v.incrementSize){
|
|
Font fuente=new Font("Dialog", Font.BOLD, 20);
|
|
int nCol=v.col+1;
|
|
int nFilas=v.filas+1;
|
|
System.out.println("NUEVA FILA : "+nFilas+" NUEVA COL: "+nCol);
|
|
JTextField[][] matriz=new JTextField[nFilas][nCol];
|
|
v.panelP.removeAll();
|
|
v.panelP.setLayout(new GridLayout(nFilas, nCol,1,1));
|
|
|
|
for(int i=0;i<nFilas;i++){
|
|
for(int j=0;j<nCol;j++){
|
|
JTextField panel=new JTextField();
|
|
panel.setFont(fuente);
|
|
panel.setText(" ");
|
|
panel.addKeyListener(new GestionTextFields(v, panel));
|
|
matriz[i][j]=panel;
|
|
}
|
|
}
|
|
|
|
for(int i=0;i<nFilas;i++){
|
|
for(int j=0;j<nCol;j++){
|
|
v.panelP.add(matriz[i][j]);
|
|
}
|
|
}
|
|
v.panelP.revalidate();
|
|
v.panelP.repaint();
|
|
v.col=nCol;
|
|
v.filas=nFilas;
|
|
v.setMatriz(matriz);
|
|
}
|
|
|
|
|
|
if (e.getSource() == v.guardar) {
|
|
int filas = v.filas;
|
|
int col = v.col;
|
|
int opcionCompartir;
|
|
|
|
String filePath = "matriz.pdf";
|
|
|
|
System.out.println("FILAS: " + v.filas + " COL: " + v.col);
|
|
char[][] matriz = new char[filas][col];
|
|
JTextField[][] matriz2 = new JTextField[filas][col];
|
|
matriz2 = v.getMatriz();
|
|
for (int i = 0; i < filas; i++) {
|
|
for (int j = 0; j < col; j++) {
|
|
//matriz[i][j]=matriz2[i][j].toString().charAt(0);
|
|
System.out.print(matriz2[i][j].getText());
|
|
}
|
|
System.out.println("");
|
|
}
|
|
try {
|
|
generarPDF(matriz2, filePath);
|
|
System.out.println("PDF creado exitosamente en: " + filePath);
|
|
opcionCompartir=JOptionPane.showConfirmDialog(null, "Desea enviar el documento a su WhatsApp?: ");
|
|
if(opcionCompartir==0){
|
|
numeroTelefonico=JOptionPane.showInputDialog("Ingrese su número telefónico");
|
|
System.out.println("Numero "+numeroTelefonico);
|
|
ws.enviarMsj(numeroTelefonico);
|
|
}else{
|
|
return;
|
|
}
|
|
} catch (Exception em) {
|
|
//em.printStackTrace();
|
|
System.out.println("Alguo salio mal al guardar o enviar msj: "+em.toString());
|
|
}
|
|
|
|
}
|
|
|
|
if(e.getSource()==v.regresar){
|
|
v.dispose();
|
|
return;
|
|
}
|
|
|
|
}
|
|
|
|
}
|