2 * Copyright (C) 2015 Roland Haeder
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.
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.
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/>.
17 package org.mxchange.addressbook.client.gui;
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;
28 * @author Roland Haeder
30 public class AddressbookFrame extends javax.swing.JFrame implements ClientFrame {
34 private final Logger LOG;
39 private final Client client;
45 LOG = LogManager.getLogger(this);
49 * Creates an instance of this frame with a client instance
52 public AddressbookFrame (final Client client) {
54 this.getLogger().debug("Initializing Swing frame ...");
59 // Has the user entered own data?
67 public Application getApplication () {
68 throw new UnsupportedOperationException("Not implemented.");
72 public final Client getClient () {
77 public ManageableContact getContactManager () {
78 throw new UnsupportedOperationException("Not implemented.");
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.
86 @SuppressWarnings ("unchecked")
87 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
88 private void initComponents() {
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();
97 enterDownDataDialog.setAlwaysOnTop(true);
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)
105 enterDownDataDialogLayout.setVerticalGroup(
106 enterDownDataDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
107 .addGap(0, 300, Short.MAX_VALUE)
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
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
118 mainMenu.setText(bundle.getString("AddressbookFrame.text")); // NOI18N
119 mainMenu.setFocusable(false);
120 mainMenu.setName(""); // NOI18N
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);
130 mainMenu.add(exitProgram);
132 menuBar.add(mainMenu);
134 addressbookMenu.setText(bundle.getString("AddressbookFrame.addressbookMenu.text")); // NOI18N
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);
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
149 menuBar.add(addressbookMenu);
151 setJMenuBar(menuBar);
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)
159 layout.setVerticalGroup(
160 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
161 .addGap(0, 279, Short.MAX_VALUE)
165 }// </editor-fold>//GEN-END:initComponents
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
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
178 * Initializes the frame
181 public void initFrame (final Client client) {
183 * Set the Nimbus look and feel
185 //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
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
192 for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
193 if ("Nimbus".equals(info.getName())) {
194 javax.swing.UIManager.setLookAndFeel(info.getClassName());
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);
210 this.getLogger().debug("Displaying form ...");
213 * Create and display the form
215 java.awt.EventQueue.invokeLater(new Runnable() {
218 new AddressbookFrame(client).setVisible(true);
228 protected final Logger getLogger () {
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