1 27 28 package org.nightlabs.editor2d.model; 29 30 import java.beans.PropertyChangeEvent ; 31 import java.beans.PropertyChangeListener ; 32 import java.util.ArrayList ; 33 import java.util.List ; 34 35 import org.eclipse.ui.views.properties.IPropertyDescriptor; 36 import org.eclipse.ui.views.properties.IPropertySource; 37 import org.eclipse.ui.views.properties.PropertyDescriptor; 38 import org.nightlabs.base.language.LanguageManager; 39 import org.nightlabs.base.property.IntPropertyDescriptor; 40 import org.nightlabs.editor2d.DrawComponent; 41 import org.nightlabs.editor2d.EditorPlugin; 42 import org.nightlabs.editor2d.properties.NamePropertyDescriptor; 43 import org.nightlabs.editor2d.properties.RotationPropertyDescriptor; 44 import org.nightlabs.language.LanguageCf; 45 46 public class DrawComponentPropertySource 47 implements IPropertySource 48 { 49 protected DrawComponent drawComponent; 50 58 65 protected LanguageManager nameLangMan; 66 public DrawComponentPropertySource(DrawComponent element) { 67 this.drawComponent = element; 68 descriptors = createPropertyDescriptors(); 69 nameLangMan = LanguageManager.sharedInstance(); 70 nameLangMan.addPropertyChangeListener(langListener); 71 } 72 73 protected PropertyChangeListener langListener = new PropertyChangeListener () 74 { 75 public void propertyChange(PropertyChangeEvent evt) 76 { 77 if (evt.getPropertyName().equals(LanguageManager.LANGUAGE_CHANGED)) 78 { 79 LanguageCf langCf = (LanguageCf) evt.getNewValue(); 80 drawComponent.setLanguageId(langCf.getLanguageID()); 81 } 82 } 83 }; 84 85 88 public Object getEditableValue() { 89 return drawComponent; 90 } 91 92 public static final String CATEGORY_NAME = EditorPlugin.getResourceString("property.category.name"); 93 public static final String CATEGORY_GEOM = EditorPlugin.getResourceString("property.category.geom"); 94 public static final String CATEGORY_ROTATION = EditorPlugin.getResourceString("property.category.rotation"); 95 96 protected List descriptors = null; 97 protected List getDescriptors() { 98 if (descriptors == null) 99 descriptors = new ArrayList (); 100 return descriptors; 101 } 102 103 protected List createPropertyDescriptors() 104 { 105 List descriptors = getDescriptors(); 106 107 PropertyDescriptor desc = new NamePropertyDescriptor(drawComponent, 119 DrawComponent.PROP_NAME, 120 EditorPlugin.getResourceString("property.name.label")); 121 desc.setCategory(CATEGORY_NAME); 122 descriptors.add(desc); 123 124 desc = new IntPropertyDescriptor(DrawComponent.PROP_X, 126 EditorPlugin.getResourceString("property.x.label")); 127 desc.setCategory(CATEGORY_GEOM); 128 descriptors.add(desc); 129 130 desc = new IntPropertyDescriptor(DrawComponent.PROP_Y, 132 EditorPlugin.getResourceString("property.y.label")); 133 desc.setCategory(CATEGORY_GEOM); 134 descriptors.add(desc); 135 136 desc = new IntPropertyDescriptor(DrawComponent.PROP_WIDTH, 138 EditorPlugin.getResourceString("property.width.label")); 139 desc.setCategory(CATEGORY_GEOM); 140 descriptors.add(desc); 141 142 desc = new IntPropertyDescriptor(DrawComponent.PROP_HEIGHT, 144 EditorPlugin.getResourceString("property.height.label")); 145 desc.setCategory(CATEGORY_GEOM); 146 descriptors.add(desc); 147 148 desc = new RotationPropertyDescriptor(DrawComponent.PROP_ROTATION, 150 EditorPlugin.getResourceString("property.rotation.label")); 151 desc.setCategory(CATEGORY_ROTATION); 152 descriptors.add(desc); 153 154 desc = new IntPropertyDescriptor(DrawComponent.PROP_ROTATION_X, 156 EditorPlugin.getResourceString("property.rotationx.label")); 157 desc.setCategory(CATEGORY_ROTATION); 158 descriptors.add(desc); 159 160 desc = new IntPropertyDescriptor(DrawComponent.PROP_ROTATION_Y, 162 EditorPlugin.getResourceString("property.rotationy.label")); 163 desc.setCategory(CATEGORY_ROTATION); 164 descriptors.add(desc); 165 166 return descriptors; 167 } 168 169 public IPropertyDescriptor[] getPropertyDescriptors() 170 { 171 if (drawComponent == null) 172 return new IPropertyDescriptor[0]; 173 174 List descriptors = getDescriptors(); 175 return (IPropertyDescriptor[])descriptors.toArray( new IPropertyDescriptor[] {} ); 176 } 177 178 181 public Object getPropertyValue(Object id) 182 { 183 if (id.equals(DrawComponent.PROP_X)) { 184 return new Integer (drawComponent.getX()); 185 } 186 else if (id.equals(DrawComponent.PROP_Y)) { 187 return new Integer (drawComponent.getY()); 188 } 189 else if (id.equals(DrawComponent.PROP_WIDTH)) { 190 return new Integer (drawComponent.getWidth()); 191 } 192 else if (id.equals(DrawComponent.PROP_HEIGHT)) { 193 return new Integer (drawComponent.getHeight()); 194 } 195 else if (id.equals(DrawComponent.PROP_ROTATION)) { 196 return new Double (drawComponent.getRotation()); 197 } 198 else if (id.equals(DrawComponent.PROP_ROTATION_X)) { 199 return new Integer (drawComponent.getRotationX()); 200 } 201 else if (id.equals(DrawComponent.PROP_ROTATION_Y)) { 202 return new Integer (drawComponent.getRotationY()); 203 } 204 else if (id.equals(DrawComponent.PROP_NAME)) { 205 return drawComponent.getI18nText().getText(nameLangMan.getCurrentLanguageID()); 206 } 207 208 return null; 209 } 210 211 214 public boolean isPropertySet(Object id) { 215 return false; 217 } 218 219 222 public void resetPropertyValue(Object id) { 223 } 225 226 229 public void setPropertyValue(Object id, Object value) 230 { 231 if (id.equals(DrawComponent.PROP_X)) { 232 drawComponent.setX(((Integer )value).intValue()); 233 } 234 else if (id.equals(DrawComponent.PROP_Y)) { 235 drawComponent.setY(((Integer )value).intValue()); 236 } 237 else if (id.equals(DrawComponent.PROP_WIDTH)) { 238 drawComponent.setWidth(((Integer )value).intValue()); 239 } 240 else if (id.equals(DrawComponent.PROP_HEIGHT)) { 241 drawComponent.setHeight(((Integer )value).intValue()); 242 } 243 else if (id.equals(DrawComponent.PROP_ROTATION)) { 244 drawComponent.setRotation(((Double )value).doubleValue()); 245 } 246 else if (id.equals(DrawComponent.PROP_ROTATION_X)) { 247 drawComponent.setRotationX(((Integer )value).intValue()); 248 } 249 else if (id.equals(DrawComponent.PROP_ROTATION_Y)) { 250 drawComponent.setRotationY(((Integer )value).intValue()); 251 } 252 else if (id.equals(DrawComponent.PROP_NAME)) { 253 drawComponent.setName((String )value); 254 } 255 } 256 257 } 258 259 | Popular Tags |