Skip to content

Commit

Permalink
Merge pull request #6 from ChrystianMelo/origin/gui
Browse files Browse the repository at this point in the history
#4 Finished the GUI development
  • Loading branch information
ChrystianMelo authored Jun 8, 2024
2 parents f74e173 + 5636a31 commit 109ae25
Show file tree
Hide file tree
Showing 24 changed files with 1,662 additions and 162 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
target/

*.jar
*.jar
*.patch
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
<version>5.6.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.netbeans.external</groupId>
<artifactId>AbsoluteLayout</artifactId>
<version>RELEASE210</version>
</dependency>
</dependencies>

<properties>
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/com/mycompany/bookstore/BookStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
*/
public class BookStore {

/**
* Usuário
*/
private User user;

/**
* Lista de clientes da livraria.
*/
Expand All @@ -28,6 +33,8 @@ public class BookStore {
public BookStore() {
costumers = new ArrayList<>();
suppliers = new ArrayList<>();

recoverUser();
}

/**
Expand Down Expand Up @@ -86,6 +93,13 @@ public void setCostumers(ArrayList<Customer> costumers) {
this.costumers = costumers;
}

/**
* Retorna o usuário.
*/
public User getUser() {
return user;
}

/**
* Obtém a lista de fornecedores da livraria.
*
Expand Down Expand Up @@ -145,4 +159,12 @@ public HashMap<Book, Integer> getAvailableBooks() {

return availableBooks;
}

/**
* Pendente API banco de dados
*/
public User recoverUser() {
return new Customer("username", "Costumer Name", new Address("Street", 123, "Neighborhood", "City", "State", "Country", "Complement"));
//return new Supplier("username", "Supplier Name", new Address("Street", 123, "Neighborhood", "City", "State", "Country", "Complement"));
}
}
164 changes: 3 additions & 161 deletions src/main/java/com/mycompany/bookstore/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
*/
package com.mycompany.bookstore;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Scanner;
import com.mycompany.bookstore.gui.BookStoreGUI;

/**
*
Expand All @@ -19,162 +16,7 @@ public class Main {
public static void main(String[] args) {
BookStore bookStore = new BookStore();

boolean finish = false;
while (!finish) {
System.out.println("-------------------------------------------------");
System.out.println("Você deseja rodar como Cliente ou Vendedor.\n \t1-Cliente 2-Vendedor");

Scanner ler = new Scanner(System.in);
int option = ler.nextInt();
switch (option) {
case 1:
runAsClient(bookStore);
break;
case 2:
runAsSupplier(bookStore);
break;
default:
System.out.println("ERROR");
finish = true;
break;
}
}
}

/**
*
*/
private static void runAsClient(BookStore bookStore) {
System.out.println("---------------------Cadastro/Login----------------------------");
System.out.println("Digite seu username:");
Scanner scanner = new Scanner(System.in);
String username = scanner.next();

Customer costumer = (Customer) retrieveUser(bookStore, username);
if (costumer == null) {
System.out.println("---------------------Cadastro----------------------------");
Address address = new Address("Street", 123, "Neighborhood", "City", "State", "Country", "Complement");
costumer = new Customer(username, "Costumer Name", address);
try {
bookStore.addCostumer(costumer);
} catch (Exception ex) {
System.out.println("ERROR");
}
}

HashMap<Book, Integer> availableBooks = bookStore.getAvailableBooks();
print(availableBooks);

System.out.println("-------------------------------------------------");
System.out.println("\t1-Adiciona libro ao carrinho \t2-Ver carrinho");
int option = scanner.nextInt();

switch (option) {
case 1:
System.out.println("-------------------------------------------------");
System.out.println("Diga o indice do livro que vc quer comprar e a quantidade?");
int bookID = scanner.nextInt();
int quantity = scanner.nextInt();

Book requested = (Book) availableBooks.keySet().toArray()[bookID - 1];

try {
costumer.addBook(requested, quantity);
} catch (Exception ex) {
System.out.println("ERROR");
}

break;

case 2:
print(costumer.getCart().getBooks());
break;
default:
break;
}
}

/**
*
*/
private static void runAsSupplier(BookStore bookStore) {
System.out.println("---------------------Cadastro/Login----------------------------");
System.out.println("Digite seu username:");
Scanner scanner = new Scanner(System.in);
String username = scanner.next();

Supplier supplier = (Supplier) retrieveUser(bookStore, username);
if (supplier == null) {
System.out.println("---------------------Cadastro----------------------------");
Address address = new Address("Street", 123, "Neighborhood", "City", "State", "Country", "Complement");
supplier = new Supplier(username, "Supplier Name", address);
try {
bookStore.addSupplier(supplier);
} catch (Exception ex) {
System.out.println("ERROR");
}
}

System.out.println("-------------------------------------------------");
System.out.println("Vc quer adicionar ou remover um livro? \n\t1-Adicionar 2-Remover");
int option = scanner.nextInt();

switch (option) {
case 1:
System.out.println("Qual o nome do livro?");
String name = scanner.next();
Book book = new Book(1, name, 19.99f, "Details");
System.out.println("Qual a quantidade disponivel?");
int quantity = scanner.nextInt();

try {
supplier.registerBook(book, quantity);
} catch (Exception ex) {
System.out.println("ERORR");
}

break;

case 2:
System.out.println("Qual o nome do livro?");
name = scanner.next();

book = null;
for (Book b : supplier.getEstoque().keySet()) {
if (name.equals(b.getName())) {
book = b;
}
}

supplier.deleteBook(book);
break;
default:
break;
}
}

private static User retrieveUser(BookStore bookStore, String username) {
User user = null;

for (User u : bookStore.getCostumers()) {
if (username.equals(u.getUsername())) {
user = u;
break;
}
}

return user;
}

private static void print(HashMap<Book, Integer> books) {
System.out.println("-------------------------------------------------");
int count = 0;
Iterator it = books.entrySet().iterator();
while (it.hasNext()) {
Map.Entry entry = (Map.Entry) it.next();
Book book = (Book) entry.getKey();
count++;
System.out.println((count) + " : " + book.getName() + " (" + entry.getValue() + ") " + "\t R$" + book.getValue());
}
BookStoreGUI gui = new BookStoreGUI(bookStore);
gui.setVisible(true);
}
}
138 changes: 138 additions & 0 deletions src/main/java/com/mycompany/bookstore/gui/BookDetails.form
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
<?xml version="1.0" encoding="UTF-8" ?>

