001/** 002 * RadioButtonEditor.java 003 * jCOLIBRI2 framework. 004 * @author Juan A. Recio-Garc�a. 005 * GAIA - Group for Artificial Intelligence Applications 006 * http://gaia.fdi.ucm.es 007 * 02/11/2007 008 */ 009package es.ucm.fdi.gaia.jcolibri.extensions.recommendation.casesDisplay.utils; 010 011import java.awt.Component; 012import java.awt.event.ItemEvent; 013import java.awt.event.ItemListener; 014 015import javax.swing.DefaultCellEditor; 016import javax.swing.JCheckBox; 017import javax.swing.JRadioButton; 018import javax.swing.JTable; 019 020/** 021 * Utility class for managing radio buttons in a table 022 * @author Juan A. Recio-Garcia 023 * @author Developed at University College Cork (Ireland) in collaboration with Derek Bridge. 024 * @version 1.0 025 * 026 */ 027public class RadioButtonEditor extends DefaultCellEditor implements ItemListener 028{ 029 030 private static final long serialVersionUID = 1L; 031 032 private JRadioButton button; 033 034 public RadioButtonEditor(JCheckBox checkBox) 035 { 036 super(checkBox); 037 } 038 039 public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) 040 { 041 if (value == null) 042 return null; 043 button = (JRadioButton) value; 044 button.addItemListener(this); 045 return (Component) value; 046 } 047 048 public Object getCellEditorValue() 049 { 050 button.removeItemListener(this); 051 return button; 052 } 053 054 public void itemStateChanged(ItemEvent e) 055 { 056 super.fireEditingStopped(); 057 } 058}