-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGUIMain.java
executable file
·444 lines (364 loc) · 14.1 KB
/
GUIMain.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
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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
import java.awt.BorderLayout;
import java.awt.CheckboxMenuItem;
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.List;
import java.awt.Menu;
import java.awt.MenuBar;
import java.awt.MenuItem;
import java.awt.Panel;
import java.awt.Polygon;
import java.awt.TextArea;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import javax.swing.DefaultListCellRenderer;
import javax.swing.Icon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.ListCellRenderer;
/*
* Version 2.0
* Matthias Guenther
* Hauptprogramm - simply the best
*/
public class GUIMain {
public TextArea myTextArea;
public TextField absender, empfaenger, empfaengerCC, subject;
public Panel buttonPanel;
public Menu file, accounts, kontenMenu, info;
public MenuItem saveItem, exit, accountnew, accountedit, readmail,
writemail, accountavailable, managelocalfiles;
public CheckboxMenuItem autoSave;
public JLabel edit;
public MenuBar menucomplete;
public List postList;
public List editalbeAccounts;
// write in the konto dates of user and will be overwritten everytime the
// account changes
public static String[] userInfos = new String[7];
// to save the current data of the user
public static String userTmpInfos = "";
private JFrame mainframe, frameEditable;
public File[] files;
public static File f = new File(
"/home/helex/NetBeansProjects/Test2/src/");
public static String dir = "/home/helex/NetBeansProjects/Test2/src/";
public String currentUserDir = "";
// display main-frame of the client
public void createMainFrame() {
mainframe = new JFrame("Email-Client");
mainframe.setVisible(false);
mainframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainframe.setSize(800, 600);
// user can change the size of the window
mainframe.setResizable(true);
// create the file menu
file = new Menu("File");
readmail = new MenuItem("Read Emails");
file.add(readmail);
readmail.addActionListener(new ReadMailListener());
writemail = new MenuItem("Write Email");
file.add(writemail);
writemail.addActionListener(new WriteMailListener());
file.addSeparator();
managelocalfiles = new MenuItem("Manage Emails");
managelocalfiles.addActionListener(new MangeMailsListener());
file.add(managelocalfiles);
file.addSeparator();
exit = new MenuItem("Quit");
file.add(exit);
exit.addActionListener(new ExitItemListener());
info = new Menu("Info");
info.add("Info");
info.addActionListener(new InfoListener());
menucomplete = new MenuBar();
menucomplete.add(file);
menucomplete.add(accounts);
menucomplete.add(info);
mainframe.setMenuBar(menucomplete);
mainframe.setVisible(true);
}
// the fucking Listeners
class InfoListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
Frame test = new JFrame("Mail-Client Infos");
JPanel aboutPanel = new JPanel();
aboutPanel.setLayout(new GridLayout(4, 1));
test.setSize(400, 200);
JLabel about = new JLabel(
"Mail-Client: Designt by Matthias Guenther");
JLabel about1 = new JLabel("Version: 2.0");
JLabel about2 = new JLabel("Contact: [email protected]");
JLabel about3 = new JLabel(
"Performed in the 'Programmierpraktikum 2, SS 2007'");
aboutPanel.add(about);
aboutPanel.add(about1);
aboutPanel.add(about2);
aboutPanel.add(about3);
test.add(aboutPanel);
test.setVisible(true);
}
}
class ReadMailListener implements ActionListener {
public void actionPerformed(ActionEvent arg0) {
GUIMailsget test = new GUIMailsget();
test.guiMailsget();
}
}
class WriteMailListener implements ActionListener {
public void actionPerformed(ActionEvent arg0) {
GUIMailsend send = new GUIMailsend();
send.guiMailsend();
}
}
class ExitItemListener implements ActionListener {
public void actionPerformed(ActionEvent arg0) {
System.exit(0);
}
}
class NewAccountListener implements ActionListener {
public void actionPerformed(ActionEvent arg0) {
GUIKontoInformation test = new GUIKontoInformation();
test.GUIKontoInformationCreate();
}
}
class MangeMailsListener implements ActionListener {
public void actionPerformed(ActionEvent arg0) {
try {
GUITreeInsert treeFrame = new GUITreeInsert();
treeFrame.setSize(400, 400);
treeFrame.setVisible(true);
} catch (Exception e) {
System.out.println(e);
}
}
}
// to list alle available Accounts
public void searchAccounts(File dir) throws IOException {
files = dir.listFiles();
accounts = new Menu("Account(s)");
accountnew = new MenuItem("New Account");
accountnew.addActionListener(new NewAccountListener());
accountedit = new MenuItem("Edit Account");
accountedit.addActionListener(new EditAccountListener());
accounts.add(accountnew);
accounts.add(accountedit);
accounts.addSeparator();
if (files != null) {
for (int i = 0; i < files.length; i++) {
String tmp = files[i].getAbsolutePath();
if (tmp.endsWith("kondat")) {
String tmpinfos = "";
FileReader f = new FileReader(tmp);
for (int c; (c = f.read()) != -1;) {
tmpinfos = tmpinfos + (char) c;
}
userInfos = tmpinfos.split("#######");
accountavailable = new MenuItem(userInfos[1]);
accountavailable.addActionListener(new accountlistener());
accounts.add(accountavailable);
}
}
}
}
class accountlistener implements ActionListener {
public void actionPerformed(ActionEvent e) {
// dirty cast to get name of the Label
String name = ((MenuItem) e.getSource()).getLabel();
FileReader file = null;
String tmp = "";
try {
file = new FileReader(dir + name + " kontoinfos.kondat");
for (int c; (c = file.read()) != -1;) {
tmp = tmp + (char) c;
}
userInfos = tmp.split("#######");
} catch (IOException es) {
System.out.println("Error reading file!");
} finally {
try {
file.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
}
class EditAccountListener implements ActionListener {
public void actionPerformed(ActionEvent arg0) {
try {
editableAccounts(f);
} catch (IOException e) {
e.printStackTrace();
}
}
}
// to list all available editable accounts
public void editableAccounts(File dir) throws IOException {
frameEditable = new JFrame("Editable Accounts");
editalbeAccounts = new List();
frameEditable.setSize(200, 200);
frameEditable.setLayout(new BorderLayout());
edit = new JLabel("Available Accounts: ");
frameEditable.add(edit, "North");
JPanel tmpe = new JPanel();
files = dir.listFiles();
if (files != null) {
for (int i = 0; i < files.length; i++) {
String tmp = files[i].getAbsolutePath();
if (tmp.endsWith("kondat")) {
String tmpinfos = "";
FileReader f = new FileReader(tmp);
for (int c; (c = f.read()) != -1;) {
tmpinfos = tmpinfos + (char) c;
}
userInfos = tmpinfos.split("#######");
editalbeAccounts.add(userInfos[1]);
tmpe.add(editalbeAccounts, "Center");
}
}
}
editalbeAccounts.addItemListener(new EditListener());
frameEditable.add(tmpe);
frameEditable.setVisible(true);
}
class EditListener implements ItemListener {
public void itemStateChanged(ItemEvent e) {
String tmp2[] = e.getSource().toString().split("=");
String tmp1 = tmp2[1].replace("]", "");
FileReader file = null;
String tmp = "";
try {
file = new FileReader(
"/home/helex/NetBeansProjects/Test2/src/" + tmp1 + " kontoinfos.kondat");
for (int c; (c = file.read()) != -1;) {
tmp = tmp + (char) c;
}
userInfos = tmp.split("#######");
} catch (IOException es) {
System.out.println("Error reading file!");
} finally {
try {
file.close();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
// close the editableAccount frame
frameEditable.setVisible(false);
System.out.println(userInfos[0]);
GUIKontoInformation test = new GUIKontoInformation();
test.emailadressinput.setText(userInfos[0]);
test.usernameinput.setText(userInfos[1]);
test.uservalidationnameinput.setText(userInfos[2]);
test.userpassinput.setText(userInfos[3]);
test.postentranceinput.setText(userInfos[4]);
test.postexitinput.setText(userInfos[6]);
test.GUIKontoInformationCreate();
}
}
// needed for the class GUIMailsget
class ComplexCellRenderer implements ListCellRenderer {
protected DefaultListCellRenderer defaultRenderer = new DefaultListCellRenderer();
public Component getListCellRendererComponent(JList list, Object value,
int index, boolean isSelected, boolean cellHasFocus) {
Font theFont = null;
Color theForeground = null;
Icon theIcon = null;
String theText = null;
JLabel renderer = (JLabel) defaultRenderer.getListCellRendererComponent(list, value, index,
isSelected, cellHasFocus);
if (value instanceof Object[]) {
Object values[] = (Object[]) value;
theFont = (Font) values[0];
theForeground = (Color) values[1];
theIcon = (Icon) values[2];
theText = (String) values[3];
} else {
theFont = list.getFont();
theForeground = list.getForeground();
theText = "";
}
if (!isSelected) {
renderer.setForeground(theForeground);
}
if (theIcon != null) {
renderer.setIcon(theIcon);
}
renderer.setText(theText);
renderer.setFont(theFont);
return renderer;
}
}
// needet for GUIMailsget for the icon color
class DiamondIcon implements Icon {
private Color color;
private boolean selected;
private int width;
private int height;
private Polygon poly;
private static final int DEFAULT_WIDTH = 10;
private static final int DEFAULT_HEIGHT = 10;
public DiamondIcon(Color color) {
this(color, true, DEFAULT_WIDTH, DEFAULT_HEIGHT);
}
public DiamondIcon(Color color, boolean selected) {
this(color, selected, DEFAULT_WIDTH, DEFAULT_HEIGHT);
}
public DiamondIcon(Color color, boolean selected, int width, int height) {
this.color = color;
this.selected = selected;
this.width = width;
this.height = height;
initPolygon();
}
private void initPolygon() {
poly = new Polygon();
int halfWidth = width / 2;
int halfHeight = height / 2;
poly.addPoint(0, halfHeight);
poly.addPoint(halfWidth, 0);
poly.addPoint(width, halfHeight);
poly.addPoint(halfWidth, height);
}
public int getIconHeight() {
return height;
}
public int getIconWidth() {
return width;
}
public void paintIcon(Component c, Graphics g, int x, int y) {
g.setColor(color);
g.translate(x, y);
if (selected) {
g.fillPolygon(poly);
} else {
g.drawPolygon(poly);
}
g.translate(-x, -y);
}
}
public static void main(String[] args) {
try {
GUIMain test = new GUIMain();
// create the search path
test.searchAccounts(f);
test.createMainFrame();
} catch (Exception msg) {
System.out.println(msg);
}
}
}