1 /*
2  * @(#)DefaultCellEditor.java 1.0 03-JUL-04
3  *
4  * Copyright (c) 2001-2004 Gaudenz Alder
5  *
6  */
7 package org.jgraph.graph;
8 
9 import java.awt.Component;
10 
11 import javax.swing.DefaultCellEditor;
12 import javax.swing.JCheckBox;
13 import javax.swing.JComboBox;
14 import javax.swing.JTextField;
15 
16 import org.jgraph.JGraph;
17 
18 /**
19  * The default editor for graph cells.
20  *
21  * @version 1.0 1/1/02
22  * @author Gaudenz Alder
23  */
24 public class DefaultRealEditor extends DefaultCellEditor
25 		implements
26 			GraphCellEditor {
27 
28 	//
29 	//  Constructors
30 	//
31 	/**
32 	 * Constructs a DefaultCellEditor that uses a text field.
33 	 *
34 	 * @param textField
35 	 *            a JTextField object used as the editor
36 	 */
DefaultRealEditor(final JTextField textField)37 	public DefaultRealEditor(final JTextField textField) {
38 		super(textField);
39 		setClickCountToStart(1);
40 	}
41 
42 	/**
43 	 * Constructs a DefaultCellEditor object that uses a check box.
44 	 *
45 	 * @param checkBox
46 	 *            a JCheckBox object
47 	 */
DefaultRealEditor(final JCheckBox checkBox)48 	public DefaultRealEditor(final JCheckBox checkBox) {
49 		super(checkBox);
50 	}
51 
52 	/**
53 	 * Constructs a DefaultCellEditor object that uses a combo box.
54 	 *
55 	 * @param comboBox
56 	 *            a JComboBox object
57 	 */
DefaultRealEditor(final JComboBox comboBox)58 	public DefaultRealEditor(final JComboBox comboBox) {
59 		super(comboBox);
60 	}
61 
62 	//
63 	//  GraphCellEditor Interface
64 	//
getGraphCellEditorComponent(JGraph graph, Object value, boolean isSelected)65 	public Component getGraphCellEditorComponent(JGraph graph, Object value,
66 			boolean isSelected) {
67 		String stringValue = graph.convertValueToString(value);
68 		delegate.setValue(stringValue);
69 		if (editorComponent instanceof JTextField)
70 			((JTextField) editorComponent).selectAll();
71 		return editorComponent;
72 	}
73 } // End of class JCellEditor
74