svn-gvsig-desktop / trunk / libraries / libUIComponent / src-test-ui / org / gvsig / gui / beans / swing / textBoxWithCalendar / jCalendarUsingSamples / Example1.java @ 13655
History | View | Annotate | Download (4.98 KB)
1 |
//**********************************************************************
|
---|---|
2 |
// Package
|
3 |
//**********************************************************************
|
4 |
|
5 |
|
6 |
//**********************************************************************
|
7 |
// Import list
|
8 |
//**********************************************************************
|
9 |
package org.gvsig.gui.beans.swing.textBoxWithCalendar.jCalendarUsingSamples; |
10 |
|
11 |
import java.awt.Container; |
12 |
import java.awt.FlowLayout; |
13 |
import java.awt.Font; |
14 |
import java.awt.GridLayout; |
15 |
import java.util.Calendar; |
16 |
import java.util.Locale; |
17 |
|
18 |
import javax.swing.BorderFactory; |
19 |
import javax.swing.JFrame; |
20 |
import javax.swing.JPanel; |
21 |
import javax.swing.border.Border; |
22 |
|
23 |
import org.freixas.jcalendar.DateEvent; |
24 |
import org.freixas.jcalendar.DateListener; |
25 |
import org.freixas.jcalendar.JCalendar; |
26 |
|
27 |
/**
|
28 |
* This example shows various instances of the JCalendar class.
|
29 |
* <hr>
|
30 |
* This program is free software; you can redistribute it and/or
|
31 |
* modify it under the terms of the Artistic License. You should have
|
32 |
* received a copy of the Artistic License along with this program. If
|
33 |
* not, a copy is available at
|
34 |
* <a href="http://opensource.org/licenses/artistic-license.php">
|
35 |
* opensource.org</a>.
|
36 |
*
|
37 |
* @author Antonio Freixas
|
38 |
*/
|
39 |
|
40 |
// Copyright ? 2004 Antonio Freixas
|
41 |
// All Rights Reserved.
|
42 |
|
43 |
public class Example1 extends JFrame { |
44 |
private static final long serialVersionUID = -2655722904436980134L; |
45 |
|
46 |
// **********************************************************************
|
47 |
// main
|
48 |
// **********************************************************************
|
49 |
|
50 |
public static void main(String[] args) { |
51 |
new Example1();
|
52 |
} |
53 |
|
54 |
// **********************************************************************
|
55 |
// Constructors
|
56 |
//**********************************************************************
|
57 |
|
58 |
/**
|
59 |
* Create various instances of a JCalendar.
|
60 |
*/
|
61 |
|
62 |
public
|
63 |
Example1() |
64 |
{ |
65 |
// Set up the frame
|
66 |
|
67 |
setTitle("Example1");
|
68 |
setDefaultCloseOperation(EXIT_ON_CLOSE); |
69 |
|
70 |
Container contentPane = getContentPane();
|
71 |
contentPane.setLayout(new GridLayout(2, 2, 5, 5)); |
72 |
|
73 |
// Create a border for all calendars
|
74 |
|
75 |
Border etchedBorder =
|
76 |
BorderFactory.createEtchedBorder();
|
77 |
Border emptyBorder =
|
78 |
BorderFactory.createEmptyBorder(10, 10, 10, 10); |
79 |
Border compoundBorder =
|
80 |
BorderFactory.createCompoundBorder(etchedBorder, emptyBorder);
|
81 |
|
82 |
// Create a date listener to be used for all calendars
|
83 |
|
84 |
MyDateListener listener = new MyDateListener();
|
85 |
|
86 |
// Display date and time using the default calendar and locale.
|
87 |
// Display today's date at the bottom.
|
88 |
|
89 |
JCalendar calendar1 = |
90 |
new JCalendar(
|
91 |
JCalendar.DISPLAY_DATE | JCalendar.DISPLAY_TIME, |
92 |
true);
|
93 |
calendar1.addDateListener(listener); |
94 |
calendar1.setBorder(compoundBorder); |
95 |
|
96 |
// Set fonts rather than using defaults
|
97 |
|
98 |
calendar1.setTitleFont(new Font("Serif", Font.BOLD|Font.ITALIC, 24)); |
99 |
calendar1.setDayOfWeekFont(new Font("SansSerif", Font.ITALIC, 12)); |
100 |
calendar1.setDayFont(new Font("SansSerif", Font.BOLD, 16)); |
101 |
calendar1.setTimeFont(new Font("DialogInput", Font.PLAIN, 10)); |
102 |
calendar1.setTodayFont(new Font("Dialog", Font.PLAIN, 14)); |
103 |
|
104 |
// Display date only
|
105 |
|
106 |
JCalendar calendar2 = new JCalendar(JCalendar.DISPLAY_DATE, false); |
107 |
calendar2.addDateListener(listener); |
108 |
calendar2.setBorder(compoundBorder); |
109 |
|
110 |
// Display time only and set the time pattern to use as a duration
|
111 |
// from 00:00 to 23:59
|
112 |
|
113 |
JCalendar calendar3 = |
114 |
new JCalendar(
|
115 |
Calendar.getInstance(),
|
116 |
Locale.getDefault(),
|
117 |
JCalendar.DISPLAY_TIME, |
118 |
false,
|
119 |
"HH:mm");
|
120 |
calendar3.addDateListener(listener); |
121 |
calendar3.setBorder(compoundBorder); |
122 |
|
123 |
// Display a French calendar
|
124 |
|
125 |
JCalendar calendar4 = |
126 |
new JCalendar(
|
127 |
Calendar.getInstance(Locale.FRENCH), |
128 |
Locale.FRENCH,
|
129 |
JCalendar.DISPLAY_DATE | JCalendar.DISPLAY_TIME, |
130 |
false);
|
131 |
calendar4.addDateListener(listener); |
132 |
calendar4.setBorder(compoundBorder); |
133 |
|
134 |
// Add all the calendars to the content pane
|
135 |
|
136 |
JPanel panel1 = new JPanel(new FlowLayout()); |
137 |
panel1.add(calendar1); |
138 |
contentPane.add(panel1); |
139 |
|
140 |
JPanel panel2 = new JPanel(new FlowLayout()); |
141 |
panel2.add(calendar2); |
142 |
contentPane.add(panel2); |
143 |
|
144 |
JPanel panel3 = new JPanel(new FlowLayout()); |
145 |
panel3.add(calendar3); |
146 |
contentPane.add(panel3); |
147 |
|
148 |
JPanel panel4 = new JPanel(new FlowLayout()); |
149 |
panel4.add(calendar4); |
150 |
contentPane.add(panel4); |
151 |
|
152 |
// Make the window visible
|
153 |
|
154 |
pack(); |
155 |
setVisible(true);
|
156 |
} |
157 |
|
158 |
//**********************************************************************
|
159 |
// Inner Classes
|
160 |
//**********************************************************************
|
161 |
|
162 |
private class MyDateListener |
163 |
implements DateListener
|
164 |
{ |
165 |
|
166 |
public void |
167 |
dateChanged( |
168 |
DateEvent e) |
169 |
{ |
170 |
Calendar c = e.getSelectedDate();
|
171 |
if (c != null) { |
172 |
System.out.println(c.getTime());
|
173 |
} |
174 |
else {
|
175 |
System.out.println("No time selected."); |
176 |
} |
177 |
} |
178 |
|
179 |
} |
180 |
|
181 |
//**********************************************************************
|
182 |
// End Inner Classes
|
183 |
//**********************************************************************
|
184 |
|
185 |
} |