Revision 9780

View differences:

trunk/libraries/libUI/src/org/gvsig/gui/beans/textBoxWithCalendar/JCalendarDatePanel.java
6 6
import java.util.Locale;
7 7

  
8 8
import javax.swing.JButton;
9
import javax.swing.JDialog;
10 9
import javax.swing.JPanel;
11 10
import javax.swing.SwingConstants;
12 11

  
13
import org.freixas.jcalendar.DateEvent;
14
import org.freixas.jcalendar.DateListener;
15
import org.freixas.jcalendar.JCalendar;
16 12
import org.gvsig.gui.beans.Messages;
17 13

  
18 14
import java.awt.Color;
......
32 28
 * @author Pablo Piqueras Bartolom? (p_queras@hotmail.com)
33 29
 */
34 30
public class JCalendarDatePanel extends JPanel implements Serializable{
35
	private static final long serialVersionUID = 6851067300202797515L;
31
	private static final long serialVersionUID = -3708600032851165498L;
36 32
	private JButton jButton = null;
37
	private JCalendar jCalendar = null;
38
	private JDialog jDialogCalendar = null;
39
	private int defaultWidth = 120;
40
	private int defaultHeight = 19;
33
	private JCalendarDateDialog jDialogCalendar = null;
34
	private int currentButtonWidth = 120;
35
	private int currentButtonHeight = 19;
41 36
	private MouseListener mouseListener;	
42 37

  
43 38
	/**
......
47 42
	
48 43
		try
49 44
		{
50
			this.setPreferredSize(new Dimension(defaultWidth, defaultHeight));
45
			this.setPreferredSize(new Dimension(currentButtonWidth, currentButtonHeight));
51 46
			initialize();			
52 47
		}
53 48
		catch(Exception e)
......
63 58
			
64 59
		try
65 60
		{			
66
			defaultWidth = width;
67
			defaultHeight = height;
61
			currentButtonWidth = width;
62
			currentButtonHeight = height;
68 63
			
69
			this.setPreferredSize(new Dimension(defaultWidth, defaultHeight));
64
			this.setPreferredSize(new Dimension(currentButtonWidth, currentButtonHeight));
70 65
			initialize();			
71 66
		}
72 67
		catch(Exception e)
......
93 88
		gridBagConstraints.gridy = 0;
94 89
		gridBagConstraints.weightx = 1.0;
95 90
		gridBagConstraints.gridx = 0;
96
		
97
		// Create the JCalendar Object
98
		this.getJCalendar();
99
		
100
		// Create the JDialog Object
101
		this.getJDialogCalendar();
102 91

  
103 92
		// Add the JButton
104 93
		this.add(getJButton(), gridBagConstraints1);
......
109 98
		// Adds the mouseListener to the jTextField and the jButton
110 99
		jButton.addMouseListener(mouseListener);
111 100
	}
112

  
113 101
	
114 102
	/**
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)
103
	 * Gets the default height of this panel
119 104
	 */
120
	public void setPreferredSizeResize(int width, int height)
105
	public int getCurrentButtonHeight()
121 106
	{
122
		defaultWidth = width;
123
		defaultHeight = height;
124
		this.setPreferredSize(new Dimension(defaultWidth, defaultHeight));
125
		this.revalidate();
107
		return this.currentButtonHeight;
126 108
	}
127 109
	
128 110
	/**
129
	 * Get the height of this panel
111
	 * Gets the default width of this panel
130 112
	 */
131
	public int getHeight()
113
	public int getCurrentButtonWidth()
132 114
	{
133
		return this.defaultHeight;
115
		return this.currentButtonWidth;
134 116
	}
135
	
136
	/**
137
	 * Get the width of this panel
138
	 */
139
	public int getWidth()
140
	{
141
		return this.defaultWidth;
142
	}
143 117

  
144 118
	/**
145 119
	 * This method initializes jButton	
......
149 123
	private JButton getJButton() {
150 124
		if (jButton == null) {
151 125
			jButton = new JButton();
152
			jButton.setPreferredSize(new Dimension(defaultWidth, defaultHeight));
126
			jButton.setPreferredSize(new Dimension(currentButtonWidth, currentButtonHeight));
153 127
			jButton.setHorizontalTextPosition(SwingConstants.LEFT);
154 128
			jButton.setBackground(Color.WHITE);
155
			jButton.setText(this.getFormattedDate(jCalendar.getDate()));
129
			jButton.setText(this.getFormattedDate(this.getJCalendarDateDialog().getDate()));
156 130
		}
157 131
		return jButton;
158 132
	}
159 133
	
160 134
	/**
161
	 * This method initializes jCalendar	
162
	 * 	
163
	 * @return javax.swing.JCalendar	
164
	 */
165
	private JCalendar getJCalendar() {
166
		if (jCalendar == null) {
167
			jCalendar = new JCalendar();
168
			jCalendar.setToolTipText(Messages.getText("calendarSelectDate"));
169
			
170
			try
171
			{
172
				jCalendar.setToolTipTextToMonthDecrButton(Messages.getText("calendarBackOneMonth"));
173
				jCalendar.setToolTipTextToMonthIncrButton(Messages.getText("calendarForwardOneMonth"));
174
				jCalendar.setToolTipTextToYearDecrButton(Messages.getText("calendarBackOneYear"));
175
				jCalendar.setToolTipTextToYearIncrButton(Messages.getText("calendarForwardOneYear"));
176

  
177
				// Adds a date listener calendar
178
				jCalendar.addDateListener(new DateListener(){
179
					/*
180
					 *  (non-Javadoc)
181
					 * @see org.freixas.jcalendar.DateListener#dateChanged(org.freixas.jcalendar.DateEvent)
182
					 */
183
					public void dateChanged(DateEvent arg0) {
184
						// TODO Auto-generated method stub
185
						jButton.setText(getFormattedDate(arg0.getSelectedDate().getTime()));
186
						jDialogCalendar.hide();
187
					}				
188
				});
189
			}
190
			catch(Exception e)
191
			{
192
				e.printStackTrace();
193
			}
194
		}
195
		return jCalendar;
196
	}
197
	
198
	/**
199 135
	 * This method initializes jDialogCalendar	
200 136
	 * 	
201 137
	 * @return javax.swing.JDialog	
202 138
	 */
203
	private JDialog getJDialogCalendar() {
139
	public JCalendarDateDialog getJCalendarDateDialog() {
204 140
		if (jDialogCalendar == null) {
205
			jDialogCalendar = new JDialog();
206
			jDialogCalendar.setSize(jCalendar.getPreferredSize());
207
			this.setDefaultTitle();
208
			
209
			// Adds the jCalendar to this dialog
210
			jDialogCalendar.getContentPane().add(jCalendar);
141
			jDialogCalendar = new JCalendarDateDialog();
211 142
		}
212 143
		return jDialogCalendar;
213 144
	}
......
219 150
	 * @return Date
220 151
	 */
221 152
	public Date getDate() {		
222
		return jCalendar.getDate();
153
		return this.getJCalendarDateDialog().getDate();
223 154
	}
224 155
	
225 156
	/**
......
229 160
	 */
230 161
	public void setDate(Date date)
231 162
	{
232
		jCalendar.setDate(date);
163
		this.getJCalendarDateDialog().setDate(date);
233 164
	}
234 165
	
235 166
	/**
......
270 201
	 * @return Title
271 202
	 */
272 203
	public String getTitle() {
273
		return this.jDialogCalendar.getTitle();
204
		return this.getJCalendarDateDialog().getTitle();
274 205
	}
275 206
		
276 207
	/**
......
279 210
	 * @param String
280 211
	 */
281 212
	public void setTitle(String title) {
282
		this.jDialogCalendar.setTitle(title);
213
		this.getJCalendarDateDialog().setTitle(title);
283 214
	}
284 215

  
285 216
	/**
286 217
	 * Sets the default title of the JDialog with the calendar component.
287 218
	 */
288 219
	public void setDefaultTitle() {
289
		this.jDialogCalendar.setTitle(Messages.getText("calendarTitle"));
220
		this.getJCalendarDateDialog().setTitle(Messages.getText("calendarTitle"));
290 221
	}	
291 222
	
292 223
	/**
293 224
	 * @see java.awt.Dialog#setModal(boolean)
294 225
	 */
295 226
	public void setModal(boolean b) {
296
		jDialogCalendar.setModal(b);
227
		this.getJCalendarDateDialog().setModal(b);
297 228
	}
298 229
	
299 230
	/**
231
	 * Sets new size for the inner JButton
232
	 * 
233
	 * @param width (the new Width for the button)
234
	 * @param height (the new Height for the button)
235
	 */
236
	public void setSizeResizeJButton(int width, int height) {
237
		this.getJButton().setPreferredSize(new Dimension(width, height));
238
	}
239
	
240
	/**
300 241
	 * Adds a component listener for the inner JDialog that cointins the calendar interface
301 242
	 * 
302 243
	 * @param componentListener
303 244
	 */
304 245
	public void addComponentListenerForJDialogCalendar(ComponentListener componentListener) {
305
		jDialogCalendar.addComponentListener(componentListener);
246
		getJCalendarDateDialog().addComponentListener(componentListener);
306 247
	}	
307 248
	
308 249
	/**
......
322 263
				// Show the JDialog
323 264
				if (getJButton().isEnabled())
324 265
				{
325
					jDialogCalendar.setLocationRelativeTo(jButton);
326
					jDialogCalendar.show();
266
					getJCalendarDateDialog().setLocationRelativeTo(jButton);
267
					getJCalendarDateDialog().show();
327 268
				}				
328 269
			}	
329 270
		};

Also available in: Unified diff