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

Guo zifan stockview #312

Open
wants to merge 53 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
a71aeb0
Logout finished
Re1uy Oct 21, 2024
81dd674
lab 5
Kevin-Xiaoran Oct 21, 2024
a4fc69d
Merge remote-tracking branch 'origin/usecase_logout' into main
Kevin-Xiaoran Oct 21, 2024
f5eddd8
Update README.md
Kevin-Xiaoran Nov 4, 2024
c528689
test
ryanjin333 Nov 4, 2024
ec1bb01
Merge pull request #3 from Kevin-Xiaoran/ryanjin1
Kevin-Xiaoran Nov 4, 2024
5a79dd2
Merge pull request #2 from Kevin-Xiaoran/Kevin-Xiaoran-update-readme
zifanguo2004 Nov 4, 2024
e10fe60
Test
Re1uy Nov 4, 2024
31fb9ba
Merge pull request #4 from Kevin-Xiaoran/Ziming-Huang
zifanguo2004 Nov 4, 2024
dfc348e
Update README.md
Kevin-Xiaoran Nov 4, 2024
758dfd4
Merge pull request #5 from Kevin-Xiaoran/Kevin-Xiaoran-patch-1
Kevin-Xiaoran Nov 4, 2024
8ddb5e5
Update README.md
Kevin-Xiaoran Nov 4, 2024
0581005
Merge pull request #6 from Kevin-Xiaoran/Kevin-Xiaoran-patch-2
ryanjin333 Nov 4, 2024
9206962
finish early version of home view
Kevin-Xiaoran Nov 7, 2024
e4cf0ea
Complete the view of WatchList Demo
Re1uy Nov 8, 2024
7334dfa
Merge pull request #7 from Kevin-Xiaoran/Ziming-Huang
Re1uy Nov 8, 2024
e575cc4
Deleted unused codes
Re1uy Nov 8, 2024
0fe5d0c
Merge pull request #8 from Kevin-Xiaoran/Ziming-Huang
Re1uy Nov 8, 2024
afbd82b
Add the return button to home page for WatchList
Re1uy Nov 8, 2024
25e0c84
Merge pull request #9 from Kevin-Xiaoran/Ziming-Huang
Re1uy Nov 8, 2024
3610af5
Logout Feature
Ta0p1 Nov 10, 2024
ec432c8
Merge pull request #10 from Kevin-Xiaoran/huan4066-logout
Ta0p1 Nov 10, 2024
cbf53f5
Adjust UI of homepage(Especially sign up).
Ta0p1 Nov 10, 2024
cf3b587
Merge pull request #11 from Kevin-Xiaoran/huan4066-signup
Ta0p1 Nov 10, 2024
f247a43
Improve the logout function.
Ta0p1 Nov 10, 2024
ebd22b9
Merge pull request #12 from Kevin-Xiaoran/huan4066-logout
Ta0p1 Nov 10, 2024
6a192d7
Add cancel button for signup and login
Re1uy Nov 11, 2024
ac4333e
Merge pull request #13 from Kevin-Xiaoran/Ziming-Huang
Re1uy Nov 11, 2024
95a8a41
configure .gitignore file
Kevin-Xiaoran Nov 11, 2024
0851346
Add AbstractViewWithBackButton view
Kevin-Xiaoran Nov 11, 2024
a91676e
Merge pull request #14 from Kevin-Xiaoran/kairanzh-home-view
Ta0p1 Nov 11, 2024
9761d0f
first demo
zifanguo2004 Nov 11, 2024
04ba0eb
part of stock view done
zifanguo2004 Nov 11, 2024
d791397
first demo
zifanguo2004 Nov 14, 2024
319a8b3
Finish GetStock method to get today stock information. source from ap…
Re1uy Nov 14, 2024
b9c3b4b
Merge pull request #15 from Kevin-Xiaoran/Ziming-Huang
Kevin-Xiaoran Nov 15, 2024
ff91b1f
Modify watchlist database
Kevin-Xiaoran Nov 15, 2024
d6104c0
Update .gitignore
Kevin-Xiaoran Nov 15, 2024
81a751d
Merge branch 'main' into kairanzh-home-view
Kevin-Xiaoran Nov 15, 2024
d5f55b2
fix stock entity data types
Kevin-Xiaoran Nov 15, 2024
d29f782
Portfolio view finished design
ryanjin333 Nov 15, 2024
5050e1c
add get/set watchlist method for DataAccess
Kevin-Xiaoran Nov 16, 2024
9953e87
fix bugs for watchListDataAccessObject
Kevin-Xiaoran Nov 16, 2024
cecd1af
Merge pull request #16 from Kevin-Xiaoran/kairanzh-home-view
Re1uy Nov 16, 2024
1f6b687
Merge pull request #17 from Kevin-Xiaoran/guozifan-stock-view
Kevin-Xiaoran Nov 16, 2024
4a9dcf7
Merge pull request #18 from Kevin-Xiaoran/ryanjin1-portfolio
Kevin-Xiaoran Nov 16, 2024
17f3c74
add portfolio data getter/setter
Kevin-Xiaoran Nov 16, 2024
dd1466e
push missing files
Kevin-Xiaoran Nov 16, 2024
79271ac
fix conflicts
Kevin-Xiaoran Nov 16, 2024
3e25a01
Merge pull request #20 from Kevin-Xiaoran/kairanzh-home-view
Re1uy Nov 16, 2024
9370a63
Pass data from HomeView to StockView
Kevin-Xiaoran Nov 16, 2024
37fd94f
Merge pull request #21 from Kevin-Xiaoran/kairanzh-home-view
Re1uy Nov 16, 2024
a7246f8
small edit
zifanguo2004 Nov 16, 2024
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
17 changes: 16 additions & 1 deletion src/main/java/app/AppBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@
import interface_adapter.login.LoginViewModel;
import interface_adapter.logout.LogoutController;
import interface_adapter.logout.LogoutPresenter;
import interface_adapter.portfolio.PortfolioViewModel;
import interface_adapter.signup.SignupController;
import interface_adapter.signup.SignupPresenter;
import interface_adapter.signup.SignupViewModel;
import interface_adapter.watchlist_view.WatchListViewModel;
import interface_adapter.portfolio.PortfolioViewModel;
import use_case.change_password.ChangePasswordInputBoundary;
import use_case.change_password.ChangePasswordInteractor;
import use_case.change_password.ChangePasswordOutputBoundary;
Expand Down Expand Up @@ -77,6 +79,8 @@ public class AppBuilder {
private StockView stockView;
private WatchListView watchListView;
private WatchListViewModel watchListViewModel;
private PortfolioView portfolioView;
private PortfolioViewModel portfolioViewModel;

public AppBuilder() {
cardPanel.setLayout(cardLayout);
Expand Down Expand Up @@ -137,13 +141,24 @@ public AppBuilder addWatchListView() {
return this;
}

/**
* Adds the Portfolio View to the application.
* @return this builder
*/
public AppBuilder addPortfolioView() {
portfolioViewModel = new PortfolioViewModel();
portfolioView = new PortfolioView(portfolioViewModel, viewManagerModel);
cardPanel.add(portfolioView, portfolioView.getViewName());
return this;
}

/**
* Adds the Home Use Case to the application.
* @return this builder
*/
public AppBuilder addHomeUseCase() {
final HomeOutputBoundary homeOutputBoundary = new HomePresenter(homeViewModel,
loginViewModel, signupViewModel, viewManagerModel);
loginViewModel, signupViewModel, viewManagerModel, portfolioViewModel);
final HomeInputBoundary homeInteractor = new HomeInteractor(userDataAccessObject, homeOutputBoundary);

final HomeController controller = new HomeController(homeInteractor);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/app/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public static void main(String[] args) {
.addLoginUseCase()
.addLogoutUseCase()
.addChangePasswordUseCase()
.addPortfolioView()
.build();

application.pack();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void search(String symbol) {
}

/**
* Executes the "switch to LoginView" Use Case.
* Executes the "switch to Portfolio" Use Case.
*/
public void switchToPortfolio() {
homeUseCaseInteractor.switchToPortfolio();
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/interface_adapter/home_view/HomePresenter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import interface_adapter.ViewManagerModel;
import interface_adapter.login.LoginViewModel;
import interface_adapter.portfolio.PortfolioViewModel;
import interface_adapter.signup.SignupViewModel;
import use_case.home_view.HomeOutputBoundary;
import use_case.home_view.HomeOutputData;
Expand All @@ -16,17 +17,20 @@ public class HomePresenter implements HomeOutputBoundary {
private final LoginViewModel loginViewModel;
private final SignupViewModel signupViewModel;
private final ViewManagerModel viewManagerModel;
private final PortfolioViewModel portfolioViewModel;

private static final String WATCHLIST_VIEW_NAME = "WatchListView";

public HomePresenter(HomeViewModel homeViewModel,
LoginViewModel loginViewModel,
SignupViewModel signupViewModel,
ViewManagerModel viewManagerModel) {
ViewManagerModel viewManagerModel,
PortfolioViewModel portfolioViewModel) {
this.homeViewModel = homeViewModel;
this.loginViewModel = loginViewModel;
this.signupViewModel = signupViewModel;
this.viewManagerModel = viewManagerModel;
this.portfolioViewModel = portfolioViewModel;
}

@Override
Expand All @@ -43,7 +47,8 @@ public void prepareFailView(String errorMessage) {

@Override
public void switchToPortfolio() {
System.out.println("Show portfolio view");
viewManagerModel.setState("PortfolioView");
viewManagerModel.firePropertyChanged();
}

@Override
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/interface_adapter/portfolio/PortfolioViewModel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package interface_adapter.portfolio;

import java.util.ArrayList;
import java.util.List;

/**
* The View Model for the Portfolio View.
*/

public class PortfolioViewModel {
private List<String[]> stockList;

public PortfolioViewModel() {
this.stockList = new ArrayList<>();
}

public List<String[]> getStockList() {
return stockList;
}

public void setStockList(List<String[]> stockList) {
this.stockList = stockList;
}

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

import interface_adapter.ViewManagerModel;
import interface_adapter.portfolio.PortfolioViewModel;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

import javax.swing.border.Border;
import javax.swing.BorderFactory;


public class PortfolioView extends JPanel {

private final ViewManagerModel viewManagerModel;

public PortfolioView(PortfolioViewModel viewModel, ViewManagerModel viewManagerModel) {
this.viewManagerModel = viewManagerModel;
setLayout(new BorderLayout());
setBackground(Color.WHITE);

// panel setup
final JPanel statisticsPanel = new JPanel();
statisticsPanel.setLayout(new BoxLayout(statisticsPanel, BoxLayout.Y_AXIS));
statisticsPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 20, 10));
statisticsPanel.setBackground(Color.WHITE);

// Container for return button and current amount
final JPanel topRowPanel = new JPanel();
topRowPanel.setLayout(new BoxLayout(topRowPanel, BoxLayout.Y_AXIS));
topRowPanel.setBackground(Color.WHITE);

// Return button
final JButton backButton = new JButton("←");
backButton.setFont(new Font("SansSerif", Font.PLAIN, 20));
backButton.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
backButton.setFocusPainted(false);
backButton.setContentAreaFilled(false);

backButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {

// Sample action, replace with your own logic
viewManagerModel.setState("home view");
viewManagerModel.firePropertyChanged();
}
});

// Current amount
final JLabel currentAmount = new JLabel("$12345");
currentAmount.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0));
currentAmount.setFont(new Font("SansSerif", Font.PLAIN, 20));

// Add return button and current amount to the top row
topRowPanel.add(backButton);
topRowPanel.add(Box.createRigidArea(new Dimension(0, 2)));
topRowPanel.add(currentAmount);

// Create a sub-panel with BorderLayout
final JPanel mainPanel = new JPanel(new BorderLayout());
mainPanel.setBackground(Color.WHITE);

// Add top row panel to the left side (WEST)
mainPanel.add(topRowPanel, BorderLayout.WEST);

// Dummy value on the right side (EAST)
final JLabel dummyValue = new JLabel("");
dummyValue.setFont(new Font("SansSerif", Font.PLAIN, 16));
mainPanel.add(dummyValue, BorderLayout.EAST);

// Add topRowPanel to statisticsPanel
statisticsPanel.add(mainPanel);

// portfolio amount changes
percentChangeLayout(statisticsPanel, "Today", "+$44.09", "+24.10%");
percentChangeLayout(statisticsPanel, "All Time", "+$84.09", "+40.10%");
add(statisticsPanel, BorderLayout.NORTH);

// Create the content panel
final JPanel contentPanel = new JPanel();
contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS));
contentPanel.setBackground(Color.WHITE);

// Create a sub-panel with BorderLayout
final JPanel titlePanel = new JPanel(new BorderLayout());
titlePanel.setBackground(Color.WHITE);

// Portfolio title on the left
final JLabel portfolioTitle = new JLabel("Portfolio");
portfolioTitle.setFont(new Font("SansSerif", Font.BOLD, 24));
portfolioTitle.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
titlePanel.add(portfolioTitle, BorderLayout.WEST);

// Dummy text on the right
final JLabel dummyLabel = new JLabel("");
dummyLabel.setFont(new Font("SansSerif", Font.PLAIN, 16));
dummyLabel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
titlePanel.add(dummyLabel, BorderLayout.EAST);

// Add the sub-panel to the main content panel
contentPanel.add(titlePanel);

addStockItem(contentPanel, "AAPL", "$226.97", "−$0.26", "+0.11%", "+$44.09", "+24.10%");
addStockItem(contentPanel, "COST", "$953.20", "+$39.27", "+4.30%", "+$386.00", "+68.03%");
addStockItem(contentPanel, "QQQ", "$514.07", "+$0.56", "+0.60%", "+$141.25", "+37.87%");

add(contentPanel, BorderLayout.CENTER);
}