<Form version="1.8" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
<Properties>
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[500, 50]"/>
</Property>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[500, 50]"/>
</Property>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[500, 50]"/>
</Property>
</Properties>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
<AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,0,50,0,0,1,-12"/>
</AuxValues>
<SubComponents>
<Component class="javax.swing.JLabel" name="coverImgLabel">
<Properties>
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
<Image iconType="3" name="/icon50x50.png"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="titleLabel">
<Properties>
<Property name="text" type="java.lang.String" value="TitleTitleTitleTitleTitleTitleTitleTitleTitleTitleTitleTitleTitleTitleTitleTitleTitle"/>
</Properties>
</Component>
</SubComponents>
<LayoutCode>
<CodeStatement>
<CodeExpression id="1_flowLayout1">
<CodeVariable name="flowLayout1" type="4096" declaredType="java.awt.FlowLayout"/>
<ExpressionOrigin>
<ExpressionProvider type="CodeConstructor">
<CodeConstructor class="java.awt.FlowLayout" parameterTypes="int, int, int"/>
</ExpressionProvider>
<Parameters>
<CodeExpression id="2">
<ExpressionOrigin>
<Value type="int" value="3"/>
</ExpressionOrigin>
</CodeExpression>
<CodeExpression id="3">
<ExpressionOrigin>
<Value type="int" value="10"/>
</ExpressionOrigin>
</CodeExpression>
<CodeExpression id="4">
<ExpressionOrigin>
<Value type="int" value="0"/>
</ExpressionOrigin>
</CodeExpression>
</Parameters>
</ExpressionOrigin>
</CodeExpression>
<StatementProvider type="CodeExpression">
<CodeExpression id="1_flowLayout1"/>
</StatementProvider>
<Parameters>
<CodeExpression id="2"/>
<CodeExpression id="3"/>
<CodeExpression id="4"/>
</Parameters>
</CodeStatement>
<CodeStatement>
<CodeExpression id="1_flowLayout1"/>
<StatementProvider type="CodeMethod">
<CodeMethod name="setAlignOnBaseline" class="java.awt.FlowLayout" parameterTypes="boolean"/>
</StatementProvider>
<Parameters>
<CodeExpression id="5">
<ExpressionOrigin>
<Value type="boolean" value="true"/>
</ExpressionOrigin>
</CodeExpression>
</Parameters>
</CodeStatement>
<CodeStatement>
<CodeExpression id="6">
<ExpressionOrigin>
<ExpressionProvider type="ComponentRef">
<ComponentRef name="."/>
</ExpressionProvider>
</ExpressionOrigin>
</CodeExpression>
<StatementProvider type="CodeMethod">
<CodeMethod name="setLayout" class="java.awt.Container" parameterTypes="java.awt.LayoutManager"/>
</StatementProvider>
<Parameters>
<CodeExpression id="1_flowLayout1"/>
</Parameters>
</CodeStatement>
<CodeStatement>
<CodeExpression id="6"/>
<StatementProvider type="CodeMethod">
<CodeMethod name="add" class="java.awt.Container" parameterTypes="java.awt.Component"/>
</StatementProvider>
<Parameters>
<CodeExpression id="7_coverImgLabel">
<CodeVariable name="coverImgLabel" type="8194" declaredType="javax.swing.JLabel"/>
<ExpressionOrigin>
<ExpressionProvider type="ComponentRef">
<ComponentRef name="coverImgLabel"/>
</ExpressionProvider>
</ExpressionOrigin>
</CodeExpression>
</Parameters>
</CodeStatement>
<CodeStatement>
<CodeExpression id="6"/>
<StatementProvider type="CodeMethod">
<CodeMethod name="add" class="java.awt.Container" parameterTypes="java.awt.Component"/>
</StatementProvider>
<Parameters>
<CodeExpression id="8_titleLabel">
<CodeVariable name="titleLabel" type="8194" declaredType="javax.swing.JLabel"/>
<ExpressionOrigin>
<ExpressionProvider type="ComponentRef">
<ComponentRef name="titleLabel"/>
</ExpressionProvider>
</ExpressionOrigin>
</CodeExpression>
</Parameters>
</CodeStatement>
</LayoutCode>
</Form>
Loading

0 comments on commit 109ae25

Please sign in to comment.