Compare commits
10 Commits
a3cb5a0791
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| dd43b8b3e4 | |||
| 8ab61b5ef8 | |||
| a9fe33c4b5 | |||
| 082074c6a7 | |||
| 8f4606e62c | |||
| f1d0a613a7 | |||
| ce1462dd73 | |||
| 31c274cd04 | |||
| 43f3bd8619 | |||
| 2d0f9a49aa |
@@ -4,6 +4,9 @@ import net.h4ckx0r.vista.MainView;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
if (System.getProperty("os.name").contains("Mac")) {
|
||||
System.setProperty("apple.laf.useScreenMenuBar", "true");
|
||||
}
|
||||
MainView.main(args);
|
||||
}
|
||||
}
|
||||
@@ -123,7 +123,7 @@ public class ControladorCurso {
|
||||
|
||||
public static int guardarCurso(Curso curso) {
|
||||
if (curso.getId() == -1) {
|
||||
curso.setId(ControladorCurso.getUltimoCurso().getId() + 1);
|
||||
curso.setId(getUltimoCurso().getId() + 1);
|
||||
return nuevoCurso(curso);
|
||||
}
|
||||
Connection conn = GestorConexiones.getConexion();
|
||||
@@ -133,7 +133,8 @@ public class ControladorCurso {
|
||||
pst.setInt(2, curso.getId());
|
||||
return pst.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
return 0;
|
||||
//throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,7 +157,8 @@ public class ControladorCurso {
|
||||
pst.setInt(1, curso.getId());
|
||||
return pst.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
return 0;
|
||||
//throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
188
src/main/java/net/h4ckx0r/controlador/ControladorEstudiante.java
Normal file
188
src/main/java/net/h4ckx0r/controlador/ControladorEstudiante.java
Normal file
@@ -0,0 +1,188 @@
|
||||
package net.h4ckx0r.controlador;
|
||||
|
||||
import net.h4ckx0r.modelo.Estudiante;
|
||||
|
||||
import java.sql.*;
|
||||
|
||||
public class ControladorEstudiante {
|
||||
public static Estudiante getPrimerEstudiante() {
|
||||
Connection conn = GestorConexiones.getConexion();
|
||||
|
||||
try {
|
||||
Statement st = conn.createStatement();
|
||||
ResultSet rs = st.executeQuery("SELECT * FROM estudiante LIMIT 1");
|
||||
|
||||
if (rs.next()) {
|
||||
return new Estudiante(
|
||||
rs.getInt("id"),
|
||||
rs.getString("nombre"),
|
||||
rs.getString("apellido1"),
|
||||
rs.getString("apellido2"),
|
||||
rs.getString("dni"),
|
||||
rs.getString("direccion"),
|
||||
rs.getString("email"),
|
||||
rs.getString("telefono"),
|
||||
rs.getInt("idTipologiaSexo"),
|
||||
rs.getBytes("imagen"),
|
||||
rs.getString("colorPreferido")
|
||||
);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Estudiante getUltimoEstudiante() {
|
||||
Connection conn = GestorConexiones.getConexion();
|
||||
|
||||
try {
|
||||
Statement st = conn.createStatement();
|
||||
ResultSet rs = st.executeQuery("SELECT * FROM estudiante ORDER BY id DESC LIMIT 1");
|
||||
|
||||
if (rs.next()) {
|
||||
return new Estudiante(
|
||||
rs.getInt("id"),
|
||||
rs.getString("nombre"),
|
||||
rs.getString("apellido1"),
|
||||
rs.getString("apellido2"),
|
||||
rs.getString("dni"),
|
||||
rs.getString("direccion"),
|
||||
rs.getString("email"),
|
||||
rs.getString("telefono"),
|
||||
rs.getInt("idTipologiaSexo"),
|
||||
rs.getBytes("imagen"),
|
||||
rs.getString("colorPreferido")
|
||||
);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Estudiante getSiguienteEstudiante(Estudiante estudianteActual) {
|
||||
Connection conn = GestorConexiones.getConexion();
|
||||
|
||||
try {
|
||||
PreparedStatement pst = conn.prepareStatement("SELECT * FROM estudiante WHERE id > ? LIMIT 1");
|
||||
pst.setInt(1, estudianteActual.getId());
|
||||
ResultSet rs = pst.executeQuery();
|
||||
if (rs.next()) {
|
||||
return new Estudiante(
|
||||
rs.getInt("id"),
|
||||
rs.getString("nombre"),
|
||||
rs.getString("apellido1"),
|
||||
rs.getString("apellido2"),
|
||||
rs.getString("dni"),
|
||||
rs.getString("direccion"),
|
||||
rs.getString("email"),
|
||||
rs.getString("telefono"),
|
||||
rs.getInt("idTipologiaSexo"),
|
||||
rs.getBytes("imagen"),
|
||||
rs.getString("colorPreferido")
|
||||
);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
public static Estudiante getAnteriorEstudiante(Estudiante estudianteActual) {
|
||||
Connection conn = GestorConexiones.getConexion();
|
||||
|
||||
try {
|
||||
PreparedStatement pst = conn.prepareStatement("SELECT * FROM estudiante WHERE id < ? ORDER BY id DESC LIMIT 1");
|
||||
pst.setInt(1, estudianteActual.getId());
|
||||
ResultSet rs = pst.executeQuery();
|
||||
if (rs.next()) {
|
||||
return new Estudiante(
|
||||
rs.getInt("id"),
|
||||
rs.getString("nombre"),
|
||||
rs.getString("apellido1"),
|
||||
rs.getString("apellido2"),
|
||||
rs.getString("dni"),
|
||||
rs.getString("direccion"),
|
||||
rs.getString("email"),
|
||||
rs.getString("telefono"),
|
||||
rs.getInt("idTipologiaSexo"),
|
||||
rs.getBytes("imagen"),
|
||||
rs.getString("colorPreferido")
|
||||
);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
public static int borrarEstudiante(Estudiante estudiante) {
|
||||
Connection conn = GestorConexiones.getConexion();
|
||||
try {
|
||||
PreparedStatement pst = conn.prepareStatement("DELETE FROM estudiante WHERE id = ?");
|
||||
pst.setInt(1, estudiante.getId());
|
||||
return pst.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
return 0;
|
||||
//throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static int guardarEstudiante(Estudiante estudiante) {
|
||||
if (estudiante.getId() == -1) {
|
||||
estudiante.setId(getUltimoEstudiante().getId() + 1);
|
||||
return nuevoEstudiante(estudiante);
|
||||
}
|
||||
Connection conn = GestorConexiones.getConexion();
|
||||
try {
|
||||
PreparedStatement pst = conn.prepareStatement("UPDATE estudiante SET nombre = ?, apellido1 = ?, apellido2 = ?, dni = ?, direccion = ?, email = ?, telefono = ?, idTipologiaSexo = ?, imagen = ?, colorPreferido = ? WHERE id = ?");
|
||||
pst.setString(1, estudiante.getNombre());
|
||||
pst.setString(2, estudiante.getApellido1());
|
||||
pst.setString(3, estudiante.getApellido2());
|
||||
pst.setString(4, estudiante.getDni());
|
||||
pst.setString(5, estudiante.getDireccion());
|
||||
pst.setString(6, estudiante.getEmail());
|
||||
pst.setString(7, estudiante.getTelefono());
|
||||
pst.setInt(8, estudiante.getIdTipologiaSexo());
|
||||
pst.setBytes(9, estudiante.getImagen());
|
||||
pst.setString(10, estudiante.getColorPreferido());
|
||||
pst.setInt(11, estudiante.getId());
|
||||
return pst.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
return 0;
|
||||
//throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static int nuevoEstudiante(Estudiante estudiante) {
|
||||
Connection conn = GestorConexiones.getConexion();
|
||||
try {
|
||||
PreparedStatement pst = conn.prepareStatement("INSERT INTO estudiante (id,nombre,apellido1,apellido2,dni,direccion,email,telefono,idTipologiaSexo,imagen,colorPreferido) VALUES (?,?,?,?,?,?,?,?,?,?,?)");
|
||||
pst.setInt(1, estudiante.getId());
|
||||
pst.setString(2, estudiante.getNombre());
|
||||
pst.setString(3, estudiante.getApellido1());
|
||||
pst.setString(4, estudiante.getApellido2());
|
||||
pst.setString(5, estudiante.getDni());
|
||||
pst.setString(6, estudiante.getDireccion());
|
||||
pst.setString(7, estudiante.getEmail());
|
||||
pst.setString(8, estudiante.getTelefono());
|
||||
pst.setInt(9, estudiante.getIdTipologiaSexo());
|
||||
pst.setBytes(10, estudiante.getImagen());
|
||||
pst.setString(11, estudiante.getColorPreferido());
|
||||
return pst.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -87,13 +87,14 @@ public class ControladorMateria {
|
||||
pst.setInt(1, materiaActual.getId());
|
||||
return pst.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
return 0;
|
||||
//throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static int guardarMateria(Materia materia) {
|
||||
if (materia.getId() == -1) {
|
||||
materia.setId(ControladorMateria.getUltimaMateria().getId() + 1);
|
||||
materia.setId(getUltimaMateria().getId() + 1);
|
||||
return nuevaMateria(materia);
|
||||
}
|
||||
Connection conn = GestorConexiones.getConexion();
|
||||
@@ -105,7 +106,8 @@ public class ControladorMateria {
|
||||
pst.setInt(4, materia.getId());
|
||||
return pst.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
return 0;
|
||||
//throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
188
src/main/java/net/h4ckx0r/controlador/ControladorProfesor.java
Normal file
188
src/main/java/net/h4ckx0r/controlador/ControladorProfesor.java
Normal file
@@ -0,0 +1,188 @@
|
||||
package net.h4ckx0r.controlador;
|
||||
|
||||
import net.h4ckx0r.modelo.Profesor;
|
||||
|
||||
import java.sql.*;
|
||||
|
||||
public class ControladorProfesor {
|
||||
public static Profesor getPrimerProfesor() {
|
||||
Connection conn = GestorConexiones.getConexion();
|
||||
|
||||
try {
|
||||
Statement st = conn.createStatement();
|
||||
ResultSet rs = st.executeQuery("SELECT * FROM profesor LIMIT 1");
|
||||
|
||||
if (rs.next()) {
|
||||
return new Profesor(
|
||||
rs.getInt("id"),
|
||||
rs.getString("nombre"),
|
||||
rs.getString("apellido1"),
|
||||
rs.getString("apellido2"),
|
||||
rs.getString("dni"),
|
||||
rs.getString("direccion"),
|
||||
rs.getString("email"),
|
||||
rs.getString("telefono"),
|
||||
rs.getInt("idTipologiaSexo"),
|
||||
rs.getBytes("imagen"),
|
||||
rs.getString("colorPreferido")
|
||||
);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Profesor getUltimoProfesor() {
|
||||
Connection conn = GestorConexiones.getConexion();
|
||||
|
||||
try {
|
||||
Statement st = conn.createStatement();
|
||||
ResultSet rs = st.executeQuery("SELECT * FROM profesor ORDER BY id DESC LIMIT 1");
|
||||
|
||||
if (rs.next()) {
|
||||
return new Profesor(
|
||||
rs.getInt("id"),
|
||||
rs.getString("nombre"),
|
||||
rs.getString("apellido1"),
|
||||
rs.getString("apellido2"),
|
||||
rs.getString("dni"),
|
||||
rs.getString("direccion"),
|
||||
rs.getString("email"),
|
||||
rs.getString("telefono"),
|
||||
rs.getInt("idTipologiaSexo"),
|
||||
rs.getBytes("imagen"),
|
||||
rs.getString("colorPreferido")
|
||||
);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Profesor getSiguienteProfesor(Profesor profesorActual) {
|
||||
Connection conn = GestorConexiones.getConexion();
|
||||
|
||||
try {
|
||||
PreparedStatement pst = conn.prepareStatement("SELECT * FROM profesor WHERE id > ? LIMIT 1");
|
||||
pst.setInt(1, profesorActual.getId());
|
||||
ResultSet rs = pst.executeQuery();
|
||||
if (rs.next()) {
|
||||
return new Profesor(
|
||||
rs.getInt("id"),
|
||||
rs.getString("nombre"),
|
||||
rs.getString("apellido1"),
|
||||
rs.getString("apellido2"),
|
||||
rs.getString("dni"),
|
||||
rs.getString("direccion"),
|
||||
rs.getString("email"),
|
||||
rs.getString("telefono"),
|
||||
rs.getInt("idTipologiaSexo"),
|
||||
rs.getBytes("imagen"),
|
||||
rs.getString("colorPreferido")
|
||||
);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
public static Profesor getAnteriorProfesor(Profesor profesorActual) {
|
||||
Connection conn = GestorConexiones.getConexion();
|
||||
|
||||
try {
|
||||
PreparedStatement pst = conn.prepareStatement("SELECT * FROM profesor WHERE id < ? ORDER BY id DESC LIMIT 1");
|
||||
pst.setInt(1, profesorActual.getId());
|
||||
ResultSet rs = pst.executeQuery();
|
||||
if (rs.next()) {
|
||||
return new Profesor(
|
||||
rs.getInt("id"),
|
||||
rs.getString("nombre"),
|
||||
rs.getString("apellido1"),
|
||||
rs.getString("apellido2"),
|
||||
rs.getString("dni"),
|
||||
rs.getString("direccion"),
|
||||
rs.getString("email"),
|
||||
rs.getString("telefono"),
|
||||
rs.getInt("idTipologiaSexo"),
|
||||
rs.getBytes("imagen"),
|
||||
rs.getString("colorPreferido")
|
||||
);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
public static int borrarProfesor(Profesor profesor) {
|
||||
Connection conn = GestorConexiones.getConexion();
|
||||
try {
|
||||
PreparedStatement pst = conn.prepareStatement("DELETE FROM profesor WHERE id = ?");
|
||||
pst.setInt(1, profesor.getId());
|
||||
return pst.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
return 0;
|
||||
//throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static int guardarProfesor(Profesor profesor) {
|
||||
if (profesor.getId() == -1) {
|
||||
profesor.setId(getUltimoProfesor().getId() + 1);
|
||||
return nuevoProfesor(profesor);
|
||||
}
|
||||
Connection conn = GestorConexiones.getConexion();
|
||||
try {
|
||||
PreparedStatement pst = conn.prepareStatement("UPDATE profesor SET nombre = ?, apellido1 = ?, apellido2 = ?, dni = ?, direccion = ?, email = ?, telefono = ?, idTipologiaSexo = ?, imagen = ?, colorPreferido = ? WHERE id = ?");
|
||||
pst.setString(1, profesor.getNombre());
|
||||
pst.setString(2, profesor.getApellido1());
|
||||
pst.setString(3, profesor.getApellido2());
|
||||
pst.setString(4, profesor.getDni());
|
||||
pst.setString(5, profesor.getDireccion());
|
||||
pst.setString(6, profesor.getEmail());
|
||||
pst.setString(7, profesor.getTelefono());
|
||||
pst.setInt(8, profesor.getIdTipologiaSexo());
|
||||
pst.setBytes(9, profesor.getImagen());
|
||||
pst.setString(10, profesor.getColorPreferido());
|
||||
pst.setInt(11, profesor.getId());
|
||||
return pst.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
return 0;
|
||||
//throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static int nuevoProfesor(Profesor profesor) {
|
||||
Connection conn = GestorConexiones.getConexion();
|
||||
try {
|
||||
PreparedStatement pst = conn.prepareStatement("INSERT INTO profesor (id,nombre,apellido1,apellido2,dni,direccion,email,telefono,idTipologiaSexo,imagen, colorPreferido) VALUES (?,?,?,?,?,?,?,?,?,?,?)");
|
||||
pst.setInt(1, profesor.getId());
|
||||
pst.setString(2, profesor.getNombre());
|
||||
pst.setString(3, profesor.getApellido1());
|
||||
pst.setString(4, profesor.getApellido2());
|
||||
pst.setString(5, profesor.getDni());
|
||||
pst.setString(6, profesor.getDireccion());
|
||||
pst.setString(7, profesor.getEmail());
|
||||
pst.setString(8, profesor.getTelefono());
|
||||
pst.setInt(9, profesor.getIdTipologiaSexo());
|
||||
pst.setBytes(10, profesor.getImagen());
|
||||
pst.setString(11, profesor.getColorPreferido());
|
||||
return pst.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package net.h4ckx0r.controlador;
|
||||
|
||||
import net.h4ckx0r.modelo.TipologiaSexo;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ControladorTipologiaSexo {
|
||||
public static List<TipologiaSexo> getAllSexos() {
|
||||
Connection conn = GestorConexiones.getConexion();
|
||||
List<TipologiaSexo> sexos = new ArrayList<>();
|
||||
|
||||
try {
|
||||
Statement st = conn.createStatement();
|
||||
ResultSet rs = st.executeQuery("SELECT * FROM tipologiaSexo");
|
||||
|
||||
while (rs.next()) {
|
||||
sexos.add(new TipologiaSexo(rs.getInt("id"), rs.getString("descripcion")));
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return sexos;
|
||||
}
|
||||
}
|
||||
14
src/main/java/net/h4ckx0r/controlador/Utils.java
Normal file
14
src/main/java/net/h4ckx0r/controlador/Utils.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package net.h4ckx0r.controlador;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class Utils {
|
||||
public static Color stringToColor(String color) {
|
||||
return Color.decode(color);
|
||||
}
|
||||
|
||||
public static String colorToString(Color color) {
|
||||
System.out.println("#" + Integer.toHexString(color.getRGB()));
|
||||
return "#" + (Integer.toHexString(color.getRGB())).substring(2);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
package net.h4ckx0r.modelo;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class Estudiante extends Persona {
|
||||
|
||||
public Estudiante(int id, String nombre, String apellido1, String apellido2, String dni, String direccion, String email, String telefono) {
|
||||
super(id, nombre, apellido1, apellido2, dni, direccion, email, telefono);
|
||||
public Estudiante(int id, String nombre, String apellido1, String apellido2, String dni, String direccion, String email, String telefono, int idTipologiaSexo, byte[] imagen, String colorPreferido) {
|
||||
super(id, nombre, apellido1, apellido2, dni, direccion, email, telefono, idTipologiaSexo, imagen, colorPreferido);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package net.h4ckx0r.modelo;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class Persona {
|
||||
private int id;
|
||||
private String nombre;
|
||||
@@ -9,8 +12,11 @@ public class Persona {
|
||||
private String direccion;
|
||||
private String email;
|
||||
private String telefono;
|
||||
private int idTipologiaSexo;
|
||||
private byte[] imagen;
|
||||
private String colorPreferido;
|
||||
|
||||
public Persona(int id, String nombre, String apellido1, String apellido2, String dni, String direccion, String email, String telefono) {
|
||||
public Persona(int id, String nombre, String apellido1, String apellido2, String dni, String direccion, String email, String telefono, int idTipologiaSexo, byte[] imagen, String colorPreferido) {
|
||||
this.id = id;
|
||||
this.nombre = nombre;
|
||||
this.apellido1 = apellido1;
|
||||
@@ -19,6 +25,9 @@ public class Persona {
|
||||
this.direccion = direccion;
|
||||
this.email = email;
|
||||
this.telefono = telefono;
|
||||
this.idTipologiaSexo = idTipologiaSexo;
|
||||
this.imagen = imagen;
|
||||
this.colorPreferido = colorPreferido;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
@@ -85,6 +94,30 @@ public class Persona {
|
||||
this.telefono = telefono;
|
||||
}
|
||||
|
||||
public int getIdTipologiaSexo() {
|
||||
return idTipologiaSexo;
|
||||
}
|
||||
|
||||
public void setIdTipologiaSexo(int idTipologiaSexo) {
|
||||
this.idTipologiaSexo = idTipologiaSexo;
|
||||
}
|
||||
|
||||
public byte[] getImagen() {
|
||||
return imagen;
|
||||
}
|
||||
|
||||
public void setImagen(byte[] imagen) {
|
||||
this.imagen = imagen;
|
||||
}
|
||||
|
||||
public String getColorPreferido() {
|
||||
return colorPreferido;
|
||||
}
|
||||
|
||||
public void setColorPreferido(String colorPreferido) {
|
||||
this.colorPreferido = colorPreferido;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Persona{" +
|
||||
@@ -96,6 +129,9 @@ public class Persona {
|
||||
", direccion='" + direccion + '\'' +
|
||||
", email='" + email + '\'' +
|
||||
", telefono='" + telefono + '\'' +
|
||||
", idTipologiaSexo=" + idTipologiaSexo +
|
||||
", imagen=" + Arrays.toString(imagen) +
|
||||
", colorPreferido=" + colorPreferido + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package net.h4ckx0r.modelo;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class Profesor extends Persona{
|
||||
public Profesor(int id, String nombre, String apellido1, String apellido2, String dni, String direccion, String email, String telefono) {
|
||||
super(id, nombre, apellido1, apellido2, dni, direccion, email, telefono);
|
||||
public Profesor(int id, String nombre, String apellido1, String apellido2, String dni, String direccion, String email, String telefono, int idTipologiaSexo, byte[] imagen, String colorPreferido) {
|
||||
super(id, nombre, apellido1, apellido2, dni, direccion, email, telefono, idTipologiaSexo, imagen, colorPreferido);
|
||||
}
|
||||
}
|
||||
|
||||
32
src/main/java/net/h4ckx0r/modelo/TipologiaSexo.java
Normal file
32
src/main/java/net/h4ckx0r/modelo/TipologiaSexo.java
Normal file
@@ -0,0 +1,32 @@
|
||||
package net.h4ckx0r.modelo;
|
||||
|
||||
public class TipologiaSexo {
|
||||
private int id;
|
||||
private String descripcion;
|
||||
|
||||
public TipologiaSexo(int id, String descripcion) {
|
||||
this.id = id;
|
||||
this.descripcion = descripcion;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getDescripcion() {
|
||||
return descripcion;
|
||||
}
|
||||
|
||||
public void setDescripcion(String descripcion) {
|
||||
this.descripcion = descripcion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return descripcion;
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,13 @@
|
||||
package net.h4ckx0r.vista;
|
||||
|
||||
import net.h4ckx0r.controlador.ControladorCurso;
|
||||
import net.h4ckx0r.controlador.ControladorEstudiante;
|
||||
import net.h4ckx0r.controlador.ControladorMateria;
|
||||
import net.h4ckx0r.controlador.ControladorProfesor;
|
||||
import net.h4ckx0r.modelo.Curso;
|
||||
import net.h4ckx0r.modelo.Estudiante;
|
||||
import net.h4ckx0r.modelo.Materia;
|
||||
import net.h4ckx0r.modelo.Profesor;
|
||||
import net.h4ckx0r.vista.panels.PanelCursos;
|
||||
import net.h4ckx0r.vista.panels.PanelMaterias;
|
||||
import net.h4ckx0r.vista.panels.PanelPersona;
|
||||
@@ -15,10 +19,6 @@ import javax.swing.*;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
|
||||
@@ -66,9 +66,11 @@ public class MainView extends JFrame {
|
||||
MainView frame = new MainView();
|
||||
frame.panelCursos.setCursoActual(ControladorCurso.getPrimerCurso());
|
||||
frame.panelMaterias.setMateriaActual(ControladorMateria.getPrimeraMateria());
|
||||
frame.panelEstudiantes.setEstudianteActual(ControladorEstudiante.getPrimerEstudiante());
|
||||
frame.panelProfesores.setProfesorActual(ControladorProfesor.getPrimerProfesor());
|
||||
|
||||
|
||||
frame.actualizarPantalla();
|
||||
frame.actualizarBotonesPantalla();
|
||||
frame.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@@ -214,6 +216,36 @@ public class MainView extends JFrame {
|
||||
|
||||
tabbedPane = new JTabbedPane(JTabbedPane.TOP);
|
||||
contentPane.add(tabbedPane, BorderLayout.CENTER);
|
||||
panelCursos.addComponentListener(new ComponentAdapter() {
|
||||
@Override
|
||||
public void componentShown(ComponentEvent e) {
|
||||
actualizarBotonesPantalla();
|
||||
}
|
||||
});
|
||||
panelMaterias.addComponentListener(new ComponentAdapter() {
|
||||
@Override
|
||||
public void componentShown(ComponentEvent e) {
|
||||
actualizarBotonesPantalla();
|
||||
}
|
||||
});
|
||||
panelEstudiantes.addComponentListener(new ComponentAdapter() {
|
||||
@Override
|
||||
public void componentShown(ComponentEvent e) {
|
||||
actualizarBotonesPantalla();
|
||||
}
|
||||
});
|
||||
panelProfesores.addComponentListener(new ComponentAdapter() {
|
||||
@Override
|
||||
public void componentShown(ComponentEvent e) {
|
||||
actualizarBotonesPantalla();
|
||||
}
|
||||
});
|
||||
panelValoracionMaterias.addComponentListener(new ComponentAdapter() {
|
||||
@Override
|
||||
public void componentShown(ComponentEvent e) {
|
||||
actualizarBotonesPantalla();
|
||||
}
|
||||
});
|
||||
|
||||
tabbedPane.addTab("Cursos", iconCursos, panelCursos, null);
|
||||
tabbedPane.addTab("Materias", iconMaterias, panelMaterias, null);
|
||||
@@ -224,44 +256,107 @@ public class MainView extends JFrame {
|
||||
|
||||
|
||||
private void agregarRegistro() {
|
||||
cargarUltimoRegistro();
|
||||
if (tabbedPane.getSelectedComponent() == panelCursos) {
|
||||
panelCursos.setCursoActual(new Curso(-1, ""));
|
||||
} else if (tabbedPane.getSelectedComponent() == panelMaterias) {
|
||||
panelMaterias.setMateriaActual(new Materia(-1, "", "", -1));
|
||||
} else if (tabbedPane.getSelectedComponent() == panelEstudiantes) {
|
||||
panelEstudiantes.setEstudianteActual(new Estudiante(-1, "", "", "", "", "", "", "", -1, null, null));
|
||||
} else if (tabbedPane.getSelectedComponent() == panelProfesores) {
|
||||
panelProfesores.setProfesorActual(new Profesor(-1, "", "", "", "", "", "", "", -1, null, null));
|
||||
}
|
||||
}
|
||||
|
||||
private void borrarRegistro() {
|
||||
|
||||
if (JOptionPane.showConfirmDialog(null, "¿Desea borrar el registro?", "¿Está seguro?", JOptionPane.YES_NO_OPTION) == 0) {
|
||||
if (JOptionPane.showConfirmDialog(this, "¿Desea borrar el registro?", "¿Está seguro?", JOptionPane.YES_NO_OPTION) != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
int resultado = 0;
|
||||
|
||||
if (tabbedPane.getSelectedComponent() == panelCursos) {
|
||||
Curso cursoSiguiente = ControladorCurso.getSiguienteCurso(panelCursos.getCursoActual());
|
||||
Curso cursoAnterior = ControladorCurso.getAnteriorCurso(panelCursos.getCursoActual());
|
||||
|
||||
resultado = ControladorCurso.borrarCurso(panelCursos.getCursoActual());
|
||||
if (resultado > 0) {
|
||||
if (cursoSiguiente != null) {
|
||||
panelCursos.setCursoActual(cursoSiguiente);
|
||||
} else if (cursoAnterior != null) {
|
||||
panelCursos.setCursoActual(cursoAnterior);
|
||||
} else {
|
||||
agregarRegistro();
|
||||
}
|
||||
}
|
||||
} else if (tabbedPane.getSelectedComponent() == panelMaterias) {
|
||||
Materia materiaSiguiente = ControladorMateria.getSiguienteMateria(panelMaterias.getMateriaActual());
|
||||
Materia materiaAnterior = ControladorMateria.getAnteriorMateria(panelMaterias.getMateriaActual());
|
||||
|
||||
resultado = ControladorMateria.borrarMateria(panelMaterias.getMateriaActual());
|
||||
if (resultado > 0) {
|
||||
if (materiaSiguiente != null) {
|
||||
panelMaterias.setMateriaActual(materiaSiguiente);
|
||||
} else if (materiaAnterior != null) {
|
||||
panelMaterias.setMateriaActual(materiaAnterior);
|
||||
} else {
|
||||
agregarRegistro();
|
||||
}
|
||||
}
|
||||
} else if (tabbedPane.getSelectedComponent() == panelEstudiantes) {
|
||||
Estudiante estudianteSiguiente = ControladorEstudiante.getSiguienteEstudiante(panelEstudiantes.getEstudianteActual());
|
||||
Estudiante estudianteAnterior = ControladorEstudiante.getAnteriorEstudiante(panelEstudiantes.getEstudianteActual());
|
||||
|
||||
resultado = ControladorEstudiante.borrarEstudiante(panelEstudiantes.getEstudianteActual());
|
||||
if (resultado > 0) {
|
||||
if (estudianteSiguiente != null) {
|
||||
panelEstudiantes.setEstudianteActual(estudianteSiguiente);
|
||||
} else if (estudianteAnterior != null) {
|
||||
panelEstudiantes.setEstudianteActual(estudianteAnterior);
|
||||
} else {
|
||||
agregarRegistro();
|
||||
}
|
||||
}
|
||||
} else if (tabbedPane.getSelectedComponent() == panelProfesores) {
|
||||
Profesor profesorSiguiente = ControladorProfesor.getSiguienteProfesor(panelProfesores.getProfesorActual());
|
||||
Profesor profesorAnterior = ControladorProfesor.getAnteriorProfesor(panelProfesores.getProfesorActual());
|
||||
|
||||
resultado = ControladorProfesor.borrarProfesor(panelProfesores.getProfesorActual());
|
||||
if (resultado > 0) {
|
||||
if (profesorSiguiente != null) {
|
||||
panelProfesores.setProfesorActual(profesorSiguiente);
|
||||
} else if (profesorAnterior != null) {
|
||||
panelProfesores.setProfesorActual(profesorAnterior);
|
||||
} else {
|
||||
agregarRegistro();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (resultado > 0) {
|
||||
JOptionPane.showMessageDialog(null, "Registro borrado correctamente");
|
||||
JOptionPane.showMessageDialog(this, "Registro borrado correctamente");
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(null, "No se pudo borrar el registro");
|
||||
JOptionPane.showMessageDialog(this, "No se pudo borrar el registro");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void guardarRegistro() {
|
||||
int resultado = 0;
|
||||
if (tabbedPane.getSelectedComponent() == panelCursos) {
|
||||
if (ControladorCurso.guardarCurso(panelCursos.getCursoActual()) > 0) {
|
||||
JOptionPane.showMessageDialog(null, "Registro guardado correctamente");
|
||||
}
|
||||
resultado = ControladorCurso.guardarCurso(panelCursos.getCursoActual());
|
||||
} else if (tabbedPane.getSelectedComponent() == panelMaterias) {
|
||||
if (ControladorMateria.guardarMateria(panelMaterias.getMateriaActual()) > 0) {
|
||||
JOptionPane.showMessageDialog(null, "Registro guardado correctamente");
|
||||
resultado = ControladorMateria.guardarMateria(panelMaterias.getMateriaActual());
|
||||
} else if (tabbedPane.getSelectedComponent() == panelEstudiantes) {
|
||||
resultado = ControladorEstudiante.guardarEstudiante(panelEstudiantes.getEstudianteActual());
|
||||
} else if (tabbedPane.getSelectedComponent() == panelProfesores) {
|
||||
resultado = ControladorProfesor.guardarProfesor(panelProfesores.getProfesorActual());
|
||||
}
|
||||
|
||||
if (resultado > 0) {
|
||||
JOptionPane.showMessageDialog(this, "Registro guardado correctamente");
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(this, "No se pudo guardar el registro");
|
||||
}
|
||||
|
||||
|
||||
@@ -273,13 +368,25 @@ public class MainView extends JFrame {
|
||||
Curso primerCurso = ControladorCurso.getPrimerCurso();
|
||||
if (primerCurso != null) {
|
||||
panelCursos.setCursoActual(primerCurso);
|
||||
actualizarPantalla();
|
||||
actualizarBotonesPantalla();
|
||||
}
|
||||
} else if (tabbedPane.getSelectedComponent() == panelMaterias) {
|
||||
Materia primeraMateria = ControladorMateria.getPrimeraMateria();
|
||||
if (primeraMateria != null) {
|
||||
panelMaterias.setMateriaActual(primeraMateria);
|
||||
actualizarPantalla();
|
||||
actualizarBotonesPantalla();
|
||||
}
|
||||
} else if (tabbedPane.getSelectedComponent() == panelEstudiantes) {
|
||||
Estudiante primerEstudiante = ControladorEstudiante.getPrimerEstudiante();
|
||||
if (primerEstudiante != null) {
|
||||
panelEstudiantes.setEstudianteActual(primerEstudiante);
|
||||
actualizarBotonesPantalla();
|
||||
}
|
||||
} else if (tabbedPane.getSelectedComponent() == panelProfesores) {
|
||||
Profesor primerProfesor = ControladorProfesor.getPrimerProfesor();
|
||||
if (primerProfesor != null) {
|
||||
panelProfesores.setProfesorActual(primerProfesor);
|
||||
actualizarBotonesPantalla();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -290,13 +397,25 @@ public class MainView extends JFrame {
|
||||
Curso ultimoCurso = ControladorCurso.getUltimoCurso();
|
||||
if (ultimoCurso != null) {
|
||||
panelCursos.setCursoActual(ultimoCurso);
|
||||
actualizarPantalla();
|
||||
actualizarBotonesPantalla();
|
||||
}
|
||||
} else if (tabbedPane.getSelectedComponent() == panelMaterias) {
|
||||
Materia ultimaMateria = ControladorMateria.getUltimaMateria();
|
||||
if (ultimaMateria != null) {
|
||||
panelMaterias.setMateriaActual(ultimaMateria);
|
||||
actualizarPantalla();
|
||||
actualizarBotonesPantalla();
|
||||
}
|
||||
} else if (tabbedPane.getSelectedComponent() == panelEstudiantes) {
|
||||
Estudiante ultimoEstudiante = ControladorEstudiante.getUltimoEstudiante();
|
||||
if (ultimoEstudiante != null) {
|
||||
panelEstudiantes.setEstudianteActual(ultimoEstudiante);
|
||||
actualizarBotonesPantalla();
|
||||
}
|
||||
} else if (tabbedPane.getSelectedComponent() == panelProfesores) {
|
||||
Profesor ultimoProfesor = ControladorProfesor.getUltimoProfesor();
|
||||
if (ultimoProfesor != null) {
|
||||
panelProfesores.setProfesorActual(ultimoProfesor);
|
||||
actualizarBotonesPantalla();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -307,14 +426,25 @@ public class MainView extends JFrame {
|
||||
Curso siguienteCurso = ControladorCurso.getSiguienteCurso(panelCursos.getCursoActual());
|
||||
if (siguienteCurso != null) {
|
||||
panelCursos.setCursoActual(siguienteCurso);
|
||||
actualizarPantalla();
|
||||
actualizarBotonesPantalla();
|
||||
}
|
||||
|
||||
} else if (tabbedPane.getSelectedComponent() == panelMaterias) {
|
||||
Materia siguienteMateria = ControladorMateria.getSiguienteMateria(panelMaterias.getMateriaActual());
|
||||
if (siguienteMateria != null) {
|
||||
panelMaterias.setMateriaActual(siguienteMateria);
|
||||
actualizarPantalla();
|
||||
actualizarBotonesPantalla();
|
||||
}
|
||||
} else if (tabbedPane.getSelectedComponent() == panelEstudiantes) {
|
||||
Estudiante siguienteEstudiante = ControladorEstudiante.getSiguienteEstudiante(panelEstudiantes.getEstudianteActual());
|
||||
if (siguienteEstudiante != null) {
|
||||
panelEstudiantes.setEstudianteActual(siguienteEstudiante);
|
||||
actualizarBotonesPantalla();
|
||||
}
|
||||
} else if (tabbedPane.getSelectedComponent() == panelProfesores) {
|
||||
Profesor siguienteProfesor = ControladorProfesor.getSiguienteProfesor(panelProfesores.getProfesorActual());
|
||||
if (siguienteProfesor != null) {
|
||||
panelProfesores.setProfesorActual(siguienteProfesor);
|
||||
actualizarBotonesPantalla();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -322,21 +452,53 @@ public class MainView extends JFrame {
|
||||
|
||||
private void cargarAnteriorRegistro() {
|
||||
if (tabbedPane.getSelectedComponent() == panelCursos) {
|
||||
Curso anteriorCurso = ControladorCurso.getAnteriorCurso(panelCursos.getCursoActual());
|
||||
Curso cursoActual = panelCursos.getCursoActual();
|
||||
if (cursoActual.getId() == -1) {
|
||||
panelCursos.setCursoActual(ControladorCurso.getUltimoCurso());
|
||||
} else {
|
||||
Curso anteriorCurso = ControladorCurso.getAnteriorCurso(cursoActual);
|
||||
if (anteriorCurso != null) {
|
||||
panelCursos.setCursoActual(anteriorCurso);
|
||||
actualizarPantalla();
|
||||
actualizarBotonesPantalla();
|
||||
}
|
||||
}
|
||||
} else if (tabbedPane.getSelectedComponent() == panelMaterias) {
|
||||
Materia materiaActual = panelMaterias.getMateriaActual();
|
||||
if (materiaActual.getId() == -1) {
|
||||
panelMaterias.setMateriaActual(ControladorMateria.getUltimaMateria());
|
||||
} else {
|
||||
Materia anteriorMateria = ControladorMateria.getAnteriorMateria(panelMaterias.getMateriaActual());
|
||||
if (anteriorMateria != null) {
|
||||
panelMaterias.setMateriaActual(anteriorMateria);
|
||||
actualizarPantalla();
|
||||
actualizarBotonesPantalla();
|
||||
}
|
||||
}
|
||||
} else if (tabbedPane.getSelectedComponent() == panelEstudiantes) {
|
||||
Estudiante estudianteActual = panelEstudiantes.getEstudianteActual();
|
||||
if (estudianteActual.getId() == -1) {
|
||||
panelEstudiantes.setEstudianteActual(ControladorEstudiante.getUltimoEstudiante());
|
||||
} else {
|
||||
Estudiante anteriorEstudiante = ControladorEstudiante.getAnteriorEstudiante(panelEstudiantes.getEstudianteActual());
|
||||
if (anteriorEstudiante != null) {
|
||||
panelEstudiantes.setEstudianteActual(anteriorEstudiante);
|
||||
actualizarBotonesPantalla();
|
||||
}
|
||||
}
|
||||
} else if (tabbedPane.getSelectedComponent() == panelProfesores) {
|
||||
Profesor profesorActual = panelProfesores.getProfesorActual();
|
||||
if (profesorActual.getId() == -1) {
|
||||
panelProfesores.setProfesorActual(ControladorProfesor.getUltimoProfesor());
|
||||
} else {
|
||||
Profesor anteriorProfesor = ControladorProfesor.getAnteriorProfesor(panelProfesores.getProfesorActual());
|
||||
if (anteriorProfesor != null) {
|
||||
panelProfesores.setProfesorActual(anteriorProfesor);
|
||||
actualizarBotonesPantalla();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void actualizarPantalla() {
|
||||
private void actualizarBotonesPantalla() {
|
||||
if (tabbedPane.getSelectedComponent() == panelCursos) {
|
||||
Curso cursoActual = panelCursos.getCursoActual();
|
||||
alternarBotonesToolbar(
|
||||
@@ -347,6 +509,16 @@ public class MainView extends JFrame {
|
||||
alternarBotonesToolbar(
|
||||
materiaActual.getId() == ControladorMateria.getPrimeraMateria().getId(),
|
||||
materiaActual.getId() == ControladorMateria.getUltimaMateria().getId());
|
||||
} else if (tabbedPane.getSelectedComponent() == panelEstudiantes) {
|
||||
Estudiante estudianteActual = panelEstudiantes.getEstudianteActual();
|
||||
alternarBotonesToolbar(
|
||||
estudianteActual.getId() == ControladorEstudiante.getPrimerEstudiante().getId(),
|
||||
estudianteActual.getId() == ControladorEstudiante.getUltimoEstudiante().getId());
|
||||
} else if (tabbedPane.getSelectedComponent() == panelProfesores) {
|
||||
Profesor profesorActual = panelProfesores.getProfesorActual();
|
||||
alternarBotonesToolbar(
|
||||
profesorActual.getId() == ControladorProfesor.getPrimerProfesor().getId(),
|
||||
profesorActual.getId() == ControladorProfesor.getUltimoProfesor().getId());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
package net.h4ckx0r.vista;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class PanelCurso extends JPanel {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* Create the panel.
|
||||
*/
|
||||
public PanelCurso() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,31 +1,57 @@
|
||||
package net.h4ckx0r.vista.panels;
|
||||
|
||||
import net.h4ckx0r.controlador.ControladorTipologiaSexo;
|
||||
import net.h4ckx0r.controlador.Utils;
|
||||
import net.h4ckx0r.modelo.*;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.Insets;
|
||||
import java.awt.BorderLayout;
|
||||
import javax.swing.filechooser.FileNameExtensionFilter;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
import static net.h4ckx0r.controlador.Utils.stringToColor;
|
||||
|
||||
public class PanelPersona extends JPanel {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private JTextField textField;
|
||||
private JTextField textField_1;
|
||||
private JTextField textField_2;
|
||||
private JTextField textField_3;
|
||||
private JTextField textField_4;
|
||||
private JTextField textField_5;
|
||||
private JTextField textField_6;
|
||||
|
||||
private Persona personaActual;
|
||||
private Color colorFondoSistema = this.getBackground();
|
||||
|
||||
private JTextField tfNombre;
|
||||
private JTextField tfApellido1;
|
||||
private JTextField tfApellido2;
|
||||
private JTextField tfDNI;
|
||||
private JTextField tfDireccion;
|
||||
private JTextField tfEmail;
|
||||
private JTextField tfTelefono;
|
||||
private JComboBox<TipologiaSexo> comboBoxSexo;
|
||||
private JLabel labelImage;
|
||||
private JPopupMenu popupMenuImage;
|
||||
private JMenuItem mntmDimensiones;
|
||||
private JTextField tfColorPreferido;
|
||||
|
||||
List<TipologiaSexo> sexos = ControladorTipologiaSexo.getAllSexos();
|
||||
|
||||
|
||||
/**
|
||||
* Create the panel.
|
||||
*/
|
||||
public PanelPersona() {
|
||||
GridBagLayout gridBagLayout = new GridBagLayout();
|
||||
gridBagLayout.columnWidths = new int[]{0, 0, 0};
|
||||
gridBagLayout.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||
gridBagLayout.columnWeights = new double[]{0.2, 1.0, Double.MIN_VALUE};
|
||||
gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE};
|
||||
gridBagLayout.columnWidths = new int[]{0, 0, 0, 0};
|
||||
gridBagLayout.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||
gridBagLayout.columnWeights = new double[]{0.2, 1.0, 0.2, Double.MIN_VALUE};
|
||||
gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE};
|
||||
setLayout(gridBagLayout);
|
||||
|
||||
JLabel lblNewLabel = new JLabel("Nombre:");
|
||||
@@ -36,14 +62,59 @@ public class PanelPersona extends JPanel {
|
||||
gbc_lblNewLabel.gridy = 0;
|
||||
add(lblNewLabel, gbc_lblNewLabel);
|
||||
|
||||
textField = new JTextField();
|
||||
tfNombre = new JTextField();
|
||||
GridBagConstraints gbc_textField = new GridBagConstraints();
|
||||
gbc_textField.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_textField.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_textField.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_textField.gridx = 1;
|
||||
gbc_textField.gridy = 0;
|
||||
add(textField, gbc_textField);
|
||||
textField.setColumns(10);
|
||||
add(tfNombre, gbc_textField);
|
||||
tfNombre.setColumns(10);
|
||||
|
||||
JScrollPane scrollPane = new JScrollPane();
|
||||
scrollPane.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
mostrarPopup(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
mostrarPopup(e);
|
||||
}
|
||||
|
||||
private void mostrarPopup(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
popupMenuImage.show(e.getComponent(), e.getX(), e.getY());
|
||||
}
|
||||
}
|
||||
});
|
||||
GridBagConstraints gbc_scrollPane = new GridBagConstraints();
|
||||
gbc_scrollPane.gridheight = 6;
|
||||
gbc_scrollPane.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_scrollPane.fill = GridBagConstraints.BOTH;
|
||||
gbc_scrollPane.gridx = 2;
|
||||
gbc_scrollPane.gridy = 0;
|
||||
add(scrollPane, gbc_scrollPane);
|
||||
|
||||
labelImage = new JLabel();
|
||||
labelImage.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
scrollPane.setViewportView(labelImage);
|
||||
|
||||
popupMenuImage = new JPopupMenu();
|
||||
scrollPane.add(popupMenuImage);
|
||||
|
||||
mntmDimensiones = new JMenuItem("No hay imagen");
|
||||
mntmDimensiones.setEnabled(false);
|
||||
popupMenuImage.add(mntmDimensiones);
|
||||
popupMenuImage.addSeparator();
|
||||
JMenuItem mntmCambiarImagen = new JMenuItem("Cambiar Imagen");
|
||||
mntmCambiarImagen.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
solicitarImagenNativo();
|
||||
}
|
||||
});
|
||||
popupMenuImage.add(mntmCambiarImagen);
|
||||
|
||||
JLabel lblNewLabel_1 = new JLabel("Primer Apellido:");
|
||||
GridBagConstraints gbc_lblNewLabel_1 = new GridBagConstraints();
|
||||
@@ -53,14 +124,14 @@ public class PanelPersona extends JPanel {
|
||||
gbc_lblNewLabel_1.gridy = 1;
|
||||
add(lblNewLabel_1, gbc_lblNewLabel_1);
|
||||
|
||||
textField_1 = new JTextField();
|
||||
tfApellido1 = new JTextField();
|
||||
GridBagConstraints gbc_textField_1 = new GridBagConstraints();
|
||||
gbc_textField_1.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_textField_1.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_textField_1.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_textField_1.gridx = 1;
|
||||
gbc_textField_1.gridy = 1;
|
||||
add(textField_1, gbc_textField_1);
|
||||
textField_1.setColumns(10);
|
||||
add(tfApellido1, gbc_textField_1);
|
||||
tfApellido1.setColumns(10);
|
||||
|
||||
JLabel lblNewLabel_2 = new JLabel("Segundo Apellido:");
|
||||
GridBagConstraints gbc_lblNewLabel_2 = new GridBagConstraints();
|
||||
@@ -70,83 +141,277 @@ public class PanelPersona extends JPanel {
|
||||
gbc_lblNewLabel_2.gridy = 2;
|
||||
add(lblNewLabel_2, gbc_lblNewLabel_2);
|
||||
|
||||
textField_2 = new JTextField();
|
||||
tfApellido2 = new JTextField();
|
||||
GridBagConstraints gbc_textField_2 = new GridBagConstraints();
|
||||
gbc_textField_2.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_textField_2.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_textField_2.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_textField_2.gridx = 1;
|
||||
gbc_textField_2.gridy = 2;
|
||||
add(textField_2, gbc_textField_2);
|
||||
textField_2.setColumns(10);
|
||||
add(tfApellido2, gbc_textField_2);
|
||||
tfApellido2.setColumns(10);
|
||||
|
||||
JLabel lblNewLabel_7 = new JLabel("Sexo:");
|
||||
GridBagConstraints gbc_lblNewLabel_7 = new GridBagConstraints();
|
||||
gbc_lblNewLabel_7.anchor = GridBagConstraints.EAST;
|
||||
gbc_lblNewLabel_7.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblNewLabel_7.gridx = 0;
|
||||
gbc_lblNewLabel_7.gridy = 3;
|
||||
add(lblNewLabel_7, gbc_lblNewLabel_7);
|
||||
|
||||
comboBoxSexo = new JComboBox<>();
|
||||
GridBagConstraints gbc_comboBoxSexo = new GridBagConstraints();
|
||||
gbc_comboBoxSexo.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_comboBoxSexo.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_comboBoxSexo.gridx = 1;
|
||||
gbc_comboBoxSexo.gridy = 3;
|
||||
add(comboBoxSexo, gbc_comboBoxSexo);
|
||||
|
||||
JLabel lblNewLabel_3 = new JLabel("DNI:");
|
||||
GridBagConstraints gbc_lblNewLabel_3 = new GridBagConstraints();
|
||||
gbc_lblNewLabel_3.anchor = GridBagConstraints.EAST;
|
||||
gbc_lblNewLabel_3.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblNewLabel_3.gridx = 0;
|
||||
gbc_lblNewLabel_3.gridy = 3;
|
||||
gbc_lblNewLabel_3.gridy = 4;
|
||||
add(lblNewLabel_3, gbc_lblNewLabel_3);
|
||||
|
||||
textField_3 = new JTextField();
|
||||
tfDNI = new JTextField();
|
||||
GridBagConstraints gbc_textField_3 = new GridBagConstraints();
|
||||
gbc_textField_3.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_textField_3.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_textField_3.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_textField_3.gridx = 1;
|
||||
gbc_textField_3.gridy = 3;
|
||||
add(textField_3, gbc_textField_3);
|
||||
textField_3.setColumns(10);
|
||||
gbc_textField_3.gridy = 4;
|
||||
add(tfDNI, gbc_textField_3);
|
||||
tfDNI.setColumns(10);
|
||||
|
||||
JLabel lblNewLabel_4 = new JLabel("Dirección:");
|
||||
GridBagConstraints gbc_lblNewLabel_4 = new GridBagConstraints();
|
||||
gbc_lblNewLabel_4.anchor = GridBagConstraints.EAST;
|
||||
gbc_lblNewLabel_4.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblNewLabel_4.gridx = 0;
|
||||
gbc_lblNewLabel_4.gridy = 4;
|
||||
gbc_lblNewLabel_4.gridy = 5;
|
||||
add(lblNewLabel_4, gbc_lblNewLabel_4);
|
||||
|
||||
textField_4 = new JTextField();
|
||||
tfDireccion = new JTextField();
|
||||
GridBagConstraints gbc_textField_4 = new GridBagConstraints();
|
||||
gbc_textField_4.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_textField_4.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_textField_4.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_textField_4.gridx = 1;
|
||||
gbc_textField_4.gridy = 4;
|
||||
add(textField_4, gbc_textField_4);
|
||||
textField_4.setColumns(10);
|
||||
gbc_textField_4.gridy = 5;
|
||||
add(tfDireccion, gbc_textField_4);
|
||||
tfDireccion.setColumns(10);
|
||||
|
||||
JLabel lblNewLabel_5 = new JLabel("Email:");
|
||||
GridBagConstraints gbc_lblNewLabel_5 = new GridBagConstraints();
|
||||
gbc_lblNewLabel_5.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblNewLabel_5.anchor = GridBagConstraints.EAST;
|
||||
gbc_lblNewLabel_5.gridx = 0;
|
||||
gbc_lblNewLabel_5.gridy = 5;
|
||||
gbc_lblNewLabel_5.gridy = 6;
|
||||
add(lblNewLabel_5, gbc_lblNewLabel_5);
|
||||
|
||||
textField_5 = new JTextField();
|
||||
tfEmail = new JTextField();
|
||||
GridBagConstraints gbc_textField_5 = new GridBagConstraints();
|
||||
gbc_textField_5.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_textField_5.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_textField_5.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_textField_5.gridx = 1;
|
||||
gbc_textField_5.gridy = 5;
|
||||
add(textField_5, gbc_textField_5);
|
||||
textField_5.setColumns(10);
|
||||
gbc_textField_5.gridy = 6;
|
||||
add(tfEmail, gbc_textField_5);
|
||||
tfEmail.setColumns(10);
|
||||
|
||||
JButton btnNewButton = new JButton("Cambiar Imagen");
|
||||
btnNewButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
solicitarImagenNativo();
|
||||
}
|
||||
});
|
||||
GridBagConstraints gbc_btnNewButton = new GridBagConstraints();
|
||||
gbc_btnNewButton.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_btnNewButton.gridx = 2;
|
||||
gbc_btnNewButton.gridy = 6;
|
||||
add(btnNewButton, gbc_btnNewButton);
|
||||
|
||||
JLabel lblNewLabel_6 = new JLabel("Teléfono");
|
||||
GridBagConstraints gbc_lblNewLabel_6 = new GridBagConstraints();
|
||||
gbc_lblNewLabel_6.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblNewLabel_6.anchor = GridBagConstraints.EAST;
|
||||
gbc_lblNewLabel_6.gridx = 0;
|
||||
gbc_lblNewLabel_6.gridy = 6;
|
||||
gbc_lblNewLabel_6.gridy = 7;
|
||||
add(lblNewLabel_6, gbc_lblNewLabel_6);
|
||||
|
||||
textField_6 = new JTextField();
|
||||
tfTelefono = new JTextField();
|
||||
GridBagConstraints gbc_textField_6 = new GridBagConstraints();
|
||||
gbc_textField_6.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_textField_6.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_textField_6.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_textField_6.gridx = 1;
|
||||
gbc_textField_6.gridy = 6;
|
||||
add(textField_6, gbc_textField_6);
|
||||
textField_6.setColumns(10);
|
||||
gbc_textField_6.gridy = 7;
|
||||
add(tfTelefono, gbc_textField_6);
|
||||
tfTelefono.setColumns(10);
|
||||
|
||||
JLabel lblNewLabel_8 = new JLabel("Color preferido:");
|
||||
GridBagConstraints gbc_lblNewLabel_8 = new GridBagConstraints();
|
||||
gbc_lblNewLabel_8.anchor = GridBagConstraints.EAST;
|
||||
gbc_lblNewLabel_8.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblNewLabel_8.gridx = 0;
|
||||
gbc_lblNewLabel_8.gridy = 8;
|
||||
add(lblNewLabel_8, gbc_lblNewLabel_8);
|
||||
|
||||
tfColorPreferido = new JTextField();
|
||||
GridBagConstraints gbc_textFieldColor = new GridBagConstraints();
|
||||
gbc_textFieldColor.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_textFieldColor.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_textFieldColor.gridx = 1;
|
||||
gbc_textFieldColor.gridy = 8;
|
||||
add(tfColorPreferido, gbc_textFieldColor);
|
||||
tfColorPreferido.setColumns(10);
|
||||
|
||||
JButton btnNewButton_1 = new JButton("Cambiar Color");
|
||||
btnNewButton_1.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
solicitarColor();
|
||||
}
|
||||
});
|
||||
GridBagConstraints gbc_btnNewButton_1 = new GridBagConstraints();
|
||||
gbc_btnNewButton_1.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_btnNewButton_1.gridx = 2;
|
||||
gbc_btnNewButton_1.gridy = 8;
|
||||
add(btnNewButton_1, gbc_btnNewButton_1);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void setPersona(Persona persona) {
|
||||
tfNombre.setText(persona.getNombre());
|
||||
tfApellido1.setText(persona.getApellido1());
|
||||
tfApellido2.setText(persona.getApellido2());
|
||||
tfDNI.setText(persona.getDni());
|
||||
tfDireccion.setText(persona.getDireccion());
|
||||
tfEmail.setText(persona.getEmail());
|
||||
tfTelefono.setText(persona.getTelefono());
|
||||
if (persona.getColorPreferido() != null && !persona.getColorPreferido().isEmpty()) {
|
||||
this.setBackground(stringToColor(persona.getColorPreferido()));
|
||||
} else {
|
||||
this.setBackground(colorFondoSistema);
|
||||
}
|
||||
tfColorPreferido.setText(persona.getColorPreferido());
|
||||
personaActual = persona;
|
||||
actualizarSexo();
|
||||
ponerImagen();
|
||||
}
|
||||
|
||||
private Persona getPersona() {
|
||||
personaActual.setNombre(tfNombre.getText());
|
||||
personaActual.setApellido1(tfApellido1.getText());
|
||||
personaActual.setApellido2(tfApellido2.getText());
|
||||
personaActual.setIdTipologiaSexo(((TipologiaSexo) comboBoxSexo.getSelectedItem()).getId());
|
||||
personaActual.setDni(tfDNI.getText());
|
||||
personaActual.setDireccion(tfDireccion.getText());
|
||||
personaActual.setEmail(tfEmail.getText());
|
||||
personaActual.setTelefono(tfTelefono.getText());
|
||||
personaActual.setColorPreferido(tfColorPreferido.getText());
|
||||
return personaActual;
|
||||
}
|
||||
|
||||
public void setEstudianteActual(Estudiante estudiante) {
|
||||
setPersona(estudiante);
|
||||
}
|
||||
|
||||
public Estudiante getEstudianteActual() {
|
||||
return (Estudiante) getPersona();
|
||||
}
|
||||
|
||||
public void setProfesorActual(Profesor profesor) {
|
||||
setPersona(profesor);
|
||||
}
|
||||
|
||||
public Profesor getProfesorActual() {
|
||||
return (Profesor) getPersona();
|
||||
}
|
||||
|
||||
private void actualizarSexo() {
|
||||
comboBoxSexo.removeAllItems();
|
||||
for (TipologiaSexo sexo : sexos) {
|
||||
comboBoxSexo.addItem(sexo);
|
||||
if (personaActual.getIdTipologiaSexo() == sexo.getId()) {
|
||||
comboBoxSexo.setSelectedItem(sexo);
|
||||
}
|
||||
}
|
||||
if (personaActual.getIdTipologiaSexo() == -1) {
|
||||
comboBoxSexo.setSelectedIndex(-1);
|
||||
}
|
||||
}
|
||||
|
||||
private void ponerImagen() {
|
||||
if (personaActual.getImagen() == null) {
|
||||
labelImage.setIcon(null);
|
||||
labelImage.setText("No hay imagen");
|
||||
mntmDimensiones.setText("No hay imagen");
|
||||
} else {
|
||||
ImageIcon icono = new ImageIcon(personaActual.getImagen());
|
||||
labelImage.setText("");
|
||||
labelImage.setIcon(icono);
|
||||
int[] dimensiones = getDimensionesImagen(icono);
|
||||
mntmDimensiones.setText("Dimensiones: " + dimensiones[0] + "x" + dimensiones[1]);
|
||||
}
|
||||
}
|
||||
|
||||
private void solicitarImagen() {
|
||||
JFileChooser fileChooser = new JFileChooser();
|
||||
fileChooser.setFileFilter(new FileNameExtensionFilter("Sólo imágenes: *.jpg, *.png", "jpg", "png"));
|
||||
int seleccion = fileChooser.showOpenDialog(this);
|
||||
if (seleccion == JFileChooser.APPROVE_OPTION) {
|
||||
File file = fileChooser.getSelectedFile();
|
||||
byte[] imagen = null;
|
||||
try {
|
||||
imagen = Files.readAllBytes(file.toPath());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
personaActual.setImagen(imagen);
|
||||
ponerImagen();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void solicitarImagenNativo() {
|
||||
JFrame frame = new JFrame();
|
||||
FileDialog fileChooser = new FileDialog(frame, "Seleccione una imagen", FileDialog.LOAD);
|
||||
fileChooser.setFilenameFilter(new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File dir, String name) {
|
||||
return name.endsWith(".jpg") || name.endsWith(".png");
|
||||
}
|
||||
});
|
||||
fileChooser.setVisible(true);
|
||||
String folder = fileChooser.getDirectory();
|
||||
String file = fileChooser.getFile();
|
||||
if (file != null) {
|
||||
try {
|
||||
ImageIcon icono = new ImageIcon(folder + file);
|
||||
if (getDimensionesImagen(icono)[0] <= 300 && getDimensionesImagen(icono)[1] <= 300) {
|
||||
this.personaActual.setImagen(Files.readAllBytes(Paths.get(folder + file)));
|
||||
ponerImagen();
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(this, "La imagen debe ser menor o igual de 300x300px");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private int[] getDimensionesImagen(ImageIcon icon) {
|
||||
return new int[] {icon.getIconWidth(), icon.getIconHeight()};
|
||||
}
|
||||
|
||||
|
||||
private void solicitarColor() {
|
||||
Color color = JColorChooser.showDialog(this, "Seleccione un color", colorFondoSistema);
|
||||
if (color != null) {
|
||||
this.setBackground(color);
|
||||
tfColorPreferido.setText(Utils.colorToString(color));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user