blob: 77d636622452f6f5eb14e7d396d0e34df783669d (
plain)
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
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
|
/* NetCalendar 2006, 2009 (c) Dipl.-Inform. (FH) Paul C. Buetow
* http://netcalendar.buetow.org - netcalendar@dev.buetow.org
*/
/**
*/
package client;
import java.awt.*;
import java.awt.event.*;
import java.text.SimpleDateFormat;
import java.util.*;
import javax.swing.*;
import javax.swing.table.*;
import shared.*;
import shared.remotecall.*;
import client.inputforms.*;
/**
* This is the main class of the client part of the netcalendar suite. It contains the main GUI.
* All subguis are created within this class.
* @author Paul C. Buetow
*/
public class NetCalendarClient extends JFrame {
private static final long serialVersionUID = 1L;
private static int iNextSession = 1;
private static int iNumCurrentSessions = 0;
private int iCurrentSession;
private NetCalendarClient netCalendarClient;
private Vector vecFrames = new Vector();
private Thread currentTimeThread;
// Diverse components
private ClientRequest lastClientRequest = null;
protected int iCurrentMouseSelectedRow = 0;
protected int iCurrentMouseSelectedCol = 0;
// GUI components
private JMenuBar jMenuBar;
private JPopupMenu jPopupMenu;
private CalendarTableModel tableModel;
private JTable jTable;
private JTextField jTextFieldRegexp;
private JTextField jTextFieldStatusMessages;
private JTextField jTextFieldCurrentTime;
// Some callback objects
private DoCallback doCallbackEditEvent;
private DoCallback doCallbackDeleteEvent;
private DoCallback doCallbackCopyEvent;
private DoCallback doCallbackDeleteCategory;
private DoCallback doCallbackRenameCategory;
// Static GUI strings which needs to be specified at least twice
private final static String DELETE_EVENT = "Delete event(s)";
private final static String EDIT_EVENT = "Edit event(s)";
private final static String COPY_EVENT = "Copy event(s)";
private final static String CREATE_EVENT = "Create new event";
private final static String DELETE_CATEGORY = "Delete whole category(s)";
private final static String RENAME_CATEGORY = "Rename whole category(s)";
private final static String ADVANCED_SEARCH = "Advanced searching";
private final static String SORT_BY_COL = "Sort by this row";
private final static String REVERSE_SORT_BY_COL = "Reverse sort by this row";
private final static String ENTER_REGEXP_HERE ="Enter some regexp search string here...";
private static final String DATE_FORMAT_NOW = "yyyy/MM/dd HH:mm:ss";
/**
* Standard constructor, creates the client GUI.
*/
public NetCalendarClient() {
super(getSessionString(iNextSession) + Config.VERSION);
this.iCurrentSession = iNextSession++;
// Save a reference of this to allow to access this object through
// inner-classes
// (See the "Advanced searching" action listener object for example!)
this.netCalendarClient = this;
iNumCurrentSessions++;
initComponents();
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setLocationRelativeTo(null);
pack();
setVisible(true);
// Start a default request to the netcalendar server
update(new ClientRequest(ClientRequest.REQUEST_ALL_EVENTS));
}
/**
* Initializes all the GUI components.
*/
private void initComponents() {
this.addWindowListener(new WindowListener() {
public void windowActivated(WindowEvent e) { }
public void windowClosing(WindowEvent e) {}
public void windowDeactivated(WindowEvent e) {}
public void windowDeiconified(WindowEvent e) {}
public void windowIconified(WindowEvent e) { }
public void windowOpened(WindowEvent e) {}
public void windowClosed(WindowEvent e) {
if (--iNumCurrentSessions == 0)
Main.exit(0);
Main.infoMessage("Closing a session window");
}
});
Container container = getContentPane();
jMenuBar = new JMenuBar();
setJMenuBar(jMenuBar);
JMenu jMenuSession = new JMenu("Session");
jMenuSession.setMnemonic(KeyEvent.VK_S);
jMenuBar.add(jMenuSession);
JMenuItem jMenuItemShowCalendar = new JMenuItem("Show calendar");
jMenuItemShowCalendar.setMnemonic(KeyEvent.VK_S);
jMenuSession.add(jMenuItemShowCalendar);
jMenuItemShowCalendar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
new JCalendarDatePicker(netCalendarClient);
}
});
jMenuSession.add(new JSeparator());
JMenuItem jMenuItemNewWindow = new JMenuItem("New window");
jMenuItemNewWindow.setMnemonic(KeyEvent.VK_N);
jMenuSession.add(jMenuItemNewWindow);
jMenuItemNewWindow.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
new NetCalendarClient();
}
});
JMenuItem jMenuItemCloseWindow = new JMenuItem("Close window");
jMenuItemCloseWindow.setMnemonic(KeyEvent.VK_C);
jMenuSession.add(jMenuItemCloseWindow);
jMenuItemCloseWindow.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
dispose();
}
});
jMenuSession.add(new JSeparator());
JMenuItem jMenuItemPreferences = new JMenuItem("Preferences");
jMenuItemPreferences.setMnemonic(KeyEvent.VK_P);
jMenuSession.add(jMenuItemPreferences);
jMenuItemPreferences.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
new Preferences(netCalendarClient);
}
});
jMenuSession.add(new JSeparator());
JMenuItem jMenuItemQuit = new JMenuItem("Quit");
jMenuItemQuit.setMnemonic(KeyEvent.VK_Q);
jMenuSession.add(jMenuItemQuit);
jMenuItemQuit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
System.exit(0);
}
});
JMenu jMenuEdit = new JMenu("Edit");
jMenuEdit.setMnemonic(KeyEvent.VK_E);
jMenuBar.add(jMenuEdit);
JMenuItem jMenuItemCreate = new JMenuItem(CREATE_EVENT);
jMenuItemCreate.setMnemonic(KeyEvent.VK_C);
jMenuEdit.add(jMenuItemCreate);
jMenuItemCreate.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
new CreateNewEvent(netCalendarClient);
}
});
JMenuItem jMenuItemEdit = new JMenuItem(EDIT_EVENT);
jMenuItemEdit.setMnemonic(KeyEvent.VK_E);
jMenuEdit.add(jMenuItemEdit);
doCallbackEditEvent = new DoCallback() {
public void callback(Object obj) {
new EditExistingEvent(netCalendarClient, (CalendarEvent) obj);
}
};
jMenuItemEdit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
foreachSelectedEvent(doCallbackEditEvent);
}
});
JMenuItem jMenuItemCopy = new JMenuItem(COPY_EVENT);
jMenuItemCopy.setMnemonic(KeyEvent.VK_O);
jMenuEdit.add(jMenuItemCopy);
doCallbackCopyEvent = new DoCallback() {
public void callback(Object obj) {
CalendarEvent calendarEvent = (CalendarEvent) obj;
ClientRequest clientRequest = new ClientRequest(ClientRequest.ADD_EVENT);
clientRequest.setEvent(calendarEvent);
ServerRequester.sendClientRequest(clientRequest);
netCalendarClient.updateLast();
}
};
jMenuItemCopy.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
foreachSelectedEvent(doCallbackCopyEvent);
}
});
JMenuItem jMenuItemDelete = new JMenuItem(DELETE_EVENT);
jMenuItemDelete.setMnemonic(KeyEvent.VK_D);
jMenuEdit.add(jMenuItemDelete);
doCallbackDeleteEvent = new DoCallback() {
public void callback(Object obj) {
deleteEvent((CalendarEvent)obj);
jTable.getSelectionModel().clearSelection();
}
};
jMenuItemDelete.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
foreachSelectedEvent(doCallbackDeleteEvent);
}
});
jMenuEdit.add(new JSeparator());
JMenuItem jMenuItemRenameCategory = new JMenuItem(RENAME_CATEGORY);
jMenuItemRenameCategory.setMnemonic(KeyEvent.VK_R);
jMenuEdit.add(jMenuItemRenameCategory);
doCallbackRenameCategory = new DoCallback() {
public void callback(Object obj) {
new RenameCategory(netCalendarClient, (CalendarEvent) obj);
jTable.getSelectionModel().clearSelection();
}
};
jMenuItemRenameCategory.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
foreachSelectedEvent(doCallbackRenameCategory);
}
});
JMenuItem jMenuItemDeleteCategory = new JMenuItem(DELETE_CATEGORY);
jMenuItemDeleteCategory.setMnemonic(KeyEvent.VK_L);
jMenuEdit.add(jMenuItemDeleteCategory);
doCallbackDeleteCategory = new DoCallback() {
public void callback(Object obj) {
deleteCategory((CalendarEvent)obj);
jTable.getSelectionModel().clearSelection();
}
};
jMenuItemDeleteCategory.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
foreachSelectedEvent(doCallbackDeleteCategory);
}
});
JMenu jMenuSorting = new JMenu("Sorting");
jMenuSorting.setMnemonic(KeyEvent.VK_O);
jMenuBar.add(jMenuSorting);
JMenuItem jMenuItemSortByDate = new JMenuItem("Sort by date");
jMenuItemSortByDate.setMnemonic(KeyEvent.VK_D);
jMenuSorting.add(jMenuItemSortByDate);
jMenuItemSortByDate.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
tableModel.sortByDate();
}
});
JMenuItem jMenuItemSortByCategory = new JMenuItem("Sort by category");
jMenuItemSortByCategory.setMnemonic(KeyEvent.VK_C);
jMenuSorting.add(jMenuItemSortByCategory);
jMenuItemSortByCategory.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
tableModel.sortByCategory();
}
});
JMenuItem jMenuItemSortByDescr = new JMenuItem("Sort by description");
jMenuItemSortByDescr.setMnemonic(KeyEvent.VK_E);
jMenuSorting.add(jMenuItemSortByDescr);
jMenuItemSortByDescr.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
tableModel.sortByDescription();
}
});
JMenuItem jMenuItemSortByPlace = new JMenuItem("Sort by place");
jMenuItemSortByPlace.setMnemonic(KeyEvent.VK_P);
jMenuSorting.add(jMenuItemSortByPlace);
jMenuItemSortByPlace.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
tableModel.sortByPlace();
}
});
JMenuItem jMenuItemSortByEventIDs = new JMenuItem("Sort by event IDs");
jMenuItemSortByEventIDs.setMnemonic(KeyEvent.VK_I);
jMenuSorting.add(jMenuItemSortByEventIDs);
jMenuItemSortByEventIDs.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
tableModel.sortByID();
}
});
jMenuSorting.add(new JSeparator());
JMenuItem jMenuItemReverseSortByDate = new JMenuItem(
"Reverse sort by date");
jMenuItemReverseSortByDate.setMnemonic(KeyEvent.VK_A);
jMenuSorting.add(jMenuItemReverseSortByDate);
jMenuItemReverseSortByDate.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
tableModel.reverseSortByDate();
}
});
JMenuItem jMenuItemReverseSortByCategory = new JMenuItem(
"Reverse sort by category");
jMenuItemReverseSortByCategory.setMnemonic(KeyEvent.VK_T);
jMenuSorting.add(jMenuItemReverseSortByCategory);
jMenuItemReverseSortByCategory.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
tableModel.reverseSortByCategory();
}
});
JMenuItem jMenuItemReverseSortByDescr = new JMenuItem(
"Reverse sort by description");
jMenuItemReverseSortByDescr.setMnemonic(KeyEvent.VK_S);
jMenuSorting.add(jMenuItemReverseSortByDescr);
jMenuItemReverseSortByDescr.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
tableModel.reverseSortByDescription();
}
});
JMenuItem jMenuItemReverseSortByPlace = new JMenuItem(
"Reverse sort by place");
jMenuItemReverseSortByPlace.setMnemonic(KeyEvent.VK_L);
jMenuSorting.add(jMenuItemReverseSortByPlace);
jMenuItemReverseSortByPlace.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
tableModel.reverseSortByPlace();
}
});
JMenuItem jMenuItemReverseSortByIDs = new JMenuItem(
"Reverse sort by event IDs");
jMenuItemReverseSortByIDs.setMnemonic(KeyEvent.VK_R);
jMenuSorting.add(jMenuItemReverseSortByIDs);
jMenuItemReverseSortByIDs.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
tableModel.reverseSortByID();
}
});
JMenu jMenuServer = new JMenu("Server");
jMenuServer.setMnemonic(KeyEvent.VK_R);
jMenuBar.add(jMenuServer);
JMenuItem jMenuItemUpdate = new JMenuItem("Update events from server");
jMenuItemUpdate.setMnemonic(KeyEvent.VK_U);
jMenuServer.add(jMenuItemUpdate);
jMenuItemUpdate.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
update(lastClientRequest);
}
});
JMenuItem jMenuItemGetAll = new JMenuItem("Get all events from server");
jMenuItemGetAll.setMnemonic(KeyEvent.VK_G);
jMenuServer.add(jMenuItemGetAll);
ActionListener actionListenerGetAll = new ActionListener() {
public void actionPerformed(ActionEvent event) {
update(new ClientRequest(ClientRequest.REQUEST_ALL_EVENTS));
}
};
jMenuItemGetAll.addActionListener(actionListenerGetAll);
JMenuItem jMenuItemAdvancedSearch = new JMenuItem(
"Advanced searching for events");
jMenuItemAdvancedSearch.setMnemonic(KeyEvent.VK_A);
jMenuServer.add(jMenuItemAdvancedSearch);
jMenuItemAdvancedSearch.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
new AdvancedSearching(netCalendarClient);
}
});
jMenuServer.add(new JSeparator());
JMenuItem jMenuItemReloadDatabase = new JMenuItem("Reload database");
jMenuItemReloadDatabase.setMnemonic(KeyEvent.VK_R);
jMenuServer.add(jMenuItemReloadDatabase);
jMenuItemReloadDatabase.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
ServerRequester.sendClientRequest(new ClientRequest(
ClientRequest.RELOAD_DATABASE));
updateLast();
}
});
JMenuItem jMenuItemFlushDatabase = new JMenuItem("Flush database");
jMenuItemFlushDatabase.setMnemonic(KeyEvent.VK_F);
jMenuServer.add(jMenuItemFlushDatabase);
jMenuItemFlushDatabase.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
ServerRequester.sendClientRequest(new ClientRequest(
ClientRequest.FLUSH_DATABASE));
}
});
jMenuServer.add(new JSeparator());
JMenuItem jMenuItemShutdownServer = new JMenuItem("Shutdown server");
jMenuItemShutdownServer.setMnemonic(KeyEvent.VK_S);
jMenuServer.add(jMenuItemShutdownServer);
jMenuItemShutdownServer.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
ServerRequester.sendClientRequest(new ClientRequest(
ClientRequest.SHUTDOWN_SERVER));
}
});
JMenu jMenuAbout = new JMenu("About");
jMenuAbout.setMnemonic(KeyEvent.VK_A);
jMenuBar.add(jMenuAbout);
JMenuItem jMenuItemAbout = new JMenuItem("About");
jMenuItemAbout.setMnemonic(KeyEvent.VK_A);
jMenuBar.add(jMenuAbout);
jMenuAbout.add(jMenuItemAbout);
jMenuItemAbout.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
new AboutWindow(netCalendarClient);
}
});
JMenuItem jMenuItemLicense = new JMenuItem("License");
jMenuItemLicense.setMnemonic(KeyEvent.VK_L);
jMenuAbout.add(jMenuItemLicense);
jMenuItemLicense.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
new LicenseWindow(netCalendarClient);
}
});
jPopupMenu = new JPopupMenu();
ActionListener jPopupMenuActionListener = new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
String sActionCommand = actionEvent.getActionCommand();
if (sActionCommand.equals(DELETE_EVENT)) {
foreachSelectedEvent(doCallbackDeleteEvent);
} else if (sActionCommand.equals(CREATE_EVENT)) {
new CreateNewEvent(netCalendarClient);
} else if (sActionCommand.equals(EDIT_EVENT)) {
foreachSelectedEvent(doCallbackEditEvent);
} else if (sActionCommand.equals(COPY_EVENT)) {
foreachSelectedEvent(doCallbackCopyEvent);
} else if (sActionCommand.equals(RENAME_CATEGORY)) {
foreachSelectedEvent(doCallbackRenameCategory);
} else if (sActionCommand.equals(DELETE_CATEGORY)) {
foreachSelectedEvent(doCallbackDeleteCategory);
} else if (sActionCommand.equals(ADVANCED_SEARCH)) {
new AdvancedSearching(netCalendarClient);
} else if (sActionCommand.equals(SORT_BY_COL)) {
tableModel.sortByCol(iCurrentMouseSelectedCol);
} else if (sActionCommand.equals(REVERSE_SORT_BY_COL)) {
tableModel.reverseSortByCol(iCurrentMouseSelectedCol);
}
}
};
JMenuItem jMenuItemPopupCreate = new JMenuItem(CREATE_EVENT);
jMenuItemPopupCreate.addActionListener(jPopupMenuActionListener);
jPopupMenu.add(jMenuItemPopupCreate);
JMenuItem jMenuItemPopupEdit = new JMenuItem(EDIT_EVENT);
jMenuItemPopupEdit.addActionListener(jPopupMenuActionListener);
jPopupMenu.add(jMenuItemPopupEdit);
JMenuItem jMenuItemPopupCopy = new JMenuItem(COPY_EVENT);
jMenuItemPopupCopy.addActionListener(jPopupMenuActionListener);
jPopupMenu.add(jMenuItemPopupCopy);
JMenuItem jMenuItemPopupDelete = new JMenuItem(DELETE_EVENT);
jMenuItemPopupDelete.addActionListener(jPopupMenuActionListener);
jPopupMenu.add(jMenuItemPopupDelete);
jPopupMenu.add(new JSeparator());
JMenuItem jMenuItemPopupRenameCategory = new JMenuItem(RENAME_CATEGORY);
jMenuItemPopupRenameCategory.addActionListener(jPopupMenuActionListener);
jPopupMenu.add(jMenuItemPopupRenameCategory);
JMenuItem jMenuItemPopupDeleteCategory = new JMenuItem(DELETE_CATEGORY);
jMenuItemPopupDeleteCategory.addActionListener(jPopupMenuActionListener);
jPopupMenu.add(jMenuItemPopupDeleteCategory);
jPopupMenu.add(new JSeparator());
JMenuItem jMenuItemPopupSort = new JMenuItem(SORT_BY_COL);
jMenuItemPopupSort.addActionListener(jPopupMenuActionListener);
jPopupMenu.add(jMenuItemPopupSort);
JMenuItem jMenuItemPopupReverseSort = new JMenuItem(REVERSE_SORT_BY_COL);
jMenuItemPopupReverseSort.addActionListener(jPopupMenuActionListener);
jPopupMenu.add(jMenuItemPopupReverseSort);
jPopupMenu.add(new JSeparator());
JMenuItem jMenuItemPopupAdvancedSearch = new JMenuItem(ADVANCED_SEARCH);
jMenuItemPopupAdvancedSearch
.addActionListener(jPopupMenuActionListener);
jPopupMenu.add(jMenuItemPopupAdvancedSearch);
jTable = new JTable();
jTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
jTable.setColumnModel(new DefaultTableColumnModel() {
private static final long serialVersionUID = 1L;
// Dont allow column moving!
public void moveColumn(int iColumnIndex, int iNewColumnIndex) { }
});
tableModel = new CalendarTableModel(jTable);
jTable.setModel(tableModel);
jTable.addMouseListener(new MouseListener() {
public void mouseClicked(MouseEvent mouseEvent) {
iCurrentMouseSelectedRow = jTable.rowAtPoint(mouseEvent.getPoint());
iCurrentMouseSelectedCol = jTable.columnAtPoint(mouseEvent.getPoint());
if (mouseEvent.getButton() != MouseEvent.BUTTON1)
jPopupMenu.show(jTable, mouseEvent.getX(), mouseEvent.getY());
}
public void mouseEntered(MouseEvent event) { }
public void mouseExited(MouseEvent event) {}
public void mousePressed(MouseEvent event) { }
public void mouseReleased(MouseEvent event) {
}
});
CalendarTableCellRenderer cellRenderer = new CalendarTableCellRenderer(tableModel);
TableColumn column = jTable.getColumn(CalendarTableModel.NUM_HEADER);
column.setMaxWidth(Config.getStringValue("client_max_events").length() * 10);
column.setResizable(false);
column.setCellRenderer(cellRenderer);
column = jTable.getColumn(CalendarTableModel.CATEGORY_HEADER);
column.setPreferredWidth(10);
column.setCellRenderer(cellRenderer);
column = jTable.getColumn(CalendarTableModel.PLACE_HEADER);
column.setPreferredWidth(10);
column.setCellRenderer(cellRenderer);
jTable.getColumn(CalendarTableModel.DATE_HEADER).setCellRenderer(cellRenderer);
jTable.getColumn(CalendarTableModel.DESCRIPTION_HEADER).setCellRenderer(cellRenderer);
jTextFieldRegexp = new JTextField();
jTextFieldRegexp.setText(ENTER_REGEXP_HERE);
jTextFieldRegexp.setEnabled(false);
ActionListener actionListenerSearchRegexp = new ActionListener() {
public void actionPerformed(ActionEvent event) {
ClientRequest clientRequest = new ClientRequest();
clientRequest.setRegexpAll(jTextFieldRegexp.getText());
clientRequest.setMainRegexp(true);
jTextFieldRegexp.setText("");
update(ServerRequester.sendClientRequest(clientRequest));
lastClientRequest = clientRequest;
}
};
MouseListener mouseListenerSearchRegexp = new MouseListener() {
public void mouseClicked(MouseEvent mouseEvent) {}
public void mousePressed(MouseEvent mouseEvent) {}
public void mouseReleased(MouseEvent mouseEvent) {}
public void mouseExited(MouseEvent mouseEvent) {
if (jTextFieldRegexp.getText().equals("")) {
jTextFieldRegexp.setText(ENTER_REGEXP_HERE);
jTextFieldRegexp.setEnabled(false);
}
}
public void mouseEntered(MouseEvent mouseEvent) {
if (!jTextFieldRegexp.isEnabled()) {
jTextFieldRegexp.setText("");
jTextFieldRegexp.setEnabled(true);
}
}
};
jTextFieldRegexp.addActionListener(actionListenerSearchRegexp);
jTextFieldRegexp.addMouseListener(mouseListenerSearchRegexp);
JButton jButtonSearch = new JButton("Search");
jButtonSearch.addActionListener(actionListenerSearchRegexp);
jButtonSearch.addMouseListener(mouseListenerSearchRegexp);
JButton jButtonGetAll = new JButton("Get all");
jButtonGetAll.addActionListener(actionListenerGetAll);
// Init split panes
JSplitPane jSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
jSplitPane.setResizeWeight(1);
jSplitPane.setDividerSize(0);
JSplitPane jSplitPane2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
jSplitPane2.setResizeWeight(1);
jSplitPane2.setDividerSize(0);
JSplitPane jSplitPane3 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
jSplitPane3.setResizeWeight(1);
jSplitPane3.setDividerSize(0);
JSplitPane jSplitPane4 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
jSplitPane4.setDividerSize(0);
// Init components
JScrollPane jScrollPaneTable = new JScrollPane(jTable);
jTextFieldStatusMessages = new JTextField("Welcome to "
+ Config.VERSION);
jTextFieldStatusMessages.setEditable(false);
jTextFieldCurrentTime = new JTextField();
jTextFieldCurrentTime.setEditable(false);
// Set split pane components
JSplitPane jSplitPaneStatus =
new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
jSplitPaneStatus.setDividerSize(0);
jSplitPaneStatus.setResizeWeight(1);
jSplitPaneStatus.setLeftComponent(jTextFieldStatusMessages);
jSplitPaneStatus.setRightComponent(jTextFieldCurrentTime);
jSplitPane.setTopComponent(jScrollPaneTable);
jSplitPane.setBottomComponent(jSplitPane2);
jSplitPane2.setTopComponent(jSplitPane3);
jSplitPane2.setBottomComponent(jSplitPaneStatus);
JPanel jPanelButtons = new JPanel();
jPanelButtons.add(jButtonSearch);
jPanelButtons.add(jButtonGetAll);
jSplitPane3.setLeftComponent(jTextFieldRegexp);
jSplitPane3.setRightComponent(jPanelButtons);
container.add(jSplitPane);
currentTimeThread = new Thread() {
public void run() {
while (true) {
updateCurrentTime();
try {
Thread.sleep(1000);
} catch (Exception e) {
System.err.println(e);
}
}
}
};
currentTimeThread.start();
}
/**
* This method sends a client request object to the server and used the server response object
* to update the JTable ith its new values using the table model.
* @param clientRequest Specifies the client request object to use for the updating.
*/
public void update(ClientRequest clientRequest) {
if (clientRequest == null)
return;
update(ServerRequester.sendClientRequest(clientRequest));
lastClientRequest = clientRequest;
}
/**
* This method sends the last client request object being used to the server again. If
* If there is no last client request, nothing will be done.
*/
public void updateLast() {
if (lastClientRequest != null)
update(ServerRequester.sendClientRequest(lastClientRequest));
}
/**
* This method updates the GUI unsing a given server response object.
* @param serverResponse Specifies the server response to use for the updating.
*/
public void update(ServerResponse serverResponse) {
if (serverResponse == null)
return;
tableModel.setEvents(serverResponse.getEvents());
}
/**
* This method tells the calendar server to delete a given calendar event.
* @param deleteEvent Specifies the calendar event to delete.
*/
public void deleteEvent(CalendarEvent deleteEvent) {
ClientRequest deleteRequest = new ClientRequest(
ClientRequest.DELETE_EVENT);
deleteRequest.setEvent(deleteEvent);
ServerRequester.sendClientRequest(deleteRequest);
updateLast();
}
/**
* This method tells the calendar server to delete a given calendar category.
* @param deleteEventsCategory Specifies the calendar event to delete its category!
*/
public void deleteCategory(CalendarEvent deleteEventsCategory) {
ClientRequest deleteRequest = new ClientRequest(
ClientRequest.DELETE_CATEGORY);
deleteRequest.setEvent(deleteEventsCategory);
ServerRequester.sendClientRequest(deleteRequest);
updateLast();
}
/**
* If the client has several main windows open, then it will display a
* session indicator so that the user knows which window belongs to which
* session window!
* @param iSession Specifies the session number of the current client window.
* @return Returns the session indicator of the current client session.
*/
private static String getSessionString(int iSession) {
return iSession > 1 ? "[" + iSession + "] " : "";
}
/**
* If the client has several main windows open, then it will display a
* session indicator so that the user knows which window belongs to which
* session window.
* @return Returns the session indicator of the current client session.
*/
public String getSessionString() {
return iCurrentSession > 1 ? "[" + iCurrentSession + "] " : "";
}
/**
* Runs a callback function on each selected event of the table.
* @param doCallback Specifies the callback object to be used.
*/
public void foreachSelectedEvent(DoCallback doCallback) {
ListSelectionModel listSelectionModel = jTable.getSelectionModel();
int iMinIndex = listSelectionModel.getMinSelectionIndex();
int iMaxIndex = listSelectionModel.getMaxSelectionIndex();
Vector vecEvents = new Vector();
for (int i = iMinIndex; i <= iMaxIndex; ++i)
if (listSelectionModel.isSelectedIndex(i))
vecEvents.add(tableModel.getEvent(i));
Enumeration enumEvents = vecEvents.elements();
while (enumEvents.hasMoreElements())
doCallback.callback(enumEvents.nextElement());
}
/**
* This method is for various status messages. All messages will show up in the
* status bar of the current client session window.
* @param sMessage Specifies the message to be displayed in the status bar.
*/
public void statusMessage(String sMessage) {
jTextFieldStatusMessages.setText(sMessage);
jTextFieldStatusMessages.updateUI();
}
/**
* This method updates the current time in the time frame in the GUI
*/
public synchronized void updateCurrentTime() {
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
jTextFieldCurrentTime.setText(sdf.format(cal.getTime()));
}
/**
* This method disposes this JFrame window including all the JFrame windows which
* belong to this session.
*/
public void dispose() {
Enumeration enumFrames = vecFrames.elements();
while (enumFrames.hasMoreElements())
((JFrame) enumFrames.nextElement()).dispose();
super.dispose();
}
/**
* This method tells the main netcalendar client JFrame which sub JFrames are opened.
* So that all the sub JFrames will be disposed as well if the main JFrame gets disposed.
* A sub JFrame is for example a input form for advanced searching or the preferences dialog.
* @param jFrame Specifies the frame object to add. .
*/
public void addFrame(JFrame jFrame) {
vecFrames.add(jFrame);
}
/**
* This method tells the main netcalendar client JFrame which sub JFrames are opened.
* So that all the sub JFrames will be disposed as well if the main JFrame gets disposed.
* A sub JFrame is for example a input form for advanced searching or the preferences dialog.
* @param jFrame Specifies the frame object to remove.
*/
public void removeFrame(JFrame jFrame) {
vecFrames.remove(jFrame);
}
}
|