Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[*] Improved the add entry dialog and added support for splitter entry. #90

Merged
merged 1 commit into from
Dec 5, 2022
Merged
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: 0 additions & 2 deletions src/main/java/billgates/Main.java
Original file line number Diff line number Diff line change
@@ -30,8 +30,6 @@
*/
public class Main {

public static final String DATETIME_PATTERN = "yyyy-MM-dd HH:mm:ss";

public static void main(String[] args) {
try {
UIManager.setLookAndFeel(new MetalLookAndFeel());
14 changes: 7 additions & 7 deletions src/main/java/billgates/database/MySQLDatabaseGateway.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package billgates.database;

import billgates.Main;
import billgates.entities.Entry;
import billgates.entities.EntryBuilder;
import billgates.entities.QueryUserData;
import billgates.entities.SplitterEntry;
import billgates.interface_adapters.DatabaseGateway;
import billgates.view.BillGatesUtilities;

import java.io.FileInputStream;
import java.io.IOException;
@@ -169,7 +169,7 @@ public List<SplitterEntry> getSplitBillData(int splitBillId) {
@Override
public List<Entry> getBillData(int billId, ZonedDateTime startDate, ZonedDateTime endDate) {
List<Entry> entries = new ArrayList<>();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(Main.DATETIME_PATTERN);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(BillGatesUtilities.DATETIME_PATTERN);

try {
Statement statement = connection.createStatement();
@@ -324,7 +324,7 @@ public SplitterEntry getSplitEntryData(int billId, int entryId) {
@Override
public void insertEntry(int billId, Entry entry) {
try {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(Main.DATETIME_PATTERN);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(BillGatesUtilities.DATETIME_PATTERN);

Statement statement = connection.createStatement();

@@ -377,7 +377,7 @@ public void insertEntry(int billId, Entry entry) {
@Override
public void insertSplitEntry(int billId, SplitterEntry entry) {
try {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(Main.DATETIME_PATTERN);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(BillGatesUtilities.DATETIME_PATTERN);

Statement statement = connection.createStatement();

@@ -421,7 +421,7 @@ public void insertSplitEntry(int billId, SplitterEntry entry) {
entry.getTo().getAttribute(),
entry.getLocation().getAttribute(),
entry.getPayee().getAttribute(),
entry.getIsPaidBack().getAttribute());
entry.getIsPaidBack().getAttribute() ? "1" : "0");
}

statement.execute(query);
@@ -563,7 +563,7 @@ public void modifySplitEntry(int billId, int entryId, String column, String newV
@Override
public void modifyEntry(int billId, Entry entry) {
try {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(Main.DATETIME_PATTERN);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(BillGatesUtilities.DATETIME_PATTERN);

Statement statement = connection.createStatement();

@@ -601,7 +601,7 @@ public void modifyEntry(int billId, Entry entry) {
@Override
public void modifySplitEntry(int billId, SplitterEntry entry) {
try {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(Main.DATETIME_PATTERN);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(BillGatesUtilities.DATETIME_PATTERN);

Statement statement = connection.createStatement();

Original file line number Diff line number Diff line change
@@ -60,7 +60,7 @@ public interface DatabaseGateway {
*
* @param splitBillId the splitBillId that we wish to query
* @return a list of SplitterEntry objects
* @see billgates.entities.SplitterEntry
* @see SplitterEntry
*/
List<SplitterEntry> getSplitBillData(int splitBillId);

@@ -72,7 +72,7 @@ public interface DatabaseGateway {
* @param startDate a ZonedDateTime object that marks the start date of this query
* @param endDate a ZonedDateTime object that marks the end date of this query
* @return a list of Entry that is within the specified date range
* @see billgates.entities.Entry
* @see Entry
*/
List<Entry> getBillData(int billId, ZonedDateTime startDate, ZonedDateTime endDate);

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package billgates.use_cases.bill_update;

import billgates.Main;
import billgates.interface_adapters.BillPanelUpdatable;
import billgates.view.BillGatesUtilities;

import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
@@ -47,7 +47,7 @@ public void updateBill(BillUpdateResponseModel model) {
// format dates
for (List<Object> list : entries) {
ZonedDateTime date = (ZonedDateTime) list.get(1);
String formatted = date.format(DateTimeFormatter.ofPattern(Main.DATETIME_PATTERN));
String formatted = date.format(DateTimeFormatter.ofPattern(BillGatesUtilities.DATETIME_PATTERN));
list.set(1, formatted);
}
String[] columns;
Original file line number Diff line number Diff line change
@@ -109,4 +109,12 @@ public String getPayee() {
public boolean getIsPaidBack() {
return this.isPaidBack;
}

public void setPayee(String payee) {
this.payee = payee;
}

public void setPaidBack(boolean paidBack) {
isPaidBack = paidBack;
}
}
42 changes: 42 additions & 0 deletions src/main/java/billgates/view/BillGatesUtilities.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package billgates.view;

import java.util.*;

public class BillGatesUtilities {

public static final String DATETIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
public static final String TIME_PATTERN = "HH:mm:ss";

static {
CURRENCY_CODES = getCurrencyCodes();
}

/**
* A list of all available currency codes of the current JVM.
* It starts with CAD, CNY, and USD; and follows by all currency codes sorted by ascending
* alphabetical order.
*/
public static final List<String> CURRENCY_CODES;

/**
* Gets a list of available currency codes according to ISO 3166.
* Notes: CAD, CNY, USD are the top three currencies.
*
* @return a list of currency codes sorted in ascending alphabetical order with CAD, CNY,
* and USD at the beginning.
*/
public static List<String> getCurrencyCodes() {
ScottCTD marked this conversation as resolved.
Show resolved Hide resolved
List<String> result = new ArrayList<>(Arrays.asList("CAD", "CNY", "USD"));
List<String> temp = new ArrayList<>();
for (Locale locale : Locale.getAvailableLocales()) {
try {
temp.add(Currency.getInstance(locale).getCurrencyCode());
} catch (IllegalArgumentException ignore) {
}
}
Collections.sort(temp);
result.addAll(temp);
return result;
}

}
22 changes: 22 additions & 0 deletions src/main/java/billgates/view/gui/ActionComboBox.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package billgates.view.gui;

import javax.swing.*;
import java.awt.*;
import java.util.List;

public class ActionComboBox<E> extends JComboBox<E> {

public static final int DEFAULT_FONT_SIZE = 14;
public static final Font DEFAULT_FONT = new FontSettings(DEFAULT_FONT_SIZE);

public ActionComboBox() {
super();
this.setFont(DEFAULT_FONT);
}

public ActionComboBox(List<E> elements) {
this();
elements.forEach(this::addItem);
}

}
13 changes: 3 additions & 10 deletions src/main/java/billgates/view/gui/ActionPanel.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package billgates.view.gui;

import billgates.Main;
import billgates.interface_adapters.UserJoinUpdatable;
import billgates.use_cases.insert_entry.InsertEntryRequestModel;
import billgates.use_cases.user_join.UserJoinViewModel;

import javax.swing.*;
import javax.swing.border.TitledBorder;
import java.awt.*;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Objects;

/**
@@ -219,13 +215,10 @@ private void backFromSplit() {

private void addEntry() {
AddEntryDialog addEntryDialog = new AddEntryDialog(this.mainFrame);
InsertEntryRequestModel model = addEntryDialog.exec();

if (addEntryDialog.getResult() == 0) {
InsertEntryRequestModel model = new InsertEntryRequestModel(addEntryDialog.getDate(),
addEntryDialog.getValue(), addEntryDialog.getCurrency(), addEntryDialog.getDescription(),
addEntryDialog.getFrom(), addEntryDialog.getTo(), addEntryDialog.getLocationText());
if (model != null) {
this.mainFrame.getInsertEntryController().insert(model);

// after adding the entry, update the current bill
SwingUtilities.invokeLater(() -> this.mainFrame.getBillUpdateController().update(-1));
}
20 changes: 20 additions & 0 deletions src/main/java/billgates/view/gui/ActionTextField.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package billgates.view.gui;

import javax.swing.*;
import java.awt.*;

public class ActionTextField extends JTextField {

public static final int DEFAULT_FONT_SIZE = 14;
public static final Font DEFAULT_FONT = new FontSettings(DEFAULT_FONT_SIZE);

public ActionTextField(int columns) {
super(columns);
this.setFont(DEFAULT_FONT);
}

public ActionTextField(String text, int columns) {
this(columns);
this.setText(text);
}
}
Loading