package org.mxchange.addressbook.client.gui;
import java.awt.BorderLayout;
+import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.text.MessageFormat;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
+import javax.swing.DefaultComboBoxModel;
+import javax.swing.JComboBox;
+import javax.swing.JDialog;
import javax.swing.JFrame;
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.JTextField;
+import javax.swing.border.TitledBorder;
import javax.swing.table.TableModel;
import org.mxchange.addressbook.BaseFrameworkSystem;
import org.mxchange.addressbook.application.AddressbookApplication;
import org.mxchange.addressbook.client.Client;
+import org.mxchange.addressbook.contact.Gender;
import org.mxchange.addressbook.exceptions.FrameAlreadyInitializedException;
import org.mxchange.addressbook.model.contact.ContactTableModel;
// Return instance
return self;
}
+
+ /**
+ * Dialog box "add contact"
+ */
+ private JDialog addContact;
+
/**
* Frame instance for "add own data"
*/
this.getLogger().trace(MessageFormat.format("client={0}: CALLED!", client));
// Set frame instance
- this.frame = new JFrame(AddressbookApplication.printableTitle());
+ this.frame = new JFrame();
+ this.frame.setTitle(this.generateFrameTitle("main"));
// Set client here
this.setClient(client);
this.getClient().getApplication().doShutdown();
}
+ /**
+ * Generates a title for borders
+ * @param key Key part to look for
+ * @return Human-readable title
+ */
+ private String generateBorderTitle (final String key) {
+ // Call bundle instance
+ return this.getBundle().getString(String.format("AddressbookFrame.border.%s.title.text", key));
+ }
+
+ /**
+ * Generates a title for all frames based on given sub title key. If null is
+ * given, the sub title is not generated.
+ *
+ * @param subKey Key for sub title resource
+ * @return A full application title
+ */
+ private String generateFrameTitle (final String subKey) {
+ // Base title
+ String title = AddressbookApplication.printableTitle();
+
+ // Is key given?
+ if (subKey != null) {
+ // Add sub title
+ title = String.format("%s - %s", title, this.getBundle().getString(String.format("AddressbookFrame.%s.title.text", subKey)));
+ }
+
+ // Return it
+ return title;
+ }
+
+ /**
+ * Initializes "add contact" dialog
+ */
+ private void initAddContactDialog () {
+ // Instance dialog and set title
+ this.addContact = new JDialog();
+ this.addContact.setTitle(this.generateFrameTitle("dialog.addContact"));
+ this.addContact.setLayout(new GridLayout(4, 1));
+
+ // Only hide it on close and make it appear in middle of screen
+ this.addContact.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
+ this.addContact.setLocationRelativeTo(null);
+
+ // Set always on top and auto-focus
+ this.addContact.setAlwaysOnTop(true);
+ this.addContact.setAutoRequestFocus(true);
+
+ // Initial dimension
+ this.addContact.setSize(400, 300);
+
+ /*
+ * Add listener which asks for confirmation, if data has been entered
+ * but not saved yet. The user may appriciate this ... ;-)
+ *
+ * @TODO Unfinished
+ */
+
+ // Init 3 panels:
+ // 1) Panel "name" input boxes
+ JPanel namePanel = new JPanel();
+ namePanel.setLayout(new BoxLayout(namePanel, BoxLayout.Y_AXIS));
+
+ // Set border to titled version
+ namePanel.setBorder(new TitledBorder(this.generateBorderTitle("name")));
+
+ // Add some input boxes for "name" panel
+ JComboBox<Gender> gender = new JComboBox<>(new DefaultComboBoxModel<Gender>());
+
+ // Panel for gender
+ JPanel gPanel = new JPanel();
+ gPanel.setLayout(new GridLayout(1, 2));
+
+ // Set tooltip text
+ gPanel.setToolTipText(this.getBundle().getString("AddressbookFrame.gender.tooltipText"));
+
+ // Gender text field
+ JLabel gLabel = new JLabel(this.getBundle().getString("AddressbookFrame.gender.text"));
+
+ // Add both to gender panel
+ gPanel.add(gLabel);
+ gPanel.add(gender);
+
+ // Add panel to north of "name" panel
+ namePanel.add(gPanel, BorderLayout.NORTH);
+
+ // Panel for surname
+ JPanel sPanel = new JPanel();
+ sPanel.setLayout(new GridLayout(1, 2));
+
+ // Set too tip text
+ sPanel.setToolTipText(this.getBundle().getString("AddressbookFrame.surname.tooltipText"));
+
+ // New label for surname is not needed
+ JLabel sLabel = new JLabel(this.getBundle().getString("AddressbookFrame.surname.text"));
+
+ // And input box
+ JTextField surname = new JTextField(20);
+
+ // Add both to surname panel
+ sPanel.add(sLabel);
+ sPanel.add(surname);
+
+ // Add surname panel to "name" panel
+ namePanel.add(sPanel, BorderLayout.CENTER);
+
+ // Finally add panel to dialog
+ this.addContact.add(namePanel);
+
+ // Only for developing:
+ /* DEBUG: */ this.addContact.setVisible(true);
+ }
+
/**
* Initialize components
*/
// Init status panel
initStatusPanel();
+
+ // Init other windows
+ initOtherDialogs();
}
/**
JMenuBar menuBar = new JMenuBar();
JMenu menu;
JMenuItem item;
-
- // Init some menus:
+
+ // Init some menus:
// 1) File menu
menu = new JMenu(this.getBundle().getString("AddressbookFrame.menu.file.text"));
-
- // Add menu items:
+
+ // Add menu items:
// 1.x) Exit program (should be last)
item = new JMenuItem(this.getBundle().getString("AddressbookFrame.menuItem.exitProgram.text"));
item.setToolTipText(this.getBundle().getString("AddressbookFrame.menuItem.exitProgram.toolTipText"));
// Add menu -> menu bar
menuBar.add(menu);
-
- // Init some menus:
+
+ // Init some menus:
// 2) Addressbook menu
menu = new JMenu(this.getBundle().getString("AddressbookFrame.menu.addressbook.text"));
this.frame.add(menuBar, BorderLayout.NORTH);
}
+ /**
+ * Initialize other dialogs (e.g. "Add contact")
+ */
+ private void initOtherDialogs () {
+ // Init other windows:
+ // 1) Add contact
+ initAddContactDialog();
+ }
+
/**
* Initializes status panel
*/
}
});
- // Add table to frame
- this.frame.add(this.dataTable, BorderLayout.CENTER);
+ // Instance scroll pane
+ JScrollPane scroller = new JScrollPane();
+
+ // Add table to scroll pane
+ scroller.setViewportView(this.dataTable);
+ scroller.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
+ scroller.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
+
+ // Add pane to frame
+ this.frame.add(scroller, BorderLayout.CENTER);
}
/**
*/
private void updateStatus (final String type) {
// Set status message
- this.statusLabel.setText(this.getBundle().getString("AddressbookFrame.statusLabel." + type + ".text"));
+ this.statusLabel.setText(this.getBundle().getString(String.format("AddressbookFrame.statusLabel.%s.text", type)));
}
}