first commit
This commit is contained in:
91
src/main/java/id/co/gtc/erhacam/PhotoRow.java
Normal file
91
src/main/java/id/co/gtc/erhacam/PhotoRow.java
Normal file
@@ -0,0 +1,91 @@
|
||||
package id.co.gtc.erhacam;
|
||||
|
||||
import Config.SomeCodes;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Alert;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.layout.HBox;
|
||||
import org.bytedeco.opencv.global.opencv_imgcodecs;
|
||||
import org.bytedeco.opencv.opencv_core.Mat;
|
||||
import org.tinylog.Logger;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static Config.SomeCodes.config;
|
||||
|
||||
public class PhotoRow {
|
||||
@FXML
|
||||
private Label datetime;
|
||||
@FXML
|
||||
private Label prefix;
|
||||
@FXML
|
||||
private HBox photos;
|
||||
|
||||
private final String borderstyle = "-fx-border-color: black; -fx-border-width: 1px;";
|
||||
|
||||
public void setDatetime(String datetime){
|
||||
this.datetime.setText(datetime);
|
||||
this.datetime.setStyle(borderstyle);
|
||||
}
|
||||
|
||||
public void setPrefix(String prefix){
|
||||
this.prefix.setText(prefix);
|
||||
this.prefix.setStyle(borderstyle);
|
||||
}
|
||||
|
||||
public void setPhotos(int width, int height, String... thumbnails){
|
||||
photos.setSpacing(10);
|
||||
for(String photopath : thumbnails){
|
||||
ImageView imgview = createImageView(loadImage(photopath), width, height);
|
||||
if (imgview!=null){
|
||||
photos.getChildren().add(imgview);
|
||||
//HBox.setMargin(imgview, new Insets(5, 5, 5, 5));
|
||||
imgview.setStyle(borderstyle);
|
||||
imgview.setOnMouseClicked(e->{
|
||||
if (e.getClickCount()>=2){
|
||||
File ff = new File(photopath);
|
||||
String hires = Path.of(config.getPhotoDirectory(), ff.getName()).toString();
|
||||
File hiresfile = new File(hires);
|
||||
if (hiresfile.isFile()){
|
||||
SomeCodes.OpenPictureInDefaultViewer(hires);
|
||||
} else {
|
||||
Alert alert = new Alert(Alert.AlertType.ERROR);
|
||||
alert.setTitle("Error");
|
||||
alert.setHeaderText("File not found");
|
||||
alert.setContentText("File not found: "+hires);
|
||||
alert.showAndWait();
|
||||
}
|
||||
e.consume();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ImageView createImageView(Image img, int width, int height){
|
||||
if (img!=null){
|
||||
ImageView imgview = new ImageView(img);
|
||||
imgview.prefWidth(width);
|
||||
imgview.prefHeight(height);
|
||||
imgview.setFitHeight(height);
|
||||
imgview.setFitWidth(width);
|
||||
imgview.setPreserveRatio(true);
|
||||
return imgview;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Image loadImage(String photopath){
|
||||
try{
|
||||
Mat mat = opencv_imgcodecs.imread(photopath);
|
||||
return SomeCodes.ConvertToImage(mat, 640,480);
|
||||
} catch (Exception e){
|
||||
Logger.error("Error loading image: " + photopath + ", Msg : " + e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user