KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > applications > todolist > gui > TodolistItemDialog


1 /*
2  * Lucane - a collaborative platform
3  * Copyright (C) 2004 Jonathan Riboux <jonathan.riboux@wanadoo.Fr>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19
20 package org.lucane.applications.todolist.gui;
21
22 import java.awt.Dimension JavaDoc;
23 import java.awt.FlowLayout JavaDoc;
24 import java.awt.GridBagConstraints JavaDoc;
25 import java.awt.GridBagLayout JavaDoc;
26 import java.awt.Insets JavaDoc;
27 import java.awt.event.ActionEvent JavaDoc;
28 import java.awt.event.ActionListener JavaDoc;
29 import java.util.Date JavaDoc;
30
31 import javax.swing.JButton JavaDoc;
32 import javax.swing.JCheckBox JavaDoc;
33 import javax.swing.JComboBox JavaDoc;
34 import javax.swing.JLabel JavaDoc;
35 import javax.swing.JPanel JavaDoc;
36 import javax.swing.JTextField JavaDoc;
37
38 import org.lucane.applications.todolist.TodolistItem;
39 import org.lucane.client.Client;
40 import org.lucane.client.Plugin;
41 import org.lucane.client.widgets.DateTimePicker;
42 import org.lucane.client.widgets.HTMLEditor;
43 import org.lucane.client.widgets.ManagedWindow;
44
45 public class TodolistItemDialog extends ManagedWindow {
46     private JTextField JavaDoc jtfName;
47     private HTMLEditor htmledComment;
48     private JComboBox JavaDoc jcmbPriority;
49     private JCheckBox JavaDoc jcbComplete;
50     private JButton JavaDoc jbOk;
51     private JButton JavaDoc jbCancel;
52
53     private DateTimePicker dtpStart;
54     private DateTimePicker dtpEnd;
55     private JCheckBox JavaDoc jcbRealStart;
56     private JCheckBox JavaDoc jcbRealEnd;
57     private DateTimePicker dtpEstimatedStart;
58     private DateTimePicker dtpEstimatedEnd;
59     private JCheckBox JavaDoc jcbEstimatedDate;
60     
61     private MainFrame mainFrame;
62     private Plugin plugin;
63     
64     private int parentTodolistId;
65     private TodolistItem todolistItem;
66     
67     private boolean modify = false;
68     
69     public TodolistItemDialog (Plugin plugin, MainFrame mainFrame, int parentTodolistId) {
70         super(plugin, "");
71         this.plugin = plugin;
72         this.mainFrame = mainFrame;
73         this.parentTodolistId = parentTodolistId;
74         init();
75     }
76     
77     public TodolistItemDialog (Plugin plugin, MainFrame mainFrame, TodolistItem todolistItem) {
78         super(plugin, "");
79         this.plugin = plugin;
80         this.mainFrame = mainFrame;
81         this.todolistItem = todolistItem;
82         modify = true;
83         init();
84     }
85     
86     private void init() {
87         if (modify) {
88             setTitle(plugin.tr("TodoListItemDialog.modificationTitle"));
89         } else {
90             setTitle(plugin.tr("TodoListItemDialog.creationTitle"));
91         }
92         setPreferredSize(new Dimension JavaDoc(640, 480));
93         this.setName("TodolistItemDialog");
94         
95         jtfName = new JTextField JavaDoc();
96         htmledComment = new HTMLEditor();
97         jcmbPriority = new JComboBox JavaDoc(TodolistItem.getPriorityLabels());
98
99         dtpStart = new DateTimePicker();
100         dtpEnd = new DateTimePicker();
101         jcbRealStart = new JCheckBox JavaDoc();
102         jcbRealStart.addActionListener(new ActionListener JavaDoc() {
103             public void actionPerformed(ActionEvent JavaDoc e) {
104                 dtpStart.setEnabled(jcbRealStart.isSelected());
105                 jcbRealEnd.setEnabled(jcbRealStart.isSelected());
106                 dtpEnd.setEnabled(jcbRealStart.isSelected() && jcbRealEnd.isSelected());
107             }
108         });
109         jcbRealEnd = new JCheckBox JavaDoc();
110         jcbRealEnd.addActionListener(new ActionListener JavaDoc() {
111             public void actionPerformed(ActionEvent JavaDoc e) {
112                 dtpEnd.setEnabled(jcbRealEnd.isSelected());
113             }
114         });
115         dtpEstimatedStart = new DateTimePicker();
116         dtpEstimatedEnd = new DateTimePicker();
117         jcbEstimatedDate = new JCheckBox JavaDoc();
118         jcbEstimatedDate.addActionListener(new ActionListener JavaDoc() {
119             public void actionPerformed(ActionEvent JavaDoc e) {
120                 dtpEstimatedStart.setEnabled(jcbEstimatedDate.isSelected());
121                 dtpEstimatedEnd.setEnabled(jcbEstimatedDate.isSelected());
122             }
123         });
124         
125         jbOk = new JButton JavaDoc(plugin.tr("TodoListItemDialog.ok"));
126         this.jbOk.setIcon(Client.getImageIcon("ok.png"));
127         jbOk.addActionListener(new ActionListener JavaDoc() {
128             public void actionPerformed(ActionEvent JavaDoc arg0) {
129                 if (modify)
130                     mainFrame.modifyTodolistItem(
131                             todolistItem,
132                             new TodolistItem(
133                                     todolistItem.getId(),
134                                     todolistItem.getParentTodolistId(),
135                                     jtfName.getText(),
136                                     htmledComment.getText(),
137                                     jcmbPriority.getSelectedIndex(),
138                                     jcbComplete.isSelected(),
139                                     jcbRealStart.isSelected()?dtpStart.getDate():null,
140                                     jcbRealEnd.isSelected()?dtpEnd.getDate():null,
141                                     jcbEstimatedDate.isSelected()?dtpEstimatedStart.getDate():null,
142                                     jcbEstimatedDate.isSelected()?dtpEstimatedEnd.getDate():null));
143                 else
144                     mainFrame
145                             .addTodolistItem(new TodolistItem(
146                                     parentTodolistId,
147                                     jtfName.getText(),
148                                     htmledComment.getText(),
149                                     jcmbPriority.getSelectedIndex(),
150                                     jcbRealStart.isSelected()?dtpStart.getDate():null,
151                                     jcbRealEnd.isSelected()?dtpEnd.getDate():null,
152                                     jcbEstimatedDate.isSelected()?dtpEstimatedStart.getDate():null,
153                                     jcbEstimatedDate.isSelected()?dtpEstimatedEnd.getDate():null));
154                 hide();
155             }
156         });
157         jbCancel = new JButton JavaDoc(plugin.tr("TodoListItemDialog.cancel"));
158         this.jbCancel.setIcon(Client.getImageIcon("cancel.png"));
159         jbCancel.addActionListener(new ActionListener JavaDoc() {
160             public void actionPerformed(ActionEvent JavaDoc arg0) {
161                 hide();
162             }
163         });
164         
165         JPanel JavaDoc jpButtons = new JPanel JavaDoc(new FlowLayout JavaDoc(FlowLayout.RIGHT, 2, 2));
166         jpButtons.add(jbOk);
167         jpButtons.add(jbCancel);
168         
169         getContentPane().setLayout(new GridBagLayout JavaDoc());
170         GridBagConstraints JavaDoc c = new GridBagConstraints JavaDoc();
171         
172         c.insets=new Insets JavaDoc(2,2,2,2);
173         c.anchor=GridBagConstraints.NORTH;
174         c.fill=GridBagConstraints.HORIZONTAL;
175
176         c.gridwidth=1;
177         c.gridy=0;
178         c.gridx=0;
179         c.weightx=0;
180         c.weighty=0;
181         getContentPane().add(new JLabel JavaDoc(plugin.tr("TodoListItemDialog.name")), c);
182         c.gridwidth=2;
183         c.gridx=1;
184         c.weightx=1;
185         getContentPane().add(jtfName, c);
186
187         c.gridwidth=1;
188         c.gridy=1;
189         c.gridx=0;
190         c.weightx=0;
191         c.weighty=1;
192         getContentPane().add(new JLabel JavaDoc(plugin.tr("TodoListItemDialog.comment")), c);
193         c.fill=GridBagConstraints.BOTH;
194         c.gridwidth=2;
195         c.gridx=1;
196         c.weightx=1;
197         getContentPane().add(htmledComment, c);
198
199         c.gridwidth=1;
200         c.gridy=2;
201         c.gridx=0;
202         c.weightx=0;
203         c.weighty=0;
204         getContentPane().add(new JLabel JavaDoc(plugin.tr("TodoListItemDialog.priority")), c);
205         c.gridwidth=2;
206         c.gridx=1;
207         c.weightx=1;
208         getContentPane().add(jcmbPriority, c);
209
210         c.gridwidth=1;
211
212         c.gridy=3;
213         c.gridx=0;
214         c.weightx=0;
215         c.weighty=0;
216         getContentPane().add(new JLabel JavaDoc(plugin.tr("TodoListItemDialog.estimatedStart")), c);
217         c.gridx=1;
218         c.weightx=1;
219         getContentPane().add(dtpEstimatedStart, c);
220
221         c.gridy=4;
222         c.gridx=0;
223         c.weightx=0;
224         c.weighty=0;
225         getContentPane().add(new JLabel JavaDoc(plugin.tr("TodoListItemDialog.estimatedEnd")), c);
226         c.gridx=1;
227         c.weightx=1;
228         getContentPane().add(dtpEstimatedEnd, c);
229
230         c.gridy=3;
231         c.gridx=2;
232         c.weightx=0;
233         c.weighty=0;
234         c.gridheight=2;
235         getContentPane().add(jcbEstimatedDate, c);
236
237         c.gridy=5;
238         c.gridx=0;
239         c.weightx=0;
240         c.weighty=0;
241         c.gridheight=1;
242         getContentPane().add(new JLabel JavaDoc(plugin.tr("TodoListItemDialog.start")), c);
243         c.gridx=1;
244         c.weightx=1;
245         getContentPane().add(dtpStart, c);
246
247         c.gridy=6;
248         c.gridx=0;
249         c.weightx=0;
250         c.weighty=0;
251         c.gridheight=1;
252         getContentPane().add(new JLabel JavaDoc(plugin.tr("TodoListItemDialog.end")), c);
253         c.gridx=1;
254         c.weightx=1;
255         getContentPane().add(dtpEnd, c);
256
257         c.gridy=5;
258         c.gridx=2;
259         c.weightx=0;
260         c.weighty=0;
261         c.gridheight=1;
262         getContentPane().add(jcbRealStart, c);
263         c.gridy = 6;
264         getContentPane().add(jcbRealEnd, c);
265
266         c.fill=GridBagConstraints.BOTH;
267         c.gridy=50;
268         c.gridx=0;
269         c.weightx=1;
270         c.weighty=0;
271         c.gridwidth=3;
272         getContentPane().add(jpButtons, c);
273         
274         if (modify) {
275             jcbComplete = new JCheckBox JavaDoc();
276             c.gridy=10;
277             c.gridx=0;
278             c.weightx=0;
279             c.weighty=0;
280             getContentPane().add(new JLabel JavaDoc(plugin.tr("TodoListItemDialog.complete")), c);
281             c.gridx=1;
282             c.weightx=1;
283             getContentPane().add(jcbComplete, c);
284
285             jtfName.setText(todolistItem.getName());
286             htmledComment.setText(todolistItem.getComment());
287             jcmbPriority.setSelectedIndex(todolistItem.getPriority());
288             jcbComplete.setSelected(todolistItem.isCompleted());
289             
290             Date JavaDoc startDate = todolistItem.getStartDate();
291             if (startDate!=null)
292                 dtpStart.setDate(todolistItem.getStartDate());
293             
294             Date JavaDoc endDate = todolistItem.getEndDate();
295             if (endDate!=null)
296                 dtpEnd.setDate(todolistItem.getEndDate());
297             
298             Date JavaDoc estimatedStartDate = todolistItem.getEstimatedStartDate();
299             if (estimatedStartDate!=null)
300                 dtpEstimatedStart.setDate(todolistItem.getEstimatedStartDate());
301             
302             Date JavaDoc estimatedEndDate = todolistItem.getEstimatedEndDate();
303             if (estimatedEndDate!=null)
304                 dtpEstimatedEnd.setDate(todolistItem.getEstimatedEndDate());
305
306             jcbRealStart.setSelected(startDate!=null);
307             dtpStart.setEnabled(startDate!=null);
308             jcbRealEnd.setEnabled(jcbRealStart.isSelected());
309             jcbRealEnd.setSelected(endDate!=null);
310             dtpEnd.setEnabled(endDate!=null);
311
312
313             if (estimatedStartDate==null || estimatedEndDate==null){
314                 jcbEstimatedDate.setSelected(false);
315                 dtpEstimatedStart.setEnabled(false);
316                 dtpEstimatedEnd.setEnabled(false);
317             } else {
318                 jcbEstimatedDate.setSelected(true);
319                 dtpEstimatedStart.setEnabled(true);
320                 dtpEstimatedEnd.setEnabled(true);
321             }
322         } else {
323             jcbRealStart.setSelected(false);
324             jcbRealEnd.setEnabled(false);
325             jcbRealEnd.setSelected(false);
326             dtpStart.setEnabled(false);
327             dtpEnd.setEnabled(false);
328             jcbEstimatedDate.setSelected(false);
329             dtpEstimatedStart.setEnabled(false);
330             dtpEstimatedEnd.setEnabled(false);
331         }
332     }
333 }
334
Popular Tags