svn-gvsig-desktop / trunk / libraries / libUI / src / org / gvsig / gui / beans / textBoxWithCalendar / JCalendarDateDialog.java @ 9033
History | View | Annotate | Download (5.65 KB)
1 |
package org.gvsig.gui.beans.textBoxWithCalendar; |
---|---|
2 |
|
3 |
import java.awt.Dimension; |
4 |
import java.io.Serializable; |
5 |
import java.text.SimpleDateFormat; |
6 |
import java.util.Date; |
7 |
import java.util.Locale; |
8 |
|
9 |
import javax.swing.JDialog; |
10 |
|
11 |
import org.freixas.jcalendar.DateEvent; |
12 |
import org.freixas.jcalendar.DateListener; |
13 |
import org.freixas.jcalendar.JCalendar; |
14 |
import org.gvsig.gui.beans.Messages; |
15 |
|
16 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
17 |
*
|
18 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
19 |
*
|
20 |
* This program is free software; you can redistribute it and/or
|
21 |
* modify it under the terms of the GNU General Public License
|
22 |
* as published by the Free Software Foundation; either version 2
|
23 |
* of the License, or (at your option) any later version.
|
24 |
*
|
25 |
* This program is distributed in the hope that it will be useful,
|
26 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
27 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
28 |
* GNU General Public License for more details.
|
29 |
*
|
30 |
* You should have received a copy of the GNU General Public License
|
31 |
* along with this program; if not, write to the Free Software
|
32 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
33 |
*
|
34 |
* For more information, contact:
|
35 |
*
|
36 |
* Generalitat Valenciana
|
37 |
* Conselleria d'Infraestructures i Transport
|
38 |
* Av. Blasco Ib??ez, 50
|
39 |
* 46010 VALENCIA
|
40 |
* SPAIN
|
41 |
*
|
42 |
* +34 963862235
|
43 |
* gvsig@gva.es
|
44 |
* www.gvsig.gva.es
|
45 |
*
|
46 |
* or
|
47 |
*
|
48 |
* IVER T.I. S.A
|
49 |
* Salamanca 50
|
50 |
* 46005 Valencia
|
51 |
* Spain
|
52 |
*
|
53 |
* +34 963163400
|
54 |
* dac@iver.es
|
55 |
*/
|
56 |
|
57 |
/**
|
58 |
* Creates a Dialog that allows users to select the date they want
|
59 |
* This class is a version of JCalendarDatePanel
|
60 |
*
|
61 |
* @author Pablo Piqueras Bartolom? (p_queras@hotmail.com)
|
62 |
*/
|
63 |
public class JCalendarDateDialog extends JDialog implements Serializable{ |
64 |
private static final long serialVersionUID = 3254428202468985837L; |
65 |
private JCalendar jCalendar = null; |
66 |
private int defaultWidth = 120; |
67 |
private int defaultHeight = 19; |
68 |
|
69 |
/**
|
70 |
* Default Constructor
|
71 |
*/
|
72 |
public JCalendarDateDialog() {
|
73 |
super();
|
74 |
try
|
75 |
{ |
76 |
this.setSize(new Dimension(defaultWidth, defaultHeight)); |
77 |
this.initialize();
|
78 |
} |
79 |
catch(Exception e) |
80 |
{ |
81 |
e.printStackTrace(); |
82 |
} |
83 |
} |
84 |
|
85 |
/**
|
86 |
* This is the default constructor with 2 parameters for set the size
|
87 |
*/
|
88 |
public JCalendarDateDialog(int width, int height) { |
89 |
super();
|
90 |
try
|
91 |
{ |
92 |
defaultWidth = width; |
93 |
defaultHeight = height; |
94 |
|
95 |
this.setSize(new Dimension(defaultWidth, defaultHeight)); |
96 |
this.initialize();
|
97 |
} |
98 |
catch(Exception e) |
99 |
{ |
100 |
e.printStackTrace(); |
101 |
} |
102 |
} |
103 |
|
104 |
/**
|
105 |
* This method initializes this
|
106 |
*/
|
107 |
private void initialize() { |
108 |
this.setDefaultTitle();
|
109 |
|
110 |
// Adds the jCalendar to this dialog
|
111 |
this.getContentPane().add(this.getJCalendar()); |
112 |
} |
113 |
|
114 |
/**
|
115 |
* Sets the size of this panel
|
116 |
*
|
117 |
* @param width (the new Width for the panel)
|
118 |
* @param height (the new Height for the panel)
|
119 |
*/
|
120 |
public void setSizeResize(int width, int height) |
121 |
{ |
122 |
this.defaultWidth = width;
|
123 |
this.defaultHeight = height;
|
124 |
this.setSize(new Dimension(defaultWidth, defaultHeight)); |
125 |
getJCalendar().revalidate(); |
126 |
} |
127 |
|
128 |
/**
|
129 |
* Get the height of this panel
|
130 |
*/
|
131 |
public int getHeight() |
132 |
{ |
133 |
return this.defaultHeight; |
134 |
} |
135 |
|
136 |
/**
|
137 |
* Get the width of this panel
|
138 |
*/
|
139 |
public int getWidth() |
140 |
{ |
141 |
return this.defaultWidth; |
142 |
} |
143 |
|
144 |
/**
|
145 |
* This method initializes jCalendar
|
146 |
*
|
147 |
* @return javax.swing.JCalendar
|
148 |
*/
|
149 |
private JCalendar getJCalendar() {
|
150 |
if (jCalendar == null) { |
151 |
jCalendar = new JCalendar();
|
152 |
jCalendar.setToolTipText(Messages.getText("calendarSelectDate"));
|
153 |
|
154 |
try
|
155 |
{ |
156 |
jCalendar.setToolTipTextToMonthDecrButton(Messages.getText("calendarBackOneMonth"));
|
157 |
jCalendar.setToolTipTextToMonthIncrButton(Messages.getText("calendarForwardOneMonth"));
|
158 |
jCalendar.setToolTipTextToYearDecrButton(Messages.getText("calendarBackOneYear"));
|
159 |
jCalendar.setToolTipTextToYearIncrButton(Messages.getText("calendarForwardOneYear"));
|
160 |
|
161 |
// Adds a date listener calendar
|
162 |
jCalendar.addDateListener(new DateListener(){
|
163 |
/*
|
164 |
* (non-Javadoc)
|
165 |
* @see org.freixas.jcalendar.DateListener#dateChanged(org.freixas.jcalendar.DateEvent)
|
166 |
*/
|
167 |
public void dateChanged(DateEvent arg0) { |
168 |
hide(); |
169 |
} |
170 |
}); |
171 |
} |
172 |
catch(Exception e) |
173 |
{ |
174 |
e.printStackTrace(); |
175 |
} |
176 |
} |
177 |
return jCalendar;
|
178 |
} |
179 |
|
180 |
/**
|
181 |
* Gets the date of the calendar (default or last selected)
|
182 |
*
|
183 |
* @return Date
|
184 |
*/
|
185 |
public Date getDate() { |
186 |
return jCalendar.getDate();
|
187 |
} |
188 |
|
189 |
/**
|
190 |
* Sets the date to the calendar
|
191 |
*
|
192 |
* @param Date
|
193 |
*/
|
194 |
public void setDate(Date date) |
195 |
{ |
196 |
jCalendar.setDate(date); |
197 |
} |
198 |
|
199 |
/**
|
200 |
* Returns the date formatted
|
201 |
*
|
202 |
* @param Date
|
203 |
* @return String The formatted date
|
204 |
*/
|
205 |
private String getFormattedDate(Date d) { |
206 |
return new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()).format(d); |
207 |
} |
208 |
|
209 |
/**
|
210 |
* Returns the date selected, formatted
|
211 |
*
|
212 |
* @return String The formatted date
|
213 |
*/
|
214 |
public String getFormattedDate() { |
215 |
return new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()).format(this.getDate()); |
216 |
} |
217 |
|
218 |
/**
|
219 |
* Gets the title of the JDialog with the calendar component. The title is displayed in the JDialog's border.
|
220 |
*
|
221 |
* @return Title
|
222 |
*/
|
223 |
public String getTitle() { |
224 |
return super.getTitle(); |
225 |
} |
226 |
|
227 |
/**
|
228 |
* Sets the title of the JDialog with the calendar component.
|
229 |
*
|
230 |
* @param String
|
231 |
*/
|
232 |
public void setTitle(String title) { |
233 |
super.setTitle(title);
|
234 |
} |
235 |
|
236 |
/**
|
237 |
* Sets the default title of the JDialog with the calendar component.
|
238 |
*/
|
239 |
public void setDefaultTitle() { |
240 |
this.setTitle(Messages.getText("calendarTitle")); |
241 |
} |
242 |
|
243 |
/**
|
244 |
* @see java.awt.Dialog#setModal(boolean)
|
245 |
*/
|
246 |
public void setModal(boolean b) { |
247 |
super.setModal(b);
|
248 |
} |
249 |
} |