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
26 import javax.swing.JTable;
27
28
29 /**
30 * Default table renderer for LongEnumCell. Displays enum state description.
31 *
32 * @author <a href="mailto:igor.kriznar@cosylab.com">Igor Kriznar</a>
33 * @version $id$
34 */
35 public class LongEnumCellRenderer extends DefaultTableCellRenderer
36 {
37 private static final long serialVersionUID = 1L;
38
39 /**
40 * Constructs a new LongEnumCellRenderer.
41 *
42 */
43 public LongEnumCellRenderer()
44 {
45 super();
46 }
47
48 /**
49 * Constructs a new LongEnumCellRenderer.
50 *
51 * @param decorateBorder if true decorated border will be used
52 * @param decorateBackground if true decorated background will be used
53 */
54 public LongEnumCellRenderer(boolean decorateBorder,
55 boolean decorateBackground)
56 {
57 super(decorateBorder, decorateBackground);
58 }
59
60 /*
61 * (non-Javadoc)
62 * @see com.cosylab.gui.components.table.renderers.DefaultTableCellRenderer#getTableCellRendererComponent(javax.swing.JTable, java.lang.Object, boolean, boolean, int, int)
63 */
64 public Component getTableCellRendererComponent(JTable table, Object cell,
65 boolean isSelected, boolean hasFocus, int row, int column)
66 {
67 super.getTableCellRendererComponent(table, cell, isSelected, hasFocus,
68 row, column);
69
70 if (cell instanceof LongEnumCell) {
71 LongEnumCell property = (LongEnumCell)cell;
72
73 if (property.isSuspended()) {
74 setText("");
75 } else {
76 long l = property.getLongValue();
77 String s = property.getStateDescription(l);
78
79 if (s == null) {
80 StringBuffer sb = new StringBuffer(8);
81 sb.append('<');
82 sb.append(l);
83 sb.append('>');
84 s = sb.toString();
85 }
86
87 setText(s);
88 }
89 }
90
91 return this;
92 }
93 }
94
95 /* __oOo__ */