From: Roland Haeder Date: Thu, 23 Jul 2015 10:57:21 +0000 (+0200) Subject: The NetBeans-created GUI was buggy, maybe because of the .form file. So I better... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=ac52e6515a6d8e23aea65a40b1ac0d1d481d6dfe;p=jaddressbook-lib.git The NetBeans-created GUI was buggy, maybe because of the .form file. So I better write my own one. Signed-off-by: Roland Häder --- 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 . + */ +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 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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 . - */ -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") - // //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(); - }// //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 - */ - // - /* - * 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); - } - // - - // 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 . + */ +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 columnNames; /** * A ContactWrapper instance @@ -48,6 +51,7 @@ public class ContactManager extends BaseManager implements ManageableContact { */ private final List 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 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 */