Skip to content

Commit 05b9574

Browse files
committed
made frontend of CollectionsWindow and started backend
1 parent 7a5bce4 commit 05b9574

24 files changed

+692
-120
lines changed

lab8/client/src/Client/Client.java renamed to lab8/client/src/client/Client.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package Client;
1+
package client;
22

33
public class Client {
44
private final String name;
+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
package client;
2+
3+
public class DataHolder {
4+
private static DataHolder instance;
5+
6+
private String name;
7+
private String coordX;
8+
private String coordY;
9+
private String area;
10+
private String population;
11+
private String metersAboveSeaLevel;
12+
private String climate;
13+
private String government;
14+
private String standards;
15+
private String governor;
16+
private DataHolder() {}
17+
18+
public static DataHolder getInstance() {
19+
if (instance == null) {
20+
instance = new DataHolder();
21+
}
22+
return instance;
23+
}
24+
25+
public String getName() {
26+
return name;
27+
}
28+
29+
public void setName(String name) {
30+
this.name = name;
31+
}
32+
33+
public String getCoordX() {
34+
return coordX;
35+
}
36+
37+
public void setCoordX(String coordX) {
38+
this.coordX = coordX;
39+
}
40+
41+
public String getCoordY() {
42+
return coordY;
43+
}
44+
45+
public void setCoordY(String coordY) {
46+
this.coordY = coordY;
47+
}
48+
49+
public String getArea() {
50+
return area;
51+
}
52+
53+
public void setArea(String area) {
54+
this.area = area;
55+
}
56+
57+
public String getPopulation() {
58+
return population;
59+
}
60+
61+
public void setPopulation(String population) {
62+
this.population = population;
63+
}
64+
65+
public String getMetersAboveSeaLevel() {
66+
return metersAboveSeaLevel;
67+
}
68+
69+
public void setMetersAboveSeaLevel(String metersAboveSeaLevel) {
70+
this.metersAboveSeaLevel = metersAboveSeaLevel;
71+
}
72+
73+
public String getClimate() {
74+
return climate;
75+
}
76+
77+
public void setClimate(String climate) {
78+
this.climate = climate;
79+
}
80+
81+
public String getGovernment() {
82+
return government;
83+
}
84+
85+
public void setGovernment(String government) {
86+
this.government = government;
87+
}
88+
89+
public String getStandards() {
90+
return standards;
91+
}
92+
93+
public void setStandards(String standards) {
94+
this.standards = standards;
95+
}
96+
97+
public String getGovernor() {
98+
return governor;
99+
}
100+
101+
public void setGovernor(String governor) {
102+
this.governor = governor;
103+
}
104+
}
105+

lab8/client/src/commandManager/CommandExecutor.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package commandManager;
22

3-
import Client.Client;
3+
import client.Client;
44
import commandLogic.CommandDescription;
55
import commandLogic.commandReceiverLogic.ReceiverManager;
66
import commandLogic.commandReceiverLogic.enums.ReceiverType;
@@ -66,6 +66,10 @@ public CommandExecutor(ArrayList<CommandDescription> commands, InputStream input
6666
manager.registerReceiver(ReceiverType.ArgumentRoute, new ArgumentCityCommandReceiver(modeManager));
6767
}
6868

69+
70+
public void executeCommand() {
71+
72+
}
6973
/**
7074
* Start executing commands from InputStream.
7175
*/

lab8/client/src/commandManager/CommandMode.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,9 @@ public enum CommandMode {
1414
/**
1515
* Commands will use simple interaction w/o user-orientation. Envisage that it will be used with file streams, e.t.c.
1616
*/
17-
NonUserMode
17+
NonUserMode,
18+
/**
19+
* Commands will use gui-friendly interaction.
20+
*/
21+
GUIMode
1822
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package commandManager;
2+
3+
import client.Client;
4+
import commandLogic.CommandDescription;
5+
import commandLogic.commandReceiverLogic.ReceiverManager;
6+
import commandLogic.commandReceiverLogic.enums.ReceiverType;
7+
import commandLogic.commandReceiverLogic.handlers.ArgumentReceiverHandler;
8+
import commandLogic.commandReceiverLogic.handlers.NonArgReceiversHandler;
9+
import commandManager.externalRecievers.ArgumentCityCommandReceiver;
10+
import commandManager.externalRecievers.ExecuteScriptReceiver;
11+
import commandManager.externalRecievers.ExitReceiver;
12+
import commandManager.externalRecievers.NonArgumentReceiver;
13+
import exceptions.*;
14+
import models.City;
15+
import models.handlers.ModeManager;
16+
import models.handlers.guiMode.GUIManager;
17+
18+
import java.util.ArrayList;
19+
import java.util.Optional;
20+
21+
import static commandManager.CommandMode.CLI_UserMode;
22+
23+
public class SingleCommandExecutor {
24+
25+
private final ArrayList<CommandDescription> commands;
26+
private final ReceiverManager manager;
27+
private final CommandMode mode;
28+
29+
/**
30+
* Constructor :/
31+
*
32+
* @param commands array of commands
33+
*/
34+
public SingleCommandExecutor(ArrayList<CommandDescription> commands, CommandMode mode) throws CommandsNotLoadedException {
35+
if (commands == null) throw new CommandsNotLoadedException();
36+
37+
this.commands = commands;
38+
this.mode = mode;
39+
manager = new ReceiverManager();
40+
41+
manager.registerHandler(ReceiverType.NoArgs, new NonArgReceiversHandler());
42+
manager.registerHandler(ReceiverType.ArgumentRoute, new ArgumentReceiverHandler<>(City.class));
43+
44+
manager.registerReceiver(ReceiverType.NoArgs, new NonArgumentReceiver());
45+
manager.registerReceiver(ReceiverType.NoArgs, new ExecuteScriptReceiver());
46+
manager.registerReceiver(ReceiverType.NoArgs, new ExitReceiver());
47+
48+
ModeManager<City> modeManager = new GUIManager();
49+
manager.registerReceiver(ReceiverType.ArgumentRoute, new ArgumentCityCommandReceiver(modeManager));
50+
}
51+
52+
public void executeCommand(String line) {
53+
try {
54+
try {
55+
Client client = Client.getInstance();
56+
String[] lineArgs = line.split(" ");
57+
CommandDescription description = Optional.ofNullable(commands).orElseThrow(CommandsNotLoadedException::new).stream().filter(x -> x.getName().equals(lineArgs[0])).findAny().orElseThrow(() -> new UnknownCommandException("Указанная команда не была обнаружена"));
58+
description.getReceiver().callReceivers(client.getName(), client.getPasswd(), manager, description, lineArgs);
59+
} catch (IllegalArgumentException | NullPointerException e) {
60+
// "Выполнение команды пропущено из-за неправильных предоставленных аргументов! (" + e.getMessage() + ")");
61+
throw new CommandInterruptedException(e);
62+
} catch (BuildObjectException | UnknownCommandException e) {
63+
// e.getMessage();
64+
throw new CommandInterruptedException(e);
65+
} catch (WrongAmountOfArgumentsException e) {
66+
// "Wrong amount of arguments! " + e.getMessage());
67+
throw new CommandInterruptedException(e);
68+
} catch (Exception e) {
69+
// "В командном менеджере произошла непредвиденная ошибка! " + e.getMessage());
70+
throw new CommandInterruptedException(e);
71+
}
72+
} catch (CommandInterruptedException ex) {
73+
if (mode.equals(CLI_UserMode)) {
74+
// "Выполнение команды было прервано. Вы можете продолжать работу. Программа возвращена в безопасное состояние.");
75+
} else {
76+
// "Команда была пропущена... Обработчик продолжает работу");
77+
}
78+
}
79+
}
80+
}

lab8/client/src/gui/CreateCityWindow.java

-4
This file was deleted.

lab8/client/src/gui/Main.java

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package gui;
22

3+
import commandManager.CommandLoaderUtility;
34
import gui.login.LoginWindow;
45
import javafx.application.Application;
56
import javafx.stage.Stage;

lab8/client/src/gui/collections/CollectionsWindow.java

+15-69
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,30 @@
11
package gui.collections;
22

3-
import Client.Client;
4-
import javafx.collections.FXCollections;
5-
import javafx.collections.ObservableList;
6-
import javafx.geometry.Insets;
7-
import javafx.geometry.Pos;
3+
import javafx.fxml.FXMLLoader;
4+
import javafx.scene.Parent;
85
import javafx.scene.Scene;
9-
import javafx.scene.control.Button;
10-
import javafx.scene.control.Label;
11-
import javafx.scene.control.TableColumn;
12-
import javafx.scene.control.TableView;
13-
import javafx.scene.control.cell.PropertyValueFactory;
14-
import javafx.scene.layout.VBox;
15-
import javafx.scene.text.Font;
16-
import javafx.scene.text.FontWeight;
17-
import javafx.scene.text.Text;
186
import javafx.stage.Stage;
19-
import javafx.scene.paint.Color;
7+
8+
import java.io.IOException;
9+
import java.net.URL;
2010

2111
public class CollectionsWindow {
2212

2313
private Stage stage;
2414
private Scene scene;
2515

2616
public CollectionsWindow() {
27-
stage = new Stage();
28-
VBox root = new VBox();
29-
root.setAlignment(Pos.CENTER);
30-
root.setSpacing(20);
31-
32-
// Username
33-
Text usernameText = new Text(Client.getInstance().getName());
34-
usernameText.setFont(Font.font("Arial", FontWeight.BOLD, 20));
35-
usernameText.setFill(Color.web("#333333")); // replace HEX_VALUE with your green color hex code
36-
37-
// Table
38-
TableView<Object> table = new TableView<>(); // Replace Object with your actual data type
39-
String[] headers = {"id", "name", "coord X", "coord Y", "creation", "area", "population", "government", "standards", "climate", "governor"};
40-
for (String header : headers) {
41-
TableColumn<Object, String> column = new TableColumn<>(header); // Replace Object with your actual data type
42-
column.setCellValueFactory(new PropertyValueFactory<>(header.toLowerCase()));
43-
table.getColumns().add(column);
17+
try {
18+
stage = new Stage();
19+
URL fxmlLocation = getClass().getResource("/collections/collectionsWindow.fxml");
20+
FXMLLoader loader = new FXMLLoader(fxmlLocation);
21+
Parent root = loader.load();
22+
23+
scene = new Scene(root, 920, 600);
24+
stage.setScene(scene);
25+
} catch (IOException e) {
26+
e.printStackTrace();
4427
}
45-
46-
// Dummy data
47-
ObservableList<Object> data = FXCollections.observableArrayList(
48-
new Object[] {1, "Vladimir", 56, 800, "990-06-01", 124, 349951, "DEMOCRACY", "VERY HIGH", "STEPPE", "ALEXEY"} // Replace Object with your actual data type
49-
// Add more dummy data here
50-
);
51-
table.setItems(data);
52-
53-
// Buttons
54-
Button createButton = new Button("Create");
55-
Button editButton = new Button("Edit");
56-
Button deleteButton = new Button("Delete");
57-
Button visualizeButton = new Button("Visualize");
58-
Button commandsButton = new Button("Commands");
59-
60-
// Action Handlers for buttons
61-
createButton.setOnAction(event -> {
62-
// Handle Create button
63-
});
64-
editButton.setOnAction(event -> {
65-
// Handle Edit button
66-
});
67-
deleteButton.setOnAction(event -> {
68-
// Handle Delete button
69-
});
70-
visualizeButton.setOnAction(event -> {
71-
// Handle Visualize button
72-
});
73-
commandsButton.setOnAction(event -> {
74-
// Handle Commands button
75-
});
76-
77-
// Adding elements to the layout
78-
root.getChildren().addAll(usernameText, table, createButton, editButton, deleteButton, visualizeButton, commandsButton);
79-
80-
scene = new Scene(root, 500, 500);
81-
stage.setScene(scene);
8228
}
8329

8430
public void show() {

0 commit comments

Comments
 (0)