private void percentChangeLayout(JPanel statisticsPanel, String title, String totalChange, String totalPercentage) {
final JPanel displayPanel = new JPanel(new BorderLayout());
displayPanel.setBackground(Color.WHITE);
displayPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0));

// Left part: Title
final JPanel leftPanel = new JPanel();
leftPanel.setLayout(new BoxLayout(leftPanel, BoxLayout.Y_AXIS));
leftPanel.setBackground(Color.WHITE);

final JLabel titleLabel = new JLabel(title);
titleLabel.setFont(new Font("SansSerif", Font.BOLD, 24));

leftPanel.add(titleLabel);

// Right part: up and down information
final JPanel rightPanel = new JPanel();
rightPanel.setLayout(new BoxLayout(rightPanel, BoxLayout.Y_AXIS));
rightPanel.setBackground(Color.WHITE);
rightPanel.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 10));

final JLabel totalChangeLabel = new JLabel(totalChange + "(" + totalPercentage + ")");
totalChangeLabel.setFont(new Font("SansSerif", Font.PLAIN, 16));

rightPanel.add(totalChangeLabel);

// Add all to displayPanel
displayPanel.add(leftPanel, BorderLayout.WEST);
displayPanel.add(rightPanel, BorderLayout.EAST);

// Add all information
statisticsPanel.add(displayPanel);
}

