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