KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > calipso > reportgenerator > userinterface > UPDateTextField


1 package com.calipso.reportgenerator.userinterface;
2
3 import com.calipso.reportgenerator.common.LanguageTraslator;
4
5 import javax.swing.text.Document JavaDoc;
6 import java.util.Date JavaDoc;
7 import java.text.DateFormat JavaDoc;
8 import java.text.SimpleDateFormat JavaDoc;
9 import java.text.ParseException JavaDoc;
10
11 /**
12  * Representa un componente <code>JTextField</code> a incluirse en una instancia
13  * de <code>UPRangePanel</code> o <code>UPValuePanel</code>.
14  * Devuele el texto del componente en un objeto <code>Date</code>
15  */

16
17 public class UPDateTextField extends UPTextField {
18
19   public UPDateTextField() {
20   }
21
22   public UPDateTextField(String JavaDoc text) {
23     super(text);
24   }
25
26   public UPDateTextField(int columns) {
27     super(columns);
28   }
29
30   public UPDateTextField(String JavaDoc text, int columns) {
31     super(text, columns);
32   }
33
34   public UPDateTextField(Document JavaDoc doc, String JavaDoc text, int columns) {
35     super(doc, text, columns);
36   }
37
38   public boolean isLessThan(UPTextField upTextField) {
39     Date JavaDoc date = (Date JavaDoc) getComponentValue();
40     int result = date.compareTo((Date JavaDoc)upTextField.getComponentValue());
41     if(result > 0) {
42       return false;
43     } else {
44       return true;
45     }
46   }
47
48   public Object JavaDoc getComponentValue() {
49     Date JavaDoc returnVal = null;
50     try {
51       String JavaDoc text = super.getText();
52       if(!text.equals("")) {
53         DateFormat JavaDoc dateFormat = SimpleDateFormat.getDateInstance(DateFormat.SHORT, LanguageTraslator.getLocale());
54         Date JavaDoc date = dateFormat.parse(text);
55         returnVal = date;
56       }
57     } catch(ParseException JavaDoc e) {
58       e.printStackTrace();
59     }
60     return returnVal;
61   }
62 }
63
Popular Tags