-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainDesign.java
More file actions
279 lines (240 loc) · 8.71 KB
/
MainDesign.java
File metadata and controls
279 lines (240 loc) · 8.71 KB
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
package speedmatch;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.beans.PropertyChangeListener;
import java.io.*;
public class MainDesign extends JFrame {
public MainDesign() {
initGUI();
}
private String[] eventarr = new String[0];
private int lselect = -1; // Selected Item Index
private int dirchange = 0; // Dummy, indicates if user specified directory
private String dir = ""; // Dummy for directory
public void setArr(String dir) {
try {
if (dirchange == 0) {
this.eventarr = Processing.getDatingsDir();
} else {
this.eventarr = Processing.getDatingsDir(dir);
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Error: " + e.getMessage(), "ERROR", JOptionPane.ERROR_MESSAGE);
}
}
public void initGUI() {
// Creating Panel
JPanel panel = new JPanel(new GridBagLayout());
panel.setOpaque(false);
this.getContentPane().add(panel);
this.getContentPane().setBackground(new Color(255, 229, 204));
setExtendedState(JFrame.MAXIMIZED_BOTH);
// Title and Subtitle
JLabel title = new JLabel("Welcome to SpeedMatch!");
title.setForeground(new Color(250, 92, 92));
title.setFont(new Font("Arial", Font.BOLD, 40));
JLabel subtitle = new JLabel("To begin, please select an existing event or create a new one");
subtitle.setForeground(new Color(250, 92, 92));
subtitle.setFont(new Font("Arial", Font.BOLD, 25));
// Seperator
JSeparator sep = new JSeparator();
sep.setPreferredSize(new Dimension(500, 20));
// Labels
JLabel label = new JLabel("Saved Speeddating Events");
label.setForeground(new Color(250, 92, 92));
label.setFont(new Font("Arial", Font.BOLD + Font.ITALIC, 15));
// Buttons
JPanel pagePanel = new JPanel();
pagePanel.setOpaque(false);
JButton next = new JButton("Next >");
pagePanel.add(next);
next.setEnabled(false);
JButton exit = new JButton("Exit");
pagePanel.add(exit);
// List of Events
setArr("");
DefaultListModel<String> dlm = new DefaultListModel<String>();
for (int i = 0; i < eventarr.length; i++) {
dlm.addElement(eventarr[i].substring(0, (eventarr[i].length() - 4)));
}
JList<String> list = new JList<String>(dlm);
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
// Buttons
JPanel eventPanel = new JPanel();
eventPanel.setOpaque(false);
JButton newEvent = new JButton("Create new event");
eventPanel.add(newEvent);
JButton changeDir = new JButton("Change Directory");
eventPanel.add(changeDir);
JButton edit = new JButton("Edit");
eventPanel.add(edit);
edit.setEnabled(false);
JButton delete = new JButton("Delete");
eventPanel.add(delete);
delete.setEnabled(false);
JButton servermode = new JButton("Change to Server Mode");
eventPanel.add(servermode);
// Action Listener for List
ListSelectionModel lsm = list.getSelectionModel();
lsm.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
if (e.getValueIsAdjusting() == false) {
lselect = list.getSelectedIndex();
next.setEnabled(true);
delete.setEnabled(true);
edit.setEnabled(true);
}
}
});
// Action Listener for Change Directory
changeDir.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
final JFileChooser fc = new JFileChooser();
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
// if (e.getSource() == changeDir) {
int returnVal = fc.showOpenDialog(MainDesign.this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File dirselect = fc.getSelectedFile();
dir = dirselect.getAbsolutePath();
char sep = '/';
if (Processing.detectOS().equals("Windows")) {
sep = '\\';
}
dir += sep;
dirchange = 1;
setArr(dir);
dlm.removeAllElements();
for (int i = 0; i < eventarr.length; i++) {
dlm.addElement(eventarr[i].substring(0, (eventarr[i].length() - 4)));
}
}
}
});
// Action Listener for new Event
newEvent.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
NewEvent NewEventWindow = new NewEvent(dirchange, dir, eventarr);
NewEventWindow.setVisible(true);
dispose();
}
});
// Action Listener for Exit
exit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dispose();
}
});
// Action Listener for Next
next.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Dating d;
try {
if (dirchange == 0) {
d = (Dating) Processing.readDatingFromWD(eventarr[lselect]);
} else {
d = (Dating) Processing.readDating(dir + eventarr[lselect]);
}
ParticipantPage pp = new ParticipantPage(d, dirchange, dir);
pp.setVisible(true);
dispose();
} catch (Exception ex) {
JOptionPane.showMessageDialog(MainDesign.this, ex.getMessage(), "ERROR while opening file",
JOptionPane.ERROR_MESSAGE);
}
}
});
// ActionListener for Delete
delete.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int askdelete = JOptionPane.showConfirmDialog(MainDesign.this,
"Are you sure you want to permanently delete " + eventarr[lselect] + "? This cannot be undone.",
"Delete Speeddating", JOptionPane.INFORMATION_MESSAGE);
if (askdelete == JOptionPane.YES_OPTION) {
if (dirchange == 0) {
Processing.deleteFile(eventarr[lselect]);
} else {
Processing.deleteFile(dir, eventarr[lselect]);
}
setArr(dir);
dlm.removeAllElements();
for (int i = 0; i < eventarr.length; i++) {
dlm.addElement(eventarr[i].substring(0, (eventarr[i].length() - 4)));
}
}
}
});
// ActionListener for Edit
edit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
EditWindow ew = new EditWindow(eventarr[lselect], dir, dirchange);
ew.setVisible(true);
}
});
// ActionListener for Servermode
servermode.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ServerConfig sc = new ServerConfig();
sc.setVisible(true);
dispose();
}
});
// GridBagConstraints
// Adding
/*
* GridBagConstraints gbc = new GridBagConstraints(); gbc.fill =
* GridBagConstraints.HORIZONTAL; gbc.gridwidth = GridBagConstraints.RELATIVE;
*
* gbc.gridx = 0; gbc.gridy = 0; gbc.ipady = 20; gbc.anchor =
* GridBagConstraints.PAGE_START; panel.add(title, gbc);
*
* gbc.gridx = 0; gbc.gridy = 1; panel.add(subtitle, gbc);
*
* gbc.gridx = 0; gbc.gridy = 2; panel.add(sep, gbc);
*
* gbc.gridx = 0; gbc.gridy = 3; panel.add(label, gbc);
*
* gbc.gridx = 0; gbc.gridy = 4; panel.add(new JScrollPane(list), gbc);
*
* gbc.gridx = 0; gbc.gridy = 5; gbc.insets = new Insets(10,0,0,0);
* panel.add(eventPanel, gbc);
*
* gbc.gridx = 0; gbc.gridy = 6; gbc.gridwidth = 5; panel.add(pagePanel, gbc);
*
* this.pack();
*
* this.setVisible(true);
*/
panel.add(title, new GridBagConstraints(1, 0, 2, 1, 0.0, 0.0, GridBagConstraints.PAGE_START,
GridBagConstraints.VERTICAL, new Insets(20, 0, 20, 0), 0, 0));
panel.add(subtitle, new GridBagConstraints(1, 1, GridBagConstraints.REMAINDER, 1, 0.0, 0.0,
GridBagConstraints.PAGE_START, GridBagConstraints.VERTICAL, new Insets(0, 0, 10, 0), 0, 0));
panel.add(sep, new GridBagConstraints(0, 2, GridBagConstraints.REMAINDER, 1, 0.0, 0.0,
GridBagConstraints.PAGE_START, GridBagConstraints.VERTICAL, new Insets(0, 0, 30, 0), 0, 0));
panel.add(label, new GridBagConstraints(0, 3, GridBagConstraints.REMAINDER, 1, 0.0, 0.0,
GridBagConstraints.PAGE_START, GridBagConstraints.VERTICAL, new Insets(30, 0, 10, 0), 0, 0));
JScrollPane sp = new JScrollPane(list);
sp.setMinimumSize(new Dimension(300, 200));
panel.add(sp, new GridBagConstraints(0, 4, GridBagConstraints.REMAINDER, 1, 0.0, 0.0,
GridBagConstraints.PAGE_START, GridBagConstraints.VERTICAL, new Insets(10, 0, 30, 0), 0, 0));
panel.add(eventPanel, new GridBagConstraints(0, 5, GridBagConstraints.REMAINDER, 1, 0.0, 0.0,
GridBagConstraints.PAGE_START, GridBagConstraints.VERTICAL, new Insets(30, 0, 30, 0), 0, 0));
panel.add(pagePanel, new GridBagConstraints(0, 6, GridBagConstraints.REMAINDER, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.VERTICAL, new Insets(50, 0, 20, 0), 0, 0));
this.pack();
this.setVisible(true);
}
public static void main(String[] args) {
File f = new File(Processing.getHomeDir());
if (!f.exists()) {
f.mkdir();
}
MainDesign frame = new MainDesign();
frame.pack();
frame.setVisible(true);
frame.setTitle("SpeedDating - MatchFinder");
// frame.setSize(800, 700);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}