1 /*
2 * Copyright (c) 2003-2008 by Cosylab d. d.
3 *
4 * This file is part of CosyBeans-Common.
5 *
6 * CosyBeans-Common is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * CosyBeans-Common is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with CosyBeans-Common. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 package com.cosylab.gui.components.table.renderers;
21
22 import com.cosylab.gui.components.numberfield.LongDocument;
23 import com.cosylab.gui.components.table.cells.LongCell;
24
25 import com.cosylab.util.StringUtilities;
26
27 import java.awt.Component;
28
29 import javax.swing.JTable;
30
31
32 /**
33 * Edits LongCell value.
34 *
35 * @author <a href="mailto:igor.kriznar@cosylab.com">Igor Kriznar</a>
36 * @version $id$
37 */
38 public class LongCellEditor extends JTextFieldCellEditor
39 {
40 private static final long serialVersionUID = 1L;
41 private LongDocument document;
42 private boolean active;
43
44 /**
45 * Creates a new DoubleCellEditor object.
46 */
47 public LongCellEditor()
48 {
49 setDocument(document = new LongDocument());
50 }
51
52 /*
53 * (non-Javadoc)
54 * @see com.cosylab.gui.components.table.renderers.JTextFieldCellEditor#getTableCellEditorComponent(javax.swing.JTable, java.lang.Object, boolean, int, int)
55 */
56 public Component getTableCellEditorComponent(JTable table, Object cell,
57 boolean isSelected, int row, int column)
58 {
59 if (cell instanceof LongCell) {
60 active = !((LongCell)cell).isSuspended();
61
62 document.setMaxValue(((LongCell)cell).getMaximum());
63 document.setMinValue(((LongCell)cell).getMinimum());
64
65 if (active) {
66 setText(Long.toString(((LongCell)cell).getLongValue()));
67 } else {
68 setText("");
69 }
70
71 selectAll();
72 }
73
74 return super.getTableCellEditorComponent(table, cell, isSelected, row,
75 column);
76 }
77
78 /* (non-Javadoc)
79 * @see javax.swing.DefaultCellEditor#getCellEditorValue()
80 */
81 public Object getCellEditorValue()
82 {
83 return document.getValue();
84 }
85
86 /* (non-Javadoc)
87 * @see com.cosylab.gui.components.table.renderers.JTextFieldCellEditor#isValueValid()
88 */
89 protected boolean isValueValid()
90 {
91 return StringUtilities.isTrueNumber(getText());
92 }
93 }
94
95 /* __oOo__ */