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