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.table.cells.LongEnumCell;
23
24 import java.awt.Component;
25 import java.awt.event.MouseEvent;
26 import java.awt.event.MouseListener;
27
28 import javax.swing.DefaultCellEditor;
29 import javax.swing.JComboBox;
30 import javax.swing.JTable;
31
32
33 /**
34 * <code>LongEnumCellRenderer</code> is the editor for the LongEnumCell.
35 *
36 * @author <a href="mailto:jernej.kamenik@cosylab.com">Jernej Kamenik</a>
37 * @version $Id: LongEnumCellEditor.java,v 1.6 2008-04-22 12:28:41 jbobnar Exp $
38 *
39 * @since May 8, 2004.
40 */
41 public class LongEnumCellEditor extends DefaultCellEditor
42 {
43 private static final long serialVersionUID = 1L;
44 EnumComboBoxModel comboModel;
45
46 /**
47 * Creates a new DiamondStatusCellEditor object.
48 */
49 public LongEnumCellEditor()
50 {
51 super(new JComboBox(new EnumComboBoxModel()));
52
53 getComponent().addMouseListener(new MouseListener() {
54 public void mouseClicked(MouseEvent e) {
55 }
56
57 public void mouseEntered(MouseEvent e) {
58 }
59
60 public void mouseExited(MouseEvent e) {
61 cancelCellEditing();
62 }
63
64 public void mousePressed(MouseEvent e) {
65 }
66
67 public void mouseReleased(MouseEvent e) {
68 }
69 });
70 }
71
72 /* (non-Javadoc)
73 * @see javax.swing.DefaultCellEditor#getTableCellEditorComponent(javax.swing.JTable, java.lang.Object, boolean, int, int)
74 */
75 public Component getTableCellEditorComponent(JTable table, Object value,
76 boolean isSelected, int row, int column)
77 {
78 JComboBox box = (JComboBox)super.getTableCellEditorComponent(table,
79 value, isSelected, row, column);
80
81 if (comboModel == null) {
82 comboModel = (EnumComboBoxModel)box.getModel();
83 }
84
85 if (value instanceof LongEnumCell) {
86 LongEnumCell cell = (LongEnumCell)value;
87 comboModel.setCell(cell);
88 } else {
89 comboModel.setCell(null);
90 }
91
92 return box;
93 }
94
95 /* (non-Javadoc)
96 * @see javax.swing.DefaultCellEditor#getCellEditorValue()
97 */
98 public Object getCellEditorValue()
99 {
100 return comboModel.getLongVale();
101 }
102 }
103
104 /* __oOo__ */