KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sellwin > gui > DateTimeRenderer


1 package sellwin.gui;
2
3 import sellwin.utils.*;
4
5 import java.awt.*;
6 import java.util.*;
7 import javax.swing.*;
8 import javax.swing.event.*;
9 import javax.swing.table.*;
10
11 // SellWin http://sourceforge.net/projects/sellwincrm
12
//Contact support@open-app.com for commercial help with SellWin
13
//This software is provided "AS IS", without a warranty of any kind.
14

15 /**
16  * This class renders a label within a table
17  * cell that needs to display a date and time
18  * string.
19  */

20 public class DateTimeRenderer extends JLabel implements TableCellRenderer {
21
22     private Date currentDate;
23
24     /**
25      * construct the date time renderer
26      */

27     public DateTimeRenderer() {
28         super();
29         setBackground(MainWindow.LETTERS);
30         setFont(MainWindow.FIELD_FONT);
31     }
32
33     /**
34      * get the table cell renderer, this method is
35      * implemented for the TableCellRenderer interface
36      * @param table description
37      * @param date description
38      * @param isSelected description
39      * @param hasFocus description
40      * @param row description
41      * @param col description
42      * @return description
43      */

44     public final Component getTableCellRendererComponent(
45         JTable table, Object JavaDoc date,
46         boolean isSelected, boolean hasFocus,
47         int row, int col) {
48
49         currentDate = (Date)date;
50
51         if (date == null)
52             date = new Date();
53         setText(Prefs.dateTimeFormat.format((Date)date));
54         return this;
55     }
56
57
58     /**
59      * get the date this renderer stores
60      * @return the date
61      */

62     public final Date getDate() {
63         return currentDate;
64     }
65
66     /**
67      * implemented for the TableCellRenderer
68      * @param value the value we are setting with
69      */

70     public final void setValue(Object JavaDoc value) {
71         if (value == null)
72             currentDate = new Date();
73         else {
74             currentDate = (Date)value;
75         }
76
77         setText(Prefs.dateTimeFormat.format((Date)currentDate));
78     }
79 }
80
Popular Tags