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