-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmsgsView.java
221 lines (170 loc) · 6.15 KB
/
msgsView.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
import java.awt.GridLayout;
import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class msgsView extends JFrame {
private static final long serialVersionUID = 1L;
boolean createNewButtonFlag = false;
boolean statusFlag = true;
boolean toFlag = false;
user userLogged = null;
msgsController L = null;
msgsModel M = null;
homeView homePage = null;
login loginPage = null;
JTable msgs = null;
JTextField nameTF = null;
JTextField surnameTF = null;
JTextField dateTimeTF = null;
JTextField toTF = null;
JTextArea msgTF = null;
JTextField retTF = null;
JComboBox statusTF = null;
JPanel left = null;
public msgsView(user userRef, login loginRef, homeView homeRef){
this.setSize(1000,600); // This is the frame, the numbers are the size of the windows
this.setTitle("Messages"); // Setting the title of the window
this.setVisible(true); // We're saying to the window to show itself
userLogged = userRef;
M = new msgsModel(userLogged, this);
loginPage = loginRef;
homePage = homeRef;
L = new msgsController(M, this, loginPage, homePage);
JMenuBar bar = new JMenuBar(); // Creating a menu bar
this.setJMenuBar(bar);
JMenu file = new JMenu("File"); // Creating a menu tab
bar.add(file); // Sticking the menu tab to the menu bar
JMenuItem logout = new JMenuItem("Logout");
file.add(logout);
logout.addActionListener(L);
logout.setActionCommand("logout");
JMenuItem backHome = new JMenuItem("Back to home");
file.add(backHome);
backHome.addActionListener(L);
backHome.setActionCommand("backHome");
if (userLogged.getType().equals("Receptionist")){
createNewButtonFlag = true;
statusFlag = false;
toFlag = true;
}
this.setLayout(new GridLayout(0,2));
left = new JPanel();
this.add(left);
drawingTable();
JPanel right = new JPanel();
this.add(right);
JLabel nameLabel = new JLabel("Name");
nameTF = new JTextField(10);
JLabel surnameLabel = new JLabel("Surname");
surnameTF = new JTextField(10);
JLabel dateTimeLabel = new JLabel("Date/Time");
dateTimeTF = new JTextField();
JLabel toLabel = new JLabel("To");
toLabel.setVisible(toFlag);
toTF = new JTextField(10);
toTF.setVisible(toFlag);
JLabel msgLabel = new JLabel("Message");
msgTF = new JTextArea(10,10);
JLabel retLabel = new JLabel("Return Number");
retTF = new JTextField(10);
JLabel statusLabel = new JLabel("Status");
statusLabel.setVisible(statusFlag);
String[] statusStrings = { "Read", "Unread" };
statusTF = new JComboBox(statusStrings);
statusTF.setVisible(statusFlag);
JButton createNew = new JButton("Create New");
createNew.setVisible(createNewButtonFlag);
createNew.addActionListener(L);
createNew.setActionCommand("createNew");
JButton save = new JButton("Save");
save.addActionListener(L);
save.setActionCommand("save");
JButton delete = new JButton("Delete");
delete.addActionListener(L);
delete.setActionCommand("delete");
GroupLayout layout = new GroupLayout(right);
right.setLayout(layout);
layout.setAutoCreateGaps(true);
layout.setAutoCreateContainerGaps(true);
layout.setHorizontalGroup(
layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(nameLabel)
.addComponent(surnameLabel)
.addComponent(dateTimeLabel)
.addComponent(toLabel)
.addComponent(msgLabel)
.addComponent(retLabel)
.addComponent(statusLabel))
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(nameTF)
.addComponent(surnameTF)
.addComponent(dateTimeTF)
.addComponent(toTF)
.addComponent(msgTF)
.addComponent(retTF)
.addComponent(statusTF)
.addGroup(layout.createSequentialGroup()
.addComponent(createNew)
.addComponent(save)
.addComponent(delete)))
);
layout.setVerticalGroup(
layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(nameLabel)
.addComponent(nameTF))
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(surnameLabel)
.addComponent(surnameTF))
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(dateTimeLabel)
.addComponent(dateTimeTF))
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(toLabel)
.addComponent(toTF))
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(msgLabel)
.addComponent(msgTF))
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(retLabel)
.addComponent(retTF))
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(statusLabel)
.addComponent(statusTF))
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(createNew)
.addComponent(save)
.addComponent(delete))
);
validate();
repaint();
}
public JTable getTable() {
return msgs;
}
public JComboBox getStatus(){
return statusTF;
}
public void drawingTable(){
left.removeAll();
String[] columnNames = {"ID","Name","Surname","Date/Time","Status"};
Object [][] data = M.queryForView();
msgs = new JTable(data, columnNames);
msgs.getSelectionModel().addListSelectionListener(L);
JScrollPane js=new JScrollPane(msgs);
left.add(js);
left.validate();
left.repaint();
}
}