KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > minigrid > MiniCellEditor


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.minigrid;
15
16 import javax.swing.*;
17 import javax.swing.table.*;
18 import java.sql.*;
19 import java.math.*;
20 import java.awt.*;
21
22 import org.compiere.grid.ed.*;
23 import org.compiere.util.*;
24
25 /**
26  * MiniTable Cell Editor based on class - Timestamp, BigDecimal
27  *
28  * @author Jorg Janke
29  * @version $Id: MiniCellEditor.java,v 1.4 2002/08/12 01:55:14 danb Exp $
30  */

31 public class MiniCellEditor extends AbstractCellEditor implements TableCellEditor
32 {
33     /**
34      * Default Constructor
35      * @param c Class
36      */

37     public MiniCellEditor(Class JavaDoc c)
38     {
39         super();
40         // Date
41
if (c == Timestamp.class)
42             m_editor = new VDate();
43         else if (c == BigDecimal.class)
44             m_editor = new VNumber("Amount", false, false, true, DisplayType.Amount, "Amount");
45         else if (c == Double JavaDoc.class)
46             m_editor = new VNumber("Number", false, false, true, DisplayType.Number, "Number");
47         else if (c == Integer JavaDoc.class)
48             m_editor = new VNumber("Integer", false, false, true, DisplayType.Integer, "Integer");
49         else
50             m_editor = new VString();
51
52     } // MiniCellEditor
53

54     private VEditor m_editor = null;
55
56     /**
57      * Sets an initial value for the editor. This will cause the editor to
58      * stopEditing and lose any partially edited value if the editor is editing
59      * when this method is called.
60      * Returns the component that should be added to the client's Component hierarchy.
61      * Once installed in the client's hierarchy this component
62      * will then be able to draw and receive user input.
63      * @param table
64      * @param value
65      * @param isSelected
66      * @param row
67      * @param column
68      * @return Component
69      */

70     public Component getTableCellEditorComponent(JTable table, Object JavaDoc value, boolean isSelected, int row, int column)
71     {
72     // ADebug.trace(ADebug.l5_DData, "VCellEditor.getTableCellEditorComponent - " + value == null ? "null" : value.toString());
73

74         // Set Value
75
m_editor.setValue(value);
76
77         // Set UI
78
m_editor.setBorder(null);
79     // m_editor.setBorder(UIManager.getBorder("Table.focusCellHighlightBorder"));
80
m_editor.setFont(table.getFont());
81         return (Component)m_editor;
82     } // getTableCellEditorComponent
83

84     /**
85      * Returns the value contained in the editor
86      * @return value
87      */

88     public Object JavaDoc getCellEditorValue()
89     {
90     // ADebug.trace(ADebug.l5_DData, "VCellEditor.getCellEditorValue - ");
91

92         if (m_editor != null)
93             return m_editor.getValue();
94         return null;
95     } // getCellEditorValue
96

97 } // MiniCellEditor
98
Popular Tags