Skip to content

Commit

Permalink
Improve modifying of videos in video panel
Browse files Browse the repository at this point in the history
  • Loading branch information
berry120 committed Dec 25, 2023
1 parent 4a97d7f commit bcaafb8
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -52,7 +53,6 @@
public class LibraryVideoPanel extends BorderPane {

private final VideoListPanel videoPanel;
private final ToolBar toolbar;
private static final Logger LOGGER = LoggerUtils.getLogger();

/**
Expand All @@ -61,8 +61,7 @@ public class LibraryVideoPanel extends BorderPane {
public LibraryVideoPanel() {
videoPanel = new VideoListPanel(QueleaProperties.get().getVidDir().getAbsolutePath());
setCenter(videoPanel);
toolbar = new ToolBar();

ToolBar toolbar = new ToolBar();
Button addButton = new Button("", new ImageView(new Image("file:icons/add.png")));
addButton.setTooltip(new Tooltip(LabelGrabber.INSTANCE.getLabel("add.videos.panel")));
addButton.setOnAction((ActionEvent t) -> {
Expand All @@ -74,7 +73,7 @@ public LibraryVideoPanel() {
chooser.setInitialDirectory(QueleaProperties.get().getVidDir().getAbsoluteFile());
List<File> files = chooser.showOpenMultipleDialog(QueleaApp.get().getMainWindow());
if(files != null) {
final boolean[] refresh = new boolean[]{false};
List<Path> copiedPaths = new ArrayList<>();
for(final File f : files) {
QueleaProperties.get().setLastDirectory(f.getParentFile());
try {
Expand All @@ -85,8 +84,8 @@ public LibraryVideoPanel() {
.addLabelledButton(LabelGrabber.INSTANCE.getLabel("file.replace.button"), (ActionEvent t1) -> {
try {
Files.delete(Paths.get(videoPanel.getDir(), f.getName()));
Files.copy(sourceFile, Paths.get(videoPanel.getDir(), f.getName()), StandardCopyOption.COPY_ATTRIBUTES);
refresh[0] = true;
Path targetFile = Files.copy(sourceFile, Paths.get(videoPanel.getDir(), f.getName()), StandardCopyOption.COPY_ATTRIBUTES);
copiedPaths.add(targetFile);
}
catch(IOException e) {
LOGGER.log(Level.WARNING, "Could not delete or copy file back into directory.", e);
Expand All @@ -97,16 +96,17 @@ public LibraryVideoPanel() {
d.showAndWait();
}
else {
Files.copy(sourceFile, Paths.get(videoPanel.getDir(), f.getName()), StandardCopyOption.COPY_ATTRIBUTES);
refresh[0] = true;
Path targetFile = Files.copy(sourceFile, Paths.get(videoPanel.getDir(), f.getName()), StandardCopyOption.COPY_ATTRIBUTES);
LOGGER.log(Level.INFO, "Copied file to " + targetFile);
copiedPaths.add(targetFile);
}
}
catch(IOException ex) {
LOGGER.log(Level.WARNING, "Could not copy file into VideoPanel from FileChooser selection", ex);
}
}
if(refresh[0]) {
videoPanel.refresh();
for(Path path : copiedPaths) {
videoPanel.addVideoFile(path.toFile());
}
}
});
Expand All @@ -117,13 +117,4 @@ public LibraryVideoPanel() {
toolbar.getItems().add(addButton);
setLeft(toolbarBox);
}

/**
* Get the video list panel.
* <p/>
* @return the video list panel.
*/
public VideoListPanel getVideoPanel() {
return videoPanel;
}
}
101 changes: 54 additions & 47 deletions Quelea/src/main/java/org/quelea/windows/library/VideoListPanel.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/*
/*
* This file is part of Quelea, free projection software for churches.
*
*
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
Expand Down Expand Up @@ -50,6 +50,7 @@
/**
* The panel displayed on the library to select the list of videos..
* <p/>
*
* @author Ben
*/
public class VideoListPanel extends BorderPane {
Expand All @@ -58,14 +59,15 @@ public class VideoListPanel extends BorderPane {
private static final String BORDER_STYLE_SELECTED = "-fx-padding: 0.2em;-fx-border-color: #0093ff;-fx-border-radius: 5;-fx-border-width: 0.1em;";
private static final String BORDER_STYLE_DESELECTED = "-fx-padding: 0.2em;-fx-border-color: rgb(0,0,0,0);-fx-border-radius: 5;-fx-border-width: 0.1em;";
private final TilePane videoList;
private String dir;
private final String dir;
private Thread updateThread;
private final VidPreviewDisplay vidPreviewDisplay;
public static final Image BLANK = new Image("file:icons/vid preview.png");

/**
* Create a new video list panel.
* <p/>
*
* @param dir the directory to use.
*/
public VideoListPanel(String dir) {
Expand Down Expand Up @@ -133,55 +135,60 @@ private void updateVideos() {
File file = files[i];
LOGGER.log(Level.INFO, "Checking file {0}", file);
if (Utils.fileIsVideo(file) && !file.isDirectory()) {
final ImageView view = new ImageView();
final Label fileLabel = new Label(trim17(file.getName()));
addVideoFile(file);
}
}
});
updateThread.start();
}

