001: // The contents of this file are subject to the Mozilla Public License Version
002: // 1.1
003: //(the "License"); you may not use this file except in compliance with the
004: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
005: //
006: //Software distributed under the License is distributed on an "AS IS" basis,
007: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
008: //for the specific language governing rights and
009: //limitations under the License.
010: //
011: //The Original Code is "The Columba Project"
012: //
013: //The Initial Developers of the Original Code are Frederik Dietz and Timo
014: // Stich.
015: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
016: //
017: //All Rights Reserved.
018: package org.columba.calendar.ui.dialog;
019:
020: import java.awt.BorderLayout;
021: import java.awt.GridLayout;
022: import java.awt.event.ActionEvent;
023: import java.awt.event.ActionListener;
024: import java.awt.event.KeyEvent;
025: import java.util.Calendar;
026:
027: import javax.swing.BorderFactory;
028: import javax.swing.JButton;
029: import javax.swing.JCheckBox;
030: import javax.swing.JComboBox;
031: import javax.swing.JComponent;
032: import javax.swing.JDialog;
033: import javax.swing.JFrame;
034: import javax.swing.JLabel;
035: import javax.swing.JPanel;
036: import javax.swing.JScrollPane;
037: import javax.swing.JTextArea;
038: import javax.swing.JTextField;
039: import javax.swing.KeyStroke;
040: import javax.swing.SwingConstants;
041:
042: import org.columba.calendar.base.CalendarItem;
043: import org.columba.calendar.model.api.IEventInfo;
044: import org.columba.calendar.model.api.IRecurrence;
045: import org.columba.calendar.ui.comp.CalendarPicker;
046: import org.columba.calendar.ui.comp.DatePicker;
047: import org.columba.calendar.ui.comp.TimePicker;
048: import org.columba.core.gui.base.ButtonWithMnemonic;
049: import org.columba.core.gui.base.SingleSideEtchedBorder;
050: import org.columba.core.gui.util.DialogHeaderPanel;
051: import org.columba.core.help.HelpManager;
052: import org.columba.core.resourceloader.IconKeys;
053: import org.columba.core.resourceloader.ImageLoader;
054: import org.columba.mail.util.MailResourceLoader;
055:
056: import com.jgoodies.forms.builder.PanelBuilder;
057: import com.jgoodies.forms.layout.CellConstraints;
058: import com.jgoodies.forms.layout.FormLayout;
059:
060: public class EditEventDialog extends JDialog implements ActionListener {
061:
062: JTextField summaryTextField = new JTextField();
063:
064: JTextField locationTextField = new JTextField();
065:
066: JTextArea descriptionTextArea = new JTextArea(3, 40);
067:
068: JComboBox classComboBox = new JComboBox();
069:
070: CalendarPicker calendarPicker = new CalendarPicker();
071:
072: JTextField categoriesTextField = new JTextField();
073:
074: JButton categoriesButton = new JButton();
075:
076: JCheckBox allDayCheckBox = new JCheckBox();
077:
078: TimePicker startTimePicker = new TimePicker();
079:
080: TimePicker endTimePicker = new TimePicker();
081:
082: JCheckBox alarmCheckBox = new JCheckBox();
083:
084: JComboBox alarmComboBox = new JComboBox();
085:
086: JButton alarmButton = new JButton();
087:
088: // click on this button will open the recurrence dialog
089: JButton recurrenceButton = new JButton();
090: JCheckBox recurrenceCheckBox = new JCheckBox();
091:
092: DatePicker startDayDatePicker;
093:
094: DatePicker endDayDatePicker;
095:
096: boolean success = false;
097:
098: private IEventInfo model;
099:
100: public EditEventDialog(JFrame parentFrame, IEventInfo model) {
101: super (parentFrame, true);
102:
103: this .model = model;
104:
105: startDayDatePicker = new DatePicker();
106:
107: endDayDatePicker = new DatePicker();
108:
109: alarmComboBox.addItem("15 minutes before");
110: alarmComboBox.addItem("1 hour before");
111: alarmComboBox.addItem("1 day before");
112:
113: classComboBox.addItem("Private");
114: classComboBox.addItem("Public");
115: classComboBox.addItem("Confidential");
116:
117: descriptionTextArea.setEnabled(true);
118: categoriesButton.setEnabled(false);
119: categoriesTextField.setEnabled(false);
120: allDayCheckBox.setEnabled(true);
121: classComboBox.setEnabled(false);
122:
123: categoriesButton.setEnabled(false);
124: alarmButton.setEnabled(false);
125: alarmCheckBox.setEnabled(false);
126: alarmComboBox.setEnabled(false);
127: recurrenceButton.setEnabled(false);
128:
129: setLayout(new BorderLayout());
130: getContentPane().add(
131: new DialogHeaderPanel("New Appointment",
132: "Edit Appointment Properties", ImageLoader
133: .getIcon(IconKeys.USER)),
134: BorderLayout.NORTH);
135: getContentPane().add(createPanel(), BorderLayout.CENTER);
136: getContentPane().add(createButtonPanel(), BorderLayout.SOUTH);
137:
138: getRootPane().registerKeyboardAction(this , "CANCEL",
139: KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
140: JComponent.WHEN_IN_FOCUSED_WINDOW);
141:
142: updateComponents(true);
143:
144: pack();
145: setLocationRelativeTo(null);
146: setVisible(true);
147:
148: }
149:
150: private JPanel createButtonPanel() {
151: JPanel bottom = new JPanel();
152: bottom.setLayout(new BorderLayout());
153: bottom
154: .setBorder(new SingleSideEtchedBorder(
155: SwingConstants.TOP));
156:
157: ButtonWithMnemonic cancelButton = new ButtonWithMnemonic(
158: MailResourceLoader.getString("global", "cancel"));
159:
160: //$NON-NLS-1$ //$NON-NLS-2$
161: cancelButton.addActionListener(this );
162: cancelButton.setActionCommand("CANCEL"); //$NON-NLS-1$
163:
164: ButtonWithMnemonic okButton = new ButtonWithMnemonic(
165: MailResourceLoader.getString("global", "ok"));
166:
167: //$NON-NLS-1$ //$NON-NLS-2$
168: okButton.addActionListener(this );
169: okButton.setActionCommand("OK"); //$NON-NLS-1$
170: okButton.setDefaultCapable(true);
171: getRootPane().setDefaultButton(okButton);
172:
173: ButtonWithMnemonic helpButton = new ButtonWithMnemonic(
174: MailResourceLoader.getString("global", "help"));
175:
176: // associate with JavaHelp
177: HelpManager.getInstance().enableHelpOnButton(helpButton,
178: "configuring_columba");
179:
180: JPanel buttonPanel = new JPanel();
181: buttonPanel.setBorder(BorderFactory.createEmptyBorder(12, 12,
182: 12, 12));
183: buttonPanel.setLayout(new GridLayout(1, 3, 6, 0));
184: buttonPanel.add(okButton);
185: buttonPanel.add(cancelButton);
186: buttonPanel.add(helpButton);
187:
188: bottom.add(buttonPanel, BorderLayout.EAST);
189:
190: return bottom;
191: }
192:
193: private JPanel createPanel() {
194: JPanel jpanel1 = new JPanel();
195: FormLayout formlayout1 = new FormLayout(
196: "FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:GROW(1.0),FILL:DEFAULT:NONE,FILL:DEFAULT:NONE",
197: "3dlu,CENTER:DEFAULT:NONE,3dlu,FILL:DEFAULT:GROW(1.0),6dlu,CENTER:DEFAULT:NONE,3dlu,CENTER:DEFAULT:NONE,3dlu");
198: CellConstraints cc = new CellConstraints();
199: jpanel1.setLayout(formlayout1);
200:
201: PanelBuilder b = new PanelBuilder(formlayout1);
202: b.setDefaultDialogBorder();
203:
204: b.addSeparator("General Information", cc.xywh(2, 2, 2, 1));
205:
206: b.add(createPanel1(), cc.xy(3, 4));
207:
208: b.addSeparator("Date and Time", cc.xywh(2, 6, 2, 1));
209:
210: b.add(createPanel2(), cc.xy(3, 8));
211:
212: return b.getPanel();
213: }
214:
215: private JPanel createPanel1() {
216: JPanel jpanel1 = new JPanel();
217: FormLayout formlayout1 = new FormLayout(
218: "3dlu,FILL:DEFAULT:NONE,3dlu,FILL:DEFAULT:GROW(1.0),3dlu,FILL:DEFAULT:NONE,3dlu,FILL:DEFAULT:NONE",
219: "3dlu,CENTER:DEFAULT:NONE,3dlu,CENTER:DEFAULT:NONE,3dlu,CENTER:DEFAULT:NONE,3dlu,CENTER:DEFAULT:NONE,3dlu,FILL:DEFAULT:GROW(1.0)");
220: CellConstraints cc = new CellConstraints();
221: jpanel1.setLayout(formlayout1);
222:
223: JLabel jlabel1 = new JLabel();
224: jlabel1.setText("Summary:");
225: jpanel1.add(jlabel1, new CellConstraints(2, 2,
226: CellConstraints.RIGHT, CellConstraints.DEFAULT));
227:
228: JLabel jlabel2 = new JLabel();
229: jlabel2.setText("Location:");
230: jpanel1.add(jlabel2, new CellConstraints(2, 4,
231: CellConstraints.RIGHT, CellConstraints.DEFAULT));
232:
233: JLabel jlabel3 = new JLabel();
234: jlabel3.setText("Description:");
235: jpanel1.add(jlabel3, new CellConstraints(2, 10, 1, 1,
236: CellConstraints.DEFAULT, CellConstraints.TOP));
237:
238: JLabel jlabel4 = new JLabel();
239: jlabel4.setText("Class:");
240: jpanel1.add(jlabel4, new CellConstraints(2, 6,
241: CellConstraints.RIGHT, CellConstraints.DEFAULT));
242:
243: jpanel1.add(summaryTextField, cc.xywh(4, 2, 5, 1));
244:
245: jpanel1.add(locationTextField, cc.xywh(4, 4, 5, 1));
246:
247: JScrollPane jscrollpane1 = new JScrollPane();
248: jscrollpane1.setViewportView(descriptionTextArea);
249: jscrollpane1
250: .setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
251: jscrollpane1
252: .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
253: jpanel1.add(jscrollpane1, cc.xywh(4, 10, 5, 1));
254:
255: jpanel1.add(classComboBox, cc.xy(4, 6));
256:
257: JLabel jlabel5 = new JLabel();
258: jlabel5.setText("Calendar:");
259: jpanel1.add(jlabel5, new CellConstraints(6, 6,
260: CellConstraints.RIGHT, CellConstraints.DEFAULT));
261:
262: jpanel1.add(calendarPicker, cc.xy(8, 6));
263:
264: jpanel1.add(new JLabel("Categories:"), new CellConstraints(2,
265: 8, CellConstraints.RIGHT, CellConstraints.DEFAULT));
266:
267: jpanel1.add(categoriesTextField, cc.xywh(4, 8, 3, 1));
268:
269: categoriesButton.setActionCommand("Categories...");
270: categoriesButton.setText("Select ...");
271: jpanel1.add(categoriesButton, cc.xy(8, 8));
272:
273: return jpanel1;
274: }
275:
276: private JPanel createPanel2() {
277: JPanel jpanel1 = new JPanel();
278: FormLayout formlayout1 = new FormLayout(
279: "3dlu,FILL:DEFAULT:NONE,3dlu,FILL:DEFAULT:GROW(1.0),3dlu,FILL:DEFAULT:GROW(1.0),3dlu,FILL:DEFAULT:NONE",
280: "3dlu,FILL:DEFAULT:NONE,3dlu,FILL:DEFAULT:NONE,3dlu,FILL:DEFAULT:NONE,3dlu,FILL:DEFAULT:NONE,3dlu");
281: CellConstraints cc = new CellConstraints();
282: jpanel1.setLayout(formlayout1);
283:
284: JLabel jlabel1 = new JLabel();
285: jlabel1.setText("Start Time:");
286: jpanel1.add(jlabel1, new CellConstraints(2, 2, 1, 1,
287: CellConstraints.RIGHT, CellConstraints.DEFAULT));
288:
289: allDayCheckBox.setActionCommand("All Day");
290: allDayCheckBox.addActionListener(this );
291: allDayCheckBox.setText("All Day");
292: jpanel1.add(allDayCheckBox, cc.xy(8, 2));
293:
294: JLabel jlabel2 = new JLabel();
295: jlabel2.setText("End Time:");
296: jpanel1.add(jlabel2, new CellConstraints(2, 4, 1, 1,
297: CellConstraints.RIGHT, CellConstraints.DEFAULT));
298:
299: jpanel1.add(startDayDatePicker, cc.xy(4, 2));
300:
301: jpanel1.add(endDayDatePicker, cc.xy(4, 4));
302:
303: jpanel1.add(startTimePicker, cc.xy(6, 2));
304:
305: jpanel1.add(endTimePicker, cc.xy(6, 4));
306:
307: alarmCheckBox.setActionCommand("Alarm");
308: alarmCheckBox.setText("Alarm");
309: jpanel1.add(alarmCheckBox, new CellConstraints(2, 6, 1, 1,
310: CellConstraints.RIGHT, CellConstraints.DEFAULT));
311:
312: jpanel1.add(createPanel3(), cc.xywh(4, 6, 3, 1));
313:
314: recurrenceCheckBox.setText("Recurrence");
315: recurrenceCheckBox.setActionCommand("Recurrence");
316: recurrenceCheckBox.addActionListener(this );
317: jpanel1.add(recurrenceCheckBox, new CellConstraints(2, 8, 1, 1,
318: CellConstraints.RIGHT, CellConstraints.DEFAULT));
319:
320: jpanel1.add(createPanel4(), cc.xywh(4, 8, 3, 1));
321:
322: return jpanel1;
323: }
324:
325: private JPanel createPanel3() {
326: JPanel jpanel1 = new JPanel();
327: FormLayout formlayout1 = new FormLayout(
328: "FILL:DEFAULT:GROW(1.0),3dlu,FILL:DEFAULT:NONE",
329: "CENTER:DEFAULT:NONE");
330: CellConstraints cc = new CellConstraints();
331: jpanel1.setLayout(formlayout1);
332:
333: jpanel1.add(alarmComboBox, cc.xy(1, 1));
334:
335: alarmButton.setActionCommand("Customize...");
336: alarmButton.setText("Customize...");
337: jpanel1.add(alarmButton, cc.xy(3, 1));
338:
339: return jpanel1;
340: }
341:
342: private JPanel createPanel4() {
343: JPanel jpanel4 = new JPanel();
344:
345: FormLayout formlayout1 = new FormLayout(
346: "CENTER:DEFAULT:NONE,3dlu,FILL:DEFAULT:NONE",
347: "CENTER:DEFAULT:NONE");
348: CellConstraints cc = new CellConstraints();
349: jpanel4.setLayout(formlayout1);
350:
351: recurrenceButton.setActionCommand("RecurrenceDialog");
352: recurrenceButton.setText("Recurrence...");
353: recurrenceButton.addActionListener(this );
354:
355: jpanel4.add(recurrenceButton, cc.xy(1, 1));
356: return jpanel4;
357: }
358:
359: public boolean success() {
360: return success;
361: }
362:
363: public void updateComponents(boolean b) {
364: if (b) {
365: summaryTextField.setText(model.getEvent().getSummary());
366: locationTextField.setText(model.getEvent().getLocation());
367: categoriesTextField.setText(model.getEvent()
368: .getCategories());
369: descriptionTextArea.setText(model.getEvent()
370: .getDescription());
371:
372: if (model.getEvent().isAllDayEvent()) {
373: // disable time pickers
374: startTimePicker.setEnabled(false);
375: endTimePicker.setEnabled(false);
376: } else {
377: // enable time pickers
378: startTimePicker.setEnabled(true);
379: endTimePicker.setEnabled(true);
380: }
381:
382: Calendar start = model.getEvent().getDtStart();
383: startDayDatePicker.setDate(start);
384: startTimePicker.setTime(start.get(Calendar.HOUR_OF_DAY),
385: start.get(Calendar.MINUTE));
386: Calendar end = model.getEvent().getDtEnd();
387: endDayDatePicker.setDate(end);
388: endTimePicker.setTime(end.get(Calendar.HOUR_OF_DAY), end
389: .get(Calendar.MINUTE));
390:
391: allDayCheckBox
392: .setSelected(model.getEvent().isAllDayEvent());
393:
394: String calendar = model.getCalendar();
395: if (calendar != null)
396: calendarPicker.setSelectedItem(model.getCalendar());
397: else
398: calendarPicker.setSelectedIndex(0);
399:
400: if (model.getEvent().getRecurrence() != null
401: && model.getEvent().getRecurrence().getType() != IRecurrence.RECURRENCE_NONE) {
402: recurrenceCheckBox.setSelected(true);
403: recurrenceButton.setEnabled(true);
404: }
405:
406: categoriesTextField.setText(model.getEvent()
407: .getCategories());
408:
409: } else {
410: model.getEvent().setSummary(summaryTextField.getText());
411: model.getEvent().setLocation(locationTextField.getText());
412: model.getEvent().setCategories(
413: categoriesTextField.getText());
414: model.getEvent().setDescription(
415: descriptionTextArea.getText());
416:
417: Calendar start = startDayDatePicker.getDate();
418: Calendar end = endDayDatePicker.getDate();
419: int startHour = 0;
420: int startMinutes = 0;
421: int endHour = 0;
422: int endMinutes = 0;
423:
424: if (allDayCheckBox.isSelected()) {
425:
426: // disable time pickers
427: startTimePicker.setEnabled(false);
428: endTimePicker.setEnabled(false);
429:
430: startHour = 0;
431: startMinutes = 0;
432: start.set(Calendar.HOUR_OF_DAY, startHour);
433: start.set(Calendar.MINUTE, startMinutes);
434:
435: endHour = 0;
436: endMinutes = 0;
437: end.set(Calendar.HOUR_OF_DAY, endHour);
438: end.set(Calendar.MINUTE, endMinutes);
439:
440: } else {
441: // enable time pickers
442: startTimePicker.setEnabled(true);
443: endTimePicker.setEnabled(true);
444:
445: startHour = startTimePicker.getHour();
446: startMinutes = startTimePicker.getMinutes();
447: start.set(Calendar.HOUR_OF_DAY, startHour);
448: start.set(Calendar.MINUTE, startMinutes);
449:
450: endHour = endTimePicker.getHour();
451: endMinutes = endTimePicker.getMinutes();
452: end.set(Calendar.HOUR_OF_DAY, endHour);
453: end.set(Calendar.MINUTE, endMinutes);
454: }
455:
456: model.getEvent().setDtStart(start);
457:
458: model.getEvent()
459: .setAllDayEvent(allDayCheckBox.isSelected());
460:
461: model.getEvent().setDtEnd(end);
462:
463: CalendarItem calendar = (CalendarItem) calendarPicker
464: .getSelectedItem();
465: model.setCalendar(calendar.getId());
466:
467: // update modification timestamp
468: model.getEvent().setDtStamp(Calendar.getInstance());
469:
470: model.getEvent().setCategories(
471: categoriesTextField.getText());
472:
473: if (!recurrenceCheckBox.isSelected()) {
474: if (model.getEvent().getRecurrence() != null)
475: model.getEvent().setRecurrence(null);
476: }
477: }
478: }
479:
480: public void actionPerformed(ActionEvent e) {
481: String action = e.getActionCommand();
482:
483: if (action.equals("OK")) //$NON-NLS-1$
484: {
485: // check if the user entered valid data
486: success = true;
487:
488: updateComponents(false);
489:
490: setVisible(false);
491: } else if (action.equals("CANCEL")) {
492: success = false;
493: setVisible(false);
494: } else if (action.equals("All Day")) {
495: if (allDayCheckBox.isSelected()) {
496: // disable time pickers
497: startTimePicker.setEnabled(false);
498: endTimePicker.setEnabled(false);
499: } else {
500: // enable time pickers
501: startTimePicker.setEnabled(true);
502: endTimePicker.setEnabled(true);
503: }
504: } else if (action.equals("RecurrenceDialog")) {
505: RecurrenceDialog r = new RecurrenceDialog(null, model);
506: if (r.success()) {
507: model = r.getModel();
508: }
509: } else if (action.equals("Recurrence")) {
510: if (recurrenceCheckBox.isSelected()) {
511: // enable button
512: recurrenceButton.setEnabled(true);
513: } else {
514: // disable button
515: recurrenceButton.setEnabled(false);
516: }
517: }
518: }
519:
520: /**
521: * @return Returns the model.
522: */
523: public IEventInfo getModel() {
524: return model;
525: }
526:
527: }
|