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 ID_XPOS = "xPos"; public static String ID_YPOS = "yPos"; 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 getEditableValue(){ 37 return point.getCopy(); 38 } 39 40 public IPropertyDescriptor[] getPropertyDescriptors(){ 41 return descriptors; 42 } 43 44 public Object getPropertyValue(Object propName){ 45 if(ID_XPOS.equals(propName)){ 46 return new String (new Integer (point.x).toString()); 47 } 48 if(ID_YPOS.equals(propName)){ 49 return new String (new Integer (point.y).toString()); 50 } 51 return null; 52 } 53 54 public boolean isPropertySet(Object propName){ 55 return ID_XPOS.equals(propName) || ID_YPOS.equals(propName); 56 } 57 58 public void resetPropertyValue(Object propName){} 59 60 public void setPropertyValue(Object propName, Object value){ 61 if(ID_XPOS.equals(propName)){ 62 Integer newInt = new Integer ((String )value); 63 point.x = newInt.intValue(); 64 } 65 if(ID_YPOS.equals(propName)){ 66 Integer newInt = new Integer ((String )value); 67 point.y = newInt.intValue(); 68 } 69 } 70 71 public String toString(){ 72 return new String ("["+point.x+","+point.y+"]"); } 74 } 75 | Popular Tags |