]> git.mxchange.org Git - jfinancials-swing.git/commitdiff
Added more input fields and overwritten toString() in Gender enum
authorRoland Haeder <roland@mxchange.org>
Tue, 28 Jul 2015 10:59:41 +0000 (12:59 +0200)
committerRoland Haeder <roland@mxchange.org>
Tue, 28 Jul 2015 10:59:41 +0000 (12:59 +0200)
Signed-off-by:Roland Häder <roland@mxchange.org>

Addressbook/src/org/mxchange/addressbook/BaseFrameworkSystem.java
Addressbook/src/org/mxchange/addressbook/FrameworkInterface.java
Addressbook/src/org/mxchange/addressbook/application/AddressbookApplication.java
Addressbook/src/org/mxchange/addressbook/client/gui/AddressbookFrame.java
Addressbook/src/org/mxchange/addressbook/contact/Gender.java
Addressbook/src/org/mxchange/addressbook/localization/bundle_de_DE.properties
Addressbook/src/org/mxchange/addressbook/localization/bundle_en_US.properties

index 9580cd137b1405b673b294fc32b58d68afdfc67e..b104090c5ba9f218fe1c7bd0f44a98097777af44 100644 (file)
@@ -166,4 +166,15 @@ public class BaseFrameworkSystem implements FrameworkInterface {
        protected final void setTableName (final String tableName) {
                this.tableName = tableName;
        }
+
+       /**
+        * Getter for human-readable string from given key
+        * 
+        * @param key Key to return
+        * @return Human-readable message
+        */
+       public final String getMessageStringFromKey (final String key) {
+               // Return message
+               return this.getBundle().getString(key);
+       }
 }
index 7d9f6c744e1fac2b5e43c93d861c8ab79d9af13f..fc44b3fcf11433edced8c75f21fa7acc9cf6668d 100644 (file)
@@ -47,4 +47,12 @@ public interface FrameworkInterface {
         * @return the application
         */
        public Application getApplication ();
+
+       /**
+        * Getter for human-readable string from given key
+        * 
+        * @param key Key to return
+        * @return Human-readable message
+        */
+       public String getMessageStringFromKey (final String key);
 }
index 78efb043b54a1454ae310a142c57faeeb83c7c91..7f55a382725a8c1b0936dc399621f00bccc6ce82 100644 (file)
@@ -127,6 +127,11 @@ public class AddressbookApplication extends BaseFrameworkSystem implements Appli
         */
        public static final String APP_VERSION = "0.0";
 
+       /**
+        * Self instance
+        */
+       private static Application selfInstance;
+
        /**
         * Console client is enabled by default
         */
@@ -137,6 +142,14 @@ public class AddressbookApplication extends BaseFrameworkSystem implements Appli
         */
        private boolean guiClient = false;
 
+       /**
+        * Protected constructor
+        */
+       protected AddressbookApplication () {
+               // Set own instance
+               selfInstance = this;
+       }
+
        /**
         * Getter for printable application name
         *
@@ -334,4 +347,14 @@ public class AddressbookApplication extends BaseFrameworkSystem implements Appli
                this.getLogger().info("End of program (last line)");
                System.exit(0);
        }
+
+       /**
+        * Getter for this application
+        * 
+        * @return Instance from this application
+        */
+       public static final Application getInstance () {
+               // Return it
+               return selfInstance;
+       }
 }
index 0f8aee83700616680624f3565a19e64550f83dff..fdc59e1e990e50d7e1e4b377e3e83552f1011e7a 100644 (file)
@@ -28,7 +28,9 @@ import java.text.MessageFormat;
 import javax.swing.BorderFactory;
 import javax.swing.BoxLayout;
 import javax.swing.DefaultComboBoxModel;
+import javax.swing.InputVerifier;
 import javax.swing.JComboBox;
+import javax.swing.JComponent;
 import javax.swing.JDialog;
 import javax.swing.JFrame;
 import javax.swing.JLabel;
@@ -274,19 +276,156 @@ public class AddressbookFrame extends BaseFrameworkSystem implements ClientFrame
                // Initial dimension
                this.addContact.setSize(500, 400);
 
