]> git.mxchange.org Git - addressbook-lib.git/blob - Addressbook/src/org/mxchange/addressbook/client/gui/AddressbookFrame.java
the contact manager instance only exists when initFrame() is called and not on object...
[addressbook-lib.git] / Addressbook / src / org / mxchange / addressbook / client / gui / AddressbookFrame.java
1 /*
2  * Copyright (C) 2015 Roland Haeder
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 package org.mxchange.addressbook.client.gui;
18
19 import org.apache.logging.log4j.LogManager;
20 import org.apache.logging.log4j.Logger;
21 import org.mxchange.addressbook.application.AddressbookApplication;
22 import org.mxchange.addressbook.application.Application;
23 import org.mxchange.addressbook.client.Client;
24 import org.mxchange.addressbook.manager.contact.ManageableContact;
25
26 /**
27  *
28  * @author Roland Haeder
29  */
30 public class AddressbookFrame extends javax.swing.JFrame implements ClientFrame {
31     /**
32      * Class' logger
33      */
34     private final Logger LOG;
35
36     /**
37      * Client instance
38      */
39     private final Client client;
40
41     /**
42      * Initialize object
43      */
44     {
45         LOG = LogManager.getLogger(this);
46     }
47
48     /**
49      * Creates an instance of this frame with a client instance
50      * @param client 
51      */
52     public AddressbookFrame (final Client client) {
53         // Debug line
54         this.getLogger().debug("Initializing Swing frame ...");
55
56         // Init components
57         initComponents();
58
59         // Set client here
60         this.client = client;
61     }
62
63     @Override
64     public Application getApplication () {
65         throw new UnsupportedOperationException("Not implemented.");
66     }
67
68     @Override
69     public final Client getClient () {
70         return this.client;
71     }
72
73     @Override
74     public ManageableContact getContactManager () {
75         throw new UnsupportedOperationException("Not implemented.");
76     }
77
78     /**
79      * This method is called from within the constructor to initialize the form.
80      * WARNING: Do NOT modify this code. The content of this method is always
81      * regenerated by the Form Editor.
82      */
83     @SuppressWarnings ("unchecked")
84     // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
85     private void initComponents() {
86
87         enterDownDataDialog = new javax.swing.JDialog();
88         menuBar = new javax.swing.JMenuBar();
89         mainMenu = new javax.swing.JMenu();
90         exitProgram = new javax.swing.JMenuItem();
91         addressbookMenu = new javax.swing.JMenu();
92         addOwnData = new javax.swing.JMenuItem();
93
94         enterDownDataDialog.setAlwaysOnTop(true);
95
96         javax.swing.GroupLayout enterDownDataDialogLayout = new javax.swing.GroupLayout(enterDownDataDialog.getContentPane());
97         enterDownDataDialog.getContentPane().setLayout(enterDownDataDialogLayout);
98         enterDownDataDialogLayout.setHorizontalGroup(
99             enterDownDataDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
100             .addGap(0, 400, Short.MAX_VALUE)
101         );
102         enterDownDataDialogLayout.setVerticalGroup(
103             enterDownDataDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
104             .addGap(0, 300, Short.MAX_VALUE)
105         );
106
107         java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/mxchange/addressbook/client/gui/Bundle"); // NOI18N
108         enterDownDataDialog.getAccessibleContext().setAccessibleName(bundle.getString("AddressbookFrame.enterDownDataDialog.AccessibleContext.accessibleName")); // NOI18N
109
110         setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
111         setTitle(AddressbookApplication.printableTitle());
112         setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
113         setName("main"); // NOI18N
114
115         mainMenu.setText(bundle.getString("AddressbookFrame.text")); // NOI18N
116         mainMenu.setFocusable(false);
117         mainMenu.setName(""); // NOI18N
118
119         exitProgram.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.ALT_MASK));
120         exitProgram.setText(bundle.getString("AddressbookFrame.exitProgram.text")); // NOI18N
121         exitProgram.setToolTipText(bundle.getString("AddressbookFrame.exitProgram.toolTipText")); // NOI18N
122         exitProgram.addActionListener(new java.awt.event.ActionListener() {
123             public void actionPerformed(java.awt.event.ActionEvent evt) {
124                 exitProgramActionPerformed(evt);
125             }
126         });
127         mainMenu.add(exitProgram);
128
129         menuBar.add(mainMenu);
130
131         addressbookMenu.setText(bundle.getString("AddressbookFrame.addressbookMenu.text")); // NOI18N
132
133         addOwnData.setText(bundle.getString("AddressbookFrame.addOwn.text")); // NOI18N
134         addOwnData.setToolTipText(bundle.getString("AddressbookFrame.addOwnData.toolTipText")); // NOI18N
135         addOwnData.setEnabled(false);
136         addOwnData.setName("addOwn"); // NOI18N
137         addOwnData.addActionListener(new java.awt.event.ActionListener() {
138             public void actionPerformed(java.awt.event.ActionEvent evt) {
139                 addOwnDataActionPerformed(evt);
140             }
141         });
142         addressbookMenu.add(addOwnData);
143         addOwnData.getAccessibleContext().setAccessibleName(bundle.getString("AddressbookFrame.addOwnData.AccessibleContext.accessibleName")); // NOI18N
144         addOwnData.getAccessibleContext().setAccessibleDescription(bundle.getString("AddressbookFrame.addOwnData.AccessibleContext.accessibleDescription")); // NOI18N
145
146         menuBar.add(addressbookMenu);
147
148         setJMenuBar(menuBar);
149
150         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
151         getContentPane().setLayout(layout);
152         layout.setHorizontalGroup(
153             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
154             .addGap(0, 400, Short.MAX_VALUE)
155         );
156         layout.setVerticalGroup(
157             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
158             .addGap(0, 279, Short.MAX_VALUE)
159         );
160
161         pack();
162     }// </editor-fold>//GEN-END:initComponents
163
164     private void exitProgramActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitProgramActionPerformed
165         // Close application instance
166         this.getClient().getApplication().doShutdown();
167     }//GEN-LAST:event_exitProgramActionPerformed
168
169     private void addOwnDataActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addOwnDataActionPerformed
170         // Asks the user to enter own data
171         this.getClient().getContactManager().doEnterOwnData();
172     }//GEN-LAST:event_addOwnDataActionPerformed
173
174     /**
175      * Setups the frame
176      * 
177      * @param client Client instance
178      */
179     @Override
180     public void setupFrame (final Client client) {
181         // Has the user entered own data?
182         if (!this.getClient().getContactManager().isOwnContactAdded()) {
183             // Debug message
184             this.getLogger().debug("Enabling menus: isOwnContactAdded()=false");
185
186             // Not entered yet, so enable menu
187             addOwnData.setEnabled(true);
188         }
189
190         /*
191          * Set the Nimbus look and feel
192          */
193         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
194         /*
195          * If Nimbus (introduced in Java SE 6) is not available, stay with the
196          * default look and feel. For details see
197          * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
198          */
199         try {
200             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
201                 if ("Nimbus".equals(info.getName())) {
202                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
203                     break;
204                 }
205             }
206         } catch (final ClassNotFoundException ex) {
207             this.getLogger().catching(ex);
208         } catch (final InstantiationException ex) {
209             this.getLogger().catching(ex);
210         } catch (final IllegalAccessException ex) {
211             this.getLogger().catching(ex);
212         } catch (final javax.swing.UnsupportedLookAndFeelException ex) {
213             this.getLogger().catching(ex);
214         }
215         //</editor-fold>
216
217         // Debug line
218         this.getLogger().debug("Displaying form ...");
219
220         /*
221          * Create and display the form
222          */
223         java.awt.EventQueue.invokeLater(new Runnable() {
224             @Override
225             public void run () {
226                 new AddressbookFrame(client).setVisible(true);
227             }
228         });
229     }
230
231     /**
232      * Getter for logger
233      *
234      * @return Logger
235      */
236     protected final Logger getLogger () {
237         return this.LOG;
238     }
239
240     // Variables declaration - do not modify//GEN-BEGIN:variables
241     private javax.swing.JMenuItem addOwnData;
242     private javax.swing.JMenu addressbookMenu;
243     private javax.swing.JDialog enterDownDataDialog;
244     private javax.swing.JMenuItem exitProgram;
245     private javax.swing.JMenu mainMenu;
246     private javax.swing.JMenuBar menuBar;
247     // End of variables declaration//GEN-END:variables
248 }