]> git.mxchange.org Git - addressbook-swing.git/blob - Addressbook/src/org/mxchange/addressbook/client/gui/AddressbookFrame.java
Added a lot stuff:
[addressbook-swing.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         statusPane = new javax.swing.JScrollPane();
88         statusText = new javax.swing.JTextPane();
89         mainMenu = new javax.swing.JMenuBar();
90         jMenu1 = new javax.swing.JMenu();
91         jMenuItem1 = new javax.swing.JMenuItem();
92         jMenu2 = new javax.swing.JMenu();
93
94         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
95         setTitle(AddressbookApplication.printableTitle());
96         setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
97         setName("main"); // NOI18N
98
99         statusText.setBackground(new java.awt.Color(240, 240, 240));
100         java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/mxchange/addressbook/client/gui/Bundle"); // NOI18N
101         statusText.setText(bundle.getString("AddressbookFrame.status.text")); // NOI18N
102         statusText.setName("status"); // NOI18N
103         statusPane.setViewportView(statusText);
104         statusText.getAccessibleContext().setAccessibleName(bundle.getString("AddressbookFrame.status.AccessibleContext.accessibleName")); // NOI18N
105
106         jMenu1.setText(bundle.getString("AddressbookFrame.text")); // NOI18N
107         jMenu1.setFocusable(false);
108         jMenu1.setName(""); // NOI18N
109
110         jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.ALT_MASK));
111         jMenuItem1.setText(bundle.getString("AddressbookFrame.jMenuItem1.text")); // NOI18N
112         jMenuItem1.setToolTipText(bundle.getString("AddressbookFrame.jMenuItem1.toolTipText")); // NOI18N
113         jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
114             public void actionPerformed(java.awt.event.ActionEvent evt) {
115                 jMenuItem1ActionPerformed(evt);
116             }
117         });
118         jMenu1.add(jMenuItem1);
119
120         mainMenu.add(jMenu1);
121
122         jMenu2.setText(bundle.getString("AddressbookFrame.jMenu2.text")); // NOI18N
123         mainMenu.add(jMenu2);
124
125         setJMenuBar(mainMenu);
126
127         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
128         getContentPane().setLayout(layout);
129         layout.setHorizontalGroup(
130             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
131             .addComponent(statusPane, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
132         );
133         layout.setVerticalGroup(
134             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
135             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
136                 .addGap(0, 257, Short.MAX_VALUE)
137                 .addComponent(statusPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
138         );
139
140         pack();
141     }// </editor-fold>//GEN-END:initComponents
142
143     private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
144         // Close application instance
145         this.getClient().getApplication().doShutdown();
146     }//GEN-LAST:event_jMenuItem1ActionPerformed
147
148     /**
149      * Initializes the frame
150      */
151     @Override
152     public void initFrame (final Client client) {
153         /*
154          * Set the Nimbus look and feel
155          */
156         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
157         /*
158          * If Nimbus (introduced in Java SE 6) is not available, stay with the
159          * default look and feel. For details see
160          * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
161          */
162         try {
163             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
164                 if ("Nimbus".equals(info.getName())) {
165                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
166                     break;
167                 }
168             }
169         } catch (final ClassNotFoundException ex) {
170             this.getLogger().catching(ex);
171         } catch (final InstantiationException ex) {
172             this.getLogger().catching(ex);
173         } catch (final IllegalAccessException ex) {
174             this.getLogger().catching(ex);
175         } catch (final javax.swing.UnsupportedLookAndFeelException ex) {
176             this.getLogger().catching(ex);
177         }
178         //</editor-fold>
179
180         // Debug line
181         this.getLogger().debug("Displaying form ...");
182
183         /*
184          * Create and display the form
185          */
186         java.awt.EventQueue.invokeLater(new Runnable() {
187             @Override
188             public void run () {
189                 new AddressbookFrame(client).setVisible(true);
190             }
191         });
192     }
193
194     /**
195      * Getter for logger
196      *
197      * @return Logger
198      */
199     protected final Logger getLogger () {
200         return this.LOG;
201     }
202
203     // Variables declaration - do not modify//GEN-BEGIN:variables
204     private javax.swing.JMenu jMenu1;
205     private javax.swing.JMenu jMenu2;
206     private javax.swing.JMenuItem jMenuItem1;
207     private javax.swing.JMenuBar mainMenu;
208     private javax.swing.JScrollPane statusPane;
209     private javax.swing.JTextPane statusText;
210     // End of variables declaration//GEN-END:variables
211 }