Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions commander/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>25</maven.compiler.source>
<maven.compiler.target>25</maven.compiler.target>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<javafx.version>21.0.6</javafx.version>
<junit.version>5.12.1</junit.version>
<maven.surefire.version>3.2.5</maven.surefire.version>
Expand Down Expand Up @@ -80,6 +80,7 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.version}</version>
<configuration>
<!--suppress UnresolvedMavenProperty -->
<groups>${groups:-}</groups>
<failIfNoTests>${failIfNoTests:-true}</failIfNoTests>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ public class CommanderApplication extends Application {
public void start(Stage stage) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(CommanderApplication.class.getResource("commander-ui.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 400, 400);
scene.getStylesheets().add(
CommanderApplication.class.getResource("commander.css").toExternalForm()
);


MainController ctrl = fxmlLoader.getController();
String home = System.getProperty("user.home");
if (ctrl != null && home != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package hse.java.commander.Examples;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.ListView;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import java.nio.file.*;
import java.util.List;

import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.stream.Collectors;

public class FillListViewWithFiles extends Application {

public List<String> listDir(Path dir) throws IOException {
try (var stream = Files.list(dir)) {
return stream
.map(p -> p.getFileName().toString())
.sorted()
.collect(Collectors.toList());
}
}

public void refreshList(ListView<String> listView, Path dir) throws IOException {
listView.getItems().clear();
listView.getItems().add("...");
listView.getItems().addAll(listDir(dir));
}

@Override
public void start(Stage primaryStage) {
ListView<String> listView = new ListView<>();
Path path = Paths.get("/Users/qwertz/Desktop/code/Java_codes/HSE/hse-java/commander/src/main/java/hse/java/commander/");

try {
refreshList(listView, path);
} catch (IOException e) {
e.printStackTrace(); // Обработка ошибки
}

VBox vbox = new VBox(listView);
Scene scene = new Scene(vbox, 400, 500);
primaryStage.setScene(scene);
primaryStage.setTitle("File List Viewer");
primaryStage.show();
}

public static void main(String[] args) {
launch(args); // Запускаем JavaFX приложение
}
}
56 changes: 56 additions & 0 deletions commander/src/main/java/hse/java/commander/Examples/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package hse.java.commander.Examples;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button; // Import Button
import javafx.scene.layout.VBox; // Import VBox
import javafx.scene.text.Text;
import javafx.stage.Stage;

import java.util.List;

public class Main extends Application {
Integer countTap = 0 ;

public static void main(String[] args) {
System.out.println("Launching Application");
Application.launch(args);
}

@Override
public void init() throws Exception {
System.out.println("Application inits");
super.init();
}

@Override
public void start(Stage stage) {
System.out.println("Application starts");

// Create button and set action
Button btn = new Button("Hello");

btn.setOnAction(event -> System.out.println("Button clicked!" + countTap++) );

// Use VBox for layout
VBox vbox = new VBox(10); // Vertical spacing of 10
vbox.getChildren().add(btn); // Add button to VBox

List<String> unnamedParams = getParameters().getUnnamed();
for (String param : unnamedParams) {
Text text = new Text(param);
vbox.getChildren().add(text); // Add text parameters to VBox
}

Scene scene = new Scene(vbox, 300, 250);
stage.setScene(scene);
stage.setTitle("JavaFX Application");
stage.show();
}

@Override
public void stop() throws Exception {
System.out.println("Application stops");
super.stop();
}
}
1 change: 1 addition & 0 deletions commander/src/main/java/hse/java/commander/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ public static void main(String[] args) {
Application.launch(CommanderApplication.class, args);
}
}

161 changes: 143 additions & 18 deletions commander/src/main/java/hse/java/commander/MainController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,169 @@

import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.layout.VBox;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.List;
import java.util.stream.Collectors;

public class MainController {

@FXML
public ListView<String> left;
private ListView<String> activeList;
private Path activeDir;

@FXML
public ListView<String> right;

@FXML
public Button move;
@FXML public ListView<String> left;
@FXML public ListView<String> right;
@FXML public Button move;
@FXML public Button copy;
@FXML public Button delete;

private Path leftDir;
private Path rightDir;

// for testing

@FXML public Label leftPathBar;
@FXML public Label rightPathBar;
@FXML public VBox leftPanel;
@FXML public VBox rightPanel;


public void setInitialDirs(Path leftStart, Path rightStart) {
this.leftDir = leftStart;
this.rightDir = rightStart;
refreshList(left, leftDir);
refreshList(right, rightDir);
}

public void initialize() {
move.setOnMouseClicked(event -> {

left.setOnMouseClicked(event -> {
activeList = left;
activeDir = leftDir;
leftPanel.getStyleClass().remove("panel-active");
leftPanel.getStyleClass().add("panel-active");
if (event.getClickCount() == 2) {
handleDoubleClick(left, leftDir, true);
}
});
System.out.println(System.getProperty("user.home"));
left.getItems().add("Kek");

left.setOnMouseClicked(event -> {
right.setOnMouseClicked(event -> {
activeList = right;
activeDir = rightDir;
rightPanel.getStyleClass().add("panel-active");
rightPanel.getStyleClass().remove("panel-active");
if (event.getClickCount() == 2) {
int index = left.getSelectionModel().getSelectedIndex();
if (index >= 0) {
left.getItems().set(index, "clicked");
}
handleDoubleClick(right, rightDir, false);
}
});

copy.setOnMouseClicked(event -> handleCopy());
move.setOnMouseClicked(event -> handleMove());
delete.setOnMouseClicked(event -> handleDelete());
}

private void handleDoubleClick(ListView<String> listView, Path currentDir, boolean isLeft) {
String selected = listView.getSelectionModel().getSelectedItem();
if (selected == null) return;

if (selected.equals("...")) {
Path parent = currentDir.getParent();
if (parent != null) {
if (isLeft) {
leftDir = parent;
activeDir = leftDir;
refreshList(left, leftDir);
} else {
rightDir = parent;
activeDir = rightDir;
refreshList(right, rightDir);
}
}
} else {
Path target = currentDir.resolve(selected);
if (Files.isDirectory(target)) {
if (isLeft) {
leftDir = target;
activeDir = leftDir;
refreshList(left, leftDir);
} else {
rightDir = target;
activeDir = rightDir;
refreshList(right, rightDir);
}
}
}
}

private void handleCopy() {
if (activeList == null || activeDir == null) return;
String selected = activeList.getSelectionModel().getSelectedItem();
if (selected == null || selected.equals("...")) return;

Path source = activeDir.resolve(selected);
Path targetDir = (activeList == left) ? rightDir : leftDir;
Path target = targetDir.resolve(selected);

try {
Files.copy(source, target, StandardCopyOption.REPLACE_EXISTING);
refreshList(left, leftDir);
refreshList(right, rightDir);
} catch (IOException e) {
e.printStackTrace();
}
}

private void handleMove() {
if (activeList == null || activeDir == null) return;
String selected = activeList.getSelectionModel().getSelectedItem();
if (selected == null || selected.equals("...")) return;

Path source = activeDir.resolve(selected);
Path targetDir = (activeList == left) ? rightDir : leftDir;
Path target = targetDir.resolve(selected);

try {
Files.move(source, target, StandardCopyOption.REPLACE_EXISTING);
refreshList(left, leftDir);
refreshList(right, rightDir);
} catch (IOException e) {
e.printStackTrace();
}
}

private void handleDelete() {
if (activeList == null || activeDir == null) return;
String selected = activeList.getSelectionModel().getSelectedItem();
if (selected == null || selected.equals("...")) return;

Path toDelete = activeDir.resolve(selected);
try {
Files.deleteIfExists(toDelete);
refreshList(left, leftDir);
refreshList(right, rightDir);
} catch (IOException e) {
e.printStackTrace();
}
}

private void refreshList(ListView<String> listView, Path dir) {
listView.getItems().clear();
listView.getItems().add("...");
try (var stream = Files.list(dir)) {
List<String> names = stream
.map(p -> p.getFileName().toString())
.sorted()
.collect(Collectors.toList());
listView.getItems().addAll(names);
} catch (IOException e) {
e.printStackTrace();
}

if (listView == left && leftPathBar != null) leftPathBar.setText(dir.toString());
if (listView == right && rightPathBar != null) rightPathBar.setText(dir.toString());
}
}
}
4 changes: 4 additions & 0 deletions commander/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
module hse.java.commander {
requires javafx.controls;
requires javafx.fxml;
requires java.xml;
requires java.desktop;

opens hse.java.commander to javafx.fxml;
exports hse.java.commander;
exports hse.java.commander.Examples;
opens hse.java.commander.Examples to javafx.fxml;
}
30 changes: 21 additions & 9 deletions commander/src/main/resources/hse/java/commander/commander-ui.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,26 @@
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="421.0" prefWidth="627.0" xmlns="http://javafx.com/javafx/17.0.12" xmlns:fx="http://javafx.com/fxml/1" fx:controller="hse.java.commander.MainController">
<HBox prefHeight="370.0" prefWidth="627.0">
<ListView fx:id="left" id="left" prefHeight="318.0" prefWidth="311.0" />
<ListView fx:id="right" id="right" prefHeight="318.0" prefWidth="321.0" />
<VBox styleClass="root-wrap"
xmlns="http://javafx.com/javafx/17.0.12"
xmlns:fx="http://javafx.com/fxml/1"
fx:controller="hse.java.commander.MainController">
<HBox styleClass="panels-box" VBox.vgrow="ALWAYS">
<VBox fx:id="leftPanel" styleClass="panel" HBox.hgrow="ALWAYS">
<Label styleClass="panel-header" text="left" maxWidth="Infinity"/>
<ListView fx:id="left" id="left" styleClass="file-list" VBox.vgrow="ALWAYS"/>
<Label fx:id="leftPathBar" styleClass="path-bar" text="/home/user" maxWidth="Infinity"/>
</VBox>
<VBox fx:id="rightPanel" styleClass="panel" HBox.hgrow="ALWAYS">
<Label styleClass="panel-header" text="right" maxWidth="Infinity"/>
<ListView fx:id="right" id="right" styleClass="file-list" VBox.vgrow="ALWAYS"/>
<Label fx:id="rightPathBar" styleClass="path-bar" text="/home/user" maxWidth="Infinity"/>
</VBox>
</HBox>
<HBox spacing="10.0">
<Button fx:id="copy" mnemonicParsing="false" text="Copy" />
<Button fx:id="move" mnemonicParsing="false" text="Move" />
<Button fx:id="delete" mnemonicParsing="false" text="Delete" />
<HBox styleClass="actions-box" spacing="8">
<Button fx:id="copy" styleClass="btn" text="Copy" HBox.hgrow="ALWAYS" maxWidth="Infinity"/>
<Button fx:id="move" styleClass="btn" text="Move" HBox.hgrow="ALWAYS" maxWidth="Infinity"/>
<Button fx:id="delete" styleClass="btn-danger" text="Delete" HBox.hgrow="ALWAYS" maxWidth="Infinity"/>
</HBox>
</VBox>
<Label fx:id="statusBar" styleClass="status-bar" text="выбери файл и действие" maxWidth="Infinity"/>
</VBox>
Loading
Loading