view.setImage(vidPreviewDisplay.getPreviewImg(file.toURI()));
public void addVideoFile(File file) {
LOGGER.log(Level.INFO, "Adding video file {0} to panel", file);
final ImageView view = new ImageView();
final Label fileLabel = new Label(trim17(file.getName()));

Platform.runLater(() -> {
final VBox viewBox = new VBox();
viewBox.setAlignment(Pos.CENTER);
view.setPreserveRatio(true);
view.setFitWidth(160);
view.setFitHeight(90);
view.setOnMouseClicked((MouseEvent t) -> {
if (t.getButton() == MouseButton.PRIMARY && t.getClickCount() > 1) {
QueleaApp.get().getMainWindow().getMainPanel().getSchedulePanel().getScheduleList().add(new VideoDisplayable(file.getAbsolutePath()));
} else if (t.getButton() == MouseButton.SECONDARY) {
ContextMenu removeMenu = new ContextMenu();
MenuItem removeItem = new MenuItem(LabelGrabber.INSTANCE.getLabel("remove.video.text"));
removeItem.setOnAction((ActionEvent t1) -> {
final boolean[] reallyDelete = new boolean[]{false};
Dialog.buildConfirmation(LabelGrabber.INSTANCE.getLabel("delete.video.title"),
LabelGrabber.INSTANCE.getLabel("delete.video.confirmation")).addYesButton((ActionEvent t2) -> {
reallyDelete[0] = true;
}).addNoButton((ActionEvent t3) -> {
}).build().showAndWait();
if (reallyDelete[0]) {
file.delete();
videoList.getChildren().remove(viewBox);
}
});
removeMenu.getItems().add(removeItem);
removeMenu.show(view, t.getScreenX(), t.getScreenY());
}
});
view.setImage(vidPreviewDisplay.getPreviewImg(file.toURI()));

Platform.runLater(() -> {
final VBox viewBox = new VBox();
viewBox.setAlignment(Pos.CENTER);
view.setPreserveRatio(true);
view.setFitWidth(160);
view.setFitHeight(90);
view.setOnMouseClicked((MouseEvent t) -> {
if (t.getButton() == MouseButton.PRIMARY && t.getClickCount() > 1) {
QueleaApp.get().getMainWindow().getMainPanel().getSchedulePanel().getScheduleList().add(new VideoDisplayable(file.getAbsolutePath()));
} else if (t.getButton() == MouseButton.SECONDARY) {
ContextMenu removeMenu = new ContextMenu();
MenuItem removeItem = new MenuItem(LabelGrabber.INSTANCE.getLabel("remove.video.text"));
removeItem.setOnAction((ActionEvent t1) -> {
final boolean[] reallyDelete = new boolean[]{false};
Dialog.buildConfirmation(LabelGrabber.INSTANCE.getLabel("delete.video.title"),
LabelGrabber.INSTANCE.getLabel("delete.video.confirmation")).addYesButton((ActionEvent t2) -> {
reallyDelete[0] = true;
}).addNoButton((ActionEvent t3) -> {
}).build().showAndWait();
if (reallyDelete[0]) {
file.delete();
videoList.getChildren().remove(viewBox);
}
});
removeMenu.getItems().add(removeItem);
removeMenu.show(view, t.getScreenX(), t.getScreenY());
}
});
// view.setOnDragDetected((MouseEvent t) -> {
// Dragboard db = startDragAndDrop(TransferMode.ANY);
// ClipboardContent content = new ClipboardContent();
// content.putString(file.getAbsolutePath());
// db.setContent(content);
// t.consume();
// });
viewBox.getChildren().add(view);
viewBox.getChildren().add(fileLabel);
setupHover(viewBox, file.getName());
videoList.getChildren().add(viewBox);
});
}
}
viewBox.getChildren().add(view);
viewBox.getChildren().add(fileLabel);
setupHover(viewBox, file.getName());
videoList.getChildren().add(viewBox);
});
updateThread.start();
}

private void setupHover(final Node view, String fileName) {
Expand All @@ -199,8 +206,8 @@ private void setupHover(final Node view, String fileName) {
}

private static String trim17(String toTrim) {
if(toTrim.length()>17) {
return toTrim.substring(0,16) + "..";
if (toTrim.length() > 17) {
return toTrim.substring(0, 16) + "..";
}
return toTrim;
}
Expand Down

0 comments on commit bcaafb8

Please sign in to comment.