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 */ 009 package jcolibri.extensions.recommendation.casesDisplay.utils; 010 011 import java.awt.Component; 012 import java.awt.event.ItemEvent; 013 import java.awt.event.ItemListener; 014 015 import javax.swing.DefaultCellEditor; 016 import javax.swing.JCheckBox; 017 import javax.swing.JRadioButton; 018 import 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 */ 027 public 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 }