Skip to content

Commit 7cff5f1

Browse files
committed
changed creation screen so that it used the existing user's username
1 parent 3399002 commit 7cff5f1

File tree

3 files changed

+112
-111
lines changed

3 files changed

+112
-111
lines changed

src/main/java/create_flashcardset_use_case/CreationScreen.java

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package create_flashcardset_use_case;
22

3+
import loginAndSignupUseCase.UserLoginResponseModel;
4+
35
import javax.swing.*;
46
import java.awt.*;
57
import java.awt.event.ActionEvent;
@@ -8,7 +10,7 @@
810

911
// Frameworks/Drivers (Blue) layer
1012

11-
public class CreationScreen extends JPanel implements ActionListener {
13+
public class CreationScreen extends JFrame implements ActionListener {
1214
/**
1315
* The title of the flashcard set chosen by the user
1416
*/
@@ -17,30 +19,26 @@ public class CreationScreen extends JPanel implements ActionListener {
1719
* The description of the flashcard set
1820
*/
1921
JTextField description = new JTextField(15);
20-
/**
21-
* The owner's username of the flashcard set
22-
*/
23-
JTextField username = new JTextField(15);
22+
// /**
23+
// * The owner's username of the flashcard set
24+
// */
25+
// JTextField username = new JTextField(15);
2426

2527
/**
2628
* The controller
2729
*/
2830
FlashcardSetController flashcardSetController;
2931

30-
/**
31-
* The application
32-
*/
33-
JFrame application; // need this variable to only close the application and not the whole program
32+
UserLoginResponseModel user;
3433

3534
private boolean privateSelected; // for public or private status of flashcard set
3635

3736
/**
3837
* A window with a title and a JButton.
3938
*/
40-
public CreationScreen(FlashcardSetController controller, JFrame application) {
41-
39+
public CreationScreen(FlashcardSetController controller, UserLoginResponseModel user) {
40+
this.user = user;
4241
this.flashcardSetController = controller;
43-
this.application = application;
4442

4543
JLabel name = new JLabel("Flashcard Set Creation Screen");
4644
name.setAlignmentX(Component.CENTER_ALIGNMENT);
@@ -49,8 +47,8 @@ public CreationScreen(FlashcardSetController controller, JFrame application) {
4947
new JLabel("Title:"), title);
5048
LabelTextPanel flashcardSetDescription = new LabelTextPanel(
5149
new JLabel("Description:"), description);
52-
LabelTextPanel flashcardSetOwner = new LabelTextPanel(
53-
new JLabel("Owner (username):"), username);
50+
// LabelTextPanel flashcardSetOwner = new LabelTextPanel(
51+
// new JLabel("Owner (username):"), username);
5452

5553
JButton signUp = new JButton("Create");
5654
JButton cancel = new JButton("Cancel");
@@ -67,14 +65,17 @@ public CreationScreen(FlashcardSetController controller, JFrame application) {
6765
privacyButton.add(privacy);
6866
privacy.addActionListener(this);
6967

70-
this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
68+
getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
7169

7270
this.add(name);
7371
this.add(flashcardSetTitle);
7472
this.add(flashcardSetDescription);
75-
this.add(flashcardSetOwner);
73+
// this.add(flashcardSetOwner);
7674
this.add(privacy);
7775
this.add(confirmationButtons);
76+
77+
this.setVisible(true);
78+
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
7879
}
7980

8081
/**
@@ -85,16 +86,16 @@ public void actionPerformed(ActionEvent evt) {
8586

8687
// Exit the creation screen if user cancels creation
8788
if (Objects.equals(evt.getActionCommand(), "Cancel")) {
88-
application.dispose();
89+
this.dispose();
8990
} else if (Objects.equals(evt.getActionCommand(), "Set as Private")) {
9091
privateSelected = !privateSelected; // toggle every time clicked
9192
} else {
9293
try {
9394
flashcardSetController.create(title.getText(), description.getText(),
94-
privateSelected, username.getText());
95+
privateSelected, user.getSignedInUsername());
9596
JOptionPane.showMessageDialog(this,
9697
String.format("Flashcard Set: [%s] created.", title.getText()));
97-
application.dispose(); // exit creation screen
98+
this.dispose(); // exit creation screen
9899
} catch (FlashcardSetCreationFailed e) {
99100
JOptionPane.showMessageDialog(this, e.getMessage());
100101

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,54 @@
1-
package create_flashcardset_use_case;
2-
3-
import dataAccess.*;
4-
import entities.FlashcardSetFactory;
5-
6-
import javax.swing.*;
7-
import java.awt.*;
8-
import java.io.IOException;
9-
10-
public class MainCreateFlashcardSet {
11-
12-
public static void main(String[] args) {
13-
14-
// Build the main program window
15-
JFrame application = new JFrame("Create a Flashcard Set");
16-
application.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
17-
CardLayout cardLayout = new CardLayout();
18-
JPanel screens = new JPanel(cardLayout);
19-
application.add(screens);
20-
21-
// Create the parts to plug into the Use Case+Entities engine
22-
DBGateway dbGateway = dbGatewaySetup();
23-
24-
FlashcardSetOutputBoundary outputBoundary = new FlashcardSetPresenter();
25-
FlashcardSetFactory flashcardSetFactory = new FlashcardSetFactory();
26-
FlashcardSetInputBoundary interactor = new FlashcardSetInteractor(dbGateway, outputBoundary,
27-
flashcardSetFactory);
28-
FlashcardSetController flashcardSetController = new FlashcardSetController(
29-
interactor
30-
);
31-
32-
// Build the GUI, plugging in the parts
33-
CreationScreen creationScreen = new CreationScreen(flashcardSetController, application);
34-
screens.add(creationScreen, "welcome");
35-
cardLayout.show(screens, "create flashcard set");
36-
application.pack();
37-
application.setVisible(true);
38-
}
39-
40-
public static DBGateway dbGatewaySetup() {
41-
IFlashcardSetDataAccess flashcardSetRepo;
42-
IFlashcardDataAccess flashcardRepo;
43-
IUserDataAccess userRepo;
44-
try {
45-
flashcardSetRepo = new FlashcardSetDataAccess("src/data/FlashcardSets.csv");
46-
flashcardRepo = new FlashcardDataAccess("src/data/Flashcards.csv");
47-
userRepo = new CommonUserDataAccess("src/data/Users.csv");
48-
} catch (IOException e) {
49-
throw new RuntimeException("Could not create file.");
50-
}
51-
52-
return new DBGateway(flashcardRepo, flashcardSetRepo, userRepo);
53-
}
54-
}
1+
//package create_flashcardset_use_case;
2+
//
3+
//import dataAccess.*;
4+
//import entities.FlashcardSetFactory;
5+
//
6+
//import javax.swing.*;
7+
//import java.awt.*;
8+
//import java.io.IOException;
9+
//
10+
//public class MainCreateFlashcardSet {
11+
//
12+
// public static void main(String[] args) {
13+
//
14+
// // Build the main program window
15+
// JFrame application = new JFrame("Create a Flashcard Set");
16+
// application.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
17+
// CardLayout cardLayout = new CardLayout();
18+
// JPanel screens = new JPanel(cardLayout);
19+
// application.add(screens);
20+
//
21+
// // Create the parts to plug into the Use Case+Entities engine
22+
// DBGateway dbGateway = dbGatewaySetup();
23+
//
24+
// FlashcardSetOutputBoundary outputBoundary = new FlashcardSetPresenter();
25+
// FlashcardSetFactory flashcardSetFactory = new FlashcardSetFactory();
26+
// FlashcardSetInputBoundary interactor = new FlashcardSetInteractor(dbGateway, outputBoundary,
27+
// flashcardSetFactory);
28+
// FlashcardSetController flashcardSetController = new FlashcardSetController(
29+
// interactor
30+
// );
31+
//
32+
// // Build the GUI, plugging in the parts
33+
// CreationScreen creationScreen = new CreationScreen(flashcardSetController);
34+
// screens.add(creationScreen, "welcome");
35+
// cardLayout.show(screens, "create flashcard set");
36+
// application.pack();
37+
// application.setVisible(true);
38+
// }
39+
//
40+
// public static DBGateway dbGatewaySetup() {
41+
// IFlashcardSetDataAccess flashcardSetRepo;
42+
// IFlashcardDataAccess flashcardRepo;
43+
// IUserDataAccess userRepo;
44+
// try {
45+
// flashcardSetRepo = new FlashcardSetDataAccess("src/data/FlashcardSets.csv");
46+
// flashcardRepo = new FlashcardDataAccess("src/data/Flashcards.csv");
47+
// userRepo = new CommonUserDataAccess("src/data/Users.csv");
48+
// } catch (IOException e) {
49+
// throw new RuntimeException("Could not create file.");
50+
// }
51+
//
52+
// return new DBGateway(flashcardRepo, flashcardSetRepo, userRepo);
53+
// }
54+
//}
Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
1-
package delete_flashcardset_use_case;
2-
3-
import create_flashcardset_use_case.MainCreateFlashcardSet;
4-
import dataAccess.*;
5-
6-
import javax.swing.*;
7-
import java.awt.*;
8-
import java.io.IOException;
9-
import java.util.concurrent.atomic.AtomicReference;
10-
11-
public class MainDeleteFlashcardSet {
12-
13-
public static void main(String[] args) {
14-
15-
// Build the main program window
16-
JFrame application = new JFrame("Delete a Flashcard Set");
17-
application.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
18-
AtomicReference<CardLayout> cardLayout = new AtomicReference<>(new CardLayout());
19-
JPanel screens = new JPanel(cardLayout.get());
20-
application.add(screens);
21-
22-
// Create the parts to plug into the Use Case+Entities engine
23-
DBGateway dbGateway = MainCreateFlashcardSet.dbGatewaySetup();
24-
DelFlashcardSetOutputBoundary outputBoundary = new DelFlashcardSetPresenter();
25-
DelFlashcardSetInputBoundary interactor = new DelFlashcardSetInteractor(dbGateway, outputBoundary);
26-
DelFlashcardSetController controller = new DelFlashcardSetController(
27-
interactor
28-
);
29-
30-
// Build the GUI, plugging in the parts
31-
int flashcardSetId = 0; // placeholder id of the flashcard set to be deleted
32-
DeletionScreen deletionScreen = new DeletionScreen(flashcardSetId, controller, application);
33-
screens.add(deletionScreen, "welcome");
34-
cardLayout.get().show(screens, "delete flashcard set");
35-
application.pack();
36-
application.setVisible(true);
37-
}
38-
}
1+
//package delete_flashcardset_use_case;
2+
//
3+
//import create_flashcardset_use_case.MainCreateFlashcardSet;
4+
//import dataAccess.*;
5+
//
6+
//import javax.swing.*;
7+
//import java.awt.*;
8+
//import java.io.IOException;
9+
//import java.util.concurrent.atomic.AtomicReference;
10+
//
11+
//public class MainDeleteFlashcardSet {
12+
//
13+
// public static void main(String[] args) {
14+
//
15+
// // Build the main program window
16+
// JFrame application = new JFrame("Delete a Flashcard Set");
17+
// application.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
18+
// AtomicReference<CardLayout> cardLayout = new AtomicReference<>(new CardLayout());
19+
// JPanel screens = new JPanel(cardLayout.get());
20+
// application.add(screens);
21+
//
22+
// // Create the parts to plug into the Use Case+Entities engine
23+
// DBGateway dbGateway = MainCreateFlashcardSet.dbGatewaySetup();
24+
// DelFlashcardSetOutputBoundary outputBoundary = new DelFlashcardSetPresenter();
25+
// DelFlashcardSetInputBoundary interactor = new DelFlashcardSetInteractor(dbGateway, outputBoundary);
26+
// DelFlashcardSetController controller = new DelFlashcardSetController(
27+
// interactor
28+
// );
29+
//
30+
// // Build the GUI, plugging in the parts
31+
// int flashcardSetId = 0; // placeholder id of the flashcard set to be deleted
32+
// DeletionScreen deletionScreen = new DeletionScreen(flashcardSetId, controller, application);
33+
// screens.add(deletionScreen, "welcome");
34+
// cardLayout.get().show(screens, "delete flashcard set");
35+
// application.pack();
36+
// application.setVisible(true);
37+
// }
38+
//}

0 commit comments

Comments
 (0)