]> git.mxchange.org Git - jaddressbook-lib.git/commitdiff
Added initial Swing frame class (Netbeans) and moved method initContactManager()...
authorRoland Haeder <roland@mxchange.org>
Tue, 21 Jul 2015 12:11:25 +0000 (14:11 +0200)
committerRoland Haeder <roland@mxchange.org>
Tue, 21 Jul 2015 12:11:44 +0000 (14:11 +0200)
Signed-off-by:Roland Häder <roland@mxchange.org>

Addressbook/src/org/mxchange/addressbook/BaseFrameworkSystem.java
Addressbook/src/org/mxchange/addressbook/application/AddressbookApplication.java
Addressbook/src/org/mxchange/addressbook/client/BaseClient.java
Addressbook/src/org/mxchange/addressbook/client/Client.java
Addressbook/src/org/mxchange/addressbook/client/console/ConsoleClient.java
Addressbook/src/org/mxchange/addressbook/client/gui/AddressbookFrame.form [new file with mode: 0644]
Addressbook/src/org/mxchange/addressbook/client/gui/AddressbookFrame.java [new file with mode: 0644]
Addressbook/src/org/mxchange/addressbook/client/gui/ClientFrame.java [new file with mode: 0644]
Addressbook/src/org/mxchange/addressbook/client/gui/SwingClient.java

index d922a491926f56345c892fa7696e0ba8d19a9c88..6a249ec7bfea18b76a06bb7508c018aea8c66cfd 100644 (file)
@@ -20,7 +20,6 @@ import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;\r
 import org.mxchange.addressbook.application.Application;\r
 import org.mxchange.addressbook.client.Client;\r
-import org.mxchange.addressbook.manager.contact.ContactManager;\r
 import org.mxchange.addressbook.manager.contact.ManageableContact;\r
 \r
 /**\r
@@ -73,7 +72,7 @@ public class BaseFrameworkSystem implements FrameworkInterface {
      * @return the application\r
      */\r
     @Override\r
