From ac52e6515a6d8e23aea65a40b1ac0d1d481d6dfe Mon Sep 17 00:00:00 2001 From: Roland Haeder <roland@mxchange.org> Date: Thu, 23 Jul 2015 12:57:21 +0200 Subject: [PATCH] The NetBeans-created GUI was buggy, maybe because of the .form file. So I better write my own one. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder <roland@mxchange.org> --- .../addressbook/BaseFrameworkSystem.java | 18 +- .../FrameAlreadyInitializedException.java | 31 ++ .../addressbook/FrameworkInterface.java | 4 +- .../client/gui/AddressbookFrame.form | 197 ------- .../client/gui/AddressbookFrame.java | 486 +++++------------- .../addressbook/client/gui/ClientFrame.java | 5 +- .../addressbook/client/gui/SwingClient.java | 10 +- .../addressbook/contact/BaseContact.java | 5 - .../localization/bundle_de_DE.properties | 4 - .../manager/contact/ContactManager.java | 47 +- 10 files changed, 228 insertions(+), 579 deletions(-) create mode 100644 Addressbook/src/org/mxchange/addressbook/FrameAlreadyInitializedException.java delete mode 100644 Addressbook/src/org/mxchange/addressbook/client/gui/AddressbookFrame.form diff --git a/Addressbook/src/org/mxchange/addressbook/BaseFrameworkSystem.java b/Addressbook/src/org/mxchange/addressbook/BaseFrameworkSystem.java index e34fe666..680474db 100644 --- a/Addressbook/src/org/mxchange/addressbook/BaseFrameworkSystem.java +++ b/Addressbook/src/org/mxchange/addressbook/BaseFrameworkSystem.java @@ -39,6 +39,11 @@ public class BaseFrameworkSystem implements FrameworkInterface { */ private Application application; + /** + * Bundle instance + */ + private final ResourceBundle bundle; + /** * Client instance */ @@ -54,10 +59,6 @@ public class BaseFrameworkSystem implements FrameworkInterface { */ private String tableName; - /** - * Bundle instance - */ - private final ResourceBundle bundle; /** * Initialize object @@ -153,4 +154,13 @@ public class BaseFrameworkSystem implements FrameworkInterface { protected final void setTableName (final String tableName) { this.tableName = tableName; } + + /** + * Getter for bundle instance + * + * @return Resource bundle + */ + protected ResourceBundle getBundle () { + return this.bundle; + } } diff --git a/Addressbook/src/org/mxchange/addressbook/FrameAlreadyInitializedException.java b/Addressbook/src/org/mxchange/addressbook/FrameAlreadyInitializedException.java new file mode 100644 index 00000000..1709f0b1 --- /dev/null +++ b/Addressbook/src/org/mxchange/addressbook/FrameAlreadyInitializedException.java @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2015 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +package org.mxchange.addressbook; + +/** + * + * @author Roland Haeder + */ +public class FrameAlreadyInitializedException extends Exception { + + /** + * Default constructor + */ + public FrameAlreadyInitializedException () { + } + +} diff --git a/Addressbook/src/org/mxchange/addressbook/FrameworkInterface.java b/Addressbook/src/org/mxchange/addressbook/FrameworkInterface.java index ae1c570b..2158bdbb 100644 --- a/Addressbook/src/org/mxchange/addressbook/FrameworkInterface.java +++ b/Addressbook/src/org/mxchange/addressbook/FrameworkInterface.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015 KLC + * Copyright (C) 2015 Roland Haeder * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,7 +22,7 @@ import org.mxchange.addressbook.manager.contact.ManageableContact; /** * - * @author KLC + * @author Roland Haeder */ public interface FrameworkInterface { diff --git a/Addressbook/src/org/mxchange/addressbook/client/gui/AddressbookFrame.form b/Addressbook/src/org/mxchange/addressbook/client/gui/AddressbookFrame.form deleted file mode 100644 index d6899f38..00000000 --- a/Addressbook/src/org/mxchange/addressbook/client/gui/AddressbookFrame.form +++ /dev/null @@ -1,197 +0,0 @@ -<?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="menuBar"> - <Properties> - <Property name="name" type="java.lang.String" value="menuBar" noResource="true"/> - </Properties> - <SubComponents> - <Menu class="javax.swing.JMenu" name="mainMenu"> - <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="exitProgram"> - <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/localization/bundle.properties" key="AddressbookFrame.exitProgram.text_1" replaceFormat="java.util.ResourceBundle.getBundle("{bundleNameSlashes}").getString("{key}")"/> - </Property> - <Property name="name" type="java.lang.String" value="exitProgram" noResource="true"/> - </Properties> - <Events> - <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="exitProgramActionPerformed"/> - </Events> - </MenuItem> - </SubComponents> - </Menu> - <Menu class="javax.swing.JMenu" name="addressbookMenu"> - <Properties> - <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor"> - <ResourceString bundle="org/mxchange/addressbook/localization/bundle.properties" key="AddressbookFrame.addressbookMenu.text_1" replaceFormat="java.util.ResourceBundle.getBundle("{bundleNameSlashes}").getString("{key}")"/> - </Property> - <Property name="name" type="java.lang.String" value="addressbookMenu" noResource="true"/> - </Properties> - <SubComponents> - <MenuItem class="javax.swing.JMenuItem" name="addOwnData"> - <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.addOwn.text" replaceFormat="java.util.ResourceBundle.getBundle("{bundleNameSlashes}").getString("{key}")"/> - </Property> - <Property name="name" type="java.lang.String" value="addOwn" noResource="true"/> - </Properties> - <AccessibilityProperties> - <Property name="AccessibleContext.accessibleName" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor"> - <ResourceString bundle="org/mxchange/addressbook/localization/bundle.properties" key="AddressbookFrame.addOwnData.AccessibleContext.accessibleName_1" replaceFormat="java.util.ResourceBundle.getBundle("{bundleNameSlashes}").getString("{key}")"/> - </Property> - </AccessibilityProperties> - <Events> - <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="addOwnDataActionPerformed"/> - </Events> - </MenuItem> - </SubComponents> - </Menu> - </SubComponents> - </Menu> - </NonVisualComponents> - <Properties> - <Property name="defaultCloseOperation" type="int" value="0"/> - <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="menuBar"/> - <SyntheticProperty name="formSizePolicy" type="int" value="1"/> - <SyntheticProperty name="generateCenter" type="boolean" value="false"/> - </SyntheticProperties> - <Events> - <EventHandler event="windowClosed" listener="java.awt.event.WindowListener" parameters="java.awt.event.WindowEvent" handler="exitProgram"/> - <EventHandler event="windowClosing" listener="java.awt.event.WindowListener" parameters="java.awt.event.WindowEvent" handler="windowClosing"/> - </Events> - <AuxValues> - <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="1"/> - <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="true"/> - <AuxValue name="FormSettings_formBundle" type="java.lang.String" value="org/mxchange/addressbook/localization/bundle"/> - <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="false"/> - <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/> - <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="true"/> - <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/> - <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/> - <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/> - <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/> - </AuxValues> - - <Layout> - <DimensionLayout dim="0"> - <Group type="103" groupAlignment="0" attributes="0"> - <Component id="statusPanel" max="32767" attributes="0"/> - <Component id="listAddressesPanel" alignment="0" pref="700" max="32767" attributes="0"/> - <Component id="toolBar" alignment="0" max="32767" attributes="0"/> - </Group> - </DimensionLayout> - <DimensionLayout dim="1"> - <Group type="103" groupAlignment="0" attributes="0"> - <Group type="102" alignment="1" attributes="0"> - <Component id="toolBar" min="-2" pref="25" max="-2" attributes="0"/> - <EmptySpace max="-2" attributes="0"/> - <Component id="listAddressesPanel" min="-2" max="-2" attributes="0"/> - <EmptySpace min="-2" pref="1" max="-2" attributes="0"/> - <Component id="statusPanel" min="-2" pref="23" max="-2" attributes="0"/> - </Group> - </Group> - </DimensionLayout> - </Layout> - <SubComponents> - <Container class="javax.swing.JPanel" name="statusPanel"> - <Properties> - <Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor"> - <Border info="org.netbeans.modules.form.compat2.border.EtchedBorderInfo"> - <EtchetBorder> - <Color PropertyName="highlight" blue="c0" green="c0" id="lightGray" palette="1" red="c0" type="palette"/> - <Color PropertyName="shadow" blue="99" green="99" red="99" type="rgb"/> - </EtchetBorder> - </Border> - </Property> - <Property name="autoscrolls" type="boolean" value="true"/> - <Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor"> - <Color id="Standardcursor"/> - </Property> - <Property name="focusable" type="boolean" value="false"/> - <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> - <Property name="AccessibleContext.accessibleDescription" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor"> - <ResourceString bundle="org/mxchange/addressbook/client/gui/Bundle.properties" key="AddressbookFrame.status.AccessibleContext.accessibleDescription" replaceFormat="java.util.ResourceBundle.getBundle("{bundleNameSlashes}").getString("{key}")"/> - </Property> - </AccessibilityProperties> - - <Layout class="org.netbeans.modules.form.compat2.layouts.DesignBoxLayout"> - <Property name="axis" type="int" value="0"/> - </Layout> - <SubComponents> - <Component class="javax.swing.JLabel" name="statusLabel"> - <Properties> - <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor"> - <ResourceString bundle="org/mxchange/addressbook/localization/bundle.properties" key="AddressbookFrame.statusLabel.text_1" replaceFormat="java.util.ResourceBundle.getBundle("{bundleNameSlashes}").getString("{key}")"/> - </Property> - <Property name="horizontalTextPosition" type="int" value="2"/> - <Property name="name" type="java.lang.String" value="statusLabel" noResource="true"/> - </Properties> - </Component> - </SubComponents> - </Container> - <Container class="javax.swing.JScrollPane" name="listAddressesPanel"> - <Properties> - <Property name="name" type="java.lang.String" value="listAddressesPanel" noResource="true"/> - </Properties> - <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.JTable" name="addressesTable"> - <Properties> - <Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.RADConnectionPropertyEditor"> - <Connection code="new AddressTableModel(this.getClient())" type="code"/> - </Property> - <Property name="columnModel" type="javax.swing.table.TableColumnModel" editor="org.netbeans.modules.form.editors2.TableColumnModelEditor"> - <TableColumnModel selectionModel="2"/> - </Property> - <Property name="columnSelectionAllowed" type="boolean" value="true"/> - <Property name="fillsViewportHeight" type="boolean" value="true"/> - <Property name="focusable" type="boolean" value="false"/> - <Property name="name" type="java.lang.String" value="addressesTable" noResource="true"/> - <Property name="tableHeader" type="javax.swing.table.JTableHeader" editor="org.netbeans.modules.form.editors2.JTableHeaderEditor"> - <TableHeader reorderingAllowed="true" resizingAllowed="true"/> - </Property> - </Properties> - </Component> - </SubComponents> - </Container> - <Container class="javax.swing.JToolBar" name="toolBar"> - <Properties> - <Property name="floatable" type="boolean" value="false"/> - <Property name="rollover" type="boolean" value="true"/> - <Property name="name" type="java.lang.String" value="toolBar" noResource="true"/> - </Properties> - - <Layout class="org.netbeans.modules.form.compat2.layouts.DesignBoxLayout"/> - </Container> - </SubComponents> -</Form> diff --git a/Addressbook/src/org/mxchange/addressbook/client/gui/AddressbookFrame.java b/Addressbook/src/org/mxchange/addressbook/client/gui/AddressbookFrame.java index 451d5250..29151b1a 100644 --- a/Addressbook/src/org/mxchange/addressbook/client/gui/AddressbookFrame.java +++ b/Addressbook/src/org/mxchange/addressbook/client/gui/AddressbookFrame.java @@ -1,355 +1,131 @@ -/* - * Copyright (C) 2015 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ -package org.mxchange.addressbook.client.gui; - -import java.awt.Color; -import java.awt.Cursor; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.InputEvent; -import java.awt.event.KeyEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.util.ResourceBundle; -import javax.swing.BorderFactory; -import javax.swing.BoxLayout; -import javax.swing.GroupLayout; -import javax.swing.JLabel; -import javax.swing.JMenu; -import javax.swing.JMenuBar; -import javax.swing.JMenuItem; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JTable; -import javax.swing.JToolBar; -import javax.swing.KeyStroke; -import javax.swing.LayoutStyle; -import javax.swing.ListSelectionModel; -import javax.swing.SwingConstants; -import javax.swing.UIManager; -import javax.swing.WindowConstants; -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; -import org.mxchange.addressbook.model.address.AddressTableModel; - -/** - * - * @author Roland Haeder - */ -public class AddressbookFrame extends javax.swing.JFrame implements ClientFrame { - /** - * Class' logger - */ - private final Logger LOG; - - /** - * Client instance - */ - private final Client client; - - /** - * Own instance - */ - private static ClientFrame self; - - /** - * Bundle instance - */ - private final ResourceBundle bundle; - - /** - * Initialize object - */ - { - LOG = LogManager.getLogger(this); - bundle = ResourceBundle.getBundle("org/mxchange/addressbook/localization/bundle"); // NOI18N - } - - /** - * Creates an instance of this frame with a client instance - * @param client - */ - private AddressbookFrame (final Client client) { - // Debug line - this.getLogger().debug("Initializing Swing frame ..."); - - // Set client here - this.client = client; - } - - @Override - public Application getApplication () { - throw new UnsupportedOperationException("Not implemented."); - } - - @Override - public final Client getClient () { - return this.client; - } - - @Override - public ManageableContact getContactManager () { - throw new UnsupportedOperationException("Not implemented."); - } - - @Override - public void initFrame () { - // Init components - this.initComponents(); - } - - /** - * This method is called from within the constructor to initialize the form. - * WARNING: Do NOT modify this code. The content of this method is always - * regenerated by the Form Editor. - */ - @SuppressWarnings ("unchecked") - // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents - private void initComponents() { - - statusPanel = new JPanel(); - statusLabel = new JLabel(); - listAddressesPanel = new JScrollPane(); - addressesTable = new JTable(); - toolBar = new JToolBar(); - menuBar = new JMenuBar(); - mainMenu = new JMenu(); - exitProgram = new JMenuItem(); - addressbookMenu = new JMenu(); - addOwnData = new JMenuItem(); - - setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); - setTitle(AddressbookApplication.printableTitle()); - setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); - setName("main"); // NOI18N - addWindowListener(new WindowAdapter() { - public void windowClosed(WindowEvent evt) { - exitProgram(evt); - } - public void windowClosing(WindowEvent evt) { - AddressbookFrame.this.windowClosing(evt); - } - }); - - statusPanel.setBorder(BorderFactory.createEtchedBorder(Color.lightGray, new Color(153, 153, 153))); - statusPanel.setAutoscrolls(true); - statusPanel.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); - statusPanel.setFocusable(false); - statusPanel.setName("status"); // NOI18N - statusPanel.setLayout(new BoxLayout(statusPanel, BoxLayout.X_AXIS)); - - ResourceBundle bundle = ResourceBundle.getBundle("org/mxchange/addressbook/localization/bundle"); // NOI18N - statusLabel.setText(bundle.getString("AddressbookFrame.statusLabel.text_1")); // NOI18N - statusLabel.setHorizontalTextPosition(SwingConstants.LEFT); - statusLabel.setName("statusLabel"); // NOI18N - statusPanel.add(statusLabel); - - listAddressesPanel.setName("listAddressesPanel"); // NOI18N - - addressesTable.setModel(new AddressTableModel(this.getClient())); - addressesTable.setColumnSelectionAllowed(true); - addressesTable.setFillsViewportHeight(true); - addressesTable.setFocusable(false); - addressesTable.setName("addressesTable"); // NOI18N - listAddressesPanel.setViewportView(addressesTable); - addressesTable.getColumnModel().getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); - - toolBar.setFloatable(false); - toolBar.setRollover(true); - toolBar.setName("toolBar"); // NOI18N - - menuBar.setName("menuBar"); // NOI18N - - ResourceBundle bundle1 = ResourceBundle.getBundle("org/mxchange/addressbook/client/gui/Bundle"); // NOI18N - mainMenu.setText(bundle1.getString("AddressbookFrame.text")); // NOI18N - mainMenu.setFocusable(false); - mainMenu.setName(""); // NOI18N - - exitProgram.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.ALT_MASK)); - exitProgram.setText(bundle.getString("AddressbookFrame.exitProgram.text_1")); // NOI18N - exitProgram.setName("exitProgram"); // NOI18N - exitProgram.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent evt) { - exitProgramActionPerformed(evt); - } - }); - mainMenu.add(exitProgram); - - menuBar.add(mainMenu); - - addressbookMenu.setText(bundle.getString("AddressbookFrame.addressbookMenu.text_1")); // NOI18N - addressbookMenu.setName("addressbookMenu"); // NOI18N - - addOwnData.setText(bundle1.getString("AddressbookFrame.addOwn.text")); // NOI18N - addOwnData.setName("addOwn"); // NOI18N - addOwnData.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent evt) { - addOwnDataActionPerformed(evt); - } - }); - addressbookMenu.add(addOwnData); - addOwnData.getAccessibleContext().setAccessibleName(bundle.getString("AddressbookFrame.addOwnData.AccessibleContext.accessibleName_1")); // NOI18N - - menuBar.add(addressbookMenu); - - setJMenuBar(menuBar); - - GroupLayout layout = new GroupLayout(getContentPane()); - getContentPane().setLayout(layout); - layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(statusPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(listAddressesPanel, GroupLayout.DEFAULT_SIZE, 700, Short.MAX_VALUE) - .addComponent(toolBar, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - ); - layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addGroup(GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addComponent(toolBar, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(listAddressesPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addGap(1, 1, 1) - .addComponent(statusPanel, GroupLayout.PREFERRED_SIZE, 23, GroupLayout.PREFERRED_SIZE)) - ); - - statusPanel.getAccessibleContext().setAccessibleName(bundle1.getString("AddressbookFrame.status.AccessibleContext.accessibleName")); // NOI18N - statusPanel.getAccessibleContext().setAccessibleDescription(bundle1.getString("AddressbookFrame.status.AccessibleContext.accessibleDescription")); // NOI18N - - pack(); - }// </editor-fold>//GEN-END:initComponents - - private void exitProgramActionPerformed(ActionEvent evt) {//GEN-FIRST:event_exitProgramActionPerformed - // Close application instance - dispose(); - }//GEN-LAST:event_exitProgramActionPerformed - - private void addOwnDataActionPerformed(ActionEvent evt) {//GEN-FIRST:event_addOwnDataActionPerformed - // Asks the user to enter own data - this.getClient().getContactManager().doEnterOwnData(); - }//GEN-LAST:event_addOwnDataActionPerformed - - private void windowClosing(WindowEvent evt) {//GEN-FIRST:event_windowClosing - // TODO add your handling code here: - dispose(); - }//GEN-LAST:event_windowClosing - - private void exitProgram(WindowEvent evt) {//GEN-FIRST:event_exitProgram - // TODO add your handling code here: - this.getClient().getApplication().doShutdown(); - }//GEN-LAST:event_exitProgram - - /** - * Setups the frame - * - * @param client Client instance - */ - @Override - public void setupFrame (final Client client) { - // Has the user entered own data? - if (this.getClient().getContactManager().isOwnContactAdded()) { - // Debug message - this.getLogger().debug("Disabling menus: isOwnContactAdded()=false"); - - // Not entered yet, so enable menu - addOwnData.setEnabled(false); - } - - /* - * Set the Nimbus look and feel - */ - //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> - /* - * If Nimbus (introduced in Java SE 6) is not available, stay with the - * default look and feel. For details see - * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html - */ - try { - for (UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { - if ("Nimbus".equals(info.getName())) { - UIManager.setLookAndFeel(info.getClassName()); - break; - } - } - } catch (final ClassNotFoundException ex) { - this.getLogger().catching(ex); - } catch (final InstantiationException ex) { - this.getLogger().catching(ex); - } catch (final IllegalAccessException ex) { - this.getLogger().catching(ex); - } catch (final javax.swing.UnsupportedLookAndFeelException ex) { - this.getLogger().catching(ex); - } - //</editor-fold> - - // All done here - statusLabel.setText(bundle.getString("AddressbookFrame.status.done.text")); - - // Debug line - this.getLogger().debug("Displaying form ..."); - - /* - * Create and display the form - */ - java.awt.EventQueue.invokeLater(new Runnable() { - @Override - public void run () { - AddressbookFrame.getSelfInstance(client).setVisible(true); - } - }); - } - - /** - * Singelton getter for this frame instance. - * - * @param client Client instance - * @return Returns a singelton instance of this frame - */ - public static final ClientFrame getSelfInstance (final Client client) { - // Is it set? - if (!(self instanceof ClientFrame)) { - // Create new instance - self = new AddressbookFrame(client); - } - - // Return instance - return self; - } - - /** - * Getter for logger - * - * @return Logger - */ - protected final Logger getLogger () { - return this.LOG; - } - - // Variables declaration - do not modify//GEN-BEGIN:variables - private JMenuItem addOwnData; - private JMenu addressbookMenu; - private JTable addressesTable; - private JMenuItem exitProgram; - private JScrollPane listAddressesPanel; - private JMenu mainMenu; - private JMenuBar menuBar; - private JLabel statusLabel; - private JPanel statusPanel; - private JToolBar toolBar; - // End of variables declaration//GEN-END:variables -} +/* + * Copyright (C) 2015 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +package org.mxchange.addressbook.client.gui; + +import javax.swing.JFrame; +import org.mxchange.addressbook.BaseFrameworkSystem; +import org.mxchange.addressbook.FrameAlreadyInitializedException; +import org.mxchange.addressbook.application.AddressbookApplication; +import org.mxchange.addressbook.client.Client; + +/** + * + * @author Roland Haeder + */ +public class AddressbookFrame extends BaseFrameworkSystem implements ClientFrame { + + /** + * Own instance + */ + private static ClientFrame self; + + /** + * Singelton getter for this frame instance. + * + * @param client Client instance + * @return Returns a singelton instance of this frame + */ + public static final ClientFrame getSelfInstance (final Client client) { + // Is it set? + if (!(self instanceof ClientFrame)) { + // Create new instance + self = new AddressbookFrame(client); + } + + // Return instance + return self; + } + + /** + * Frame instance + */ + private final JFrame frame; + + /** + * Whether this frame has been initialized + */ + private boolean isInitialized; + + /** + * Creates an instance of this frame with a client instance + * @param client + */ + private AddressbookFrame (final Client client) { + // Debug line + this.getLogger().debug("Initializing Swing frame ..."); + + // Set frame instance + this.frame = new JFrame(AddressbookApplication.printableTitle()); + + // Set client here + this.setClient(client); + } + + @Override + public void setVisible (final boolean visible) { + throw new UnsupportedOperationException("Not supported yet."); + } + + /** + * Setups the frame + * + * @param client Client instance + */ + @Override + public void setupFrame (final Client client) { + // Has the user entered own data? + if (this.getClient().getContactManager().isOwnContactAdded()) { + // Debug message + this.getLogger().debug("Disabling menus: isOwnContactAdded()=false"); + + // Not entered yet, so enable menu + //addOwnData.setEnabled(false); + } + + // All done here + //statusLabel.setText(bundle.getString("AddressbookFrame.status.done.text")); + } + + /** + * Initalizes this frame. Having initComponents() exposed (publicly + * accessible) means that any other object can initialize components which + * you may not want. + * + * @throws org.mxchange.addressbook.FrameAlreadyInitializedException If this method has been called twice + */ + @Override + public void initFrame () throws FrameAlreadyInitializedException { + // Has this frame been initialized? + if (this.isInitialized) { + // Throw exception + throw new FrameAlreadyInitializedException(); + } + + // Init components + this.initComponents(); + + // Set flag + this.isInitialized = true; + } + + /** + * Initialize components + */ + private void initComponents () { + } + +} diff --git a/Addressbook/src/org/mxchange/addressbook/client/gui/ClientFrame.java b/Addressbook/src/org/mxchange/addressbook/client/gui/ClientFrame.java index 17318d44..06af9bb5 100644 --- a/Addressbook/src/org/mxchange/addressbook/client/gui/ClientFrame.java +++ b/Addressbook/src/org/mxchange/addressbook/client/gui/ClientFrame.java @@ -16,6 +16,7 @@ */ package org.mxchange.addressbook.client.gui; +import org.mxchange.addressbook.FrameAlreadyInitializedException; import org.mxchange.addressbook.FrameworkInterface; import org.mxchange.addressbook.client.Client; @@ -42,6 +43,8 @@ public interface ClientFrame extends FrameworkInterface { /** * Initializes frame + * + * @throws org.mxchange.addressbook.FrameAlreadyInitializedException If this method has been called twice */ - public void initFrame (); + public void initFrame () throws FrameAlreadyInitializedException; } diff --git a/Addressbook/src/org/mxchange/addressbook/client/gui/SwingClient.java b/Addressbook/src/org/mxchange/addressbook/client/gui/SwingClient.java index 9ea4e881..8992b3a1 100644 --- a/Addressbook/src/org/mxchange/addressbook/client/gui/SwingClient.java +++ b/Addressbook/src/org/mxchange/addressbook/client/gui/SwingClient.java @@ -16,6 +16,7 @@ */ package org.mxchange.addressbook.client.gui; +import org.mxchange.addressbook.FrameAlreadyInitializedException; import org.mxchange.addressbook.UnhandledUserChoiceException; import org.mxchange.addressbook.application.Application; import org.mxchange.addressbook.client.BaseClient; @@ -138,8 +139,13 @@ public class SwingClient extends BaseClient implements Client { // Init contact manager here this.initContactManager(); - // Init frame - this.frame.initFrame(); + try { + // Init frame + this.frame.initFrame(); + } catch (final FrameAlreadyInitializedException ex) { + this.getLogger().catching(ex); + System.exit(1); + } // Now start the frame this.frame.setupFrame(this); diff --git a/Addressbook/src/org/mxchange/addressbook/contact/BaseContact.java b/Addressbook/src/org/mxchange/addressbook/contact/BaseContact.java index 78d4f079..2a1ecb73 100644 --- a/Addressbook/src/org/mxchange/addressbook/contact/BaseContact.java +++ b/Addressbook/src/org/mxchange/addressbook/contact/BaseContact.java @@ -28,11 +28,6 @@ import org.mxchange.addressbook.client.Client; * @since 0.0 */ public class BaseContact extends BaseFrameworkSystem { - /** - * Amount of columns - */ - public static final int COLUMN_COUNT = 14; - /** * Birth day */ diff --git a/Addressbook/src/org/mxchange/addressbook/localization/bundle_de_DE.properties b/Addressbook/src/org/mxchange/addressbook/localization/bundle_de_DE.properties index e4c5738b..bbc3dbb8 100644 --- a/Addressbook/src/org/mxchange/addressbook/localization/bundle_de_DE.properties +++ b/Addressbook/src/org/mxchange/addressbook/localization/bundle_de_DE.properties @@ -26,7 +26,3 @@ AddressbookFrame.addOwnData.toolTipText=Erlaubt das Hinzuf\u00fcgen eigener Date AddressbookFrame.addOwnData.AccessibleContext.accessibleName=addOwn AddressbookFrame.addOwnData.AccessibleContext.accessibleDescription= AddressbookFrame.status.done.text=Fertig. -AddressbookFrame.addOwnData.AccessibleContext.accessibleName_1=null -AddressbookFrame.addressbookMenu.text_1=null -AddressbookFrame.exitProgram.text_1=null -AddressbookFrame.statusLabel.text_1=null diff --git a/Addressbook/src/org/mxchange/addressbook/manager/contact/ContactManager.java b/Addressbook/src/org/mxchange/addressbook/manager/contact/ContactManager.java index e89b7081..fefd2c14 100644 --- a/Addressbook/src/org/mxchange/addressbook/manager/contact/ContactManager.java +++ b/Addressbook/src/org/mxchange/addressbook/manager/contact/ContactManager.java @@ -23,7 +23,6 @@ import java.util.Iterator; import java.util.List; import org.mxchange.addressbook.UnhandledUserChoiceException; import org.mxchange.addressbook.client.Client; -import org.mxchange.addressbook.contact.BaseContact; import org.mxchange.addressbook.contact.Contact; import org.mxchange.addressbook.database.frontend.contact.ContactDatabaseFrontend; import org.mxchange.addressbook.database.frontend.contact.ContactWrapper; @@ -37,6 +36,10 @@ import org.mxchange.addressbook.manager.BaseManager; * @version 0.0 */ public class ContactManager extends BaseManager implements ManageableContact { + /** + * Column name list + */ + private final List<String> columnNames; /** * A ContactWrapper instance @@ -48,6 +51,7 @@ public class ContactManager extends BaseManager implements ManageableContact { */ private final List<Contact> contacts; + /** * @param maxContacts Maximum allowed contacts * @param client Client instance to use @@ -56,20 +60,26 @@ public class ContactManager extends BaseManager implements ManageableContact { // Always call super constructor first super(); + // Set client instance + this.setClient(client); + // Init contacts this.contacts = new ArrayList<>(maxContacts); // Init database connection this.contactDatabase = new ContactDatabaseFrontend(this); + // Initialize list + this.columnNames = new ArrayList<>(15); + + // And fill it + this.fillColumnNamesFromBundle(); + // Read all entries this.contactDatabase.readAllContacts(); // Debug message //* NOISY-DEBUG: */ this.getLogger().debug("client=" + client); - - // Init client - this.setClient(client); } /** @@ -364,11 +374,7 @@ public class ContactManager extends BaseManager implements ManageableContact { @Override public int getColumnCount () { - /* - * Return constant, may look useful. But without this, e.g. the - * AddressTableModel have a hard-coded value. - */ - return BaseContact.COLUMN_COUNT; + return this.columnNames.size(); } /** @@ -463,6 +469,29 @@ public class ContactManager extends BaseManager implements ManageableContact { return this.contacts.size(); } + /** + * Fills the column names array with strings from bundle + */ + private void fillColumnNamesFromBundle () { + // First get an iterator from key set to iterate over + Iterator<String> iterator = this.getBundle().keySet().iterator(); + + // Then iterate over all + while (iterator.hasNext()) { + // Get next element + String key = iterator.next(); + + // Does the key start with ContactManager.columnName ? + if (key.startsWith("ContactManager.columnName")) { + // This is the wanted entry. + this.getLogger().debug(MessageFormat.format("key={0}", key)); + + // So add it + this.columnNames.add(this.getBundle().getString(key)); + } + } + } + /** * Flushes all entries by calling database backend */ -- 2.39.5