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