*/\r
private boolean guiClient = false;\r
\r
+ /**\r
+ * Getter for printable application name\r
+ * \r
+ * @return A printable name\r
+ */\r
+ public static String printableTitle () {\r
+ return MessageFormat.format("{0} v{1}", APP_TITLE, APP_VERSION);\r
+ }\r
+\r
/**\r
* Bootstraps application\r
*/\r
// Launch application\r
ApplicationManager.getManager(this).start();\r
\r
- this.getLogger().info("End of program (last line)");\r
+ // Good bye, but this should not be reached ...\r
+ this.getLogger().warn("Unusual exit reached.");\r
+ this.doShutdown();\r
}\r
\r
/**\r
// Start application\r
new AddressbookApplication().start(args);\r
}\r
+\r
+ /**\r
+ * Shuts down the application.\r
+ */\r
+ @Override\r
+ public void doShutdown () {\r
+ // Shutdown client\r
+ this.getClient().doShutdown();\r
+\r
+ this.getLogger().info("End of program (last line)");\r
+ System.exit(0);\r
+ }\r
}\r
* Run the main loop\r
*/\r
public void doMainLoop();\r
+\r
+ /**\r
+ * Shutdown the application\r
+ */\r
+ public void doShutdown ();\r
}\r
}\r
\r
/**\r
- * Disables running state, so the main loop can abort.\r
+ * Shutdown method for all clients\r
*/\r
- public void disableIsRunning () {\r
- this.isRunning = false;\r
+ public void doShutdown () {\r
+ // Disable client\r
+ this.disableIsRunning();\r
+\r
+ // Shuts down contact manager\r
+ this.getContactManager().doShutdown();\r
}\r
\r
/**\r
return this.isRunning;\r
}\r
\r
+ /**\r
+ * Disables running state, so the main loop can abort.\r
+ */\r
+ protected void disableIsRunning () {\r
+ this.isRunning = false;\r
+ }\r
+\r
/**\r
* Fills menu map with swing menus\r
*/\r
return this.menus;\r
}\r
\r
+ /**\r
+ * Initializes contact manager\r
+ */\r
+ protected void initContactManager () {\r
+ // Debug message\r
+ this.getLogger().debug("Initializing contact manager ...");\r
+ \r
+ // Init contact manager with console client\r
+ // @TODO Static initial amount of contacts\r
+ ManageableContact manager = new ContactManager (100, (Client) this);\r
+ \r
+ // Set it here\r
+ this.setContactManager(manager);\r
+ \r
+ // Debug message\r
+ this.getLogger().debug("Contact manager has been initialized.");\r
+ }\r
+\r
/**\r
* Shows given menu\r
*\r
// Show menu\r
menu.show((Client) this);\r
}\r
-\r
- /**\r
- * Initializes contact manager\r
- */\r
- protected void initContactManager () {\r
- // Debug message\r
- this.getLogger().debug("Initializing contact manager ...");\r
- \r
- // Init contact manager with console client\r
- // @TODO Static initial amount of contacts\r
- ManageableContact manager = new ContactManager (100, (Client) this);\r
- \r
- // Set it here\r
- this.setContactManager(manager);\r
- \r
- // Debug message\r
- this.getLogger().debug("Contact manager has been initialized.");\r
- }\r
}\r
*/\r
public void displayAddressBox (final Contact contact);\r
\r
+ /**\r
+ * Shuts down the client and therefore whole application\r
+ */\r
+ public void doShutdown ();\r
+\r
/**\r
* Displays a message to the user\r
*\r
@Override\r
public void displayOtherDataBox (final Contact contact) {\r
// Cellphone and such ...\r
- this.outputMessage("Telefonnumer: " + contact.getPhoneNumber() + "\nFaxnummer: " + contact.getFaxNumber() + "\nHandy: " + contact.getCellphoneNumber() + "\nKommentar:\n" + contact.getComment());\r
+ this.outputMessage(MessageFormat.format("Telefonnumer: {0}\nFaxnummer: {1}\nHandy: {2}\nKommentar:\n{3}", contact.getPhoneNumber(), contact.getFaxNumber(), contact.getCellphoneNumber(), contact.getComment()));\r
+ }\r
+\r
+ /**\r
+ * Shutdown this client\r
+ */\r
+ @Override\r
+ public void doShutdown () {\r
+ // Parent call\r
+ super.doShutdown();\r
+\r
+ // @TODO Add other shutdown stuff\r
}\r
\r
@Override\r
break;\r
\r
case '0': // Program exit\r
- this.disableIsRunning();\r
+ this.getApplication().doShutdown();\r
break;\r
\r
default:\r
// @TODO throw own exception\r
- throw new UnhandledUserChoiceException("Choice '" + choice + "' not handled yet.");\r
+ throw new UnhandledUserChoiceException(MessageFormat.format("Choice '{0}' not handled yet.", choice));\r
}\r
}\r
\r
*/\r
@Override\r
public void showWelcome () {\r
- this.outputMessage("Welcome to " + AddressbookApplication.APP_TITLE + " v" + AddressbookApplication.APP_VERSION);\r
+ this.outputMessage("Welcome to " + AddressbookApplication.printableTitle());\r
this.outputMessage("");\r
this.outputMessage("Copyright(c) 2015 by Roland Haeder, this is free software");\r
\r
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.5" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
+ <NonVisualComponents>
+ <Menu class="javax.swing.JMenuBar" name="mainMenu">
+ <SubComponents>
+ <Menu class="javax.swing.JMenu" name="jMenu1">
+ <Properties>
+ <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
+ <ResourceString bundle="org/mxchange/addressbook/client/gui/Bundle.properties" key="AddressbookFrame.text" replaceFormat="java.util.ResourceBundle.getBundle("{bundleNameSlashes}").getString("{key}")"/>
+ </Property>
+ <Property name="focusable" type="boolean" value="false"/>
+ <Property name="name" type="java.lang.String" value="" noResource="true"/>
+ </Properties>
+ <SubComponents>
+ <MenuItem class="javax.swing.JMenuItem" name="jMenuItem1">
+ <Properties>
+ <Property name="accelerator" type="javax.swing.KeyStroke" editor="org.netbeans.modules.form.editors.KeyStrokeEditor">
+ <KeyStroke key="Alt+X"/>
+ </Property>
+ <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
+ <ResourceString bundle="org/mxchange/addressbook/client/gui/Bundle.properties" key="AddressbookFrame.jMenuItem1.text" replaceFormat="java.util.ResourceBundle.getBundle("{bundleNameSlashes}").getString("{key}")"/>
+ </Property>
+ <Property name="toolTipText" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
+ <ResourceString bundle="org/mxchange/addressbook/client/gui/Bundle.properties" key="AddressbookFrame.jMenuItem1.toolTipText" replaceFormat="java.util.ResourceBundle.getBundle("{bundleNameSlashes}").getString("{key}")"/>
+ </Property>
+ </Properties>
+ <Events>
+ <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jMenuItem1ActionPerformed"/>
+ </Events>
+ </MenuItem>
+ </SubComponents>
+ </Menu>
+ <Menu class="javax.swing.JMenu" name="jMenu2">
+ <Properties>
+ <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
+ <ResourceString bundle="org/mxchange/addressbook/client/gui/Bundle.properties" key="AddressbookFrame.jMenu2.text" replaceFormat="java.util.ResourceBundle.getBundle("{bundleNameSlashes}").getString("{key}")"/>
+ </Property>
+ </Properties>
+ </Menu>
+ </SubComponents>
+ </Menu>
+ </NonVisualComponents>
<Properties>
<Property name="defaultCloseOperation" type="int" value="3"/>
+ <Property name="title" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
+ <Connection code="AddressbookApplication.printableTitle()" type="code"/>
+ </Property>
+ <Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor">
+ <Color id="Standardcursor"/>
+ </Property>
+ <Property name="name" type="java.lang.String" value="main" noResource="true"/>
</Properties>
<SyntheticProperties>
+ <SyntheticProperty name="menuBar" type="java.lang.String" value="mainMenu"/>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
</SyntheticProperties>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
- <EmptySpace min="0" pref="400" max="32767" attributes="0"/>
+ <Component id="statusPane" alignment="0" pref="400" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
- <EmptySpace min="0" pref="300" max="32767" attributes="0"/>
+ <Group type="102" alignment="1" attributes="0">
+ <EmptySpace min="0" pref="257" max="32767" attributes="0"/>
+ <Component id="statusPane" min="-2" max="-2" attributes="0"/>
+ </Group>
</Group>
</DimensionLayout>
</Layout>
+ <SubComponents>
+ <Container class="javax.swing.JScrollPane" name="statusPane">
+ <AuxValues>
+ <AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
+ </AuxValues>
+
+ <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
+ <SubComponents>
+ <Component class="javax.swing.JTextPane" name="statusText">
+ <Properties>
+ <Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
+ <Color blue="f0" green="f0" red="f0" type="rgb"/>
+ </Property>
+ <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
+ <ResourceString bundle="org/mxchange/addressbook/client/gui/Bundle.properties" key="AddressbookFrame.status.text" replaceFormat="java.util.ResourceBundle.getBundle("{bundleNameSlashes}").getString("{key}")"/>
+ </Property>
+ <Property name="name" type="java.lang.String" value="status" noResource="true"/>
+ </Properties>
+ <AccessibilityProperties>
+ <Property name="AccessibleContext.accessibleName" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
+ <ResourceString bundle="org/mxchange/addressbook/client/gui/Bundle.properties" key="AddressbookFrame.status.AccessibleContext.accessibleName" replaceFormat="java.util.ResourceBundle.getBundle("{bundleNameSlashes}").getString("{key}")"/>
+ </Property>
+ </AccessibilityProperties>
+ </Component>
+ </SubComponents>
+ </Container>
+ </SubComponents>
</Form>
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+import org.mxchange.addressbook.application.AddressbookApplication;
import org.mxchange.addressbook.application.Application;
import org.mxchange.addressbook.client.Client;
import org.mxchange.addressbook.manager.contact.ManageableContact;
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
+ statusPane = new javax.swing.JScrollPane();
+ statusText = new javax.swing.JTextPane();
+ mainMenu = new javax.swing.JMenuBar();
+ jMenu1 = new javax.swing.JMenu();
+ jMenuItem1 = new javax.swing.JMenuItem();
+ jMenu2 = new javax.swing.JMenu();
+
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
+ setTitle(AddressbookApplication.printableTitle());
+ setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
+ setName("main"); // NOI18N
+
+ statusText.setBackground(new java.awt.Color(240, 240, 240));
+ java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/mxchange/addressbook/client/gui/Bundle"); // NOI18N
+ statusText.setText(bundle.getString("AddressbookFrame.status.text")); // NOI18N
+ statusText.setName("status"); // NOI18N
+ statusPane.setViewportView(statusText);
+ statusText.getAccessibleContext().setAccessibleName(bundle.getString("AddressbookFrame.status.AccessibleContext.accessibleName")); // NOI18N
+
+ jMenu1.setText(bundle.getString("AddressbookFrame.text")); // NOI18N
+ jMenu1.setFocusable(false);
+ jMenu1.setName(""); // NOI18N
+
+ jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.ALT_MASK));
+ jMenuItem1.setText(bundle.getString("AddressbookFrame.jMenuItem1.text")); // NOI18N
+ jMenuItem1.setToolTipText(bundle.getString("AddressbookFrame.jMenuItem1.toolTipText")); // NOI18N
+ jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ jMenuItem1ActionPerformed(evt);
+ }
+ });
+ jMenu1.add(jMenuItem1);
+
+ mainMenu.add(jMenu1);
+
+ jMenu2.setText(bundle.getString("AddressbookFrame.jMenu2.text")); // NOI18N
+ mainMenu.add(jMenu2);
+
+ setJMenuBar(mainMenu);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGap(0, 400, Short.MAX_VALUE)
+ .addComponent(statusPane, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGap(0, 300, Short.MAX_VALUE)
+ .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
+ .addGap(0, 257, Short.MAX_VALUE)
+ .addComponent(statusPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
+ private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
+ // Close application instance
+ this.getClient().getApplication().doShutdown();
+ }//GEN-LAST:event_jMenuItem1ActionPerformed
+
/**
* Initializes the frame
*/
}
// Variables declaration - do not modify//GEN-BEGIN:variables
+ private javax.swing.JMenu jMenu1;
+ private javax.swing.JMenu jMenu2;
+ private javax.swing.JMenuItem jMenuItem1;
+ private javax.swing.JMenuBar mainMenu;
+ private javax.swing.JScrollPane statusPane;
+ private javax.swing.JTextPane statusText;
// End of variables declaration//GEN-END:variables
}
--- /dev/null
+AddressbookFrame.jMenu2.text=Edit
+AddressbookFrame.text=File
+AddressbookFrame.jMenuItem1.text=Exit program
+AddressbookFrame.jMenuItem1.toolTipText=Exits the program cleanly.
+AddressbookFrame.status.AccessibleContext.accessibleName=
+AddressbookFrame.status.text=Welcome ...
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.\r
}\r
\r
+ @Override\r
+ public void doShutdown () {\r
+ // Parent call\r
+ super.doShutdown();\r
+\r
+ // @TODO Add other shutdown stuff\r
+ }\r
+\r
@Override\r
public void doUserMenuChoice () throws UnhandledUserChoiceException {\r
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.\r
+ // Not implemented here\r
}\r
\r
@Override\r
\r
@Override\r
public void showCurrentMenu () {\r
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.\r
+ // Not implemented here\r
}\r
\r
@Override\r
\r
@Override\r
public void showWelcome () {\r
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.\r
+ // Not implemented here\r
}\r
\r
@Override\r
*/\r
public interface DatabaseBackend extends FrameworkInterface {\r
\r
+ /**\r
+ * Shuts down this backend\r
+ */\r
+ public void doShutdown ();\r
+\r
/**\r
* Rewinds backend\r
*/\r
return list.iterator();\r
}\r
\r
+ /**\r
+ * Shuts down this backend\r
+ */\r
+ @Override\r
+ public void doShutdown () {\r
+ try {\r
+ // Close file\r
+ this.storageFile.close();\r
+ } catch (final IOException ex) {\r
+ this.getLogger().catching(ex);\r
+ System.exit(1);\r
+ }\r
+ }\r
+\r
/**\r
* Get length of underlaying file\r
*\r
this.initBackend();\r
}\r
\r
+ /**\r
+ * Shuts down the database layer\r
+ */\r
+ @Override\r
+ public void doShutdown () {\r
+ // Shutdown backend\r
+ this.getBackend().doShutdown();\r
+ }\r
+\r
/**\r
* Flushes all contact entries to database\r
* @param contactManager An instance of a MangeableContact class\r
*/\r
public interface ContactWrapper extends DatabaseWrapper {\r
\r
+ /**\r
+ * Shuts down the database layer\r
+ */\r
+ public void doShutdown ();\r
+\r
/**\r
* Flushes all contact entries to database\r
* \r
this.registerContact(contact);\r
}\r
\r
+ /**\r
+ * Shuts down this contact manager\r
+ */\r
+ @Override\r
+ public void doShutdown () {\r
+ // Shut down the database layer\r
+ this.contactDatabase.doShutdown();\r
+ }\r
+\r
/**\r
* Getter for whole contact list\r
* \r
*/\r
public interface ManageableContact extends Manageable {\r
\r
+ /**\r
+ * Shuts down this contact manager\r
+ */\r
+ public void doShutdown ();\r
+\r
/**\r
* List all contacts\r
*/\r