KickJava   Java API By Example, From Geeks To Geeks.

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


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
30 import javax.swing.JButton JavaDoc;
31 import javax.swing.JLabel JavaDoc;
32 import javax.swing.JPanel JavaDoc;
33 import javax.swing.JTextField JavaDoc;
34
35 import org.lucane.applications.todolist.Todolist;
36 import org.lucane.applications.todolist.io.IO;
37 import org.lucane.client.Client;
38 import org.lucane.client.Plugin;
39 import org.lucane.client.widgets.HTMLEditor;
40 import org.lucane.client.widgets.ManagedWindow;
41
42 public class TodolistDialog extends ManagedWindow {
43     private JTextField JavaDoc jtfName;
44     private HTMLEditor htmledComment;
45     private JButton JavaDoc jbOk;
46     private JButton JavaDoc jbCancel;
47     
48     private MainFrame mainFrame;
49     private Plugin plugin;
50     
51     private Todolist todolist;
52     
53     private boolean modify = false;
54     
55     public TodolistDialog (Plugin plugin, MainFrame mainFrame) {
56         super(plugin, "");
57         this.plugin = plugin;
58         this.mainFrame = mainFrame;
59         init();
60     }
61     
62     public TodolistDialog (Plugin plugin, MainFrame mainFrame, Todolist todolist) {
63         super(plugin, "");
64         this.plugin = plugin;
65         this.mainFrame = mainFrame;
66         this.todolist = todolist;
67         modify=true;
68         init();
69     }
70     
71     private void init() {
72         if (modify) {
73             setTitle(plugin.tr("TodoListDialog.modificationTitle"));
74         } else {
75             setTitle(plugin.tr("TodoListDialog.creationTitle"));
76         }
77         this.setName("TodolistDialog");
78         setPreferredSize(new Dimension JavaDoc(512, 384));
79         
80         jtfName = new JTextField JavaDoc();
81         htmledComment = new HTMLEditor();
82         
83         jbOk = new JButton JavaDoc(plugin.tr("TodoListDialog.ok"));
84         this.jbOk.setIcon(Client.getImageIcon("ok.png"));
85         jbOk.addActionListener(new ActionListener JavaDoc() {
86             public void actionPerformed(ActionEvent JavaDoc arg0) {
87                 if (modify)
88                     mainFrame.modifyTodolist(
89                             todolist,
90                             new Todolist(
91                                     todolist.getId(),
92                                     todolist.getUserName(),
93                                     jtfName.getText(),
94                                     htmledComment.getText()));
95                 else
96                     mainFrame.addTodolist(new Todolist(IO.getInstance(plugin).getUserName(), jtfName.getText(), htmledComment.getText()));
97                 hide();
98             }
99         });
100         jbCancel = new JButton JavaDoc(plugin.tr("TodoListDialog.cancel"));
101         this.jbCancel.setIcon(Client.getImageIcon("cancel.png"));
102         jbCancel.addActionListener(new ActionListener JavaDoc() {
103             public void actionPerformed(ActionEvent JavaDoc arg0) {
104                 hide();
105             }
106         });
107
108         JPanel JavaDoc jpButtons = new JPanel JavaDoc(new FlowLayout JavaDoc(FlowLayout.RIGHT, 2, 2));
109         jpButtons.add(jbOk);
110         jpButtons.add(jbCancel);
111         
112         getContentPane().setLayout(new GridBagLayout JavaDoc());
113         GridBagConstraints JavaDoc c = new GridBagConstraints JavaDoc();
114         
115         c.insets=new Insets JavaDoc(2,2,2,2);
116         c.anchor=GridBagConstraints.NORTH;
117         c.fill=GridBagConstraints.HORIZONTAL;
118         c.gridy=0;
119         c.gridx=0;
120         c.weightx=0;
121         c.weighty=0;
122         getContentPane().add(new JLabel JavaDoc(plugin.tr("TodoListDialog.name")), c);
123         c.gridx=1;
124         c.weightx=1;
125         getContentPane().add(jtfName, c);
126
127         c.gridy=1;
128         c.gridx=0;
129         c.weightx=0;
130         c.weighty=1;
131         getContentPane().add(new JLabel JavaDoc(plugin.tr("TodoListDialog.comment")), c);
132         c.fill=GridBagConstraints.BOTH;
133         c.gridx=1;
134         c.weightx=1;
135         getContentPane().add(htmledComment, c);
136
137         c.fill=GridBagConstraints.BOTH;
138         c.gridy=2;
139         c.gridx=0;
140         c.weightx=1;
141         c.weighty=0;
142         c.gridwidth=2;
143         getContentPane().add(jpButtons, c);
144         
145         if (modify) {
146             jtfName.setText(todolist.getName());
147             htmledComment.setText(todolist.getComment());
148         }
149     }
150 }
151
Popular Tags