|
@@ -1,14 +1,16 @@
|
|
|
package com.usoftchina.smartschool.device.client.biometric.controller;
|
|
package com.usoftchina.smartschool.device.client.biometric.controller;
|
|
|
|
|
|
|
|
-import com.github.sarxos.webcam.Webcam;
|
|
|
|
|
import com.usoftchina.smartschool.device.client.biometric.DeviceClient;
|
|
import com.usoftchina.smartschool.device.client.biometric.DeviceClient;
|
|
|
import com.usoftchina.smartschool.device.client.biometric.control.ParameterizedScene;
|
|
import com.usoftchina.smartschool.device.client.biometric.control.ParameterizedScene;
|
|
|
-import com.usoftchina.smartschool.device.client.biometric.control.VideoPanel;
|
|
|
|
|
import com.usoftchina.smartschool.device.client.biometric.po.Person;
|
|
import com.usoftchina.smartschool.device.client.biometric.po.Person;
|
|
|
import com.usoftchina.smartschool.device.client.biometric.po.SexType;
|
|
import com.usoftchina.smartschool.device.client.biometric.po.SexType;
|
|
|
|
|
+import com.usoftchina.smartschool.device.client.biometric.service.FileService;
|
|
|
import com.usoftchina.smartschool.device.client.biometric.service.PersonService;
|
|
import com.usoftchina.smartschool.device.client.biometric.service.PersonService;
|
|
|
import com.usoftchina.smartschool.device.client.biometric.util.AlertUtils;
|
|
import com.usoftchina.smartschool.device.client.biometric.util.AlertUtils;
|
|
|
|
|
+import com.usoftchina.smartschool.device.client.biometric.util.ViewUtils;
|
|
|
import com.usoftchina.smartschool.device.context.SpringContextHolder;
|
|
import com.usoftchina.smartschool.device.context.SpringContextHolder;
|
|
|
|
|
+import javafx.beans.property.ObjectProperty;
|
|
|
|
|
+import javafx.beans.property.SimpleObjectProperty;
|
|
|
import javafx.beans.value.ChangeListener;
|
|
import javafx.beans.value.ChangeListener;
|
|
|
import javafx.beans.value.ObservableValue;
|
|
import javafx.beans.value.ObservableValue;
|
|
|
import javafx.collections.FXCollections;
|
|
import javafx.collections.FXCollections;
|
|
@@ -22,15 +24,14 @@ import javafx.scene.control.ComboBox;
|
|
|
import javafx.scene.control.TextField;
|
|
import javafx.scene.control.TextField;
|
|
|
import javafx.scene.image.Image;
|
|
import javafx.scene.image.Image;
|
|
|
import javafx.scene.image.ImageView;
|
|
import javafx.scene.image.ImageView;
|
|
|
-import javafx.scene.layout.StackPane;
|
|
|
|
|
import javafx.stage.FileChooser;
|
|
import javafx.stage.FileChooser;
|
|
|
import javafx.stage.Stage;
|
|
import javafx.stage.Stage;
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.util.StringUtils;
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
|
|
-import javax.imageio.ImageIO;
|
|
|
|
|
import java.io.File;
|
|
import java.io.File;
|
|
|
|
|
+import java.io.IOException;
|
|
|
import java.net.URL;
|
|
import java.net.URL;
|
|
|
import java.util.ResourceBundle;
|
|
import java.util.ResourceBundle;
|
|
|
|
|
|
|
@@ -55,11 +56,17 @@ public class PersonEditController implements Initializable {
|
|
|
|
|
|
|
|
private PersonService personService;
|
|
private PersonService personService;
|
|
|
|
|
|
|
|
|
|
+ private FileService fileService;
|
|
|
|
|
+
|
|
|
private Person person;
|
|
private Person person;
|
|
|
|
|
|
|
|
private FileChooser fileChooser;
|
|
private FileChooser fileChooser;
|
|
|
|
|
|
|
|
- private File imageFile;
|
|
|
|
|
|
|
+ private File lastSelectedImage;
|
|
|
|
|
+
|
|
|
|
|
+ private File lastSnapshot;
|
|
|
|
|
+
|
|
|
|
|
+ private File unsavedImage;
|
|
|
|
|
|
|
|
private ObservableList<SexType> sexOptions =
|
|
private ObservableList<SexType> sexOptions =
|
|
|
FXCollections.observableArrayList(
|
|
FXCollections.observableArrayList(
|
|
@@ -70,6 +77,7 @@ public class PersonEditController implements Initializable {
|
|
|
@Override
|
|
@Override
|
|
|
public void initialize(URL location, ResourceBundle resources) {
|
|
public void initialize(URL location, ResourceBundle resources) {
|
|
|
personService = SpringContextHolder.getContext().getBean(PersonService.class);
|
|
personService = SpringContextHolder.getContext().getBean(PersonService.class);
|
|
|
|
|
+ fileService = SpringContextHolder.getContext().getBean(FileService.class);
|
|
|
|
|
|
|
|
nameField.sceneProperty().addListener(new ChangeListener<Scene>() {
|
|
nameField.sceneProperty().addListener(new ChangeListener<Scene>() {
|
|
|
@Override
|
|
@Override
|
|
@@ -104,6 +112,17 @@ public class PersonEditController implements Initializable {
|
|
|
if (null == person.getSex()) {
|
|
if (null == person.getSex()) {
|
|
|
sexBox.getSelectionModel().selectFirst();
|
|
sexBox.getSelectionModel().selectFirst();
|
|
|
}
|
|
}
|
|
|
|
|
+ lastSnapshot = null;
|
|
|
|
|
+ lastSelectedImage = null;
|
|
|
|
|
+ unsavedImage = null;
|
|
|
|
|
+ if (null != person.getFaceImage()) {
|
|
|
|
|
+ File imageFile = fileService.getById(person.getFaceImage());
|
|
|
|
|
+ if (imageFile.exists()) {
|
|
|
|
|
+ imageView.imageProperty().setValue(new Image(imageFile.toURI().toString()));
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ imageView.imageProperty().setValue(null);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void save() {
|
|
private void save() {
|
|
@@ -115,6 +134,19 @@ public class PersonEditController implements Initializable {
|
|
|
AlertUtils.warn("请填写卡号").ifPresent(b -> cardNoField.requestFocus());
|
|
AlertUtils.warn("请填写卡号").ifPresent(b -> cardNoField.requestFocus());
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
+ if (null != unsavedImage) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ person.setFaceImage(fileService.save(unsavedImage));
|
|
|
|
|
+ // 清除临时文件
|
|
|
|
|
+ if (null != lastSnapshot) {
|
|
|
|
|
+ lastSnapshot.delete();
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ logger.error("Save image error", e);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if (null == imageView.getImage()){
|
|
|
|
|
+ person.setFaceImage(null);
|
|
|
|
|
+ }
|
|
|
personService.save(person);
|
|
personService.save(person);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -141,25 +173,43 @@ public class PersonEditController implements Initializable {
|
|
|
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("图片文件", "*.png", "*.jpg", "*.bmp", "*.gif"));
|
|
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("图片文件", "*.png", "*.jpg", "*.bmp", "*.gif"));
|
|
|
}
|
|
}
|
|
|
// 打开上次文件夹
|
|
// 打开上次文件夹
|
|
|
- if (null != imageFile) {
|
|
|
|
|
- fileChooser.setInitialDirectory(imageFile.getParentFile());
|
|
|
|
|
|
|
+ if (null != lastSelectedImage) {
|
|
|
|
|
+ fileChooser.setInitialDirectory(lastSelectedImage.getParentFile());
|
|
|
}
|
|
}
|
|
|
- imageFile = fileChooser.showOpenDialog(nameField.getScene().getWindow());
|
|
|
|
|
- if (null != imageFile) {
|
|
|
|
|
- imageView.setImage(new Image(imageFile.toURI().toString()));
|
|
|
|
|
|
|
+ lastSelectedImage = fileChooser.showOpenDialog(nameField.getScene().getWindow());
|
|
|
|
|
+ if (null != lastSelectedImage) {
|
|
|
|
|
+ unsavedImage = lastSelectedImage;
|
|
|
|
|
+ imageView.imageProperty().setValue(new Image(unsavedImage.toURI().toString()));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@FXML
|
|
@FXML
|
|
|
- public void handleOpenVideo(ActionEvent event) {
|
|
|
|
|
- VideoPanel videoPanel = new VideoPanel();
|
|
|
|
|
- StackPane stackPane = new StackPane();
|
|
|
|
|
- stackPane.getChildren().add(videoPanel.getVideoPanel());
|
|
|
|
|
- Stage stage = new Stage();
|
|
|
|
|
- stage.setScene(new Scene(stackPane, 800, 600));
|
|
|
|
|
- stage.setResizable(false);
|
|
|
|
|
- stage.setTitle("人脸采集");
|
|
|
|
|
- stage.getIcons().addAll(DeviceClient.defaultIcons);
|
|
|
|
|
- stage.show();
|
|
|
|
|
|
|
+ public void handleOpenCamera(ActionEvent event) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ ObjectProperty<File> fileObjectProperty = new SimpleObjectProperty<>();
|
|
|
|
|
+ Scene scene = ViewUtils.load("/view/camera.fxml", fileObjectProperty);
|
|
|
|
|
+ Stage stage = new Stage();
|
|
|
|
|
+ stage.setScene(scene);
|
|
|
|
|
+ stage.setResizable(false);
|
|
|
|
|
+ stage.setTitle("人脸采集");
|
|
|
|
|
+ stage.getIcons().addAll(DeviceClient.defaultIcons);
|
|
|
|
|
+ stage.centerOnScreen();
|
|
|
|
|
+ stage.show();
|
|
|
|
|
+ fileObjectProperty.addListener(new ChangeListener<File>() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void changed(ObservableValue<? extends File> observable, File oldValue, File newValue) {
|
|
|
|
|
+ if (null != lastSnapshot) {
|
|
|
|
|
+ lastSnapshot.delete();
|
|
|
|
|
+ }
|
|
|
|
|
+ lastSnapshot = newValue;
|
|
|
|
|
+ if (null != lastSnapshot) {
|
|
|
|
|
+ unsavedImage = lastSnapshot;
|
|
|
|
|
+ imageView.imageProperty().setValue(new Image(unsavedImage.toURI().toString()));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ logger.error("Camera error", e);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|