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