]> git.mxchange.org Git - jfinancials-swing.git/blob - Addressbook/src/org/mxchange/addressbook/client/gui/AddressbookFrame.java
Renamed some classes/interfaces to make it clear they belong only to this project...
[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.addressbook.exceptions.ContactAlreadyAddedException;
50 import org.mxchange.addressbook.manager.contact.ManageableAddressbookContact;
51 import org.mxchange.addressbook.model.contact.ContactTableModel;
52 import org.mxchange.jcore.client.Client;
53 import org.mxchange.jcore.contact.Contact;
54 import org.mxchange.jcore.contact.Gender;
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                 ManageableAddressbookContact manager = (ManageableAddressbookContact) 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.jcore.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 new menu item with given key to menu instance
303          *
304          * @param menu Menu instance to add item to
305          * @param key Message key part
306          * @param listener Listener instance
307          */
308         private void addMenuItem (final JMenu menu, final String key, final ActionListener listener) {
309                 // Trace message
310                 this.getLogger().trace(MessageFormat.format("menu={0},key={1},listener={2} - CALLED!", menu, key, listener)); //NOI18N
311                 
312                 // New instance
313                 JMenuItem item = this.initMenuItemWithTooltip(key);
314                 
315                 // Add listener
316                 item.addActionListener(listener);
317                 
318                 // Add item -> menu
319                 menu.add(item);
320                 
321                 // Trace message
322                 this.getLogger().trace("EXIT!"); //NOI18N
323         }
324
325         /**
326          * Adds a JTextField with label and tool tip to given panel
327          *
328          * @param panel Panel instance to add text field
329          * @param key Part of message key from resource bundle
330          * @param fieldLength Length of text field
331          */
332         private void addTextFieldWithLabelToPanel (final JPanel panel, final String key, final int fieldLength) {
333                 // Trace message
334                 this.getLogger().trace(MessageFormat.format("panel={0},key={1},fieldLength={2} - CALLED!", panel, key, fieldLength)); //NOI18N
335                 
336                 // Init label for given key
337                 JLabel label = new JLabel(this.getBundle().getString(String.format("AddressbookFrame.%s.text", key))); //NOI18N
338                 
339                 // And input box wih tool tip
340                 JTextField field = new JTextField(fieldLength);
341                 field.setToolTipText(this.getBundle().getString(String.format("AddressbookFrame.%s.toolTipText", key))); //NOI18N
342                 
343                 // Add both to panel
344                 panel.add(label);
345                 panel.add(field);
346                 
347                 // Trace message
348                 this.getLogger().trace("EXIT!"); //NOI18N
349         }
350
351         /**
352          * Generates a title for borders
353          *
354          * @param key Key part to look for
355          * @return Human-readable title
356          */
357         private String generateBorderTitle (final String key) {
358                 // Call bundle instance
359                 return this.getBundle().getString(String.format("AddressbookFrame.border.%s.title.text", key)); //NOI18N
360         }
361
362         /**
363          * Generates a title for all frames based on given sub title key. If null is
364          * given, the sub title is not generated.
365          *
366          * @param subKey Key for sub title resource
367          * @return A full application title
368          */
369         private String generateFrameTitle (final String subKey) {
370                 // Base title
371                 String title = AddressbookApplication.printableTitle();
372
373                 // Is key given?
374                 if (subKey != null) {
375                         // Add sub title
376                         title = String.format("%s - %s", title, this.getBundle().getString(String.format("AddressbookFrame.%s.title.text", subKey))); //NOI18N
377                 }
378
379                 // Return it
380                 return title;
381         }
382
383         /**
384          * Initializes "add" and "cancel" buttons
385          */
386         private void initAddCancelButtons () {
387                 // Trace message
388                 this.getLogger().trace("CALLED!"); //NOI18N
389
390                 // Init panel
391                 JPanel panel = new JPanel();
392                 panel.setLayout(new GridLayout(1, 2, 10, 10));
393
394                 // Generate "add" button
395                 JButton addButton = new JButton(this.getBundle().getString("AddressbookFrame.button.addAddress.text"));
396
397                 // Add listener
398                 addButton.addActionListener(new AddActionListener(this.addContact, this));
399
400                 // Add button to panel
401                 panel.add(addButton);
402
403                 // Generate "cancel" button
404                 JButton cancelButton = new JButton(this.getBundle().getString("AddressbookFrame.button.cancel.text"));
405
406                 // Add listener
407                 cancelButton.addActionListener(new CancelActionListener(this.addContact, this));
408
409                 // Add button to panel
410                 panel.add(cancelButton);
411
412                 // Add panel to main panel
413                 this.addContact.add(panel);
414
415                 // Trace message
416                 this.getLogger().trace("EXIT!"); //NOI18N
417         }
418
419         /**
420          * Initializes "add contact" dialog
421          */
422         private void initAddContactDialog () {
423                 // Trace message
424                 this.getLogger().trace("CALLED!"); //NOI18N
425
426                 // Instance dialog and set title
427                 this.addContact = new JDialog();
428                 this.addContact.setTitle(this.generateFrameTitle("dialog.addContact")); //NOI18N
429
430                 // Set layout
431                 this.addContact.setLayout(new GridLayout(0, 1, 2, 2));
432
433                 // Only hide it on close and make it appear in middle of screen
434                 this.addContact.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
435                 this.addContact.setLocationRelativeTo(this.frame);
436
437                 // Set always on top and auto-focus
438                 this.addContact.setAlwaysOnTop(true);
439                 this.addContact.setAutoRequestFocus(true);
440
441                 // Initial dimension
442                 this.addContact.setSize(500, 500);
443
444                 // And it is not resizeable
445                 this.addContact.setResizable(false);
446
447                 /*
448                  * Add listener which asks for confirmation, if data has been entered
449                  * but not saved yet. The user may appriciate this ... ;-)
450                  *
451                  * @TODO Unfinished
452                  */
453                 this.addContact.addWindowListener(new WindowAdapter() {
454                         /**
455                          * Invoked when a window has been closed.
456                          */
457                         @Override
458                         public void windowClosed (final WindowEvent e) {
459                                 // Enable main window again
460                                 AddressbookFrame.getSelfInstance(null).enableMainWindow();
461                         }
462
463                         /**
464                          * Invoked when a window is in the process of being closed. The
465                          * close operation can be overridden at this point.
466                          */
467                         @Override
468                         public void windowClosing (final WindowEvent e) {
469                                 e.getWindow().dispose();
470                         }
471                 });
472
473                 // Init 3 panels:
474                 // 1) "name" panel
475                 initNameDataPanel(this.addContact);
476
477                 // 2) "address" panel
478                 initAddressDataPanel(this.addContact);
479
480                 // 3) "other" panel
481                 initOtherDataPanel(this.addContact);
482
483                 // 4) "Add" and "Cancel" buttons, combined they are unique for this dialog
484                 initAddCancelButtons();
485
486                 // x)Only for developing:
487                 /* DEBUG: */ this.addContact.setVisible(true);
488
489                 // Trace message
490                 this.getLogger().trace("EXIT!"); //NOI18N
491         }
492
493         /**
494          * Initializes address panel
495          *
496          * @param dialog A JDialog instance to this components to
497          */
498         private void initAddressDataPanel (final JDialog dialog) {
499                 // Trace message
500                 this.getLogger().trace("CALLED!"); //NOI18N
501
502                 // Panel "address" input boxes
503                 JPanel addressPanel = new JPanel();
504                 addressPanel.setLayout(new GridLayout(0, 4, 3, 3));
505
506                 // Set border to titled version
507                 addressPanel.setBorder(new TitledBorder(this.generateBorderTitle("address"))); //NOI18N
508
509                 // Add text field for street
510                 this.addTextFieldWithLabelToPanel(addressPanel, "street", 20); //NOI18N
511
512                 // Number label
513                 JLabel numberLabel = new JLabel(this.getBundle().getString("AddressbookFrame.number.text"));
514
515                 // And text field, but only accept numbers
516                 JFormattedTextField number = new JFormattedTextField();
517                 number.setToolTipText(this.getBundle().getString("AddressbookFrame.number.toolTipText"));
518
519                 // Add both to street panel
520                 addressPanel.add(numberLabel);
521                 addressPanel.add(number);
522
523                 // Label for ZIP code, again numbers only
524                 JLabel zipLabel = new JLabel(this.getBundle().getString("AddressbookFrame.zip.text"));
525
526                 // Init text field with label
527                 JFormattedTextField zip = new JFormattedTextField();
528                 zip.setToolTipText(this.getBundle().getString("AddressbookFrame.zip.toolTipText"));
529
530                 // Add both to street panel
531                 addressPanel.add(zipLabel);
532                 addressPanel.add(zip);
533
534                 // Add text field for city name
535                 this.addTextFieldWithLabelToPanel(addressPanel, "city", 20); //NOI18N
536
537                 // Add panel to dialog
538                 dialog.add(addressPanel);
539
540                 // Trace message
541                 this.getLogger().trace("EXIT!"); //NOI18N
542         }
543
544         /**
545          * Initialize components
546          */
547         private void initComponents () {
548                 // Debug line
549                 this.getLogger().trace("CALLED!"); //NOI18N
550
551                 // Set default close operation
552                 this.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
553
554                 // Register shutdown listener
555                 this.frame.addWindowListener(new WindowAdapter() {
556                         /**
557                          * Invoked when a window has been closed.
558                          */
559                         @Override
560                         public void windowClosed (final WindowEvent e) {
561                                 // Shutdown application cleanly
562                                 self.shutdownApplication();
563                         }
564
565                         /**
566                          * Invoked when a window is in the process of being closed. The
567                          * close operation can be overridden at this point.
568                          */
569                         @Override
570                         public void windowClosing (final WindowEvent e) {
571                                 // Also shutdown cleanly here
572                                 self.shutdownApplication();
573                         }
574                 });
575
576                 // Setup layout manager
577                 this.frame.setLayout(new BorderLayout(2, 2));
578
579                 // Set window size
580                 this.frame.setSize(700, 400);
581
582                 // Center window in middle of screen, instead of top-left corner
583                 this.frame.setLocationRelativeTo(null);
584
585                 // Init menu system
586                 initMenuSystem();
587
588                 // Init table
589                 initTable();
590
591                 // Init status panel
592                 initStatusPanel();
593
594                 // Init other windows
595                 initOtherDialogs();
596
597                 // Trace message
598                 this.getLogger().trace("EXIT!"); //NOI18N
599         }
600
601         /**
602          * Initializes a menu item instance with tool tip
603          * 
604          * @param key Message key part
605          * @return A finished JMenuItem instance
606          */
607         private JMenuItem initMenuItemWithTooltip (final String key) {
608                 // Debug line
609                 this.getLogger().trace(MessageFormat.format("key={0} - CALLED!", key)); //NOI18N
610
611                 JMenuItem item = new JMenuItem(this.getBundle().getString(String.format("AddressbookFrame.menuItem.%s.text", key))); //NOI18N
612                 item.setToolTipText(this.getBundle().getString(String.format("AddressbookFrame.menuItem.%s.toolTipText", key))); //NOI18N
613
614                 // Trace message
615                 this.getLogger().trace(MessageFormat.format("item={0} - EXIT!", item)); //NOI18N
616
617                 // Return it
618                 return item;
619         }
620
621         /**
622          * Initializes the menu system
623          */
624         private void initMenuSystem () {
625                 // Trace message
626                 this.getLogger().trace("CALLED!"); //NOI18N
627
628                 // Init menu bar, menu and item instances
629                 JMenuBar menuBar = new JMenuBar();
630                 JMenu menu;
631                 JMenuItem item;
632
633                 // Init some menus:
634                 // 1) File menu
635                 menu = new JMenu(this.getBundle().getString("AddressbookFrame.menu.file.text"));
636
637                 // Add menu items:
638                 // 1.x) Exit program (should be last)
639                 this.addMenuItem(menu, "exitProgram", new ActionListener() { //NOI18N
640                         /**
641                          * If the user has performed this action
642                          *
643                          * @param e An instance of an ActionEvent class
644                          */
645                         @Override
646                         public void actionPerformed (final ActionEvent e) {
647                                 self.shutdownApplication();
648                         }
649                 });
650
651                 // Add menu -> menu bar
652                 menuBar.add(menu);
653
654                 // Init some menus:
655                 // 2) Addressbook menu
656                 menu = new JMenu(this.getBundle().getString("AddressbookFrame.menu.addressbook.text"));
657
658                 // 2.1) Add own data
659                 this.addOwnItem = this.initMenuItemWithTooltip("addOwnData"); //NOI18N
660
661                 // Add listener to exit menu
662                 this.addOwnItem.addActionListener(new ActionListener() {
663                         /**
664                          * If the user has performed this action
665                          *
666                          * @param e An instance of an ActionEvent class
667                          */
668                         @Override
669                         public void actionPerformed (final ActionEvent e) {
670                                 try {
671                                         ManageableAddressbookContact manager = (ManageableAddressbookContact) self.getClient().getManager();
672                                         manager.doEnterOwnData();
673                                 } catch (final ContactAlreadyAddedException ex) {
674                                         // Already added, log away
675                                         // @TODO maybe output message here?
676                                         self.logException(ex);
677                                 }
678                         }
679                 });
680
681                 // Add item -> menu
682                 menu.add(this.addOwnItem);
683
684                 // 2.2) Edit own data
685                 this.editOwnItem = this.initMenuItemWithTooltip("editOwnData"); //NOI18N
686
687                 // Add listener to exit menu
688                 this.editOwnItem.addActionListener(new ActionListener() {
689                         /**
690                          * If the user has performed this action
691                          *
692                          * @param e An instance of an ActionEvent class
693                          */
694                         @Override
695                         public void actionPerformed (final ActionEvent e) {
696                                 ManageableAddressbookContact manager = (ManageableAddressbookContact) self.getClient().getManager();
697                                 manager.doChangeOwnData();
698                         }
699                 });
700
701                 // Add item -> menu
702                 menu.add(this.editOwnItem);
703
704                 // Init more menus:
705                 // 1) Add new contact
706                 this.addMenuItem(menu, "addNewContact", new ActionListener() { //NOI18N
707                         /**
708                          * If the user has performed this action
709                          *
710                          * @param e An instance of an ActionEvent class
711                          */
712                         @Override
713                         public void actionPerformed (final ActionEvent e) {
714                                 ManageableAddressbookContact manager = (ManageableAddressbookContact) self.getClient().getManager();
715                                 manager.doAddOtherAddress();
716                         }
717                 });
718
719                 // Add menu -> menu bar
720                 menuBar.add(menu);
721
722                 // Add menu bar -> frame
723                 this.frame.add(menuBar, BorderLayout.NORTH);
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 }