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 ...");
64 public Application getApplication () {
65 throw new UnsupportedOperationException("Not implemented.");
69 public final Client getClient () {
74 public ManageableContact getContactManager () {
75 throw new UnsupportedOperationException("Not implemented.");
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.
83 @SuppressWarnings ("unchecked")
84 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
85 private void initComponents() {
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();
94 enterDownDataDialog.setAlwaysOnTop(true);
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)
102 enterDownDataDialogLayout.setVerticalGroup(
103 enterDownDataDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
104 .addGap(0, 300, Short.MAX_VALUE)
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
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
115 mainMenu.setText(bundle.getString("AddressbookFrame.text")); // NOI18N
116 mainMenu.setFocusable(false);
117 mainMenu.setName(""); // NOI18N
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);
127 mainMenu.add(exitProgram);
129 menuBar.add(mainMenu);
131 addressbookMenu.setText(bundle.getString("AddressbookFrame.addressbookMenu.text")); // NOI18N
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);
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
146 menuBar.add(addressbookMenu);
148 setJMenuBar(menuBar);
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)
156 layout.setVerticalGroup(
157 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
158 .addGap(0, 279, Short.MAX_VALUE)
162 }// </editor-fold>//GEN-END:initComponents
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
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
177 * @param client Client instance
180 public void setupFrame (final Client client) {
181 // Has the user entered own data?
182 if (!this.getClient().getContactManager().isOwnContactAdded()) {
184 this.getLogger().debug("Enabling menus: isOwnContactAdded()=false");
186 // Not entered yet, so enable menu
187 addOwnData.setEnabled(true);
191 * Set the Nimbus look and feel
193 //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
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
200 for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
201 if ("Nimbus".equals(info.getName())) {
202 javax.swing.UIManager.setLookAndFeel(info.getClassName());
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);
218 this.getLogger().debug("Displaying form ...");
221 * Create and display the form
223 java.awt.EventQueue.invokeLater(new Runnable() {
226 new AddressbookFrame(client).setVisible(true);
236 protected final Logger getLogger () {
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