1 18 19 package sync4j.syncclient.demo; 20 21 import java.awt.BorderLayout ; 22 import java.awt.CardLayout ; 23 import java.awt.GridLayout ; 24 import java.awt.Label ; 25 import java.awt.Panel ; 26 import java.awt.ScrollPane ; 27 import java.awt.TextField ; 28 import java.awt.event.ActionEvent ; 29 import java.awt.event.ActionListener ; 30 import java.awt.event.MouseEvent ; 31 import java.awt.event.MouseListener ; 32 33 import sync4j.foundation.pdi.event.Calendar; 34 35 42 public class CalendarForm extends Panel 43 implements ActionListener , MouseListener , ConfigurationParameters { 44 46 public static final int TF_COLUMNS = 10; 51 52 54 private MainWindow mw = null; 58 59 private Language ln = new Language(); 60 61 private TextField tf1 = null; 62 private TextField tf2 = null; 63 private TextField tf3 = null; 64 private TextField tf4 = null; 65 private TextField tf5 = null; 66 private TextField tf6 = null; 67 private TextField tf7 = null; 68 69 private CardLayout cardLayout = null; 70 private Panel fieldPanel = null; 71 private ScrollPane scrollGeneralPane = null; 72 73 public String getStartDate() { 75 return tf2.getText(); 76 } 77 public String getStartTime() { 78 return tf6.getText(); 79 } 80 public String getEndDate() { 81 return tf3.getText(); 82 } 83 public String getEndTime() { 84 return tf7.getText(); 85 } 86 87 92 public CalendarForm(MainWindow mw) { 93 94 this.mw = mw; 95 96 Panel generalPanel = new Panel (); 97 generalPanel.setLayout(new GridLayout (16, 2)); 98 99 Label lb1 = new Label (ln.getString("summary" )); 103 Label lb2 = new Label (ln.getString("start_date")); 104 Label lb3 = new Label (ln.getString("end_date" )); 105 Label lb4 = new Label (ln.getString("location" )); 106 107 Label lb5 = new Label (ln.getString("description")); 111 Label lb6 = new Label (ln.getString("start_time" )); 112 Label lb7 = new Label (ln.getString("end_time" )); 113 114 tf1 = new TextField (TF_COLUMNS); 115 tf2 = new TextField (TF_COLUMNS); 116 tf3 = new TextField (TF_COLUMNS); 117 tf4 = new TextField (TF_COLUMNS); 118 tf5 = new TextField (TF_COLUMNS); 119 tf6 = new TextField (TF_COLUMNS); 120 tf7 = new TextField (TF_COLUMNS); 121 122 tf1.addMouseListener(this); 123 tf2.addMouseListener(this); 124 tf3.addMouseListener(this); 125 tf4.addMouseListener(this); 126 tf5.addMouseListener(this); 127 tf6.addMouseListener(this); 128 tf7.addMouseListener(this); 129 130 generalPanel.add(lb1 ); 131 generalPanel.add(tf1 ); 132 generalPanel.add(lb2 ); 133 generalPanel.add(tf2 ); 134 generalPanel.add(lb6 ); 135 generalPanel.add(tf6 ); 136 generalPanel.add(lb3 ); 137 generalPanel.add(tf3 ); 138 generalPanel.add(lb7 ); 139 generalPanel.add(tf7 ); 140 generalPanel.add(lb4 ); 141 generalPanel.add(tf4 ); 142 generalPanel.add(lb5 ); 143 generalPanel.add(tf5 ); 144 generalPanel.add(new Label ()); 145 generalPanel.add(new Label ()); 146 generalPanel.add(new Label ()); 147 generalPanel.add(new Label ()); 148 generalPanel.add(new Label ()); 149 generalPanel.add(new Label ()); 150 generalPanel.add(new Label ()); 151 generalPanel.add(new Label ()); 152 generalPanel.add(new Label ()); 153 generalPanel.add(new Label ()); 154 generalPanel.add(new Label ()); 155 generalPanel.add(new Label ()); 156 generalPanel.add(new Label ()); 157 generalPanel.add(new Label ()); 158 generalPanel.add(new Label ()); 159 generalPanel.add(new Label ()); 160 generalPanel.add(new Label ()); 161 generalPanel.add(new Label ()); 162 163 scrollGeneralPane = new ScrollPane (ScrollPane.SCROLLBARS_AS_NEEDED); 164 scrollGeneralPane.add(generalPanel); 165 166 fieldPanel = new Panel (); 167 fieldPanel.setSize(100,100); 168 cardLayout = new CardLayout (); 169 fieldPanel.setLayout(cardLayout); 170 fieldPanel.add(scrollGeneralPane,"general"); 171 172 cardLayout.show(fieldPanel, "general"); 176 177 setLayout(new BorderLayout ()); 178 add(fieldPanel,BorderLayout.CENTER); 179 } 180 181 public void actionPerformed(ActionEvent evt) { 182 } 184 185 193 public void mouseClicked(MouseEvent evt) { 194 } 196 197 203 public void mousePressed(MouseEvent evt) { 204 } 206 207 213 public void mouseReleased(MouseEvent evt) { 214 } 216 217 223 public void mouseEntered(MouseEvent evt) { 224 } 226 227 233 public void mouseExited(MouseEvent evt) { 234 } 236 238 245 protected void setFields(Calendar calendar) { 246 247 String dateStart = null; 248 String dateEnd = null; 249 String timeStart = null; 250 String timeEnd = null; 251 252 dateStart = (String )calendar.getEvent().getDtStart().getPropertyValue(); 253 dateEnd = (String )calendar.getEvent().getDtEnd().getPropertyValue() ; 254 255 dateStart = FieldsHelper.convertDateFromUTC(dateStart); 256 if (dateStart != null && dateStart.length() > 10) { 257 timeStart = dateStart.substring(11,16); 258 dateStart = dateStart.substring(0,10); 259 } 260 261 dateEnd = FieldsHelper.convertDateFromUTC(dateEnd); 262 if (dateEnd != null && dateEnd.length() > 10) { 263 timeEnd = dateEnd.substring(11,16); 264 dateEnd = dateEnd.substring(0,10); 265 } 266 267 tf1.setText((String )calendar.getEvent() 269 .getSummary().getPropertyValue()); 270 tf2.setText(dateStart); 271 tf3.setText(dateEnd ); 272 tf4.setText((String )calendar.getEvent() 273 .getLocation().getPropertyValue()); 274 tf5.setText((String )calendar.getEvent() 275 .getDescription().getPropertyValue()); 276 tf6.setText(timeStart != null ? timeStart : ""); 277 tf7.setText(timeEnd != null ? timeEnd : ""); 278 } 279 280 287 protected Calendar getFields(){ 288 289 Calendar calendar = new Calendar(); 290 291 String fullStartDate = tf2.getText() + " " + tf6.getText() + ":00"; 292 String fullEndDate = tf3.getText() + " " + tf7.getText() + ":00"; 293 294 String startDate = FieldsHelper.convertDateToUTC(fullStartDate); 295 String endDate = FieldsHelper.convertDateToUTC(fullEndDate ); 296 297 calendar.getEvent().getSummary ().setPropertyValue(tf1.getText()); 298 calendar.getEvent().getDtStart ().setPropertyValue(startDate ); 299 calendar.getEvent().getDtEnd ().setPropertyValue(endDate ); 300 calendar.getEvent().getLocation ().setPropertyValue(tf4.getText()); 301 calendar.getEvent().getDescription().setPropertyValue(tf5.getText()); 302 303 return calendar; 304 } 305 306 309 protected void blankFields() { 310 tf1.setText (""); 311 tf2.setText (""); 312 tf3.setText (""); 313 tf4.setText (""); 314 tf5.setText (""); 315 tf6.setText (""); 316 tf7.setText (""); 317 } 318 } | Popular Tags |