KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > core > gui > dialog > DateChooserDialog


1 //The contents of this file are subject to the Mozilla Public License Version 1.1
2
//(the "License"); you may not use this file except in compliance with the
3
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
4
//
5
//Software distributed under the License is distributed on an "AS IS" basis,
6
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
7
//for the specific language governing rights and
8
//limitations under the License.
9
//
10
//The Original Code is "The Columba Project"
11
//
12
//The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14
//
15
//All Rights Reserved.
16

17 package org.columba.core.gui.dialog;
18
19 import java.awt.BorderLayout JavaDoc;
20 import java.awt.Dialog JavaDoc;
21 import java.awt.GridLayout JavaDoc;
22 import java.awt.event.ActionEvent JavaDoc;
23 import java.awt.event.ActionListener JavaDoc;
24 import java.util.Calendar JavaDoc;
25 import java.util.Date JavaDoc;
26
27 import javax.swing.BorderFactory JavaDoc;
28 import javax.swing.JButton JavaDoc;
29 import javax.swing.JDialog JavaDoc;
30 import javax.swing.JPanel JavaDoc;
31
32 import org.columba.core.gui.base.ButtonWithMnemonic;
33 import org.columba.core.gui.base.DateChooser;
34 import org.columba.core.resourceloader.GlobalResourceLoader;
35
36 /**
37  * @author fdietz
38  */

39
40 public class DateChooserDialog extends JDialog JavaDoc implements ActionListener JavaDoc {
41     protected DateChooser dateChooser;
42
43     protected JButton JavaDoc okButton;
44     protected JButton JavaDoc cancelButton;
45     protected JPanel JavaDoc panel;
46
47     protected boolean success = false;
48
49     protected JDialog JavaDoc dialog;
50
51     public DateChooserDialog(JDialog JavaDoc parent) {
52         super(parent, true);
53
54         //TODO (@author fdietz): i18n
55
setTitle("Choose Date...");
56
57         dateChooser = new DateChooser();
58
59         panel = new JPanel JavaDoc();
60         panel.setLayout(new BorderLayout JavaDoc());
61
62         getContentPane().add(panel, BorderLayout.CENTER);
63
64         panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
65
66         panel.add(dateChooser, BorderLayout.CENTER);
67
68         JPanel JavaDoc bottomPanel = new JPanel JavaDoc();
69
70         /*
71          * bottomPanel.setBorder(new WizardTopBorder()); Border border =
72          * bottomPanel.getBorder(); Border margin =
73          * BorderFactory.createEmptyBorder(15, 10, 10, 10);
74          * bottomPanel.setBorder(new CompoundBorder(border, margin));
75          */

76         bottomPanel.setLayout(new BorderLayout JavaDoc());
77         bottomPanel.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0));
78
79         JPanel JavaDoc buttonPanel = new JPanel JavaDoc();
80         buttonPanel.setLayout(new GridLayout JavaDoc(1, 2, 10, 10));
81         bottomPanel.add(buttonPanel, BorderLayout.EAST);
82
83         cancelButton = new ButtonWithMnemonic(GlobalResourceLoader.getString(
84                 "global", "global", "cancel"));
85         cancelButton.setActionCommand("CANCEL");
86         cancelButton.addActionListener(this);
87         okButton = new ButtonWithMnemonic(GlobalResourceLoader.getString("global",
88                 "global", "ok"));
89         okButton.setActionCommand("OK");
90         okButton.addActionListener(this);
91
92         buttonPanel.add(cancelButton);
93         buttonPanel.add(okButton);
94
95         panel.add(bottomPanel, BorderLayout.SOUTH);
96
97         pack();
98
99
100         setLocationRelativeTo(null);
101     }
102
103     public Date JavaDoc getDate() {
104         return dateChooser.getSelectedDate().getTime();
105     }
106
107     public void setDate(Date JavaDoc d) {
108         Calendar JavaDoc c = Calendar.getInstance();
109         c.setTime(d);
110         dateChooser.setSelectedDate(c);
111     }
112
113     public boolean success() {
114         return success;
115     }
116
117     public void actionPerformed(ActionEvent JavaDoc ev) {
118         String JavaDoc action = ev.getActionCommand();
119
120         if (action.equals("OK")) {
121             success = true;
122             setVisible(false);
123         } else if (action.equals("CANCEL")) {
124             success = false;
125             setVisible(false);
126         }
127     }
128 }
129
Popular Tags