]> git.mxchange.org Git - jfinancials-swing.git/blobdiff - Addressbook/src/org/mxchange/addressbook/client/gui/AddressbookFrame.java
Introduced new model as we need gender value verfication, maybe this works?
[jfinancials-swing.git] / Addressbook / src / org / mxchange / addressbook / client / gui / AddressbookFrame.java
index 8f8cee6d1795935fd7a8789188676fa8aa760e47..2c9494ba812137d68af8c272ef71db5380a245dc 100644 (file)
@@ -16,7 +16,9 @@
  */
 package org.mxchange.addressbook.client.gui;
 
+import org.mxchange.addressbook.model.gender.GenderComboBoxModel;
 import java.awt.BorderLayout;
+import java.awt.GridLayout;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.MouseAdapter;
@@ -26,13 +28,17 @@ import java.awt.event.WindowEvent;
 import java.text.MessageFormat;
 import javax.swing.BorderFactory;
 import javax.swing.BoxLayout;
+import javax.swing.JComboBox;
+import javax.swing.JDialog;
 import javax.swing.JFrame;
 import javax.swing.JLabel;
 import javax.swing.JMenu;
 import javax.swing.JMenuBar;
 import javax.swing.JMenuItem;
 import javax.swing.JPanel;
+import javax.swing.JScrollPane;
 import javax.swing.JTable;
+import javax.swing.border.TitledBorder;
 import javax.swing.table.TableModel;
 import org.mxchange.addressbook.BaseFrameworkSystem;
 import org.mxchange.addressbook.application.AddressbookApplication;
@@ -67,6 +73,12 @@ public class AddressbookFrame extends BaseFrameworkSystem implements ClientFrame
                // Return instance
                return self;
        }
+
+       /**
+        * Dialog box "add contact"
+        */
+       private JDialog addContact;
+
        /**
         * Frame instance for "add own data"
         */
@@ -112,7 +124,8 @@ public class AddressbookFrame extends BaseFrameworkSystem implements ClientFrame
                this.getLogger().trace(MessageFormat.format("client={0}: CALLED!", client));
 
                // Set frame instance
-               this.frame = new JFrame(AddressbookApplication.printableTitle());
+               this.frame = new JFrame();
+               this.frame.setTitle(this.generateFrameTitle("main"));
 
                // Set client here
                this.setClient(client);
@@ -208,6 +221,82 @@ public class AddressbookFrame extends BaseFrameworkSystem implements ClientFrame
                this.getClient().getApplication().doShutdown();
        }
 
+       /**
+        * Generates a title for borders
+        * @param key Key part to look for
+        * @return Human-readable title
+        */
+       private String generateBorderTitle (final String key) {
+               // Call bundle instance
+               return this.getBundle().getString(String.format("AddressbookFrame.border.%s.title.text", key));
+       }
+
+       /**
+        * Generates a title for all frames based on given sub title key. If null is
+        * given, the sub title is not generated.
+        * 
+        * @param subKey Key for sub title resource
+        * @return A full application title
+        */
+       private String generateFrameTitle (final String subKey) {
+               // Base title
+               String title = AddressbookApplication.printableTitle();
+
+               // Is key given?
+               if (subKey != null) {
+                       // Add sub title
+                       title = String.format("%s - %s", title, this.getBundle().getString(String.format("AddressbookFrame.%s.title.text", subKey)));
+               }
+
+               // Return it
+               return title;
+       }
+
+       /**
+        * Initializes "add contact" dialog
+        */
+       private void initAddContactDialog () {
+               // Instance dialog and set title
+               this.addContact = new JDialog();
+               this.addContact.setTitle(this.generateFrameTitle("dialog.addContact"));
+               this.addContact.setLayout(new GridLayout(4, 1));
+               
+               // Only hide it on close and make it appear in middle of screen
+               this.addContact.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
+               this.addContact.setLocationRelativeTo(null);
+               
+               // Set always on top and auto-focus
+               this.addContact.setAlwaysOnTop(true);
+               this.addContact.setAutoRequestFocus(true);
+               
+               // Initial dimension
+               this.addContact.setSize(400, 300);
+               
+               /*
+                * Add listener which asks for confirmation, if data has been entered
+                * but not saved yet. The user may appriciate this ... ;-)
+                *
+                * @TODO Unfinished
+                */
+               
+               // Init 3 panels:
+               // 1) Panel "name" input boxes
+               JPanel panel = new JPanel();
+               panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
+               
+               // Set border to titled version
+               panel.setBorder(new TitledBorder(this.generateBorderTitle("name")));
+
+               // Add some input boxes for "name" panel
+               JComboBox<String> gender = new JComboBox<>(new GenderComboBoxModel(this.getClient()));
+
+               // Finally add panel to dialog
+               this.addContact.add(panel);
+               
+               // Only for developing:
+               /* DEBUG: */ this.addContact.setVisible(true);
+       }
+
        /**
         * Initialize components
         */
