KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > JProfilePane


1 import javax.swing.*;
2 import javax.accessibility.Accessible JavaDoc;
3 import java.awt.image.ImageObserver JavaDoc;
4 import java.awt.*;
5 import java.io.Serializable JavaDoc;
6 import org.jivesoftware.smack.util.StringUtils;
7
8
9 /** Profile tabbed pane.*/
10 public final class JProfilePane extends JTabbedPane implements Accessible JavaDoc, ImageObserver JavaDoc, MenuContainer, Serializable JavaDoc, SwingConstants{
11     
12     private static final int GAP=10;
13     final private Box generalBox=new Box(BoxLayout.Y_AXIS);
14     final private JPanel general=new JPanel();
15     final private JPanel generalPanel=new JPanel(new SpringLayout());
16         final private JLabel fullNameLbl=new JLabel();
17         final private JTextField fullName=new JTextField(20);
18         final private JLabel nickNameLbl=new JLabel();
19         final private JTextField nickName=new JTextField(20);
20         final private JLabel birthdayLbl=new JLabel();
21         final private JTextField birthday=new JTextField(20);
22         final private JLabel emailLbl=new JLabel();
23         final private JTextField email=new JTextField(20);
24         final private JLabel homepageLbl=new JLabel();
25         final private JTextField homepage=new JTextField(20);
26         final private JLabel phoneLbl=new JLabel();
27         final private JTextField phone=new JTextField(20);
28     final private Box locationBox=new Box(BoxLayout.Y_AXIS);
29     final private JPanel location=new JPanel();
30     final private JPanel locationPanel=new JPanel(new SpringLayout());
31         final private JLabel streetLbl=new JLabel();
32         final private JTextField street=new JTextField(20);
33         final private JLabel cityLbl=new JLabel();
34         final private JTextField city=new JTextField(20);
35         final private JLabel stateLbl=new JLabel();
36         final private JTextField state=new JTextField(20);
37         final private JLabel postcodeLbl=new JLabel();
38         final private JTextField postcode=new JTextField(20);
39         final private JLabel countryLbl=new JLabel();
40         final private JTextField country=new JTextField(20);
41     final private Box workBox=new Box(BoxLayout.Y_AXIS);
42     final private JPanel work=new JPanel();
43     final private JPanel workPanel=new JPanel(new SpringLayout());
44         final private JLabel companyLbl=new JLabel();
45         final private JTextField company=new JTextField(20);
46         final private JLabel positionLbl=new JLabel();
47         final private JTextField position=new JTextField(20);
48         final private JLabel departmentLbl=new JLabel();
49         final private JTextField department=new JTextField(20);
50         final private JLabel roleLbl=new JLabel();
51         final private JTextField role=new JTextField(20);
52     final private JPanel notesPanel=new JPanel(new GridLayout(1,1,GAP,GAP));
53         final private JTextArea notes=new JTextArea(3,20);
54         final private JScrollPane notesSp=new JScrollPane(notes);
55     final private JPanel keyPanel=new JPanel(new BorderLayout(GAP,GAP));
56         final private JLabel keyStatusLbl=new JLabel();
57         final private JLabel keyInfoLbl=new JLabel();
58         private String JavaDoc keyStatus=new String JavaDoc("key_none"); // may be key_ok, key_none,key_invalid
59
private String JavaDoc keyDate=new String JavaDoc("");
60         private String JavaDoc keyFingerprint=new String JavaDoc("");
61     private boolean showKeyPanel=true; // optional last panel
62
private boolean showStatus=false; //optional first panel
63

64     /** Creates a new blank, editable profile pane with no status panel and a key panel.*/
65     public JProfilePane(){
66         super();
67         // general panel
68
generalPanel.add(fullNameLbl);
69         generalPanel.add(fullName);
70         generalPanel.add(nickNameLbl);
71         generalPanel.add(nickName);
72         generalPanel.add(birthdayLbl);
73         generalPanel.add(birthday);
74         generalPanel.add(emailLbl);
75         generalPanel.add(email);
76         generalPanel.add(homepageLbl);
77         generalPanel.add(homepage);
78         generalPanel.add(phoneLbl);
79         generalPanel.add(phone);
80         // location panel
81
locationPanel.add(streetLbl);
82         locationPanel.add(street);
83         locationPanel.add(cityLbl);
84         locationPanel.add(city);
85         locationPanel.add(stateLbl);
86         locationPanel.add(state);
87         locationPanel.add(postcodeLbl);
88         locationPanel.add(postcode);
89         locationPanel.add(countryLbl);
90         locationPanel.add(country);
91         // work panel
92
workPanel.add(companyLbl);
93         workPanel.add(company);
94         workPanel.add(positionLbl);
95         workPanel.add(position);
96         workPanel.add(departmentLbl);
97         workPanel.add(department);
98         workPanel.add(roleLbl);
99         workPanel.add(role);
100         //notes panel
101
notes.setLineWrap(true);
102         notesSp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
103         if(WhisperIM.isMac){
104             notesSp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
105         }
106         else{
107             notesSp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
108         }
109         notesPanel.add(notesSp);
110         // key panel
111
keyPanel.add(keyStatusLbl,BorderLayout.NORTH);
112         keyInfoLbl.setVerticalAlignment(TOP);
113         keyInfoLbl.setHorizontalAlignment(CENTER);
114         keyStatusLbl.setHorizontalAlignment(CENTER);
115         keyPanel.add(keyInfoLbl,BorderLayout.CENTER);
116         // set layouts
117
SpringUtilities.makeCompactGrid(generalPanel,6,2,GAP,GAP,GAP,GAP);
118         generalBox.add(generalPanel);
119         generalBox.add(Box.createGlue());
120         general.add(generalBox);
121         // ..location
122
SpringUtilities.makeCompactGrid(locationPanel,5,2,GAP,GAP,GAP,GAP);
123         locationBox.add(locationPanel);
124         locationBox.add(Box.createGlue());
125         location.add(locationBox);
126         // ..work
127
SpringUtilities.makeCompactGrid(workPanel,4,2,GAP,GAP,GAP,GAP);
128         workBox.add(workPanel);
129         workBox.add(Box.createGlue());
130         work.add(workBox);
131         // add the parent panels
132
add(general);
133         add(location);
134         add(work);
135         add(notesPanel);
136         add(keyPanel);
137         setIconAt(4,Icons.UNLOCKED);
138         // and set the labels according to languae in use
139
this.setLang();
140     }
141     
142     public JProfilePane(Profile p, boolean isEditable, whisper.PublicKey key, boolean isKeyValid){
143         this();
144         set(p,isEditable,key,isKeyValid);
145     }
146     
147     
148     public void set(Profile p, boolean isEditable, whisper.PublicKey key, boolean isKeyValid){
149         fullName.setText(p.FullName);
150         nickName.setText(p.NickName);
151         birthday.setText(p.Birthday);
152         email.setText(p.Email);
153         homepage.setText(p.HomePage);
154         phone.setText(p.Phone);
155         street.setText(p.Street);
156         city.setText(p.City);
157         state.setText(p.State);
158         postcode.setText(p.PostCode);
159         country.setText(p.Country);
160         company.setText(p.Company);
161         position.setText(p.Position);
162         department.setText(p.Department);
163         role.setText(p.Role);
164         notes.setText(p.Notes);
165         if(!isEditable){
166             setEditable(false);
167         }
168         if(key!=null){
169             keyDate=key.date();
170             keyFingerprint=StringUtils.encodeHex(key.getKeyID());
171             keyInfoLbl.setText("<html>"+Lang.gs("key_date")+" "+keyDate+"<br>"+Lang.gs("key_fingerprint")+" "+keyFingerprint);
172             if(isKeyValid){
173                 keyStatus="key_ok";
174                 setIconAt(4,Icons.KEY);
175             }
176             else{
177                 keyStatus="key_invalid";
178                 setIconAt(4,Icons.WARNING);
179             }
180         }
181         else{
182             keyStatus="key_none";
183             setIconAt(4,Icons.UNLOCKED);
184             keyInfoLbl.setText("");
185         }
186         keyStatusLbl.setText("<html><p>"+Lang.gs(keyStatus)+"</p></html>");
187     }
188     
189     public Profile get(){
190         Profile p=new Profile();
191         p.FullName=fullName.getText();
192         p.NickName=nickName.getText();
193         p.Birthday=birthday.getText();
194         p.Email=email.getText();
195         p.HomePage=homepage.getText();
196         p.Phone=phone.getText();
197         p.Street=street.getText();
198         p.City=city.getText();
199         p.State=state.getText();
200         p.PostCode=postcode.getText();
201         p.Country=country.getText();
202         p.Company=company.getText();
203         p.Department=department.getText();
204         p.Position=position.getText();
205         p.Role=role.getText();
206         p.Notes=notes.getText();
207         return p;
208     }
209     
210     public void setEditable(boolean b){
211         fullName.setEditable(b);
212         nickName.setEditable(b);
213         birthday.setEditable(b);
214         email.setEditable(b);
215         homepage.setEditable(b);
216         phone.setEditable(b);
217         street.setEditable(b);
218         city.setEditable(b);
219         state.setEditable(b);
220         postcode.setEditable(b);
221         country.setEditable(b);
222         company.setEditable(b);
223         position.setEditable(b);
224         department.setEditable(b);
225         role.setEditable(b);
226         notes.setEditable(b);
227     }
228     
229     /** Sets the labels using the Lang resource bundle.
230     * Used when the user changes language thru preferences dialog.*/

231     public void setLang(){
232         int i=0;
233         if(showStatus){
234             setTitleAt(0,Lang.gs("status"));
235             i=1;
236         }
237         setTitleAt(i,Lang.gs("general"));
238         setTitleAt(i+1,Lang.gs("location"));
239         setTitleAt(i+2,Lang.gs("work"));
240         setTitleAt(i+3,Lang.gs("notes"));
241         if(showKeyPanel){
242             setTitleAt(i+4,Lang.gs("key"));
243         }
244         // general panel
245
fullNameLbl.setText(Lang.gs("form_name"));
246         nickNameLbl.setText(Lang.gs("form_nick"));
247         birthdayLbl.setText(Lang.gs("birthday"));
248         emailLbl.setText(Lang.gs("form_email"));
249         homepageLbl.setText(Lang.gs("form_url"));
250         phoneLbl.setText(Lang.gs("form_phone"));
251         // location panel
252
streetLbl.setText(Lang.gs("street"));
253         cityLbl.setText(Lang.gs("form_city"));
254         stateLbl.setText(Lang.gs("form_state"));
255         postcodeLbl.setText(Lang.gs("form_zip"));
256         countryLbl.setText(Lang.gs("form_country"));
257         //work panel
258
companyLbl.setText(Lang.gs("company"));
259         positionLbl.setText(Lang.gs("position"));
260         departmentLbl.setText(Lang.gs("department"));
261         roleLbl.setText(Lang.gs("role"));
262         // key panel
263
keyStatusLbl.setText("<html><p>"+Lang.gs(keyStatus)+"</p></html>");
264         if(!keyStatus.equals("key_none")){
265             keyInfoLbl.setText("<html>"+Lang.gs("key_date")+" "+keyDate+"<br>"+Lang.gs("key_fingerprint")+" "+keyFingerprint);
266         }
267     }
268 }
269
Popular Tags