Skip to content

Commit 2d04b60

Browse files
author
Nasim Bondar Sahebi
committed
package enhancement and updating chaView with chat history.
1 parent 6f727ce commit 2d04b60

File tree

5 files changed

+94
-32
lines changed

5 files changed

+94
-32
lines changed

src/main/java/entities/Chat.java renamed to src/main/java/entities/chat/Chat.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package entities;
1+
package entities.chat;
22
import java.util.ArrayList;
33
// Chat is an abstract class
44
public class Chat {

src/main/java/entities/GroupChat.java renamed to src/main/java/entities/chat/GroupChat.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
package entities;
1+
package entities.chat;
22

33
import java.util.ArrayList;
44

5-
public class GroupChat extends Chat{
5+
public class GroupChat extends Chat {
66

77
/*
88
From Chat, GroupChat has:
9-
String name;
9+
String name;
1010
String chatID;
1111
String senderUsername;
1212
Arraylist<Message> convHist;

src/main/java/entities/PrivateChat.java renamed to src/main/java/entities/chat/PrivateChat.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
package entities;
1+
package entities.chat;
22

33
import java.util.ArrayList;
44

5-
public class PrivateChat extends Chat{
5+
public class PrivateChat extends Chat {
66

77
/*
88
From Chat, PrivateChat has:
@@ -20,15 +20,17 @@ public class PrivateChat extends Chat{
2020
* @param chatID The ID of the chat
2121
* @param senderUsername The user sending the messages
2222
* @param recipientUsername The user receiving the messages
23+
*
2324
*/
24-
public PrivateChat(String name, String chatID, String senderUsername, String recipientUsername){
25+
public PrivateChat(String name, String chatID, String senderUsername, String recipientUsername ){
2526
this.name = name;
2627
this.chatID = chatID;
2728
this.senderUsername = senderUsername;
2829
this.recipientUsername = recipientUsername;
2930
this.convHist = new ArrayList<Message>();
3031
}
3132

33+
3234
/**
3335
* Get the recipient's username
3436
* @return senderRecipient
@@ -40,4 +42,13 @@ public String getRecipientUsername(){
4042
public void setRecipientUsername(String recipientUsername) {
4143
this.recipientUsername= recipientUsername;
4244
}
45+
46+
public String getSendertUsername(){
47+
return this.senderUsername;
48+
}
49+
public String setSendertUsername(String recipientUsername){
50+
this.recipientUsername = recipientUsername;
51+
}
52+
53+
4354
}

src/main/java/chatlinitation/ChatView.java renamed to src/main/java/screens/chat_screen/ChatView.java

Lines changed: 74 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
package chatlinitation;
1+
package screens.chat_screen;
22

33

44
import javax.swing.*;
5+
import javax.swing.border.EmptyBorder;
56

67

78
import java.awt.*;
@@ -15,7 +16,7 @@
1516
* "userB'S username." AT the bottom of the frame, there is another text field to type a message and
1617
* send button to send the message
1718
*
18-
* In the middle of the frame I put andJTextArea for the chat History.
19+
* In the middle of the frame there i sJpanel and Jlabels for the converstaion history.
1920
*
2021
*/
2122

@@ -26,22 +27,32 @@
2627

2728
class ChatView extends JFrame implements ActionListener{
2829

29-
private ChatViewmodel viewmodel;
30+
// private ChatInteractor chatInteractor;
3031
private JFrame frame ;
3132
private JButton addbutton;
32-
private JButton send;
33+
private JButton sendbutton;
3334
private JLabel l;
3435
private JLabel label;
3536
private JTextField usernametextfield;
3637
private JTextField messagetextfield;
3738
private JMenuBar menubar;
3839
private JPanel panel;
39-
private JTextArea textArea;
40+
41+
private JPanel conversationHistoryPanel;
42+
private JPanel messagePanel;
43+
private JLabel testMessageHeader;
44+
private JLabel testMessage;
45+
46+
//isNewchat check we already have a chat with a user
47+
private boolean isNewchat;
48+
4049

4150

4251
//this is constructor od this class
43-
public ChatView(){
44-
viewmodel = new ChatViewmodel();
52+
public ChatView(boolean isNewchat){
53+
54+
this.isNewchat = isNewchat;
55+
4556
frame= new JFrame();
4657

4758
// create a menubar at the top of the frame
@@ -59,7 +70,8 @@ public ChatView(){
5970
addbutton = new JButton("add");
6071
addbutton.setFocusable(false);
6172

62-
73+
// create conversation history-related components
74+
conversationHistoryPanel = new JPanel();
6375

6476
//create a new "panel" and new "label" and a text flied ."label"a nd "txtfield1"
6577
panel = new JPanel();
@@ -68,13 +80,14 @@ public ChatView(){
6880

6981

7082
//adding "send" button
71-
send = new JButton("Send");
72-
send.setFocusable(false);
83+
sendbutton = new JButton("Send");
84+
sendbutton.setFocusable(false);
7385

7486

7587
}
7688

7789

90+
7891
// create a setup for display of buttons and other component of the frame.
7992
public void chatdisplay(){
8093

@@ -94,18 +107,51 @@ public void chatdisplay(){
94107
// adding label and textfiled1 to our panel .
95108
panel.add(label);
96109
panel.add(messagetextfield);
97-
panel.add(send);
110+
panel.add(sendbutton);
111+
112+
98113

114+
// add content to conversationHistoryPanel
115+
conversationHistoryPanel.setLayout(new BoxLayout(conversationHistoryPanel, BoxLayout.Y_AXIS));
116+
117+
// messagePanel = new JPanel();
118+
// messagePanel.setLayout(new BoxLayout(messagePanel, BoxLayout.Y_AXIS));
119+
// testMessageHeader = new JLabel("Username placeholder | Timestamp placeholder");
120+
// testMessage = new JLabel("Message placeholder");
121+
// messagePanel.add(testMessageHeader);
122+
// messagePanel.add(testMessage);
123+
//
124+
// conversationHistoryPanel.add(messagePanel);
125+
126+
JPanel messagePanel1 = new JPanel();
127+
messagePanel1.setLayout(new BoxLayout(messagePanel1, BoxLayout.Y_AXIS));
128+
messagePanel1.setBorder(new EmptyBorder(10, 10, 10, 10));
129+
JLabel testMessageHeader1 = new JLabel("Username placeholder1 | Timestamp placeholder");
130+
JLabel testMessage1 = new JLabel("Message placeholder1");
131+
messagePanel1.add(testMessageHeader1);
132+
messagePanel1.add(testMessage1);
133+
134+
JPanel messagePanel2 = new JPanel();
135+
messagePanel2.setLayout(new BoxLayout(messagePanel2, BoxLayout.Y_AXIS));
136+
messagePanel2.setBorder(new EmptyBorder(10, 10, 10, 10));
137+
JLabel testMessageHeader2 = new JLabel("Username placeholder2 | Timestamp placeholder");
138+
JLabel testMessage2 = new JLabel("Message placeholder2");
139+
messagePanel2.add(testMessageHeader2);
140+
messagePanel2.add(testMessage2);
141+
142+
conversationHistoryPanel.add(messagePanel1);
143+
conversationHistoryPanel.add(messagePanel2);
99144

100145

101-
// set the text part in the middle
102-
textArea = new JTextArea();
103146

104147

105148
//Locating the Components to the frame.
106149
frame.getContentPane().add(BorderLayout.SOUTH, panel);
107-
frame.getContentPane().add(BorderLayout.NORTH, menubar);
108-
frame.getContentPane().add(BorderLayout.CENTER, textArea);
150+
if (isNewchat){
151+
frame.getContentPane().add(BorderLayout.NORTH, menubar);
152+
}
153+
154+
frame.getContentPane().add(BorderLayout.CENTER, conversationHistoryPanel);
109155

110156
// set the frame visibile
111157
frame.setVisible(true);
@@ -127,11 +173,14 @@ public void actionPerformed(ActionEvent e) {
127173

128174

129175
if (e.getSource() == addbutton){
176+
130177
String input = usernametextfield.getText();
178+
131179
frame.setTitle(input);
180+
//controller:
132181

133-
//set the username in our viewmodel
134-
viewmodel.setRecipientUsername(input);
182+
// set the username in our viewmodel
183+
// chatInteractor.setRecipientUsername(input);
135184

136185
//todo
137186
//we should find the user with username "input" from list of user's that have logged in and set the
@@ -148,12 +197,12 @@ public void actionPerformed(ActionEvent e) {
148197

149198
//first is to convert textfield input to String and set the frame title to that input.
150199

151-
if (e.getSource() == send){
200+
if (e.getSource() == sendbutton){
152201
//when the messge type is STring
153202
String input = usernametextfield.getText();
154203

155-
//setting the txtmessage content in our viewmodel
156-
viewmodel.setMessage(input);
204+
// getting the txtmessage content in our viewmodel
205+
// chatInteractor.setMessage(input);
157206

158207
//todo
159208
//this is part of the chatHisroy of UI. for now I put a text ( it may needed to change later)
@@ -164,13 +213,15 @@ public static void main(String args[]) {
164213
EventQueue.invokeLater(new Runnable() {
165214
@Override
166215
public void run() {
167-
ChatView chat = new ChatView();
216+
ChatView chat = new ChatView(true);
217+
// chat.getframe().setTitle("AMMY")
168218
chat.chatdisplay();
169219

170220
chat.addbutton.addActionListener(chat);
221+
chat.sendbutton.addActionListener(chat);
222+
171223
//todo
172-
//after chat history is done next line code can run.
173-
// chat.send.addActionListener(chat);
224+
//chat history
174225

175226

176227
}

src/main/java/chatlinitation/ChatInteractor.java renamed to src/main/java/use_cases/chat_initiation_use_case/ChatInteractor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
package chatlinitation;
1+
package use_cases.chat_initiation_use_case;
22

33

44

5-
import entities.PrivateChat;
5+
import entities.chat.PrivateChat;
66

77
/**
88
* Chatinteractor connects our ChatView UI to our Entities.

0 commit comments

Comments
 (0)