KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > editor2d > properties > DoubleCellEditor


1 /**
2  * <p> Project: com.nightlabs.editor2d </p>
3  * <p> Copyright: Copyright (c) 2004 </p>
4  * <p> Company: NightLabs GmbH (Germany) </p>
5  * <p> Creation Date: 18.03.2005 </p>
6  * <p> Author: Daniel Mazurek </p>
7 **/

8 package com.nightlabs.editor2d.properties;
9
10 import org.eclipse.jface.util.Assert;
11 import org.eclipse.jface.viewers.CellEditor;
12 import org.eclipse.swt.widgets.Composite;
13 import org.eclipse.swt.widgets.Control;
14 import org.eclipse.swt.widgets.Text;
15
16 public class DoubleCellEditor
17 extends CellEditor
18 {
19   protected Text text;
20   
21   public DoubleCellEditor() {
22     super();
23   }
24
25   public DoubleCellEditor(Composite parent) {
26     super(parent);
27   }
28
29   public DoubleCellEditor(Composite parent, int style) {
30     super(parent, style);
31   }
32
33   protected Control createControl(Composite parent) {
34     text = new Text(parent, getStyle());
35     return text;
36   }
37
38   protected Object JavaDoc doGetValue() {
39     String JavaDoc stringVal = text.getText();
40     Double JavaDoc d = new Double JavaDoc(stringVal);
41     return d;
42   }
43
44   protected void doSetFocus() {
45     if (text != null) {
46       text.selectAll();
47       text.setFocus();
48     }
49   }
50
51   protected void doSetValue(Object JavaDoc value) {
52     Assert.isTrue(text != null && (value instanceof Double JavaDoc));
53     Double JavaDoc val = (Double JavaDoc) value;
54     String JavaDoc stringVal = Double.toString(val.doubleValue());
55     text.setText(stringVal);
56   }
57
58 }
59
Popular Tags