-               // Only for developing:
-               /* DEBUG: */ this.addContact.setVisible(true);
-
                /*
                 * 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) "Name" panel
+               // 1) "name" panel
                initNamePanel();
+
+               // 2) "address" panel
+               initAddressPanel();
+
+               // x)Only for developing:
+               /* DEBUG: */ this.addContact.setVisible(true);
+       }
+
+       /**
+        * Initializes address panel
+        */
+       private void initAddressPanel () {
+               // Panel "address" input boxes
+               JPanel addressPanel = new JPanel();
+               addressPanel.setLayout(new BoxLayout(addressPanel, BoxLayout.Y_AXIS));
+               
+               // Set border to titled version
+               addressPanel.setBorder(new TitledBorder(this.generateBorderTitle("address")));
+
+               // Init all elements:
+               // 1) Street and number together
+               JPanel streetNumberPanel = new JPanel();
+               streetNumberPanel.setLayout(new GridLayout(1, 4));
+
+               // Label for street
+               JLabel streetLabel = new JLabel(this.getBundle().getString("AddressbookFrame.street.text"));
+
+               // Init text field with label
+               JTextField street = new JTextField(20);
+               street.setToolTipText(this.getBundle().getString("AddressbookFrame.street.tooltipText"));
+
+               // Add both to street panel
+               streetNumberPanel.add(streetLabel);
+               streetNumberPanel.add(street);
+
+               // Number label
+               JLabel numberLabel = new JLabel(this.getBundle().getString("AddressbookFrame.number.text"));
+
+               // And text field, but only accept numbers
+               JTextField number = new JTextField(4);
+               number.setToolTipText(this.getBundle().getString("AddressbookFrame.number.tooltipText"));
+
+               // Add number verifier
+               number.setInputVerifier(new InputVerifier() {
+
+                       /**
+                        * Method to verify that the entered data is a number.
+                        * 
+                        * @param input Input to verify
+                        * @return Whether the data is a number
+                        */
+                       @Override
+                       public boolean verify (final JComponent input) {
+                               // Cast on text field
+                               JTextField text = (JTextField) input;
+
+                               // Default is passed
+                               boolean isValid = true;
+
+                               // Try to convert input text to a number
+                               try {
+                                       int num = Integer.valueOf(text.getText());
+                               } catch (final NumberFormatException ex) {
+                                       // Didn't work
+                                       isValid = false;
+                               }
+
+                               // Return status
+                               return isValid;
+                       }
+               });
+
+               // Add both to street panel
+               streetNumberPanel.add(numberLabel);
+               streetNumberPanel.add(number);
+
+               // Add panel to address panel
+               addressPanel.add(streetNumberPanel);
+
+               // 2) ZIP code and ccity name
+               JPanel zipCityPanel = new JPanel();
+               zipCityPanel.setLayout(new GridLayout(1, 4));
+
+               // Label for ZIP code, again numbers only
+               JLabel zipLabel = new JLabel(this.getBundle().getString("AddressbookFrame.zip.text"));
+
+               // Init text field with label
+               JTextField zip = new JTextField(20);
+               zip.setToolTipText(this.getBundle().getString("AddressbookFrame.zip.tooltipText"));
+
+               // Add number verifier
+               zip.setInputVerifier(new InputVerifier() {
+
+                       /**
+                        * Method to verify that the entered data is a number.
+                        * 
+                        * @param input Input to verify
+                        * @return Whether the data is a number
+                        */
+                       @Override
+                       public boolean verify (final JComponent input) {
+                               // Cast on text field
+                               JTextField text = (JTextField) input;
+
+                               // Default is passed
+                               boolean isValid = true;
+
+                               // Try to convert input text to a number
+                               try {
+                                       int num = Integer.valueOf(text.getText());
+                               } catch (final NumberFormatException ex) {
+                                       // Didn't work
+                                       isValid = false;
+                               }
+
+                               // Return status
+                               return isValid;
+                       }
+               });
+
+               // Add both to street panel
+               zipCityPanel.add(zipLabel);
+               zipCityPanel.add(zip);
+
+               // Label for street
+               JLabel cityLabel = new JLabel(this.getBundle().getString("AddressbookFrame.city.text"));
+
+               // Init text field with label
+               JTextField city = new JTextField(20);
+               city.setToolTipText(this.getBundle().getString("AddressbookFrame.city.tooltipText"));
+
+               // Add both to street panel
+               zipCityPanel.add(cityLabel);
+               zipCityPanel.add(city);
+
+               // Add panel to address panel
+               addressPanel.add(zipCityPanel);
+
+               // Add panel to dialog
+               this.addContact.add(addressPanel);
        }
 
        /**
@@ -435,76 +574,70 @@ public class AddressbookFrame extends BaseFrameworkSystem implements ClientFrame
         * Initializes name panel
         */
        private void initNamePanel () {
-               // 1) Panel "name" input boxes
+               // Panel "name" input boxes
                JPanel namePanel = new JPanel();
                namePanel.setLayout(new BoxLayout(namePanel, BoxLayout.Y_AXIS));
-               
+
                // Set border to titled version
                namePanel.setBorder(new TitledBorder(this.generateBorderTitle("name")));
-               
-               // Get all genders
-               Gender[] genders = Gender.values();
-               
-               // Init gender combo box
-               JComboBox<Gender> gender = new JComboBox<>(new DefaultComboBoxModel<>(genders));
-               
+
                // Panel for gender
                JPanel gPanel = new JPanel();
                gPanel.setLayout(new GridLayout(1, 2));
                
-               // Set tooltip text
-               gPanel.setToolTipText(this.getBundle().getString("AddressbookFrame.gender.tooltipText"));
-               
                // Gender text field
                JLabel gLabel = new JLabel(this.getBundle().getString("AddressbookFrame.gender.text"));
                
+               // Get all genders
+               Gender[] genders = Gender.values();
+               
+               // Init gender combo box with tool tip
+               JComboBox<Gender> gender = new JComboBox<>(new DefaultComboBoxModel<>(genders));
+               gender.setToolTipText(this.getBundle().getString("AddressbookFrame.gender.tooltipText"));
+
                // Add both to gender panel
                gPanel.add(gLabel);
                gPanel.add(gender);
-               
+
                // Add gender panel to "name" panel
                namePanel.add(gPanel);
-               
+
                // Panel for surname
                JPanel sPanel = new JPanel();
                sPanel.setLayout(new GridLayout(1, 2));
-               
-               // Set too tip text
-               sPanel.setToolTipText(this.getBundle().getString("AddressbookFrame.surname.tooltipText"));
-               
+
                // New label for surname is not needed
                JLabel sLabel = new JLabel(this.getBundle().getString("AddressbookFrame.surname.text"));
-               
-               // And input box
+
+               // And input box wih tool tip
                JTextField surname = new JTextField(20);
-               
+               surname.setToolTipText(this.getBundle().getString("AddressbookFrame.surname.tooltipText"));
+
                // Add both to surname panel
                sPanel.add(sLabel);
                sPanel.add(surname);
-               
+
                // Add surname panel to "name" panel
                namePanel.add(sPanel);
-               
+
                // Panel for surname
                JPanel fPanel = new JPanel();
                fPanel.setLayout(new GridLayout(1, 2));
-               
-               // Set too tip text
-               fPanel.setToolTipText(this.getBundle().getString("AddressbookFrame.familyName.tooltipText"));
-               
+
                // New label for surname is not needed
                JLabel fLabel = new JLabel(this.getBundle().getString("AddressbookFrame.familyName.text"));
-               
-               // And input box
+
+               // And input box wih tool tip
                JTextField familyName = new JTextField(20);
-               
+               familyName.setToolTipText(this.getBundle().getString("AddressbookFrame.familyName.tooltipText"));
+
                // Add both to surname panel
                fPanel.add(fLabel);
                fPanel.add(familyName);
-               
+
                // Add family namepanel to "name" panel
                namePanel.add(fPanel);
-               
+
                // Finally add panel to dialog
                this.addContact.add(namePanel);
        }
