svn-gvsig-desktop / trunk / libraries / libUIComponent / src / org / gvsig / gui / beans / swing / textBoxWithCalendar / JCalendarCDatePanel.java @ 13191
History | View | Annotate | Download (5.29 KB)
1 |
package org.gvsig.gui.beans.swing.textBoxWithCalendar; |
---|---|
2 |
|
3 |
import java.awt.BorderLayout; |
4 |
import java.awt.Color; |
5 |
import java.awt.Dimension; |
6 |
import java.text.SimpleDateFormat; |
7 |
import java.util.Calendar; |
8 |
import java.util.Date; |
9 |
import java.util.Locale; |
10 |
|
11 |
import javax.swing.JPanel; |
12 |
|
13 |
import org.freixas.jcalendar.JCalendarCombo; |
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 Panel for include in other panels -> this panel allows users to set the date they want
|
59 |
* The difference from this class to the JCalendarDatePanel is that in this class the user can move
|
60 |
* the calendar with the mouse
|
61 |
*
|
62 |
* @author Pablo Piqueras Bartolom? (p_queras@hotmail.com)
|
63 |
*/
|
64 |
public class JCalendarCDatePanel extends JPanel implements IMethodsForGraphicalCalendarComponents, java.io.Serializable { |
65 |
private static final long serialVersionUID = 5913389251907361930L; |
66 |
private final int defaultWidth = 120; |
67 |
private final int defaultHeight = 19; |
68 |
private JCalendarCombo calendar = null; |
69 |
|
70 |
/**
|
71 |
* This is the default constructor: creates the panel with a JCalendar object
|
72 |
*/
|
73 |
public JCalendarCDatePanel() {
|
74 |
|
75 |
try
|
76 |
{ |
77 |
// Set properties to the current panel
|
78 |
this.setPreferredSize(new Dimension(defaultWidth, defaultHeight)); |
79 |
this.setLayout(new BorderLayout()); |
80 |
|
81 |
// Adds the JCalendar to the current panel
|
82 |
this.add(this.getJCalendarCombo()); |
83 |
} |
84 |
catch(Exception e) |
85 |
{ |
86 |
e.printStackTrace(); |
87 |
} |
88 |
} |
89 |
|
90 |
/**
|
91 |
* This is the default constructor with 2 parameters: creates the panel with a JCalendar object
|
92 |
*/
|
93 |
public JCalendarCDatePanel(int width, int height) { |
94 |
|
95 |
try {
|
96 |
|
97 |
// Set properties to the current panel
|
98 |
this.setPreferredSize(new Dimension(width, height)); |
99 |
this.setLayout(new BorderLayout()); |
100 |
|
101 |
// Adds the JCalendar to the current panel
|
102 |
this.add(this.getJCalendarCombo()); |
103 |
} |
104 |
catch(Exception e) |
105 |
{ |
106 |
e.printStackTrace(); |
107 |
} |
108 |
} |
109 |
|
110 |
/**
|
111 |
* Returns a reference to the JCalendarCombo private attribute
|
112 |
*
|
113 |
* @return A reference to the calendar
|
114 |
*/
|
115 |
private JCalendarCombo getJCalendarCombo() {
|
116 |
if (this.calendar == null) { |
117 |
// Create a JCalendar
|
118 |
calendar = new JCalendarCombo(Calendar.getInstance(), Locale.getDefault(), JCalendarCombo.DISPLAY_DATE, true); |
119 |
calendar.setDateFormat(new SimpleDateFormat("yyyy-MM-dd")); |
120 |
calendar.setEditable(false);
|
121 |
calendar.setBackground(Color.WHITE);
|
122 |
calendar.setToolTipText(Messages.getText("calendarSelectDate"));
|
123 |
calendar.setToolTipTextToMonthDecrButton(Messages.getText("calendarBackOneMonth"));
|
124 |
calendar.setToolTipTextToMonthIncrButton(Messages.getText("calendarForwardOneMonth"));
|
125 |
calendar.setToolTipTextToYearDecrButton(Messages.getText("calendarBackOneYear"));
|
126 |
calendar.setToolTipTextToYearIncrButton(Messages.getText("calendarForwardOneYear"));
|
127 |
} |
128 |
|
129 |
return this.calendar; |
130 |
} |
131 |
|
132 |
/**
|
133 |
* Sets the size of the CalendarDatePanel for resize the JCalendarCommbo and this panel
|
134 |
*
|
135 |
* @param width (the new Width for the panel)
|
136 |
* @param height (the new Height for the panel)
|
137 |
*/
|
138 |
public void setPreferredSizeResize(int width, int height) |
139 |
{ |
140 |
this.setPreferredSize(new Dimension(width, height)); |
141 |
calendar.setPreferredSize(new Dimension(width, height)); |
142 |
calendar.setSize(new Dimension(width, height)); |
143 |
this.revalidate();
|
144 |
} |
145 |
|
146 |
/*
|
147 |
* (non-Javadoc)
|
148 |
* @see org.gvsig.gui.beans.swing.textBoxWithCalendar.IMethodsForGraphicalCalendarComponents#setDate(java.util.Date)
|
149 |
*/
|
150 |
public void setDate(Date date) |
151 |
{ |
152 |
calendar.setDate(date); |
153 |
} |
154 |
|
155 |
/*
|
156 |
* (non-Javadoc)
|
157 |
* @see org.gvsig.gui.beans.swing.textBoxWithCalendar.IMethodsForGraphicalCalendarComponents#getDate()
|
158 |
*/
|
159 |
public Date getDate() |
160 |
{ |
161 |
return calendar.getDate();
|
162 |
} |
163 |
|
164 |
/**
|
165 |
* Allows select the date
|
166 |
*/
|
167 |
public void enableCalendar() |
168 |
{ |
169 |
calendar.setEnabled(true);
|
170 |
} |
171 |
|
172 |
/**
|
173 |
* Don't allow select the date
|
174 |
*/
|
175 |
public void disableCalendar() |
176 |
{ |
177 |
calendar.setEnabled(false);
|
178 |
} |
179 |
|
180 |
/*
|
181 |
* (non-Javadoc)
|
182 |
* @see org.gvsig.gui.beans.swing.textBoxWithCalendar.IMethodsForGraphicalCalendarComponents#getFormattedDate()
|
183 |
*/
|
184 |
public String getFormattedDate() { |
185 |
return new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()).format(this.getDate()); |
186 |
} |
187 |
} |