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 ID_WIDTH = "width"; public static String ID_HEIGHT = "height"; 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 getEditableValue(){ 36 return dimension.getCopy(); 37 } 38 39 public Object getPropertyValue(Object propName){ 40 return getPropertyValue((String )propName); 41 } 42 43 public Object getPropertyValue(String propName){ 44 if(ID_HEIGHT.equals(propName)){ 45 return new String (new Integer (dimension.height).toString()); 46 } 47 if(ID_WIDTH.equals(propName)){ 48 return new String (new Integer (dimension.width).toString()); 49 } 50 return null; 51 } 52 53 public void setPropertyValue(Object propName, Object value){ 54 setPropertyValue((String )propName, value); 55 } 56 57 public void setPropertyValue(String propName, Object value){ 58 if(ID_HEIGHT.equals(propName)){ 59 Integer newInt = new Integer ((String )value); 60 dimension.height = newInt.intValue(); 61 } 62 if(ID_WIDTH.equals(propName)){ 63 Integer newInt = new Integer ((String )value); 64 dimension.width = newInt.intValue(); 65 } 66 } 67 68 public IPropertyDescriptor[] getPropertyDescriptors(){ 69 return descriptors; 70 } 71 72 public void resetPropertyValue(String propName){ 73 } 74 75 public void resetPropertyValue(Object propName){ 76 } 77 78 public boolean isPropertySet(Object propName){ 79 return true; 80 } 81 82 public boolean isPropertySet(String propName){ 83 if(ID_HEIGHT.equals(propName) || ID_WIDTH.equals(propName))return true; 84 return false; 85 } 86 87 public String toString(){ 88 return new String ("("+dimension.width+","+dimension.height+")"); } 90 91 } 92 | Popular Tags |