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
2 changes: 1 addition & 1 deletion JavaCreditest/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions JavaCreditest/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
requires com.google.gson;
requires java.naming;
requires java.sql;
requires java.persistence;
requires javax.persistence;

opens ru.meowmure.javacreditest.Clockshop to com.google.gson;
opens ru.meowmure.javacreditest.Model to com.google.gson;
opens ru.meowmure.javacreditest to javafx.fxml;
exports ru.meowmure.javacreditest.Clockshop;
exports ru.meowmure.javacreditest.Model;
exports ru.meowmure.javacreditest;
exports ru.meowmure.javacreditest.Controllers;
opens ru.meowmure.javacreditest.Controllers to javafx.fxml;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import javafx.scene.Scene;
import javafx.scene.control.ListView;
import javafx.stage.Stage;
import ru.meowmure.javacreditest.Clockshop.Clock;
import ru.meowmure.javacreditest.Model.Clock;
import ru.meowmure.javacreditest.Controllers.GUIController;
import ru.meowmure.javacreditest.Controllers.ItemController;
import ru.meowmure.javacreditest.Controllers.TimeController;
Expand All @@ -28,7 +28,7 @@ public void start(Stage stage) throws IOException {

public void showMainWindow() {
try {
FXMLLoader loader = new FXMLLoader(ClockShopApplication.class.getResource("NewMainWindow.fxml"));
FXMLLoader loader = new FXMLLoader(ClockShopApplication.class.getResource("MainWindow.fxml"));
Scene mainScene = new Scene(loader.load());
Stage mainStage = new Stage();
mainStage.setTitle("Shop");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ru.meowmure.javacreditest.Controllers;

import javafx.scene.Group;
import ru.meowmure.javacreditest.Clockshop.Clock;
import ru.meowmure.javacreditest.Model.Clock;
import ru.meowmure.javacreditest.Exceptions.IncorrectNumberException;

import java.sql.PreparedStatement;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package ru.meowmure.javacreditest.Controllers;

import javafx.scene.paint.Color;
import ru.meowmure.javacreditest.Exceptions.IncorrectNumberException;
import ru.meowmure.javacreditest.Model.Clock;

public class DefaultList {
public static void createDefaultList(GUIController controller) {
try {
Color colorRolex = Color.GOLD;
Clock clockRolex = new Clock(controller.getGroup(), colorRolex);
clockRolex.setName("Day Date 40");
clockRolex.setMark("Rolex");
clockRolex.setCost(500000);
clockRolex.setTyped(true);

Color colorPatekPhilippe = Color.GHOSTWHITE;
Clock clockPatekPhilippe = new Clock(controller.getGroup(), colorPatekPhilippe);
clockPatekPhilippe.setName("Nautilus");
clockPatekPhilippe.setMark("Patek Philippe");
clockPatekPhilippe.setCost(990000);
clockPatekPhilippe.setTyped(true);

Color colorTAGHeuer = Color.ROYALBLUE;
Clock clockTAGheuer = new Clock(controller.getGroup(), colorTAGHeuer);
clockTAGheuer.setName("Monaco");
clockTAGheuer.setMark("TAG Heuer");
clockTAGheuer.setCost(478000);
clockTAGheuer.setTyped(false);

Color colorLongines = Color.LIMEGREEN;
Clock clockLongines = new Clock(controller.getGroup(), colorLongines);
clockLongines.setName("Spirit");
clockLongines.setMark("Longines");
clockLongines.setCost(333600);
clockLongines.setTyped(false);

Color colorAudemarsPiguet = Color.LIGHTSTEELBLUE;
Clock clockAudemarsPiguet = new Clock(controller.getGroup(), colorAudemarsPiguet);
clockAudemarsPiguet.setName("Royal Oak");
clockAudemarsPiguet.setMark("Audemars Piguet");
clockAudemarsPiguet.setCost(777000);
clockAudemarsPiguet.setTyped(true);

controller.getListView().getItems().add(clockRolex);
controller.getListView().getItems().add(clockPatekPhilippe);
controller.getListView().getItems().add(clockTAGheuer);
controller.getListView().getItems().add(clockLongines);
controller.getListView().getItems().add(clockAudemarsPiguet);
} catch (IncorrectNumberException e) {
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,15 @@
import javafx.fxml.FXML;
import javafx.scene.Group;
import javafx.scene.control.*;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.MenuItem;
import javafx.scene.control.TextField;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.Color;
import javafx.stage.FileChooser;
import ru.meowmure.javacreditest.ClockShopApplication;
import ru.meowmure.javacreditest.Clockshop.Clock;
import ru.meowmure.javacreditest.Exceptions.IncorrectNumberException;
import ru.meowmure.javacreditest.Model.Clock;

import java.io.*;
import java.util.*;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;


public class GUIController {
Expand Down Expand Up @@ -69,18 +65,32 @@ public class GUIController {

private ClockShopApplication app;

public void setApp(ClockShopApplication app) { this.app = app; }

public void setApp(ClockShopApplication app) {
this.app = app;
}

public void setListView(ListView<Clock> listView) {
this.listView = listView;
}

public void add(ActionEvent actionEvent) {
Color color = new Random().nextInt(2) == 0 ? Color.AQUA : Color.MAGENTA;
Clock clock = new Clock(group, color);
Clock clock = new Clock(group);
app.showAddWindow(clock, listView);
}

public ListView<Clock> getListView() {
return listView;
}

public Group getGroup() {
return group;
}

public void setGroup(Group group) {
this.group = group;
}

public void onItemSelected(MouseEvent mouseEvent) {
if (listView.getItems().isEmpty()) return;

Expand Down Expand Up @@ -240,49 +250,6 @@ public void dataBaseSave(ActionEvent actionEvent) {
}

public void defaultClockBrands() {
try {
Color colorRolex = Color.GOLD;
Clock clockRolex = new Clock(group, colorRolex);
clockRolex.setName("Day Date 40");
clockRolex.setMark("Rolex");
clockRolex.setCost(500000);
clockRolex.setTyped(true);

Color colorPatekPhilippe = Color.GHOSTWHITE;
Clock clockPatekPhilippe = new Clock(group, colorPatekPhilippe);
clockPatekPhilippe.setName("Nautilus");
clockPatekPhilippe.setMark("PatekPhilippe");
clockPatekPhilippe.setCost(990000);
clockPatekPhilippe.setTyped(true);

Color colorTAGHeuer = Color.ROYALBLUE;
Clock clockTAGheuer = new Clock(group, colorTAGHeuer);
clockTAGheuer.setName("Monaco");
clockTAGheuer.setMark("TAG Heuer");
clockTAGheuer.setCost(478000);
clockTAGheuer.setTyped(false);

Color colorLongines = Color.LIMEGREEN;
Clock clockLongines = new Clock(group, colorLongines);
clockLongines.setName("Spirit");
clockLongines.setMark("Longines");
clockLongines.setCost(333600);
clockLongines.setTyped(false);

Color colorAudemarsPiguet = Color.LIGHTSTEELBLUE;
Clock clockAudemarsPiguet = new Clock(group, colorAudemarsPiguet);
clockAudemarsPiguet.setName("Royal Oak");
clockAudemarsPiguet.setMark("Audemars Piguet");
clockAudemarsPiguet.setCost(777000);
clockAudemarsPiguet.setTyped(true);

listView.getItems().add(clockRolex);
listView.getItems().add(clockPatekPhilippe);
listView.getItems().add(clockTAGheuer);
listView.getItems().add(clockLongines);
listView.getItems().add(clockAudemarsPiguet);
} catch (IncorrectNumberException e) {
throw new RuntimeException(e);
}
DefaultList.createDefaultList(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,41 @@


import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.*;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import ru.meowmure.javacreditest.ClockShopApplication;
import ru.meowmure.javacreditest.Clockshop.Clock;
import ru.meowmure.javacreditest.Exceptions.IncorrectNumberException;
import ru.meowmure.javacreditest.Model.Clock;

import java.net.URL;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class ItemController {

public class ItemController implements Initializable {
ObservableList list = FXCollections.observableArrayList();
@FXML
private Button buttonCreate = new Button();
@FXML
private TextField name = new TextField();
private TextField name = new TextField();
@FXML
private ChoiceBox<String> brandsChoiceBox;
private ChoiceBox<String> mark = new ChoiceBox<>();
@FXML
private TextField price = new TextField();
@FXML
private CheckBox type = new CheckBox();
private ClockShopApplication app;
private ListView<Clock> listView;
private Clock clock;
private List<String> brands = Arrays.asList("Rolex", "Patek Philippe", "TAG Heuer", "Longines", "Audemars Piguet");
private List<Color> brandColors = Arrays.asList(Color.GOLD, Color.GHOSTWHITE, Color.ROYALBLUE, Color.LIMEGREEN, Color.LIGHTSTEELBLUE);

List<Color> colors = new ArrayList<>(Arrays.asList(Color.GOLD, Color.GHOSTWHITE, Color.ROYALBLUE, Color.LIMEGREEN, Color.LIGHTSTEELBLUE));
List<String> brands = new ArrayList<>(Arrays.asList("Rolex", "Patek Philippe", "TAG Heuer", "Longines", "Audemars Piguet"));


public void setApp(ClockShopApplication app) {
mark.setItems(FXCollections.observableArrayList("Rolex", "Patek Philippe", "TAG Heuer", "Longines", "Audemars Piguet"));
this.app = app;
}

Expand All @@ -47,25 +48,32 @@ public ListView<Clock> getListView() {
return listView;
}

public void setObject(Clock clock) {
this.clock = clock;
}

public void create(ActionEvent actionEvent) {
if ((brandsChoiceBox == null || brandsChoiceBox.getItems().isEmpty()) || (name == null || name.getText().isEmpty()) || (price == null || price.getText().isEmpty()) || (type == null)) {
if ((mark == null || mark.getItems().isEmpty()) || (name == null || name.getText().isEmpty()) || (price == null || price.getText().isEmpty()) || (type == null)) {
new Alert(Alert.AlertType.ERROR, "The one of the fields is null or empty").showAndWait();
return;
}
clock.setMark(mark.getValue());
clock.setColor(colors.get(brands.indexOf(mark.getValue())));

try {
clock.setCost(Integer.parseInt(price.getText()));
} catch ( IncorrectNumberException e) {
new Alert(Alert.AlertType.ERROR, "Price is below zero").showAndWait();
new Alert(Alert.AlertType.ERROR, e.getMessage()).showAndWait();
return;
} catch (NumberFormatException e) {
new Alert(Alert.AlertType.ERROR, "Price is not a number").showAndWait();
new Alert(Alert.AlertType.ERROR, e.getMessage()).showAndWait();
return;
}

clock.setName(name.getText());
clock.setTyped(type.isSelected());

checkMatches();
//checkMatches();

listView.getItems().add(clock);

Expand All @@ -81,21 +89,11 @@ public void checkMatches() {
}
}
}
public void setObject(Clock clock) {
this.clock = clock;
}
//public void setObject(Clock clock) {
// this.clock = clock;
// }

public void returnList() {
app.GUIcontroller.setListView(listView);
}

@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
brandsChoiceBox.getItems().addAll(brands);
}

public void onMarkSelected(ActionEvent actionEvent) {
clock.setMark(brandsChoiceBox.getValue());
clock.setColor(brandColors.get(brands.indexOf(brandsChoiceBox.getValue())));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.Group;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.control.TextField;
import javafx.scene.text.Font;
import javafx.stage.Stage;
import ru.meowmure.javacreditest.ClockShopApplication;
import ru.meowmure.javacreditest.Clockshop.Clock;
import ru.meowmure.javacreditest.Model.Clock;

public class TimeController {
@FXML
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ru.meowmure.javacreditest.Clockshop;
package ru.meowmure.javacreditest.Model;


import com.google.gson.annotations.Expose;
Expand All @@ -15,7 +15,7 @@
@Table(name = "clocks")
public class Clock implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@GeneratedValue(strategy = GenerationType.AUTO)
private transient int id;
@Expose
private String name;
Expand Down Expand Up @@ -48,6 +48,18 @@ public Clock(Group group, Color color) {
blue = color.getBlue();
}

public Clock(Group group) {
clockPane = new ClockPane(group, this);
timeStart = new GregorianCalendar();
}

public void setColor(Color color) {
red = color.getRed();
green = color.getGreen();
blue = color.getBlue();
clockPane.setColor(color);
}

public int getId() {
return id;
}
Expand Down Expand Up @@ -142,12 +154,6 @@ public void setTime(int hours, int minutes, int seconds) {
timeStart = new GregorianCalendar();
}

public void setColor(Color color) {
red = color.getRed();
blue = color.getBlue();
green = color.getGreen();
}

public void clockRestored(Group group) {
clockPane = new ClockPane(group, this, Color.color(red, green, blue));
}
Expand Down
Loading