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 @@ -48,6 +51,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 @@ -61,6 +66,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 @@ -108,13 +114,16 @@ public class CadastrarEventoController implements ControllerServiceFile, Control
ObservableMap<Instituicao, FXMLLoader> colaboradorObservableMap = FXCollections.<Instituicao, FXMLLoader>observableHashMap();
@FXML
Button botaoNovaLocalizacao;
@FXML
ImageView capaEvento;
ObservableMap<Participante, FXMLLoader> participantes = FXCollections.<Participante, FXMLLoader>observableHashMap();
private Alert mensagem = new Alert(AlertType.NONE);
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 @@ -259,6 +268,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 @@ -752,4 +775,21 @@ public void removerLocalizacao(Localizacao localizacao) {

botaoNovaLocalizacao.setDisable(false);
}

public void loadImagem(){
InputStream fileAsStream;
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Alterar foto da instituição");
robsonad07 marked this conversation as resolved.
Show resolved Hide resolved
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,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 @@ -66,6 +69,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 @@ -74,6 +78,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 @@ -84,6 +89,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 @@ -130,8 +136,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 @@ -151,6 +160,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 @@ -244,6 +254,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 loadMetas() {
Expand Down Expand Up @@ -295,6 +320,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 @@ -791,4 +830,21 @@ public void onChanged(MapChangeListener.Change<? extends Instituicao, ? extends
}
});
}

public void loadImagem(){
InputStream fileAsStream;
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Alterar foto da instituição");
robsonad07 marked this conversation as resolved.
Show resolved Hide resolved
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,11 +60,26 @@ 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
public void verDetalhes(ActionEvent event) throws IOException, SQLException {
try {
System.out.println("Entre!!!!");
robsonad07 marked this conversation as resolved.
Show resolved Hide resolved
URL url = App.class.getResource("view/visualizarEvento.fxml");
FXMLLoader loaderVisualizacao = new FXMLLoader(url);
Parent objVisualizacao = loaderVisualizacao.load();
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>

<VBox id="pageVisualizarEvento" fx:id="root" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.casaculturaqxd.sgec.controller.VisualizarEventoController">
<VBox id="pageVisualizarEvento" fx:id="root" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" xmlns="http://javafx.com/javafx/20.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.casaculturaqxd.sgec.controller.VisualizarEventoController">
<children>
<ScrollPane fitToWidth="true" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308">
<content>
Expand All @@ -34,6 +34,11 @@
<ImageView fx:id="capaEvento" fitHeight="200.0" fitWidth="1000.0" pickOnBounds="true" preserveRatio="true" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox alignment="CENTER" prefHeight="50.0" prefWidth="1380.0">
<children>
<Button mnemonicParsing="false" onAction="#loadImagem" style="-fx-background-color: #2A3F25; -fx-text-fill: #FFFEF7;" text="Mudar Imagem" />
</children>
</HBox>
</children>
<VBox.margin>
<Insets bottom="10.0" top="10.0" />
Expand Down