2 * Copyright (C) 2015 Roland Haeder
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.addressbook.client.gui;
19 import java.awt.BorderLayout;
20 import java.awt.GridLayout;
21 import java.awt.event.ActionEvent;
22 import java.awt.event.ActionListener;
23 import java.awt.event.MouseAdapter;
24 import java.awt.event.MouseEvent;
25 import java.awt.event.WindowAdapter;
26 import java.awt.event.WindowEvent;
27 import java.io.IOException;
28 import java.lang.reflect.InvocationTargetException;
29 import java.sql.SQLException;
30 import java.text.MessageFormat;
31 import javax.swing.BorderFactory;
32 import javax.swing.BoxLayout;
33 import javax.swing.DefaultComboBoxModel;
34 import javax.swing.JButton;
35 import javax.swing.JComboBox;
36 import javax.swing.JDialog;
37 import javax.swing.JFormattedTextField;
38 import javax.swing.JFrame;
39 import javax.swing.JLabel;
40 import javax.swing.JMenu;
41 import javax.swing.JMenuBar;
42 import javax.swing.JMenuItem;
43 import javax.swing.JPanel;
44 import javax.swing.JScrollPane;
45 import javax.swing.JTable;
46 import javax.swing.JTextArea;
47 import javax.swing.JTextField;
48 import javax.swing.border.TitledBorder;
49 import javax.swing.table.TableModel;
50 import org.mxchange.addressbook.application.AddressbookApplication;
51 import org.mxchange.addressbook.exceptions.ContactAlreadyAddedException;
52 import org.mxchange.addressbook.manager.contact.ManageableContactAddressbook;
53 import org.mxchange.jcore.BaseFrameworkSystem;
54 import org.mxchange.jcore.client.Client;
55 import org.mxchange.jcore.exceptions.FrameAlreadyInitializedException;
56 import org.mxchange.jcore.model.contact.Contact;
57 import org.mxchange.jcore.model.contact.gender.Gender;
58 import org.mxchange.jcoreswing.client.gui.ClientFrame;
59 import org.mxchange.jcoreswing.model.swing.contact.ContactTableModel;
63 * @author Roland Haeder
65 public class AddressbookFrame extends BaseFrameworkSystem implements ClientFrame {
70 private static ClientFrame self;
73 * Singelton getter for this frame instance.
75 * @param client Client instance
76 * @return Returns a singelton instance of this frame
78 public static final ClientFrame getSelfInstance (final Client client) {
80 if (!(self instanceof ClientFrame)) {
81 // Create new instance
82 self = new AddressbookFrame(client);
90 * Dialog box "add contact"
92 private JDialog addContact;
95 * Frame instance for "add own data"
97 private JMenuItem addOwnItem;
100 * Instance to table model
102 private TableModel dataModel;
107 private JTable dataTable;
110 * Frame instance for "edit own data"
112 private JMenuItem editOwnItem;
117 private final JFrame frame;
120 * Whether this frame has been initialized
122 private boolean initialized;
125 * Status label needs to be updated
127 private JLabel statusLabel;
130 * Creates an instance of this frame with a client instance
134 private AddressbookFrame (final Client client) {
136 this.getLogger().trace(MessageFormat.format("client={0}: CALLED!", client)); //NOI18N
138 // Set frame instance
139 this.frame = new JFrame();
140 this.frame.setTitle(this.generateFrameTitle("main")); //NOI18N
143 this.setClient(client);
146 this.getLogger().trace("EXIT!"); //NOI18N
150 public Contact doEnterOwnData () {
152 this.getLogger().trace("CALLED!"); //NOI18N
154 // Is the "add contact" window visible?
155 if (this.addContact.isVisible()) {
156 // Something bad happened
157 throw new IllegalStateException("Window addContact is already visible."); //NOI18N
160 // Disable main window
161 this.frame.setEnabled(false);
163 // Make other window visible
164 this.addContact.setVisible(true);
167 this.getLogger().trace("Returning null : EXIT!"); //NOI18N
169 // Return value is not supported
174 * Shutdown this frame
177 public void doShutdown () {
179 this.getLogger().trace("CALLED!"); //NOI18N
181 // First only show shutdown status
182 this.updateStatus("shutdown"); //NOI18N
185 this.getLogger().trace("EXIT!"); //NOI18N
189 * Enables main window (frame)
192 public void enableMainWindow () {
194 this.getLogger().trace("CALLED!"); //NOI18N
197 this.frame.setEnabled(true);
199 // Request focus for this window
200 this.frame.requestFocus();
203 this.getLogger().trace("EXIT!"); //NOI18N
207 * Setups the frame, do not set isInitialized here
209 * @param client Client instance
212 public void setupFrame (final Client client) throws IOException {
214 this.getLogger().trace(MessageFormat.format("client={0}: CALLED!", client)); //NOI18N
216 // Has the user entered own data?
217 if (((ManageableContactAddressbook) this.getClient().getManager()).isOwnContactAdded()) {
219 this.getLogger().debug("Disabling menus: isOwnContactAdded()=false"); //NOI18N
221 // Not entered yet, so disable "add" menu
222 this.addOwnItem.setEnabled(false);
225 this.editOwnItem.setEnabled(false);
228 // Make the frame visible
229 this.frame.setVisible(true);
232 this.updateStatus("done"); //NOI18N
235 this.getLogger().trace("EXIT!"); //NOI18N
239 * Initalizes this frame. Having initComponents() exposed (publicly
240 * accessible) means that any other object can initialize components which
243 * @throws org.mxchange.jcore.exceptions.FrameAlreadyInitializedException If
244 * this method has been called twice
247 public void init () throws FrameAlreadyInitializedException {
249 this.getLogger().trace("CALLED!"); //NOI18N
251 // Has this frame been initialized?
252 if (this.isInitialized()) {
254 throw new FrameAlreadyInitializedException();
258 this.initComponents();
261 this.initialized = true;
264 this.getLogger().trace("EXIT!"); //NOI18N
268 * Returns field isInitialized. This flag indicates whether this frame has
269 * been initialized or not.
271 * @return Field isInitialized
274 public final boolean isInitialized () {
275 return this.initialized;
279 * Shuts down the application.
282 public void shutdownApplication () {
284 this.getLogger().trace("CALLED!"); //NOI18N
286 // To do this, the frame must be initialized
287 if (!this.isInitialized()) {
288 // Not initalized, so bad call
289 this.getLogger().fatal("Bad call of shutdownApplication(). Please report this."); //NOI18N
293 // Call shutdown method
295 this.getClient().getApplication().doShutdown();
296 } catch (final SQLException | IOException ex) {
298 this.abortProgramWithException(ex);
302 this.getLogger().trace("EXIT!"); //NOI18N
306 * Adds a new menu item with given key to menu instance
308 * @param menu Menu instance to add item to
309 * @param key Message key part
310 * @param listener Listener instance
312 private void addMenuItem (final JMenu menu, final String key, final ActionListener listener) {
314 this.getLogger().trace(MessageFormat.format("menu={0},key={1},listener={2} - CALLED!", menu, key, listener)); //NOI18N
317 JMenuItem item = this.initMenuItemWithTooltip(key);
320 item.addActionListener(listener);
326 this.getLogger().trace("EXIT!"); //NOI18N
330 * Adds a JTextField with label and tool tip to given panel
332 * @param panel Panel instance to add text field
333 * @param key Part of message key from resource bundle
334 * @param fieldLength Length of text field
336 private void addTextFieldWithLabelToPanel (final JPanel panel, final String key, final int fieldLength) {
338 this.getLogger().trace(MessageFormat.format("panel={0},key={1},fieldLength={2} - CALLED!", panel, key, fieldLength)); //NOI18N
340 // Init label for given key
341 JLabel label = new JLabel(this.getBundle().getString(String.format("AddressbookFrame.%s.text", key))); //NOI18N
343 // And input box wih tool tip
344 JTextField field = new JTextField(fieldLength);
345 field.setToolTipText(this.getBundle().getString(String.format("AddressbookFrame.%s.toolTipText", key))); //NOI18N
352 this.getLogger().trace("EXIT!"); //NOI18N
356 * Generates a title for borders
358 * @param key Key part to look for
359 * @return Human-readable title
361 private String generateBorderTitle (final String key) {
362 // Call bundle instance
363 return this.getBundle().getString(String.format("AddressbookFrame.border.%s.title.text", key)); //NOI18N
367 * Generates a title for all frames based on given sub title key. If null is
368 * given, the sub title is not generated.
370 * @param subKey Key for sub title resource
371 * @return A full application title
373 private String generateFrameTitle (final String subKey) {
375 String title = AddressbookApplication.printableTitle();
378 if (subKey != null) {
380 title = String.format("%s - %s", title, this.getBundle().getString(String.format("AddressbookFrame.%s.title.text", subKey))); //NOI18N
388 * Initializes "add" and "cancel" buttons
390 private void initAddCancelButtons () {
392 this.getLogger().trace("CALLED!"); //NOI18N
395 JPanel panel = new JPanel();
396 panel.setLayout(new GridLayout(1, 2, 10, 10));
398 // Generate "add" button
399 JButton addButton = new JButton(this.getBundle().getString("AddressbookFrame.button.addAddress.text"));
402 addButton.addActionListener(new AddActionListener(this.addContact, this));
404 // Add button to panel
405 panel.add(addButton);
407 // Generate "cancel" button
408 JButton cancelButton = new JButton(this.getBundle().getString("AddressbookFrame.button.cancel.text"));
411 cancelButton.addActionListener(new CancelActionListener(this.addContact, this));
413 // Add button to panel
414 panel.add(cancelButton);
416 // Add panel to main panel
417 this.addContact.add(panel);
420 this.getLogger().trace("EXIT!"); //NOI18N
424 * Initializes "add contact" dialog
426 private void initAddContactDialog () {
428 this.getLogger().trace("CALLED!"); //NOI18N
430 // Instance dialog and set title
431 this.addContact = new JDialog();
432 this.addContact.setTitle(this.generateFrameTitle("dialog.addContact")); //NOI18N
435 this.addContact.setLayout(new GridLayout(0, 1, 2, 2));
437 // Only hide it on close and make it appear in middle of screen
438 this.addContact.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
439 this.addContact.setLocationRelativeTo(this.frame);
441 // Set always on top and auto-focus
442 this.addContact.setAlwaysOnTop(true);
443 this.addContact.setAutoRequestFocus(true);
446 this.addContact.setSize(500, 500);
448 // And it is not resizeable
449 this.addContact.setResizable(false);
452 * Add listener which asks for confirmation, if data has been entered
453 * but not saved yet. The user may appriciate this ... ;-)
457 this.addContact.addWindowListener(new WindowAdapter() {
459 * Invoked when a window has been closed.
462 public void windowClosed (final WindowEvent e) {
463 // Enable main window again
464 AddressbookFrame.getSelfInstance(null).enableMainWindow();
468 * Invoked when a window is in the process of being closed. The
469 * close operation can be overridden at this point.
472 public void windowClosing (final WindowEvent e) {
473 e.getWindow().dispose();
479 initNameDataPanel(this.addContact);
481 // 2) "address" panel
482 initAddressDataPanel(this.addContact);
485 initOtherDataPanel(this.addContact);
487 // 4) "Add" and "Cancel" buttons, combined they are unique for this dialog
488 initAddCancelButtons();
490 // x)Only for developing:
493 */ this.addContact.setVisible(true);
496 this.getLogger().trace("EXIT!"); //NOI18N
500 * Initializes address panel
502 * @param dialog A JDialog instance to this components to
504 private void initAddressDataPanel (final JDialog dialog) {
506 this.getLogger().trace("CALLED!"); //NOI18N
508 // Panel "address" input boxes
509 JPanel addressPanel = new JPanel();
510 addressPanel.setLayout(new GridLayout(0, 4, 3, 3));
512 // Set border to titled version
513 addressPanel.setBorder(new TitledBorder(this.generateBorderTitle("address"))); //NOI18N
515 // Add text field for street
516 this.addTextFieldWithLabelToPanel(addressPanel, "street", 20); //NOI18N
519 JLabel numberLabel = new JLabel(this.getBundle().getString("AddressbookFrame.number.text"));
521 // And text field, but only accept numbers
522 JFormattedTextField number = new JFormattedTextField();
523 number.setToolTipText(this.getBundle().getString("AddressbookFrame.number.toolTipText"));
525 // Add both to street panel
526 addressPanel.add(numberLabel);
527 addressPanel.add(number);
529 // Label for ZIP code, again numbers only
530 JLabel zipLabel = new JLabel(this.getBundle().getString("AddressbookFrame.zip.text"));
532 // Init text field with label
533 JFormattedTextField zip = new JFormattedTextField();
534 zip.setToolTipText(this.getBundle().getString("AddressbookFrame.zip.toolTipText"));
536 // Add both to street panel
537 addressPanel.add(zipLabel);
538 addressPanel.add(zip);
540 // Add text field for city name
541 this.addTextFieldWithLabelToPanel(addressPanel, "city", 20); //NOI18N
543 // Add panel to dialog
544 dialog.add(addressPanel);
547 this.getLogger().trace("EXIT!"); //NOI18N
551 * Initialize components
553 private void initComponents () {
555 this.getLogger().trace("CALLED!"); //NOI18N
557 // Set default close operation
558 this.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
560 // Register shutdown listener
561 this.frame.addWindowListener(new WindowAdapter() {
563 * Invoked when a window has been closed.
566 public void windowClosed (final WindowEvent e) {
567 // Shutdown application cleanly
568 self.shutdownApplication();
572 * Invoked when a window is in the process of being closed. The
573 * close operation can be overridden at this point.
576 public void windowClosing (final WindowEvent e) {
577 // Also shutdown cleanly here
578 self.shutdownApplication();
582 // Setup layout manager
583 this.frame.setLayout(new BorderLayout(2, 2));
586 this.frame.setSize(700, 400);
588 // Center window in middle of screen, instead of top-left corner
589 this.frame.setLocationRelativeTo(null);
592 this.initMenuSystem();
598 this.initStatusPanel();
600 // Init other windows
601 this.initOtherDialogs();
604 this.getLogger().trace("EXIT!"); //NOI18N
608 * Initializes a menu item instance with tool tip
610 * @param key Message key part
611 * @return A finished JMenuItem instance
613 private JMenuItem initMenuItemWithTooltip (final String key) {
615 this.getLogger().trace(MessageFormat.format("key={0} - CALLED!", key)); //NOI18N
617 JMenuItem item = new JMenuItem(this.getBundle().getString(String.format("AddressbookFrame.menuItem.%s.text", key))); //NOI18N
618 item.setToolTipText(this.getBundle().getString(String.format("AddressbookFrame.menuItem.%s.toolTipText", key))); //NOI18N
621 this.getLogger().trace(MessageFormat.format("item={0} - EXIT!", item)); //NOI18N
628 * Initializes the menu system
630 private void initMenuSystem () {
632 this.getLogger().trace("CALLED!"); //NOI18N
634 // Init menu bar, menu and item instances
635 JMenuBar menuBar = new JMenuBar();
641 menu = new JMenu(this.getBundle().getString("AddressbookFrame.menu.file.text"));
644 // 1.x) Exit program (should be last)
645 this.addMenuItem(menu, "exitProgram", new ActionListener() { //NOI18N
647 * If the user has performed this action
649 * @param e An instance of an ActionEvent class
652 public void actionPerformed (final ActionEvent e) {
653 self.shutdownApplication();
657 // Add menu -> menu bar
661 // 2) Addressbook menu
662 menu = new JMenu(this.getBundle().getString("AddressbookFrame.menu.addressbook.text"));
665 this.addOwnItem = this.initMenuItemWithTooltip("addOwnData"); //NOI18N
667 // Add listener to exit menu
668 this.addOwnItem.addActionListener(new ActionListener() {
670 * If the user has performed this action
672 * @param e An instance of an ActionEvent class
675 public void actionPerformed (final ActionEvent e) {
677 ((ManageableContactAddressbook) self.getClient().getManager()).doEnterOwnData();
678 } catch (final ContactAlreadyAddedException ex) {
679 // Already added, log away
680 // TODO maybe output message here?
681 self.logException(ex);
682 } catch (final IOException ex) {
683 // Somethind bad happened here
684 // TODO Output error message here?
690 menu.add(this.addOwnItem);
692 // 2.2) Edit own data
693 this.editOwnItem = this.initMenuItemWithTooltip("editOwnData"); //NOI18N
695 // Add listener to exit menu
696 this.editOwnItem.addActionListener(new ActionListener() {
698 * If the user has performed this action
700 * @param e An instance of an ActionEvent class
703 public void actionPerformed (final ActionEvent e) {
705 ((ManageableContactAddressbook) self.getClient().getManager()).doChangeOwnData();
706 } catch (final IOException | SQLException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
707 self.logException(ex);
713 menu.add(this.editOwnItem);
716 // 1) Add new contact
717 this.addMenuItem(menu, "addNewContact", new ActionListener() { //NOI18N
719 * If the user has performed this action
721 * @param e An instance of an ActionEvent class
724 public void actionPerformed (final ActionEvent e) {
725 ((ManageableContactAddressbook) self.getClient().getManager()).doAddOtherAddress();
729 // Add menu -> menu bar
732 // Add menu bar -> frame
733 this.frame.add(menuBar, BorderLayout.NORTH);
736 this.getLogger().trace("EXIT!"); //NOI18N
740 * Initializes name panel
742 * @param dialog A JDialog instance to this components to
744 private void initNameDataPanel (final JDialog dialog) {
746 this.getLogger().trace(MessageFormat.format("dialog={0} - CALLED!", dialog)); //NOI18N
748 // Panel "name" input boxes
749 JPanel namePanel = new JPanel();
750 namePanel.setLayout(new GridLayout(0, 2, 3, 3));
752 // Set border to titled version
753 namePanel.setBorder(new TitledBorder(this.generateBorderTitle("name"))); //NOI18N
756 JLabel gLabel = new JLabel(this.getBundle().getString("AddressbookFrame.gender.text"));
759 Gender[] genders = Gender.values();
761 // Init gender combo box with tool tip
762 JComboBox<Gender> gender = new JComboBox<>(new DefaultComboBoxModel<>(genders));
763 gender.setToolTipText(this.getBundle().getString("AddressbookFrame.gender.toolTipText"));
765 // Add both to gender panel
766 namePanel.add(gLabel);
767 namePanel.add(gender);
769 // Add text field for surname
770 this.addTextFieldWithLabelToPanel(namePanel, "surname", 20); //NOI18N
772 // Add text field for family name
773 this.addTextFieldWithLabelToPanel(namePanel, "familyName", 20); //NOI18N
775 // Finally add panel to dialog
776 dialog.add(namePanel);
779 this.getLogger().trace("EXIT!"); //NOI18N
783 * Initializes "other" data panel
785 * @param dialog A JDialog instance to this components to TODO Fill this
788 private void initOtherDataPanel (final JDialog dialog) {
790 this.getLogger().trace(MessageFormat.format("dialog={0} - CALLED!", dialog)); //NOI18N
792 // Panel "other" input boxes
793 JPanel otherPanel = new JPanel();
794 otherPanel.setLayout(new GridLayout(0, 2, 3, 3));
795 otherPanel.setBorder(new TitledBorder(this.generateBorderTitle("other"))); //NOI18N
797 // Add text field for email address
798 this.addTextFieldWithLabelToPanel(otherPanel, "emailAddress", 20); //NOI18N
800 // Add text field for phone number
801 this.addTextFieldWithLabelToPanel(otherPanel, "phoneNumber", 20); //NOI18N
803 // Add text field for cellphone number
804 this.addTextFieldWithLabelToPanel(otherPanel, "cellphoneNumber", 20); //NOI18N
806 // Add text field for fax number
807 this.addTextFieldWithLabelToPanel(otherPanel, "faxNumber", 20); //NOI18N
810 JLabel commentLabel = new JLabel(this.getBundle().getString("AddressbookFrame.comment.text"));
812 // Init text area with tool tip
813 JTextArea comment = new JTextArea(5, 20);
814 comment.setToolTipText(this.getBundle().getString("AddressbookFrame.comment.toolTipText"));
817 otherPanel.add(commentLabel);
818 otherPanel.add(comment);
820 // Finally add panel to dialog
821 dialog.add(otherPanel);
824 this.getLogger().trace("EXIT!"); //NOI18N
828 * Initialize other dialogs (e.g. "Add contact")
830 private void initOtherDialogs () {
832 this.getLogger().trace("CALLED!"); //NOI18N
834 // Init other windows:
836 initAddContactDialog();
839 this.getLogger().trace("EXIT!"); //NOI18N
843 * Initializes status panel
845 private void initStatusPanel () {
847 this.getLogger().trace("CALLED!"); //NOI18N
849 // Init status label (which needs to be updated
850 this.statusLabel = new JLabel();
851 this.updateStatus("initializing"); //NOI18N
853 // Init status bar in south
854 JPanel panel = new JPanel();
855 panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
856 panel.add(this.statusLabel);
857 panel.setBorder(BorderFactory.createEtchedBorder());
859 // Add panel to frame
860 this.frame.add(panel, BorderLayout.SOUTH);
863 this.getLogger().trace("EXIT!"); //NOI18N
867 * Initializes the table which will show all contacts
869 private void initTable () {
871 this.getLogger().trace("CALLED!"); //NOI18N
873 // Instance table model
874 this.dataModel = new ContactTableModel(this.getClient().getManager());
877 this.dataTable = new JTable(this.dataModel);
879 // Add mouse listener
880 this.dataTable.addMouseListener(new MouseAdapter() {
882 * If the user peformed a click on a cell
884 * @param e Mouse event instance
887 public void mouseClicked (final MouseEvent e) {
888 throw new UnsupportedOperationException("Unfinished."); //NOI18N
892 // Instance scroll pane
893 JScrollPane scroller = new JScrollPane();
895 // Add table to scroll pane
896 scroller.setViewportView(this.dataTable);
897 scroller.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
898 scroller.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
901 this.frame.add(scroller, BorderLayout.CENTER);
904 this.getLogger().trace("EXIT!"); //NOI18N
908 * Updates status to given type
910 * @param type Status type
912 private void updateStatus (final String type) {
914 this.getLogger().trace(MessageFormat.format("type={0} - CALLED!", type)); //NOI18N
916 // Set status message
917 this.statusLabel.setText(this.getBundle().getString(String.format("AddressbookFrame.statusLabel.%s.text", type))); //NOI18N
920 this.getLogger().trace("EXIT!"); //NOI18N
924 * Class for "add address" button
926 private static class AddActionListener extends BaseFrameworkSystem implements ActionListener {
931 private final JDialog dialog;
934 * Frame (not JFrame) instance
936 private final ClientFrame frame;
939 * Constructor for action listener
941 * @param dialog Dialog instance to call back
942 * @param frame Frame instance (not JFrame)
944 protected AddActionListener (final JDialog dialog, final ClientFrame frame) {
945 // Set dialog and frame here
946 this.dialog = dialog;
951 * If the action has been performed
953 * @param e The performed action event
956 public void actionPerformed (final ActionEvent e) {
957 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
962 * Class for "cancel address" button
964 private static class CancelActionListener extends BaseFrameworkSystem implements ActionListener {
969 private final JDialog dialog;
972 * Frame (not JFrame) instance
974 private final ClientFrame frame;
977 * Constructor for action listener
979 * @param dialog Dialog instance to call back
980 * @param frame Frame instance (not JFrame)
982 protected CancelActionListener (final JDialog dialog, final ClientFrame frame) {
983 // Set dialog and frame here
984 this.dialog = dialog;
989 * If the action has been performed
991 * @param e The performed action event
994 public void actionPerformed (final ActionEvent e) {
995 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.