*/
package org.mxchange.addressbook.client.gui;
+import org.mxchange.addressbook.model.gender.GenderComboBoxModel;
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.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.border.TitledBorder;
import javax.swing.table.TableModel;
import org.mxchange.addressbook.BaseFrameworkSystem;
import org.mxchange.addressbook.application.AddressbookApplication;
// 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 panel = new JPanel();
+ panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
+
+ // Set border to titled version
+ panel.setBorder(new TitledBorder(this.generateBorderTitle("name")));
+
+ // Add some input boxes for "name" panel
+ JComboBox<String> gender = new JComboBox<>(new GenderComboBoxModel(this.getClient()));
+
+ // Finally add panel to dialog
+ this.addContact.add(panel);
+
+ // 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)));
}
}