@@ -257,6 +346,9 @@ public class AddressbookFrame extends BaseFrameworkSystem implements ClientFrame
 
                // Init status panel
                initStatusPanel();
+
+               // Init other windows
+               initOtherDialogs();
        }
 
        /**
@@ -267,12 +359,12 @@ public class AddressbookFrame extends BaseFrameworkSystem implements ClientFrame
                JMenuBar menuBar = new JMenuBar();
                JMenu menu;
                JMenuItem item;
-
-       // Init some menus:
+               
+               // Init some menus:
                // 1) File menu
                menu = new JMenu(this.getBundle().getString("AddressbookFrame.menu.file.text"));
-
-       // Add menu items:
+               
+               // Add menu items:
                // 1.x) Exit program (should be last)
                item = new JMenuItem(this.getBundle().getString("AddressbookFrame.menuItem.exitProgram.text"));
                item.setToolTipText(this.getBundle().getString("AddressbookFrame.menuItem.exitProgram.toolTipText"));
@@ -295,8 +387,8 @@ public class AddressbookFrame extends BaseFrameworkSystem implements ClientFrame
 
                // Add menu -> menu bar
                menuBar.add(menu);
-
-       // Init some menus:
+               
+               // Init some menus:
                // 2) Addressbook menu
                menu = new JMenu(this.getBundle().getString("AddressbookFrame.menu.addressbook.text"));
 
@@ -347,6 +439,15 @@ public class AddressbookFrame extends BaseFrameworkSystem implements ClientFrame
                this.frame.add(menuBar, BorderLayout.NORTH);
        }
 
+       /**
+        * Initialize other dialogs (e.g. "Add contact")
+        */
+       private void initOtherDialogs () {
+               // Init other windows:
+               // 1) Add contact
+               initAddContactDialog();
+       }
+
        /**
         * Initializes status panel
         */
@@ -388,8 +489,16 @@ public class AddressbookFrame extends BaseFrameworkSystem implements ClientFrame
                        }
                });
 
-               // Add table to frame
-               this.frame.add(this.dataTable, BorderLayout.CENTER);
+               // Instance scroll pane
+               JScrollPane scroller = new JScrollPane();
+
+               // Add table to scroll pane
+               scroller.setViewportView(this.dataTable);
+               scroller.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
+               scroller.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
+
+               // Add pane to frame
+               this.frame.add(scroller, BorderLayout.CENTER);
        }
 
        /**
@@ -399,6 +508,6 @@ public class AddressbookFrame extends BaseFrameworkSystem implements ClientFrame
         */
        private void updateStatus (final String type) {
                // Set status message
-               this.statusLabel.setText(this.getBundle().getString("AddressbookFrame.statusLabel." + type + ".text"));
+               this.statusLabel.setText(this.getBundle().getString(String.format("AddressbookFrame.statusLabel.%s.text", type)));
        }
 }