1 import javax.swing.*; 2 import javax.accessibility.Accessible ; 3 import java.awt.image.ImageObserver ; 4 import java.awt.*; 5 import java.io.Serializable ; 6 import org.jivesoftware.smack.util.StringUtils; 7 8 9 10 public final class JProfilePane extends JTabbedPane implements Accessible , ImageObserver , MenuContainer, Serializable , 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 keyStatus=new String ("key_none"); private String keyDate=new String (""); 60 private String keyFingerprint=new String (""); 61 private boolean showKeyPanel=true; private boolean showStatus=false; 64 65 public JProfilePane(){ 66 super(); 67 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 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 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.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 keyPanel.add(keyStatusLbl,BorderLayout.NORTH); 112 keyInfoLbl.setVerticalAlignment(TOP); 113 keyInfoLbl.setHorizontalAlignment(CENTER); 114 keyStatusLbl.setHorizontalAlignment(CENTER); 115 keyPanel.add(keyInfoLbl,BorderLayout.CENTER); 116 SpringUtilities.makeCompactGrid(generalPanel,6,2,GAP,GAP,GAP,GAP); 118 generalBox.add(generalPanel); 119 generalBox.add(Box.createGlue()); 120 general.add(generalBox); 121 SpringUtilities.makeCompactGrid(locationPanel,5,2,GAP,GAP,GAP,GAP); 123 locationBox.add(locationPanel); 124 locationBox.add(Box.createGlue()); 125 location.add(locationBox); 126 SpringUtilities.makeCompactGrid(workPanel,4,2,GAP,GAP,GAP,GAP); 128 workBox.add(workPanel); 129 workBox.add(Box.createGlue()); 130 work.add(workBox); 131 add(general); 133 add(location); 134 add(work); 135 add(notesPanel); 136 add(keyPanel); 137 setIconAt(4,Icons.UNLOCKED); 138 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 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 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 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 companyLbl.setText(Lang.gs("company")); 259 positionLbl.setText(Lang.gs("position")); 260 departmentLbl.setText(Lang.gs("department")); 261 roleLbl.setText(Lang.gs("role")); 262 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 |