Imagen de perfil
This commit is contained in:
@@ -22,7 +22,8 @@ public class ControladorEstudiante {
|
|||||||
rs.getString("direccion"),
|
rs.getString("direccion"),
|
||||||
rs.getString("email"),
|
rs.getString("email"),
|
||||||
rs.getString("telefono"),
|
rs.getString("telefono"),
|
||||||
rs.getInt("idTipologiaSexo")
|
rs.getInt("idTipologiaSexo"),
|
||||||
|
rs.getBytes("imagen")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,7 +51,8 @@ public class ControladorEstudiante {
|
|||||||
rs.getString("direccion"),
|
rs.getString("direccion"),
|
||||||
rs.getString("email"),
|
rs.getString("email"),
|
||||||
rs.getString("telefono"),
|
rs.getString("telefono"),
|
||||||
rs.getInt("idTipologiaSexo")
|
rs.getInt("idTipologiaSexo"),
|
||||||
|
rs.getBytes("imagen")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,7 +80,8 @@ public class ControladorEstudiante {
|
|||||||
rs.getString("direccion"),
|
rs.getString("direccion"),
|
||||||
rs.getString("email"),
|
rs.getString("email"),
|
||||||
rs.getString("telefono"),
|
rs.getString("telefono"),
|
||||||
rs.getInt("idTipologiaSexo")
|
rs.getInt("idTipologiaSexo"),
|
||||||
|
rs.getBytes("imagen")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,7 +110,8 @@ public class ControladorEstudiante {
|
|||||||
rs.getString("direccion"),
|
rs.getString("direccion"),
|
||||||
rs.getString("email"),
|
rs.getString("email"),
|
||||||
rs.getString("telefono"),
|
rs.getString("telefono"),
|
||||||
rs.getInt("idTipologiaSexo")
|
rs.getInt("idTipologiaSexo"),
|
||||||
|
rs.getBytes("imagen")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,7 +142,7 @@ public class ControladorEstudiante {
|
|||||||
}
|
}
|
||||||
Connection conn = GestorConexiones.getConexion();
|
Connection conn = GestorConexiones.getConexion();
|
||||||
try {
|
try {
|
||||||
PreparedStatement pst = conn.prepareStatement("UPDATE estudiante SET nombre = ?, apellido1 = ?, apellido2 = ?, dni = ?, direccion = ?, email = ?, telefono = ?, idTipologiaSexo = ? WHERE id = ?");
|
PreparedStatement pst = conn.prepareStatement("UPDATE estudiante SET nombre = ?, apellido1 = ?, apellido2 = ?, dni = ?, direccion = ?, email = ?, telefono = ?, idTipologiaSexo = ?, imagen = ? WHERE id = ?");
|
||||||
pst.setString(1, estudiante.getNombre());
|
pst.setString(1, estudiante.getNombre());
|
||||||
pst.setString(2, estudiante.getApellido1());
|
pst.setString(2, estudiante.getApellido1());
|
||||||
pst.setString(3, estudiante.getApellido2());
|
pst.setString(3, estudiante.getApellido2());
|
||||||
@@ -147,7 +151,8 @@ public class ControladorEstudiante {
|
|||||||
pst.setString(6, estudiante.getEmail());
|
pst.setString(6, estudiante.getEmail());
|
||||||
pst.setString(7, estudiante.getTelefono());
|
pst.setString(7, estudiante.getTelefono());
|
||||||
pst.setInt(8, estudiante.getIdTipologiaSexo());
|
pst.setInt(8, estudiante.getIdTipologiaSexo());
|
||||||
pst.setInt(9, estudiante.getId());
|
pst.setBytes(9, estudiante.getImagen());
|
||||||
|
pst.setInt(10, estudiante.getId());
|
||||||
return pst.executeUpdate();
|
return pst.executeUpdate();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
return 0;
|
return 0;
|
||||||
@@ -158,7 +163,7 @@ public class ControladorEstudiante {
|
|||||||
public static int nuevoEstudiante(Estudiante estudiante) {
|
public static int nuevoEstudiante(Estudiante estudiante) {
|
||||||
Connection conn = GestorConexiones.getConexion();
|
Connection conn = GestorConexiones.getConexion();
|
||||||
try {
|
try {
|
||||||
PreparedStatement pst = conn.prepareStatement("INSERT INTO estudiante (id,nombre,apellido1,apellido2,dni,direccion,email,telefono,idTipologiaSexo) VALUES (?,?,?,?,?,?,?,?,?)");
|
PreparedStatement pst = conn.prepareStatement("INSERT INTO estudiante (id,nombre,apellido1,apellido2,dni,direccion,email,telefono,idTipologiaSexo,imagen) VALUES (?,?,?,?,?,?,?,?,?,?)");
|
||||||
pst.setInt(1, estudiante.getId());
|
pst.setInt(1, estudiante.getId());
|
||||||
pst.setString(2, estudiante.getNombre());
|
pst.setString(2, estudiante.getNombre());
|
||||||
pst.setString(3, estudiante.getApellido1());
|
pst.setString(3, estudiante.getApellido1());
|
||||||
@@ -168,6 +173,7 @@ public class ControladorEstudiante {
|
|||||||
pst.setString(7, estudiante.getEmail());
|
pst.setString(7, estudiante.getEmail());
|
||||||
pst.setString(8, estudiante.getTelefono());
|
pst.setString(8, estudiante.getTelefono());
|
||||||
pst.setInt(9, estudiante.getIdTipologiaSexo());
|
pst.setInt(9, estudiante.getIdTipologiaSexo());
|
||||||
|
pst.setBytes(10, estudiante.getImagen());
|
||||||
return pst.executeUpdate();
|
return pst.executeUpdate();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
|||||||
@@ -22,7 +22,8 @@ public class ControladorProfesor {
|
|||||||
rs.getString("direccion"),
|
rs.getString("direccion"),
|
||||||
rs.getString("email"),
|
rs.getString("email"),
|
||||||
rs.getString("telefono"),
|
rs.getString("telefono"),
|
||||||
rs.getInt("idTipologiaSexo")
|
rs.getInt("idTipologiaSexo"),
|
||||||
|
rs.getBytes("imagen")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,7 +51,8 @@ public class ControladorProfesor {
|
|||||||
rs.getString("direccion"),
|
rs.getString("direccion"),
|
||||||
rs.getString("email"),
|
rs.getString("email"),
|
||||||
rs.getString("telefono"),
|
rs.getString("telefono"),
|
||||||
rs.getInt("idTipologiaSexo")
|
rs.getInt("idTipologiaSexo"),
|
||||||
|
rs.getBytes("imagen")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,7 +80,8 @@ public class ControladorProfesor {
|
|||||||
rs.getString("direccion"),
|
rs.getString("direccion"),
|
||||||
rs.getString("email"),
|
rs.getString("email"),
|
||||||
rs.getString("telefono"),
|
rs.getString("telefono"),
|
||||||
rs.getInt("idTipologiaSexo")
|
rs.getInt("idTipologiaSexo"),
|
||||||
|
rs.getBytes("imagen")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,7 +110,8 @@ public class ControladorProfesor {
|
|||||||
rs.getString("direccion"),
|
rs.getString("direccion"),
|
||||||
rs.getString("email"),
|
rs.getString("email"),
|
||||||
rs.getString("telefono"),
|
rs.getString("telefono"),
|
||||||
rs.getInt("idTipologiaSexo")
|
rs.getInt("idTipologiaSexo"),
|
||||||
|
rs.getBytes("imagen")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,23 +135,24 @@ public class ControladorProfesor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int guardarProfesor(Profesor estudiante) {
|
public static int guardarProfesor(Profesor profesor) {
|
||||||
if (estudiante.getId() == -1) {
|
if (profesor.getId() == -1) {
|
||||||
estudiante.setId(getUltimoProfesor().getId() + 1);
|
profesor.setId(getUltimoProfesor().getId() + 1);
|
||||||
return nuevoProfesor(estudiante);
|
return nuevoProfesor(profesor);
|
||||||
}
|
}
|
||||||
Connection conn = GestorConexiones.getConexion();
|
Connection conn = GestorConexiones.getConexion();
|
||||||
try {
|
try {
|
||||||
PreparedStatement pst = conn.prepareStatement("UPDATE profesor SET nombre = ?, apellido1 = ?, apellido2 = ?, dni = ?, direccion = ?, email = ?, telefono = ?, idTipologiaSexo = ? WHERE id = ?");
|
PreparedStatement pst = conn.prepareStatement("UPDATE profesor SET nombre = ?, apellido1 = ?, apellido2 = ?, dni = ?, direccion = ?, email = ?, telefono = ?, idTipologiaSexo = ?, imagen = ? WHERE id = ?");
|
||||||
pst.setString(1, estudiante.getNombre());
|
pst.setString(1, profesor.getNombre());
|
||||||
pst.setString(2, estudiante.getApellido1());
|
pst.setString(2, profesor.getApellido1());
|
||||||
pst.setString(3, estudiante.getApellido2());
|
pst.setString(3, profesor.getApellido2());
|
||||||
pst.setString(4, estudiante.getDni());
|
pst.setString(4, profesor.getDni());
|
||||||
pst.setString(5, estudiante.getDireccion());
|
pst.setString(5, profesor.getDireccion());
|
||||||
pst.setString(6, estudiante.getEmail());
|
pst.setString(6, profesor.getEmail());
|
||||||
pst.setString(7, estudiante.getTelefono());
|
pst.setString(7, profesor.getTelefono());
|
||||||
pst.setInt(8, estudiante.getIdTipologiaSexo());
|
pst.setInt(8, profesor.getIdTipologiaSexo());
|
||||||
pst.setInt(9, estudiante.getId());
|
pst.setBytes(9, profesor.getImagen());
|
||||||
|
pst.setInt(10, profesor.getId());
|
||||||
return pst.executeUpdate();
|
return pst.executeUpdate();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
return 0;
|
return 0;
|
||||||
@@ -158,7 +163,7 @@ public class ControladorProfesor {
|
|||||||
public static int nuevoProfesor(Profesor profesor) {
|
public static int nuevoProfesor(Profesor profesor) {
|
||||||
Connection conn = GestorConexiones.getConexion();
|
Connection conn = GestorConexiones.getConexion();
|
||||||
try {
|
try {
|
||||||
PreparedStatement pst = conn.prepareStatement("INSERT INTO profesor (id,nombre,apellido1,apellido2,dni,direccion,email,telefono,idTipologiaSexo) VALUES (?,?,?,?,?,?,?,?,?)");
|
PreparedStatement pst = conn.prepareStatement("INSERT INTO profesor (id,nombre,apellido1,apellido2,dni,direccion,email,telefono,idTipologiaSexo,imagen) VALUES (?,?,?,?,?,?,?,?,?,?)");
|
||||||
pst.setInt(1, profesor.getId());
|
pst.setInt(1, profesor.getId());
|
||||||
pst.setString(2, profesor.getNombre());
|
pst.setString(2, profesor.getNombre());
|
||||||
pst.setString(3, profesor.getApellido1());
|
pst.setString(3, profesor.getApellido1());
|
||||||
@@ -168,6 +173,7 @@ public class ControladorProfesor {
|
|||||||
pst.setString(7, profesor.getEmail());
|
pst.setString(7, profesor.getEmail());
|
||||||
pst.setString(8, profesor.getTelefono());
|
pst.setString(8, profesor.getTelefono());
|
||||||
pst.setInt(9, profesor.getIdTipologiaSexo());
|
pst.setInt(9, profesor.getIdTipologiaSexo());
|
||||||
|
pst.setBytes(10, profesor.getImagen());
|
||||||
return pst.executeUpdate();
|
return pst.executeUpdate();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package net.h4ckx0r.modelo;
|
|||||||
|
|
||||||
public class Estudiante extends Persona {
|
public class Estudiante extends Persona {
|
||||||
|
|
||||||
public Estudiante(int id, String nombre, String apellido1, String apellido2, String dni, String direccion, String email, String telefono, int idTipologiaSexo) {
|
public Estudiante(int id, String nombre, String apellido1, String apellido2, String dni, String direccion, String email, String telefono, int idTipologiaSexo, byte[] imagen) {
|
||||||
super(id, nombre, apellido1, apellido2, dni, direccion, email, telefono, idTipologiaSexo);
|
super(id, nombre, apellido1, apellido2, dni, direccion, email, telefono, idTipologiaSexo, imagen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package net.h4ckx0r.modelo;
|
package net.h4ckx0r.modelo;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
public class Persona {
|
public class Persona {
|
||||||
private int id;
|
private int id;
|
||||||
private String nombre;
|
private String nombre;
|
||||||
@@ -10,8 +12,9 @@ public class Persona {
|
|||||||
private String email;
|
private String email;
|
||||||
private String telefono;
|
private String telefono;
|
||||||
private int idTipologiaSexo;
|
private int idTipologiaSexo;
|
||||||
|
private byte[] imagen;
|
||||||
|
|
||||||
public Persona(int id, String nombre, String apellido1, String apellido2, String dni, String direccion, String email, String telefono, int idTipologiaSexo) {
|
public Persona(int id, String nombre, String apellido1, String apellido2, String dni, String direccion, String email, String telefono, int idTipologiaSexo, byte[] imagen) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.nombre = nombre;
|
this.nombre = nombre;
|
||||||
this.apellido1 = apellido1;
|
this.apellido1 = apellido1;
|
||||||
@@ -21,6 +24,7 @@ public class Persona {
|
|||||||
this.email = email;
|
this.email = email;
|
||||||
this.telefono = telefono;
|
this.telefono = telefono;
|
||||||
this.idTipologiaSexo = idTipologiaSexo;
|
this.idTipologiaSexo = idTipologiaSexo;
|
||||||
|
this.imagen = imagen;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getId() {
|
public int getId() {
|
||||||
@@ -95,6 +99,14 @@ public class Persona {
|
|||||||
this.idTipologiaSexo = idTipologiaSexo;
|
this.idTipologiaSexo = idTipologiaSexo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public byte[] getImagen() {
|
||||||
|
return imagen;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setImagen(byte[] imagen) {
|
||||||
|
this.imagen = imagen;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Persona{" +
|
return "Persona{" +
|
||||||
@@ -107,6 +119,7 @@ public class Persona {
|
|||||||
", email='" + email + '\'' +
|
", email='" + email + '\'' +
|
||||||
", telefono='" + telefono + '\'' +
|
", telefono='" + telefono + '\'' +
|
||||||
", idTipologiaSexo=" + idTipologiaSexo +
|
", idTipologiaSexo=" + idTipologiaSexo +
|
||||||
|
", imagen=" + Arrays.toString(imagen) +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package net.h4ckx0r.modelo;
|
package net.h4ckx0r.modelo;
|
||||||
|
|
||||||
public class Profesor extends Persona{
|
public class Profesor extends Persona{
|
||||||
public Profesor(int id, String nombre, String apellido1, String apellido2, String dni, String direccion, String email, String telefono, int idTipologiaSexo) {
|
public Profesor(int id, String nombre, String apellido1, String apellido2, String dni, String direccion, String email, String telefono, int idTipologiaSexo, byte[] imagen) {
|
||||||
super(id, nombre, apellido1, apellido2, dni, direccion, email, telefono, idTipologiaSexo);
|
super(id, nombre, apellido1, apellido2, dni, direccion, email, telefono, idTipologiaSexo, imagen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -262,9 +262,9 @@ public class MainView extends JFrame {
|
|||||||
} else if (tabbedPane.getSelectedComponent() == panelMaterias) {
|
} else if (tabbedPane.getSelectedComponent() == panelMaterias) {
|
||||||
panelMaterias.setMateriaActual(new Materia(-1, "", "", -1));
|
panelMaterias.setMateriaActual(new Materia(-1, "", "", -1));
|
||||||
} else if (tabbedPane.getSelectedComponent() == panelEstudiantes) {
|
} else if (tabbedPane.getSelectedComponent() == panelEstudiantes) {
|
||||||
panelEstudiantes.setEstudianteActual(new Estudiante(-1, "", "", "", "", "", "", "", -1));
|
panelEstudiantes.setEstudianteActual(new Estudiante(-1, "", "", "", "", "", "", "", -1, null));
|
||||||
} else if (tabbedPane.getSelectedComponent() == panelProfesores) {
|
} else if (tabbedPane.getSelectedComponent() == panelProfesores) {
|
||||||
panelProfesores.setProfesorActual(new Profesor(-1, "", "", "", "", "", "", "", -1));
|
panelProfesores.setProfesorActual(new Profesor(-1, "", "", "", "", "", "", "", -1, null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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,14 +1,21 @@
|
|||||||
package net.h4ckx0r.vista.panels;
|
package net.h4ckx0r.vista.panels;
|
||||||
|
|
||||||
import net.h4ckx0r.controlador.ControladorCurso;
|
|
||||||
import net.h4ckx0r.controlador.ControladorTipologiaSexo;
|
import net.h4ckx0r.controlador.ControladorTipologiaSexo;
|
||||||
import net.h4ckx0r.modelo.*;
|
import net.h4ckx0r.modelo.*;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.GridBagLayout;
|
import javax.swing.filechooser.FileNameExtensionFilter;
|
||||||
import java.awt.GridBagConstraints;
|
import java.awt.*;
|
||||||
import java.awt.Insets;
|
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.util.List;
|
||||||
|
import java.awt.event.MouseAdapter;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
|
||||||
public class PanelPersona extends JPanel {
|
public class PanelPersona extends JPanel {
|
||||||
|
|
||||||
@@ -24,16 +31,22 @@ public class PanelPersona extends JPanel {
|
|||||||
private JTextField tfEmail;
|
private JTextField tfEmail;
|
||||||
private JTextField tfTelefono;
|
private JTextField tfTelefono;
|
||||||
private JComboBox<TipologiaSexo> comboBoxSexo;
|
private JComboBox<TipologiaSexo> comboBoxSexo;
|
||||||
|
private JLabel labelImage;
|
||||||
|
private JPopupMenu popupMenuImage;
|
||||||
|
private JMenuItem mntmDimensiones;
|
||||||
|
|
||||||
|
List<TipologiaSexo> sexos = ControladorTipologiaSexo.getAllSexos();
|
||||||
|
private JTextField textField;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create the panel.
|
* Create the panel.
|
||||||
*/
|
*/
|
||||||
public PanelPersona() {
|
public PanelPersona() {
|
||||||
GridBagLayout gridBagLayout = new GridBagLayout();
|
GridBagLayout gridBagLayout = new GridBagLayout();
|
||||||
gridBagLayout.columnWidths = new int[]{0, 0, 0};
|
gridBagLayout.columnWidths = new int[]{0, 0, 0, 0};
|
||||||
gridBagLayout.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 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, Double.MIN_VALUE};
|
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, 1.0, 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);
|
setLayout(gridBagLayout);
|
||||||
|
|
||||||
JLabel lblNewLabel = new JLabel("Nombre:");
|
JLabel lblNewLabel = new JLabel("Nombre:");
|
||||||
@@ -46,13 +59,58 @@ public class PanelPersona extends JPanel {
|
|||||||
|
|
||||||
tfNombre = new JTextField();
|
tfNombre = new JTextField();
|
||||||
GridBagConstraints gbc_textField = new GridBagConstraints();
|
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.fill = GridBagConstraints.HORIZONTAL;
|
||||||
gbc_textField.gridx = 1;
|
gbc_textField.gridx = 1;
|
||||||
gbc_textField.gridy = 0;
|
gbc_textField.gridy = 0;
|
||||||
add(tfNombre, gbc_textField);
|
add(tfNombre, gbc_textField);
|
||||||
tfNombre.setColumns(10);
|
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:");
|
JLabel lblNewLabel_1 = new JLabel("Primer Apellido:");
|
||||||
GridBagConstraints gbc_lblNewLabel_1 = new GridBagConstraints();
|
GridBagConstraints gbc_lblNewLabel_1 = new GridBagConstraints();
|
||||||
gbc_lblNewLabel_1.anchor = GridBagConstraints.EAST;
|
gbc_lblNewLabel_1.anchor = GridBagConstraints.EAST;
|
||||||
@@ -63,7 +121,7 @@ public class PanelPersona extends JPanel {
|
|||||||
|
|
||||||
tfApellido1 = new JTextField();
|
tfApellido1 = new JTextField();
|
||||||
GridBagConstraints gbc_textField_1 = new GridBagConstraints();
|
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.fill = GridBagConstraints.HORIZONTAL;
|
||||||
gbc_textField_1.gridx = 1;
|
gbc_textField_1.gridx = 1;
|
||||||
gbc_textField_1.gridy = 1;
|
gbc_textField_1.gridy = 1;
|
||||||
@@ -80,7 +138,7 @@ public class PanelPersona extends JPanel {
|
|||||||
|
|
||||||
tfApellido2 = new JTextField();
|
tfApellido2 = new JTextField();
|
||||||
GridBagConstraints gbc_textField_2 = new GridBagConstraints();
|
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.fill = GridBagConstraints.HORIZONTAL;
|
||||||
gbc_textField_2.gridx = 1;
|
gbc_textField_2.gridx = 1;
|
||||||
gbc_textField_2.gridy = 2;
|
gbc_textField_2.gridy = 2;
|
||||||
@@ -97,7 +155,7 @@ public class PanelPersona extends JPanel {
|
|||||||
|
|
||||||
comboBoxSexo = new JComboBox<>();
|
comboBoxSexo = new JComboBox<>();
|
||||||
GridBagConstraints gbc_comboBoxSexo = new GridBagConstraints();
|
GridBagConstraints gbc_comboBoxSexo = new GridBagConstraints();
|
||||||
gbc_comboBoxSexo.insets = new Insets(0, 0, 5, 0);
|
gbc_comboBoxSexo.insets = new Insets(0, 0, 5, 5);
|
||||||
gbc_comboBoxSexo.fill = GridBagConstraints.HORIZONTAL;
|
gbc_comboBoxSexo.fill = GridBagConstraints.HORIZONTAL;
|
||||||
gbc_comboBoxSexo.gridx = 1;
|
gbc_comboBoxSexo.gridx = 1;
|
||||||
gbc_comboBoxSexo.gridy = 3;
|
gbc_comboBoxSexo.gridy = 3;
|
||||||
@@ -113,7 +171,7 @@ public class PanelPersona extends JPanel {
|
|||||||
|
|
||||||
tfDNI = new JTextField();
|
tfDNI = new JTextField();
|
||||||
GridBagConstraints gbc_textField_3 = new GridBagConstraints();
|
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.fill = GridBagConstraints.HORIZONTAL;
|
||||||
gbc_textField_3.gridx = 1;
|
gbc_textField_3.gridx = 1;
|
||||||
gbc_textField_3.gridy = 4;
|
gbc_textField_3.gridy = 4;
|
||||||
@@ -130,7 +188,7 @@ public class PanelPersona extends JPanel {
|
|||||||
|
|
||||||
tfDireccion = new JTextField();
|
tfDireccion = new JTextField();
|
||||||
GridBagConstraints gbc_textField_4 = new GridBagConstraints();
|
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.fill = GridBagConstraints.HORIZONTAL;
|
||||||
gbc_textField_4.gridx = 1;
|
gbc_textField_4.gridx = 1;
|
||||||
gbc_textField_4.gridy = 5;
|
gbc_textField_4.gridy = 5;
|
||||||
@@ -147,13 +205,25 @@ public class PanelPersona extends JPanel {
|
|||||||
|
|
||||||
tfEmail = new JTextField();
|
tfEmail = new JTextField();
|
||||||
GridBagConstraints gbc_textField_5 = new GridBagConstraints();
|
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.fill = GridBagConstraints.HORIZONTAL;
|
||||||
gbc_textField_5.gridx = 1;
|
gbc_textField_5.gridx = 1;
|
||||||
gbc_textField_5.gridy = 6;
|
gbc_textField_5.gridy = 6;
|
||||||
add(tfEmail, gbc_textField_5);
|
add(tfEmail, gbc_textField_5);
|
||||||
tfEmail.setColumns(10);
|
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");
|
JLabel lblNewLabel_6 = new JLabel("Teléfono");
|
||||||
GridBagConstraints gbc_lblNewLabel_6 = new GridBagConstraints();
|
GridBagConstraints gbc_lblNewLabel_6 = new GridBagConstraints();
|
||||||
gbc_lblNewLabel_6.insets = new Insets(0, 0, 5, 5);
|
gbc_lblNewLabel_6.insets = new Insets(0, 0, 5, 5);
|
||||||
@@ -164,13 +234,44 @@ public class PanelPersona extends JPanel {
|
|||||||
|
|
||||||
tfTelefono = new JTextField();
|
tfTelefono = new JTextField();
|
||||||
GridBagConstraints gbc_textField_6 = new GridBagConstraints();
|
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.fill = GridBagConstraints.HORIZONTAL;
|
||||||
gbc_textField_6.gridx = 1;
|
gbc_textField_6.gridx = 1;
|
||||||
gbc_textField_6.gridy = 7;
|
gbc_textField_6.gridy = 7;
|
||||||
add(tfTelefono, gbc_textField_6);
|
add(tfTelefono, gbc_textField_6);
|
||||||
tfTelefono.setColumns(10);
|
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);
|
||||||
|
|
||||||
|
textField = 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(textField, gbc_textFieldColor);
|
||||||
|
textField.setColumns(10);
|
||||||
|
|
||||||
|
JButton btnNewButton_1 = new JButton("Cambiar Color");
|
||||||
|
btnNewButton_1.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
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) {
|
private void setPersona(Persona persona) {
|
||||||
@@ -183,6 +284,7 @@ public class PanelPersona extends JPanel {
|
|||||||
tfTelefono.setText(persona.getTelefono());
|
tfTelefono.setText(persona.getTelefono());
|
||||||
personaActual = persona;
|
personaActual = persona;
|
||||||
actualizarSexo();
|
actualizarSexo();
|
||||||
|
ponerImagen();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Persona getPersona() {
|
private Persona getPersona() {
|
||||||
@@ -214,7 +316,6 @@ public class PanelPersona extends JPanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void actualizarSexo() {
|
private void actualizarSexo() {
|
||||||
List<TipologiaSexo> sexos = ControladorTipologiaSexo.getAllSexos();
|
|
||||||
comboBoxSexo.removeAllItems();
|
comboBoxSexo.removeAllItems();
|
||||||
for (TipologiaSexo sexo : sexos) {
|
for (TipologiaSexo sexo : sexos) {
|
||||||
comboBoxSexo.addItem(sexo);
|
comboBoxSexo.addItem(sexo);
|
||||||
@@ -227,4 +328,69 @@ public class PanelPersona extends JPanel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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()};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user