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;
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     * @author azin azadi
016     */
017    public class GStringEditor implements GBasicCellEditor, ActionListener {
018        EditingFinishedListener listener;
019        protected String initVal;
020    
021        public void setEditingFinishedListener(EditingFinishedListener listener) {
022            this.listener = listener;
023        }
024    
025        protected JTextField jt;
026    
027        public Component getEditorComponent(Object value) {
028            initVal = value + "";
029            jt = new JTextField(initVal);
030            jt.setBorder(null);
031            jt.setBackground(Color.yellow);
032            return jt;
033        }
034    
035        public void cancelEditing() {
036        }
037    
038        public Object getEditorValue() {
039            return jt.getText();
040        }
041    
042        protected void finishEdit() {
043            listener.editingFinished(jt.getText());
044        }
045    
046        public void actionPerformed(ActionEvent e) {
047            finishEdit();
048        }
049    }