Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/imagens capas #200

Merged
merged 11 commits into from
Dec 5, 2023
7 changes: 6 additions & 1 deletion src/main/java/com/casaculturaqxd/sgec/DAO/EventoDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,13 @@ public boolean inserirEvento(Evento evento) {
}

try {
String sql = "INSERT INTO evento (nome_evento, publico_esperado, publico_alcancado, descricao, data_inicial, data_final, horario, classificacao_etaria, certificavel, carga_horaria, acessivel_em_libras, num_participantes_esperado, num_municipios_esperado) VALUES (?, ?, ?, ?, ?, ?, ?, ?::faixa_etaria, ?, ?, ?, ?, ?) RETURNING id_evento";
String sql = "INSERT INTO evento (nome_evento, publico_esperado, publico_alcancado, descricao, data_inicial, data_final, horario, classificacao_etaria, certificavel, carga_horaria, acessivel_em_libras, num_participantes_esperado, num_municipios_esperado, id_service_file) VALUES (?, ?, ?, ?, ?, ?, ?, ?::faixa_etaria, ?, ?, ?, ?, ?, ?) RETURNING id_evento";

PreparedStatement stmt = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
Integer idServiceFile = null;
if (evento.getImagemCapa() != null) {
idServiceFile = evento.getImagemCapa().getServiceFileId();
}

stmt.setString(1, evento.getNome());
stmt.setInt(2, evento.getPublicoEsperado());
Expand All @@ -63,6 +67,7 @@ public boolean inserirEvento(Evento evento) {
stmt.setBoolean(11, evento.isAcessivelEmLibras());
stmt.setInt(12, evento.getNumParticipantesEsperado());
stmt.setInt(13, evento.getNumMunicipiosEsperado());
stmt.setObject(14, idServiceFile, Types.INTEGER);

stmt.executeUpdate();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.casaculturaqxd.sgec.controller;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Date;
import java.sql.SQLException;
import java.sql.Time;
Expand Down Expand Up @@ -51,6 +54,8 @@
import javafx.scene.control.ButtonBar;
import javafx.scene.control.ButtonType;
import javafx.scene.control.ButtonBar.ButtonData;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.DateCell;
Expand All @@ -65,6 +70,7 @@
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.FileChooser;
import javafx.stage.FileChooser.ExtensionFilter;
import javafx.stage.Stage;
import javafx.util.converter.LocalTimeStringConverter;

Expand Down Expand Up @@ -121,11 +127,14 @@ public class CadastrarEventoController implements ControllerServiceFile, Control
ObservableList<PreviewParticipanteController> participantes = FXCollections
.<PreviewParticipanteController>observableList(new ArrayList<>());
private Alert mensagem = new Alert(AlertType.NONE);
@FXML
ImageView capaEvento;
File file = null;

public void initialize() throws IOException {
eventoDAO = new EventoDAO(db.getConnection());
participanteDAO.setConnection(db.getConnection());
serviceFileDAO = new ServiceFileDAO(eventoDAO.getConnection());
serviceFileDAO = new ServiceFileDAO(db.getConnection());

formatterHorario = new SimpleDateFormat("HH:mm");
addListenersServiceFile(mapServiceFiles);
Expand Down Expand Up @@ -303,6 +312,20 @@ private Evento getTargetEvento() throws SQLException {
builderEvento.setListaArquivos(listaArquivos);
builderEvento.setLocalizacoes(locais);
builderEvento.setListaMetas(getMetasSelecionadas());
if(file != null){
ServiceFile serviceFileTemp = new ServiceFile(file);
try {
if(serviceFileDAO.getArquivo(serviceFileTemp.getFileKey()).isEmpty()){
serviceFileDAO.inserirArquivo(serviceFileTemp);
serviceFileTemp = serviceFileDAO.getArquivo(serviceFileTemp.getFileKey()).get();
} else {
serviceFileTemp = serviceFileDAO.getArquivo(serviceFileTemp.getFileKey()).get();
}
} catch (SQLException e) {
e.printStackTrace();
}
builderEvento.setImagemCapa(serviceFileTemp);
}

return builderEvento.getEvento();
}
Expand Down Expand Up @@ -669,32 +692,29 @@ public boolean camposObrigatoriosPreenchidos() {

public void addListenersParticipante(ObservableList<PreviewParticipanteController> observableList) {
CadastrarEventoController superController = this;
observableList.addListener(new ListChangeListener<PreviewParticipanteController>() {
@Override
public void onChanged(ListChangeListener.Change<? extends PreviewParticipanteController> change) {

while (change.next()) {
if (change.wasAdded()) {
observableList.addListener((ListChangeListener<PreviewParticipanteController>) change -> {

for (PreviewParticipanteController addedController : change.getAddedSubList()) {
addedController.setParentController(superController);
while (change.next()) {
if (change.wasAdded()) {

secaoParticipantes.getChildren().add(addedController.getContainer());
}
for (PreviewParticipanteController addedController : change.getAddedSubList()) {
addedController.setParentController(superController);

secaoParticipantes.getChildren().add(addedController.getContainer());
}

if (change.wasRemoved()) {
}

for (PreviewParticipanteController removedController : change.getRemoved()) {
secaoParticipantes.getChildren().remove(removedController.getContainer());
}
if (change.wasRemoved()) {

for (PreviewParticipanteController removedController : change.getRemoved()) {
secaoParticipantes.getChildren().remove(removedController.getContainer());
}
}

}
});

}
});
}

public void addListenersOrganizador(ObservableList<PreviewInstituicaoController> observableList) {
Expand Down Expand Up @@ -923,4 +943,21 @@ public void removerLocalizacao(Localizacao localizacao) {

botaoNovaLocalizacao.setDisable(false);
}

public void loadImagem(){
InputStream fileAsStream;
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Alterar foto do evento");
ExtensionFilter filterImagens = new ExtensionFilter("imagem", "*.jpeg", "*.jpg", "*.png", "*.bmp");
fileChooser.getExtensionFilters().add(filterImagens);
try {
file = fileChooser.showOpenDialog(stage);
fileAsStream = new FileInputStream(file);
capaEvento.setImage(new Image(fileAsStream));
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (NullPointerException e) {
e.printStackTrace();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public class LoginController {

private User usuario;
private UserDAO userDAO;
private final Database userConnection = DatabasePostgres.getInstance("URL", "USER_NAME",
"PASSWORD");

private final Database userConnection = DatabasePostgres.getInstance("URL", "USER_NAME", "PASSWORD");

/**
* Carrega a página com o botão de login desabilitado
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.casaculturaqxd.sgec.controller;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Date;
import java.sql.SQLException;
import java.sql.Time;
Expand Down Expand Up @@ -70,6 +73,7 @@
import javafx.scene.control.Tooltip;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.control.cell.TextFieldTableCell;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.Clipboard;
import javafx.scene.input.ClipboardContent;
Expand All @@ -78,6 +82,7 @@
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.FileChooser;
import javafx.stage.FileChooser.ExtensionFilter;
import javafx.stage.Stage;
import javafx.util.Duration;
import javafx.util.converter.IntegerStringConverter;
Expand All @@ -88,6 +93,7 @@ public class VisualizarEventoController implements ControllerServiceFile, Contro
private DatabasePostgres db = DatabasePostgres.getInstance("URL", "USER_NAME", "PASSWORD");
private EventoDAO eventoDAO = new EventoDAO();
private LocalizacaoDAO localizacaoDAO = new LocalizacaoDAO();
private ServiceFileDAO serviceFileDAO;
private File lastDirectoryOpen;
private ArrayList<ServiceFile> removedFiles;
private DateFormat formatterHorario;
Expand Down Expand Up @@ -134,8 +140,11 @@ public class VisualizarEventoController implements ControllerServiceFile, Contro
@FXML
private ImageView copiaCola;
@FXML
ImageView capaEvento;
@FXML
private Tooltip tooltipCliboard;
private Alert mensagem = new Alert(AlertType.NONE);
File file = null;

public void initialize() throws IOException {
formatterHorario = new SimpleDateFormat("HH:mm");
Expand All @@ -155,6 +164,7 @@ public void initialize() throws IOException {
removedFiles = new ArrayList<>();
eventoDAO.setConnection(db.getConnection());
localizacaoDAO.setConnection(db.getConnection());
serviceFileDAO = new ServiceFileDAO(db.getConnection());
compararDatas();
}

Expand Down Expand Up @@ -253,6 +263,21 @@ private void loadContent() throws IOException, SQLException {
addIndicador(tabelaIndicadoresGerais, numeroPublico);
addIndicador(tabelaIndicadoresMeta1, numeroMestres);
addIndicador(tabelaIndicadoresMeta2, numeroMunicipios);

if(evento.getImagemCapa() != null){
InputStream fileAsStream;
try {
file = serviceFileDAO.getContent(evento.getImagemCapa());
fileAsStream = new FileInputStream(file);
this.capaEvento.setImage(new Image(fileAsStream));
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (NullPointerException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
}

private void loadInstituicoes() {
Expand Down Expand Up @@ -319,6 +344,20 @@ private Evento getTargetEvento() {
.setHorario(formatTimeInputField(horario)).setCargaHoraria(formatTimeInputField(cargaHoraria))
.setNumParticipantesEsperado(numeroMestres.getValorEsperado())
.setMunicipiosEsperado(numeroMunicipios.getValorEsperado());
if(file != null){
ServiceFile serviceFileTemp = new ServiceFile(file);
try {
if(serviceFileDAO.getArquivo(serviceFileTemp.getFileKey()).isEmpty()){
serviceFileDAO.inserirArquivo(serviceFileTemp);
serviceFileTemp = serviceFileDAO.getArquivo(serviceFileTemp.getFileKey()).get();
} else {
serviceFileTemp = serviceFileDAO.getArquivo(serviceFileTemp.getFileKey()).get();
}
} catch (SQLException e) {
e.printStackTrace();
}
eventoBuilder.setImagemCapa(serviceFileTemp);
}

return eventoBuilder.getEvento();
}
Expand Down Expand Up @@ -983,4 +1022,21 @@ public void onChanged(ListChangeListener.Change<? extends PreviewInstituicaoCont
}
});
}

public void loadImagem(){
InputStream fileAsStream;
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Alterar foto do evento");
ExtensionFilter filterImagens = new ExtensionFilter("imagem", "*.jpeg", "*.jpg", "*.png", "*.bmp");
fileChooser.getExtensionFilters().add(filterImagens);
try {
file = fileChooser.showOpenDialog(stage);
fileAsStream = new FileInputStream(file);
capaEvento.setImage(new Image(fileAsStream));
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (NullPointerException e) {
e.printStackTrace();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package com.casaculturaqxd.sgec.controller.preview;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.sql.SQLException;
import java.util.NoSuchElementException;

import com.casaculturaqxd.sgec.App;
import com.casaculturaqxd.sgec.DAO.EventoDAO;
import com.casaculturaqxd.sgec.DAO.ServiceFileDAO;
import com.casaculturaqxd.sgec.controller.VisualizarEventoController;
import com.casaculturaqxd.sgec.jdbc.DatabasePostgres;
import com.casaculturaqxd.sgec.models.Evento;
Expand All @@ -17,20 +22,28 @@
import javafx.scene.Parent;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.control.Button;
import javafx.scene.control.Label;

public class PreviewEventoController {
private EventoDAO dao = new EventoDAO();
private DatabasePostgres db = DatabasePostgres.getInstance("URL", "USER_NAME", "PASSWORD");
private ServiceFileDAO serviceFileDAO;
private Evento evento;
@FXML
Label dataHora, titulo;
@FXML
Button detalhes;
@FXML
ImageView imagem;

File file = null;

public void initialize() {
dao.setConnection(db.getConnection());
serviceFileDAO = new ServiceFileDAO(db.getConnection());
}

public void setEvento(Evento evento) {
Expand All @@ -47,6 +60,20 @@ private void setarInformacoesEvento() {
this.dataHora.setText(evento.getDataInicial().toString() + "\t" + evento.getHorario());
this.titulo.setText(evento.getNome());
}
if(evento.getImagemCapa() != null){
InputStream fileAsStream;
try {
file = serviceFileDAO.getContent(evento.getImagemCapa());
fileAsStream = new FileInputStream(file);
this.imagem.setImage(new Image(fileAsStream));
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (NullPointerException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
}

@FXML
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.FlowPane?>
<?import javafx.scene.layout.HBox?>
Expand All @@ -24,13 +25,26 @@
<children>
<VBox id="container" spacing="20.0" AnchorPane.bottomAnchor="10.0" AnchorPane.leftAnchor="30.0" AnchorPane.rightAnchor="30.0" AnchorPane.topAnchor="50.0">
<children>
<VBox>
<VBox maxHeight="-Infinity" maxWidth="-Infinity" VBox.vgrow="ALWAYS">
<children>
<Label text="Criar Evento" textFill="#352929">
<font>
<Font name="System Bold" size="20.0" />
</font>
</Label>
<HBox alignment="CENTER" maxHeight="1.7976931348623157E308" style="-fx-background-color: FFFEF7;">
<children>
<ImageView fx:id="capaEvento" fitHeight="200.0" fitWidth="898.0" pickOnBounds="true" preserveRatio="true" />
</children>
</HBox>
<VBox alignment="CENTER" prefHeight="51.0" prefWidth="1300.0" spacing="10.0">
<children>
<Button fx:id="buttonAlterarCapa" mnemonicParsing="false" onAction="#loadImagem" style="-fx-background-color: #2A3F25; -fx-text-fill: #FFFEF7;" text="Alterar imagem" textAlignment="CENTER" />
</children>
<VBox.margin>
<Insets bottom="10.0" top="10.0" />
</VBox.margin>
</VBox>
<VBox>
<children>
<VBox>
Expand Down
Loading
Loading