Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libUIComponent / src-test-ui / org / gvsig / gui / beans / swing / textBoxWithCalendar / jCalendarUsingSamples / Example1.java @ 13191

History | View | Annotate | Download (4.92 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
44
    extends JFrame
45
{
46

    
47
//**********************************************************************
48
// main
49
//**********************************************************************
50

    
51
public static void
52
main(
53
    String[] args)
54
{
55
    new Example1();
56
}
57

    
58
//**********************************************************************
59
// Constructors
60
//**********************************************************************
61

    
62
/**
63
 * Create various instances of a JCalendar.
64
 */
65

    
66
public
67
Example1()
68
{
69
    // Set up the frame
70

    
71
    setTitle("Example1");
72
    setDefaultCloseOperation(EXIT_ON_CLOSE);
73

    
74
    Container contentPane = getContentPane();
75
    contentPane.setLayout(new GridLayout(2, 2, 5, 5));
76

    
77
    // Create a border for all calendars
78

    
79
    Border etchedBorder =
80
        BorderFactory.createEtchedBorder();
81
    Border emptyBorder =
82
        BorderFactory.createEmptyBorder(10, 10, 10, 10);
83
    Border compoundBorder =
84
        BorderFactory.createCompoundBorder(etchedBorder, emptyBorder);
85

    
86
    // Create a date listener to be used for all calendars
87

    
88
    MyDateListener listener = new MyDateListener();
89

    
90
    // Display date and time using the default calendar and locale.
91
    // Display today's date at the bottom.
92

    
93
    JCalendar calendar1 =
94
        new JCalendar(
95
            JCalendar.DISPLAY_DATE | JCalendar.DISPLAY_TIME,
96
            true);
97
    calendar1.addDateListener(listener);
98
    calendar1.setBorder(compoundBorder);
99

    
100
    // Set fonts rather than using defaults
101

    
102
    calendar1.setTitleFont(new Font("Serif", Font.BOLD|Font.ITALIC, 24));
103
    calendar1.setDayOfWeekFont(new Font("SansSerif", Font.ITALIC, 12));
104
    calendar1.setDayFont(new Font("SansSerif", Font.BOLD, 16));
105
    calendar1.setTimeFont(new Font("DialogInput", Font.PLAIN, 10));
106
    calendar1.setTodayFont(new Font("Dialog", Font.PLAIN, 14));
107

    
108
    // Display date only
109

    
110
    JCalendar calendar2 = new JCalendar(JCalendar.DISPLAY_DATE, false);
111
    calendar2.addDateListener(listener);
112
    calendar2.setBorder(compoundBorder);
113

    
114
    // Display time only and set the time pattern to use as a duration
115
    // from 00:00 to 23:59
116

    
117
    JCalendar calendar3 =
118
        new JCalendar(
119
            Calendar.getInstance(),
120
            Locale.getDefault(),
121
            JCalendar.DISPLAY_TIME,
122
            false,
123
            "HH:mm");
124
    calendar3.addDateListener(listener);
125
    calendar3.setBorder(compoundBorder);
126

    
127
    // Display a French calendar
128

    
129
    JCalendar calendar4 =
130
        new JCalendar(
131
            Calendar.getInstance(Locale.FRENCH),
132
            Locale.FRENCH,
133
            JCalendar.DISPLAY_DATE | JCalendar.DISPLAY_TIME,
134
            false);
135
    calendar4.addDateListener(listener);
136
    calendar4.setBorder(compoundBorder);
137

    
138
    // Add all the calendars to the content pane
139

    
140
    JPanel panel1 = new JPanel(new FlowLayout());
141
    panel1.add(calendar1);
142
    contentPane.add(panel1);
143

    
144
    JPanel panel2 = new JPanel(new FlowLayout());
145
    panel2.add(calendar2);
146
    contentPane.add(panel2);
147

    
148
    JPanel panel3 = new JPanel(new FlowLayout());
149
    panel3.add(calendar3);
150
    contentPane.add(panel3);
151

    
152
    JPanel panel4 = new JPanel(new FlowLayout());
153
    panel4.add(calendar4);
154
    contentPane.add(panel4);
155

    
156
    // Make the window visible
157

    
158
    pack();
159
    setVisible(true);
160
}
161

    
162
//**********************************************************************
163
// Inner Classes
164
//**********************************************************************
165

    
166
private class MyDateListener
167
      implements DateListener
168
{
169

    
170
public void
171
dateChanged(
172
    DateEvent e)
173
{
174
    Calendar c = e.getSelectedDate();
175
    if (c != null) {
176
        System.out.println(c.getTime());
177
    }
178
    else {
179
        System.out.println("No time selected.");
180
    }
181
}
182

    
183
}
184

    
185
//**********************************************************************
186
// End Inner Classes
187
//**********************************************************************
188

    
189
}