KickJava   Java API By Example, From Geeks To Geeks.

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


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 contact modification panel.
33  *
34  * @author Fabio Maggi @ Funambol
35  * @author Alessandro Morandi, Giorgio Orsi
36  * @version $Id: ContactModify.java,v 1.5 2005/01/19 11:01:11 fabius Exp $
37  */

38 public class ContactModify
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 ContactModify(MainWindow mw) {
64
65         Button JavaDoc butCancel = null ;
66         Button JavaDoc butOk = null ;
67         Label JavaDoc title = null ;
68         Panel JavaDoc buttonPanel = null ;
69
70         this.mw = mw;
71
72         setLayout(new BorderLayout JavaDoc());
73         title = new Label JavaDoc(ln.getString ("contact_modify"));
74
75         form = new ContactForm(mw);
76
77         butOk = new Button JavaDoc (ln.getString ("ok" ) ) ;
78         butOk.setActionCommand ("ok" ) ;
79         butOk.addActionListener (this ) ;
80
81         butCancel = new Button JavaDoc (ln.getString ("cancel" ) ) ;
82         butCancel.setActionCommand ("cancel" ) ;
83         butCancel.addActionListener (this ) ;
84
85         buttonPanel = new Panel JavaDoc();
86         buttonPanel.setLayout(new GridLayout JavaDoc(1, 2));
87         buttonPanel.add (butOk ) ;
88         buttonPanel.add (butCancel ) ;
89
90         add(title , BorderLayout.NORTH ) ;
91         add(form , BorderLayout.CENTER ) ;
92         add(buttonPanel , BorderLayout.SOUTH ) ;
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
102         if (evt.getActionCommand().equals("ok")) {
103
104             cfields = new CheckContactFields(mw, form);
105
106             if (!cfields.areFieldsRight()) {
107                 cfields.show();
108                 mw.setEnabled(false);
109             } else {
110                 saveContact();
111             }
112
113         } else if (evt.getActionCommand().equals("cancel")) {
114             mw.show(KEY_CONTACTLIST);
115         }
116     }
117
118     //---------------------------------------------------------- Protected methods
119

120     /**
121      * Sets the fields with the values contained in the specified Contact object
122      * and the checkbox with the specified type.
123      *
124      * @param contact the Contact object which is the source of the values
125      */

126     protected void fillFields(Contact contact) {
127         form.setFields(contact);
128     }
129
130     //---------------------------------------------------------- Private methods
131

132     /**
133      * Saves the modified contact.
134      */

135     private void saveContact() {
136         mw.writeModContact(form.getFields(),mw.getCurrentIndex().intValue());
137         mw.show(KEY_CONTACTLIST);
138     }
139
140 }
Popular Tags