Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
torakiki committed Jan 3, 2024
1 parent 90dc182 commit 59a5623
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 55 deletions.
Expand Up @@ -18,17 +18,21 @@
*/
package org.pdfsam.ui.components.selection.multiple;

import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.application.Platform;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.collections.ListChangeListener.Change;
import javafx.collections.ObservableList;
import javafx.css.PseudoClass;
import javafx.geometry.Orientation;
import javafx.geometry.Point2D;
import javafx.scene.Scene;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.Label;
import javafx.scene.control.MenuItem;
import javafx.scene.control.ScrollBar;
import javafx.scene.control.SelectionMode;
import javafx.scene.control.SeparatorMenuItem;
import javafx.scene.control.TableRow;
Expand All @@ -42,7 +46,9 @@
import javafx.scene.input.KeyCodeCombination;
import javafx.scene.input.KeyCombination;
import javafx.scene.input.TransferMode;
import javafx.scene.layout.Region;
import javafx.stage.Window;
import javafx.util.Duration;
import org.apache.commons.lang3.StringUtils;
import org.kordamp.ikonli.Ikon;
import org.kordamp.ikonli.javafx.FontIcon;
Expand Down Expand Up @@ -86,12 +92,6 @@

import static java.util.Optional.of;
import static java.util.Optional.ofNullable;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.geometry.Orientation;
import javafx.scene.control.ScrollBar;
import javafx.scene.layout.Region;
import javafx.util.Duration;
import static org.apache.commons.lang3.StringUtils.defaultString;
import static org.pdfsam.core.context.ApplicationContext.app;
import static org.pdfsam.core.support.EncryptionUtils.encrypt;
Expand All @@ -109,10 +109,10 @@
public class SelectionTable extends TableView<SelectionTableRowData> implements ToolBound, RestorableView {

private static final Logger LOG = LoggerFactory.getLogger(SelectionTable.class);
private static final PseudoClass DRAG_HOVERED_TOP_ROW_PSEUDO_CLASS = PseudoClass
.getPseudoClass("drag-hovered-row-top");
private static final PseudoClass DRAG_HOVERED_BOTTOM_ROW_PSEUDO_CLASS = PseudoClass
.getPseudoClass("drag-hovered-row-bottom");
private static final PseudoClass DRAG_HOVERED_TOP_ROW_PSEUDO_CLASS = PseudoClass.getPseudoClass(
"drag-hovered-row-top");
private static final PseudoClass DRAG_HOVERED_BOTTOM_ROW_PSEUDO_CLASS = PseudoClass.getPseudoClass(
"drag-hovered-row-bottom");
private static final DataFormat DND_TABLE_SELECTION_MIME_TYPE = new DataFormat(
"application/x-java-table-selection-list");

Expand Down Expand Up @@ -180,8 +180,8 @@ private void initTopSectionContextMenu(ContextMenu contextMenu, boolean hasRange
new SetPageRangesRequest(getSelectionModel().getSelectedItem().pageSelection.get()),
toolBinding()));
setPageRangesItem.setAccelerator(new KeyCodeCombination(KeyCode.R, KeyCombination.CONTROL_DOWN));
selectionChangedConsumer = selectionChangedConsumer
.andThen(e -> setPageRangesItem.setDisable(!e.isSingleSelection()));
selectionChangedConsumer = selectionChangedConsumer.andThen(
e -> setPageRangesItem.setDisable(!e.isSingleSelection()));
contextMenu.getItems().add(setPageRangesItem);
}
contextMenu.getItems().add(new SeparatorMenuItem());
Expand All @@ -193,23 +193,23 @@ private void initItemsSectionContextMenu(ContextMenu contextMenu, boolean canDup
removeSelected.setOnAction(e -> eventStudio().broadcast(new RemoveSelectedEvent(), toolBinding()));
removeSelected.setAccelerator(new KeyCodeCombination(KeyCode.DELETE));
contextMenu.getItems().add(removeSelected);
selectionChangedConsumer = selectionChangedConsumer
.andThen(e -> removeSelected.setDisable(e.isClearSelection()));
selectionChangedConsumer = selectionChangedConsumer.andThen(
e -> removeSelected.setDisable(e.isClearSelection()));
if (canMove) {
MenuItem moveTopSelected = createMenuItem(i18n().tr("Move to Top"), UniconsLine.ANGLE_DOUBLE_UP);
moveTopSelected
.setOnAction(e -> eventStudio().broadcast(new MoveSelectedEvent(MoveType.TOP), toolBinding()));
moveTopSelected.setOnAction(
e -> eventStudio().broadcast(new MoveSelectedEvent(MoveType.TOP), toolBinding()));

MenuItem moveUpSelected = createMenuItem(i18n().tr("Move Up"), UniconsLine.ANGLE_UP);
moveUpSelected.setOnAction(e -> eventStudio().broadcast(new MoveSelectedEvent(MoveType.UP), toolBinding()));

MenuItem moveDownSelected = createMenuItem(i18n().tr("Move Down"), UniconsLine.ANGLE_DOWN);
moveDownSelected
.setOnAction(e -> eventStudio().broadcast(new MoveSelectedEvent(MoveType.DOWN), toolBinding()));
moveDownSelected.setOnAction(
e -> eventStudio().broadcast(new MoveSelectedEvent(MoveType.DOWN), toolBinding()));

MenuItem moveBottomSelected = createMenuItem(i18n().tr("Move to Bottom"), UniconsLine.ANGLE_DOUBLE_DOWN);
moveBottomSelected
.setOnAction(e -> eventStudio().broadcast(new MoveSelectedEvent(MoveType.BOTTOM), toolBinding()));
moveBottomSelected.setOnAction(
e -> eventStudio().broadcast(new MoveSelectedEvent(MoveType.BOTTOM), toolBinding()));

contextMenu.getItems().addAll(moveTopSelected, moveUpSelected, moveDownSelected, moveBottomSelected);

Expand All @@ -232,8 +232,8 @@ private void initItemsSectionContextMenu(ContextMenu contextMenu, boolean canDup

contextMenu.getItems().add(duplicateItem);

selectionChangedConsumer = selectionChangedConsumer
.andThen(e -> duplicateItem.setDisable(e.isClearSelection()));
selectionChangedConsumer = selectionChangedConsumer.andThen(
e -> duplicateItem.setDisable(e.isClearSelection()));
}
}

Expand All @@ -249,8 +249,8 @@ private void initBottomSectionContextMenu(ContextMenu contextMenu) {
}));

