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