index a2740595432101b6f7e19c4eacc81531e3c6701e..6bd68df38d9ea1a745564c176dee70d483ddd945 100644 (file)
@@ -16,6 +16,8 @@
  */
 package org.mxchange.addressbook.contact;
 
+import org.mxchange.addressbook.application.AddressbookApplication;
+
 /**
  * Gender enum
  * @author Roland Haeder
@@ -104,8 +106,8 @@ public enum Gender {
                        // Debug message
                        //* NOISY-DEBUG: */ System.out.println("gender=" + gender);
 
-                       // Is it "U"?
-                       if (gender.getDatabaseValue().equals("U")) {
+                       // Is it UNKNOWN?
+                       if (gender.equals(Gender.UNKNOWN)) {
                                // Skip this
                                continue;
                        }
@@ -166,4 +168,15 @@ public enum Gender {
        protected String getMessageKey () {
                return this.messageKey;
        }
+
+       /**
+        * Overwritten to return human-readable strings
+        * 
+        * @return Human-readable strings
+        */
+       @Override
+       public String toString () {
+               // Get key from bundle and return it
+               return AddressbookApplication.getInstance().getMessageStringFromKey(this.getMessageKey());
+       }
 }
index 9fbe609c165d74c494a7c31fe02c8a5199591009..570c12fede8eecbabe2f57bc296d44e7ff96bdef 100644 (file)
@@ -27,12 +27,21 @@ AddressbookFrame.menuItem.editOwnData.toolTipText=Erlaubt das \u00c4ndern eigene
 AddressbookFrame.dialog.addContact.title.text=Neue Adresse hinzuf\u00fcgen
 AddressbookFrame.main.title.text=Adressen auflisten
 AddressbookFrame.border.name.title.text=Anrede, Vorname, Nachname:
+AddressbookFrame.border.address.title.text=Anschrift:
 AddressbookFrame.gender.text=Anrede:
 AddressbookFrame.gender.tooltipText=W\u00e4hlen Sie die Anrede aus.
 AddressbookFrame.surname.text=Vorname:
 AddressbookFrame.surname.tooltipText=Geben Sie den Vornamen ein.
 AddressbookFrame.familyName.text=Nachname:
 AddressbookFrame.familyName.tooltipText=Geben Sie den Nachnamen ein.
+AddressbookFrame.street.text=Stra\u00dfe:
+AddressbookFrame.street.tooltipText=Geben Sie die Stra\u00dfe ein.
+AddressbookFrame.number.text=Hausnummer:
+AddressbookFrame.number.tooltipText=Geben Sie die Hausnummer ein.
+AddressbookFrame.zip.text=PLZ:
+AddressbookFrame.zip.tooltipText=Geben Sie die Postleitzahl ein.
+AddressbookFrame.city.text=Stadt:
+AddressbookFrame.city.tooltipText=Geben Sie die Stadt ein.
 BaseContact.gender.unknown.text=Unbekannt
 BaseContact.gender.male.text=Herr
 BaseContact.gender.female.text=Frau
index 1bb83cd4b7f4ea9402bacf1420dcb22473590ada..7800af35131ed987a4d44cf9ae8816ff16433609 100644 (file)
@@ -27,12 +27,21 @@ AddressbookFrame.menuItem.editOwnData.toolTipText=Allows the user to edit own ad
 AddressbookFrame.dialog.addContact.title.text=Add new address
 AddressbookFrame.main.title.text=List addresses
 AddressbookFrame.border.name.title.text=Gender, surname, family name:
+AddressbookFrame.border.address.title.text=Anschrift:
 AddressbookFrame.gender.text=Gender:
 AddressbookFrame.gender.tooltipText=Choose gender.
 AddressbookFrame.surname.text=Surname:
 AddressbookFrame.surname.tooltipText=Enter surname.
 AddressbookFrame.familyName.text=Family name:
 AddressbookFrame.familyName.tooltipText=Enter family name.
+AddressbookFrame.street.text=Street:
+AddressbookFrame.street.tooltipText=Enter street.
+AddressbookFrame.number.text=Number:
+AddressbookFrame.number.tooltipText=Enter number.
+AddressbookFrame.zip.text=ZIP:
+AddressbookFrame.zip.tooltipText=Enter zip code.
+AddressbookFrame.city.text=City:
+AddressbookFrame.city.tooltipText=Enter city.
 BaseContact.gender.unknown.text=Unknown
 BaseContact.gender.male.text=Mr.
 BaseContact.gender.female.text=Mrs.