KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sellwin > gui > DateRenderer


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 implements a date renderer for the
17  * tables used in SellWIN that display a Java Date
18  */

19 public class DateRenderer extends JLabel implements TableCellRenderer {
20
21     private Date currentDate;
22
23     /**
24      * construct a date renderer
25      */

26     public DateRenderer() {
27         super();
28         setBackground(MainWindow.LETTERS);
29         setFont(MainWindow.FIELD_FONT);
30     }
31
32     /**
33      * part of the java interface spec
34      */

35     public final Component getTableCellRendererComponent(
36         JTable table, Object JavaDoc date,
37         boolean isSelected, boolean hasFocus,
38         int row, int col) {
39
40         currentDate = (Date)date;
41
42         if (date == null)
43             date = new Date();
44         setText(Prefs.dateFormat.format((Date)date));
45         return this;
46     }
47
48
49     /**
50      * get the date used by this renderer
51      * @return the date being used
52      */

53     public final Date getDate() {
54         return currentDate;
55     }
56
57     /**
58      * set the label's text using the object (date)
59      * @param value the object we are to render
60      */

61     public final void setValue(Object JavaDoc value) {
62         if (value == null)
63             currentDate = new Date();
64         else {
65             currentDate = (Date)value;
66         }
67
68
69         setText(currentDate.toString());
70     }
71 }
72
Popular Tags