Skip to content

Commit

Permalink
Implemented DnD for lighttable module
Browse files Browse the repository at this point in the history
increased version
  • Loading branch information
cleme authored and cleme committed Oct 8, 2023
1 parent 5960359 commit d6b1ea5
Show file tree
Hide file tree
Showing 3 changed files with 261 additions and 3 deletions.
4 changes: 2 additions & 2 deletions PhotoSlide/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<groupId>org.photoslide</groupId>
<artifactId>PhotoSlide</artifactId>
<version>1.3.4-RELEASE</version>
<version>1.3.5-SNAPSHOT</version>

<!-- This description text is included in the Windows installer by default, see win-jpackage.txt -->
<description>Photoslide is an app for managing and editing photos like Lightroom/ON1/...</description>
Expand All @@ -17,7 +17,7 @@
<mainClass>org.photoslide.App</mainClass>
<app.name>Photoslide</app.name>
<maven.build.timestamp.format>yy.ww.WWkkmm</maven.build.timestamp.format>
<app.version>1.3.4</app.version>
<app.version>1.3.5</app.version>
<jvm.modules>java.base,jdk.management,java.naming,java.sql,java.transaction.xa,java.xml,jdk.unsupported,java.management,java.datatransfer,java.desktop,java.security.jgss,java.xml.crypto,jdk.javadoc,javafx.media,javafx.controls,javafx.fxml,javafx.graphics,javafx.base,javafx.swing,javafx.web,java.logging,jdk.charsets,java.se,java.net.http,java.prefs,jdk.crypto.ec,jdk.crypto.cryptoki,jdk.localedata,java.compiler,jdk.net,java.instrument,java.scripting,java.rmi</jvm.modules>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>21</maven.compiler.source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,32 @@ public void setSelectedPath(Path sPath) {
System.out.println("Drop Target dragged");
Dragboard db = t.getDragboard();
boolean success = false;
if (db.hasString()) {
if (db.hasFiles()) {
List<File> files = db.getFiles();
MediaLoadingTaskFiles taskMLoadingFiles = new MediaLoadingTaskFiles(files, fullMediaList, factory, sPath, mainController, mediaQTYLabel, sortOrderComboBox.getSelectionModel().getSelectedItem(), metadataController);
executorParallel.submit(taskMLoadingFiles);
taskMLoadingFiles.setOnFailed((tf) -> {
Logger.getLogger(LighttableController.class.getName()).log(Level.SEVERE, null, tf.getSource().getException());
mainController.getProgressbar().progressProperty().unbind();
mainController.getProgressbarLabel().textProperty().unbind();
mainController.getProgressPane().setVisible(false);
mainController.getStatusLabelLeft().setVisible(false);
});
taskMLoadingFiles.setOnSucceeded((tc) -> {
mainController.getStatusLabelLeft().setVisible(false);
mainController.getProgressPane().setVisible(false);
filteredMediaList.setPredicate(standardFilter().and(filterDeleted(showDeletedButton.isSelected())));
sortedMediaList.setComparator(new MediaFilenameComparator());
mainController.getProgressbar().progressProperty().unbind();
mainController.getProgressbarLabel().textProperty().unbind();
mainController.getStatusLabelRight().textProperty().unbind();
util.hideNodeAfterTime(mainController.getStatusLabelRight(), 2, true);
sortOrderComboBox.setDisable(false);
mainController.getStatusLabelRight().setText("Finished MediaLoading Task.");
util.hideNodeAfterTime(mainController.getStatusLabelRight(), 2, true);
mainController.getProgressPane().setVisible(false);
mainController.getStatusLabelLeft().setText("");
});
success = true;
}
t.setDropCompleted(success);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.photoslide.browserlighttable;

import java.io.File;
import org.photoslide.datamodel.MediaFileLoader;
import org.photoslide.MainViewController;
import org.photoslide.datamodel.FileTypes;
import org.photoslide.datamodel.MediaFile;
import org.photoslide.browsermetadata.MetadataController;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Stream;
import javafx.application.Platform;
import javafx.collections.ObservableList;
import javafx.concurrent.Task;
import javafx.scene.control.Label;
import org.photoslide.ThreadFactoryBuilder;
import org.photoslide.Utility;
import org.photoslide.browsercollections.FilenameComparator;

/**
*
* @author selfemp
*/
public class MediaLoadingTaskFiles extends Task<MediaFile> {

private final Path selectedPath;
private final Label mediaQTYLabel;
private final MainViewController mainController;
private final String sort;
private final MetadataController metadataController;
private final MediaGridCellFactory factory;
private final ObservableList<MediaFile> fullMediaList;
private final List<File> fileArray;
private final MediaFileLoader fileLoader;
private ExecutorService executorParallel;
private final int loadingLimit;

public MediaLoadingTaskFiles(List<File> fileArray, ObservableList<MediaFile> fullMediaList, MediaGridCellFactory factory, Path sPath, MainViewController mainControllerParam, Label mediaQTYLabelParam, String sortParm, MetadataController metaControllerParam) {
selectedPath = sPath;
this.fileArray = fileArray;
fileLoader = new MediaFileLoader();
mediaQTYLabel = mediaQTYLabelParam;
mainController = mainControllerParam;
sort = sortParm;
metadataController = metaControllerParam;
this.factory = factory;
this.fullMediaList = fullMediaList;
executorParallel = Executors.newCachedThreadPool(new ThreadFactoryBuilder().setNamePrefix("lightTableControllerSelectionMediaLoading").build());
if (Utility.nativeMemorySize > 4194500) {
loadingLimit = 75;
} else {
loadingLimit = 100;
}
}

@Override
protected MediaFile call() throws Exception {
final long qty;
List<MediaFile> content = new ArrayList<>();

updateTitle("Reading mediafiles...");
qty = fileArray.size();
if (qty == 0) {
Platform.runLater(() -> {
mediaQTYLabel.setText(qty + " media files.");
mainController.getProgressPane().setVisible(false);
mainController.getStatusLabelLeft().setVisible(false);
});
return null;
} else {
Platform.runLater(() -> {
mainController.getStatusLabelLeft().setVisible(true);
mainController.getProgressPane().setVisible(true);
mainController.getProgressbarLabel().setText(qty + " files found - Loading...");
mediaQTYLabel.setText(qty + " media files");
mainController.getStatusLabelRight().setVisible(true);
});
}
Logger.getLogger(LighttableController.class.getName()).log(Level.INFO, "Starting collecting..." + selectedPath);
long starttime = System.currentTimeMillis();

AtomicInteger iatom = new AtomicInteger(1);
String targetPath = fullMediaList.get(0).getPathStorage().getParent().toString();
fileArray.forEach((fileItem) -> {
if (this.isCancelled()) {
return;
}
if (this.isCancelled() == false) {
if (Files.isDirectory(fileItem.toPath()) == false) {
try {
boolean validFile = FileTypes.isValidType(fileItem.toString());
if (validFile == true) {
Path targetFile = Files.copy(fileItem.toPath(), Path.of(targetPath + File.separator + fileItem.toPath().getFileName()), StandardCopyOption.REPLACE_EXISTING);
if (FileTypes.isValidType(fileItem.toString())) {
MediaFile m = new MediaFile();
m.setName(targetFile.getFileName().toString());
m.setPathStorage(targetFile);
m.setMediaType(MediaFile.MediaTypes.IMAGE);
if (Utility.nativeMemorySize > 4194500) {
Thread.ofVirtual().start(() -> {
try {
loadItem(targetFile, m);
updateValue(m);
} catch (IOException ex) {
m.setMediaType(MediaFile.MediaTypes.NONE);
}
});
} else {
try {
loadItem(targetFile, m);
updateValue(m);
} catch (IOException ex) {
m.setMediaType(MediaFile.MediaTypes.NONE);
}
}
}
}
} catch (IOException ex) {
Logger.getLogger(MediaLoadingTaskFiles.class.getName()).log(Level.SEVERE, null, ex);
}
}
updateMessage(iatom.get() + " / " + qty);
iatom.addAndGet(1);
}
});
if (this.isCancelled()) {
return null;
}
long endtime = System.currentTimeMillis();
Logger.getLogger(LighttableController.class.getName()).log(Level.INFO, "Collect Time in s: " + (endtime - starttime) / 1000 + " " + selectedPath);

switch (sort) {
case "filename":
Comparator<MediaFile> comparing2 = Comparator.comparing((MediaFile t) -> {
return t.getName();
});
content.sort(comparing2);
break;
case "File creation time":
Comparator<MediaFile> comparing = Comparator.comparing((MediaFile t) -> {
try {
return t.getCreationTime();
} catch (IOException ex) {
Logger.getLogger(MediaLoadingTaskFiles.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
});
content.sort(comparing);
break;

}
return null;
}

public void loadItem(Path fileItem, MediaFile m) throws IOException {
if (this.isCancelled()) {
return;
}
//TODO: load in background or load during real media loading to speed up
m.readEdits();
if (this.isCancelled()) {
return;
}
m.getCreationTime();
if (this.isCancelled()) {
return;
}
if (mainController.isMediaFileBookmarked(m)) {
m.setBookmarked(true);
}
if (this.isCancelled()) {
return;
}
if (FileTypes.isValidVideo(fileItem.toString())) {
m.setMediaType(MediaFile.MediaTypes.VIDEO);
if (this.isCancelled()) {
return;
}
if (this.isCancelled()) {
return;
}
} else if (FileTypes.isValidImage(fileItem.toString())) {
m.setMediaType(MediaFile.MediaTypes.IMAGE);
if (sort.equalsIgnoreCase("Capture time")) {
try {
metadataController.readBasicMetadata(this, m);
} catch (IOException ex) {
Logger.getLogger(MediaLoadingTaskFiles.class.getName()).log(Level.SEVERE, null, ex);
}
}
if (this.isCancelled()) {
return;
}
if (this.isCancelled()) {
return;
}
} else {
m.setMediaType(MediaFile.MediaTypes.NONE);
}
}

@Override
protected void updateValue(MediaFile v) {
if (v != null) {
super.updateValue(v);
Platform.runLater(() -> {
fullMediaList.add(v);
});
}
}

@Override
protected void succeeded() {
super.succeeded();
executorParallel.shutdown();
}

}

0 comments on commit d6b1ea5

Please sign in to comment.