001/* 002 * Copyright (c) 2005 Jens Schou, Staffan Gustafsson, Bjorn Lanneskog, 003 * Einar Pehrson and Sebastian Kekkonen 004 * 005 * This file is part of 006 * CleanSheets Extension for Test Cases 007 * 008 * CleanSheets Extension for Test Cases is free software; you can 009 * redistribute it and/or modify it under the terms of the GNU General Public 010 * License as published by the Free Software Foundation; either version 2 of 011 * the License, or (at your option) any later version. 012 * 013 * CleanSheets Extension for Test Cases is distributed in the hope that 014 * it will be useful, but WITHOUT ANY WARRANTY; without even the implied 015 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 016 * See the GNU General Public License for more details. 017 * 018 * You should have received a copy of the GNU General Public License 019 * along with CleanSheets Extension for Test Cases; if not, write to the 020 * Free Software Foundation, Inc., 59 Temple Place, Suite 330, 021 * Boston, MA 02111-1307 USA 022 */ 023package csheets.ext.test.ui; 024 025import java.awt.Color; 026import java.awt.Component; 027 028import javax.swing.JComboBox; 029import javax.swing.JTable; 030import javax.swing.table.TableCellRenderer; 031 032import csheets.ext.test.TestCase; 033 034/** 035 * A combo box in which validation states are selected, which acts as a table 036 * cell renderer. 037 * @author Einar Pehrson 038 */ 039@SuppressWarnings("serial") 040public class ValidationStateRenderer extends JComboBox implements TableCellRenderer { 041 042 /** 043 * Creates a new validation state renderer. 044 */ 045 public ValidationStateRenderer() { 046 super(TestCase.ValidationState.values()); 047 } 048 049 public Component getTableCellRendererComponent(JTable table, Object value, 050 boolean selected, boolean hasFocus, int row, int column) { 051 TestCase.ValidationState state = (TestCase.ValidationState)value; 052 053 // Sets colors 054 switch (state) { 055 case VALID: 056 setForeground(Color.green); 057 break; 058 case REJECTED: 059 setForeground(Color.red); 060 break; 061 default: 062 if (selected) { 063 setForeground(table.getSelectionForeground()); 064 super.setBackground(table.getSelectionBackground()); 065 } else { 066 setForeground(table.getForeground()); 067 setBackground(table.getBackground()); 068 } 069 } 070 071 // Selects the current value 072 setSelectedItem(value); 073 return this; 074 } 075}