]> git.mxchange.org Git - addressbook-lib.git/blob - Addressbook/src/org/mxchange/addressbook/client/gui/AddressbookFrame.java
Added stuff for Swing client
[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         // Has the user entered own data?
60         //if (client.)
61
62         // Set client here
63         this.client = client;
64     }
65
66     @Override
67     public Application getApplication () {
68         throw new UnsupportedOperationException("Not implemented.");
69     }
70
71     @Override
72     public final Client getClient () {
73         return this.client;
74     }
75
76     @Override
77     public ManageableContact getContactManager () {
78         throw new UnsupportedOperationException("Not implemented.");
79     }
80
81     /**
82      * This method is called from within the constructor to initialize the form.
83      * WARNING: Do NOT modify this code. The content of this method is always
84      * regenerated by the Form Editor.
85      */
86     @SuppressWarnings ("unchecked")
87     // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
88     private void initComponents() {
89
90         enterDownDataDialog = new javax.swing.JDialog();
91         menuBar = new javax.swing.JMenuBar();
92         mainMenu = new javax.swing.JMenu();
93         exitProgram = new javax.swing.JMenuItem();
94         addressbookMenu = new javax.swing.JMenu();
95         addOwnData = new javax.swing.JMenuItem();
96
97         enterDownDataDialog.setAlwaysOnTop(true);
98
99         javax.swing.GroupLayout enterDownDataDialogLayout = new javax.swing.GroupLayout(enterDownDataDialog.getContentPane());
100         enterDownDataDialog.getContentPane().setLayout(enterDownDataDialogLayout);
101         enterDownDataDialogLayout.setHorizontalGroup(
102             enterDownDataDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
103             .addGap(0, 400, Short.MAX_VALUE)
104         );
105         enterDownDataDialogLayout.setVerticalGroup(
106             enterDownDataDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
107             .addGap(0, 300, Short.MAX_VALUE)
108         );
109
110         java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/mxchange/addressbook/client/gui/Bundle"); // NOI18N
111         enterDownDataDialog.getAccessibleContext().setAccessibleName(bundle.getString("AddressbookFrame.enterDownDataDialog.AccessibleContext.accessibleName")); // NOI18N
112
113         setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
114         setTitle(AddressbookApplication.printableTitle());
115         setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
116         setName("main"); // NOI18N
117
118         mainMenu.setText(bundle.getString("AddressbookFrame.text")); // NOI18N
119         mainMenu.setFocusable(false);
120         mainMenu.setName(""); // NOI18N
121
122         exitProgram.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.ALT_MASK));
123         exitProgram.setText(bundle.getString("AddressbookFrame.exitProgram.text")); // NOI18N
124         exitProgram.setToolTipText(bundle.getString("AddressbookFrame.exitProgram.toolTipText")); // NOI18N
125         exitProgram.addActionListener(new java.awt.event.ActionListener() {
126             public void actionPerformed(java.awt.event.ActionEvent evt) {
127                 exitProgramActionPerformed(evt);
128             }
129         });
130         mainMenu.add(exitProgram);
131
132         menuBar.add(mainMenu);
133
134         addressbookMenu.setText(bundle.getString("AddressbookFrame.addressbookMenu.text")); // NOI18N
135
136         addOwnData.setText(bundle.getString("AddressbookFrame.addOwn.text")); // NOI18N
137         addOwnData.setToolTipText(bundle.getString("AddressbookFrame.addOwnData.toolTipText")); // NOI18N
138         addOwnData.setEnabled(false);
139         addOwnData.setName("addOwn"); // NOI18N
140         addOwnData.addActionListener(new java.awt.event.ActionListener() {
141             public void actionPerformed(java.awt.event.ActionEvent evt) {
142                 addOwnDataActionPerformed(evt);
143             }
144         });
145         addressbookMenu.add(addOwnData);
146         addOwnData.getAccessibleContext().setAccessibleName(bundle.getString("AddressbookFrame.addOwnData.AccessibleContext.accessibleName")); // NOI18N
147         addOwnData.getAccessibleContext().setAccessibleDescription(bundle.getString("AddressbookFrame.addOwnData.AccessibleContext.accessibleDescription")); // NOI18N
148
149         menuBar.add(addressbookMenu);
150
151         setJMenuBar(menuBar);
152
153         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
154         getContentPane().setLayout(layout);
155         layout.setHorizontalGroup(
156             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
157             .addGap(0, 400, Short.MAX_VALUE)
158         );
159         layout.setVerticalGroup(
160             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
161             .addGap(0, 279, Short.MAX_VALUE)
162         );
163
164         pack();
165     }// </editor-fold>//GEN-END:initComponents
166
167     private void exitProgramActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitProgramActionPerformed
168         // Close application instance
169         this.getClient().getApplication().doShutdown();
170     }//GEN-LAST:event_exitProgramActionPerformed
171
172     private void addOwnDataActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addOwnDataActionPerformed
173         // Asks the user to enter own data
174         this.getClient().getContactManager().doEnterOwnData();
175     }//GEN-LAST:event_addOwnDataActionPerformed
176
177     /**
178      * Initializes the frame
179      */
180     @Override
181     public void initFrame (final Client client) {
182         /*
183          * Set the Nimbus look and feel
184          */
185         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
186         /*
187          * If Nimbus (introduced in Java SE 6) is not available, stay with the
188          * default look and feel. For details see
189          * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
190          */
191         try {
192             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
193                 if ("Nimbus".equals(info.getName())) {
194                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
195                     break;
196                 }
197             }
198         } catch (final ClassNotFoundException ex) {
199             this.getLogger().catching(ex);
200         } catch (final InstantiationException ex) {
201             this.getLogger().catching(ex);
202         } catch (final IllegalAccessException ex) {
203             this.getLogger().catching(ex);
204         } catch (final javax.swing.UnsupportedLookAndFeelException ex) {
205             this.getLogger().catching(ex);
206         }
207         //</editor-fold>
208
209         // Debug line
210         this.getLogger().debug("Displaying form ...");
211
212         /*
213          * Create and display the form
214          */
215         java.awt.EventQueue.invokeLater(new Runnable() {
216             @Override
217             public void run () {
218                 new AddressbookFrame(client).setVisible(true);
219             }
220         });
221     }
222
223     /**
224      * Getter for logger
225      *
226      * @return Logger
227      */
228     protected final Logger getLogger () {
229         return this.LOG;
230     }
231
232     // Variables declaration - do not modify//GEN-BEGIN:variables
233     private javax.swing.JMenuItem addOwnData;
234     private javax.swing.JMenu addressbookMenu;
235     private javax.swing.JDialog enterDownDataDialog;
236     private javax.swing.JMenuItem exitProgram;
237     private javax.swing.JMenu mainMenu;
238     private javax.swing.JMenuBar menuBar;
239     // End of variables declaration//GEN-END:variables
240 }