Statistics
| Revision:

root / trunk / libraries / libUI / src / org / gvsig / gui / beans / textBoxWithCalendar / JCalendarCDatePanel.java @ 7891

History | View | Annotate | Download (5.3 KB)

1
package org.gvsig.gui.beans.textBoxWithCalendar;
2

    
3
import java.awt.BorderLayout;
4
import java.awt.Color;
5
import java.awt.Dimension;
6

    
7
import javax.swing.JPanel;
8

    
9
import org.freixas.jcalendar.*;
10

    
11
import com.iver.andami.PluginServices;
12

    
13
import java.text.SimpleDateFormat;
14
import java.util.Calendar;
15
import java.util.Date;
16
import java.util.Locale;
17

    
18
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
19
 *
20
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
21
 *
22
 * This program is free software; you can redistribute it and/or
23
 * modify it under the terms of the GNU General Public License
24
 * as published by the Free Software Foundation; either version 2
25
 * of the License, or (at your option) any later version.
26
 *
27
 * This program is distributed in the hope that it will be useful,
28
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
30
 * GNU General Public License for more details.
31
 *
32
 * You should have received a copy of the GNU General Public License
33
 * along with this program; if not, write to the Free Software
34
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
35
 *
36
 * For more information, contact:
37
 *
38
 *  Generalitat Valenciana
39
 *   Conselleria d'Infraestructures i Transport
40
 *   Av. Blasco Ib??ez, 50
41
 *   46010 VALENCIA
42
 *   SPAIN
43
 *
44
 *      +34 963862235
45
 *   gvsig@gva.es
46
 *      www.gvsig.gva.es
47
 *
48
 *    or
49
 *
50
 *   IVER T.I. S.A
51
 *   Salamanca 50
52
 *   46005 Valencia
53
 *   Spain
54
 *
55
 *   +34 963163400
56
 *   dac@iver.es
57
 */
58

    
59
/**
60
 * Creates a Panel for include in other panels -> this panel allows users to set the date they want
61
 * The difference from this class to the JCalendarDatePanel is that in this class the user can move
62
 *    the calendar with the mouse
63
 * 
64
 * @author Pablo Piqueras Bartolom? (p_queras@hotmail.com)
65
 */
66
public class JCalendarCDatePanel extends JPanel implements java.io.Serializable{
67
        private static final long serialVersionUID = 8509184989434648171L;
68
        private int defaultWidth = 120;
69
        private int defaultHeight = 19;
70
        private JCalendarCombo calendar = null;
71
        
72
        /**
73
         * This is the default constructor: creates the panel with a JCalendar object
74
         */
75
        public JCalendarCDatePanel() {
76
                        
77
                try
78
                {
79
                        // Set properties to the current panel
80
                        this.setPreferredSize(new Dimension(defaultWidth, defaultHeight));
81
                        this.setLayout(new BorderLayout());
82
                        
83
                    // Adds the JCalendar to the current panel
84
                    this.add(this.getJCalendarCombo());
85
                }
86
                catch(Exception e)
87
                {
88
                        e.printStackTrace();
89
                }
90
        }
91
        
92
        /**
93
         * This is the default constructor with 2 parameters: creates the panel with a JCalendar object
94
         */
95
        public JCalendarCDatePanel(int width, int height) {
96
                        
97
                try
98
                {                        
99
                        defaultWidth = width;
100
                        defaultHeight = height;
101
                        
102
                        // Set properties to the current panel
103
                        this.setPreferredSize(new Dimension(defaultWidth, defaultHeight));
104
                        this.setLayout(new BorderLayout());                        
105
                    
106
                    // Adds the JCalendar to the current panel
107
                    this.add(this.getJCalendarCombo());
108
                }
109
                catch(Exception e)
110
                {
111
                        e.printStackTrace();
112
                }
113
        }
114

    
115
        /**
116
         * Returns a reference to the JCalendarCombo private attribute
117
         * 
118
         * @return A reference to the calendar
119
         */
120
        private JCalendarCombo getJCalendarCombo() {
121
                if (this.calendar == null) {
122
                        // Create a JCalendar
123
                        calendar = new JCalendarCombo(Calendar.getInstance(), Locale.getDefault(), JCalendarCombo.DISPLAY_DATE, true);
124
                        calendar.setDateFormat(new SimpleDateFormat("yyyy-MM-dd"));
125
                        calendar.setPreferredSize(new Dimension(defaultWidth, defaultHeight));
126
                    calendar.setEditable(false);                    
127
                    calendar.setBackground(Color.WHITE);
128
                    calendar.setToolTipText(PluginServices.getText(this, "calendarSelectDate"));
129
                    calendar.setToolTipTextToMonthDecrButton(PluginServices.getText(null, "calendarBackOneMonth"));
130
                    calendar.setToolTipTextToMonthIncrButton(PluginServices.getText(null, "calendarForwardOneMonth"));
131
                    calendar.setToolTipTextToYearDecrButton(PluginServices.getText(null, "calendarBackOneYear"));
132
                    calendar.setToolTipTextToYearIncrButton(PluginServices.getText(null, "calendarForwardOneYear"));
133
                }
134
                
135
                return this.calendar;
136
        }
137
        
138
        /**
139
         * Sets the size of the CalendarDatePanel for resize the JCalendarCommbo and this panel
140
         * 
141
         * @param width (the new Width for the panel)
142
         * @param height (the new Height for the panel)
143
         */
144
        public void setPreferredSizeResize(int width, int height)
145
        {
146
                defaultWidth = width;
147
                defaultHeight = height;
148
                this.setPreferredSize(new Dimension(defaultWidth, defaultHeight));
149
                calendar.setPreferredSize(new Dimension(defaultWidth, defaultHeight));                   
150
                calendar.setSize(new Dimension(defaultWidth, defaultHeight));
151
                this.revalidate();
152
        }
153
        
154
        /**
155
         * Get the height of this panel
156
         */
157
        public int getHeight()
158
        {
159
                return this.defaultHeight;
160
        }
161
        
162
        /**
163
         * Get the width of this panel
164
         */
165
        public int getWidth()
166
        {
167
                return this.defaultWidth;
168
        }
169
        
170
        /**
171
         * Sets the date to the calendar
172
         * 
173
         * @param date
174
         */
175
        public void setDate(Date date)
176
        {
177
                calendar.setDate(date);
178
        }
179
        
180
        /**
181
         * Gets the date of the calendar 
182
         * 
183
         * @return Date
184
         */
185
        public Date getDate()
186
        {
187
                return calendar.getDate();
188
        }
189
        
190
        /**
191
         * Allows select the date
192
         */
193
        public void enableCalendar()
194
        {
195
                calendar.setEnabled(true);
196
        }
197
        
198
        /**
199
         * Don't allow select the date
200
         */
201
        public void disableCalendar()
202
        {
203
                calendar.setEnabled(false);
204
        }
205
}