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