KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > usertasks > DateSelectionPanel


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.tasklist.usertasks;
20
21 import java.text.SimpleDateFormat JavaDoc;
22 import java.util.Date JavaDoc;
23
24 import org.openide.explorer.propertysheet.editors.EnhancedCustomPropertyEditor;
25
26 /**
27  * This is a small panel to allow the user to select a full date. When I
28  * started the implementation of the Alarm functionality I had the user to
29  * write the complete time/date, and I pretty soon realized that noone will
30  * remember the format each time.... Well, the panel "works for me now" so I
31  * move on to the next phase in my project, but one should really:
32  *
33  * @author Trond Norbye
34  */

35 public class DateSelectionPanel extends javax.swing.JPanel JavaDoc
36     implements EnhancedCustomPropertyEditor {
37
38     private static final long serialVersionUID = 1;
39
40     /**
41      * A SimpleDateFormat I use for conversion to/from textual representation
42      * of date fields.
43      */

44     private SimpleDateFormat JavaDoc format;
45    
46     /** Creates new form DateSelectionPanel. */
47     public DateSelectionPanel() {
48         this(new Date JavaDoc());
49     }
50
51     /**
52      * Create a new DateSelectionPanel with the given date selected...
53      *
54      * @param date initial selection
55      */

56     public DateSelectionPanel(Date JavaDoc date) {
57         initComponents();
58         jCalendar.setDate(date);
59     }
60     
61     /**
62      * Returns the selected date
63      *
64      * @return selected date
65      */

66     public Date JavaDoc getDate() {
67         return jCalendar.getDate();
68     }
69     
70     /** This method is called from within the constructor to
71      * initialize the form.
72      * WARNING: Do NOT modify this code. The content of this method is
73      * always regenerated by the Form Editor.
74      */

75     private void initComponents() {//GEN-BEGIN:initComponents
76
jPanel1 = new javax.swing.JPanel JavaDoc();
77         jCalendar = new com.toedter.calendar.JCalendar();
78         jLabel1 = new javax.swing.JLabel JavaDoc();
79         timeFld = new javax.swing.JTextField JavaDoc();
80
81         setLayout(new java.awt.BorderLayout JavaDoc());
82
83         setBorder(new javax.swing.border.EmptyBorder JavaDoc(new java.awt.Insets JavaDoc(11, 11, 12, 12)));
84         jPanel1.setBorder(new javax.swing.border.EmptyBorder JavaDoc(new java.awt.Insets JavaDoc(0, 0, 11, 0)));
85         jPanel1.add(jCalendar);
86
87         jLabel1.setText("@");
88         jPanel1.add(jLabel1);
89
90         timeFld.setColumns(8);
91         timeFld.setHorizontalAlignment(javax.swing.JTextField.CENTER);
92         timeFld.setInputVerifier(new javax.swing.InputVerifier JavaDoc() {
93             public boolean verify(javax.swing.JComponent JavaDoc obj) {
94                 boolean ret;
95                 try {
96                     format.applyPattern("HH:mm:ss");
97                     format.parse(((javax.swing.JTextField JavaDoc)obj).getText());
98                     ret = true;
99                 } catch (Exception JavaDoc e) {
100                     ret = false;
101                 }
102                 return ret;
103             }
104         });
105         jPanel1.add(timeFld);
106
107         add(jPanel1, java.awt.BorderLayout.CENTER);
108
109     }//GEN-END:initComponents
110

111     // Variables declaration - do not modify//GEN-BEGIN:variables
112
private com.toedter.calendar.JCalendar jCalendar;
113     private javax.swing.JLabel JavaDoc jLabel1;
114     private javax.swing.JPanel JavaDoc jPanel1;
115     private javax.swing.JTextField JavaDoc timeFld;
116     // End of variables declaration//GEN-END:variables
117

118     // When used as a property customizer
119
public Object JavaDoc getPropertyValue() throws IllegalStateException JavaDoc {
120         return getDate();
121     }
122 }
123
Popular Tags