KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > syncclient > demo > ContactNew


1 /**
2  * Copyright (C) 2003-2005 Funambol
3  *
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 2 of the License, or
7  * (at your option) any later version.
8  *
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.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18
19 package sync4j.syncclient.demo;
20
21 import java.awt.BorderLayout JavaDoc;
22 import java.awt.Button JavaDoc;
23 import java.awt.GridLayout JavaDoc;
24 import java.awt.Label JavaDoc;
25 import java.awt.Panel JavaDoc;
26 import java.awt.event.ActionEvent JavaDoc;
27 import java.awt.event.ActionListener JavaDoc;
28
29 import sync4j.foundation.pdi.contact.Contact;
30
31 /**
32  * The new contact insertion panel.
33  *
34  * @author Fabio Maggi @ Funambol
35  * @author Alessandro Morandi, Giorgio Orsi
36  * @version $Id: ContactNew.java,v 1.5 2005/01/19 11:01:11 fabius Exp $
37  */

38 public class ContactNew
39 extends Panel JavaDoc
40 implements ActionListener JavaDoc, ConfigurationParameters {
41
42     //---------------------------------------------------------- Constants
43

44     //---------------------------------------------------------- Private data
45

46     //
47
// The window containing this panel
48
//
49
private MainWindow mw = null ;
50
51     private ContactForm form = null ;
52     private CheckContactFields cfields = null ;
53
54     private Language ln = new Language() ;
55
56     //---------------------------------------------------------- Public methods
57

58     /**
59      * Creates the panel.
60      *
61      * @param mw the window containing this panel
62      */

63     public ContactNew(MainWindow mw) {
64
65         Button JavaDoc butOk = null ;
66         Button JavaDoc butCancel = null ;
67         Panel JavaDoc buttonPanel = null ;
68         Label JavaDoc title = null ;
69
70         this.mw = mw;
71
72         setLayout (new BorderLayout JavaDoc() ) ;
73         title = new Label JavaDoc (ln.getString ("new_contact") ) ;
74         form = new ContactForm (mw ) ;
75
76         butOk = new Button JavaDoc (ln.getString ("ok") ) ;
77         butOk.setActionCommand ("ok" ) ;
78         butOk.addActionListener (this ) ;
79
80         butCancel = new Button JavaDoc (ln.getString ("cancel" ) ) ;
81         butCancel.setActionCommand ("cancel" ) ;
82         butCancel.addActionListener (this ) ;
83
84         buttonPanel = new Panel JavaDoc();
85         buttonPanel.setLayout(new GridLayout JavaDoc(1, 2));
86         buttonPanel.add (butOk ) ;
87         buttonPanel.add (butCancel ) ;
88
89         add(title , BorderLayout.NORTH ) ;
90         add(form , BorderLayout.CENTER ) ;
91         add(buttonPanel , BorderLayout.SOUTH ) ;
92
93     }
94
95     /**
96      * Invoked when an action occurs (i.e. a button is pressed).
97      *
98      * @param evt the occurred action
99      */

100     public void actionPerformed(ActionEvent JavaDoc evt) {
101         if (evt.getActionCommand().equals("ok")) {
102
103                 cfields = new CheckContactFields(mw, form);
104                 if (!cfields.areFieldsRight()) {
105                     cfields.show();
106                     mw.setEnabled(false);
107                 } else {
108                     saveContact();
109                 }
110         } else if (evt.getActionCommand().equals("cancel")) {
111             mw.show(KEY_CONTACTLIST);
112         }
113     }
114
115     //---------------------------------------------------------- Protected methods
116

117     /**
118      * Sets all the textfields in the DemoContactForm
119      * subpanel to an empty string.
120      */

121     protected void blankFields() {
122         form.blankFields();
123     }
124
125     //---------------------------------------------------------- Private methods
126

127     /**
128      * Saves the new contact.
129      */

130     private void saveContact() {
131         mw.writeNewContact(form.getFields());
132         mw.show(KEY_CONTACTLIST);
133     }
134
135 }
Popular Tags