Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.ui / src / test / java / org / gvsig / gui / beans / swing / textBoxWithCalendar / jCalendarUsingSamples / Example1.java @ 40561

History | View | Annotate | Download (5.92 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
//**********************************************************************
25
// Package
26
//**********************************************************************
27

    
28

    
29
//**********************************************************************
30
// Import list
31
//**********************************************************************
32
package org.gvsig.gui.beans.swing.textBoxWithCalendar.jCalendarUsingSamples;
33

    
34
import java.awt.Container;
35
import java.awt.FlowLayout;
36
import java.awt.Font;
37
import java.awt.GridLayout;
38
import java.util.Calendar;
39
import java.util.Locale;
40

    
41
import javax.swing.BorderFactory;
42
import javax.swing.JFrame;
43
import javax.swing.JPanel;
44
import javax.swing.border.Border;
45

    
46
import org.freixas.jcalendar.DateEvent;
47
import org.freixas.jcalendar.DateListener;
48
import org.freixas.jcalendar.JCalendar;
49

    
50
/**
51
 * This example shows various instances of the JCalendar class.
52
 * <hr>
53
 * This program is free software; you can redistribute it and/or
54
 * modify it under the terms of the Artistic License. You should have
55
 * received a copy of the Artistic License along with this program. If
56
 * not, a copy is available at
57
 * <a href="http://opensource.org/licenses/artistic-license.php">
58
 * opensource.org</a>.
59
 *
60
 * @author Antonio Freixas
61
 */
62

    
63
// Copyright ? 2004 Antonio Freixas
64
// All Rights Reserved.
65

    
66
public class Example1 extends JFrame {
67
        private static final long serialVersionUID = -2655722904436980134L;
68

    
69
        // **********************************************************************
70
        // main
71
        // **********************************************************************
72

    
73
        public static void main(String[] args) {
74
                new Example1();
75
        }
76

    
77
// **********************************************************************
78
// Constructors
79
//**********************************************************************
80

    
81
/**
82
 * Create various instances of a JCalendar.
83
 */
84

    
85
public
86
Example1()
87
{
88
    // Set up the frame
89

    
90
    setTitle("Example1");
91
    setDefaultCloseOperation(EXIT_ON_CLOSE);
92

    
93
    Container contentPane = getContentPane();
94
    contentPane.setLayout(new GridLayout(2, 2, 5, 5));
95

    
96
    // Create a border for all calendars
97

    
98
    Border etchedBorder =
99
        BorderFactory.createEtchedBorder();
100
    Border emptyBorder =
101
        BorderFactory.createEmptyBorder(10, 10, 10, 10);
102
    Border compoundBorder =
103
        BorderFactory.createCompoundBorder(etchedBorder, emptyBorder);
104

    
105
    // Create a date listener to be used for all calendars
106

    
107
    MyDateListener listener = new MyDateListener();
108

    
109
    // Display date and time using the default calendar and locale.
110
    // Display today's date at the bottom.
111

    
112
    JCalendar calendar1 =
113
        new JCalendar(
114
            JCalendar.DISPLAY_DATE | JCalendar.DISPLAY_TIME,
115
            true);
116
    calendar1.addDateListener(listener);
117
    calendar1.setBorder(compoundBorder);
118

    
119
    // Set fonts rather than using defaults
120

    
121
    calendar1.setTitleFont(new Font("Serif", Font.BOLD|Font.ITALIC, 24));
122
    calendar1.setDayOfWeekFont(new Font("SansSerif", Font.ITALIC, 12));
123
    calendar1.setDayFont(new Font("SansSerif", Font.BOLD, 16));
124
    calendar1.setTimeFont(new Font("DialogInput", Font.PLAIN, 10));
125
    calendar1.setTodayFont(new Font("Dialog", Font.PLAIN, 14));
126

    
127
    // Display date only
128

    
129
    JCalendar calendar2 = new JCalendar(JCalendar.DISPLAY_DATE, false);
130
    calendar2.addDateListener(listener);
131
    calendar2.setBorder(compoundBorder);
132

    
133
    // Display time only and set the time pattern to use as a duration
134
    // from 00:00 to 23:59
135

    
136
    JCalendar calendar3 =
137
        new JCalendar(
138
            Calendar.getInstance(),
139
            Locale.getDefault(),
140
            JCalendar.DISPLAY_TIME,
141
            false,
142
            "HH:mm");
143
    calendar3.addDateListener(listener);
144
    calendar3.setBorder(compoundBorder);
145

    
146
    // Display a French calendar
147

    
148
    JCalendar calendar4 =
149
        new JCalendar(
150
            Calendar.getInstance(Locale.FRENCH),
151
            Locale.FRENCH,
152
            JCalendar.DISPLAY_DATE | JCalendar.DISPLAY_TIME,
153
            false);
154
    calendar4.addDateListener(listener);
155
    calendar4.setBorder(compoundBorder);
156

    
157
    // Add all the calendars to the content pane
158

    
159
    JPanel panel1 = new JPanel(new FlowLayout());
160
    panel1.add(calendar1);
161
    contentPane.add(panel1);
162

    
163
    JPanel panel2 = new JPanel(new FlowLayout());
164
    panel2.add(calendar2);
165
    contentPane.add(panel2);
166

    
167
    JPanel panel3 = new JPanel(new FlowLayout());
168
    panel3.add(calendar3);
169
    contentPane.add(panel3);
170

    
171
    JPanel panel4 = new JPanel(new FlowLayout());
172
    panel4.add(calendar4);
173
    contentPane.add(panel4);
174

    
175
    // Make the window visible
176

    
177
    pack();
178
    setVisible(true);
179
}
180

    
181
//**********************************************************************
182
// Inner Classes
183
//**********************************************************************
184

    
185
private class MyDateListener
186
      implements DateListener
187
{
188

    
189
public void
190
dateChanged(
191
    DateEvent e)
192
{
193
    Calendar c = e.getSelectedDate();
194
    if (c != null) {
195
        System.out.println(c.getTime());
196
    }
197
    else {
198
        System.out.println("No time selected.");
199
    }
200
}
201

    
202
}
203

    
204
//**********************************************************************
205
// End Inner Classes
206
//**********************************************************************
207

    
208
}