-/*
- * 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.AddressbookApplication;
-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();
-
- // Has the user entered own data?
- //if (client.)
-
- // 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() {
-
- enterDownDataDialog = new javax.swing.JDialog();
- menuBar = new javax.swing.JMenuBar();
- mainMenu = new javax.swing.JMenu();
- exitProgram = new javax.swing.JMenuItem();
- addressbookMenu = new javax.swing.JMenu();
- addOwnData = new javax.swing.JMenuItem();
-
- enterDownDataDialog.setAlwaysOnTop(true);
-
- javax.swing.GroupLayout enterDownDataDialogLayout = new javax.swing.GroupLayout(enterDownDataDialog.getContentPane());
- enterDownDataDialog.getContentPane().setLayout(enterDownDataDialogLayout);
- enterDownDataDialogLayout.setHorizontalGroup(
- enterDownDataDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGap(0, 400, Short.MAX_VALUE)
- );
- enterDownDataDialogLayout.setVerticalGroup(
- enterDownDataDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGap(0, 300, Short.MAX_VALUE)
- );
-
- java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/mxchange/addressbook/client/gui/Bundle"); // NOI18N
- enterDownDataDialog.getAccessibleContext().setAccessibleName(bundle.getString("AddressbookFrame.enterDownDataDialog.AccessibleContext.accessibleName")); // NOI18N
-
- setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
- setTitle(AddressbookApplication.printableTitle());
- setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
- setName("main"); // NOI18N
-
- mainMenu.setText(bundle.getString("AddressbookFrame.text")); // NOI18N
- mainMenu.setFocusable(false);
- mainMenu.setName(""); // NOI18N
-
- exitProgram.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.ALT_MASK));
- exitProgram.setText(bundle.getString("AddressbookFrame.exitProgram.text")); // NOI18N
- exitProgram.setToolTipText(bundle.getString("AddressbookFrame.exitProgram.toolTipText")); // NOI18N
- exitProgram.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- exitProgramActionPerformed(evt);
- }
- });
- mainMenu.add(exitProgram);
-
- menuBar.add(mainMenu);
-
- addressbookMenu.setText(bundle.getString("AddressbookFrame.addressbookMenu.text")); // NOI18N
-
- addOwnData.setText(bundle.getString("AddressbookFrame.addOwn.text")); // NOI18N
- addOwnData.setToolTipText(bundle.getString("AddressbookFrame.addOwnData.toolTipText")); // NOI18N
- addOwnData.setEnabled(false);
- addOwnData.setName("addOwn"); // NOI18N
- addOwnData.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- addOwnDataActionPerformed(evt);
- }
- });
- addressbookMenu.add(addOwnData);
- addOwnData.getAccessibleContext().setAccessibleName(bundle.getString("AddressbookFrame.addOwnData.AccessibleContext.accessibleName")); // NOI18N
- addOwnData.getAccessibleContext().setAccessibleDescription(bundle.getString("AddressbookFrame.addOwnData.AccessibleContext.accessibleDescription")); // NOI18N
-
- menuBar.add(addressbookMenu);
-
- setJMenuBar(menuBar);
-
- 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, 279, Short.MAX_VALUE)
- );
-
- pack();
- }// </editor-fold>//GEN-END:initComponents
-
- private void exitProgramActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitProgramActionPerformed
- // Close application instance
- this.getClient().getApplication().doShutdown();
- }//GEN-LAST:event_exitProgramActionPerformed
-
- private void addOwnDataActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addOwnDataActionPerformed
- // Asks the user to enter own data
- this.getClient().getContactManager().doEnterOwnData();
- }//GEN-LAST:event_addOwnDataActionPerformed
-
- /**
- * 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
- private javax.swing.JMenuItem addOwnData;
- private javax.swing.JMenu addressbookMenu;
- private javax.swing.JDialog enterDownDataDialog;
- private javax.swing.JMenuItem exitProgram;
- private javax.swing.JMenu mainMenu;
- private javax.swing.JMenuBar menuBar;
- // End of variables declaration//GEN-END:variables
-}
+/*\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 javax.swing.JFrame;\r
+import org.mxchange.addressbook.BaseFrameworkSystem;\r
+import org.mxchange.addressbook.FrameAlreadyInitializedException;\r
+import org.mxchange.addressbook.application.AddressbookApplication;\r
+import org.mxchange.addressbook.client.Client;\r
+\r
+/**\r
+ *\r
+ * @author Roland Haeder\r
+ */\r
+public class AddressbookFrame extends BaseFrameworkSystem implements ClientFrame {\r
+\r
+ /**\r
+ * Own instance\r
+ */\r
+ private static ClientFrame self;\r
+\r
+ /**\r
+ * Singelton getter for this frame instance.\r
+ *\r
+ * @param client Client instance\r
+ * @return Returns a singelton instance of this frame\r
+ */\r
+ public static final ClientFrame getSelfInstance (final Client client) {\r
+ // Is it set?\r
+ if (!(self instanceof ClientFrame)) {\r
+ // Create new instance\r
+ self = new AddressbookFrame(client);\r
+ }\r
+ \r
+ // Return instance\r
+ return self;\r
+ }\r
+\r
+ /**\r
+ * Frame instance\r
+ */\r
+ private final JFrame frame;\r
+\r
+ /**\r
+ * Whether this frame has been initialized\r
+ */\r
+ private boolean isInitialized;\r
+\r
+ /**\r
+ * Creates an instance of this frame with a client instance\r
+ * @param client\r
+ */\r
+ private AddressbookFrame (final Client client) {\r
+ // Debug line\r
+ this.getLogger().debug("Initializing Swing frame ...");\r
+\r
+ // Set frame instance\r
+ this.frame = new JFrame(AddressbookApplication.printableTitle());\r
+\r
+ // Set client here\r
+ this.setClient(client);\r
+ }\r
+\r
+ @Override\r
+ public void setVisible (final boolean visible) {\r
+ throw new UnsupportedOperationException("Not supported yet.");\r
+ }\r
+\r
+ /**\r
+ * Setups the frame\r
+ * \r
+ * @param client Client instance\r
+ */\r
+ @Override\r
+ public void setupFrame (final Client client) {\r
+ // Has the user entered own data?\r
+ if (this.getClient().getContactManager().isOwnContactAdded()) {\r
+ // Debug message\r
+ this.getLogger().debug("Disabling menus: isOwnContactAdded()=false");\r
+\r
+ // Not entered yet, so enable menu\r
+ //addOwnData.setEnabled(false);\r
+ }\r
+\r
+ // All done here\r
+ //statusLabel.setText(bundle.getString("AddressbookFrame.status.done.text"));\r
+ }\r
+\r
+ /**\r
+ * Initalizes this frame. Having initComponents() exposed (publicly\r
+ * accessible) means that any other object can initialize components which\r
+ * you may not want.\r
+ * \r
+ * @throws org.mxchange.addressbook.FrameAlreadyInitializedException If this method has been called twice\r
+ */\r
+ @Override\r
+ public void initFrame () throws FrameAlreadyInitializedException {\r
+ // Has this frame been initialized?\r
+ if (this.isInitialized) {\r
+ // Throw exception\r
+ throw new FrameAlreadyInitializedException();\r
+ }\r
+\r
+ // Init components\r
+ this.initComponents();\r
+\r
+ // Set flag\r
+ this.isInitialized = true;\r
+ }\r
+\r
+ /**\r
+ * Initialize components\r
+ */\r
+ private void initComponents () {\r
+ }\r
+\r
+}\r