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 import java.awt.event.ActionEvent ; 28 import java.awt.event.ActionListener ; 29 import java.awt.event.ItemEvent ; 30 import java.awt.event.ItemListener ; 31 import java.awt.event.MouseEvent ; 32 import java.awt.event.MouseListener ; 33 34 import sync4j.foundation.pdi.common.*; 35 36 42 public class CalendarList 43 extends Panel 44 implements ActionListener , 45 ItemListener , 46 MouseListener , 47 ConfigurationParameters { 48 49 51 private static final int LIST_SCROLLBAR_WIDTH = 25; 56 57 59 private MainWindow mw = null ; 63 private List list = null ; 64 private Button butModify = null ; 65 private Button butDelete = null ; 66 private Button butNew = null ; 67 68 private Language ln = new Language() ; 69 70 72 77 public CalendarList(MainWindow mw) { 78 79 Label title = null ; 80 Button butSync = null ; 81 82 Panel editButtonPanel = null ; 83 Panel buttonPanel = null ; 84 85 this.mw = mw; 86 87 setLayout(new BorderLayout ()); 88 title = new Label (ln.getString("calendar_list")); 89 list = new List (10 ); 90 list.addItemListener (this ) ; 91 list.addMouseListener (this ) ; 92 93 butNew = new Button (ln.getString ("new") ) ; 94 butNew.setActionCommand ("new" ) ; 95 butNew.addActionListener (this ) ; 96 97 butModify = new Button (ln.getString ("modify") ) ; 98 butModify.setActionCommand ("modify" ) ; 99 butModify.addActionListener (this ) ; 100 butModify.setEnabled (false ) ; 101 102 butDelete = new Button (ln.getString ("delete") ) ; 103 butDelete.setActionCommand ("delete" ) ; 104 butDelete.addActionListener (this ) ; 105 butDelete.setEnabled (false ) ; 106 107 butSync = new Button (ln.getString ("synchronize") ); 108 butSync.setActionCommand ("sync" ) ; 109 butSync.addActionListener (this ) ; 110 111 editButtonPanel = new Panel (); 112 editButtonPanel.setLayout(new GridLayout (1,3)); 113 editButtonPanel.add (butNew ) ; 114 editButtonPanel.add (butModify ) ; 115 editButtonPanel.add (butDelete ) ; 116 117 buttonPanel = new Panel (); 118 buttonPanel.setLayout(new GridLayout (2,1)); 119 buttonPanel.add (editButtonPanel ) ; 120 buttonPanel.add (butSync ) ; 121 122 add(title , BorderLayout.NORTH ) ; 123 add(list , BorderLayout.CENTER ) ; 124 add(buttonPanel , BorderLayout.SOUTH ) ; 125 } 126 127 132 public void actionPerformed(ActionEvent evt) { 133 134 if (evt.getActionCommand().equals("sync") ) { 135 mw.show(KEY_SYNC); 136 } else if (evt.getActionCommand().equals("modify") ) { 137 mw.show(KEY_CALENDARMODIFY); 138 } else if (evt.getActionCommand().equals("delete") ) { 139 mw.deleteCalendar(); 140 } else if (evt.getActionCommand().equals("new") ) { 141 mw.show(KEY_CALENDARNEW); 142 } 143 } 144 145 153 public void itemStateChanged(ItemEvent evt) { 154 mw.setCurrentIndex((Integer ) evt.getItem()); 155 butModify.setEnabled(true); 156 butDelete.setEnabled(true); 157 } 158 159 168 public void mouseClicked(MouseEvent evt) { 169 if (evt.getClickCount()>=2) { 170 if (butModify.isEnabled() && 171 evt.getX()<=(getSize().width - LIST_SCROLLBAR_WIDTH) && 172 evt.getY() <= (mw.calendars.size() * list.getPreferredSize().height / 10)) { 173 mw.show(KEY_CALENDARMODIFY); 174 } 175 } 176 } 177 178 184 public void mousePressed(MouseEvent evt) { 185 } 187 188 194 public void mouseReleased(MouseEvent evt) { 195 } 197 198 204 public void mouseEntered(MouseEvent evt) { 205 } 207 208 214 public void mouseExited(MouseEvent evt) { 215 } 217 218 220 224 protected void fillList() { 225 list.removeAll(); 226 227 String tmpDisplayName = null ; 228 String tmpDescription = null ; 229 DemoCalendar tmpCalendar = null ; 230 231 for (int i=0, l = mw.calendars.size(); i < l; i++) { 232 tmpCalendar = (DemoCalendar) mw.calendars.elementAt(i); 233 tmpDisplayName = (String ) tmpCalendar.getCalendar(). 234 getEvent().getSummary().getPropertyValue(); 235 236 tmpDescription = (String ) tmpCalendar.getCalendar(). 237 getEvent().getDescription().getPropertyValue(); 238 239 if (tmpDisplayName != null && !tmpDisplayName.equals ("")) { 240 list.add(tmpDisplayName); 241 } else if (tmpDescription != null && !tmpDescription.equals ("")) { 242 list.add(tmpDescription); 243 } else { 244 245 tmpDisplayName = "Unknow"; 246 list.add(tmpDisplayName); 247 } 248 } 249 250 butModify.setEnabled(false); 254 butDelete.setEnabled(false); 255 } 256 257 259 } | Popular Tags |