1 18 19 package sync4j.syncclient.demo; 20 21 import java.awt.BorderLayout ; 22 import java.awt.Button ; 23 import java.awt.GridLayout ; 24 import java.awt.Label ; 25 import java.awt.List ; 26 import java.awt.Panel ; 27 28 import java.awt.event.ActionEvent ; 29 import java.awt.event.ActionListener ; 30 import java.awt.event.ItemEvent ; 31 import java.awt.event.ItemListener ; 32 import java.awt.event.MouseEvent ; 33 import java.awt.event.MouseListener ; 34 import sync4j.foundation.pdi.common.*; 35 36 43 public class ContactList 44 extends Panel 45 implements ActionListener , 46 ItemListener , 47 MouseListener , 48 ConfigurationParameters { 49 50 52 54 private static final int LIST_SCROLLBAR_WIDTH = 25; 59 60 private MainWindow mw = null ; 64 private List list = null ; 65 private Button butModify = null ; 66 private Button butDelete = null ; 67 private Button butNew = null ; 68 69 private Language ln = new Language() ; 70 71 73 78 public ContactList(MainWindow mw) { 79 80 Button butSync = null ; 81 Label title = null ; 82 83 Panel editButtonPanel = null ; 84 Panel buttonPanel = null ; 85 86 this.mw = mw; 87 88 setLayout(new BorderLayout ()); 89 title = new Label (ln.getString ("contact_list")); 90 91 list = new List (10); 92 list.addItemListener (this); 93 list.addMouseListener (this); 94 95 butNew = new Button (ln.getString ("new") ) ; 96 butNew.setActionCommand ("new" ) ; 97 butNew.addActionListener (this ) ; 98 99 butModify = new Button (ln.getString ("modify") ) ; 100 butModify.setActionCommand ("modify" ) ; 101 butModify.addActionListener (this ) ; 102 butModify.setEnabled (false ) ; 103 104 butDelete = new Button (ln.getString ("delete") ) ; 105 butDelete.setActionCommand ("delete" ) ; 106 butDelete.addActionListener (this ) ; 107 butDelete.setEnabled (false ) ; 108 109 butSync = new Button (ln.getString ("synchronize") ) ; 110 butSync.setActionCommand ("sync" ) ; 111 butSync.addActionListener (this ) ; 112 113 editButtonPanel = new Panel (); 114 editButtonPanel.setLayout(new GridLayout (1, 3)); 115 editButtonPanel.add(butNew); 116 editButtonPanel.add(butModify); 117 editButtonPanel.add(butDelete); 118 119 buttonPanel = new Panel (); 120 buttonPanel.setLayout(new GridLayout (2, 1)); 121 buttonPanel.add(editButtonPanel); 122 buttonPanel.add(butSync); 123 124 add(title,BorderLayout.NORTH); 125 add(list,BorderLayout.CENTER); 126 add(buttonPanel,BorderLayout.SOUTH); 127 } 128 129 134 public void actionPerformed(ActionEvent evt) { 135 if (evt.getActionCommand().equals("sync")) { 136 mw.show(KEY_SYNC); 137 } 138 else if (evt.getActionCommand().equals("modify") ) { 139 mw.show(KEY_CONTACTMODIFY); 140 } 141 else if (evt.getActionCommand().equals("delete") ) { 142 mw.deleteContact(); 143 } 144 else if (evt.getActionCommand().equals("new" ) ) { 145 mw.show(KEY_CONTACTNEW); 146 } 147 } 148 149 156 public void itemStateChanged(ItemEvent evt) { 157 mw.setCurrentIndex((Integer ) evt.getItem()); 158 butModify.setEnabled(true); 159 butDelete.setEnabled(true); 160 } 161 162 171 public void mouseClicked(MouseEvent evt) { 172 if (evt.getClickCount()>=2) { 173 if (butModify.isEnabled() && 174 evt.getX()<=(getSize().width - LIST_SCROLLBAR_WIDTH) && 175 evt.getY() <= (mw.contacts.size() * list.getPreferredSize().height / 10)) { 176 mw.show(KEY_CONTACTMODIFY); 177 } 178 } 179 } 180 181 187 public void mousePressed(MouseEvent evt) { 188 } 190 191 197 public void mouseReleased(MouseEvent evt) { 198 } 200 201 207 public void mouseEntered(MouseEvent evt) { 208 } 210 211 217 public void mouseExited(MouseEvent evt) { 218 } 220 221 223 227 protected void fillList() { 228 229 String tmpDisplayName = null; 230 DemoContact tmpContact = null; 231 232 list.removeAll(); 233 234 for (int i=0, l = mw.contacts.size(); i < l; i++) { 235 tmpContact = (DemoContact) mw.contacts.elementAt(i); 236 tmpDisplayName = (String ) tmpContact.getContact().getName(). 237 getDisplayName().getPropertyValue(); 238 if (tmpDisplayName!=null && !tmpDisplayName.equals("")) { 239 list.add(tmpDisplayName); 240 } 241 else { 242 243 String display_name = ""; 244 245 if (tmpContact.getContact().getName(). 246 getLastName().getPropertyValue() != null 247 && !((String )tmpContact.getContact().getName(). 248 getLastName().getPropertyValue()).trim().equals("")) { 249 250 display_name += (String )tmpContact.getContact(). 251 getName().getLastName().getPropertyValue(); 252 } 253 254 if (tmpContact.getContact().getName(). 255 getFirstName().getPropertyValue() != null 256 && !((String )tmpContact.getContact().getName(). 257 getFirstName().getPropertyValue()).trim().equals("")) { 258 259 if (!display_name.equals("")) { 260 display_name += ","; 261 } 262 263 display_name += (String )tmpContact.getContact().getName(). 264 getFirstName().getPropertyValue(); 265 266 } 267 268 if (display_name.equals("")) { 269 display_name = "Unknow"; 270 } 271 272 tmpContact.getContact().getName().getDisplayName(). 273 setPropertyValue(display_name); 274 275 276 list.add(display_name); 277 } 278 } 279 280 butModify.setEnabled (false) ; 284 butDelete.setEnabled (false) ; 285 } 286 287 289 } | Popular Tags |