private void addStockItem(JPanel contentPanel, String code, String price, String dailyChange, String dailyPercentage, String totalChange, String totalPercentage) {
final JPanel stockPanel = new JPanel(new BorderLayout());
stockPanel.setBackground(Color.WHITE);
// Create a matte border and an empty border
final Border matteBorder = BorderFactory.createMatteBorder(0, 0, 1, 0, Color.LIGHT_GRAY);
final Border emptyBorder = BorderFactory.createEmptyBorder(0, 30, 0, 0);

// Combine them using CompoundBorder
final Border combinedBorder = BorderFactory.createCompoundBorder(emptyBorder, matteBorder);

// Set the combined border
stockPanel.setBorder(combinedBorder);

// Left part: Stock code and price
final JPanel leftPanel = new JPanel();
leftPanel.setLayout(new BoxLayout(leftPanel, BoxLayout.Y_AXIS));
leftPanel.setBackground(Color.WHITE);

final JLabel stockCodeLabel = new JLabel(code);
stockCodeLabel.setFont(new Font("SansSerif", Font.BOLD, 24));
stockCodeLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0));
final JLabel stockPriceLabel = new JLabel(price);
stockPriceLabel.setFont(new Font("SansSerif", Font.PLAIN, 18));

leftPanel.add(stockCodeLabel);
leftPanel.add(stockPriceLabel);

// Right part: up and down information
final JPanel rightPanel = new JPanel();
rightPanel.setLayout(new BoxLayout(rightPanel, BoxLayout.Y_AXIS));
rightPanel.setBackground(Color.WHITE);
rightPanel.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 10));

final JLabel dailyChangeLabel = new JLabel(dailyChange + "(" + dailyPercentage + ")");
dailyChangeLabel.setFont(new Font("SansSerif", Font.PLAIN, 16));
dailyChangeLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0));

final JLabel totalChangeLabel = new JLabel(totalChange + "(" + totalPercentage + ")");
totalChangeLabel.setFont(new Font("SansSerif", Font.PLAIN, 16));
totalChangeLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0));

rightPanel.add(dailyChangeLabel);
rightPanel.add(totalChangeLabel);

// Add all to stockPanel
stockPanel.add(leftPanel, BorderLayout.WEST);
stockPanel.add(rightPanel, BorderLayout.EAST);

// Add all information
contentPanel.add(stockPanel);
}

public String getViewName() {
return "PortfolioView";
}
}