KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sellwin > gui > DateEditor


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

17 /**
18  * This class ties the date editor dialog to
19  * a table's date column
20  */

21 public class DateEditor extends DefaultCellEditor implements DateEditorDialogListener {
22
23     private DateRenderer renderer = new DateRenderer();
24     private Date currentDate = null;
25     private JButton editorComponent=null;
26     private JTable table=null;
27
28     /**
29      * construct the date editor
30      * @param b the button that causes the date editor dialog to popup
31      * @param table the table that will use this trigger
32      */

33     public DateEditor(JButton b, JTable table) {
34         super(new JCheckBox());
35         this.table = table;
36
37         editorComponent = b;
38         setClickCountToStart(1);
39
40         b.addActionListener(new ActionListener() {
41             public void actionPerformed(ActionEvent e) {
42                 fireEditingStopped();
43             }
44         });
45     }
46
47     /**
48      * get the date
49      * @return the current date
50      */

51     public final Date getDate() {
52         return currentDate;
53     }
54
55
56     /**
57      * set the date
58      * @param d the date
59      */

60     public final void setDate(Date d) {
61         currentDate = d;
62         ((JButton)editorComponent).setText(Prefs.dateFormat.format(currentDate));
63         TableModel model = table.getModel();
64         table.tableChanged(new TableModelEvent(model));
65         fireEditingStopped();
66     }
67
68     /**
69      * get the table's cell editor component
70      * @param table description
71      * @return description
72      * @exception class-name description
73      */

74     public final Component getTableCellEditorComponent(
75         JTable table,
76         Object JavaDoc value,
77         boolean isSelected,
78         int row, int col) {
79
80         if (value == null) value = new Date();
81         Date dt = (Date)value;
82         
83         ((JButton)editorComponent).setText(Prefs.dateFormat.format(dt));
84         currentDate = (Date)value;
85         return editorComponent;
86     }
87
88     /**
89      * fire the editing stopped message
90      */

91     protected final void fireEditingStopped() {
92         super.fireEditingStopped();
93     }
94
95     /**
96      * get the cell editor value
97      * @return description
98      */

99     public final Object JavaDoc getCellEditorValue() {
100         return currentDate;
101     }
102 }
103
Popular Tags