]> git.mxchange.org Git - addressbook-lib.git/blob - src/org/mxchange/addressbook/client/gui/AddressbookFrame.java
Updated jcore + added more thrown exceptions + catched them
[addressbook-lib.git] / src / org / mxchange / addressbook / client / gui / AddressbookFrame.java
1 /*
2  * Copyright (C) 2015 Roland Haeder
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 package org.mxchange.addressbook.client.gui;
18
19 import java.awt.BorderLayout;
20 import java.awt.GridLayout;
21 import java.awt.event.ActionEvent;
22 import java.awt.event.ActionListener;
23 import java.awt.event.MouseAdapter;
24 import java.awt.event.MouseEvent;
25 import java.awt.event.WindowAdapter;
26 import java.awt.event.WindowEvent;
27 import java.io.IOException;
28 import java.lang.reflect.InvocationTargetException;
29 import java.sql.SQLException;
30 import java.text.MessageFormat;
31 import javax.swing.BorderFactory;
32 import javax.swing.BoxLayout;
33 import javax.swing.DefaultComboBoxModel;
34 import javax.swing.JButton;
35 import javax.swing.JComboBox;
36 import javax.swing.JDialog;
37 import javax.swing.JFormattedTextField;
38 import javax.swing.JFrame;
39 import javax.swing.JLabel;
40 import javax.swing.JMenu;
41 import javax.swing.JMenuBar;
42 import javax.swing.JMenuItem;
43 import javax.swing.JPanel;
44 import javax.swing.JScrollPane;
45 import javax.swing.JTable;
46 import javax.swing.JTextArea;
47 import javax.swing.JTextField;
48 import javax.swing.border.TitledBorder;
49 import javax.swing.table.TableModel;
50 import org.mxchange.addressbook.BaseAddressbookSystem;
51 import org.mxchange.addressbook.application.AddressbookApplication;
52 import org.mxchange.addressbook.exceptions.ContactAlreadyAddedException;
53 import org.mxchange.addressbook.manager.contact.ManageableAddressbookContact;
54 import org.mxchange.jcore.client.Client;
55 import org.mxchange.jcore.client.gui.ClientFrame;
56 import org.mxchange.jcore.contact.Contact;
57 import org.mxchange.jcore.contact.Gender;
58 import org.mxchange.jcore.exceptions.BadTokenException;
59 import org.mxchange.jcore.exceptions.CorruptedDatabaseFileException;
60 import org.mxchange.jcore.exceptions.FrameAlreadyInitializedException;
61 import org.mxchange.jcore.model.swing.contact.ContactTableModel;
62
63 /**
64  *
65  * @author Roland Haeder
66  */
67 public class AddressbookFrame extends BaseAddressbookSystem implements ClientFrame {
68
69         /**
70          * Own instance
71          */
72         private static ClientFrame self;
73
74         /**
75          * Singelton getter for this frame instance.
76          *
77          * @param client Client instance
78          * @return Returns a singelton instance of this frame
79          */
80         public static final ClientFrame getSelfInstance (final Client client) {
81                 // Is it set?
82                 if (!(self instanceof ClientFrame)) {
83                         // Create new instance
84                         self = new AddressbookFrame(client);
85                 }
86
87                 // Return instance
88                 return self;
89         }
90
91         /**
92          * Dialog box "add contact"
93          */
94         private JDialog addContact;
95
96         /**
97          * Frame instance for "add own data"
98          */
99         private JMenuItem addOwnItem;
100
101         /**
102          * Instance to table model
103          */
104         private TableModel dataModel;
105
106         /**
107          * Table instance
108          */
109         private JTable dataTable;
110
111         /**
112          * Frame instance for "edit own data"
113          */
114         private JMenuItem editOwnItem;
115
116         /**
117          * Frame instance
118          */
119         private final JFrame frame;
120
121         /**
122          * Whether this frame has been initialized
123          */
124         private boolean initialized;
125
126         /**
127          * Status label needs to be updated
128          */
129         private JLabel statusLabel;
130
131         /**
132          * Creates an instance of this frame with a client instance
133          *
134          * @param client
135          */
136         private AddressbookFrame (final Client client) {
137                 // Debug line
138                 this.getLogger().trace(MessageFormat.format("client={0}: CALLED!", client)); //NOI18N
139
140                 // Set frame instance
141                 this.frame = new JFrame();
142                 this.frame.setTitle(this.generateFrameTitle("main")); //NOI18N
143
144                 // Set client here
145                 this.setClient(client);
146
147                 // Trace message
148                 this.getLogger().trace("EXIT!"); //NOI18N
149         }
150
151         @Override
152         public Contact doEnterOwnData () {
153                 // Trace message
154                 this.getLogger().trace("CALLED!"); //NOI18N
155
156                 // Is the "add contact" window visible?
157                 if (this.addContact.isVisible()) {
158                         // Something bad happened
159                         throw new IllegalStateException("Window addContact is already visible."); //NOI18N
160                 }
161
162                 // Disable main window
163                 this.frame.setEnabled(false);
164
165                 // Make other window visible
166                 this.addContact.setVisible(true);
167
168                 // Trace message
169                 this.getLogger().trace("Returning null : EXIT!"); //NOI18N
170
171                 // Return value is not supported
172                 return null;
173         }
174
175         /**
176          * Shutdown this frame
177          */
178         @Override
179         public void doShutdown () {
180                 // Trace message
181                 this.getLogger().trace("CALLED!"); //NOI18N
182
183                 // First only show shutdown status
184                 this.updateStatus("shutdown"); //NOI18N
185
186                 // Trace message
187                 this.getLogger().trace("EXIT!"); //NOI18N
188         }
189
190
191         /**
192          * Enables main window (frame)
193          */
194         @Override
195         public void enableMainWindow () {
196                 // Trace message
197                 this.getLogger().trace("CALLED!"); //NOI18N
198
199                 // Enable it again
200                 this.frame.setEnabled(true);
201
202                 // Request focus for this window
203                 this.frame.requestFocus();
204
205                 // Trace message
206                 this.getLogger().trace("EXIT!"); //NOI18N
207         }
208
209         /**
210          * Setups the frame, do not set isInitialized here
211          *
212          * @param client Client instance
213          */
214         @Override
215         public void setupFrame (final Client client) throws IOException, BadTokenException {
216                 // Debug line
217                 this.getLogger().trace(MessageFormat.format("client={0}: CALLED!", client)); //NOI18N
218
219                 // Get and cast manager instance
220                 ManageableAddressbookContact manager = (ManageableAddressbookContact) this.getClient().getManager();
221
222                 // Has the user entered own data?
223                 if (manager.isOwnContactAdded()) {
224                         // Debug message
225                         this.getLogger().debug("Disabling menus: isOwnContactAdded()=false"); //NOI18N
226
227                         // Not entered yet, so disable "add" menu
228                         this.addOwnItem.setEnabled(false);
229                 } else {
230                         // Disable "edit"
231                         this.editOwnItem.setEnabled(false);
232                 }
233
234                 // Make the frame visible
235                 this.frame.setVisible(true);
236
237                 // All done here
238                 this.updateStatus("done"); //NOI18N
239
240                 // Trace message
241                 this.getLogger().trace("EXIT!"); //NOI18N
242         }
243
244         /**
245          * Initalizes this frame. Having initComponents() exposed (publicly
246          * accessible) means that any other object can initialize components which
247          * you may not want.
248          *
249          * @throws
250          * org.mxchange.jcore.exceptions.FrameAlreadyInitializedException If
251          * this method has been called twice
252          */
253         @Override
254         public void init () throws FrameAlreadyInitializedException {
255                 // Debug line
256                 this.getLogger().trace("CALLED!"); //NOI18N
257
258                 // Has this frame been initialized?
259                 if (this.isInitialized()) {
260                         // Throw exception
261                         throw new FrameAlreadyInitializedException();
262                 }
263
264                 // Init components
265                 this.initComponents();
266
267                 // Set flag
268                 this.initialized = true;
269
270                 // Trace message
271                 this.getLogger().trace("EXIT!"); //NOI18N
272         }
273
274         /**
275          * Returns field isInitialized. This flag indicates whether this frame has
276          * been initialized or not.
277          *
278          * @return Field isInitialized
279          */
280         @Override
281         public final boolean isInitialized () {
282                 return this.initialized;
283         }
284
285         /**
286          * Shuts down the application.
287          */
288         @Override
289         public void shutdownApplication () {
290                 // Trace message
291                 this.getLogger().trace("CALLED!"); //NOI18N
292
293                 // To do this, the frame must be initialized
294                 if (!this.isInitialized()) {
295                         // Not initalized, so bad call
296                         this.getLogger().fatal("Bad call of shutdownApplication(). Please report this."); //NOI18N
297                         return;
298                 }
299
300                 // Call shutdown method
301                 try {
302                         this.getClient().getApplication().doShutdown();
303                 } catch (final SQLException | IOException ex) {
304                         // Abort here
305                         this.abortProgramWithException(ex);
306                 }
307
308                 // Trace message
309                 this.getLogger().trace("EXIT!"); //NOI18N
310         }
311
312         /**
313          * Adds a new menu item with given key to menu instance
314          *
315          * @param menu Menu instance to add item to
316          * @param key Message key part
317          * @param listener Listener instance
318          */
319         private void addMenuItem (final JMenu menu, final String key, final ActionListener listener) {
320                 // Trace message
321                 this.getLogger().trace(MessageFormat.format("menu={0},key={1},listener={2} - CALLED!", menu, key, listener)); //NOI18N
322                 
323                 // New instance
324                 JMenuItem item = this.initMenuItemWithTooltip(key);
325                 
326                 // Add listener
327                 item.addActionListener(listener);
328                 
329                 // Add item -> menu
330                 menu.add(item);
331                 
332                 // Trace message
333                 this.getLogger().trace("EXIT!"); //NOI18N
334         }
335
336         /**
337          * Adds a JTextField with label and tool tip to given panel
338          *
339          * @param panel Panel instance to add text field
340          * @param key Part of message key from resource bundle
341          * @param fieldLength Length of text field
342          */
343         private void addTextFieldWithLabelToPanel (final JPanel panel, final String key, final int fieldLength) {
344                 // Trace message
345                 this.getLogger().trace(MessageFormat.format("panel={0},key={1},fieldLength={2} - CALLED!", panel, key, fieldLength)); //NOI18N
346                 
347                 // Init label for given key
348                 JLabel label = new JLabel(this.getBundle().getString(String.format("AddressbookFrame.%s.text", key))); //NOI18N
349                 
350                 // And input box wih tool tip
351                 JTextField field = new JTextField(fieldLength);
352                 field.setToolTipText(this.getBundle().getString(String.format("AddressbookFrame.%s.toolTipText", key))); //NOI18N
353                 
354                 // Add both to panel
355                 panel.add(label);
356                 panel.add(field);
357                 
358                 // Trace message
359                 this.getLogger().trace("EXIT!"); //NOI18N
360         }
361
362         /**
363          * Generates a title for borders
364          *
365          * @param key Key part to look for
366          * @return Human-readable title
367          */
368         private String generateBorderTitle (final String key) {
369                 // Call bundle instance
370                 return this.getBundle().getString(String.format("AddressbookFrame.border.%s.title.text", key)); //NOI18N
371         }
372
373         /**
374          * Generates a title for all frames based on given sub title key. If null is
375          * given, the sub title is not generated.
376          *
377          * @param subKey Key for sub title resource
378          * @return A full application title
379          */
380         private String generateFrameTitle (final String subKey) {
381                 // Base title
382                 String title = AddressbookApplication.printableTitle();
383
384                 // Is key given?
385                 if (subKey != null) {
386                         // Add sub title
387                         title = String.format("%s - %s", title, this.getBundle().getString(String.format("AddressbookFrame.%s.title.text", subKey))); //NOI18N
388                 }
389
390                 // Return it
391                 return title;
392         }
393
394         /**
395          * Initializes "add" and "cancel" buttons
396          */
397         private void initAddCancelButtons () {
398                 // Trace message
399                 this.getLogger().trace("CALLED!"); //NOI18N
400
401                 // Init panel
402                 JPanel panel = new JPanel();
403                 panel.setLayout(new GridLayout(1, 2, 10, 10));
404
405                 // Generate "add" button
406                 JButton addButton = new JButton(this.getBundle().getString("AddressbookFrame.button.addAddress.text"));
407
408                 // Add listener
409                 addButton.addActionListener(new AddActionListener(this.addContact, this));
410
411                 // Add button to panel
412                 panel.add(addButton);
413
414                 // Generate "cancel" button
415                 JButton cancelButton = new JButton(this.getBundle().getString("AddressbookFrame.button.cancel.text"));
416
417                 // Add listener
418                 cancelButton.addActionListener(new CancelActionListener(this.addContact, this));
419
420                 // Add button to panel
421                 panel.add(cancelButton);
422
423                 // Add panel to main panel
424                 this.addContact.add(panel);
425
426                 // Trace message
427                 this.getLogger().trace("EXIT!"); //NOI18N
428         }
429
430         /**
431          * Initializes "add contact" dialog
432          */
433         private void initAddContactDialog () {
434                 // Trace message
435                 this.getLogger().trace("CALLED!"); //NOI18N
436
437                 // Instance dialog and set title
438                 this.addContact = new JDialog();
439                 this.addContact.setTitle(this.generateFrameTitle("dialog.addContact")); //NOI18N
440
441                 // Set layout
442                 this.addContact.setLayout(new GridLayout(0, 1, 2, 2));
443
444                 // Only hide it on close and make it appear in middle of screen
445                 this.addContact.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
446                 this.addContact.setLocationRelativeTo(this.frame);
447
448                 // Set always on top and auto-focus
449                 this.addContact.setAlwaysOnTop(true);
450                 this.addContact.setAutoRequestFocus(true);
451
452                 // Initial dimension
453                 this.addContact.setSize(500, 500);
454
455                 // And it is not resizeable
456                 this.addContact.setResizable(false);
457
458                 /*
459                  * Add listener which asks for confirmation, if data has been entered
460                  * but not saved yet. The user may appriciate this ... ;-)
461                  *
462                  * @TODO Unfinished
463                  */
464                 this.addContact.addWindowListener(new WindowAdapter() {
465                         /**
466                          * Invoked when a window has been closed.
467                          */
468                         @Override
469                         public void windowClosed (final WindowEvent e) {
470                                 // Enable main window again
471                                 AddressbookFrame.getSelfInstance(null).enableMainWindow();
472                         }
473
474                         /**
475                          * Invoked when a window is in the process of being closed. The
476                          * close operation can be overridden at this point.
477                          */
478                         @Override
479                         public void windowClosing (final WindowEvent e) {
480                                 e.getWindow().dispose();
481                         }
482                 });
483
484                 // Init 3 panels:
485                 // 1) "name" panel
486                 initNameDataPanel(this.addContact);
487
488                 // 2) "address" panel
489                 initAddressDataPanel(this.addContact);
490
491                 // 3) "other" panel
492                 initOtherDataPanel(this.addContact);
493
494                 // 4) "Add" and "Cancel" buttons, combined they are unique for this dialog
495                 initAddCancelButtons();
496
497                 // x)Only for developing:
498                 /* DEBUG: */ this.addContact.setVisible(true);
499
500                 // Trace message
501                 this.getLogger().trace("EXIT!"); //NOI18N
502         }
503
504         /**
505          * Initializes address panel
506          *
507          * @param dialog A JDialog instance to this components to
508          */
509         private void initAddressDataPanel (final JDialog dialog) {
510                 // Trace message
511                 this.getLogger().trace("CALLED!"); //NOI18N
512
513                 // Panel "address" input boxes
514                 JPanel addressPanel = new JPanel();
515                 addressPanel.setLayout(new GridLayout(0, 4, 3, 3));
516
517                 // Set border to titled version
518                 addressPanel.setBorder(new TitledBorder(this.generateBorderTitle("address"))); //NOI18N
519
520                 // Add text field for street
521                 this.addTextFieldWithLabelToPanel(addressPanel, "street", 20); //NOI18N
522
523                 // Number label
524                 JLabel numberLabel = new JLabel(this.getBundle().getString("AddressbookFrame.number.text"));
525
526                 // And text field, but only accept numbers
527                 JFormattedTextField number = new JFormattedTextField();
528                 number.setToolTipText(this.getBundle().getString("AddressbookFrame.number.toolTipText"));
529
530                 // Add both to street panel
531                 addressPanel.add(numberLabel);
532                 addressPanel.add(number);
533
534                 // Label for ZIP code, again numbers only
535                 JLabel zipLabel = new JLabel(this.getBundle().getString("AddressbookFrame.zip.text"));
536
537                 // Init text field with label
538                 JFormattedTextField zip = new JFormattedTextField();
539                 zip.setToolTipText(this.getBundle().getString("AddressbookFrame.zip.toolTipText"));
540
541                 // Add both to street panel
542                 addressPanel.add(zipLabel);
543                 addressPanel.add(zip);
544
545                 // Add text field for city name
546                 this.addTextFieldWithLabelToPanel(addressPanel, "city", 20); //NOI18N
547
548                 // Add panel to dialog
549                 dialog.add(addressPanel);
550
551                 // Trace message
552                 this.getLogger().trace("EXIT!"); //NOI18N
553         }
554
555         /**
556          * Initialize components
557          */
558         private void initComponents () {
559                 // Debug line
560                 this.getLogger().trace("CALLED!"); //NOI18N
561
562                 // Set default close operation
563                 this.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
564
565                 // Register shutdown listener
566                 this.frame.addWindowListener(new WindowAdapter() {
567                         /**
568                          * Invoked when a window has been closed.
569                          */
570                         @Override
571                         public void windowClosed (final WindowEvent e) {
572                                 // Shutdown application cleanly
573                                 self.shutdownApplication();
574                         }
575
576                         /**
577                          * Invoked when a window is in the process of being closed. The
578                          * close operation can be overridden at this point.
579                          */
580                         @Override
581                         public void windowClosing (final WindowEvent e) {
582                                 // Also shutdown cleanly here
583                                 self.shutdownApplication();
584                         }
585                 });
586
587                 // Setup layout manager
588                 this.frame.setLayout(new BorderLayout(2, 2));
589
590                 // Set window size
591                 this.frame.setSize(700, 400);
592
593                 // Center window in middle of screen, instead of top-left corner
594                 this.frame.setLocationRelativeTo(null);
595
596                 // Init menu system
597                 initMenuSystem();
598
599                 // Init table
600                 initTable();
601
602                 // Init status panel
603                 initStatusPanel();
604
605                 // Init other windows
606                 initOtherDialogs();
607
608                 // Trace message
609                 this.getLogger().trace("EXIT!"); //NOI18N
610         }
611
612         /**
613          * Initializes a menu item instance with tool tip
614          * 
615          * @param key Message key part
616          * @return A finished JMenuItem instance
617          */
618         private JMenuItem initMenuItemWithTooltip (final String key) {
619                 // Debug line
620                 this.getLogger().trace(MessageFormat.format("key={0} - CALLED!", key)); //NOI18N
621
622                 JMenuItem item = new JMenuItem(this.getBundle().getString(String.format("AddressbookFrame.menuItem.%s.text", key))); //NOI18N
623                 item.setToolTipText(this.getBundle().getString(String.format("AddressbookFrame.menuItem.%s.toolTipText", key))); //NOI18N
624
625                 // Trace message
626                 this.getLogger().trace(MessageFormat.format("item={0} - EXIT!", item)); //NOI18N
627
628                 // Return it
629                 return item;
630         }
631
632         /**
633          * Initializes the menu system
634          */
635         private void initMenuSystem () {
636                 // Trace message
637                 this.getLogger().trace("CALLED!"); //NOI18N
638
639                 // Init menu bar, menu and item instances
640                 JMenuBar menuBar = new JMenuBar();
641                 JMenu menu;
642                 JMenuItem item;
643
644                 // Init some menus:
645                 // 1) File menu
646                 menu = new JMenu(this.getBundle().getString("AddressbookFrame.menu.file.text"));
647
648                 // Add menu items:
649                 // 1.x) Exit program (should be last)
650                 this.addMenuItem(menu, "exitProgram", new ActionListener() { //NOI18N
651                         /**
652                          * If the user has performed this action
653                          *
654                          * @param e An instance of an ActionEvent class
655                          */
656                         @Override
657                         public void actionPerformed (final ActionEvent e) {
658                                 self.shutdownApplication();
659                         }
660                 });
661
662                 // Add menu -> menu bar
663                 menuBar.add(menu);
664
665                 // Init some menus:
666                 // 2) Addressbook menu
667                 menu = new JMenu(this.getBundle().getString("AddressbookFrame.menu.addressbook.text"));
668
669                 // 2.1) Add own data
670                 this.addOwnItem = this.initMenuItemWithTooltip("addOwnData"); //NOI18N
671
672                 // Add listener to exit menu
673                 this.addOwnItem.addActionListener(new ActionListener() {
674                         /**
675                          * If the user has performed this action
676                          *
677                          * @param e An instance of an ActionEvent class
678                          */
679                         @Override
680                         public void actionPerformed (final ActionEvent e) {
681                                 try {
682                                         ManageableAddressbookContact manager = (ManageableAddressbookContact) self.getClient().getManager();
683                                         manager.doEnterOwnData();
684                                 } catch (final ContactAlreadyAddedException ex) {
685                                         // Already added, log away
686                                         // @TODO maybe output message here?
687                                         self.logException(ex);
688                                 } catch (final IOException | BadTokenException ex) {
689                                         // Somethind bad happened here
690                                         // @TODO Output error message here?
691                                 }
692                         }
693                 });
694
695                 // Add item -> menu
696                 menu.add(this.addOwnItem);
697
698                 // 2.2) Edit own data
699                 this.editOwnItem = this.initMenuItemWithTooltip("editOwnData"); //NOI18N
700
701                 // Add listener to exit menu
702                 this.editOwnItem.addActionListener(new ActionListener() {
703                         /**
704                          * If the user has performed this action
705                          *
706                          * @param e An instance of an ActionEvent class
707                          */
708                         @Override
709                         public void actionPerformed (final ActionEvent e) {
710                                 ManageableAddressbookContact manager = (ManageableAddressbookContact) self.getClient().getManager();
711                                 try {
712                                         manager.doChangeOwnData();
713                                 } catch (final IOException | BadTokenException | CorruptedDatabaseFileException | SQLException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
714                                         self.logException(ex);
715                                 }
716                         }
717                 });
718
719                 // Add item -> menu
720                 menu.add(this.editOwnItem);
721
722                 // Init more menus:
723                 // 1) Add new contact
724                 this.addMenuItem(menu, "addNewContact", new ActionListener() { //NOI18N
725                         /**
726                          * If the user has performed this action
727                          *
728                          * @param e An instance of an ActionEvent class
729                          */
730                         @Override
731                         public void actionPerformed (final ActionEvent e) {
732                                 ManageableAddressbookContact manager = (ManageableAddressbookContact) self.getClient().getManager();
733                                 manager.doAddOtherAddress();
734                         }
735                 });
736
737                 // Add menu -> menu bar
738                 menuBar.add(menu);
739
740                 // Add menu bar -> frame
741                 this.frame.add(menuBar, BorderLayout.NORTH);
742
743                 // Trace message
744                 this.getLogger().trace("EXIT!"); //NOI18N
745         }
746
747         /**
748          * Initializes name panel
749          *
750          * @param dialog A JDialog instance to this components to
751          */
752         private void initNameDataPanel (final JDialog dialog) {
753                 // Trace message
754                 this.getLogger().trace(MessageFormat.format("dialog={0} - CALLED!", dialog)); //NOI18N
755
756                 // Panel "name" input boxes
757                 JPanel namePanel = new JPanel();
758                 namePanel.setLayout(new GridLayout(0, 2, 3, 3));
759
760                 // Set border to titled version
761                 namePanel.setBorder(new TitledBorder(this.generateBorderTitle("name"))); //NOI18N
762
763                 // Gender text field
764                 JLabel gLabel = new JLabel(this.getBundle().getString("AddressbookFrame.gender.text"));
765
766                 // Get all genders
767                 Gender[] genders = Gender.values();
768
769                 // Init gender combo box with tool tip
770                 JComboBox<Gender> gender = new JComboBox<>(new DefaultComboBoxModel<>(genders));
771                 gender.setToolTipText(this.getBundle().getString("AddressbookFrame.gender.toolTipText"));
772
773                 // Add both to gender panel
774                 namePanel.add(gLabel);
775                 namePanel.add(gender);
776
777                 // Add text field for surname
778                 this.addTextFieldWithLabelToPanel(namePanel, "surname", 20); //NOI18N
779
780                 // Add text field for family name
781                 this.addTextFieldWithLabelToPanel(namePanel, "familyName", 20); //NOI18N
782
783                 // Finally add panel to dialog
784                 dialog.add(namePanel);
785
786                 // Trace message
787                 this.getLogger().trace("EXIT!"); //NOI18N
788         }
789
790         /**
791          * Initializes "other" data panel
792          *
793          * @param dialog A JDialog instance to this components to
794          * @todo Fill this with life
795          */
796         private void initOtherDataPanel (final JDialog dialog) {
797                 // Trace message
798                 this.getLogger().trace(MessageFormat.format("dialog={0} - CALLED!", dialog)); //NOI18N
799
800                 // Panel "other" input boxes
801                 JPanel otherPanel = new JPanel();
802                 otherPanel.setLayout(new GridLayout(0, 2, 3, 3));
803                 otherPanel.setBorder(new TitledBorder(this.generateBorderTitle("other"))); //NOI18N
804
805                 // Add text field for email address
806                 this.addTextFieldWithLabelToPanel(otherPanel, "emailAddress", 20); //NOI18N
807
808                 // Add text field for phone number
809                 this.addTextFieldWithLabelToPanel(otherPanel, "phoneNumber", 20); //NOI18N
810
811                 // Add text field for cellphone number
812                 this.addTextFieldWithLabelToPanel(otherPanel, "cellphoneNumber", 20); //NOI18N
813
814                 // Add text field for fax number
815                 this.addTextFieldWithLabelToPanel(otherPanel, "faxNumber", 20); //NOI18N
816
817                 // Init label
818                 JLabel commentLabel = new JLabel(this.getBundle().getString("AddressbookFrame.comment.text"));
819
820                 // Init text area with tool tip
821                 JTextArea comment = new JTextArea(5, 20);
822                 comment.setToolTipText(this.getBundle().getString("AddressbookFrame.comment.toolTipText"));
823
824                 // Add both to panel
825                 otherPanel.add(commentLabel);
826                 otherPanel.add(comment);
827
828                 // Finally add panel to dialog
829                 dialog.add(otherPanel);
830
831                 // Trace message
832                 this.getLogger().trace("EXIT!"); //NOI18N
833         }
834
835         /**
836          * Initialize other dialogs (e.g. "Add contact")
837          */
838         private void initOtherDialogs () {
839                 // Trace message
840                 this.getLogger().trace("CALLED!"); //NOI18N
841
842                 // Init other windows:
843                 // 1) Add contact
844                 initAddContactDialog();
845
846                 // Trace message
847                 this.getLogger().trace("EXIT!"); //NOI18N
848         }
849
850         /**
851          * Initializes status panel
852          */
853         private void initStatusPanel () {
854                 // Trace message
855                 this.getLogger().trace("CALLED!"); //NOI18N
856
857                 // Init status label (which needs to be updated
858                 this.statusLabel = new JLabel();
859                 this.updateStatus("initializing"); //NOI18N
860
861                 // Init status bar in south
862                 JPanel panel = new JPanel();
863                 panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
864                 panel.add(this.statusLabel);
865                 panel.setBorder(BorderFactory.createEtchedBorder());
866
867                 // Add panel to frame
868                 this.frame.add(panel, BorderLayout.SOUTH);
869
870                 // Trace message
871                 this.getLogger().trace("EXIT!"); //NOI18N
872         }
873
874         /**
875          * Initializes the table which will show all contacts
876          */
877         private void initTable () {
878                 // Trace message
879                 this.getLogger().trace("CALLED!"); //NOI18N
880
881                 // Instance table model
882                 this.dataModel = new ContactTableModel(this.getClient());
883
884                 // Instance table
885                 this.dataTable = new JTable(this.dataModel);
886
887                 // Add mouse listener
888                 this.dataTable.addMouseListener(new MouseAdapter() {
889                         /**
890                          * If the user peformed a click on a cell
891                          *
892                          * @param e Mouse event instance
893                          */
894                         @Override
895                         public void mouseClicked (final MouseEvent e) {
896                                 throw new UnsupportedOperationException("Unfinished."); //NOI18N
897                         }
898                 });
899
900                 // Instance scroll pane
901                 JScrollPane scroller = new JScrollPane();
902
903                 // Add table to scroll pane
904                 scroller.setViewportView(this.dataTable);
905                 scroller.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
906                 scroller.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
907
908                 // Add pane to frame
909                 this.frame.add(scroller, BorderLayout.CENTER);
910
911                 // Trace message
912                 this.getLogger().trace("EXIT!"); //NOI18N
913         }
914
915         /**
916          * Updates status to given type
917          *
918          * @param type Status type
919          */
920         private void updateStatus (final String type) {
921                 // Trace message
922                 this.getLogger().trace(MessageFormat.format("type={0} - CALLED!", type)); //NOI18N
923
924                 // Set status message
925                 this.statusLabel.setText(this.getBundle().getString(String.format("AddressbookFrame.statusLabel.%s.text", type))); //NOI18N
926
927                 // Trace message
928                 this.getLogger().trace("EXIT!"); //NOI18N
929         }
930
931         /**
932          * Class for "add address" button
933          */
934         private static class AddActionListener extends BaseAddressbookSystem implements ActionListener {
935                 /**
936                  * Dialog instance
937                  */
938                 private final JDialog dialog;
939
940                 /**
941                  * Frame (not JFrame) instance
942                  */
943                 private final ClientFrame frame;
944
945                 /**
946                  * Constructor for action listener
947                  * 
948                  * @param dialog Dialog instance to call back
949                  * @param frame Frame instance (not JFrame)
950                  */
951                 protected AddActionListener (final JDialog dialog, final ClientFrame frame) {
952                         // Set dialog and frame here
953                         this.dialog = dialog;
954                         this.frame = frame;
955                 }
956
957                 /**
958                  * If the action has been performed
959                  *
960                  * @param e The performed action event
961                  */
962                 @Override
963                 public void actionPerformed (final ActionEvent e) {
964                         throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
965                 }
966         }
967
968         /**
969          * Class for "cancel address" button
970          */
971         private static class CancelActionListener extends BaseAddressbookSystem implements ActionListener {
972                 /**
973                  * Dialog instance
974                  */
975                 private final JDialog dialog;
976
977                 /**
978                  * Frame (not JFrame) instance
979                  */
980                 private final ClientFrame frame;
981
982                 /**
983                  * Constructor for action listener
984                  * 
985                  * @param dialog Dialog instance to call back
986                  * @param frame Frame instance (not JFrame)
987                  */
988                 protected CancelActionListener (final JDialog dialog, final ClientFrame frame) {
989                         // Set dialog and frame here
990                         this.dialog = dialog;
991                         this.frame = frame;
992                 }
993
994                 /**
995                  * If the action has been performed
996                  *
997                  * @param e The performed action event
998                  */
999                 @Override
1000                 public void actionPerformed (final ActionEvent e) {
1001                         throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
1002                 }
1003         }
1004 }