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