MenuItem openFileItem = createMenuItem(i18n().tr("Open"), UniconsLine.FILE_ALT);
openFileItem.setOnAction(e -> eventStudio()
.broadcast(new NativeOpenFileRequest(getSelectionModel().getSelectedItem().descriptor().getFile())));
openFileItem.setOnAction(e -> eventStudio().broadcast(
new NativeOpenFileRequest(getSelectionModel().getSelectedItem().descriptor().getFile())));

MenuItem openFolderItem = createMenuItem(i18n().tr("Open Folder"), UniconsLine.FOLDER);
openFolderItem.setOnAction(e -> eventStudio().broadcast(new NativeOpenFileRequest(
Expand Down Expand Up @@ -326,17 +326,17 @@ private void initDragAndDrop(boolean canMove) {
}

if (e.getGestureSource() != row && e.getDragboard().hasContent(DND_TABLE_SELECTION_MIME_TYPE)) {
if (!((List<Integer>) e.getDragboard().getContent(DND_TABLE_SELECTION_MIME_TYPE))
.contains(rowIndex)) {
if (!((List<Integer>) e.getDragboard().getContent(DND_TABLE_SELECTION_MIME_TYPE)).contains(
rowIndex)) {
e.acceptTransferModes(TransferMode.MOVE);
e.consume();
}
}
});
row.setOnDragEntered(e -> {
if (!row.isEmpty() && e.getDragboard().hasContent(DND_TABLE_SELECTION_MIME_TYPE)) {
if (!((List<Integer>) e.getDragboard().getContent(DND_TABLE_SELECTION_MIME_TYPE))
.contains(row.getIndex())) {
if (!((List<Integer>) e.getDragboard().getContent(DND_TABLE_SELECTION_MIME_TYPE)).contains(
row.getIndex())) {
row.setOpacity(0.6);
}
}
Expand All @@ -345,8 +345,8 @@ private void initDragAndDrop(boolean canMove) {
clearHoverPseudoClasses(row);

if (!row.isEmpty() && e.getDragboard().hasContent(DND_TABLE_SELECTION_MIME_TYPE)) {
if (!((List<Integer>) e.getDragboard().getContent(DND_TABLE_SELECTION_MIME_TYPE))
.contains(row.getIndex())) {
if (!((List<Integer>) e.getDragboard().getContent(DND_TABLE_SELECTION_MIME_TYPE)).contains(
row.getIndex())) {
row.setOpacity(1);
}
}
Expand Down Expand Up @@ -523,10 +523,9 @@ public void showPasswordFieldPopup(ShowPasswordFieldPopupRequest request) {

private void copySelectedToClipboard() {
ClipboardContent content = new ClipboardContent();
writeContent(getSelectionModel()
.getSelectedItems().stream().map(item -> item.descriptor().getFile().getAbsolutePath() + ", "
+ item.descriptor().getFile().length() + ", " + item.descriptor().pages().getValue())
.collect(Collectors.toList())).to(content);
writeContent(getSelectionModel().getSelectedItems().stream()
.map(item -> item.descriptor().getFile().getAbsolutePath() + ", " + item.descriptor().getFile().length()
+ ", " + item.descriptor().pages().getValue()).collect(Collectors.toList())).to(content);
Clipboard.getSystemClipboard().setContent(content);
}

Expand Down
Expand Up @@ -29,14 +29,13 @@

import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;

class MockFileExplorer extends VBox {

MockFileExplorer(Path tempFolder) throws URISyntaxException, IOException {
MockFileExplorer(Path tempFolder) throws IOException {
var fileList = new ListView<File>();

fileList.setId("file-list");
Expand Down
Expand Up @@ -19,7 +19,9 @@
package org.pdfsam.ui.components.selection.multiple;

import javafx.application.Platform;
import javafx.beans.value.WritableIntegerValue;
import javafx.collections.FXCollections;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
Expand Down Expand Up @@ -61,16 +63,13 @@
import org.testfx.util.WaitForAsyncUtils;

import java.io.File;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import javafx.beans.value.WritableIntegerValue;
import javafx.scene.Node;

import static org.apache.commons.lang3.StringUtils.isBlank;
import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -112,8 +111,9 @@ public static void setUp() {

@Start
public void start(Stage stage) throws Exception {
victim = new SelectionTable(MODULE, true, true, new SelectionTableColumn<?>[] { new LoadingColumn(MODULE),
FileColumn.NAME, LongColumn.SIZE, IntColumn.PAGES, LongColumn.LAST_MODIFIED, new PageRangesColumn() });
victim = new SelectionTable(MODULE, true, true,
new SelectionTableColumn<?>[] { new LoadingColumn(MODULE), FileColumn.NAME, LongColumn.SIZE,
IntColumn.PAGES, LongColumn.LAST_MODIFIED, new PageRangesColumn() });
victim.setId("victim");
firstItem = populate();
Scene scene = new Scene(victim);
Expand Down Expand Up @@ -398,14 +398,8 @@ public void scrollsTableWhenEdgeReached() throws Exception {
}

WaitForAsyncUtils.waitForAsyncFx(2000, () -> eventStudio().broadcast(loadEvent, MODULE));

MockFileExplorer mockFileExplorer;

try {
mockFileExplorer = new MockFileExplorer(folder);
} catch (URISyntaxException ex) {
throw new RuntimeException(ex);
}
var mockFileExplorer = new MockFileExplorer(folder);

Platform.runLater(() -> {
var stage = new Stage();
Expand All @@ -429,7 +423,7 @@ public void scrollsTableWhenEdgeReached() throws Exception {
.filter(c -> Objects.nonNull(c.getItem())).findFirst().orElseThrow();

robot.drag(cell).dropTo("temp16.pdf");

WaitForAsyncUtils.waitForFxEvents();

verifyThat(robot.lookup("temp17.pdf").queryAs(Node.class), Node::isVisible);
Expand All @@ -438,13 +432,8 @@ public void scrollsTableWhenEdgeReached() throws Exception {
@Test
@Tag("NoHeadless")
public void dropsOnFirstIndex() throws Exception {
MockFileExplorer mockFileExplorer;

try {
mockFileExplorer = new MockFileExplorer(folder);
} catch (URISyntaxException ex) {
throw new RuntimeException(ex);
}
var mockFileExplorer = new MockFileExplorer(folder);

Platform.runLater(() -> {
var stage = new Stage();
Expand Down

0 comments on commit 59a5623

Please sign in to comment.