From: Roland Haeder Date: Tue, 21 Jul 2015 12:11:25 +0000 (+0200) Subject: Added initial Swing frame class (Netbeans) and moved method initContactManager()... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=27f135983830bf9fc71b909db6c0fb97c618fccc;p=jaddressbook-share-lib.git Added initial Swing frame class (Netbeans) and moved method initContactManager() to BaseClient as only clients initialize it. Signed-off-by:Roland Häder --- diff --git a/Addressbook/src/org/mxchange/addressbook/BaseFrameworkSystem.java b/Addressbook/src/org/mxchange/addressbook/BaseFrameworkSystem.java index d922a49..6a249ec 100644 --- a/Addressbook/src/org/mxchange/addressbook/BaseFrameworkSystem.java +++ b/Addressbook/src/org/mxchange/addressbook/BaseFrameworkSystem.java @@ -20,7 +20,6 @@ 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.ContactManager; import org.mxchange.addressbook.manager.contact.ManageableContact; /** @@ -73,7 +72,7 @@ public class BaseFrameworkSystem implements FrameworkInterface { * @return the application */ @Override - public Application getApplication () { + public final Application getApplication () { return this.application; } @@ -83,7 +82,7 @@ public class BaseFrameworkSystem implements FrameworkInterface { * @return the client */ @Override - public Client getClient () { + public final Client getClient () { return this.client; } @@ -92,7 +91,7 @@ public class BaseFrameworkSystem implements FrameworkInterface { * @return the contactManager */ @Override - public ManageableContact getContactManager () { + public final ManageableContact getContactManager () { return this.contactManager; } @@ -100,7 +99,7 @@ public class BaseFrameworkSystem implements FrameworkInterface { * Contact manager instance * @param contactManager the contactManager to set */ - protected void setContactManager (final ManageableContact contactManager) { + protected final void setContactManager (final ManageableContact contactManager) { this.contactManager = contactManager; } @@ -108,7 +107,7 @@ public class BaseFrameworkSystem implements FrameworkInterface { * Client instance * @param client the client to set */ - protected void setClient (final Client client) { + protected final void setClient (final Client client) { this.client = client; } @@ -117,7 +116,7 @@ public class BaseFrameworkSystem implements FrameworkInterface { * * @param application the application to set */ - protected void setApplication(final Application application) { + protected final void setApplication(final Application application) { this.application = application; } @@ -126,7 +125,7 @@ public class BaseFrameworkSystem implements FrameworkInterface { * * @return Logger */ - protected Logger getLogger () { + protected final Logger getLogger () { return this.LOG; } @@ -135,7 +134,7 @@ public class BaseFrameworkSystem implements FrameworkInterface { * * @return the tableName */ - protected String getTableName () { + protected final String getTableName () { return this.tableName; } @@ -144,27 +143,7 @@ public class BaseFrameworkSystem implements FrameworkInterface { * * @param tableName the tableName to set */ - protected void setTableName (final String tableName) { + protected final void setTableName (final String tableName) { this.tableName = tableName; } - - /** - * Initializes contact manager - * - * @param client Client instance - */ - protected void initContactManager (final Client client) { - // Debug message - this.getLogger().debug("Initializing contact manager ..."); - - // Init contact manager with console client - // @TODO Static initial amount of contacts - ManageableContact manager = new ContactManager (100, client); - - // Set it here - this.setContactManager(manager); - - // Debug message - this.getLogger().debug("Contact manager has been initialized."); - } } diff --git a/Addressbook/src/org/mxchange/addressbook/application/AddressbookApplication.java b/Addressbook/src/org/mxchange/addressbook/application/AddressbookApplication.java index fcda1bc..0b6e918 100644 --- a/Addressbook/src/org/mxchange/addressbook/application/AddressbookApplication.java +++ b/Addressbook/src/org/mxchange/addressbook/application/AddressbookApplication.java @@ -164,7 +164,10 @@ public class AddressbookApplication extends BaseFrameworkSystem implements Appli this.getLogger().error("No client choosen. Cannot launch."); System.exit(1); } - + + // Init client + client.initClient(); + // Set client instance this.setClient(client); diff --git a/Addressbook/src/org/mxchange/addressbook/client/BaseClient.java b/Addressbook/src/org/mxchange/addressbook/client/BaseClient.java index 399ddb4..04b1ad5 100644 --- a/Addressbook/src/org/mxchange/addressbook/client/BaseClient.java +++ b/Addressbook/src/org/mxchange/addressbook/client/BaseClient.java @@ -19,6 +19,8 @@ package org.mxchange.addressbook.client; import java.util.HashMap; import java.util.Map; import org.mxchange.addressbook.BaseFrameworkSystem; +import org.mxchange.addressbook.manager.contact.ContactManager; +import org.mxchange.addressbook.manager.contact.ManageableContact; import org.mxchange.addressbook.menu.Menu; /** @@ -146,4 +148,22 @@ public abstract class BaseClient extends BaseFrameworkSystem { // Show menu menu.show((Client) this); } + + /** + * Initializes contact manager + */ + protected void initContactManager () { + // Debug message + this.getLogger().debug("Initializing contact manager ..."); + + // Init contact manager with console client + // @TODO Static initial amount of contacts + ManageableContact manager = new ContactManager (100, (Client) this); + + // Set it here + this.setContactManager(manager); + + // Debug message + this.getLogger().debug("Contact manager has been initialized."); + } } diff --git a/Addressbook/src/org/mxchange/addressbook/client/Client.java b/Addressbook/src/org/mxchange/addressbook/client/Client.java index 9a8ad8b..a776c88 100644 --- a/Addressbook/src/org/mxchange/addressbook/client/Client.java +++ b/Addressbook/src/org/mxchange/addressbook/client/Client.java @@ -149,4 +149,9 @@ public interface Client extends FrameworkInterface { * Shows current menu selection to the user */ public void showCurrentMenu(); + + /** + * Inizializes this client + */ + public void initClient (); } diff --git a/Addressbook/src/org/mxchange/addressbook/client/console/ConsoleClient.java b/Addressbook/src/org/mxchange/addressbook/client/console/ConsoleClient.java index 5249c5f..82d80d8 100644 --- a/Addressbook/src/org/mxchange/addressbook/client/console/ConsoleClient.java +++ b/Addressbook/src/org/mxchange/addressbook/client/console/ConsoleClient.java @@ -52,14 +52,8 @@ public class ConsoleClient extends BaseClient implements Client { // Set application instance this.setApplication(application); - // Init contact manager here - this.initContactManager(this); - // Init scanner instance this.scanner = new Scanner(System.in); - - // Fill menu map - this.fillMenuMap(); } /** @@ -71,7 +65,7 @@ public class ConsoleClient extends BaseClient implements Client { @Override public void displayAddressBox (final Contact contact) { // Simple display ... - // @todo Use mask + // @todo Use mask this.outputMessage("Strasse, PLZ Ort, Land: " + contact.getStreet() + "\n" + contact.getZipCode() + " " + contact.getCity() + "\n" + contact.getCountryCode()); } @@ -257,6 +251,18 @@ public class ConsoleClient extends BaseClient implements Client { return new ConsoleMenuItem(accessKey,text); } + /** + * Inizializes this client + */ + @Override + public void initClient () { + // Init contact manager here + this.initContactManager(); + + // Fill menu map + this.fillMenuMap(); + } + /** * Displays textural message to the user * @param message 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 index 0000000..112b81f --- /dev/null +++ b/Addressbook/src/org/mxchange/addressbook/client/gui/AddressbookFrame.form @@ -0,0 +1,35 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
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 index 0000000..1a629c0 --- /dev/null +++ b/Addressbook/src/org/mxchange/addressbook/client/gui/AddressbookFrame.java @@ -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 . + */ +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") + // //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(); + }// //GEN-END:initComponents + + /** + * Initializes the frame + */ + @Override + public void initFrame (final Client client) { + /* + * Set the Nimbus look and feel + */ + // + /* + * 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); + } + // + + // 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 index 0000000..21a822b --- /dev/null +++ b/Addressbook/src/org/mxchange/addressbook/client/gui/ClientFrame.java @@ -0,0 +1,33 @@ +/* + * 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 . + */ +package org.mxchange.addressbook.client.gui; + +import org.mxchange.addressbook.FrameworkInterface; +import org.mxchange.addressbook.client.Client; + +/** + * + * @author Roland Haeder + */ +public interface ClientFrame extends FrameworkInterface { + /** + * Initializes the frame + * + * @param client Client instance + */ + public void initFrame (final Client client); +} diff --git a/Addressbook/src/org/mxchange/addressbook/client/gui/SwingClient.java b/Addressbook/src/org/mxchange/addressbook/client/gui/SwingClient.java index 87686e9..88dfb96 100644 --- a/Addressbook/src/org/mxchange/addressbook/client/gui/SwingClient.java +++ b/Addressbook/src/org/mxchange/addressbook/client/gui/SwingClient.java @@ -29,6 +29,11 @@ import org.mxchange.addressbook.menu.item.SelectableMenuItem; * @author Roland Haeder */ public class SwingClient extends BaseClient implements Client { + /** + * Swing frame instance + */ + private final ClientFrame frame; + /** * Constructor with application instance * @param application @@ -39,8 +44,8 @@ public class SwingClient extends BaseClient implements Client { // Set application instance this.setApplication(application); - // Init contact manager here - this.initContactManager(this); + // Init frame instance + this.frame = new AddressbookFrame(this); } @Override @@ -97,6 +102,18 @@ public class SwingClient extends BaseClient implements Client { return null; } + /** + * Inizializes this client + */ + @Override + public void initClient () { + // Init contact manager here + this.initContactManager(); + + // Now start the frame + this.frame.initFrame(this); + } + @Override public void outputMessage (final String message) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.