diff --git a/.idea/discord.xml b/.idea/discord.xml
new file mode 100644
index 0000000..30bab2a
--- /dev/null
+++ b/.idea/discord.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml
deleted file mode 100644
index 2b63946..0000000
--- a/.idea/uiDesigner.xml
+++ /dev/null
@@ -1,124 +0,0 @@
-
-
-
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
-
-
-
- -
-
-
-
-
-
- -
-
-
-
-
-
- -
-
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
-
-
- -
-
-
- -
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 03b7fd1..2f1dc56 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -5,63 +5,32 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
-
-
-
-
-
-
-
+
-
@@ -72,6 +41,7 @@
@@ -94,6 +64,9 @@
+
+
+
@@ -113,24 +86,12 @@
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
"git-widget-placeholder": "main",
"ignore.virus.scanning.warn.message": "true",
- "last_opened_file_path": "E:/ibrahem/oop/progect1/library-system/src/main/resources/com/asu/librarysystem",
+ "last_opened_file_path": "D:/Programming/Repos/library-system",
"project.structure.last.edited": "Libraries",
"project.structure.proportion": "0.15",
"project.structure.side.proportion": "0.2"
}
}
-
-
-
-
-
-
-
-
-
-
-
-
@@ -241,4 +202,15 @@
+
+
+
+
+ file://$PROJECT_DIR$/src/main/java/com/asu/librarysystem/MainController.java
+ 25
+
+
+
+
+
\ No newline at end of file
diff --git a/book-covers/jane_eyre.jpg b/book-covers/jane_eyre.jpg
new file mode 100644
index 0000000..ca8d7d2
Binary files /dev/null and b/book-covers/jane_eyre.jpg differ
diff --git a/data/bookSceneAssets/Rating_icons/1_star.png b/data/bookSceneAssets/Rating_icons/1_star.png
new file mode 100644
index 0000000..df65fd0
Binary files /dev/null and b/data/bookSceneAssets/Rating_icons/1_star.png differ
diff --git a/data/bookSceneAssets/Rating_icons/2_stars.png b/data/bookSceneAssets/Rating_icons/2_stars.png
new file mode 100644
index 0000000..17445b3
Binary files /dev/null and b/data/bookSceneAssets/Rating_icons/2_stars.png differ
diff --git a/data/bookSceneAssets/Rating_icons/3_stars.png b/data/bookSceneAssets/Rating_icons/3_stars.png
new file mode 100644
index 0000000..754cd2f
Binary files /dev/null and b/data/bookSceneAssets/Rating_icons/3_stars.png differ
diff --git a/data/bookSceneAssets/Rating_icons/4_stars.png b/data/bookSceneAssets/Rating_icons/4_stars.png
new file mode 100644
index 0000000..e8d7563
Binary files /dev/null and b/data/bookSceneAssets/Rating_icons/4_stars.png differ
diff --git a/data/bookSceneAssets/Rating_icons/5_stars.png b/data/bookSceneAssets/Rating_icons/5_stars.png
new file mode 100644
index 0000000..eb44302
Binary files /dev/null and b/data/bookSceneAssets/Rating_icons/5_stars.png differ
diff --git a/data/bookSceneAssets/Rating_icons/fiveStarsRate.png b/data/bookSceneAssets/Rating_icons/fiveStarsRate.png
new file mode 100644
index 0000000..c9cc679
Binary files /dev/null and b/data/bookSceneAssets/Rating_icons/fiveStarsRate.png differ
diff --git a/data/bookSceneAssets/Rating_icons/fourStarsRate.png b/data/bookSceneAssets/Rating_icons/fourStarsRate.png
new file mode 100644
index 0000000..2c9b763
Binary files /dev/null and b/data/bookSceneAssets/Rating_icons/fourStarsRate.png differ
diff --git a/data/bookSceneAssets/Rating_icons/oneStarRate.png b/data/bookSceneAssets/Rating_icons/oneStarRate.png
new file mode 100644
index 0000000..460c97b
Binary files /dev/null and b/data/bookSceneAssets/Rating_icons/oneStarRate.png differ
diff --git a/data/bookSceneAssets/Rating_icons/threeStarsRate.png b/data/bookSceneAssets/Rating_icons/threeStarsRate.png
new file mode 100644
index 0000000..c4cfa6d
Binary files /dev/null and b/data/bookSceneAssets/Rating_icons/threeStarsRate.png differ
diff --git a/data/bookSceneAssets/Rating_icons/twoStarsRate.png b/data/bookSceneAssets/Rating_icons/twoStarsRate.png
new file mode 100644
index 0000000..5377a63
Binary files /dev/null and b/data/bookSceneAssets/Rating_icons/twoStarsRate.png differ
diff --git a/data/bookSceneAssets/Status_icons/addToCartButton.png b/data/bookSceneAssets/Status_icons/addToCartButton.png
new file mode 100644
index 0000000..fefcd72
Binary files /dev/null and b/data/bookSceneAssets/Status_icons/addToCartButton.png differ
diff --git a/data/bookSceneAssets/Status_icons/notifyMeButton.png b/data/bookSceneAssets/Status_icons/notifyMeButton.png
new file mode 100644
index 0000000..af19f15
Binary files /dev/null and b/data/bookSceneAssets/Status_icons/notifyMeButton.png differ
diff --git a/data/bookSceneAssets/Status_icons/outOfStock.png b/data/bookSceneAssets/Status_icons/outOfStock.png
new file mode 100644
index 0000000..2c1c578
Binary files /dev/null and b/data/bookSceneAssets/Status_icons/outOfStock.png differ
diff --git a/data/bookSceneAssets/user-profile.png b/data/bookSceneAssets/user-profile.png
new file mode 100644
index 0000000..ce8d742
Binary files /dev/null and b/data/bookSceneAssets/user-profile.png differ
diff --git a/data/covers/1.jpg b/data/covers/1.jpg
index 6eea682..ca8d7d2 100644
Binary files a/data/covers/1.jpg and b/data/covers/1.jpg differ
diff --git a/data/covers/10.jpg b/data/covers/10.jpg
index 45eb190..5e7bb32 100644
Binary files a/data/covers/10.jpg and b/data/covers/10.jpg differ
diff --git a/data/covers/11.jpg b/data/covers/11.jpg
new file mode 100644
index 0000000..5e7bb32
Binary files /dev/null and b/data/covers/11.jpg differ
diff --git a/data/covers/2.jpg b/data/covers/2.jpg
index 1818948..5e7bb32 100644
Binary files a/data/covers/2.jpg and b/data/covers/2.jpg differ
diff --git a/data/covers/3.jpg b/data/covers/3.jpg
index 7ea1ef8..5e7bb32 100644
Binary files a/data/covers/3.jpg and b/data/covers/3.jpg differ
diff --git a/data/covers/4.jpg b/data/covers/4.jpg
index ec45449..5e7bb32 100644
Binary files a/data/covers/4.jpg and b/data/covers/4.jpg differ
diff --git a/data/covers/5.jpg b/data/covers/5.jpg
index 24b44d1..5e7bb32 100644
Binary files a/data/covers/5.jpg and b/data/covers/5.jpg differ
diff --git a/data/covers/6.jpg b/data/covers/6.jpg
index f67ac1a..5e7bb32 100644
Binary files a/data/covers/6.jpg and b/data/covers/6.jpg differ
diff --git a/data/covers/7.jpg b/data/covers/7.jpg
index da0e97d..5e7bb32 100644
Binary files a/data/covers/7.jpg and b/data/covers/7.jpg differ
diff --git a/data/covers/8.jpg b/data/covers/8.jpg
index 204280f..5e7bb32 100644
Binary files a/data/covers/8.jpg and b/data/covers/8.jpg differ
diff --git a/data/covers/9.jpg b/data/covers/9.jpg
index 37e5b13..5e7bb32 100644
Binary files a/data/covers/9.jpg and b/data/covers/9.jpg differ
diff --git a/src/main/java/com/asu/librarysystem/Book.java b/src/main/java/com/asu/librarysystem/Book.java
index 6d4129f..c2c7adf 100644
--- a/src/main/java/com/asu/librarysystem/Book.java
+++ b/src/main/java/com/asu/librarysystem/Book.java
@@ -2,6 +2,8 @@
import java.io.File;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
+import java.util.ArrayList;
+import java.util.Arrays;
public class Book {
private static int idCounter = 0;
@@ -11,18 +13,27 @@ public class Book {
private int publicationYear;
private boolean status;
private int price;
- private int rating;
+ private int quantity;
+ private String descreption;
private File cover;
+ private ArrayList categories;
- public Book(String title, String author, int publicationYear, boolean status, int price, int rating, String coverPath) {
+
+
+ public Book(String title, String author, int publicationYear, boolean status, int price, int quantity
+ , String descreption, String coverPath, Category[] categories) {
this.id = ++idCounter;
this.title = title;
this.author = author;
this.publicationYear = publicationYear;
this.status = status;
this.price = price;
- this.rating = rating;
+ this.quantity = quantity;
+ this.descreption = descreption;
+
setCover(coverPath);
+
+ this.categories = new ArrayList(Arrays.asList(categories));
}
public int getId() {
@@ -49,10 +60,6 @@ public int getPrice() {
return price;
}
- public int getRating() {
- return rating;
- }
-
public void setTitle(String title) {
this.title = title;
}
@@ -73,6 +80,14 @@ public void setPrice(int price) {
this.price = price;
}
+ public void setQuantity(int quantity) { this.quantity = quantity; }
+
+ public int getQuantity() { return quantity; }
+
+ public boolean isAvailable() { return quantity > 0; }
+
+ public String getDescreption() { return descreption; }
+
public void setCover(String path) {
File newCover = new File(path);
@@ -92,4 +107,10 @@ public void setCover(String path) {
public String getCoverPath() {
return cover.getAbsolutePath();
}
+
+ public ArrayList getCategories(){
+ return this.categories;
+ }
+
+
}
diff --git a/src/main/java/com/asu/librarysystem/BookController.java b/src/main/java/com/asu/librarysystem/BookController.java
new file mode 100644
index 0000000..ee94d0b
--- /dev/null
+++ b/src/main/java/com/asu/librarysystem/BookController.java
@@ -0,0 +1,376 @@
+package com.asu.librarysystem;
+
+import javafx.collections.FXCollections;
+import javafx.collections.ObservableList;
+import javafx.event.ActionEvent;
+import javafx.fxml.FXML;
+import javafx.fxml.FXMLLoader;
+import javafx.fxml.Initializable;
+import javafx.geometry.Insets;
+import javafx.geometry.Pos;
+import javafx.scene.AccessibleRole;
+import javafx.scene.Cursor;
+import javafx.scene.control.*;
+import javafx.scene.image.Image;
+import javafx.scene.image.ImageView;
+import javafx.scene.input.KeyEvent;
+import javafx.scene.input.MouseEvent;
+import javafx.scene.layout.GridPane;
+import javafx.scene.layout.HBox;
+import javafx.scene.layout.VBox;
+import javafx.scene.text.Text;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.ResourceBundle;
+
+public class BookController implements Initializable {
+
+ @FXML
+ VBox mainContainer;
+ @FXML
+ ImageView bookCover, statusImage, oneStarIcon, twoStarsIcon, threeStarsIcon, fourStarsIcon, fiveStarsIcon, notifyMe;
+ @FXML
+ Label name, author, releaseDate, price, description, countRatings, totalRating, textAreaCharCount;
+ @FXML
+ Text warningMessage;
+ @FXML
+ ProgressBar oneStarBar, twoStarsBar, threeStarsBar, fourStarsBar, fiveStarsBar;
+ @FXML
+ TextArea reviewTextArea;
+ @FXML
+ Button reviewSubmitButton;
+ @FXML
+ ComboBox ratingOptions;
+ @FXML
+ VBox commentSection;
+ @FXML
+ HBox propertiesButtons;
+ @FXML
+ GridPane recommendations;
+
+ private Book currentBook;
+
+ private final ObservableList optionsList = FXCollections.observableArrayList(1, 2, 3, 4, 5);
+
+ @Override
+ public void initialize(URL url, ResourceBundle resourceBundle) {
+ ratingOptions.setItems(optionsList);
+ }
+
+ public void setScene(Book book) throws IOException {
+ currentBook = book;
+ setCover(book.getCoverPath());
+
+ setProperties(book.getTitle(), book.getAuthor(), Integer.toString(book.getPublicationYear())
+ , book.getDescreption(), book.getPrice(), book.getQuantity());
+
+ Library.getReviewHandler().addReview(1, book.getId(), 3, "I don't love this book");
+ ArrayList ratings = Library.getReviewHandler().getBookRatings(book.getId());
+ setRatings(ratings);
+
+ InputStream stream1 = new FileInputStream("data/bookSceneAssets/Rating_icons/1_star.png");
+ InputStream stream2 = new FileInputStream("data/bookSceneAssets/Rating_icons/2_stars.png");
+ InputStream stream3 = new FileInputStream("data/bookSceneAssets/Rating_icons/3_stars.png");
+ InputStream stream4 = new FileInputStream("data/bookSceneAssets/Rating_icons/4_stars.png");
+ InputStream stream5 = new FileInputStream("data/bookSceneAssets/Rating_icons/5_stars.png");
+
+
+ oneStarIcon.setImage(new Image(stream1));
+ twoStarsIcon.setImage(new Image(stream2));
+ threeStarsIcon.setImage(new Image(stream3));
+ fourStarsIcon.setImage(new Image(stream4));
+ fiveStarsIcon.setImage(new Image(stream5));
+
+ showRecommendations();
+
+
+ TextFormatter formatter = new TextFormatter<>(change -> {
+ String newText = change.getControlNewText();
+ if (newText.length() > 300 && !change.getControlNewText().endsWith("\b")) {
+ return null; // Reject the change
+ } else {
+ return change; // Accept the change
+ }
+ });
+
+ reviewTextArea.setTextFormatter(formatter);
+
+
+ ArrayList comments = Library.getReviewHandler().getBookReviews(book.getId());
+ showComments(comments);
+
+ }
+
+
+
+ private void setCover(String path) {
+
+ Image cover = new Image(path);
+ bookCover.setImage(cover);
+ }
+
+
+
+ private void setProperties(String name, String author, String releaseDate,String description
+ ,int price, int quantity){
+
+ Label nameAttribute = new Label("Title");
+ nameAttribute.setStyle("-fx-font-weight: bold;");
+ this.name.setText(nameAttribute.getText() + ": " + name);
+
+ Label authorAttribute = new Label("Author");
+ authorAttribute.setStyle("-fx-font-weight: bold;");
+ this.author.setText(authorAttribute.getText() + ": " + author);
+
+ Label releaseDateAttribute = new Label("Release Date");
+ releaseDateAttribute.setStyle("-fx-font-weight: bold;");
+ this.releaseDate.setText(releaseDateAttribute.getText() + ": " + releaseDate);
+
+ Label priceAttribute = new Label("Price");
+ priceAttribute.setStyle("-fx-font-weight: bold;");
+ this.price.setText(priceAttribute.getText() + ": " + formatPrice(price) + "$");
+
+ this.description.setText(description);
+
+ if (quantity > 0){
+ try {
+ InputStream imageLocation = new FileInputStream("data/bookSceneAssets/Status_icons/addToCartButton.png");
+ Image available = new Image(imageLocation);
+
+ statusImage.setImage(available);
+ statusImage.setAccessibleRole(AccessibleRole.BUTTON);
+ statusImage.setCursor(Cursor.HAND);
+ statusImage.setOnMouseClicked(this::addToCart);
+
+ propertiesButtons.getChildren().remove(notifyMe);
+ } catch (FileNotFoundException e) {
+ throw new RuntimeException(e);
+ }
+ } else {
+ try {
+ InputStream outOfStockImage = new FileInputStream("data/bookSceneAssets/Status_icons/outOfStock.png");
+ Image outOfStock = new Image(outOfStockImage);
+ statusImage.setImage(outOfStock);
+ statusImage.setCursor(Cursor.DEFAULT);
+ statusImage.setOnMouseClicked(null);
+
+ InputStream notifyMeImage = new FileInputStream("data/bookSceneAssets/Status_icons/notifyMeButton.png");
+ Image notifyMe = new Image(notifyMeImage);
+ this.notifyMe.setImage(notifyMe);
+
+
+ } catch (FileNotFoundException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+ public void addToCart(MouseEvent e) {
+ System.out.println("Hello");
+ }
+
+ private String formatPrice(int price){
+ return (--price) + ".99";
+ }
+
+
+
+ private void setRatings(ArrayList ratings){
+ int total = 0;
+ for (int i = 1; i <= 5; i++){
+ total += ratings.get(i);
+ }
+ this.countRatings.setText(total + " RATINGS");
+
+ oneStarBar.setProgress( changeProgress(total, ratings.get(1)) );
+ twoStarsBar.setProgress( changeProgress(total, ratings.get(2)) );
+ threeStarsBar.setProgress( changeProgress(total, ratings.get(3)) );
+ fourStarsBar.setProgress( changeProgress(total, ratings.get(4)) );
+ fiveStarsBar.setProgress( changeProgress(total, ratings.get(5)) );
+
+ String score = calculateScore(ratings, total);
+ totalRating.setText(score);
+ }
+
+ public double changeProgress(int totalRating, int barRating){
+ return ((double)barRating / totalRating);
+ }
+
+ public String calculateScore(ArrayList reviews, int total){
+ if (total == 0){
+ return "0";
+ }
+
+ double allRatings = reviews.get(1) + reviews.get(2) * 2 + reviews.get(3) * 3 + reviews.get(4) * 4
+ + reviews.get(5) * 5;
+
+ double score = allRatings / (double) (total * 5);
+
+ score = score * 5;
+
+
+ return String.format("%.1f", score);
+ }
+
+
+ private void showRecommendations() throws IOException {
+ ArrayList availableBooks = Library.copyElementOfArrayList();
+ int counter = 0;
+ for (Book book : availableBooks){
+ if (counter == 6) break;
+
+ if (findingCommonCategories(book)){
+ FXMLLoader fxmlLoader=new FXMLLoader();
+ fxmlLoader.setLocation(getClass().getResource("Book-View-Card.fxml"));
+
+ VBox CardOfBook=fxmlLoader.load();
+
+ BooksViewCard recommendedBook = fxmlLoader.getController();
+ recommendedBook.setData(book);
+
+ recommendations.add(CardOfBook, counter,0);
+ GridPane.setMargin(CardOfBook,new Insets(10));
+ counter++;
+ }
+ }
+ }
+
+ private boolean findingCommonCategories(Book book){
+ for (Category category : book.getCategories()) {
+ for (Category category2 : currentBook.getCategories()) {
+ if (category == category2) {
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
+
+
+ public void setTypedCharacter(KeyEvent event){
+ int inputTextLength = reviewTextArea.getLength();
+
+ int maxCommentLenght = 300;
+ if (maxCommentLenght - inputTextLength <= 0){
+ displayCharLimitReachedWarning();
+ } else {
+ warningMessage.setText("");
+
+ textAreaCharCount.setText( Integer.toString(maxCommentLenght - inputTextLength) );
+ }
+ }
+
+ private void displayCharLimitReachedWarning(){
+ textAreaCharCount.setText("0");
+ String maxCharLimitReached = "Warning: Character limit reached";
+ warningMessage.setText(maxCharLimitReached);
+ }
+
+
+
+
+
+
+
+
+ public void submitReview(ActionEvent event) throws FileNotFoundException {
+ if (choseNoRating()){
+ displayNoRatingSelectedWarning();
+ } else {
+ Account activeUser = Library.getActiveAccount();
+ Library.getReviewHandler().addReview(activeUser.getId(), currentBook.getId(),
+ ratingOptions.getValue(), reviewTextArea.getText());
+ System.out.println("review added");
+
+ showComments(Library.getReviewHandler().getBookReviews(currentBook.getId()));
+ setRatings(Library.getReviewHandler().getBookRatings(currentBook.getId()));
+ }
+
+ }
+
+ private boolean choseNoRating(){
+ return ratingOptions.getValue() == null;
+ }
+
+ private void displayNoRatingSelectedWarning(){
+ String noRatingSelected = "Warning: you haven't chosen a rating";
+ warningMessage.setText(noRatingSelected);
+ }
+
+
+
+
+
+
+
+ private void showComments(ArrayList comments) throws FileNotFoundException {
+ commentSection.getChildren().clear();
+
+ InputStream stream1 = new FileInputStream("data/bookSceneAssets/Rating_icons/oneStarRate.png");
+ InputStream stream2 = new FileInputStream("data/bookSceneAssets/Rating_icons/twoStarsRate.png");
+ InputStream stream3 = new FileInputStream("data/bookSceneAssets/Rating_icons/threeStarsRate.png");
+ InputStream stream4 = new FileInputStream("data/bookSceneAssets/Rating_icons/fourStarsRate.png");
+ InputStream stream5 = new FileInputStream("data/bookSceneAssets/Rating_icons/fiveStarsRate.png");
+ InputStream stream6 = new FileInputStream("data/bookSceneAssets/user-profile.png");
+
+ Image oneStar = new Image(stream1);
+ Image twoStars = new Image(stream2);
+ Image threeStars = new Image(stream3);
+ Image fourStars = new Image(stream4);
+ Image fiveStars = new Image(stream5);
+ Image userIcon = new Image(stream6);
+
+ for (var comment : comments){
+ VBox container = new VBox();
+ container.setSpacing(40d);
+ container.setMaxWidth(1214);
+ container.setAlignment(Pos.CENTER_LEFT);
+
+
+ HBox innerContainer = new HBox();
+ innerContainer.setSpacing(40d);
+ innerContainer.setMaxWidth(1214);
+ innerContainer.setAlignment(Pos.CENTER_LEFT);
+
+
+ Label username = new Label();
+ username.setText(Integer.toString(comment.getReviewerId()));
+ username.setStyle("-fx-font-weight: 500;");
+ username.setStyle("-fx-font-size: 48px;");
+
+
+ ImageView rate = new ImageView();
+ if (comment.getRating() == 1){
+ rate.setImage(oneStar);
+ } else if (comment.getRating() == 2){
+ rate.setImage(twoStars);
+ } else if (comment.getRating() == 3){
+ rate.setImage(threeStars);
+ } else if (comment.getRating() == 4){
+ rate.setImage(fourStars);
+ } else {
+ rate.setImage(fiveStars);
+ }
+
+ ImageView user = new ImageView(userIcon);
+
+ Label text = new Label();
+ text.setStyle("-fx-font-size: 36px;");
+ text.setText(comment.getText());
+
+ innerContainer.getChildren().addAll(user, username, rate);
+ container.getChildren().addAll(innerContainer, text);
+
+ commentSection.getChildren().add(container);
+ }
+ }
+
+
+}
diff --git a/src/main/java/com/asu/librarysystem/BooksViewCard.java b/src/main/java/com/asu/librarysystem/BooksViewCard.java
index 6f34c8c..5526842 100644
--- a/src/main/java/com/asu/librarysystem/BooksViewCard.java
+++ b/src/main/java/com/asu/librarysystem/BooksViewCard.java
@@ -70,15 +70,16 @@ public void setData(Book book){
public void showDetailsOfBook(ActionEvent event){
Book book= searchBookByTitle(bookName.getText());
try {
- FXMLLoader loader = new FXMLLoader(getClass().getResource("name.fxml"));
+ FXMLLoader loader = new FXMLLoader(getClass().getResource("book-view.fxml"));
Parent root = loader.load();
-// clsssName objName = loader.getController();
-// objName.method;
- Stage stage = (Stage)((Node)event.getSource()).getScene().getWindow();
- Scene scene= new Scene(root);
- stage.setScene(scene);
- stage.show();
+ BookController bookc = loader.getController();
+ assert book != null;
+ bookc.setScene(book);
+
+ Scene newScene = new Scene(root);
+ MainApplication.st.setScene(newScene);
+ MainApplication.st.show();
} catch (IOException e) {
e.printStackTrace();
}
diff --git a/src/main/java/com/asu/librarysystem/Category.java b/src/main/java/com/asu/librarysystem/Category.java
new file mode 100644
index 0000000..90600d1
--- /dev/null
+++ b/src/main/java/com/asu/librarysystem/Category.java
@@ -0,0 +1,9 @@
+package com.asu.librarysystem;
+
+public enum Category {
+ HORROR,
+ DRAMA,
+ NOVEL,
+ SELFDEVELOPMENT,
+ ADVENTURE,
+}
diff --git a/src/main/java/com/asu/librarysystem/Library.java b/src/main/java/com/asu/librarysystem/Library.java
index 3a07fa0..6266d33 100644
--- a/src/main/java/com/asu/librarysystem/Library.java
+++ b/src/main/java/com/asu/librarysystem/Library.java
@@ -9,8 +9,8 @@ public class Library {
protected static ArrayList customers = new ArrayList();
protected static ArrayList borrowers = new ArrayList();
private static Account activeAccount;
- private static Admin admin;
- private static ReviewHandler reviewHandler;
+ private static Admin admin ;
+ private static ReviewHandler reviewHandler = new ReviewHandler();
//########################## Start for book #########################//
public static void addBook(Book book) {
@@ -327,6 +327,12 @@ public static ReviewHandler getReviewHandler() {
return reviewHandler;
}
+
+ public static Account getActiveAccount() {
+ return activeAccount;
+ }
+
+
public static ArrayList copyElementOfArrayList() {
return books;
}
@@ -383,7 +389,7 @@ public static void writeLibrary() {
try {
FileOutputStream write1=new FileOutputStream("books_data.txt");
for (Book obj : books) {
- write1.write((obj.getId()+","+obj.getTitle()+","+obj.getAuthor()+","+obj.getPublicationYear()+","+obj.isStatus()+","+obj.getPrice()+","+obj.getRating()+","+obj.getCoverPath()+"\n").getBytes());
+ write1.write((obj.getId()+","+obj.getTitle()+","+obj.getAuthor()+","+obj.getPublicationYear()+","+obj.isStatus()+","+obj.getPrice()+","+obj.getCoverPath()+"\n").getBytes());
}
write1.close();
} catch (FileNotFoundException e) {
@@ -450,85 +456,86 @@ public static void writeLibrary() {
}
}
- public static void readLibrary() {
- Scanner scanner1 = null;
- try {
- scanner1 = new Scanner(new FileInputStream("books_data.txt"));
- } catch (FileNotFoundException e) {
- System.out.println("can't read");
- }
-
- while (scanner1.hasNextLine()) {
- String line1 = scanner1.nextLine();
- String[] parts1 = line1.split(",");
- Book book=new Book(parts1[1],parts1[2],Integer.valueOf(parts1[3]),Boolean.valueOf(parts1[4]),Integer.valueOf(parts1[5]),Integer.valueOf(parts1[6]),parts1[7]);
- addBook(book);
- }
- scanner1.close();
-
- Scanner scanner2 = null;
- try {
- scanner2 = new Scanner(new FileInputStream("customers_data.txt"));
- } catch (FileNotFoundException e) {
- System.out.println("can't read");
- }
-
- while (scanner2.hasNextLine()) {
- String line2 = scanner2.nextLine();
- String[] parts2 = line2.split(",");
- Customer customer=new Customer(parts2[1],parts2[2],parts2[3]);
- addCustomer(customer);
- }
- scanner2.close();
-
- Scanner scanner3 = null;
- try {
- scanner3 = new Scanner(new FileInputStream("borrowers_data.txt"));
- } catch (FileNotFoundException e) {
- System.out.println("can't read");
- }
-
- while (scanner3.hasNextLine()) {
- String line3 = scanner3.nextLine();
- String[] parts3 = line3.split(",");
- Borrower borrower = new Borrower(parts3[1],parts3[2],parts3[3]);
- addBorrower(borrower);
- }
- scanner3.close();
-
- for(Borrower borrower : borrowers) {
- Scanner scanner = null;
- try {
- scanner = new Scanner(new FileInputStream("transaction_data_"+borrower.getUserName()+".txt"));
- } catch (FileNotFoundException e) {
- System.out.println("can't read");
- }
-
- while (scanner.hasNextLine()) {
- String line = scanner.nextLine();
- String[] parts = line.split(",");
- Transaction transaction = new Transaction(searchBookByTitle(parts[1]).getId(), borrower.getId(), Integer.valueOf(parts[3]), Integer.valueOf(parts[4]));
- borrower.addTransaction(searchBookById(transaction.getBookId()), transaction.getBorrowDate(),transaction.getReturnDate());
- }
- scanner.close();
- }
-
- for(Customer customer : customers) {
- Scanner scanner = null;
- try {
- scanner = new Scanner(new FileInputStream("order_data_"+customer.getUserName()+".txt"));
- } catch (FileNotFoundException e) {
- System.out.println("can't read");
- }
-
- while (scanner.hasNextLine()) {
- String line = scanner.nextLine();
- String[] parts = line.split(",");
- Order order = new Order(searchBookByTitle(parts[1]).getId(),Integer.valueOf(parts[2]));
- customer.addOrder(order.getBookId(),order.getQuantity());
- }
- scanner.close();
- }
- }
+// public static void readLibrary() {
+// Scanner scanner1 = null;
+// try {
+// scanner1 = new Scanner(new FileInputStream("books_data.txt"));
+// } catch (FileNotFoundException e) {
+// System.out.println("can't read");
+// }
+//
+// while (scanner1.hasNextLine()) {
+// String line1 = scanner1.nextLine();
+// String[] parts1 = line1.split(",");
+//// Book book=new Book(parts1[1],parts1[2],Integer.valueOf(parts1[3]),Boolean.valueOf(parts1[4]),Integer.valueOf(parts1[5]),Integer.valueOf(parts1[6]),parts1[7]);
+// addBook(book);
+// }
+// scanner1.close();
+//
+// Scanner scanner2 = null;
+// try {
+// scanner2 = new Scanner(new FileInputStream("customers_data.txt"));
+// } catch (FileNotFoundException e) {
+// System.out.println("can't read");
+// }
+//
+// while (scanner2.hasNextLine()) {
+// String line2 = scanner2.nextLine();
+// String[] parts2 = line2.split(",");
+// Customer customer=new Customer(parts2[1],parts2[2],parts2[3]);
+// addCustomer(customer);
+// }
+// scanner2.close();
+//
+// Scanner scanner3 = null;
+// try {
+// scanner3 = new Scanner(new FileInputStream("borrowers_data.txt"));
+// } catch (FileNotFoundException e) {
+// System.out.println("can't read");
+// }
+//
+// while (scanner3.hasNextLine()) {
+// String line3 = scanner3.nextLine();
+// String[] parts3 = line3.split(",");
+// Borrower borrower = new Borrower(parts3[1],parts3[2],parts3[3]);
+// addBorrower(borrower);
+// }
+// scanner3.close();
+//
+// for(Borrower borrower : borrowers) {
+// Scanner scanner = null;
+// try {
+// scanner = new Scanner(new FileInputStream("transaction_data_"+borrower.getUserName()+".txt"));
+// } catch (FileNotFoundException e) {
+// System.out.println("can't read");
+// }
+//
+// while (scanner.hasNextLine()) {
+// String line = scanner.nextLine();
+// String[] parts = line.split(",");
+// Transaction transaction = new Transaction(searchBookByTitle(parts[1]).getId(), borrower.getId(), Integer.valueOf(parts[3]), Integer.valueOf(parts[4]));
+// borrower.addTransaction(searchBookById(transaction.getBookId()), transaction.getBorrowDate(),transaction.getReturnDate());
+// }
+// scanner.close();
+// }
+//
+// for(Customer customer : customers) {
+// Scanner scanner = null;
+// try {
+// scanner = new Scanner(new FileInputStream("order_data_"+customer.getUserName()+".txt"));
+// } catch (FileNotFoundException e) {
+// System.out.println("can't read");
+// }
+//
+// while (scanner.hasNextLine()) {
+// String line = scanner.nextLine();
+// String[] parts = line.split(",");
+// Order order = new Order(searchBookByTitle(parts[1]).getId(),Integer.valueOf(parts[2]));
+// customer.addOrder(order.getBookId(),order.getQuantity());
+// }
+// scanner.close();
+// }
+// }
+
+}
-}
\ No newline at end of file
diff --git a/src/main/java/com/asu/librarysystem/MainApplication.java b/src/main/java/com/asu/librarysystem/MainApplication.java
index 2d0ca27..86ad701 100644
--- a/src/main/java/com/asu/librarysystem/MainApplication.java
+++ b/src/main/java/com/asu/librarysystem/MainApplication.java
@@ -1,24 +1,29 @@
package com.asu.librarysystem;
import javafx.application.Application;
+import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
-import javafx.scene.image.Image;
import javafx.stage.Stage;
+
import java.io.IOException;
-import javafx.fxml.FXMLLoader;
-import static com.asu.librarysystem.Library.*;
-public class MainApplication extends Application {
+import java.util.ArrayList;
+
+public class MainApplication extends Application {
+ public static ArrayList books = new ArrayList();
+
+ public static Stage st;
+ @Override
public void start(Stage stage) throws IOException {
- Scene scene = new Scene(FXMLLoader.load(getClass().getResource("hello-view.fxml")));
+ FXMLLoader fxmlLoader = new FXMLLoader(MainApplication.class.getResource("hello-view.fxml"));
+ Scene scene = new Scene(fxmlLoader.load());
+ stage.setTitle("Hello!");
- Image icon =new Image("E:\\ibrahem\\oop\\progect1\\library-system\\src\\main\\resources\\icon\\icons8-library-64.png");
- stage.getIcons().add(icon);
- stage.setTitle("library");
stage.setScene(scene);
+ st = stage;
stage.show();
// FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("hello-view.fxml"));
@@ -29,84 +34,40 @@ public void start(Stage stage) throws IOException {
}
public static void main(String[] args) {
-// Customer customer=new Customer("Ibrahem","111","111");
-// addCustomer(customer);
-// Borrower borrower = new Borrower("Ibrahem","111","111");
-// addBorrower(borrower);
-// Book book1 = new Book("Harry Potter and the Prisoner of Azkaban","J. K. Rowling",2023,true,200,4,"E:\\ibrahem\\oop\\progect1\\library-system\\src\\main\\resources\\image\\Harry_Potter_and_the_Prisoner_of_Azkaban.jpg");
-// Book book2 = new Book("Harry Potter and the Chamber of Secrets","J. K. Rowling",2020,true,200,3,"E:\\ibrahem\\oop\\progect1\\library-system\\src\\main\\resources\\image\\Harry_Potter_and_the_Chamber_of_Secrets.jpg");
-// Book book3 = new Book("The Alchemist ","Paulo Coelho ",2021,true,200,2,"E:\\ibrahem\\oop\\progect1\\library-system\\src\\main\\resources\\image\\TheAlchemist.jpg");
-// Book book4 = new Book("A Tale of Two Cities","Charles Dickens",2023,true,200,4,"E:\\ibrahem\\oop\\progect1\\library-system\\src\\main\\resources\\image\\Tales_serial.jpg");
-// Book book5 = new Book("The Little Prince ","Antoine de Saint-Exupéry",2020,true,200,3,"E:\\ibrahem\\oop\\progect1\\library-system\\src\\main\\resources\\image\\Littleprince.jpeg");
-// Book book6 = new Book("Harry Potter and the Philosopher's Stone","J. K. Rowling",2021,true,200,2,"E:\\ibrahem\\oop\\progect1\\library-system\\src\\main\\resources\\image\\Harry_Potter_and_the_Philosopher's_Stone_Book_Cover.jpg");
-// Book book7 = new Book("And Then There Were None","Agatha Christie",2023,true,200,4,"E:\\ibrahem\\oop\\progect1\\library-system\\src\\main\\resources\\image\\And_Then_There_Were_None_First_Edition_Cover_1939.jpg");
-// Book book8 = new Book("The Hobbit","J. R. R. Tolkien",2020,true,200,3,"E:\\ibrahem\\oop\\progect1\\library-system\\src\\main\\resources\\image\\TheHobbit_FirstEdition.jpg");
-// Book book9 = new Book("She: A History of Adventure","H. Rider Haggard",2021,true,200,2,"E:\\ibrahem\\oop\\progect1\\library-system\\src\\main\\resources\\image\\330px-SHE,_A_History_of_Adventure_(1st_Edition_Cover),_by_H._Rider_Haggard.jpg");
-// Book book10 = new Book("The Da Vinci Code","Dan Brown",2021,true,200,2,"E:\\ibrahem\\oop\\progect1\\library-system\\src\\main\\resources\\image\\DaVinciCode.jpg");
-// addBook(book1);
-// addBook(book2);
-// addBook(book3);
-// addBook(book4);
-// addBook(book5);
-// addBook(book6);
-// addBook(book7);
-// addBook(book8);
-// addBook(book9);
-// addBook(book10);
-// customer.addOrder(book1.getId(),2);
-// customer.addOrder(book2.getId(),2);
-// customer.addOrder(book3.getId(),1);
-// customer.addOrder(book5.getId(),2);
-// customer.addOrder(book7.getId(),2);
-//
-// borrower.addTransaction(book3,2020,2022);
-// borrower.addTransaction(book5,2020,2022);
-// borrower.addTransaction(book9,2020,2022);
-// writeLibrary();
- readLibrary();
+ Book book100 = new Book("Jane Eyre", "Charlotte Bronte", 1847, true, 8
+ , 1, "Orphaned Jane is sent to work as a governess for brooding Mr. Rochester's daughter, Adele. Love begins to grow between Jane and her moody employer, but his mysterious first wife threatens to ruin their chance at happiness."
+ , "D:\\Programming\\Repos\\library-system\\book-covers\\jane_eyre.jpg", new Category[]{Category.HORROR, Category.DRAMA});
+ Book book1 = new Book("Harry Potter and the Prisoner of Azkaban","J. K. Rowling",2023,true,200,4,"A very interesting book", "src/main/resources/image/330px-BlackBeautyCoverFirstEd1877.jpeg", new Category[]{Category.HORROR});
+ Book book2 = new Book("Harry Potter and the Chamber of Secrets","J. K. Rowling",2020,true,200,3,"A very interesting book", "src/main/resources/image/330px-BlackBeautyCoverFirstEd1877.jpeg", new Category[]{Category.ADVENTURE});
+ Book book3 = new Book("The Alchemist ","Paulo Coelho ",2021,true,200,2,"A very interesting book", "src/main/resources/image/330px-BlackBeautyCoverFirstEd1877.jpeg", new Category[]{Category.ADVENTURE});
+ Book book4 = new Book("A Tale of Two Cities","Charles Dickens",2023,true,200,4,"A very interesting book", "src/main/resources/image/330px-BlackBeautyCoverFirstEd1877.jpeg", new Category[]{Category.ADVENTURE});
+ Book book5 = new Book("The Little Prince ","Antoine de Saint-Exupéry",2020,true,200,3,"A very interesting book", "src/main/resources/image/330px-BlackBeautyCoverFirstEd1877.jpeg", new Category[]{Category.ADVENTURE});
+ Book book6 = new Book("Harry Potter and the Philosopher's Stone","J. K. Rowling",2021,true,200,2,"A very interesting book", "src/main/resources/image/330px-BlackBeautyCoverFirstEd1877.jpeg", new Category[]{Category.ADVENTURE});
+ Book book7 = new Book("And Then There Were None","Agatha Christie",2023,true,200,4,"A very interesting book", "src/main/resources/image/330px-BlackBeautyCoverFirstEd1877.jpeg", new Category[]{Category.ADVENTURE});
+ Book book8 = new Book("The Hobbit","J. R. R. Tolkien",2020,true,200,3,"A very interesting book", "src/main/resources/image/330px-BlackBeautyCoverFirstEd1877.jpeg", new Category[]{Category.ADVENTURE});
+ Book book9 = new Book("She: A History of Adventure","H. Rider Haggard",2021,true,200,2,"A very interesting book", "src/main/resources/image/330px-BlackBeautyCoverFirstEd1877.jpeg", new Category[]{Category.ADVENTURE});
+ Book book10 = new Book("The Da Vinci Code","Dan Brown",2021,true,200,2,"A very interesting book", "src/main/resources/image/330px-BlackBeautyCoverFirstEd1877.jpeg", new Category[]{Category.ADVENTURE});
+ Library.addBook(book1);
+ Library.addBook(book2);
+ Library. addBook(book3);
+ Library.addBook(book4);
+ Library.addBook(book5);
+ Library.addBook(book6);
+ Library.addBook(book7);
+ Library.addBook(book8);
+ Library.addBook(book9);
+ Library.addBook(book10);
+
+
+
+ books.add(book100);
+ Library.addBorrower(new Borrower("arsany", "123", "01277535814"));
+ Library.logInByUserName("arsany", "123");
+
launch();
- // Order class testing
-// Book book1 = new Book("book1","author1",2023,true,200,4);
-// Book book2 = new Book("book2","author1",2023,true,200,4);
-// Book book3 = new Book("book3","author1",2023,true,200,4);
-// Order o = new Order(book1, 6);
-// Borrower b1 = new Borrower("hossam","hos", "1999999999");
-// Borrower b2 = new Borrower("hossam","hos", "1060606060");
-// b1.addTransaction(book1,20230519,20231103);
-// b1.addTransaction(book2,20230519,20231003);
-// b2.addTransaction(book3,20220815,20231130);
-// b2.addTransaction(book1,20220815,20231130);
-// b1.deleteTransaction(4);
-// System.out.println("Book Price: " + book1.getPrice());
-// System.out.println("Order Price: " + o.getPrice());
-// System.out.println(b1.finesIfLate());
-// ArrayList b = new ArrayList();
-// b.add(1);
-// b.add(2);
-// b.add(888);
-// b.add(4);
-// b.remove(3);
-//
-// System.out.println(b.get(2));
-//
-// // Testing Cover
-// Book book = new Book("The Old Man And The Sea", "Ernest Hemingway", 1952, true, 200, 0, "book-covers/the_old_man_and_the_sea.jpg");
-// System.out.println(book.getCoverPath());
-//
-// // Testing ReviewHandler
-// ReviewHandler reviewHandler = new ReviewHandler();
-// reviewHandler.addReview(1, 1, 1, "Nice Book");
-// reviewHandler.addReview(2, 1, 1, "");
-// reviewHandler.addReview(3, 1, 1, "");
-// reviewHandler.addReview(4, 1, 1, "");
-// reviewHandler.addReview(5, 1, 1, "Bad Book");
-// reviewHandler.deleteReview(3, 1);
-// ArrayList ratings = reviewHandler.getBookRatings(1);
-// System.out.println(ratings.get(1));
-// System.out.println(reviewHandler.getReviewText(1, 1));
-// System.out.println(reviewHandler.getReviewText(5, 1));
+
}
}
diff --git a/src/main/java/com/asu/librarysystem/MainController.java b/src/main/java/com/asu/librarysystem/MainController.java
index 3a165d5..0c75403 100644
--- a/src/main/java/com/asu/librarysystem/MainController.java
+++ b/src/main/java/com/asu/librarysystem/MainController.java
@@ -1,14 +1,39 @@
package com.asu.librarysystem;
+import javafx.event.ActionEvent;
import javafx.fxml.FXML;
+import javafx.fxml.FXMLLoader;
+import javafx.scene.Node;
+import javafx.scene.Parent;
+import javafx.scene.Scene;
+import javafx.scene.control.Button;
import javafx.scene.control.Label;
+import javafx.stage.Stage;
+
+import java.io.IOException;
+import java.util.Objects;
public class MainController {
@FXML
- private Label welcomeText;
+ Button button;
- @FXML
- protected void onHelloButtonClick() {
- welcomeText.setText("Welcome to JavaFX Application!");
+ private Stage stage;
+ private Scene scene;
+ private Parent root;
+
+ public void pressed(ActionEvent event) {
+ try {
+ FXMLLoader loader = new FXMLLoader(getClass().getResource("book-view.fxml"));
+ Parent root = loader.load();
+
+ BookController bookc = loader.getController();
+ bookc.setScene(MainApplication.books.get(0));
+
+ Scene newScene = new Scene(root);
+ MainApplication.st.setScene(newScene);
+ MainApplication.st.show();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
}
}
\ No newline at end of file
diff --git a/src/main/resources/com/asu/librarysystem/book-view.fxml b/src/main/resources/com/asu/librarysystem/book-view.fxml
new file mode 100644
index 0000000..f3b410a
--- /dev/null
+++ b/src/main/resources/com/asu/librarysystem/book-view.fxml
@@ -0,0 +1,254 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/resources/com/asu/librarysystem/hello-view.fxml b/src/main/resources/com/asu/librarysystem/hello-view.fxml
index 23a7eff..985741c 100644
--- a/src/main/resources/com/asu/librarysystem/hello-view.fxml
+++ b/src/main/resources/com/asu/librarysystem/hello-view.fxml
@@ -1,15 +1,10 @@
-
-
-
+
-
-
-
-
-
-
-
-
+
+
+
+
+