-    public Application getApplication () {\r
+    public final Application getApplication () {\r
        return this.application;\r
     }\r
 \r
@@ -83,7 +82,7 @@ public class BaseFrameworkSystem implements FrameworkInterface {
      * @return the client\r
      */\r
     @Override\r
-    public Client getClient () {\r
+    public final Client getClient () {\r
        return this.client;\r
     }\r
 \r
@@ -92,7 +91,7 @@ public class BaseFrameworkSystem implements FrameworkInterface {
      * @return the contactManager\r
      */\r
     @Override\r
-    public ManageableContact getContactManager () {\r
+    public final ManageableContact getContactManager () {\r
        return this.contactManager;\r
     }\r
 \r
@@ -100,7 +99,7 @@ public class BaseFrameworkSystem implements FrameworkInterface {
      * Contact manager instance\r
      * @param contactManager the contactManager to set\r
      */\r
-    protected void setContactManager (final ManageableContact contactManager) {\r
+    protected final void setContactManager (final ManageableContact contactManager) {\r
        this.contactManager = contactManager;\r
     }\r
 \r
@@ -108,7 +107,7 @@ public class BaseFrameworkSystem implements FrameworkInterface {
      * Client instance\r
      * @param client the client to set\r
      */\r
-    protected void setClient (final Client client) {\r
+    protected final void setClient (final Client client) {\r
        this.client = client;\r
     }\r
 \r
@@ -117,7 +116,7 @@ public class BaseFrameworkSystem implements FrameworkInterface {
      *\r
      * @param application the application to set\r
      */\r
-    protected void setApplication(final Application application) {\r
+    protected final void setApplication(final Application application) {\r
        this.application = application;\r
     }\r
 \r
@@ -126,7 +125,7 @@ public class BaseFrameworkSystem implements FrameworkInterface {
      *\r
      * @return Logger\r
      */\r
-    protected Logger getLogger () {\r
+    protected final Logger getLogger () {\r
        return this.LOG;\r
     }\r
 \r
@@ -135,7 +134,7 @@ public class BaseFrameworkSystem implements FrameworkInterface {
      * \r
      * @return the tableName\r
      */\r
-    protected String getTableName () {\r
+    protected final String getTableName () {\r
        return this.tableName;\r
     }\r
 \r
@@ -144,27 +143,7 @@ public class BaseFrameworkSystem implements FrameworkInterface {
      * \r
      * @param tableName the tableName to set\r
      */\r
-    protected void setTableName (final String tableName) {\r
+    protected final void setTableName (final String tableName) {\r
        this.tableName = tableName;\r
     }\r
-\r
-    /**\r
-     * Initializes contact manager\r
-     * \r
-     * @param client Client instance\r
-     */\r
-    protected void initContactManager (final Client client) {\r
-       // Debug message\r
-       this.getLogger().debug("Initializing contact manager ...");\r
-       \r
-       // Init contact manager with console client\r
-       // @TODO Static initial amount of contacts\r
-       ManageableContact manager = new ContactManager (100, client);\r
-       \r
-       // Set it here\r
-       this.setContactManager(manager);\r
-       \r
-       // Debug message\r
-       this.getLogger().debug("Contact manager has been initialized.");\r
-    }\r
 }\r
index fcda1bca021f4c138bdefe0856442683fe4b0818..0b6e918d4f14b2ff39e18c3c94b055c2def6f14e 100644 (file)
@@ -164,7 +164,10 @@ public class AddressbookApplication extends BaseFrameworkSystem implements Appli
            this.getLogger().error("No client choosen. Cannot launch.");\r
            System.exit(1);\r
        }\r
-       \r
+\r
+       // Init client\r
+       client.initClient();\r
+\r
        // Set client instance\r
        this.setClient(client);\r
        \r
index 399ddb4ac1bc57272941224a59bce3ae7f7dfba7..04b1ad5ce34a484a1b7538aaf413f798e7ce098e 100644 (file)
@@ -19,6 +19,8 @@ package org.mxchange.addressbook.client;
 import java.util.HashMap;\r
 import java.util.Map;\r
 import org.mxchange.addressbook.BaseFrameworkSystem;\r
+import org.mxchange.addressbook.manager.contact.ContactManager;\r
+import org.mxchange.addressbook.manager.contact.ManageableContact;\r
 import org.mxchange.addressbook.menu.Menu;\r
 \r
 /**\r
@@ -146,4 +148,22 @@ public abstract class BaseClient extends BaseFrameworkSystem {
        // Show menu\r
        menu.show((Client) this);\r
     }\r
+\r
+    /**\r
+     * Initializes contact manager\r
+     */\r
+    protected void initContactManager () {\r
+       // Debug message\r
+       this.getLogger().debug("Initializing contact manager ...");\r
+       \r
+       // Init contact manager with console client\r
+       // @TODO Static initial amount of contacts\r
+       ManageableContact manager = new ContactManager (100, (Client) this);\r
+       \r
+       // Set it here\r
+       this.setContactManager(manager);\r
+       \r
+       // Debug message\r
+       this.getLogger().debug("Contact manager has been initialized.");\r
+    }\r
 }\r
index 9a8ad8b467e6759c4f6782463e2a748b0c0e59fc..a776c88f97d8b66dc514fadc612ad90f95aa074b 100644 (file)
@@ -149,4 +149,9 @@ public interface Client extends FrameworkInterface {
      * Shows current menu selection to the user\r
      */\r
     public void showCurrentMenu();\r
+\r
+    /**\r
+     * Inizializes this client\r
+     */\r
+    public void initClient ();\r
 }\r
index 5249c5f9fecd2a958f884821f6a1323b0ef9b048..82d80d824e86ceebc5353cf7cda31952d2467662 100644 (file)
@@ -52,14 +52,8 @@ public class ConsoleClient extends BaseClient implements Client {
        // Set application instance\r
        this.setApplication(application);\r
 \r
-       // Init contact manager here\r
-       this.initContactManager(this);\r
-\r
        // Init scanner instance\r
        this.scanner = new Scanner(System.in);\r
-\r
-       // Fill menu map\r
-       this.fillMenuMap();\r
     }\r
 \r
     /**\r
@@ -71,7 +65,7 @@ public class ConsoleClient extends BaseClient implements Client {
     @Override\r
     public void displayAddressBox (final Contact contact) {\r
        // Simple display ...\r
-        // @todo Use mask\r
+       // @todo Use mask\r
        this.outputMessage("Strasse, PLZ Ort, Land: " + contact.getStreet() + "\n" + contact.getZipCode() + " " + contact.getCity() +  "\n" + contact.getCountryCode());\r
     }\r
 \r
@@ -257,6 +251,18 @@ public class ConsoleClient extends BaseClient implements Client {
        return new ConsoleMenuItem(accessKey,text);\r
     }\r
 \r
+    /**\r
+     * Inizializes this client\r
+     */\r
+    @Override\r
+    public void initClient () {\r
+       // Init contact manager here\r
+       this.initContactManager();\r
+       \r
+       // Fill menu map\r
+       this.fillMenuMap();\r
+    }\r
+\r
     /**\r
      * Displays textural message to the user\r
      * @param message\r
diff --git a/Addressbook/src/org/mxchange/addressbook/client/gui/AddressbookFrame.form b/Addressbook/src/org/mxchange/addressbook/client/gui/AddressbookFrame.form
new file mode 100644 (file)
index 0000000..112b81f
--- /dev/null
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<Form version="1.5" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
+  <Properties>
+    <Property name="defaultCloseOperation" type="int" value="3"/>
+  </Properties>
+  <SyntheticProperties>
+    <SyntheticProperty name="formSizePolicy" type="int" value="1"/>
+    <SyntheticProperty name="generateCenter" type="boolean" value="false"/>
+  </SyntheticProperties>
+  <AuxValues>
+    <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="1"/>
+    <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
+    <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
+    <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
+    <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="true"/>
+    <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
+    <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
+    <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
+    <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
+  </AuxValues>
+
+  <Layout>
+    <DimensionLayout dim="0">
+      <Group type="103" groupAlignment="0" attributes="0">
+          <EmptySpace min="0" pref="400" max="32767" attributes="0"/>
+      </Group>
+    </DimensionLayout>
+    <DimensionLayout dim="1">
+      <Group type="103" groupAlignment="0" attributes="0">
+          <EmptySpace min="0" pref="300" max="32767" attributes="0"/>
+      </Group>
+    </DimensionLayout>
+  </Layout>
+</Form>
diff --git a/Addressbook/src/org/mxchange/addressbook/client/gui/AddressbookFrame.java b/Addressbook/src/org/mxchange/addressbook/client/gui/AddressbookFrame.java
new file mode 100644 (file)
index 0000000..1a629c0
--- /dev/null
@@ -0,0 +1,159 @@
+/*
+ * Copyright (C) 2015 Roland Haeder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.client.gui;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.mxchange.addressbook.application.Application;
+import org.mxchange.addressbook.client.Client;
+import org.mxchange.addressbook.manager.contact.ManageableContact;
+
+/**
+ *
+ * @author Roland Haeder
+ */
+public class AddressbookFrame extends javax.swing.JFrame implements ClientFrame {
+    /**
+     * Class' logger
+     */
+    private final Logger LOG;
+
+    /**
+     * Client instance
+     */
+    private final Client client;
+
+    /**
+     * Initialize object
+     */
+    {
+       LOG = LogManager.getLogger(this);
+    }
+
+    /**
+     * Creates an instance of this frame with a client instance
+     * @param client 
+     */
+    public AddressbookFrame (final Client client) {
+       // Debug line
+       this.getLogger().debug("Initializing Swing frame ...");
+
+       // Init components
+       initComponents();
+
+       // Set client here
+       this.client = client;
+    }
+
+    @Override
+    public Application getApplication () {
+       throw new UnsupportedOperationException("Not implemented.");
+    }
+
+    @Override
+    public final Client getClient () {
+       return this.client;
+    }
+
+    @Override
+    public ManageableContact getContactManager () {
+       throw new UnsupportedOperationException("Not implemented.");
+    }
+
+    /**
+     * This method is called from within the constructor to initialize the form.
+     * WARNING: Do NOT modify this code. The content of this method is always
+     * regenerated by the Form Editor.
+     */
+    @SuppressWarnings ("unchecked")
+    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
+    private void initComponents() {
+
+        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
+
+        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
+        getContentPane().setLayout(layout);
+        layout.setHorizontalGroup(
+            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addGap(0, 400, Short.MAX_VALUE)
+        );
+        layout.setVerticalGroup(
+            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addGap(0, 300, Short.MAX_VALUE)
+        );
+
+        pack();
+    }// </editor-fold>//GEN-END:initComponents
+
+    /**
+     * Initializes the frame
+     */
+    @Override
+    public void initFrame (final Client client) {
+       /*
+        * Set the Nimbus look and feel
+        */
+        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
+        /*
+        * If Nimbus (introduced in Java SE 6) is not available, stay with the
+        * default look and feel. For details see
+        * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
+        */
+       try {
+           for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
+               if ("Nimbus".equals(info.getName())) {
+                   javax.swing.UIManager.setLookAndFeel(info.getClassName());
+                   break;
+               }
+           }
+       } catch (final ClassNotFoundException ex) {
+           this.getLogger().catching(ex);
+       } catch (final InstantiationException ex) {
+           this.getLogger().catching(ex);
+       } catch (final IllegalAccessException ex) {
+           this.getLogger().catching(ex);
+       } catch (final javax.swing.UnsupportedLookAndFeelException ex) {
+           this.getLogger().catching(ex);
+       }
+        //</editor-fold>
+
+       // Debug line
+       this.getLogger().debug("Displaying form ...");
+
+       /*
+        * Create and display the form
+        */
+       java.awt.EventQueue.invokeLater(new Runnable() {
+           @Override
+           public void run () {
+               new AddressbookFrame(client).setVisible(true);
+           }
+       });
+    }
+
+    /**
+     * Getter for logger
+     *
+     * @return Logger
+     */
+    protected final Logger getLogger () {
+       return this.LOG;
+    }
+
+    // Variables declaration - do not modify//GEN-BEGIN:variables
+    // End of variables declaration//GEN-END:variables
+}
diff --git a/Addressbook/src/org/mxchange/addressbook/client/gui/ClientFrame.java b/Addressbook/src/org/mxchange/addressbook/client/gui/ClientFrame.java
new file mode 100644 (file)
index 0000000..21a822b
--- /dev/null
@@ -0,0 +1,33 @@
+/*\r
+ * Copyright (C) 2015 Roland Haeder\r
+ *\r
+ * This program is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
+ */\r
+package org.mxchange.addressbook.client.gui;\r
+\r
+import org.mxchange.addressbook.FrameworkInterface;\r
+import org.mxchange.addressbook.client.Client;\r
+\r
+/**\r
+ *\r
+ * @author Roland Haeder\r
+ */\r
+public interface ClientFrame extends FrameworkInterface {\r
+    /**\r
+     * Initializes the frame\r
+     * \r
+     * @param client Client instance\r
+     */\r
+    public void initFrame (final Client client);\r
+}\r
index 87686e9ecbbbd5d5f7532d9be766b7c9699cb88c..88dfb96b58fef366eceaa729e52064b8e69ca5be 100644 (file)
@@ -29,6 +29,11 @@ import org.mxchange.addressbook.menu.item.SelectableMenuItem;
  * @author Roland Haeder\r
  */\r
 public class SwingClient extends BaseClient implements Client {\r
+    /**\r
+     * Swing frame instance\r
+     */\r
+    private final ClientFrame frame;\r
+\r
     /**\r
      * Constructor with application instance\r
      * @param application \r
@@ -39,8 +44,8 @@ public class SwingClient extends BaseClient implements Client {
        // Set application instance\r
        this.setApplication(application);\r
 \r
-       // Init contact manager here\r
-       this.initContactManager(this);\r
+       // Init frame instance\r
+       this.frame = new AddressbookFrame(this);\r
     }\r
 \r
     @Override\r
@@ -97,6 +102,18 @@ public class SwingClient extends BaseClient implements Client {
        return null;\r
     }\r
 \r
+    /**\r
+     * Inizializes this client\r
+     */\r
+    @Override\r
+    public void initClient () {\r
+       // Init contact manager here\r
+       this.initContactManager();\r
+       \r
+       // Now start the frame\r
+       this.frame.initFrame(this);\r
+    }\r
+\r
     @Override\r
     public void outputMessage (final String message) {\r
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.\r