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