001: /*
002: * ComboBoxCellRenderer.java
003: *
004: * Copyright (C) 2002, 2003, 2004, 2005, 2006 Takis Diakoumis
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
019: *
020: */
021:
022: package org.underworldlabs.swing.table;
023:
024: import java.awt.Color;
025: import java.awt.Component;
026: import java.awt.Font;
027: import java.awt.Graphics;
028: import javax.swing.JLabel;
029: import javax.swing.JTable;
030: import javax.swing.table.TableCellRenderer;
031:
032: /* ----------------------------------------------------------
033: * CVS NOTE: Changes to the CVS repository prior to the
034: * release of version 3.0.0beta1 has meant a
035: * resetting of CVS revision numbers.
036: * ----------------------------------------------------------
037: */
038:
039: /**
040: *
041: * @author Takis Diakoumis
042: * @version $Revision: 1.4 $
043: * @date $Date: 2006/05/14 06:56:07 $
044: */
045: public class ComboBoxCellRenderer extends JLabel implements
046: TableCellRenderer {
047:
048: private static Color iconColor;
049:
050: static {
051: iconColor = Color.DARK_GRAY.darker();
052: }
053:
054: /** Creates a new instance of ComboBoxCellRenderer */
055: public ComboBoxCellRenderer() {
056: }
057:
058: public Component getTableCellRendererComponent(JTable table,
059: Object value, boolean isSelected, boolean cellHasFocus,
060: int row, int col) {
061: setFont(table.getFont());
062:
063: if (value == null) {
064: setText("");
065: } else {
066: setText(value.toString());
067: }
068:
069: return this ;
070: }
071:
072: private int ICON_HEIGHT = 10;
073:
074: public void paintComponent(Graphics g) {
075: super .paintComponent(g);
076:
077: int height = getHeight();
078: int width = getWidth();
079:
080: int x = 0, y = 0;
081: int xo = width - 15;
082: int yo = (height - ICON_HEIGHT) / 2;
083:
084: g.setColor(iconColor);
085: for (int i = 1; i <= ICON_HEIGHT; i++) {
086:
087: y = yo + i + 2;
088:
089: for (int j = i; j <= ICON_HEIGHT; j++) {
090:
091: if (j > ICON_HEIGHT - i)
092: break;
093:
094: x = xo + j;
095: g.drawLine(x, y, x, y);
096:
097: }
098:
099: }
100:
101: }
102:
103: }
|