KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > editor2d > model > DimensionPropertySource


1 package com.nightlabs.editor2d.model;
2
3 import org.eclipse.draw2d.geometry.Dimension;
4 import org.eclipse.ui.views.properties.IPropertyDescriptor;
5 import org.eclipse.ui.views.properties.IPropertySource;
6 import org.eclipse.ui.views.properties.PropertyDescriptor;
7 import org.eclipse.ui.views.properties.TextPropertyDescriptor;
8
9 import com.nightlabs.editor2d.EditorPlugin;
10
11 public class DimensionPropertySource implements IPropertySource {
12
13     public static String JavaDoc ID_WIDTH = "width"; //$NON-NLS-1$
14
public static String JavaDoc ID_HEIGHT = "height";//$NON-NLS-1$
15
protected static IPropertyDescriptor[] descriptors;
16
17     static {
18         PropertyDescriptor widthProp =
19             new TextPropertyDescriptor(ID_WIDTH,
20                 EditorPlugin.getResourceString("property.width.label"));
21         widthProp.setValidator(NumberCellEditorValidator.getSharedInstance());
22         PropertyDescriptor heightProp =
23             new TextPropertyDescriptor(ID_HEIGHT,
24                     EditorPlugin.getResourceString("property.height.label"));
25         heightProp.setValidator(NumberCellEditorValidator.getSharedInstance());
26         descriptors = new IPropertyDescriptor[] {widthProp,heightProp};
27     }
28
29     protected Dimension dimension = null;
30
31     public DimensionPropertySource(Dimension dimension){
32         this.dimension = dimension.getCopy();
33     }
34
35     public Object JavaDoc getEditableValue(){
36         return dimension.getCopy();
37     }
38
39     public Object JavaDoc getPropertyValue(Object JavaDoc propName){
40         return getPropertyValue((String JavaDoc)propName);
41     }
42
43     public Object JavaDoc getPropertyValue(String JavaDoc propName){
44         if(ID_HEIGHT.equals(propName)){
45             return new String JavaDoc(new Integer JavaDoc(dimension.height).toString());
46         }
47         if(ID_WIDTH.equals(propName)){
48             return new String JavaDoc(new Integer JavaDoc(dimension.width).toString());
49         }
50         return null;
51     }
52
53     public void setPropertyValue(Object JavaDoc propName, Object JavaDoc value){
54         setPropertyValue((String JavaDoc)propName, value);
55     }
56
57     public void setPropertyValue(String JavaDoc propName, Object JavaDoc value){
58         if(ID_HEIGHT.equals(propName)){
59             Integer JavaDoc newInt = new Integer JavaDoc((String JavaDoc)value);
60             dimension.height = newInt.intValue();
61         }
62         if(ID_WIDTH.equals(propName)){
63             Integer JavaDoc newInt = new Integer JavaDoc((String JavaDoc)value);
64             dimension.width = newInt.intValue();
65         }
66     }
67
68     public IPropertyDescriptor[] getPropertyDescriptors(){
69         return descriptors;
70     }
71
72     public void resetPropertyValue(String JavaDoc propName){
73     }
74
75     public void resetPropertyValue(Object JavaDoc propName){
76     }
77
78     public boolean isPropertySet(Object JavaDoc propName){
79         return true;
80     }
81
82     public boolean isPropertySet(String JavaDoc propName){
83         if(ID_HEIGHT.equals(propName) || ID_WIDTH.equals(propName))return true;
84         return false;
85     }
86
87     public String JavaDoc toString(){
88         return new String JavaDoc("("+dimension.width+","+dimension.height+")");//$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$
89
}
90
91 }
92
Popular Tags