Skip to content

Commit

Permalink
Refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrystianMelo committed Jun 12, 2024
1 parent 9879d5e commit a47f22d
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 39 deletions.
25 changes: 1 addition & 24 deletions src/main/java/com/mycompany/bookstore/Book.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ public class Book {
*/
private String details;

/**
*
*/
private int quantity;

/**
*
*/
Expand All @@ -58,7 +53,6 @@ public Book() {
details = "Empty";
name = "Unknown";
value = -1;
quantity = 0;
cover = new javax.swing.ImageIcon(getClass().getResource("/icon50x50.png"));
}

Expand All @@ -75,7 +69,6 @@ public Book(int id, String name, float value, String details) {
this.details = details;
this.name = name;
this.value = value;
this.quantity = 1;
this.cover = new javax.swing.ImageIcon(getClass().getResource("/icon50x50.png"));;
}

Expand All @@ -86,15 +79,13 @@ public Book(int id, String name, float value, String details) {
* @param name Nome do livro.
* @param value Valor do livro.
* @param details Detalhes do livro.
* @param quantity Quantidade de livro.
* @param cover Capa do livro.
*/
public Book(int id, String name, float value, String details, int quantity, ImageIcon cover) {
public Book(int id, String name, float value, String details, ImageIcon cover) {
this.id = id;
this.details = details;
this.name = name;
this.value = value;
this.quantity = quantity;
this.cover = cover;
}

Expand Down Expand Up @@ -179,20 +170,6 @@ public void setDetails(String details) {
this.details = details;
}

/**
*
*/
public int getQuantity() {
return quantity;
}

/**
*
*/
public void setQuantity(int quantity) {
this.quantity = quantity;
}

/**
*
*/
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/com/mycompany/bookstore/gui/BookDetails.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand All @@ -34,9 +35,9 @@ public class BookDetails extends javax.swing.JPanel {
/**
* Creates new form BookDetails
*/
public BookDetails(BookStore store, Book book) {
public BookDetails(BookStore store, Map.Entry<Book, Integer> entry) {
this.store = store;
this.book = book;
this.book = entry.getKey();

initComponents();

Expand All @@ -62,7 +63,7 @@ public void mouseClicked(MouseEvent e) {
});

titleLabel.setText(book.getName());
quantityLabel.setText(String.valueOf(book.getQuantity()));
quantityLabel.setText(String.valueOf(entry.getValue()));
supplierLabel.setText("By Amazon");
valueLabel1.setText(String.valueOf(book.getValue()));

Expand Down
9 changes: 5 additions & 4 deletions src/main/java/com/mycompany/bookstore/gui/BookList.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import javax.swing.DefaultListModel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;
Expand All @@ -25,12 +26,12 @@ public class BookList extends javax.swing.JPanel {
/**
* Creates new form BookList
*/
public BookList(BookStore store, ArrayList<Book> books) {
public BookList(BookStore store, HashMap<Book, Integer> books) {
initComponents();

DefaultListModel<BookDetails> listModel = new DefaultListModel<>();
for (Book b : books) {
listModel.addElement(new BookDetails(store, b));
for (Map.Entry entry : books.entrySet()) {
listModel.addElement(new BookDetails(store, entry));
}

FlowLayout layoyt = new FlowLayout();
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/mycompany/bookstore/gui/BookStoreGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -143,7 +142,7 @@ public void mouseClicked(MouseEvent e) {
dialog.setLocationRelativeTo(BookStoreGUI.this);
dialog.setLayout(new FlowLayout());
dialog.setSize(500, 400);
dialog.add(new BookList(store, new ArrayList<>(customer.getCart().getBooks().keySet())));
dialog.add(new BookList(store, customer.getCart().getBooks()));

dialog.setVisible(true);
}
Expand Down
12 changes: 9 additions & 3 deletions src/main/java/com/mycompany/bookstore/gui/CustomerPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
*/
package com.mycompany.bookstore.gui;

import com.mycompany.bookstore.Book;
import com.mycompany.bookstore.BookStore;
import com.mycompany.bookstore.Customer;
import java.awt.FlowLayout;
import java.util.ArrayList;
import java.util.HashMap;

/**
*
Expand All @@ -21,11 +22,16 @@ public CustomerPanel(BookStore store) {
initComponents();

allBooksPane.setLayout(new FlowLayout());
allBooksPane.add(new BookList(store, new ArrayList<>(store.getAvailableBooks().keySet())));
allBooksPane.add(new BookList(store, store.getAvailableBooks()));

starredBooksPane.setLayout(new FlowLayout());

Customer customer = (Customer) store.getUser();
starredBooksPane.add(new BookList(store, customer.getFavorites()));
HashMap<Book, Integer> hashMap = new HashMap<>();
for (Book b : customer.getFavorites()) {
hashMap.put(b, 1);
}
starredBooksPane.add(new BookList(store, hashMap));
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/mycompany/bookstore/gui/SupplierPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.mycompany.bookstore.BookStore;
import com.mycompany.bookstore.Supplier;
import java.awt.FlowLayout;
import java.util.ArrayList;
import java.util.HashMap;

/**
*
Expand All @@ -21,12 +21,12 @@ public SupplierPanel(BookStore store) {
initComponents();

salesPane.setLayout(new FlowLayout());
BookList bookList1 = new BookList(store, new ArrayList<>());
BookList bookList1 = new BookList(store, new HashMap<>());
salesPane.add(bookList1);

stockPane.setLayout(new FlowLayout());
Supplier supplier = (Supplier) store.getUser();
BookList bookList2 = new BookList(store, new ArrayList<>(supplier.getEstoque().keySet()));
BookList bookList2 = new BookList(store, supplier.getEstoque());
stockPane.add(bookList2);
}

Expand Down

0 comments on commit a47f22d

Please sign in to comment.