diff --git a/src/main/java/com/mycompany/bookstore/Book.java b/src/main/java/com/mycompany/bookstore/Book.java index 8f2a1c0..d8563c7 100644 --- a/src/main/java/com/mycompany/bookstore/Book.java +++ b/src/main/java/com/mycompany/bookstore/Book.java @@ -35,11 +35,6 @@ public class Book { */ private String details; - /** - * - */ - private int quantity; - /** * */ @@ -58,7 +53,6 @@ public Book() { details = "Empty"; name = "Unknown"; value = -1; - quantity = 0; cover = new javax.swing.ImageIcon(getClass().getResource("/icon50x50.png")); } @@ -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"));; } @@ -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; } @@ -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; - } - /** * */ diff --git a/src/main/java/com/mycompany/bookstore/gui/BookDetails.java b/src/main/java/com/mycompany/bookstore/gui/BookDetails.java index 0c1c4b4..dee0f26 100644 --- a/src/main/java/com/mycompany/bookstore/gui/BookDetails.java +++ b/src/main/java/com/mycompany/bookstore/gui/BookDetails.java @@ -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; @@ -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 entry) { this.store = store; - this.book = book; + this.book = entry.getKey(); initComponents(); @@ -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())); diff --git a/src/main/java/com/mycompany/bookstore/gui/BookList.java b/src/main/java/com/mycompany/bookstore/gui/BookList.java index f0f3b80..1749735 100644 --- a/src/main/java/com/mycompany/bookstore/gui/BookList.java +++ b/src/main/java/com/mycompany/bookstore/gui/BookList.java @@ -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; @@ -25,12 +26,12 @@ public class BookList extends javax.swing.JPanel { /** * Creates new form BookList */ - public BookList(BookStore store, ArrayList books) { + public BookList(BookStore store, HashMap books) { initComponents(); DefaultListModel 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(); diff --git a/src/main/java/com/mycompany/bookstore/gui/BookStoreGUI.java b/src/main/java/com/mycompany/bookstore/gui/BookStoreGUI.java index 5b8afca..630b6d0 100644 --- a/src/main/java/com/mycompany/bookstore/gui/BookStoreGUI.java +++ b/src/main/java/com/mycompany/bookstore/gui/BookStoreGUI.java @@ -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; @@ -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); } diff --git a/src/main/java/com/mycompany/bookstore/gui/CustomerPanel.java b/src/main/java/com/mycompany/bookstore/gui/CustomerPanel.java index 2f76032..34fb23c 100644 --- a/src/main/java/com/mycompany/bookstore/gui/CustomerPanel.java +++ b/src/main/java/com/mycompany/bookstore/gui/CustomerPanel.java @@ -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; /** * @@ -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 hashMap = new HashMap<>(); + for (Book b : customer.getFavorites()) { + hashMap.put(b, 1); + } + starredBooksPane.add(new BookList(store, hashMap)); } /** diff --git a/src/main/java/com/mycompany/bookstore/gui/SupplierPanel.java b/src/main/java/com/mycompany/bookstore/gui/SupplierPanel.java index acf5fd7..8686731 100644 --- a/src/main/java/com/mycompany/bookstore/gui/SupplierPanel.java +++ b/src/main/java/com/mycompany/bookstore/gui/SupplierPanel.java @@ -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; /** * @@ -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); }