KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.nightlabs.editor2d.model;
2
3 import org.eclipse.draw2d.geometry.Point;
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 LocationPropertySource
12 implements IPropertySource
13 {
14     public static String JavaDoc ID_XPOS = "xPos"; //$NON-NLS-1$
15
public static String JavaDoc ID_YPOS = "yPos"; //$NON-NLS-1$
16
protected static IPropertyDescriptor[] descriptors;
17
18     static{
19         PropertyDescriptor xProp =
20             new TextPropertyDescriptor(ID_XPOS,
21                 EditorPlugin.getResourceString("property.xposition.label"));
22         xProp.setValidator(NumberCellEditorValidator.getSharedInstance());
23         PropertyDescriptor yProp =
24             new TextPropertyDescriptor(ID_YPOS,
25                     EditorPlugin.getResourceString("property.yposition.label"));
26         yProp.setValidator(NumberCellEditorValidator.getSharedInstance());
27         descriptors = new IPropertyDescriptor[] {xProp, yProp};
28     }
29
30     protected Point point = null;
31
32     public LocationPropertySource(Point point){
33         this.point = point.getCopy();
34     }
35
36     public Object JavaDoc getEditableValue(){
37         return point.getCopy();
38     }
39
40     public IPropertyDescriptor[] getPropertyDescriptors(){
41         return descriptors;
42     }
43
44     public Object JavaDoc getPropertyValue(Object JavaDoc propName){
45         if(ID_XPOS.equals(propName)){
46             return new String JavaDoc(new Integer JavaDoc(point.x).toString());
47         }
48         if(ID_YPOS.equals(propName)){
49             return new String JavaDoc(new Integer JavaDoc(point.y).toString());
50         }
51         return null;
52     }
53
54     public boolean isPropertySet(Object JavaDoc propName){
55         return ID_XPOS.equals(propName) || ID_YPOS.equals(propName);
56     }
57
58     public void resetPropertyValue(Object JavaDoc propName){}
59
60     public void setPropertyValue(Object JavaDoc propName, Object JavaDoc value){
61         if(ID_XPOS.equals(propName)){
62             Integer JavaDoc newInt = new Integer JavaDoc((String JavaDoc)value);
63             point.x = newInt.intValue();
64         }
65         if(ID_YPOS.equals(propName)){
66             Integer JavaDoc newInt = new Integer JavaDoc((String JavaDoc)value);
67             point.y = newInt.intValue();
68         }
69     }
70
71     public String JavaDoc toString(){
72         return new String JavaDoc("["+point.x+","+point.y+"]");//$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$
73
}
74 }
75
Popular Tags