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