001 // GraphLab Project: http://graphlab.sharif.edu 002 // Copyright (C) 2008 Mathematical Science Department of Sharif University of Technology 003 // Distributed under the terms of the GNU General Public License (GPL): http://www.gnu.org/licenses/ 004 package graphlab.ui.components.gpropertyeditor.editors.inplace; 005 006 import graphlab.ui.components.gpropertyeditor.EditingFinishedListener; 007 import graphlab.ui.components.gpropertyeditor.GBasicCellEditor; 008 009 import javax.swing.*; 010 import java.awt.*; 011 import java.awt.event.ActionEvent; 012 import java.awt.event.ActionListener; 013 014 /** 015 * User: root 016 */ 017 public class GBooleanEditor implements GBasicCellEditor, ActionListener { 018 private EditingFinishedListener listener; 019 private JCheckBox j; 020 021 public Object[] getValues() { 022 return new Boolean[]{true, false}; 023 } 024 025 public void setEditingFinishedListener(EditingFinishedListener listener) { 026 this.listener = listener; 027 } 028 029 public Component getEditorComponent(Object value) { 030 Boolean b = (Boolean) value; 031 j = new JCheckBox("", b); 032 j.setOpaque(false); 033 j.addActionListener(this); 034 j.setHorizontalAlignment(JCheckBox.CENTER); 035 return j; 036 } 037 038 public void cancelEditing() { 039 listener.editingFinished(getEditorValue()); 040 } 041 042 public Object getEditorValue() { 043 return j.isSelected(); 044 } 045 046 public void actionPerformed(ActionEvent e) { 047 listener.editingFinished(getEditorValue()); 048 } 049 }