From c80ffcc34ea3132c0a05d493da821bde947ca841 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isidoro=20Nevares=20Mart=C3=ADn?= Date: Sat, 7 Feb 2026 22:40:51 +0100 Subject: [PATCH] Commit Inicial --- .classpath | 41 +++++ .gitignore | 3 + .project | 23 +++ .settings/org.eclipse.jdt.core.prefs | 13 ++ .settings/org.eclipse.m2e.core.prefs | 4 + ficheros/contexto_ia_atletas.txt | 27 ++++ pom.xml | 15 ++ .../jjoo/ClienteJuegosOlimpicosIA.java | 145 ++++++++++++++++++ .../gestores/GestorFicheroConfiguracion.java | 39 +++++ src/main/resources/conf.properties | 5 + 10 files changed, 315 insertions(+) create mode 100644 .classpath create mode 100644 .gitignore create mode 100644 .project create mode 100644 .settings/org.eclipse.jdt.core.prefs create mode 100644 .settings/org.eclipse.m2e.core.prefs create mode 100644 ficheros/contexto_ia_atletas.txt create mode 100644 pom.xml create mode 100644 src/main/java/org/lapaloma/jjoo/ClienteJuegosOlimpicosIA.java create mode 100644 src/main/java/org/lapaloma/jjoo/gestores/GestorFicheroConfiguracion.java create mode 100644 src/main/resources/conf.properties diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..51a6fca --- /dev/null +++ b/.classpath @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..93e00af --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/bin/ +*.class +/target/ diff --git a/.project b/.project new file mode 100644 index 0000000..477414a --- /dev/null +++ b/.project @@ -0,0 +1,23 @@ + + + aadd_act5_5_ia_swing + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..bfac099 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,13 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate +org.eclipse.jdt.core.compiler.codegen.targetPlatform=24 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=24 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning +org.eclipse.jdt.core.compiler.release=disabled +org.eclipse.jdt.core.compiler.source=24 diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/ficheros/contexto_ia_atletas.txt b/ficheros/contexto_ia_atletas.txt new file mode 100644 index 0000000..a600646 --- /dev/null +++ b/ficheros/contexto_ia_atletas.txt @@ -0,0 +1,27 @@ +Actúa como un extractor de datos JSON que, a la vez, es experto en deporte olímpico. +Analiza el texto que te van a proporcionar. +Devuelve exclusivamente un objeto JSON con esta estructura: +{ + "nombre": "", + "apellidos": "", + "fecha_nacimiento": "YYYY-MM-DD", + "sexo": "H/M", + "participaciones": [ + { + "disciplina": {"nombre_diciplina": "", + "diciplina_individual": "0/1", + } + + "juego": {"nombre": "Ciudad_Juego(en español)", + "pais": "País_Organizador(en español)", + "anyo": YYYY, + "verano": 0/1 + "mascota":{ + "nombre": "Nombre_Mascota", + "url_imagen": "https://img.olympics.com/images/image/private/xxx" + } + } + } + ] +} +No escribas nada de texto antes o después del JSON. \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..aa94a05 --- /dev/null +++ b/pom.xml @@ -0,0 +1,15 @@ + + 4.0.0 + org.lapaloma.jjoo + ProyectoJJOO + 0.0.1-SNAPSHOT + + + + + tools.jackson.dataformat + jackson-dataformat-xml + 3.0.1 + + + \ No newline at end of file diff --git a/src/main/java/org/lapaloma/jjoo/ClienteJuegosOlimpicosIA.java b/src/main/java/org/lapaloma/jjoo/ClienteJuegosOlimpicosIA.java new file mode 100644 index 0000000..4862087 --- /dev/null +++ b/src/main/java/org/lapaloma/jjoo/ClienteJuegosOlimpicosIA.java @@ -0,0 +1,145 @@ +package org.lapaloma.jjoo; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.Font; +import java.awt.Toolkit; +import java.awt.datatransfer.Clipboard; +import java.awt.datatransfer.StringSelection; + +import javax.swing.BorderFactory; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; +import javax.swing.SwingUtilities; +import javax.swing.Timer; + +/** + * + * ClienteIAJuegosOlimpicos: Clase que realiza .... + * + * @author Isidoro Nevares Martín - IES Virgen de la Paloma + * @date 7 feb 2026 + * + * + */ + +public class ClienteJuegosOlimpicosIA extends JFrame { + private static final long serialVersionUID = -6074564949314600423L; + + private JTextArea txtPeticion; + private JButton btnEnviar; + + public ClienteJuegosOlimpicosIA() { + // Configuración básica de la ventana + setTitle("Cliente IA - Acceso a Datos con IA (Groq)"); + setSize(500, 300); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setLocationRelativeTo(null); + setLayout(new BorderLayout(10, 10)); + + // Panel superior con FlowLayout alineado a la izquierda + JPanel panelNorte = new JPanel(new FlowLayout(FlowLayout.LEFT)); + JLabel lblTitulo = new JLabel("Petición a procesar (sobre deportistas):"); + lblTitulo.setFont(new Font("SansSerif", Font.BOLD, 13)); + + // Esto asegura que la etiqueta tenga espacio suficiente independientemente del + // layout + lblTitulo.setPreferredSize(new Dimension(300, 30)); + + panelNorte.add(lblTitulo); + add(panelNorte, BorderLayout.NORTH); + + // Caja de texto central (tipo chat) + txtPeticion = new JTextArea(); + txtPeticion.setLineWrap(true); + txtPeticion.setWrapStyleWord(true); + + JScrollPane scrollPane = new JScrollPane(txtPeticion); + scrollPane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10), + BorderFactory.createLineBorder(Color.GRAY))); + add(scrollPane, BorderLayout.CENTER); + + + + // Contenedor para la parte inferior del panel central + JPanel panelEjemplo = new JPanel(new BorderLayout()); + + // Usamos JTextArea para que el texto pueda seleccionarse y copiarse + JTextArea txtEjemplo = new JTextArea( + "Ejemplo: Obtén información completa, precisa y ordenada de atletas que participaron en juegos olímpicos de la siguiente disciplinas: Atletismo, natación y gimnasia. Serán 6 deportistas (3 hombres y 3 mujeres) por disciplina. Proporciona información de deportistas de distintos juegos olímpicos."); + + txtEjemplo.setEditable(false); // No se puede borrar/escribir + txtEjemplo.setLineWrap(true); + txtEjemplo.setWrapStyleWord(true); + txtEjemplo.setBackground(getBackground()); // Color igual al del panel + txtEjemplo.setForeground(new Color(100, 100, 100)); + txtEjemplo.setFont(new Font("SansSerif", Font.ITALIC, 11)); + txtEjemplo.setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 10)); + + // Botón de copiar pequeño + JButton btnCopiar = new JButton("📋"); // Puedes usar un icono .png si prefieres + btnCopiar.setToolTipText("Copiar texto al portapapeles"); + btnCopiar.setPreferredSize(new Dimension(50, 30)); + + // Acción del botón + btnCopiar.addActionListener(e -> { + copiarAlPortapapeles(txtEjemplo.getText()); + // Opcional: feedback visual rápido + btnCopiar.setText("✅"); + new Timer(1500, ev -> btnCopiar.setText("📋")).start(); + }); + + // Montaje + panelEjemplo.add(txtEjemplo, BorderLayout.CENTER); + panelEjemplo.add(btnCopiar, BorderLayout.EAST); // Botón a la derecha + + // Añadir al panel central igual que antes + JPanel panelCentral = new JPanel(new BorderLayout()); + panelCentral.add(scrollPane, BorderLayout.CENTER); + panelCentral.add(panelEjemplo, BorderLayout.SOUTH); + + add(panelCentral, BorderLayout.CENTER); + + // Panel inferior para el botón de envío + JPanel panelSur = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + btnEnviar = new JButton("Enviar ➤"); + btnEnviar.setBackground(new Color(66, 133, 244)); + btnEnviar.setForeground(Color.WHITE); + btnEnviar.setFocusPainted(false); + + btnEnviar.addActionListener(e -> procesarPeticionCliente()); + + panelSur.add(btnEnviar); + add(panelSur, BorderLayout.SOUTH); + } + private void copiarAlPortapapeles(String texto) { + StringSelection selection = new StringSelection(texto.replace("Ejemplo: ", "")); + Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); + clipboard.setContents(selection, selection); + } + public static void main(String[] args) { + SwingUtilities.invokeLater(() -> { + new ClienteJuegosOlimpicosIA().setVisible(true); + }); + } + + private void procesarPeticionCliente() { + // TODO Auto-generated method stub + String textoPrompt = txtPeticion.getText(); + + System.out.println("Enviando petición: " + textoPrompt); + + + // Aquí se llamaría al método que hace la petición a la IA y procesa la respuesta + // Los parámetros de la petición (URL, API Key, modelo, contexto) + // están en el fichero de configuración conf.properties en la carpeta de recursos + + } + +} diff --git a/src/main/java/org/lapaloma/jjoo/gestores/GestorFicheroConfiguracion.java b/src/main/java/org/lapaloma/jjoo/gestores/GestorFicheroConfiguracion.java new file mode 100644 index 0000000..40ed58b --- /dev/null +++ b/src/main/java/org/lapaloma/jjoo/gestores/GestorFicheroConfiguracion.java @@ -0,0 +1,39 @@ +/** + * GestorFicheroConfiguracion: clase utilitaria para leer propiedades del archivo application.properties. + * Provee un método estático que devuelve el valor asociado a una clave. + * + * @author Isidoro Nevares Martín - IES Virgen de la Paloma + * @date 25 nov 2025 + */ +package org.lapaloma.jjoo.gestores; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +public class GestorFicheroConfiguracion { + private static final Properties PROPIEDADES = new Properties(); + + static { + try (InputStream is = GestorFicheroConfiguracion.class.getClassLoader() + .getResourceAsStream("conf.properties")) { + if (is != null) { + PROPIEDADES.load(is); + } else { + throw new IllegalStateException("No se encontró application.properties en el classpath"); + } + } catch (IOException e) { + throw new IllegalStateException("Error al cargar application.properties", e); + } + } + + /** + * Obtiene el valor asociado a la clave especificada. + * + * @param clave la clave a buscar + * @return el valor o {@code null} si no existe + */ + public static String obtenerValor(String clave) { + return PROPIEDADES.getProperty(clave); + } +} diff --git a/src/main/resources/conf.properties b/src/main/resources/conf.properties new file mode 100644 index 0000000..86b06ce --- /dev/null +++ b/src/main/resources/conf.properties @@ -0,0 +1,5 @@ +# Fichero para la carga de datos de Atletas con IA (GROQ) +key.api.proveedor.ia=aquí_va_tu_api_key_de_groq +url.api.proveedor.ia=https://api.groq.com/openai/v1/chat/completions +model.proveedor.ia=openai/gpt-oss-120b +fichero.contexto.ia.atletas=ficheros/contexto_ia_atletas.txt