KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sellwin > gui > DescEditor


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 description editor dialog to
19  * the activity table's description column
20  */

21 public class DescEditor extends DefaultCellEditor implements DescEditorDialogListener {
22
23     private DescRenderer renderer = new DescRenderer();
24     private String JavaDoc currentDesc = null;
25     private JButton editorComponent=null;
26     private JTable table=null;
27
28     /**
29      * construct the desc editor
30      * @param b the button that causes the desc editor dialog to popup
31      * @param table the table that will use this trigger
32      */

33     public DescEditor(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 desc
49      * @return the current date
50      */

51     public final String JavaDoc getDesc() {
52         return currentDesc;
53     }
54
55
56     /**
57      * set the desc
58      * @param d the desc
59      */

60     public final void setDesc(String JavaDoc d) {
61         currentDesc = d;
62         ((JButton)editorComponent).setText(currentDesc);
63         ActivityTableModel model = (ActivityTableModel)table.getModel();
64         Activity act = model.getActivity(table.getSelectedRow());
65         table.tableChanged(new TableModelEvent(model));
66         fireEditingStopped();
67     }
68
69     /**
70      * get the table's cell editor component
71      * @param table description
72      * @return description
73      * @exception class-name description
74      */

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

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

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