Skip to content

Instantly share code, notes, and snippets.

View HashRaygoza's full-sized avatar

David Raygoza Gómez HashRaygoza

View GitHub Profile
@HashRaygoza
HashRaygoza / agregarDato.java
Created May 9, 2020 19:29
Agrega datos a un celda de Excel, usando la conversion de tipo adecuada
protected void agregarDato(Cell celda, Object dato) {
if (dato instanceof BigDecimal) {
BigDecimal d = (BigDecimal) dato;
celda.setCellValue(d.doubleValue());
}
if (dato instanceof Integer) {
Integer i = (Integer) dato;
celda.setCellValue(i);
}
@HashRaygoza
HashRaygoza / crearEncabezado.java
Created May 9, 2020 19:28
Crea el encabezado del reporte en base a las anotaciones
protected void crearEncabezado(Row fila, Class claseDatos) {
Field[] campos = claseDatos.getDeclaredFields();
int numCelda = 0;
for (Field campo : campos) {
ColumnaReporte columna = campo.getAnnotation(ColumnaReporte.class);
if (columna != null) {
Cell celda = fila.createCell(numCelda);
celda.setCellValue(columna.nombreColumna());
numCelda++;
@HashRaygoza
HashRaygoza / ColumnaReporte.java
Created May 9, 2020 19:26
Anotacion para columna de reporte
package mx.ticom.autoreporte.anotaciones;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface ColumnaReporte {
@HashRaygoza
HashRaygoza / App.java
Created March 6, 2020 06:44
ejemplo del uso de fuentes en iText 7
package com.hash.databaseio.fuentesitext;
import com.itextpdf.io.font.FontProgram;
import com.itextpdf.io.font.FontProgramFactory;
import com.itextpdf.io.font.PdfEncodings;
import com.itextpdf.io.font.constants.StandardFonts;
import com.itextpdf.kernel.font.PdfFont;
import com.itextpdf.kernel.font.PdfFontFactory;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
@HashRaygoza
HashRaygoza / CuentaCaracteres.java
Created February 13, 2020 00:29
Manejador de eventos de documento
package com.hash.databaseio.doclistener;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.SwingUtilities;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
/**
*
@HashRaygoza
HashRaygoza / PanelPrincipal.java
Created February 13, 2020 00:28
Interfaz del ejemplo con banda magnética
package com.hash.databaseio.doclistener;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
/**
*
@HashRaygoza
HashRaygoza / App.java
Created February 13, 2020 00:27
Clase principal de la prueba de lector de banda magnética
package com.hash.databaseio.doclistener;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
public class App {
public static void main(String[] args) {
@HashRaygoza
HashRaygoza / callMethod.java
Created February 10, 2020 03:51
Llamando un metodo
public void callMethod(Object objeto, String nombreMetodo) throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method metodo = objeto.getClass().getMethod(nombreMetodo);
metodo.invoke(objeto);
}
@HashRaygoza
HashRaygoza / callSetter.java
Created February 10, 2020 03:51
ejemplo de como llamar un Setter
public void callSetter(Object objeto, String nombreCampo, Object valor) throws IntrospectionException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
PropertyDescriptor descriptor;
descriptor = new PropertyDescriptor(nombreCampo, objeto.getClass());
descriptor.getWriteMethod().invoke(objeto, valor);
}
@HashRaygoza
HashRaygoza / calGetter.java
Created February 10, 2020 03:50
funcion que llama a un getter
public Object callGetter(Object obj, String fieldName) throws IntrospectionException, llegalAccessException, IllegalArgumentException, InvocationTargetException {
PropertyDescriptor pd;
pd = new PropertyDescriptor(fieldName, obj.getClass());
return pd.getReadMethod().invoke(obj);
}