svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.ui / src / test / java / org / gvsig / gui / beans / swing / textBoxWithCalendar / jCalendarUsingSamples / Example2.java @ 40561
History | View | Annotate | Download (5.65 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.gui.beans.swing.textBoxWithCalendar.jCalendarUsingSamples; |
25 |
|
26 |
|
27 |
//**********************************************************************
|
28 |
// Import list
|
29 |
//**********************************************************************
|
30 |
|
31 |
import java.awt.BorderLayout; |
32 |
import java.awt.Container; |
33 |
import java.awt.Font; |
34 |
import java.awt.GridLayout; |
35 |
import java.text.SimpleDateFormat; |
36 |
import java.util.Calendar; |
37 |
import java.util.Locale; |
38 |
|
39 |
import javax.swing.JFrame; |
40 |
import javax.swing.JPanel; |
41 |
|
42 |
import org.freixas.jcalendar.DateEvent; |
43 |
import org.freixas.jcalendar.DateListener; |
44 |
import org.freixas.jcalendar.JCalendarCombo; |
45 |
|
46 |
/**
|
47 |
* This example shows various instances of the JCalendarCombo class.
|
48 |
* <hr>
|
49 |
* This program is free software; you can redistribute it and/or
|
50 |
* modify it under the terms of the Artistic License. You should have
|
51 |
* received a copy of the Artistic License along with this program. If
|
52 |
* not, a copy is available at
|
53 |
* <a href="http://opensource.org/licenses/artistic-license.php">
|
54 |
* opensource.org</a>.
|
55 |
*
|
56 |
* @author Antonio Freixas
|
57 |
*/
|
58 |
|
59 |
// Copyright ? 2004 Antonio Freixas
|
60 |
// All Rights Reserved.
|
61 |
|
62 |
class Example2 extends JFrame { |
63 |
private static final long serialVersionUID = 1804829593564929253L; |
64 |
|
65 |
// **********************************************************************
|
66 |
// main
|
67 |
// **********************************************************************
|
68 |
|
69 |
public static void main(String[] args) { |
70 |
new Example2();
|
71 |
} |
72 |
|
73 |
// **********************************************************************
|
74 |
// Constructors
|
75 |
//**********************************************************************
|
76 |
|
77 |
/**
|
78 |
* Create various instances of a JCalendarCombo.
|
79 |
*/
|
80 |
|
81 |
public
|
82 |
Example2() |
83 |
{ |
84 |
// Set up the frame
|
85 |
|
86 |
setTitle("Example2");
|
87 |
setDefaultCloseOperation(EXIT_ON_CLOSE); |
88 |
|
89 |
Container contentPane = getContentPane();
|
90 |
contentPane.setLayout(new GridLayout(2, 2, 5, 5)); |
91 |
|
92 |
// Create a date listener to be used for all calendars
|
93 |
|
94 |
MyDateListener listener = new MyDateListener();
|
95 |
|
96 |
// Display date and time using the default calendar and locale.
|
97 |
// Display today's date at the bottom. Allow editing
|
98 |
|
99 |
JCalendarCombo calendar1 = |
100 |
new JCalendarCombo(
|
101 |
JCalendarCombo.DISPLAY_DATE | JCalendarCombo.DISPLAY_TIME, |
102 |
true);
|
103 |
calendar1.setEditable(true);
|
104 |
calendar1.addDateListener(listener); |
105 |
|
106 |
// Set fonts rather than using defaults
|
107 |
|
108 |
calendar1.setFont(new Font("DialogInput", Font.PLAIN, 16)); |
109 |
|
110 |
calendar1.setTitleFont(new Font("Serif", Font.BOLD|Font.ITALIC, 24)); |
111 |
calendar1.setDayOfWeekFont(new Font("SansSerif", Font.ITALIC, 12)); |
112 |
calendar1.setDayFont(new Font("SansSerif", Font.BOLD, 16)); |
113 |
calendar1.setTimeFont(new Font("DialogInput", Font.PLAIN, 10)); |
114 |
calendar1.setTodayFont(new Font("Dialog", Font.PLAIN, 14)); |
115 |
|
116 |
// Display date only
|
117 |
|
118 |
JCalendarCombo calendar2 = |
119 |
new JCalendarCombo(JCalendarCombo.DISPLAY_DATE, false); |
120 |
calendar2.addDateListener(listener); |
121 |
|
122 |
// Display time only and set the time pattern to use as a duration
|
123 |
// from 00:00 to 23:59
|
124 |
|
125 |
JCalendarCombo calendar3 = |
126 |
new JCalendarCombo(
|
127 |
Calendar.getInstance(),
|
128 |
Locale.getDefault(),
|
129 |
JCalendarCombo.DISPLAY_TIME, |
130 |
false,
|
131 |
"HH:mm:ss");
|
132 |
calendar3.setDateFormat(new SimpleDateFormat("HH:mm:ss")); |
133 |
calendar3.addDateListener(listener); |
134 |
|
135 |
// Display a French calendar
|
136 |
|
137 |
JCalendarCombo calendar4 = |
138 |
new JCalendarCombo(
|
139 |
Calendar.getInstance(Locale.FRENCH), |
140 |
Locale.FRENCH,
|
141 |
JCalendarCombo.DISPLAY_DATE | JCalendarCombo.DISPLAY_TIME, |
142 |
false);
|
143 |
calendar4.addDateListener(listener); |
144 |
|
145 |
// Add all the calendars to the content pane
|
146 |
|
147 |
JPanel panel1 = new JPanel(new BorderLayout()); |
148 |
panel1.add(calendar1, BorderLayout.NORTH);
|
149 |
contentPane.add(panel1); |
150 |
|
151 |
JPanel panel2 = new JPanel(new BorderLayout()); |
152 |
panel2.add(calendar2, BorderLayout.NORTH);
|
153 |
contentPane.add(panel2); |
154 |
|
155 |
JPanel panel3 = new JPanel(new BorderLayout()); |
156 |
panel3.add(calendar3, BorderLayout.NORTH);
|
157 |
contentPane.add(panel3); |
158 |
|
159 |
JPanel panel4 = new JPanel(new BorderLayout()); |
160 |
panel4.add(calendar4, BorderLayout.NORTH);
|
161 |
contentPane.add(panel4); |
162 |
|
163 |
// Make the window visible
|
164 |
|
165 |
pack(); |
166 |
setVisible(true);
|
167 |
} |
168 |
|
169 |
//**********************************************************************
|
170 |
// Inner Classes
|
171 |
//**********************************************************************
|
172 |
|
173 |
private class MyDateListener |
174 |
implements DateListener
|
175 |
{ |
176 |
|
177 |
public void |
178 |
dateChanged( |
179 |
DateEvent e) |
180 |
{ |
181 |
Calendar c = e.getSelectedDate();
|
182 |
if (c != null) { |
183 |
System.out.println(c.getTime());
|
184 |
} |
185 |
else {
|
186 |
System.out.println("No time selected."); |
187 |
} |
188 |
} |
189 |
|
190 |
} |
191 |
|
192 |
//**********************************************************************
|
193 |
// End Inner Classes
|
194 |
//**********************************************************************
|
195 |
|
196 |
} |